I'm trying to make an efficient "entity system" in C++, I've read a lot of blog/articles/documentation on the Internet to get lot of information but I've got some questions again.
I've find two interesting subjects:
For me, the two systems look very similar.
So, I've found this example by Adam Smith: https://stackoverflow.com/a/2021868
I need to have a flexible system like this:
// Abstract class
class Component
{
// data here
}
// exemple
class Car : public Component
{
// Data here
}
// Entity with components
class Entity
{
std::vector<Component*> components;
}
So, if my entity have the followings components: Car, Transform, Sprite, did my components array will had linear data like data-driven system?
Now, I have Systems:
class System
{
virtual void init();
virtual void clear();
virtual void update();
std::unordered_map< const char*, Entity*> entities;
}
class RendererSystem : public System
{
// Methods's definition (init, clear, …).
void update()
{
for( entity, … )
{
Sprite* s = entity->getComponent('sprite');
...
}
}
}
All this points look "blur" in my mind.
new
(if it's a pointer). Then once you allocated it you won't need to do it again as soon as you will pass the reference to the item aroundIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With