Connection between Properties of Entities in Data Oriented Design
Posted
by
sharethis
on Stack Overflow
See other posts from Stack Overflow
or by sharethis
Published on 2012-12-15T17:02:30Z
Indexed on
2012/12/15
17:03 UTC
Read the original article
Hit count: 198
I want to start with an example illustrating my question. The following way it is done in the most games.
class car
{
vec3 position;
vec3 rotation;
mesh model;
imge texture;
void move(); // modify position and rotation
void draw(); // use model, texture, ...
};
vector<car> cars;
for(auto i = cars.begin(); i != cars.end(); ++i)
{
i->move();
i->draw();
}
Data oriented design means to process the same calculation on the hole batch of data at once. This way it takes more advantage out of the processor cache.
struct movedata
{
vec3 position;
vec3 rotation;
};
struct drawdata
{
mesh model;
imge texture;
};
vector<movedata> movedatas;
vector<drawdata> drawdatas;
for(auto i = movedatas.begin(); i != movedatas.end(); ++i)
{
// modify position and rotation
}
for(auto i = drawdatas.begin(); i != drawdatas.end(); ++i)
{
// use model, texture, ...
}
But there comes a point where you need to find other properties according to an entity.
For example if the car crashes, I do not need the drawdata
and the movedata
any more. So I need to delete the entries of this entity in all vectors.
The entries are not linked by code. So my question is the following. How are properties of the same entity conceptually linked in a data oriented design?
© Stack Overflow or respective owner