I’ve got a hobby game that I’ve been using as a framework for learning graphics programming. It’s kind of a hybrid 3D modeler and sandbox simulation game, so there’s a fair amount of dynamically generated geometry.
I’m struggling to design my basic game loop and data structures. I am attracted to the ECS paradigm for its tendency to resist spaghettification. But I’m having trouble understanding how dynamically generated data fits into this pattern.
The simplest example that confuses me is a particle system. Let’s say I have an entity that can move around and also emits particles. The entity’s motion path generates a spline, which has to be recorded somewhere. It’s easy enough to imagine a ParticleEmitter component that records N previous object positions.
The first difficulty appears when I want to have the particles collide with the scene. It feels incorrect to model each particle as an entity (my camera sees a lot of the scene at once, so there could be thousands of particles spawned or killed on any individual frame), but I also feel like it’s incorrect for code cleanliness to teach the physics system about particles as a special case.
So it seems the answer is to have the particle system emit collision volumes without associating an entity to each collision volume. I guess I could generalize the Collision component to represent a collection of rigid bodies, and attach a single Collision component to the same entity as the ParticleEmitter. But the resulting collision geometry is dynamic, which means it can’t fit in the fixed-size Collision component.
Furthermore, the Physics system is going to update the position, velocity, and inertia of each particle separately, and probably needs a persistent BVH data structure to do so efficiently. Where does *that* data live? If the Collision component just points into the Physics system’s internal data structures, doesn’t that require the ParticleEmitter know at least enough about the Physics system to ask it to create collision volumes?