Hi All,
After reading the abundance of message's recently about the subject, it got me interested in researching into it. Al tough I feel that I understand the theory behind it, there are a few conflicting ideas in articles and question I have, and am hoping someone can help me with.
In relation to the article I read on GameDev http://www.gamedev.net/page/resources/_/technical/game-programming/implementing-component-entity-systems-r3382 I have implemented a small demo using this, but am unsure if i'm going in the right direction.
In the article things are defined as Position[Entity_MAX], Velocity[Entity_MAX], Appearance[Entity_MAX].
When an entity is created, it returns an unsigned int, which I take to go across all arrays - for example the first entity that is created has a position and a velocity which is Position[0], Velocity[0], if a static item was then added it would be Position[1] and Appearance[1].
My real confusion is of the empty space ( if my understanding of how it all ties together is correct ) If I have many components created in this way - for example 50, and the majority of my entity's only use one or two of these components at a time - will that not just waste a wide range of space? - or is this acceptable because of the cache speed increase?
Alternately, am I just creating the Components in the wrong way? While using the technique he shows for the mask, I run into a problem.
My code at the minute, when being used to move and render is as below
World = new s_World;
CreateDynamicObject( World, 0.0f, 0.0f, 0.0001f, 0.0001f ); // xPos, yPos, xVel, yVel
Graphics = new cGraphics();
Physics = new cPhysics();
void cGame::Render() {
glClearColor( 0.1f, 0.1f, 0.1f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT );
Physics->Update( World );
Graphics->Render( World );
}
void cGraphics::Render( s_World *World ) {
for( int entity = 0; entity < ENTITY_MAX; entity++ ) {
if( (World->mask[entity] & STATIC_MASK) == STATIC_MASK) {
// Render Code
}
}
}