Jump to content

  • Log In with Google      Sign In   
  • Create Account


need help with data oriented design


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
23 replies to this topic

#21 cool mr croc   Members   -  Reputation: 113

Like
0Likes
Like

Posted 05 June 2012 - 12:32 PM

thanks, its helped alot. how about encapsulating further entity data? i assume its ok to create a little struct that contains all of that?

Sponsor:

#22 BeerNutts   Crossbones+   -  Reputation: 2520

Like
1Likes
Like

Posted 05 June 2012 - 01:14 PM

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.

Edited by BeerNutts, 05 June 2012 - 01:16 PM.

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)

#23 cool mr croc   Members   -  Reputation: 113

Like
0Likes
Like

Posted 05 June 2012 - 02:07 PM

thanks mate thats looks very interesting. ill have a look once i finish this program, ill probably have a que or two.

#24 cool mr croc   Members   -  Reputation: 113

Like
0Likes
Like

Posted 06 June 2012 - 07:31 AM

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?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS