forked from OpenApoc/OpenApoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
framework.h
121 lines (94 loc) · 2.74 KB
/
framework.h
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
#pragma once
#include "library/sp.h"
#include "library/strings.h"
#include "library/vec.h"
#include <functional>
#include <future>
namespace OpenApoc
{
class Shader;
class GameCore;
class FrameworkPrivate;
class ApocCursor;
class Event;
class Image;
class Data;
class Renderer;
class SoundBackend;
class JukeBox;
class StageCmd;
class Stage;
class RGBImage;
#define FRAMES_PER_SECOND 100
class Framework
{
private:
up<FrameworkPrivate> p;
UString programName;
bool createWindow;
void audioInitialise();
void audioShutdown();
static Framework *instance;
up<ApocCursor> cursor;
std::list<StageCmd> stageCommands;
public:
std::unique_ptr<Data> data;
std::unique_ptr<Renderer> renderer;
std::unique_ptr<SoundBackend> soundBackend;
std::unique_ptr<JukeBox> jukebox;
Framework(const UString programName, bool createWindow = true);
~Framework();
static Framework &getInstance();
static Framework *tryGetInstance();
void run(sp<Stage> initialStage);
void processEvents();
/* PushEvent() take ownership of the Event, and will delete it after use*/
void pushEvent(up<Event> e);
void pushEvent(Event *e);
void translateSdlEvents();
void shutdownFramework();
bool isShuttingDown();
void displayInitialise();
void displayShutdown();
int displayGetWidth();
int displayGetHeight();
Vec2<int> displayGetSize();
void displaySetTitle(UString NewTitle);
void displaySetIcon(sp<RGBImage> icon);
bool displayHasWindow() const;
bool isSlowMode();
void setSlowMode(bool SlowEnabled);
sp<Stage> stageGetCurrent();
sp<Stage> stageGetPrevious();
sp<Stage> stageGetPrevious(sp<Stage> From);
void stageQueueCommand(const StageCmd &cmd);
ApocCursor &getCursor();
void textStartInput();
void textStopInput();
void toolTipStartTimer(up<Event> e);
void toolTipStopTimer();
void toolTipTimerCallback(unsigned int interval, void *data);
void showToolTip(sp<Image> image, const Vec2<int> &position);
UString textGetClipboard();
void threadPoolTaskEnqueue(std::function<void()> task);
// add new work item to the pool
template <class F, class... Args>
auto threadPoolEnqueue(F &&f, Args &&... args)
-> std::shared_future<typename std::result_of<F(Args...)>::type>
{
using return_type = typename std::result_of<F(Args...)>::type;
auto task = std::make_shared<std::packaged_task<return_type()>>(
std::bind(std::forward<F>(f), std::forward<Args>(args)...));
std::shared_future<return_type> res = task->get_future().share();
this->threadPoolTaskEnqueue([task, res]() {
(*task)();
// Without a future.get() any exceptions are dropped on the floor
res.get();
});
return res;
}
UString getDataDir() const;
UString getCDPath() const;
};
static inline Framework &fw() { return Framework::getInstance(); }
}; // namespace OpenApoc