game-component granularity

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • game-component granularity

      hi guys,

      a question about game component design: what IS a component and what not? for example how is a position and/or orientation handled?

      I've looked at the article in gdmag and in a figure there's a component "Position" mentioned.
      I've also looked at the nebula3-sourcecode and there the physics- and rendering-components store their own transformation:
      (this is from the physics-component handling new transform-message from the physics-engine)

      Source Code

      1. Ptr<UpdateTransform> msg = UpdateTransform::Create();
      2. msg->SetMatrix(this->GetPhysicsEntity()->GetTransform());
      3. this->entity->SendSync(msg.upcast<Messaging::Message>());
      4. this->entity->SetFloat4(Attr::VelocityVector, this->GetPhysicsEntity()->GetVelocity());

      and in the transform-update-handling in the rendering-component this is called:

      Source Code

      1. // set transformation directly
      2. IndexT i;
      3. for (i = 0; i < this->graphicsEntities.Size(); i++)
      4. {
      5. this->graphicsEntities[i]->SetTransform(m);
      6. }

      (in this system a component can send a message to every other component in the same entity)

      But this approach needs a messaging-system where messages are NOT broadcasted because then an update-trigger from the physics would generate an update OF the physics-component again (physics send a transform-update to the entity and this would call every component with this message(also the physics, which triggered the update)). This approach handle transforms in many components internally (for example in the physics- and rendering-component)

      is it better to store the position and orientation in an extra component? this would require an mechanism to detect when the game triggered an transform-update from outside (and the physics-component would need an update of the transform; kinematic objects come to mind) or if the transform was changed from the physics itself (which would not require an update of the physics-component) under the assumtion that the phyics-component only contains an pointer to an rigid body which handles it's own transform-matrix.

      any thoughts on this? and more in general, what is a component and what not?

      thanks :)
    • okay, to answer my own question and for reference: it's really tough.

      I've found a LONG discussion about this here: ogre3d.org/forums/viewtopic.php?f=1&t=36015&start=450

      I try to implement a transform-component which has a flag in it's setter-method which says if a perhaps available physics-component need to be updated or not. and if in the physics-component a new transform is generated it will set the transform without the flag set..

      I'm away coding ;)
    • I am personally trying to move away from components and "objects" with large inheritance hierarchies and dependencies in my own projects, in favor of more data driven implementations. I don't think there is an ultimate "perfect answer" to these things though, you just have to weigh the ups against the downs really.
      "There are of course many problems connected with life, of which some of the most popular are: Why are people born? Why do they die? Why do they want to spend so much of the intervening time wearing digital watches?"
      -Douglas Adams
    • steelblood_relic is right - there's no generic answer to this question other than, "do what seems right for your game."

      In the book I propose a group of subsystems (like the physics system, renderer, script system) communicate through events. In a rigorously implemented architecture, each subsystem would have a completely separate and distinct set of data to make it work. In practice, performance and memory size get in the way of this goal, motivating you to break the rules.

      Its similar to the thought process behind modular code when do you break a class into multiple classes? When do you break a method into multiple methods? Taking any path to extremes serves no one. This, IMO, will always be the sole prerogative of the programmer, who does things in a way they feel to be the best compromise between two mutually exclusive goals.
      Mr.Mike
      Author, Programmer, Brewer, Patriot