June 2018
Intermediate to advanced
280 pages
7h 46m
English
The following code simulates a 3D world with an attached physics engine. Since creating new 3D objects is heavy and costly in terms of memory, once created they will be the same and just moved from one place to another. Imagine a 3D world with a lot of rocks, trees, bushes, and different textures. By having only one rock of a kind, a tree, bush (they could share some textures) and just remembering where they are located, we save a lot of memory and we are still able to fill with them a considerable large-sized terrain:
package gof.structural.flyweight;import java.util.ArrayList;import java.util.List;import java.util.Map;import java.util.concurrent.ConcurrentHashMap;import java.util.stream.Collectors;publicclass Main{ publicstaticvoid ...Read now
Unlock full access