diff --git a/library/Core.cpp b/library/Core.cpp index 59334906d..826576b77 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -752,6 +752,7 @@ Core::Core() misc_data_mutex=0; last_world_data_ptr = NULL; last_local_map_ptr = NULL; + last_pause_state = false; top_viewscreen = NULL; screen_window = NULL; server = NULL; @@ -1116,6 +1117,15 @@ int Core::Update() } } + if (df::global::pause_state) + { + if (*df::global::pause_state != last_pause_state) + { + onStateChange(out, last_pause_state ? SC_UNPAUSED : SC_PAUSED); + last_pause_state = *df::global::pause_state; + } + } + // Execute per-frame handlers onUpdate(out); diff --git a/library/include/Core.h b/library/include/Core.h index e4d1080d6..0d5d3150e 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -75,7 +75,9 @@ namespace DFHack SC_MAP_UNLOADED = 3, SC_VIEWSCREEN_CHANGED = 4, SC_CORE_INITIALIZED = 5, - SC_BEGIN_UNLOAD = 6 + SC_BEGIN_UNLOAD = 6, + SC_PAUSED = 7, + SC_UNPAUSED = 8 }; // Core is a singleton. Why? Because it is closely tied to SDL calls. It tracks the global state of DF. @@ -221,6 +223,7 @@ namespace DFHack // for state change tracking void *last_local_map_ptr; df::viewscreen *top_viewscreen; + bool last_pause_state; // Very important! bool started; diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index d56d4df60..86ea1459f 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -39,6 +39,8 @@ if dfhack.is_core_context then SC_MAP_UNLOADED = 3 SC_VIEWSCREEN_CHANGED = 4 SC_CORE_INITIALIZED = 5 + SC_PAUSED = 7 + SC_UNPAUSED = 8 end -- Error handling diff --git a/plugins/ruby/ruby.cpp b/plugins/ruby/ruby.cpp index 6dd0b39c8..08ea13b9f 100644 --- a/plugins/ruby/ruby.cpp +++ b/plugins/ruby/ruby.cpp @@ -194,6 +194,8 @@ DFhackCExport command_result plugin_onstatechange ( color_ostream &out, state_ch // if we go through plugin_eval at BEGIN_UNLOAD, it'll // try to get the suspend lock and deadlock at df exit case SC_BEGIN_UNLOAD : return CR_OK; + SCASE(PAUSED); + SCASE(UNPAUSED); #undef SCASE }