-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.hpp
More file actions
132 lines (107 loc) · 4.08 KB
/
manager.hpp
File metadata and controls
132 lines (107 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef MANAGER_H
#define MANAGER_H
#include <Nostalgia/components/game_loop.hpp>
#include <Nostalgia/components/event_handling.hpp>
namespace ManagerEnums
{
enum TheatreState_t : int
{
NOT_IN_LEVEL,
LOADING_LEVEL,
IN_LEVEL,
SHUTTING_DOWN_LEVEL,
};
enum TheatreReturnValue_t : int
{
FUCKED,
MORE_WORK,
FINISHED,
};
}
// Basic idea taken from Valve's Source Engine, specifically the file -> (src/app/legion/gamemanager.h)
class IManager : public OnUpdate, public OnTick, public OnInput, public OnEvent
{
public:
virtual constexpr const char* DebugName() = 0;
virtual bool Init() = 0;
virtual ManagerEnums::TheatreReturnValue_t TheatreInit(bool IsFirstCall) = 0;
virtual ManagerEnums::TheatreReturnValue_t TheatreShutdown(bool IsFirstCall) = 0;
virtual void Shutdown() = 0;
virtual void OnSave() = 0;
virtual void OnRestore() = 0;
// Add/Remove managers
static void Add(IManager* ManagerToAdd);
static void Remove(IManager* ManagerToRemove);
static void RemoveAll();
// Init/Shutdown managers
static bool InitAllManagers();
static void ShutdownAllManagers();
// Start/Stop running all game managers
static void Start();
static void Stop();
static void FPSCounter(bool);
static bool FPSCounterEnabled();
static double GetFPS();
// Return the current frame or tick number
static long FrameNumber();
static long TickNumber();
// In fixed update: return current/delta time
static double FixedUpdateCurrentTime();
static double FixedUpdateDeltaTime();
// In rendering: return current/delta time
static double CurrentTime();
static double DeltaTime();
// Helpers for loading a theatre
static void StartNewTheatre();
static void ShutdownTheatre();
static ManagerEnums::TheatreState_t GetTheatreState();
protected:
static void UpdateTheatreStateMachine();
virtual ~IManager() {}
typedef ManagerEnums::TheatreReturnValue_t (IManager::*ManagerTheatreFunction_t)(bool IsFirstCall);
typedef bool (IManager::*ManagerInitFunc_t)();
typedef void (IManager::*ManagerFunc_t)();
// Go through every added manager and invoke the supplied method, in specific order (forwards or backwards)
static void InvokeInput(InputEvent*);
static void InvokeEvent(IEvent*);
static void InvokeMethod(ManagerFunc_t Function);
static void InvokeMethodReverseOrder(ManagerFunc_t Function);
static bool InvokeMethod(ManagerInitFunc_t Function);
static ManagerEnums::TheatreReturnValue_t
InvokeTheatreMethod(ManagerTheatreFunction_t Function, bool IsFirstCall);
static ManagerEnums::TheatreReturnValue_t
InvokeTheatreMethodReverseOrder(ManagerTheatreFunction_t Function, bool IsFirstCall);
static std::vector<IManager*> m_sGameManagers;
static bool m_sTheatreShutdownRequested,
m_sTheatreStartRequested,
m_sStopRequested,
m_sIsRunning,
m_sIsInitialized,
m_sCountFPS;
static long m_sFrameNumber, m_sTickNumber;
static double m_sCurrentTime, m_sLastTime, m_sFrameRate;
static ManagerEnums::TheatreState_t theatre_state;
};
class Manager : public IManager
{
public:
virtual ~Manager();
// Managers are expected to implement these methods.
virtual constexpr const char* DebugName() override { return "Manager"; };
virtual bool Init() override { return true; }
virtual void Shutdown() override {}
virtual void OnSave() override {}
virtual void OnRestore() override {}
virtual void Update() override {}
virtual void Tick() override {}
virtual void Input(InputEvent*) override {}
virtual void Event(IEvent*) override {}
virtual ManagerEnums::TheatreReturnValue_t TheatreInit(bool IsFirstCall) override
{ return ManagerEnums::FINISHED; }
virtual ManagerEnums::TheatreReturnValue_t TheatreShutdown(bool IsFirstCall) override
{ return ManagerEnums::FINISHED; }
};
// Automatically remove the game manager if it gets deleted
inline Manager::~Manager()
{ IManager::Remove(this); }
#endif // MANAGER_H