Best data structure for a particle system?

xbut360 ritih35959 at larland.com
Tue May 2 09:57:35 UTC 2023


On Friday, 15 November 2013 at 11:52:44 UTC, Mikko Ronkainen 
wrote:
> What would be the best data structure for handling particles in 
> a particle system in D2?
>
> Here's some thoughts:
>
> Particles are simple structs.
> Two lists, one for alive particles, one for dead ones.
> Memory allocations should be avoided, preallocate everything, 
> no allocations when moving between lists.
> Keep alive list as short as possible for fast iteration -> move 
> dead particles off  during iteration.
> Removal and addition of single items only, and it should be 
> fast.
>
> Maybe a single-linked list, std.container.SList? Is there any 
> gotchas? Or some better container for this scenario?

Another popular data structure for particle systems is a quadtree 
or octree, which is a tree data structure that recursively 
subdivides a 2D or 3D space into smaller regions (for more about 
data https://www.programmingassignment.net/). This allows for 
efficient spatial queries, such as finding nearby particles or 
detecting collisions between particles, by traversing the tree 
and only considering particles in nearby regions


More information about the Digitalmars-d-learn mailing list