I don´t get the point, why I should use the DoWithX functions.
Whats better with them?
I think:
is much faster to write, needs less knowledge of the system (You don´t need to know all the different Callback classes) and in addition looks much cleaner than those big classes.
The current implementation of the above code:
Whats better with them?
I think:
Code:
cEntity *ent = m_Player->GetWorld()->GetEntityById(Id);
if(ent && ent->IsA("cPawn"))
{
reinterpret_cast<cPawn*>(ent)->TakeDamage(1, m_Player);
}
The current implementation of the above code:
Code:
class cDamageEntity : public cEntityCallback
{
virtual bool Item(cEntity * a_Entity) override
{
if( a_Entity->IsA("cPawn") )
{
reinterpret_cast< cPawn* >( a_Entity )->TakeDamage(Damage, Instigator );
}
return true;
}
public:
int Damage;
cEntity * Instigator;
} Callback;
Callback.Damage = 1; // TODO: Find proper damage from current item equipped
Callback.Instigator = m_Player;
cWorld * World = m_Player->GetWorld();
World->DoWithEntityByID(a_Packet->m_TargetID, Callback);