Dots101/Entities101/Assets/Tornado/README.md
In this Tornado simulation, a tornado travels in a figure-8 pattern and tears apart buildings made of bars connected at their end points. The tornado is depicted as a swarm of swirling cubes. The bars and cubes collide with the ground but not with each other.
BuildingSpawnSystem: spawns the points and bars that make up theBuildingSystem: simulates the points and bars. (Updated in the FixedStepSimulationSystemGroup.)BuildingRenderSystem: updates the bar transforms for rendering.
buildings.CameraSystem: moves the camera to follow the tornado.ConfigAuthoring: contains all sim parameters plus prefabs for the bars and particles.TornadoSpawnSystem: spawns the cube particles that make up the tornado.TornadoSystem: simulates the cube particles. (Updated in the FixedStepSimulationSystemGroup.)TornadoSpawnSystem and BuildingSpawnSystem at runtime.IJobParallelFor.The advantage of an entity is flexibility: entities can be independently created and destroyed, their components can be added and removed, and a reference to an entity will remain valid for the entity's lifetime. All entities sharing a subset of component types can be processed together in a single query. On the downside, a reference to an entity is composed of two ints (index and version numbers), and looking up an entity via reference is costlier than if we could just follow a pointer.
The advantage of using arrays instead of entities is that items can be looked up directly by their index. Not only is the lookup cheaper, a reference to an item can be stored as just a single int. On the downside, elements in an array cannot be independently added and removed without also shifting the other elements within the array, thereby changing their indexes.
In this sample, we use entities to render the bars and cubes, but what about the points? The points never change in structure and are never reordered nor deleted, only created (when bars disconnect), so the advantages of entities don't apply here. Storing the points in an array also allows for cheaper lookups, of which we'll need to do many per frame.
Furthermore, the simulation has a large number of bars, each of which must reference its two points. Were the points stored as entities, each bar would require 16 bytes for these references (2 ints per point). By storing the points in an array, each bar requires only 8 bytes for these references (1 int per point). Smaller data is always a good thing, as it leas to less memory access.