-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfhooks.cpp
78 lines (68 loc) · 2.2 KB
/
dfhooks.cpp
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
#include "ChainLoader.h"
#include <cstddef>
#include <iostream>
#ifdef WIN32
#define DFhackCExport extern "C" __declspec(dllexport)
#define DFhackDataExport extern "C" __declspec(dllexport)
#else
#define DFhackCExport extern "C" __attribute__ ((visibility("default")))
#define DFhackDataExport __attribute__ ((visibility("default")))
#endif
static ChainLoader * chain = NULL;
// called from the main thread before the simulation thread is started
// and the main event loop is initiated
DFhackCExport void dfhooks_init() {
// don't initialize if already initialized
if (chain)
return;
try {
chain = new ChainLoader();
chain->init();
} catch (std::exception& e) {
std::cerr << "Failed to load dfhooks libraries:" << e.what() << std::endl;
}
}
// called from the main thread after the main event loops exits
DFhackCExport void dfhooks_shutdown() {
if (!chain)
return;
chain->shutdown();
delete chain;
chain = NULL;
}
// called from the simulation thread in the main event loop
DFhackCExport void dfhooks_update() {
if (!chain)
return;
chain->update();
}
// called from the simulation thread just before adding the macro
// recording/playback overlay
DFhackCExport void dfhooks_prerender() {
if (!chain)
return;
chain->prerender();
}
// called from the main thread for each SDL event. if true is returned, then
// the event has been consumed and further processing shouldn't happen
DFhackCExport bool dfhooks_sdl_event(SDL_Event* event) {
if (!chain)
return false;
return chain->sdl_event(event);
}
// called from the main thread just after setting mouse state in gps and just
// before rendering the screen buffer to the screen.
DFhackCExport void dfhooks_sdl_loop() {
if (!chain)
return;
chain->sdl_loop();
}
// called from the main thread for each utf-8 char read from the ncurses input
// key is positive for ncurses keys and negative for everything else
// if true is returned, then the event has been consumed and further processing
// shouldn't happen
DFhackCExport bool dfhooks_ncurses_key(int key) {
if (!chain)
return false;
return chain->ncurses_key(key);
}