Horde3D
http://www.horde3d.org/forums/

Question about GameEngine events
http://www.horde3d.org/forums/viewtopic.php?f=6&t=1019
Page 1 of 1

Author:  EsaK [ 03.12.2009, 21:05 ]
Post subject:  Question about GameEngine events

I'm looking at possibly using GameEngine for my little game. I have looked at the samples but I'm missing some more advanced sample of how to actually use the GameEngine, particularly in code.
For example what I have learned so far is that events are a central piece (for triggering actions) but I have not yet figured out how to use these in my own game logic... for starters I want to listen/catch an event when a gameentity collides with some other gameentity (through bullet physics).
Are there any more advanced examples of how to do this, or could someone provide some code snippet of how to accomplish this?
Thanks in advance.

Author:  Volker [ 04.12.2009, 08:14 ]
Post subject:  Re: Question about GameEngine events

I can't offer you a out of the box sample right now, but in the BulletPhyiscs Component there is a GameEvent:E_COLLISION that will be sent for every colliding object. You may have a look at Physics.cpp line 142. So if you create a new e.g. collision component for the GameEngine you can register that component for E_COLLISION events and implement some reaction when an E_COLLISION event was sent by the bullet component.

Something like this:

Code:
GameComponent* CollisionComponent::createComponent( GameEntity* owner )
{
   return new CollisionComponent( owner );
}

CollisionComponent::CollisionComponent(GameEntity *owner) : GameComponent(owner, "CollisionHandler")
{
   owner->addListener(GameEvent::E_COLLISION, this);
   CollisionManager::instance()->addComponent(this);   
}

CollisionComponent::~CollisionComponent()
{
   CollisionManager::instance()->removeComponent(this);
}

void CollisionComponent::executeEvent(GameEvent *event)
{
   if( event->id() == GameEvent::E_COLLISION )
   {
      // DO SOMETHING
   }
}


Author:  EsaK [ 06.12.2009, 21:19 ]
Post subject:  Re: Question about GameEngine events

Thanks for the answer.
I saw that there already is a CollisionComponent in the GameEngine. I guess that I can use it (and it's two methods: numCollisions() and collision() in my render loop)?

If someone has a more complete example of how to use the GameEngine this is very much welcome :-)
(For example how a game entity/character can pick up an object and walk around with it and then drop it.)

Author:  AcidFaucet [ 09.12.2009, 00:27 ]
Post subject:  Re: Question about GameEngine events

Okay ...

I would likely do it with two new components (probably tied to a single manager and in a single dll), InventoryComponent and ItemComponent. Whatever has an item component would have a physics component as well as the item will listen to collision events. When the item receives an event it would do checkEvent to the other entity for some new event type (e.g. PickupItemEvent), the checkEvent handler of the other entity in the InventoryComponent would see if it's allowed to pick the item up. If the item finds out that it's accepted than it will executeEvent on the other entity. Assumably the inventory component would receive a pointer to the item or increment an ammo counter or something, after which the item would disable its physics and graphic components (it'll only need to worry about them when responding to a DropItem event.

Dropping the item is more complicated.

Recap step-by-step:

    - 2 new components (both of which should be made to be useable for all sorts of item 'types', so you can have an inventory for a character, a crate, etc)
    - new events and event data classes
    - Process
      - checkEvent on the entity who may have an InventoryComponent on collision
      - if ok then executeEvent on the entity who has the InventoryComponent, and disable graphics and physics for the pickup item

Obviously this is kind of cumbersome for simple cases (e.g. ammo counts), but its flexible, though I implemented a PropertyMap (binds existing variables) and DynamicDataSet (on the fly data) for the simple cases where you just need to do a "Does the entity have? Ok, set it to ____." At some point in the not so distant future I'll end up pushing out all my changes, too busy on tool dev to do the necessary initial-debugging.

NOTE: Just use the BulletPhysics component, the collision component doesn't really do too much.

Author:  EsaK [ 09.12.2009, 10:21 ]
Post subject:  Re: Question about GameEngine events

Thanks for the suggestions.
But how would I do if I for example want a character to pick up a crate and walk around with it and then drop it (the crate being visible the whole time)?
... to let the crate "attach to" and "follow" the character and still have the physics for the crate (for collision detection)?

Author:  AcidFaucet [ 10.12.2009, 00:44 ]
Post subject:  Re: Question about GameEngine events

That's more complicated.

In that case you don't need to disable anything. Attach as normal, and add the ability to turn a dynamic physics object into a kinematic physics object and vice-versa.

Both entities will need to make sure that their physics primitives are ignoring collisions with the other entity (else inter-penetration could get violent), not too difficult.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/