Add "headless" mode, use in travis

develop
lethosor 2018-02-03 23:59:01 -05:00
parent 78c60e249e
commit 638f0ab35a
2 changed files with 24 additions and 2 deletions

@ -31,6 +31,7 @@ before_install:
- pip install --user "sphinx==1.4" "requests[security]" - pip install --user "sphinx==1.4" "requests[security]"
- sh travis/build-lua.sh - sh travis/build-lua.sh
- sh travis/download-df.sh - sh travis/download-df.sh
- echo "export DFHACK_HEADLESS=1" >> "$HOME/.dfhackrc"
script: script:
- export PATH="$PATH:$HOME/lua53/bin" - export PATH="$PATH:$HOME/lua53/bin"
- git tag tmp-travis-build - git tag tmp-travis-build

@ -81,6 +81,10 @@ using namespace DFHack;
#include "SDL_events.h" #include "SDL_events.h"
#ifdef LINUX_BUILD
#include <dlfcn.h>
#endif
using namespace tthread; using namespace tthread;
using namespace df::enums; using namespace df::enums;
using df::global::init; using df::global::init;
@ -1638,7 +1642,24 @@ bool Core::Init()
cerr << "Initializing Console.\n"; cerr << "Initializing Console.\n";
// init the console. // init the console.
bool is_text_mode = (init && init->display.flag.is_set(init_display_flags::TEXT)); bool is_text_mode = (init && init->display.flag.is_set(init_display_flags::TEXT));
if (is_text_mode || getenv("DFHACK_DISABLE_CONSOLE")) bool is_headless = bool(getenv("DFHACK_HEADLESS"));
if (is_headless)
{
#ifdef LINUX_BUILD
auto endwin = (int(*)(void))dlsym(RTLD_DEFAULT, "endwin");
if (endwin)
{
endwin();
}
else
{
cerr << "endwin(): bind failed" << endl;
}
#else
cerr << "Headless mode not supported on Windows" << endl;
#endif
}
if ((is_text_mode && !is_headless) || getenv("DFHACK_DISABLE_CONSOLE"))
{ {
con.init(true); con.init(true);
cerr << "Console is not available. Use dfhack-run to send commands.\n"; cerr << "Console is not available. Use dfhack-run to send commands.\n";
@ -1718,7 +1739,7 @@ bool Core::Init()
HotkeyMutex = new mutex(); HotkeyMutex = new mutex();
HotkeyCond = new condition_variable(); HotkeyCond = new condition_variable();
if (!is_text_mode) if (!is_text_mode || is_headless)
{ {
cerr << "Starting IO thread.\n"; cerr << "Starting IO thread.\n";
// create IO thread // create IO thread