diff options
| author | Petr Mrázek | 2012-04-01 02:56:54 +0200 |
|---|---|---|
| committer | Petr Mrázek | 2012-04-01 02:56:54 +0200 |
| commit | 7ff728b6fcbff9e6e8cfe49b65d0645729e249f8 (patch) | |
| tree | 5738ea52006e3651be1890eca0f4ca4d1908b8ce /library/Core.cpp | |
| parent | 209b26128464537be2474b78da7b3409fa4f4d92 (diff) | |
| download | dfhack-7ff728b6fcbff9e6e8cfe49b65d0645729e249f8.tar.gz dfhack-7ff728b6fcbff9e6e8cfe49b65d0645729e249f8.tar.bz2 dfhack-7ff728b6fcbff9e6e8cfe49b65d0645729e249f8.tar.xz | |
Track world and map changes separately for plugin_onstatechange
Diffstat (limited to 'library/Core.cpp')
| -rw-r--r-- | library/Core.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/library/Core.cpp b/library/Core.cpp index 8adbf374..0a7cbefd 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -609,6 +609,7 @@ Core::Core() HotkeyCond = 0; misc_data_mutex=0; last_world_data_ptr = NULL; + last_local_map_ptr = NULL; top_viewscreen = NULL; screen_window = NULL; server = NULL; @@ -869,16 +870,41 @@ int Core::Update() // detect if the game was loaded or unloaded in the meantime void *new_wdata = NULL; - if (df::global::world) { + void *new_mapdata = NULL; + if (df::global::world) + { df::world_data *wdata = df::global::world->world_data; // when the game is unloaded, world_data isn't deleted, but its contents are if (wdata && !wdata->sites.empty()) new_wdata = wdata; + new_mapdata = df::global::world->map.block_index; } - - if (new_wdata != last_world_data_ptr) { + // if the world changes + if (new_wdata != last_world_data_ptr) + { + // we check for map change too + bool mapchange = new_mapdata != last_local_map_ptr; + // and if the world is going away, we report the map change first + if(!new_wdata && mapchange) + { + last_local_map_ptr = new_mapdata; + plug_mgr->OnStateChange(out, new_mapdata ? SC_MAP_LOADED : 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); + if(new_wdata && mapchange) + { + last_local_map_ptr = new_mapdata; + plug_mgr->OnStateChange(out, new_mapdata ? SC_MAP_LOADED : SC_MAP_UNLOADED); + } + // update tracking variable last_world_data_ptr = new_wdata; - plug_mgr->OnStateChange(out, new_wdata ? SC_GAME_LOADED : SC_GAME_UNLOADED); + } + // otherwise just check for map change... + else if (new_mapdata != last_local_map_ptr) + { + last_local_map_ptr = new_mapdata; + plug_mgr->OnStateChange(out, new_mapdata ? SC_MAP_LOADED : SC_MAP_UNLOADED); } // detect if the viewscreen changed |
