Skip to content

Commit

Permalink
Load: Fix Async loading of the map file when command ManiacLoad is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Oct 9, 2024
1 parent 9b104b5 commit c5c235a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,6 @@ void Player::LoadSavegame(const std::string& save_name, int save_id) {
if (!load_on_map) {
Scene::PopUntil(Scene::Title);
}
Game_Map::Dispose();

Main_Data::game_switches->SetLowerLimit(lcf::Data::switches.size());
Main_Data::game_switches->SetData(std::move(save->system.switches));
Expand All @@ -1180,18 +1179,27 @@ void Player::LoadSavegame(const std::string& save_name, int save_id) {
int map_id = Main_Data::game_player->GetMapId();

FileRequestAsync* map = Game_Map::RequestMap(map_id);
save_request_id = map->Bind([save=std::move(*save)](auto* request) { OnMapSaveFileReady(request, std::move(save)); });
save_request_id = map->Bind(
[save=*save, load_on_map, save_id](auto* request) {
Game_Map::Dispose();

OnMapSaveFileReady(request, std::move(save));

if (load_on_map) {
// Increment frame counter for consistency with a normal savegame load
IncFrame();
static_cast<Scene_Map*>(Scene::instance.get())->StartFromSave(save_id);
}
}
);
map->SetImportantFile(true);

Main_Data::game_system->ReloadSystemGraphic();

map->Start();
// load_on_map is handled in the async callback
if (!load_on_map) {
Scene::Push(std::make_shared<Scene_Map>(save_id));
} else {
// Increment frame counter for consistency with a normal savegame load
IncFrame();
static_cast<Scene_Map*>(Scene::instance.get())->StartFromSave(save_id);
}
}

Expand Down

0 comments on commit c5c235a

Please sign in to comment.