Removed duplicate code. Some cleanup

svn-id: r47735
This commit is contained in:
Filippos Karapetis 2010-01-31 01:26:06 +00:00
parent 8b9cdd671f
commit 7f4aa161bc
5 changed files with 18 additions and 45 deletions

View File

@ -893,26 +893,17 @@ bool Console::cmdRestoreGame(int argc, const char **argv) {
return true;
}
EngineState *newstate = NULL;
Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
Common::SeekableReadStream *in = saveFileMan->openForLoading(argv[1]);
if (in) {
// found a savegame file
newstate = gamestate_restore(_vm->_gamestate, in);
gamestate_restore(_vm->_gamestate, in);
delete in;
}
if (newstate) {
_vm->_gamestate->successor = newstate; // Set successor
script_abort_flag = 2; // Abort current game with replay
shrink_execution_stack(_vm->_gamestate, _vm->_gamestate->execution_stack_base + 1);
return 0;
} else {
if (_vm->_gamestate->r_acc == make_reg(0, 1)) {
DebugPrintf("Restoring gamestate '%s' failed.\n", argv[1]);
return 1;
return true;
}
return false;

View File

@ -475,23 +475,17 @@ void SciMetaEngine::removeSaveState(const char *target, int slot) const {
}
Common::Error SciEngine::loadGameState(int slot) {
EngineState *newstate = NULL;
Common::String fileName = Common::String::printf("%s.%03d", _targetName.c_str(), slot);
Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
Common::SeekableReadStream *in = saveFileMan->openForLoading(fileName);
if (in) {
// found a savegame file
newstate = gamestate_restore(_gamestate, in);
gamestate_restore(_gamestate, in);
delete in;
}
if (newstate) {
_gamestate->successor = newstate; // Set successor
script_abort_flag = 2; // Abort current game with replay
shrink_execution_stack(_gamestate, _gamestate->execution_stack_base + 1);
if (_gamestate->r_acc != make_reg(0, 1)) {
return Common::kNoError;
} else {
warning("Restoring gamestate '%s' failed", fileName.c_str());

View File

@ -618,17 +618,9 @@ reg_t kRestoreGame(EngineState *s, int argc, reg_t *argv) {
if ((in = saveFileMan->openForLoading(filename))) {
// found a savegame file
EngineState *newstate = gamestate_restore(s, in);
gamestate_restore(s, in);
delete in;
if (newstate) {
s->successor = newstate;
script_abort_flag = 2; // Abort current game with replay
shrink_execution_stack(s, s->execution_stack_base + 1);
} else {
s->r_acc = make_reg(0, 1);
warning("Restoring failed (game_id = '%s')", game_id.c_str());
}
return s->r_acc;
}
}

View File

@ -903,28 +903,21 @@ static void reconstruct_sounds(EngineState *s) {
}
#endif
EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
EngineState *retval;
#ifdef USE_OLD_MUSIC_FUNCTIONS
SongLibrary temp;
#endif
/*
if (s->sound_server) {
if ((s->sound_server->restore)(s, dirname)) {
warning("Restoring failed for the sound subsystem");
return NULL;
}
}
*/
SavegameMetadata meta;
Common::Serializer ser(fh, 0);
sync_SavegameMetadata(ser, meta);
if (fh->eos())
return false;
if (fh->eos()) {
s->r_acc = make_reg(0, 1); // signal failure
return;
}
if ((meta.savegame_version < MINIMUM_SAVEGAME_VERSION) ||
(meta.savegame_version > CURRENT_SAVEGAME_VERSION)) {
@ -933,7 +926,8 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
else
warning("Savegame version is %d- maximum supported is %0d", meta.savegame_version, CURRENT_SAVEGAME_VERSION);
return NULL;
s->r_acc = make_reg(0, 1); // signal failure
return;
}
if (meta.savegame_version >= 12) {
@ -1027,7 +1021,10 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
}
#endif
return retval;
s->successor = retval; // Set successor
script_abort_flag = 2; // Abort current game with replay
shrink_execution_stack(s, s->execution_stack_base + 1);
}
bool get_savegame_metadata(Common::SeekableReadStream *stream, SavegameMetadata *meta) {

View File

@ -63,9 +63,8 @@ int gamestate_save(EngineState *s, Common::WriteStream *save, const char *savena
* Restores a game state from a directory.
* @param s An older state from the same game
* @param dirname The subdirectory to restore from
* @return NULL on failure, a pointer to a valid EngineState otherwise
*/
EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *save);
void gamestate_restore(EngineState *s, Common::SeekableReadStream *save);
/**
* Read the header from a savegame.