From 0182e0c980d7ee384944272fee5504b5a6ac2cd8 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 28 Jul 2014 08:57:55 +0400 Subject: [PATCH] Fix SC_WORLD_LOADED/UNLOADED now that loading and saving takes many frames. During the loading or saving screen, consider the map and world as not loaded, because they are likely only partially valid. This fixes errors from the log-region script. --- library/Core.cpp | 29 +++++++++++++++++++---------- library/xml | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 6cc47292f..01964139c 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -61,6 +61,8 @@ using namespace DFHack; #include "df/world_data.h" #include "df/interfacest.h" #include "df/viewscreen_dwarfmodest.h" +#include "df/viewscreen_loadgamest.h" +#include "df/viewscreen_savegamest.h" #include #include @@ -1268,10 +1270,23 @@ void Core::doUpdate(color_ostream &out, bool first_update) if (first_update) onStateChange(out, SC_CORE_INITIALIZED); + // find the current viewscreen + df::viewscreen *screen = NULL; + if (df::global::gview) + { + screen = &df::global::gview->view; + while (screen->child) + screen = screen->child; + } + + bool is_load_save = + strict_virtual_cast(screen) || + strict_virtual_cast(screen); + // detect if the game was loaded or unloaded in the meantime void *new_wdata = NULL; void *new_mapdata = NULL; - if (df::global::world) + if (df::global::world && !is_load_save) { df::world_data *wdata = df::global::world->world_data; // when the game is unloaded, world_data isn't deleted, but its contents are @@ -1313,16 +1328,10 @@ void Core::doUpdate(color_ostream &out, bool first_update) } // detect if the viewscreen changed - if (df::global::gview) + if (screen != top_viewscreen) { - df::viewscreen *screen = &df::global::gview->view; - while (screen->child) - screen = screen->child; - if (screen != top_viewscreen) - { - top_viewscreen = screen; - onStateChange(out, SC_VIEWSCREEN_CHANGED); - } + top_viewscreen = screen; + onStateChange(out, SC_VIEWSCREEN_CHANGED); } if (df::global::pause_state) diff --git a/library/xml b/library/xml index ac936b06b..cb4c883d4 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit ac936b06bd0a69c84c4e0a94a4f22b3b1402b23b +Subproject commit cb4c883d4f4f46fc9b4856d7e91f55e1b39b56c5