1
\$\begingroup\$

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++)

\$\endgroup\$
5
  • 5
    \$\begingroup\$ "The idea of searching through a "master list" of all entities in the entire game world seems inefficient and slow." -- So you ran a profiling tool and measured and made sure it actually was slow before asking this question, right? \$\endgroup\$ Dec 31, 2015 at 23:50
  • \$\begingroup\$ People like you ruin StackExchange. You want to say that it is not inefficient? Say it. After all, Game engine architecture is your "passion." If you have nothing else to contribute to my question, then keep it quiet and don't waste my time. \$\endgroup\$ Jan 1, 2016 at 2:08
  • 3
    \$\begingroup\$ @JavaManTeaMan Why so angry? He suggests you to measure and test your question with profiling before asking. That is the only real way to understand if it is inefficient or not. \$\endgroup\$ Jan 1, 2016 at 12:48
  • \$\begingroup\$ @JavaManTeaMan Also Without knowing how many entities will you have and what kind of game are we talking about its impossible to tell. Still component systems can be really fast if implemented properly due to cache efficiency. \$\endgroup\$
    – akaltar
    Jan 1, 2016 at 15:15
  • \$\begingroup\$ @JavaManTeaMan: yeah, I honestly have no idea if it's inefficient for your use case because you didn't explain anything about what you're doing; just that your common sense told you that it "seems" slow. What's inefficient about it? You have very large numbers of entities? You have a large game world and only need to iterate through a subset of relevant entities at any given time? Your implementation of an ECS is sub-par and less efficient than it could be? Why is it inefficient for you? \$\endgroup\$ Jan 1, 2016 at 19:09

3 Answers 3

5
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged .