I’m trying to build a simple entity/component system in c++ base on the second answer to this question : Best way to organize entities in a game?
Now, I would like to have a static std::map that returns (and even automatically create, if possible).
What I am thinking is something along the lines of:
PositionComponent *pos = systems[PositionComponent].instances[myEntityID];
What would be the best way to achieve that?
Maybe this?
Then you can do:
Just out of curiosity, I checked the assembler code of this C++ code
to be sure that it is really a constant. Assembler (stripped) outputted by GCC (without any optimisations):
So it actually has to read the
L__ZTI3Foo$non_lazy_ptrsymbol (I wonder though that this is not constant — maybe with other compiler options or with other compilers, it is). So a constant may be slightly faster (if the compiler sees the constant at compile time) because you save a read.