Added player events
This commit is contained in:
parent
bc1194d03b
commit
7fa50c22e5
3 changed files with 157 additions and 0 deletions
101
src/events.cpp
101
src/events.cpp
|
|
@ -337,6 +337,30 @@ void E_WorldThingDestroyed(AActor* actor)
|
|||
handler->WorldThingDestroyed(actor);
|
||||
}
|
||||
|
||||
void E_PlayerEntered(int num)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
handler->PlayerEntered(num);
|
||||
}
|
||||
|
||||
void E_PlayerRespawned(int num)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
handler->PlayerRespawned(num);
|
||||
}
|
||||
|
||||
void E_PlayerDied(int num)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
|
||||
handler->PlayerDied(num);
|
||||
}
|
||||
|
||||
void E_PlayerDisconnected(int num)
|
||||
{
|
||||
for (DStaticEventHandler* handler = E_LastEventHandler; handler; handler = handler->prev)
|
||||
handler->PlayerDisconnected(num);
|
||||
}
|
||||
|
||||
// normal event loopers (non-special, argument-less)
|
||||
DEFINE_EVENT_LOOPER(RenderFrame)
|
||||
DEFINE_EVENT_LOOPER(WorldLightning)
|
||||
|
|
@ -348,6 +372,7 @@ IMPLEMENT_CLASS(DEventHandler, false, false);
|
|||
IMPLEMENT_CLASS(DBaseEvent, false, false)
|
||||
IMPLEMENT_CLASS(DRenderEvent, false, false)
|
||||
IMPLEMENT_CLASS(DWorldEvent, false, false)
|
||||
IMPLEMENT_CLASS(DPlayerEvent, false, false)
|
||||
|
||||
DEFINE_FIELD_X(RenderEvent, DRenderEvent, ViewPos);
|
||||
DEFINE_FIELD_X(RenderEvent, DRenderEvent, ViewAngle);
|
||||
|
|
@ -357,6 +382,7 @@ DEFINE_FIELD_X(RenderEvent, DRenderEvent, FracTic);
|
|||
DEFINE_FIELD_X(RenderEvent, DRenderEvent, Camera);
|
||||
|
||||
DEFINE_FIELD_X(WorldEvent, DWorldEvent, IsSaveGame);
|
||||
DEFINE_FIELD_X(WorldEvent, DWorldEvent, IsReopen);
|
||||
DEFINE_FIELD_X(WorldEvent, DWorldEvent, Thing);
|
||||
DEFINE_FIELD_X(WorldEvent, DWorldEvent, Inflictor);
|
||||
DEFINE_FIELD_X(WorldEvent, DWorldEvent, Damage);
|
||||
|
|
@ -365,6 +391,9 @@ DEFINE_FIELD_X(WorldEvent, DWorldEvent, DamageType);
|
|||
DEFINE_FIELD_X(WorldEvent, DWorldEvent, DamageFlags);
|
||||
DEFINE_FIELD_X(WorldEvent, DWorldEvent, DamageAngle);
|
||||
|
||||
DEFINE_FIELD_X(PlayerEvent, DPlayerEvent, PlayerNumber);
|
||||
DEFINE_FIELD_X(PlayerEvent, DPlayerEvent, IsReturn);
|
||||
|
||||
DEFINE_ACTION_FUNCTION(DEventHandler, Create)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
|
|
@ -486,8 +515,14 @@ DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldThingDamaged)
|
|||
DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldThingDestroyed)
|
||||
DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldLightning)
|
||||
DEFINE_EMPTY_HANDLER(DStaticEventHandler, WorldTick)
|
||||
|
||||
DEFINE_EMPTY_HANDLER(DStaticEventHandler, RenderFrame)
|
||||
|
||||
DEFINE_EMPTY_HANDLER(DStaticEventHandler, PlayerEntered)
|
||||
DEFINE_EMPTY_HANDLER(DStaticEventHandler, PlayerRespawned)
|
||||
DEFINE_EMPTY_HANDLER(DStaticEventHandler, PlayerDied)
|
||||
DEFINE_EMPTY_HANDLER(DStaticEventHandler, PlayerDisconnected)
|
||||
|
||||
DEFINE_ACTION_FUNCTION(DStaticEventHandler, GetOrder)
|
||||
{
|
||||
PARAM_SELF_PROLOGUE(DStaticEventHandler);
|
||||
|
|
@ -505,6 +540,7 @@ static DWorldEvent* E_SetupWorldEvent()
|
|||
static DWorldEvent* e = nullptr;
|
||||
if (!e) e = (DWorldEvent*)RUNTIME_CLASS(DWorldEvent)->CreateNew();
|
||||
e->IsSaveGame = savegamerestore;
|
||||
e->IsReopen = level.FromSnapshot;
|
||||
e->Thing = nullptr;
|
||||
e->Inflictor = nullptr;
|
||||
e->Damage = 0;
|
||||
|
|
@ -669,6 +705,71 @@ void DStaticEventHandler::RenderFrame()
|
|||
}
|
||||
}
|
||||
|
||||
static DPlayerEvent* E_SetupPlayerEvent()
|
||||
{
|
||||
static DPlayerEvent* e = nullptr;
|
||||
if (!e) e = (DPlayerEvent*)RUNTIME_CLASS(DPlayerEvent)->CreateNew();
|
||||
e->PlayerNumber = -1;
|
||||
e->IsReturn = level.FromSnapshot;
|
||||
return e;
|
||||
}
|
||||
|
||||
void DStaticEventHandler::PlayerEntered(int num)
|
||||
{
|
||||
IFVIRTUAL(DStaticEventHandler, PlayerEntered)
|
||||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (func == DStaticEventHandler_PlayerEntered_VMPtr)
|
||||
return;
|
||||
DPlayerEvent* e = E_SetupPlayerEvent();
|
||||
e->PlayerNumber = num;
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, e };
|
||||
GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void DStaticEventHandler::PlayerRespawned(int num)
|
||||
{
|
||||
IFVIRTUAL(DStaticEventHandler, PlayerRespawned)
|
||||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (func == DStaticEventHandler_PlayerRespawned_VMPtr)
|
||||
return;
|
||||
DPlayerEvent* e = E_SetupPlayerEvent();
|
||||
e->PlayerNumber = num;
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, e };
|
||||
GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void DStaticEventHandler::PlayerDied(int num)
|
||||
{
|
||||
IFVIRTUAL(DStaticEventHandler, PlayerDied)
|
||||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (func == DStaticEventHandler_PlayerDied_VMPtr)
|
||||
return;
|
||||
DPlayerEvent* e = E_SetupPlayerEvent();
|
||||
e->PlayerNumber = num;
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, e };
|
||||
GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void DStaticEventHandler::PlayerDisconnected(int num)
|
||||
{
|
||||
IFVIRTUAL(DStaticEventHandler, PlayerDisconnected)
|
||||
{
|
||||
// don't create excessive DObjects if not going to be processed anyway
|
||||
if (func == DStaticEventHandler_PlayerDisconnected_VMPtr)
|
||||
return;
|
||||
DPlayerEvent* e = E_SetupPlayerEvent();
|
||||
e->PlayerNumber = num;
|
||||
VMValue params[2] = { (DStaticEventHandler*)this, e };
|
||||
GlobalVMStack.Call(func, params, 2, nullptr, 0, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void DStaticEventHandler::OnDestroy()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue