2017-01-22 00:33:53 +00:00
|
|
|
#ifndef EVENTS_H
|
|
|
|
#define EVENTS_H
|
|
|
|
|
|
|
|
#include "dobject.h"
|
2017-01-23 21:05:51 +00:00
|
|
|
#include "serializer.h"
|
2017-02-03 10:28:40 +00:00
|
|
|
#include "d_event.h"
|
|
|
|
#include "d_gui.h"
|
2017-01-22 00:33:53 +00:00
|
|
|
|
2017-01-22 06:56:57 +00:00
|
|
|
class DStaticEventHandler;
|
2017-01-22 05:04:35 +00:00
|
|
|
|
|
|
|
// register
|
2017-01-22 06:56:57 +00:00
|
|
|
bool E_RegisterHandler(DStaticEventHandler* handler);
|
2017-01-22 05:04:35 +00:00
|
|
|
// unregister
|
2017-01-22 06:56:57 +00:00
|
|
|
bool E_UnregisterHandler(DStaticEventHandler* handler);
|
|
|
|
// find
|
|
|
|
bool E_CheckHandler(DStaticEventHandler* handler);
|
2017-01-22 07:36:39 +00:00
|
|
|
// check type
|
|
|
|
bool E_IsStaticType(PClass* type);
|
|
|
|
// init static handlers
|
|
|
|
void E_InitStaticHandlers(bool map);
|
2017-02-03 11:01:15 +00:00
|
|
|
// shutdown handlers
|
|
|
|
void E_Shutdown(bool map);
|
2017-01-22 05:04:35 +00:00
|
|
|
|
|
|
|
// called right after the map has loaded (approximately same time as OPEN ACS scripts)
|
2017-01-23 22:17:12 +00:00
|
|
|
void E_WorldLoaded();
|
2017-01-22 05:04:35 +00:00
|
|
|
// called when the map is about to unload (approximately same time as UNLOADING ACS scripts)
|
2017-01-30 06:47:15 +00:00
|
|
|
void E_WorldUnloaded();
|
2017-01-23 22:17:12 +00:00
|
|
|
// called right after the map has loaded (every time, UNSAFE VERSION)
|
|
|
|
void E_WorldLoadedUnsafe();
|
|
|
|
// called right before the map is unloaded (every time, UNSAFE VERSION)
|
2017-01-30 06:47:15 +00:00
|
|
|
void E_WorldUnloadedUnsafe();
|
|
|
|
// called around PostBeginPlay of each actor.
|
|
|
|
void E_WorldThingSpawned(AActor* actor);
|
2017-01-31 00:07:00 +00:00
|
|
|
// called after AActor::Die of each actor.
|
|
|
|
void E_WorldThingDied(AActor* actor, AActor* inflictor);
|
2017-01-31 02:11:09 +00:00
|
|
|
// called after AActor::Revive.
|
|
|
|
void E_WorldThingRevived(AActor* actor);
|
2017-01-31 02:35:44 +00:00
|
|
|
// called before P_DamageMobj and before AActor::DamageMobj virtuals.
|
|
|
|
void E_WorldThingDamaged(AActor* actor, AActor* inflictor, AActor* source, int damage, FName mod, int flags, DAngle angle);
|
2017-01-31 00:07:00 +00:00
|
|
|
// called before AActor::Destroy of each actor.
|
|
|
|
void E_WorldThingDestroyed(AActor* actor);
|
|
|
|
// same as ACS SCRIPT_Lightning
|
|
|
|
void E_WorldLightning();
|
2017-01-31 01:24:38 +00:00
|
|
|
// this executes on every tick, before everything
|
|
|
|
void E_WorldTick();
|
2017-01-22 05:04:35 +00:00
|
|
|
// called on each render frame once.
|
|
|
|
void E_RenderFrame();
|
2017-02-03 11:29:17 +00:00
|
|
|
// called after everything's been rendered, but before console/menus
|
|
|
|
void E_RenderOverlay();
|
2017-02-02 18:26:56 +00:00
|
|
|
// this executes when a player enters the level (once). PlayerEnter+inhub = RETURN
|
2017-02-02 18:46:10 +00:00
|
|
|
void E_PlayerEntered(int num, bool fromhub);
|
2017-02-02 18:26:56 +00:00
|
|
|
// this executes when a player respawns. includes resurrect cheat.
|
|
|
|
void E_PlayerRespawned(int num);
|
|
|
|
// this executes when a player dies (partially duplicating worldthingdied, but whatever)
|
|
|
|
void E_PlayerDied(int num);
|
|
|
|
// this executes when a player leaves the game
|
|
|
|
void E_PlayerDisconnected(int num);
|
2017-02-03 10:28:40 +00:00
|
|
|
// this executes on events.
|
|
|
|
bool E_Responder(event_t* ev); // splits events into InputProcess and UiProcess
|
2017-02-06 13:52:20 +00:00
|
|
|
// this executes on console/net events.
|
2017-03-06 09:25:30 +00:00
|
|
|
void E_Console(int player, FString name, int arg1, int arg2, int arg3, bool manual);
|
2017-02-03 10:28:40 +00:00
|
|
|
|
2017-03-03 22:57:41 +00:00
|
|
|
// send networked event. unified function.
|
2017-03-06 09:25:30 +00:00
|
|
|
bool E_SendNetworkEvent(FString name, int arg1, int arg2, int arg3, bool manual);
|
2017-03-03 22:57:41 +00:00
|
|
|
|
2017-02-03 10:28:40 +00:00
|
|
|
// check if there is anything that should receive GUI events
|
|
|
|
bool E_CheckUiProcessors();
|
2017-02-03 18:34:34 +00:00
|
|
|
// check if we need native mouse due to UiProcessors
|
|
|
|
bool E_CheckRequireMouse();
|
2017-01-23 21:05:51 +00:00
|
|
|
|
|
|
|
// serialization stuff
|
|
|
|
void E_SerializeEvents(FSerializer& arc);
|
2017-01-22 05:04:35 +00:00
|
|
|
|
2017-01-30 06:47:15 +00:00
|
|
|
// ==============================================
|
|
|
|
//
|
|
|
|
// EventHandler - base class
|
|
|
|
//
|
|
|
|
// ==============================================
|
|
|
|
|
2017-01-22 06:56:57 +00:00
|
|
|
class DStaticEventHandler : public DObject // make it a part of normal GC process
|
2017-01-22 00:33:53 +00:00
|
|
|
{
|
2017-02-26 09:58:22 +00:00
|
|
|
DECLARE_CLASS(DStaticEventHandler, DObject);
|
2017-02-09 13:35:45 +00:00
|
|
|
HAS_OBJECT_POINTERS
|
2017-01-22 00:33:53 +00:00
|
|
|
public:
|
2017-01-30 05:50:09 +00:00
|
|
|
DStaticEventHandler()
|
|
|
|
{
|
|
|
|
prev = 0;
|
|
|
|
next = 0;
|
2017-02-03 10:28:40 +00:00
|
|
|
Order = 0;
|
|
|
|
IsUiProcessor = false;
|
2017-01-30 05:50:09 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 06:56:57 +00:00
|
|
|
DStaticEventHandler* prev;
|
|
|
|
DStaticEventHandler* next;
|
|
|
|
virtual bool IsStatic() { return true; }
|
2017-01-22 00:33:53 +00:00
|
|
|
|
2017-02-03 10:28:40 +00:00
|
|
|
//
|
|
|
|
int Order;
|
|
|
|
bool IsUiProcessor;
|
2017-02-03 18:34:34 +00:00
|
|
|
bool RequireMouse;
|
2017-02-02 17:57:00 +00:00
|
|
|
|
2017-01-23 22:17:12 +00:00
|
|
|
// serialization handler. let's keep it here so that I don't get lost in serialized/not serialized fields
|
|
|
|
void Serialize(FSerializer& arc) override
|
|
|
|
{
|
|
|
|
Super::Serialize(arc);
|
2017-02-09 13:35:45 +00:00
|
|
|
/*
|
2017-01-23 22:17:12 +00:00
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
Printf("DStaticEventHandler::Serialize: reading object %s\n", GetClass()->TypeName.GetChars());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf("DStaticEventHandler::Serialize: store object %s\n", GetClass()->TypeName.GetChars());
|
|
|
|
}
|
2017-02-09 13:35:45 +00:00
|
|
|
*/
|
2017-02-03 10:28:40 +00:00
|
|
|
|
|
|
|
arc("Order", Order);
|
|
|
|
arc("IsUiProcessor", IsUiProcessor);
|
2017-02-03 18:34:34 +00:00
|
|
|
arc("RequireMouse", RequireMouse);
|
2017-01-23 22:17:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 00:33:53 +00:00
|
|
|
// destroy handler. this unlinks EventHandler from the list automatically.
|
|
|
|
void OnDestroy() override;
|
|
|
|
|
2017-02-02 18:26:56 +00:00
|
|
|
//
|
2017-02-03 10:28:40 +00:00
|
|
|
void OnRegister(); // you can set order and IsUi here.
|
|
|
|
void OnUnregister();
|
|
|
|
|
|
|
|
//
|
|
|
|
void WorldLoaded();
|
|
|
|
void WorldUnloaded();
|
|
|
|
void WorldThingSpawned(AActor*);
|
|
|
|
void WorldThingDied(AActor*, AActor*);
|
|
|
|
void WorldThingRevived(AActor*);
|
|
|
|
void WorldThingDamaged(AActor*, AActor*, AActor*, int, FName, int, DAngle);
|
|
|
|
void WorldThingDestroyed(AActor*);
|
|
|
|
void WorldLightning();
|
|
|
|
void WorldTick();
|
2017-02-02 18:26:56 +00:00
|
|
|
|
|
|
|
//
|
2017-02-03 10:28:40 +00:00
|
|
|
void RenderFrame();
|
2017-02-03 11:29:17 +00:00
|
|
|
void RenderOverlay();
|
2017-02-02 17:57:00 +00:00
|
|
|
|
2017-02-02 18:26:56 +00:00
|
|
|
//
|
2017-02-03 10:28:40 +00:00
|
|
|
void PlayerEntered(int num, bool fromhub);
|
|
|
|
void PlayerRespawned(int num);
|
|
|
|
void PlayerDied(int num);
|
|
|
|
void PlayerDisconnected(int num);
|
2017-02-02 18:26:56 +00:00
|
|
|
|
2017-02-03 10:28:40 +00:00
|
|
|
// return true if handled.
|
2017-02-06 13:52:20 +00:00
|
|
|
bool InputProcess(event_t* ev);
|
|
|
|
bool UiProcess(event_t* ev);
|
|
|
|
|
|
|
|
//
|
2017-03-06 09:25:30 +00:00
|
|
|
void ConsoleProcess(int player, FString name, int arg1, int arg2, int arg3, bool manual);
|
2017-01-22 00:33:53 +00:00
|
|
|
};
|
2017-01-22 06:56:57 +00:00
|
|
|
class DEventHandler : public DStaticEventHandler
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DEventHandler, DStaticEventHandler) // TODO: make sure this does not horribly break anything
|
|
|
|
public:
|
|
|
|
bool IsStatic() override { return false; }
|
|
|
|
};
|
|
|
|
extern DStaticEventHandler* E_FirstEventHandler;
|
2017-02-24 18:00:10 +00:00
|
|
|
extern DStaticEventHandler* E_LastEventHandler;
|
2017-01-22 00:33:53 +00:00
|
|
|
|
2017-01-30 23:28:47 +00:00
|
|
|
// we cannot call this DEvent because in ZScript, 'event' is a keyword
|
|
|
|
class DBaseEvent : public DObject
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DBaseEvent, DObject)
|
|
|
|
public:
|
2017-01-30 06:47:15 +00:00
|
|
|
|
2017-01-30 23:28:47 +00:00
|
|
|
DBaseEvent()
|
|
|
|
{
|
|
|
|
// each type of event is created only once to avoid new/delete hell
|
|
|
|
// since from what I remember object creation and deletion results in a lot of GC processing
|
|
|
|
// (and we aren't supposed to pass event objects around anyway)
|
|
|
|
this->ObjectFlags |= OF_Fixed;
|
2017-01-31 02:02:55 +00:00
|
|
|
// we don't want to store events into the savegames because they are global.
|
|
|
|
this->ObjectFlags |= OF_Transient;
|
2017-01-30 23:28:47 +00:00
|
|
|
}
|
|
|
|
};
|
2017-01-30 06:47:15 +00:00
|
|
|
|
2017-01-30 23:28:47 +00:00
|
|
|
class DRenderEvent : public DBaseEvent
|
2017-01-22 00:33:53 +00:00
|
|
|
{
|
2017-01-30 23:28:47 +00:00
|
|
|
DECLARE_CLASS(DRenderEvent, DBaseEvent)
|
2017-01-22 00:33:53 +00:00
|
|
|
public:
|
2017-01-22 05:04:35 +00:00
|
|
|
// these are for all render events
|
2017-01-22 00:33:53 +00:00
|
|
|
DVector3 ViewPos;
|
|
|
|
DAngle ViewAngle;
|
|
|
|
DAngle ViewPitch;
|
|
|
|
DAngle ViewRoll;
|
|
|
|
double FracTic; // 0..1 value that describes where we are inside the current gametic, render-wise.
|
2017-01-22 05:04:35 +00:00
|
|
|
AActor* Camera;
|
2017-01-22 00:33:53 +00:00
|
|
|
|
2017-01-30 23:28:47 +00:00
|
|
|
DRenderEvent()
|
2017-01-30 06:47:15 +00:00
|
|
|
{
|
|
|
|
FracTic = 0;
|
|
|
|
Camera = nullptr;
|
|
|
|
}
|
2017-01-22 06:56:57 +00:00
|
|
|
};
|
2017-01-22 00:33:53 +00:00
|
|
|
|
2017-01-30 23:28:47 +00:00
|
|
|
class DWorldEvent : public DBaseEvent
|
2017-01-30 06:47:15 +00:00
|
|
|
{
|
2017-01-30 23:28:47 +00:00
|
|
|
DECLARE_CLASS(DWorldEvent, DBaseEvent)
|
2017-01-30 06:47:15 +00:00
|
|
|
public:
|
2017-01-30 23:28:47 +00:00
|
|
|
// for loaded/unloaded
|
|
|
|
bool IsSaveGame;
|
2017-02-02 18:26:56 +00:00
|
|
|
bool IsReopen;
|
2017-01-30 23:28:47 +00:00
|
|
|
// for thingspawned, thingdied, thingdestroyed
|
2017-01-30 06:47:15 +00:00
|
|
|
AActor* Thing;
|
2017-01-31 00:07:00 +00:00
|
|
|
// for thingdied
|
|
|
|
AActor* Inflictor; // can be null
|
2017-01-31 02:35:44 +00:00
|
|
|
// for damagemobj
|
|
|
|
int Damage;
|
|
|
|
AActor* DamageSource; // can be null
|
|
|
|
FName DamageType;
|
|
|
|
int DamageFlags;
|
|
|
|
DAngle DamageAngle;
|
2017-01-30 06:47:15 +00:00
|
|
|
|
2017-01-30 23:28:47 +00:00
|
|
|
DWorldEvent()
|
2017-01-30 06:47:15 +00:00
|
|
|
{
|
|
|
|
IsSaveGame = false;
|
2017-02-02 18:26:56 +00:00
|
|
|
IsReopen = false;
|
2017-01-30 06:47:15 +00:00
|
|
|
Thing = nullptr;
|
2017-01-31 00:07:00 +00:00
|
|
|
Inflictor = nullptr;
|
2017-01-31 02:35:44 +00:00
|
|
|
Damage = 0;
|
|
|
|
DamageSource = nullptr;
|
|
|
|
DamageFlags = 0;
|
2017-01-30 06:47:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-02 18:26:56 +00:00
|
|
|
class DPlayerEvent : public DBaseEvent
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DPlayerEvent, DBaseEvent)
|
|
|
|
public:
|
|
|
|
// we currently have only one member: player index
|
|
|
|
// in ZScript, we have global players[] array from which we can
|
|
|
|
// get both the player itself and player's body,
|
|
|
|
// so no need to pass it here.
|
|
|
|
int PlayerNumber;
|
|
|
|
// we set this to true if level was reopened (RETURN scripts)
|
|
|
|
bool IsReturn;
|
|
|
|
|
|
|
|
DPlayerEvent()
|
|
|
|
{
|
|
|
|
PlayerNumber = -1;
|
|
|
|
IsReturn = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-03 10:28:40 +00:00
|
|
|
class DUiEvent : public DBaseEvent
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DUiEvent, DBaseEvent)
|
|
|
|
public:
|
|
|
|
// this essentially translates event_t UI events to ZScript.
|
|
|
|
EGUIEvent Type;
|
|
|
|
// for keys/chars/whatever
|
|
|
|
FString KeyString;
|
|
|
|
int KeyChar;
|
|
|
|
// for mouse
|
|
|
|
int MouseX;
|
|
|
|
int MouseY;
|
|
|
|
// global (?)
|
|
|
|
bool IsShift;
|
|
|
|
bool IsCtrl;
|
|
|
|
bool IsAlt;
|
|
|
|
|
|
|
|
DUiEvent()
|
|
|
|
{
|
|
|
|
Type = EV_GUI_None;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DInputEvent : public DBaseEvent
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DInputEvent, DBaseEvent)
|
|
|
|
public:
|
|
|
|
// this translates regular event_t events to ZScript (not UI, UI events are sent via DUiEvent and only if requested!)
|
|
|
|
EGenericEvent Type;
|
|
|
|
// for keys
|
|
|
|
int KeyScan;
|
|
|
|
FString KeyString;
|
|
|
|
int KeyChar;
|
|
|
|
// for mouse
|
|
|
|
int MouseX;
|
|
|
|
int MouseY;
|
|
|
|
|
|
|
|
DInputEvent()
|
|
|
|
{
|
|
|
|
Type = EV_None;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-06 13:52:20 +00:00
|
|
|
class DConsoleEvent : public DBaseEvent
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DConsoleEvent, DBaseEvent)
|
|
|
|
public:
|
|
|
|
// player that activated this event. note that it's always -1 for non-playsim events (i.e. these not called with netevent)
|
|
|
|
int Player;
|
|
|
|
//
|
|
|
|
FString Name;
|
|
|
|
int Args[3];
|
2017-03-06 09:25:30 +00:00
|
|
|
//
|
|
|
|
bool IsManual;
|
2017-02-06 13:52:20 +00:00
|
|
|
|
|
|
|
DConsoleEvent()
|
|
|
|
{
|
|
|
|
Player = -1;
|
2017-03-06 09:25:30 +00:00
|
|
|
IsManual = false;
|
2017-02-06 13:52:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-22 00:33:53 +00:00
|
|
|
#endif
|