need help with data oriented design

Started by
22 comments, last by cool mr croc 11 years, 10 months ago
thanks, its helped alot. how about encapsulating further entity data? i assume its ok to create a little struct that contains all of that?
Advertisement
I tend to think of DOD in a Component/Entity manner, where the Components are just pieces of Data, and an Entity is a collection of Components, and there are systems, which act on the components. So, the Brick would have a Location Component (Position and Velocity), a Color Component, a RectDimensions, and a Strength Component (how hard it is to smash), and it would be processed via the Brick System (for how to handle collisions). The ball entity would have the same components, except a Circle Component instead of Rectangle, and it would be processed by the Ball System, and the Paddle would have all those components, except it would be processed by the Paddle System. The paddle could have extra components as well, such a bullets, if it is able to shoot bullets (like Arkanoid did).

However, all these components are stored in like vectors, and are handled at the same time, but run through the different systems, based on which entity owns that component.

kind of like this (pseudo code):



class System {
virutal void HandleLocation(Location &locationComponent) = 0;
// fill with rest
};

class BrickSystem : public System
{
void HandleLocation(Location &locationComponent);
};

typedef uint32_t TEntity;

class Component {
TEntity Owner; // who owns us, unique value
System *ComponentSystem; // System to handle this component
};

class Location : public Component {
Vector2 Location;
Vector2 Velocity;
};

std::vector<Location> LocationList;
BrickSystem *BrickSys;

void main()
{

// Initialize the systems
BrickSys = new BrickSystem();

// Load the bricks
for (each brick to load) {
TEntity BrickEntity = GetUniqueId();
Location BrickLocation(BrickEntity, CurrentBrickX, CurrentBrickY, 0.0f, 0.0f);
BrickLocation.SetSystem(BrickSys);
LocationList.push_back(Location);
// Load other components into brick
}

}

void Update()
{
for (each it = item in LocationList) {
// Will call brick System handleLocaiton for brick's, BallSystem Handle Location for ball, etc
it->GetSystem()->HandleLocation(it);
}
}


Or something like that.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

thanks mate thats looks very interesting. ill have a look once i finish this program, ill probably have a que or two.
one more question and ill be donw, consider the following code


class application
{
vector<pos> ballPos>
vector<pos> batPos>
vector<pos> brickPos>

vector<bool> ballCol>
vector<bool> batCol>
vector<bool> brickCol>

vector<vel> ballVel>
vector<vel> batVel>
vector<vel> brickVel>

int somethingOnlybatHas1;
int somethingOnlybatHas2;
int somethingOnlybatHas2;

int somethingOnlyBricksSystemHas;
void update()
{
//loop through collections and call check collisions and resize
}
void checkCollision(//pos vec1, pos vec2, col result1, col result2)
{
//check collision, store result
}
void resize()
{
}
};


is there a better way to encapsulate this so the variables unique to each system is held within its class? i was planning on having system classes each containing their containers. and perhaps with their own update function. does that sound good?

This topic is closed to new replies.

Advertisement