M4: Fixes for loading savegames

This commit is contained in:
Paul Gilbert 2023-10-01 20:35:09 -07:00 committed by Eugene Sandulenko
parent 7a8ac084d4
commit ae41287b2c
5 changed files with 29 additions and 3 deletions

View File

@ -284,7 +284,7 @@ int kernel_save_game(int slot, const char *desc, int32 sizeofDesc, M4sprite *thu
}
bool kernel_load_game(int slot) {
return g_engine->loadGameState(slot).getCode() == Common::kNoError;
return g_engine->loadGameStateDoIt(slot).getCode() == Common::kNoError;
}
int32 extract_room_num(const Common::String &name) {

View File

@ -20,6 +20,7 @@
*/
#include "m4/adv_r/adv_game.h"
#include "m4/core/rooms.h"
namespace M4 {

View File

@ -85,7 +85,7 @@ void Sections::game_daemon_code() {
if (_G(kernel).trigger == 32001) {
_G(game).room_id = -1;
_G(game).section_id = -1;
_G(game).previous_room = -2;
_G(game).previous_room = RESTORING_GAME;
}
}

View File

@ -79,6 +79,12 @@ Common::Error M4Engine::run() {
// Set the console
setDebugger(new Console());
// Check for launcher savegame to load
if (ConfMan.hasKey("save_slot")) {
_G(kernel).restore_slot = ConfMan.getInt("save_slot");
_G(game).previous_room = RESTORING_GAME;
}
// Run game here
m4_inflight();
}
@ -94,7 +100,7 @@ void M4Engine::m4_inflight() {
_G(kernel).going = true;
while (KEEP_PLAYING) {
if (_G(game).previous_room == -2) {
if (_G(game).previous_room == RESTORING_GAME) {
midi_stop();
kernel_load_game(_G(kernel).restore_slot);
}
@ -121,6 +127,21 @@ bool M4Engine::canSaveGameStateCurrently(Common::U32String *msg) {
return g_vars && g_vars->getInterface() && g_vars->getInterface()->_visible;
}
Common::Error M4Engine::loadGameState(int slot) {
// Don't load savegame immediately, just set the slot for the engine's
// kernel to take care of in the outer game loop
_G(kernel).restore_slot = slot;
_G(game).new_room = RESTORING_GAME;
_G(game).new_section = RESTORING_GAME;
_G(game).previous_room = RESTORING_GAME;
return Common::kNoError;
}
Common::Error M4Engine::loadGameStateDoIt(int slot) {
return Engine::loadGameState(slot);
}
Common::Error M4Engine::syncGame(Common::Serializer &s) {
_G(game).syncGame(s);
_G(player).syncGame(s);
@ -136,6 +157,7 @@ Common::Error M4Engine::syncGame(Common::Serializer &s) {
if (s.isLoading()) {
// set up variables so everyone knows we've teleported
_G(kernel).restore_game = true;
_G(between_rooms) = true;
_G(game).previous_room = KERNEL_RESTORING_GAME;
digi_set_overall_volume(_G(game).digi_overall_volume_percent);

View File

@ -102,6 +102,9 @@ public:
bool canLoadGameStateCurrently(Common::U32String * msg = nullptr) override;
bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
Common::Error loadGameState(int slot) override;
Common::Error loadGameStateDoIt(int slot);
/**
* Uses a serializer to allow implementing savegame
* loading and saving using a single method