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-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-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-22 05:04:35 +00:00
|
|
|
// called on each render frame once.
|
|
|
|
void E_RenderFrame();
|
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-01-22 06:56:57 +00:00
|
|
|
DECLARE_CLASS(DStaticEventHandler, DObject)
|
2017-01-22 00:33:53 +00:00
|
|
|
public:
|
2017-01-30 05:50:09 +00:00
|
|
|
DStaticEventHandler()
|
|
|
|
{
|
|
|
|
prev = 0;
|
|
|
|
next = 0;
|
2017-01-30 06:19:38 +00:00
|
|
|
isMapScope = false;
|
2017-01-30 05:50:09 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 06:56:57 +00:00
|
|
|
DStaticEventHandler* prev;
|
|
|
|
DStaticEventHandler* next;
|
2017-01-30 06:19:38 +00:00
|
|
|
bool isMapScope;
|
2017-01-22 06:56:57 +00:00
|
|
|
virtual bool IsStatic() { return true; }
|
2017-01-22 00:33:53 +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);
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
|
|
|
Printf("DStaticEventHandler::Serialize: reading object %s\n", GetClass()->TypeName.GetChars());
|
2017-01-30 06:19:38 +00:00
|
|
|
isMapScope = true; // unserialized static handler means map scope anyway. other handlers don't get serialized.
|
2017-01-23 22:17:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf("DStaticEventHandler::Serialize: store object %s\n", GetClass()->TypeName.GetChars());
|
|
|
|
}
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
|
2017-01-22 00:33:53 +00:00
|
|
|
// destroy handler. this unlinks EventHandler from the list automatically.
|
|
|
|
void OnDestroy() override;
|
|
|
|
|
2017-01-23 22:17:12 +00:00
|
|
|
virtual void WorldLoaded();
|
2017-01-30 06:47:15 +00:00
|
|
|
virtual void WorldUnloaded();
|
|
|
|
virtual void WorldThingSpawned(AActor*);
|
2017-01-22 00:33:53 +00:00
|
|
|
virtual void RenderFrame();
|
|
|
|
};
|
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-01-22 00:33:53 +00:00
|
|
|
|
2017-01-30 06:47:15 +00:00
|
|
|
|
|
|
|
// ==============================================
|
|
|
|
//
|
|
|
|
// RenderEventHandler - for renderer events
|
|
|
|
//
|
|
|
|
// ==============================================
|
|
|
|
|
2017-01-22 06:56:57 +00:00
|
|
|
class DStaticRenderEventHandler : public DStaticEventHandler
|
2017-01-22 00:33:53 +00:00
|
|
|
{
|
2017-01-22 06:56:57 +00:00
|
|
|
DECLARE_CLASS(DStaticRenderEventHandler, DStaticEventHandler)
|
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 06:47:15 +00:00
|
|
|
DStaticRenderEventHandler()
|
|
|
|
{
|
|
|
|
FracTic = 0;
|
|
|
|
Camera = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-23 22:17:12 +00:00
|
|
|
// serialization handler for our local stuff
|
|
|
|
void Serialize(FSerializer& arc) override
|
|
|
|
{
|
|
|
|
Super::Serialize(arc);
|
|
|
|
arc("ViewPos", ViewPos);
|
|
|
|
arc("ViewAngle", ViewAngle);
|
|
|
|
arc("ViewPitch", ViewPitch);
|
|
|
|
arc("ViewRoll", ViewRoll);
|
|
|
|
arc("FracTic", FracTic);
|
|
|
|
arc("Camera", Camera);
|
|
|
|
}
|
|
|
|
|
2017-01-22 00:33:53 +00:00
|
|
|
void RenderFrame() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Setup();
|
|
|
|
};
|
2017-01-22 06:56:57 +00:00
|
|
|
class DRenderEventHandler : public DStaticRenderEventHandler
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DRenderEventHandler, DStaticRenderEventHandler) // TODO: make sure this does not horribly break anythings
|
|
|
|
public:
|
|
|
|
bool IsStatic() override { return false; }
|
|
|
|
};
|
2017-01-22 00:33:53 +00:00
|
|
|
|
2017-01-30 06:47:15 +00:00
|
|
|
// ==============================================
|
|
|
|
//
|
|
|
|
// WorldEventHandler - for world events
|
|
|
|
//
|
|
|
|
// ==============================================
|
|
|
|
class DStaticWorldEventHandler : public DStaticEventHandler
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DStaticWorldEventHandler, DStaticEventHandler)
|
|
|
|
public:
|
|
|
|
// for WorldLoaded, WorldUnloaded.
|
|
|
|
bool IsSaveGame; // this will be true if world event was triggered during savegame loading.
|
|
|
|
// for WorldThingSpawned
|
|
|
|
AActor* Thing;
|
|
|
|
|
|
|
|
DStaticWorldEventHandler()
|
|
|
|
{
|
|
|
|
IsSaveGame = false;
|
|
|
|
Thing = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Serialize(FSerializer& arc) override
|
|
|
|
{
|
|
|
|
Super::Serialize(arc);
|
|
|
|
arc("IsSaveGame", IsSaveGame);
|
|
|
|
arc("Thing", Thing);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WorldLoaded() override;
|
|
|
|
void WorldUnloaded() override;
|
|
|
|
void WorldThingSpawned(AActor*) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Setup();
|
|
|
|
};
|
|
|
|
// not sure if anyone wants non-static world handler, but here it is, just in case.
|
|
|
|
class DWorldEventHandler : public DStaticWorldEventHandler
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DWorldEventHandler, DStaticWorldEventHandler)
|
|
|
|
public:
|
|
|
|
bool IsStatic() override { return false; }
|
|
|
|
};
|
|
|
|
|
2017-01-22 00:33:53 +00:00
|
|
|
#endif
|