Handling game logic events by behavior components
Posted
by
chehob
on Game Development
See other posts from Game Development
or by chehob
Published on 2012-12-04T09:47:44Z
Indexed on
2012/12/04
11:31 UTC
Read the original article
Hit count: 233
My question continues on topic discussed here
I have tried implementing attribute/behavior design and here is a quick example demonstrating the issue.
class HealthAttribute : public ActorAttribute
{
public:
HealthAttribute( float val ) : mValue( val ) { }
float Get( void ) const { return mValue; }
void Set( float val ) { mValue = val; }
private:
float mValue;
};
class HealthBehavior : public ActorBehavior
{
public:
HealthBehavior( shared_ptr< HealthAttribute > health )
: pHealth( health )
{
// Set OnDamage() to listen for game logic event "DamageEvent"
}
void OnDamage( IEventDataPtr pEventData )
{
// Check DamageEvent target entity
// ( compare my entity ID with event's target entity ID )
// If not my entity, do nothing
// Else, modify health attribute with received DamageEvent data
}
protected:
shared_ptr< HealthAttribute > pHealth;
};
My question - is it possible to get rid of this annoying check for game logic events? In the current implementation when some entity must receive damage, game logic just fires off event that contains damage value and the entity id which should receive that damage. And all HealthBehaviors are subscribed to the DamageEvent type, which leads to any entity possesing HealthBehavior call OnDamage() even if he is not the addressee.
© Game Development or respective owner