2022-12-23 20:05:00 -07:00
|
|
|
#include "Core.h"
|
|
|
|
#include "Export.h"
|
|
|
|
|
2023-05-15 18:33:57 -06:00
|
|
|
#include "df/gamest.h"
|
|
|
|
|
|
|
|
static bool disabled = false;
|
|
|
|
|
2023-04-13 01:40:10 -06:00
|
|
|
// called from the main thread before the simulation thread is started
|
|
|
|
// and the main event loop is initiated
|
2022-12-23 20:05:00 -07:00
|
|
|
DFhackCExport void dfhooks_init() {
|
2023-05-15 19:15:46 -06:00
|
|
|
if (getenv("DFHACK_DISABLE")) {
|
|
|
|
fprintf(stdout, "dfhack: DFHACK_DISABLE detected in environment; disabling\n");
|
|
|
|
disabled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we need to init DF globals before we can check the commandline
|
2023-05-15 18:33:57 -06:00
|
|
|
if (!DFHack::Core::getInstance().InitMainThread() || !df::global::game)
|
|
|
|
return;
|
|
|
|
const std::string & cmdline = df::global::game->command_line.original;
|
|
|
|
if (cmdline.find("--disable-dfhack") != std::string::npos) {
|
|
|
|
fprintf(stdout, "dfhack: --disable-dfhack specified on commandline; disabling\n");
|
|
|
|
disabled = true;
|
|
|
|
}
|
2022-12-23 20:05:00 -07:00
|
|
|
}
|
|
|
|
|
2023-04-13 01:40:10 -06:00
|
|
|
// called from the main thread after the main event loops exits
|
2022-12-23 20:05:00 -07:00
|
|
|
DFhackCExport void dfhooks_shutdown() {
|
2023-05-15 18:33:57 -06:00
|
|
|
if (disabled)
|
|
|
|
return;
|
2022-12-23 20:05:00 -07:00
|
|
|
DFHack::Core::getInstance().Shutdown();
|
|
|
|
}
|
|
|
|
|
2023-04-13 01:40:10 -06:00
|
|
|
// called from the simulation thread in the main event loop
|
2022-12-23 20:05:00 -07:00
|
|
|
DFhackCExport void dfhooks_update() {
|
2023-05-15 18:33:57 -06:00
|
|
|
if (disabled)
|
|
|
|
return;
|
2022-12-23 20:05:00 -07:00
|
|
|
DFHack::Core::getInstance().Update();
|
|
|
|
}
|
|
|
|
|
2023-04-13 01:40:10 -06:00
|
|
|
// called from the simulation thread just before adding the macro
|
|
|
|
// recording/playback overlay
|
2022-12-23 20:05:00 -07:00
|
|
|
DFhackCExport void dfhooks_prerender() {
|
2023-05-15 18:33:57 -06:00
|
|
|
if (disabled)
|
|
|
|
return;
|
2022-12-23 20:05:00 -07:00
|
|
|
// TODO: render overlay widgets that are not attached to a viewscreen
|
|
|
|
}
|
|
|
|
|
2023-04-13 01:40:10 -06:00
|
|
|
// 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
|
2022-12-23 20:05:00 -07:00
|
|
|
DFhackCExport bool dfhooks_sdl_event(SDL::Event* event) {
|
2023-05-15 18:33:57 -06:00
|
|
|
if (disabled)
|
|
|
|
return false;
|
2022-12-23 20:05:00 -07:00
|
|
|
return DFHack::Core::getInstance().DFH_SDL_Event(event);
|
|
|
|
}
|
2023-01-04 10:57:06 -07:00
|
|
|
|
2023-04-13 01:40:10 -06:00
|
|
|
// called from the main thread for each utf-8 char read from the ncurses input
|
2022-12-23 20:05:00 -07:00
|
|
|
// key is positive for ncurses keys and negative for everything else
|
2023-01-04 10:57:06 -07:00
|
|
|
// if true is returned, then the event has been consumed and further processing
|
|
|
|
// shouldn't happen
|
2022-12-23 20:05:00 -07:00
|
|
|
DFhackCExport bool dfhooks_ncurses_key(int key) {
|
2023-05-15 18:33:57 -06:00
|
|
|
if (disabled)
|
|
|
|
return false;
|
2022-12-23 20:05:00 -07:00
|
|
|
return DFHack::Core::getInstance().DFH_ncurses_key(key);
|
|
|
|
}
|