Today was a refactoring day. WARNING technical talk incoming.
I read an article about particle systems and ended up implementing one of the data containers described there. (
http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/flexible-particle-system-the-container-r3701)
Basically I have two custom lists for dynamic data now:
Synchronization list is for objects which are synchronized over network (players, bullets etc). Each object has a certain id that coincide it's position in this list.
Look at the picture below:1. In the server every new node is added to the first available spot.
2. When node is "destroyed", it's just marked inactive.
3. When client receives a packet about new node, it's placed in it's certain position.
Pros of this approach:+ element positions in the list won't change
+ number of lookups when adding elements can be reduced by keeping track of the first empty slot
Recycle list is for dynamic objects which aren't synchronized (primarily particles). All active elements are located in the first part of the list and inactive ones are in the end.
Look at the picture below:1. Every new node is put after last active node.
2. 3. When node is "destroyed", it's marked as inactive and swapped with last active one.
Pros of this approach:+ When iterating over this list there no need to check null values or inactive elements.
+ All operations have constant complexity.
+ Inactive elements can be reused -> zero garbage.
Legend:Green dot's - active objecs
Red dot's - inactve objects (nor updated or drawn)
White dot's - NULLs
That looks really cool, following!
Thank you guys, it's really motivating. I'll keep posting updates.