Skip to content

Collision and Object Model

mconbere edited this page Oct 18, 2011 · 1 revision

We have layered a new object/action model on top of the existing Maratis infrastructure. It did not support easily creating your own object model purely in C++, so this ability was added. The collision model was updated to fairly efficiently call custom collision interactions between all pairs of colliding world objects.

The object/action model is still somewhat in flux. The best current example of how the model is intended to work is following how the newt::Player obtains a gem in their inventory after colliding with newt::Gem.

Flow of Player/Gem interaction:

  • in Game::update(), all collisions are enumerated. For each pair of Entity objects a and b, a->CollidesWith(b) and b->CollidesWith(a) are called. Entity objects implement a default null action for all possible actions, Entity::CollidesWith(Entity*) being the action created for collisions.

  • in Gem::CollidesWith(Entity*), the gem recognizes the collision with another object. The gem then calls the action Entity::TransferInventory(const Inventory&) on the colliding entity. If the colliding entity responded to the transfer, the gem clears its inventory and schedules itself to be removed at the end of the update with Entity::RemoveAtEndOfUpdate(). Entities are removed at the end of an update because there may be subsequent collisions involving the entity, so the lifespan of an entity should at least until the end of an update.

A couple of points about this interaction model:

  • Entity contains stubs for all object interaction. This may not be ideal, but it decouples entities. One entity does not need to know any details about another entity. I'm hopeful that this is a property we can maintain.

  • There is not currently an ordering of object types specified in the collision model, so it is pure chance if the player collides with the gem first, or the other way around. It may be advantageous to create a more strict ordering in the future.

If you have any questions about how to use objects or add actions, feel free to talk to Morgan. Nothing is set in stone right now, or ever, this merely seemed convenient and sufficient for our medium-term goals.

Clone this wiki locally