Added WorldThingGround event to hook into the actor at exact moment its corpse spawns gibs upon being crushed.

# Conflicts:
#	src/events.cpp
#	src/events.h
This commit is contained in:
nashmuhandes 2020-09-06 20:34:40 +08:00 committed by drfrag
parent 64e0ea59d1
commit 51a07d41c0
4 changed files with 30 additions and 1 deletions

View file

@ -381,6 +381,15 @@ void E_WorldThingDied(AActor* actor, AActor* inflictor)
handler->WorldThingDied(actor, inflictor);
}
void E_WorldThingGround(AActor* actor)
{
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
if (actor->ObjectFlags & OF_EuthanizeMe)
return;
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
handler->WorldThingGround(actor);
}
void E_WorldThingRevived(AActor* actor)
{
// don't call anything if actor was destroyed on PostBeginPlay/BeginPlay/whatever.
@ -820,6 +829,20 @@ void DStaticEventHandler::WorldThingDied(AActor* actor, AActor* inflictor)
}
}
void DStaticEventHandler::WorldThingGround(AActor* actor)
{
IFVIRTUAL(DStaticEventHandler, WorldThingGround)
{
// don't create excessive DObjects if not going to be processed anyway
if (isEmpty(func)) return;
FWorldEvent e = E_SetupWorldEvent();
e.Thing = actor;
VMValue params[2] = { (DStaticEventHandler*)this, &e };
VMCall(func, params, 2, nullptr, 0);
}
}
void DStaticEventHandler::WorldThingRevived(AActor* actor)
{
IFVIRTUAL(DStaticEventHandler, WorldThingRevived)

View file

@ -40,6 +40,8 @@ void E_WorldUnloadedUnsafe();
void E_WorldThingSpawned(AActor* actor);
// called after AActor::Die of each actor.
void E_WorldThingDied(AActor* actor, AActor* inflictor);
// called inside AActor::Grind just before the corpse is destroyed
void E_WorldThingGround(AActor* actor);
// called after AActor::Revive.
void E_WorldThingRevived(AActor* actor);
// called before P_DamageMobj and before AActor::DamageMobj virtuals.
@ -162,6 +164,7 @@ public:
void WorldUnloaded();
void WorldThingSpawned(AActor* actor);
void WorldThingDied(AActor* actor, AActor* inflictor);
void WorldThingGround(AActor* actor);
void WorldThingRevived(AActor* actor);
void WorldThingDamaged(AActor* actor, AActor* inflictor, AActor* source, int damage, FName mod, int flags, DAngle angle);
void WorldThingDestroyed(AActor* actor);

View file

@ -1209,6 +1209,7 @@ bool AActor::Grind(bool items)
S_Sound (this, CHAN_BODY, 0, "misc/fallingsplat", 1, ATTN_IDLE);
Translation = BloodTranslation;
}
E_WorldThingGround(this);
return false;
}
if (!(flags & MF_NOBLOOD))
@ -1251,6 +1252,7 @@ bool AActor::Grind(bool items)
gib->Translation = BloodTranslation;
}
S_Sound (this, CHAN_BODY, 0, "misc/fallingsplat", 1, ATTN_IDLE);
E_WorldThingGround(this);
}
if (flags & MF_ICECORPSE)
{

View file

@ -15,7 +15,7 @@ struct WorldEvent native play version("2.4")
native readonly bool IsSaveGame;
// this will be true if we are re-entering the hub level.
native readonly bool IsReopen;
// for thingspawned/thingdied/thingdestroyed
// for thingspawned/thingdied/thingdestroyed/thingground
native readonly Actor Thing;
// for thingdied. can be null
native readonly Actor Inflictor;
@ -328,6 +328,7 @@ class StaticEventHandler : Object native play version("2.4")
virtual void WorldUnloaded(WorldEvent e) {}
virtual void WorldThingSpawned(WorldEvent e) {}
virtual void WorldThingDied(WorldEvent e) {}
virtual void WorldThingGround(WorldEvent e) {}
virtual void WorldThingRevived(WorldEvent e) {}
virtual void WorldThingDamaged(WorldEvent e) {}
virtual void WorldThingDestroyed(WorldEvent e) {}