diff options
| author | Alexander Gavrilov | 2012-05-17 20:04:09 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-05-17 20:04:09 +0400 |
| commit | e9ef9b87b575b4746e2090556c192237c95f508a (patch) | |
| tree | 911e7c2d889c964b27038ab4b60afb762cf63eb2 /library/Core.cpp | |
| parent | 2c0024adc91491b6d687f3b56d6a5779a3391e59 (diff) | |
| download | dfhack-e9ef9b87b575b4746e2090556c192237c95f508a.tar.gz dfhack-e9ef9b87b575b4746e2090556c192237c95f508a.tar.bz2 dfhack-e9ef9b87b575b4746e2090556c192237c95f508a.tar.xz | |
Add central locations for onUpdate and onStateChange handling in core.
Diffstat (limited to 'library/Core.cpp')
| -rw-r--r-- | library/Core.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/library/Core.cpp b/library/Core.cpp index 7f08f402..1d2a7602 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1017,7 +1017,7 @@ int Core::Update() Lua::Core::Reset(out, "DF code execution"); if (first_update) - plug_mgr->OnStateChange(out, SC_CORE_INITIALIZED); + onStateChange(out, SC_CORE_INITIALIZED); // detect if the game was loaded or unloaded in the meantime void *new_wdata = NULL; @@ -1043,11 +1043,11 @@ int Core::Update() // and if the world is going away, we report the map change first if(had_map) - plug_mgr->OnStateChange(out, SC_MAP_UNLOADED); + onStateChange(out, SC_MAP_UNLOADED); // and if the world is appearing, we report map change after that - plug_mgr->OnStateChange(out, new_wdata ? SC_WORLD_LOADED : SC_WORLD_UNLOADED); + onStateChange(out, new_wdata ? SC_WORLD_LOADED : SC_WORLD_UNLOADED); if(isMapLoaded()) - plug_mgr->OnStateChange(out, SC_MAP_LOADED); + onStateChange(out, SC_MAP_LOADED); } // otherwise just check for map change... else if (new_mapdata != last_local_map_ptr) @@ -1058,7 +1058,7 @@ int Core::Update() if (isMapLoaded() != had_map) { getWorld()->ClearPersistentCache(); - plug_mgr->OnStateChange(out, new_mapdata ? SC_MAP_LOADED : SC_MAP_UNLOADED); + onStateChange(out, new_mapdata ? SC_MAP_LOADED : SC_MAP_UNLOADED); } } @@ -1071,15 +1071,12 @@ int Core::Update() if (screen != top_viewscreen) { top_viewscreen = screen; - plug_mgr->OnStateChange(out, SC_VIEWSCREEN_CHANGED); + onStateChange(out, SC_VIEWSCREEN_CHANGED); } } - // notify all the plugins that a game tick is finished - plug_mgr->OnUpdate(out); - - // process timers in lua - Lua::Core::onUpdate(out); + // Execute per-frame handlers + onUpdate(out); // Release the fake suspend lock { @@ -1116,6 +1113,22 @@ int Core::Update() return 0; }; +void Core::onUpdate(color_ostream &out) +{ + // notify all the plugins that a game tick is finished + plug_mgr->OnUpdate(out); + + // process timers in lua + Lua::Core::onUpdate(out); +} + +void Core::onStateChange(color_ostream &out, state_change_event event) +{ + plug_mgr->OnStateChange(out, event); + + Lua::Core::onStateChange(out, event); +} + // FIXME: needs to terminate the IO threads and properly dismantle all the machinery involved. int Core::Shutdown ( void ) { |
