I have been developing a game engine. I was wondering what I should use for a component system. I've read up on entity component systems, but what other alternatives are there? The idea of searching through a "master list" of all entities in the entire game world seems inefficient and slow. I need the most efficient one possible (3D and 2D, if that matters). Using object oriented programming (C++)
closed as off-topic by ashes999, bummzack, Alexandre Vaillancourt♦, Sean Middleditch, Josh♦ Jan 4 '16 at 16:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Josh
You will end with up keeping a list/array/database/dictionary/hastable (etc.) of all objects you have somehow, divided into chunks or not. That is the only way to track and store changes in your game on runtime.
But there is a choice you can make; which one do you care about: memory or CPU? If you care about memory, you should go with single master-list. If you care about CPU, you should go with divided lists like chunks/tagging/layering etc..
But please note that, if your game don't get big enough, these optimizations will be barely noticable for both developers and players.
Build a system where objects can be in multiple lists at once and build lists according to processing categories along with the master list.
This way you can run through the list that suits your purpose.
Divide your world up into chunks. Store a linked list of entities in each chunk. When an entity moves out of a chunk, move it from one list to another.
This allows you to pick out which chunks of entities to send to the player and which to unload more efficiently.
Linked lists are especially good for this because adding/removing elements is fast, as well as them being dynamic.