Sign in to follow this  

Entity Component System - Accessing Components

This topic is 1118 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm experimenting with building an Entity Component System, and I've run into the problem of accessing components. I am currently just using a method for each individual component type and a specific typed variable. I'd like to change to something better, but I don't know what is best.

I've thought of simply searching through a dynamic list each time a component is accessed, but I'm afraid this will start to lag if there are many access calls per second (which there currently are). Also, I'm afraid a dynamic list will take longer to append and will be less memory efficient than what I have now.

I googled the question and someone suggested a hash map, which has a constant access time, but I have never used a hash map (I know :O) and after a little bit of research, I still couldn't see the benefit of using one for something like this.

So my question is, in an entity component system, what is a good way to quickly and efficiently access components?

Share this post


Link to post
Share on other sites

Since you do not describe how you are defining and using your components (other then that they are accessed through a method), it is hard to give any direct advice as how to store and access them.

 

There are many forms of entity-compoennt systems - some where an entity an object with a list of components and others where an entity is just a an id and the components are stored in seperat lists and accessed through that entity id.

 

I am personally using an approach based on the latter (where an entyity is represented by an id) since I like the simplicity and performance of that method,

I also think its very readable, but it can be a bit hard to wrap your head around initially if you are more used to the object oriented style of programming.

 

I started out by following some great articles here on gamedev:

 

http://www.gamedev.net/page/resources/_/technical/game-programming/understanding-component-entity-systems-r3013

http://www.gamedev.net/page/resources/_/technical/game-programming/implementing-component-entity-systems-r3382

http://www.gamedev.net/page/resources/_/technical/game-programming/case-study-bomberman-mechanics-in-an-entity-component-system-r3159

 

Have a look and see if that is something you could use maybe.

Share this post


Link to post
Share on other sites

This topic is 1118 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this