MCPcopy Create free account
hub / github.com/DFHack/dfhack / doUpdate

Method doUpdate

library/Core.cpp:1519–1616  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1517}
1518
1519void Core::doUpdate(color_ostream &out)
1520{
1521 Lua::Core::Reset(out, "DF code execution");
1522
1523 // find the current viewscreen
1524 df::viewscreen *screen = nullptr;
1525 if (df::global::gview)
1526 {
1527 screen = &df::global::gview->view;
1528 while (screen->child)
1529 screen = screen->child;
1530 }
1531
1532 // detect if the viewscreen changed, and trigger events later
1533 bool vs_changed = false;
1534 if (screen != top_viewscreen)
1535 {
1536 top_viewscreen = screen;
1537 vs_changed = true;
1538 }
1539
1540 bool is_save = strict_virtual_cast<df::viewscreen_savegamest>(screen) ||
1541 strict_virtual_cast<df::viewscreen_export_regionst>(screen);
1542 bool is_load_save = is_save ||
1543 strict_virtual_cast<df::viewscreen_game_cleanerst>(screen) ||
1544 strict_virtual_cast<df::viewscreen_loadgamest>(screen);
1545
1546 // save data (do this before updating last_world_data_ptr and triggering unload events)
1547 if ((df::global::game && df::global::game->main_interface.options.do_manual_save && !d->last_manual_save_request) ||
1548 (df::global::plotinfo && df::global::plotinfo->main.autosave_request && !d->last_autosave_request) ||
1549 (is_load_save && !d->was_load_save && is_save))
1550 {
1551 plug_mgr->doSaveData(out);
1552 Persistence::Internal::save(out);
1553 }
1554
1555 // detect if the game was loaded or unloaded in the meantime
1556 df::world_data* new_wdata = nullptr;
1557 df::map_block**** new_mapdata = nullptr;
1558 if (df::global::world && !is_load_save)
1559 {
1560 df::world_data *wdata = df::global::world->world_data;
1561 // when the game is unloaded, world_data isn't deleted, but its contents are
1562 // regions work to detect arena too
1563 if (wdata && !wdata->regions.empty())
1564 new_wdata = wdata;
1565 new_mapdata = df::global::world->map.block_index;
1566 }
1567
1568 // if the world changes
1569 if (new_wdata != last_world_data_ptr)
1570 {
1571 // we check for map change too
1572 bool had_map = isMapLoaded();
1573 last_world_data_ptr = new_wdata;
1574 last_local_map_ptr = new_mapdata;
1575
1576 // and if the world is going away, we report the map change first

Callers

nothing calls this directly

Calls 4

saveFunction · 0.85
doSaveDataMethod · 0.80
isMapLoadedFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected