Initializers in class

1
2
3
4
5
6
class RenderSystem{
public:
 RenderSystem(EntityManager & entity_manager) : entity_manager_handle(entity_manager) {}
private:
 EntityManager & entity_manager_handle;
};


I am using this sort of a class an I'm wondering if it's ok to have an access to other classes like this. If not what are the downsides and what would be a better way. Thanks.
I'm guessing this is a game you're programming? It looks like maybe your RenderSystem and EntityManager are too entangled; why does the RenderSystem need a handle to the EntityManager?

Maybe instead you could pass some container containing your entities to the RenderSystem in a function call. Something like:

1
2
3
4
5
6
7
8
9
10
11
12
class EntityManager
{
   std::vector<Entity*> entitylist;
}

RenderSystem rendersystem;
EntityManager entitymanager;



rendersystem.RenderEntities(entitymanager.entitylist);


I used to do what you're doing, which is basically giving every separate system a handle to every other system. The problem is that when you do this, you risk not fully separating out the duties of each subsystem. I prefer to send only the necessary data to a class via function calls because you are then less likely to mix up the roles of your classes.


Last edited on
EntityManager is just a container with a few helper functions. Something like:

struct EntityManager{
int CreateEntity();

int mask[ENTITY_COUNT];
Texture textures[ENTITY_COUNT];
// And so on
}

I'm using the handle just to access render components and mostly don't call EntityManager functions from other managers. I got the idea from a gamedev.net article and it seemed like an easy way to implement entity-component system.
Topic archived. No new replies allowed.