add SC_PAUSED / SC_UNPAUSED onStateChange events

develop
jj 2012-07-05 18:03:02 +02:00
parent 7074048146
commit 8e17ebbefc
4 changed files with 18 additions and 1 deletions

@ -752,6 +752,7 @@ Core::Core()
misc_data_mutex=0; misc_data_mutex=0;
last_world_data_ptr = NULL; last_world_data_ptr = NULL;
last_local_map_ptr = NULL; last_local_map_ptr = NULL;
last_pause_state = false;
top_viewscreen = NULL; top_viewscreen = NULL;
screen_window = NULL; screen_window = NULL;
server = 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 // Execute per-frame handlers
onUpdate(out); onUpdate(out);

@ -75,7 +75,9 @@ namespace DFHack
SC_MAP_UNLOADED = 3, SC_MAP_UNLOADED = 3,
SC_VIEWSCREEN_CHANGED = 4, SC_VIEWSCREEN_CHANGED = 4,
SC_CORE_INITIALIZED = 5, 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. // 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 // for state change tracking
void *last_local_map_ptr; void *last_local_map_ptr;
df::viewscreen *top_viewscreen; df::viewscreen *top_viewscreen;
bool last_pause_state;
// Very important! // Very important!
bool started; bool started;

@ -39,6 +39,8 @@ if dfhack.is_core_context then
SC_MAP_UNLOADED = 3 SC_MAP_UNLOADED = 3
SC_VIEWSCREEN_CHANGED = 4 SC_VIEWSCREEN_CHANGED = 4
SC_CORE_INITIALIZED = 5 SC_CORE_INITIALIZED = 5
SC_PAUSED = 7
SC_UNPAUSED = 8
end end
-- Error handling -- Error handling

@ -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 // if we go through plugin_eval at BEGIN_UNLOAD, it'll
// try to get the suspend lock and deadlock at df exit // try to get the suspend lock and deadlock at df exit
case SC_BEGIN_UNLOAD : return CR_OK; case SC_BEGIN_UNLOAD : return CR_OK;
SCASE(PAUSED);
SCASE(UNPAUSED);
#undef SCASE #undef SCASE
} }