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.
develop
Alexander Gavrilov 2014-07-28 08:57:55 +04:00
parent 1c409975de
commit 0182e0c980
2 changed files with 20 additions and 11 deletions

@ -61,6 +61,8 @@ using namespace DFHack;
#include "df/world_data.h" #include "df/world_data.h"
#include "df/interfacest.h" #include "df/interfacest.h"
#include "df/viewscreen_dwarfmodest.h" #include "df/viewscreen_dwarfmodest.h"
#include "df/viewscreen_loadgamest.h"
#include "df/viewscreen_savegamest.h"
#include <df/graphic.h> #include <df/graphic.h>
#include <stdio.h> #include <stdio.h>
@ -1268,10 +1270,23 @@ void Core::doUpdate(color_ostream &out, bool first_update)
if (first_update) if (first_update)
onStateChange(out, SC_CORE_INITIALIZED); 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<df::viewscreen_loadgamest>(screen) ||
strict_virtual_cast<df::viewscreen_savegamest>(screen);
// detect if the game was loaded or unloaded in the meantime // detect if the game was loaded or unloaded in the meantime
void *new_wdata = NULL; void *new_wdata = NULL;
void *new_mapdata = 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; df::world_data *wdata = df::global::world->world_data;
// when the game is unloaded, world_data isn't deleted, but its contents are // 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 // detect if the viewscreen changed
if (df::global::gview) if (screen != top_viewscreen)
{ {
df::viewscreen *screen = &df::global::gview->view; top_viewscreen = screen;
while (screen->child) onStateChange(out, SC_VIEWSCREEN_CHANGED);
screen = screen->child;
if (screen != top_viewscreen)
{
top_viewscreen = screen;
onStateChange(out, SC_VIEWSCREEN_CHANGED);
}
} }
if (df::global::pause_state) if (df::global::pause_state)

@ -1 +1 @@
Subproject commit ac936b06bd0a69c84c4e0a94a4f22b3b1402b23b Subproject commit cb4c883d4f4f46fc9b4856d7e91f55e1b39b56c5