Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualirlanrobson

Posted 07 February 2014 - 02:15 PM

What are Actor and RigidBody? Are those components?

 

This means that there is some outside code that knows specifically about a PhysicsSystem, and more importantly that entities with Actor and RigidBody should be added via PhysicsSystem.PushSync.

 

Instead, I would think this logic would exist in the PhysicsSystem. e.g. systems in general implement a common interface that has methods for adding/removing entities. When it's called, the PhysicsSystem itself knows that it's interested in entities with Actor and Rigid body, and can then add them to some internal list. That way you don't need outside logic that knows about the PhysicsSystem (other than a single line of code that says, "create a PhysicsSystem and add it to the list of systems") and that it depends on Actor & RigidBody.

 

1. Yes

2. Was just a simple way of saying...

3. I completely agree with you in that case. Now, following your method, becomes:

class Entity {
public:
template <class T> 
T* GetComponent(const std::string& _id)
{
std::map<std::string, Component*>::iterator it = component.find(_id);
if (it != component.end()) {
return static_cast<T>(it->second);
} else {
return 0;
}
}
};
class PhysicsSystem {
public:
PushComponent(Entity* _entity)
{
Actor* actor = _entity->GetComponent<Actor*>("Actor");
RigidBody* rbody = _entity->GetComponent<RigidBody*>("RigidBody");

if (rbody && actor)  {
PhysicsSync sync(actor, body);
sync.push_back(sync);
}
}
};

#1irlanrobson

Posted 07 February 2014 - 02:14 PM

What are Actor and RigidBody? Are those components?

 

This means that there is some outside code that knows specifically about a PhysicsSystem, and more importantly that entities with Actor and RigidBody should be added via PhysicsSystem.PushSync.

 

Instead, I would think this logic would exist in the PhysicsSystem. e.g. systems in general implement a common interface that has methods for adding/removing entities. When it's called, the PhysicsSystem itself knows that it's interested in entities with Actor and Rigid body, and can then add them to some internal list. That way you don't need outside logic that knows about the PhysicsSystem (other than a single line of code that says, "create a PhysicsSystem and add it to the list of systems") and that it depends on Actor & RigidBody.

 

1. Yes

2. Was just a simple way of saying...

3. I completely agree with you in that case... so following your method:

class Entity {
public:
template <class T> 
T* GetComponent(const std::string& _id)
{
std::map<std::string, Component*>::iterator it = component.find(_id);
if (it != component.end()) {
return static_cast<T>(it->second);
} else {
return 0;
}
}
};
class PhysicsSystem {
public:
PushComponent(Entity* _entity)
{
Actor* actor = _entity->GetComponent<Actor*>("Actor");
RigidBody* rbody = _entity->GetComponent<RigidBody*>("RigidBody");

if (rbody && actor)  {
PhysicsSync sync(actor, body);
sync.push_back(sync);
}
}
};

PARTNERS