After a lot of testing and improvements done to my current Entity system that we are using for our final project at Algonquin College, Ottawa, I have come to the conclusion that since components are simply blobs of information and the information doesn't require to be copied in order to be modified (it is modified when is acceded directly through the entity) then they make the perfect structs.
Why is this a good change? structs are of the value type and therefore are not going to be managed by the garbage collector, and the overhead of pooling them as classes versus the overhead of having them living at all times inside of a super class is basically the same, the amount of memory used in comparison can be neglected, not even in the case that we make thousands of entities, this is simply because the entities themselves are to be pooled as well.
In a nutshell, an entity class can be seen as a group of structs with an unique name, in the past I have gone completely religious about not making a class and make all sorts of routes to access a component from an integer, this was in a way handy and neat but it soon became really slow, not slow to develop with but slow to actually access all the components that were required to be modified by the calling system or action.
To further clarify an entity as it stand right now in my current design it would be like this:
Entity class:
{
Contains all the component structs as PUBLIC fields (very important).
Some constructors that take nothing, some that take a name (global name enum), inside of the constructor we call every struct initialize which will give all the fields within the component struct an initial value (this is handy because we would like to reuse the entity and to do so we need a way to give it a clean start), and finally subscribe the unique tag that identified the entity as unique(this is acquired from the entity factory at the moment).
methods to pool the entity back out, or from specific systems.
}
I will be providing code as time allows, but what I want to get across is that thanks to this changes our game now can easily ramp up the limits in graphics, physics and overall all.
No comments:
Post a Comment