Merge branch 'develop' into myk_remote_server

develop
Myk 2023-05-17 10:21:02 -07:00 committed by GitHub
commit f265767d7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 19 deletions

@ -53,7 +53,7 @@ double quotes. To include a double quote character, use ``\"``.
If the first non-whitespace character is ``:``, the command is parsed in If the first non-whitespace character is ``:``, the command is parsed in
an alternative mode. The non-whitespace characters following the ``:`` are an alternative mode. The non-whitespace characters following the ``:`` are
the command name, and the remaining part of the line is used verbatim as the command name, and the remaining part of the line is used verbatim as
the first argument. This is very useful for the `lua` and `rb` commands. the first argument. This is very useful for the `lua` command.
As an example, the following two command lines are exactly equivalent:: As an example, the following two command lines are exactly equivalent::
:foo a b "c d" e f :foo a b "c d" e f
@ -306,6 +306,23 @@ the root DF folder.
Note that ``script-paths.txt`` is only read at startup, but the paths can also be Note that ``script-paths.txt`` is only read at startup, but the paths can also be
modified programmatically at any time through the `Lua API <lua-api-internal>`. modified programmatically at any time through the `Lua API <lua-api-internal>`.
Commandline options
===================
In addition to `Using an OS terminal`_ to execute commands on startup, DFHack
also recognizes a single commandline option that can be specified on the
commandline:
- ``--disable-dfhack``: If this option is passed on the Dwarf Fortress
commandline, then DFHack will be disabled for the session. You will have to
restart Dwarf Fortress without specifying this option in order to use DFHack.
If you are launching Dwarf Fortress from Steam, you can enter the option in
the "Launch Options" text box in the properties for the Dwarf Fortress app.
Note that if you do this, DFHack will be disabled regardless of whether you
run Dwarf Fortress from its own app or DFHack's. You will have to clear the
DF Launch Options in order to use DFHack again. Note that even if DFHack is
disabled, :file:`stdout.txt` and :file:`stderr.txt` will still be redirected
to :file:`stdout.log` and :file:`stderr.log`, respectively.
.. _env-vars: .. _env-vars:
@ -319,6 +336,11 @@ on UNIX-like systems:
DFHACK_SOME_VAR=1 ./dfhack DFHACK_SOME_VAR=1 ./dfhack
- ``DFHACK_DISABLE``: if set, DFHack will not initialize, not even to redirect
standard output or standard error. This is provided as an alternative
to the ``--disable-dfhack`` commandline parameter above for when environment
variables are more convenient.
- ``DFHACK_PORT``: the port to use for the RPC server (used by ``dfhack-run`` - ``DFHACK_PORT``: the port to use for the RPC server (used by ``dfhack-run``
and `remotefortressreader` among others) instead of the default ``5000``. As and `remotefortressreader` among others) instead of the default ``5000``. As
with the default, if this port cannot be used, the server is not started. with the default, if this port cannot be used, the server is not started.

@ -45,10 +45,12 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Fixes ## Fixes
- RemoteServer: fix crash on malformed json in ``dfhack-config/remote-server.json`` - RemoteServer: fix crash on malformed json in ``dfhack-config/remote-server.json``
- `autolabor`: work detail override warning now only appears on the work details screen
## Misc Improvements ## Misc Improvements
- Terminal console no longer appears in front of the game window on startup - Terminal console no longer appears in front of the game window on startup
- `gui/design`: Improved performance for drawing shapes - `gui/design`: Improved performance for drawing shapes
- Core: For debugging purposes, you can now pass ``--disable-dfhack`` on the Dwarf Fortress commandline or specify ``DFHACK_DISABLE=1`` in the environment to disable DFHack for the current session.
## Documentation ## Documentation

@ -1471,16 +1471,8 @@ std::string Core::getHackPath()
#endif #endif
} }
bool Core::Init() bool Core::InitMainThread() {
{ Filesystem::init();
if(started)
return true;
if(errorstate)
return false;
// Lock the CoreSuspendMutex until the thread exits or call Core::Shutdown
// Core::Update will temporary unlock when there is any commands queued
MainThread::suspend().lock();
// Re-route stdout and stderr again - DF seems to set up stdout and // Re-route stdout and stderr again - DF seems to set up stdout and
// stderr.txt on Windows as of 0.43.05. Also, log before switching files to // stderr.txt on Windows as of 0.43.05. Also, log before switching files to
@ -1496,8 +1488,6 @@ bool Core::Init()
if (!freopen("stderr.log", "w", stderr)) if (!freopen("stderr.log", "w", stderr))
std::cerr << "Could not redirect stderr to stderr.log" << std::endl; std::cerr << "Could not redirect stderr to stderr.log" << std::endl;
Filesystem::init();
std::cerr << "DFHack build: " << Version::git_description() << "\n" std::cerr << "DFHack build: " << Version::git_description() << "\n"
<< "Starting with working directory: " << Filesystem::getcwd() << std::endl; << "Starting with working directory: " << Filesystem::getcwd() << std::endl;
@ -1566,6 +1556,20 @@ bool Core::Init()
// Init global object pointers // Init global object pointers
df::global::InitGlobals(); df::global::InitGlobals();
return true;
}
bool Core::InitSimulationThread()
{
if(started)
return true;
if(errorstate)
return false;
// Lock the CoreSuspendMutex until the thread exits or call Core::Shutdown
// Core::Update will temporary unlock when there is any commands queued
MainThread::suspend().lock();
std::cerr << "Initializing Console.\n"; std::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));
@ -1965,7 +1969,7 @@ int Core::Update()
if(!started) if(!started)
{ {
// Initialize the core // Initialize the core
Init(); InitSimulationThread();
if(errorstate) if(errorstate)
return -1; return -1;
} }

@ -1,31 +1,56 @@
#include "Core.h" #include "Core.h"
#include "Export.h" #include "Export.h"
#include "df/gamest.h"
static bool disabled = false;
// called from the main thread before the simulation thread is started // called from the main thread before the simulation thread is started
// and the main event loop is initiated // and the main event loop is initiated
DFhackCExport void dfhooks_init() { DFhackCExport void dfhooks_init() {
// TODO: initialize things we need to do while still in the main thread 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
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;
}
} }
// called from the main thread after the main event loops exits // called from the main thread after the main event loops exits
DFhackCExport void dfhooks_shutdown() { DFhackCExport void dfhooks_shutdown() {
if (disabled)
return;
DFHack::Core::getInstance().Shutdown(); DFHack::Core::getInstance().Shutdown();
} }
// called from the simulation thread in the main event loop // called from the simulation thread in the main event loop
DFhackCExport void dfhooks_update() { DFhackCExport void dfhooks_update() {
if (disabled)
return;
DFHack::Core::getInstance().Update(); DFHack::Core::getInstance().Update();
} }
// called from the simulation thread just before adding the macro // called from the simulation thread just before adding the macro
// recording/playback overlay // recording/playback overlay
DFhackCExport void dfhooks_prerender() { DFhackCExport void dfhooks_prerender() {
if (disabled)
return;
// TODO: render overlay widgets that are not attached to a viewscreen // TODO: render overlay widgets that are not attached to a viewscreen
} }
// called from the main thread for each SDL event. if true is returned, then // 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 // the event has been consumed and further processing shouldn't happen
DFhackCExport bool dfhooks_sdl_event(SDL::Event* event) { DFhackCExport bool dfhooks_sdl_event(SDL::Event* event) {
if (disabled)
return false;
return DFHack::Core::getInstance().DFH_SDL_Event(event); return DFHack::Core::getInstance().DFH_SDL_Event(event);
} }
@ -34,5 +59,7 @@ DFhackCExport bool dfhooks_sdl_event(SDL::Event* event) {
// if true is returned, then the event has been consumed and further processing // if true is returned, then the event has been consumed and further processing
// shouldn't happen // shouldn't happen
DFhackCExport bool dfhooks_ncurses_key(int key) { DFhackCExport bool dfhooks_ncurses_key(int key) {
if (disabled)
return false;
return DFHack::Core::getInstance().DFH_ncurses_key(key); return DFHack::Core::getInstance().DFH_ncurses_key(key);
} }

@ -191,7 +191,8 @@ namespace DFHack
struct Private; struct Private;
std::unique_ptr<Private> d; std::unique_ptr<Private> d;
bool Init(); bool InitMainThread();
bool InitSimulationThread();
int Update (void); int Update (void);
int Shutdown (void); int Shutdown (void);
bool DFH_SDL_Event(SDL::Event* event); bool DFH_SDL_Event(SDL::Event* event);

@ -8,9 +8,9 @@ AutolaborOverlay = defclass(AutolaborOverlay, overlay.OverlayWidget)
AutolaborOverlay.ATTRS{ AutolaborOverlay.ATTRS{
default_pos={x=7,y=-13}, default_pos={x=7,y=-13},
default_enabled=true, default_enabled=true,
viewscreens='dwarfmode/Info/LABOR', viewscreens='dwarfmode/Info/LABOR/WORK_DETAILS',
frame={w=29, h=5}, frame={w=29, h=5},
frame_style=gui.THIN_FRAME, frame_style=gui.MEDIUM_FRAME,
frame_background=gui.CLEAR_PEN, frame_background=gui.CLEAR_PEN,
} }

@ -1 +1 @@
Subproject commit 54bd83727df5f7048f5a7251b99ada1930e18ad9 Subproject commit 2554b931bfc23564de5bc7cb28eed673e82d06d3