2012-07-29 19:35:11 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is based on WME Lite.
|
|
|
|
* http://dead-code.org/redir.php?target=wmelite
|
|
|
|
* Copyright (c) 2011 Jan Nedoma
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/wintermute/base/base_persistence_manager.h"
|
|
|
|
#include "engines/wintermute/wintermute.h"
|
|
|
|
#include "engines/wintermute/base/saveload.h"
|
|
|
|
#include "engines/wintermute/ad/ad_scene.h"
|
2012-08-07 11:32:26 +00:00
|
|
|
#include "engines/wintermute/base/base_engine.h"
|
2012-07-29 19:35:11 +00:00
|
|
|
#include "engines/wintermute/base/base_game.h" // Temporary
|
|
|
|
#include "engines/wintermute/base/base_region.h"
|
|
|
|
#include "engines/wintermute/base/base_sub_frame.h"
|
|
|
|
#include "engines/wintermute/base/font/base_font.h"
|
2012-09-11 00:51:33 +00:00
|
|
|
#include "engines/wintermute/base/gfx/base_renderer.h"
|
2012-07-29 19:35:11 +00:00
|
|
|
#include "engines/wintermute/base/sound/base_sound.h"
|
|
|
|
#include "engines/wintermute/base/scriptables/script.h"
|
|
|
|
#include "common/savefile.h"
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
|
2012-08-13 01:42:30 +00:00
|
|
|
namespace Wintermute {
|
2012-07-29 19:35:11 +00:00
|
|
|
|
|
|
|
bool SaveLoad::loadGame(const Common::String &filename, BaseGame *gameRef) {
|
|
|
|
gameRef->LOG(0, "Loading game '%s'...", filename.c_str());
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
bool ret;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
gameRef->_renderer->initSaveLoad(false);
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
gameRef->_loadInProgress = true;
|
|
|
|
BasePersistenceManager *pm = new BasePersistenceManager();
|
|
|
|
if (DID_SUCCEED(ret = pm->initLoad(filename))) {
|
|
|
|
//if (DID_SUCCEED(ret = cleanup())) {
|
|
|
|
if (DID_SUCCEED(ret = SystemClassRegistry::getInstance()->loadTable(gameRef, pm))) {
|
|
|
|
if (DID_SUCCEED(ret = SystemClassRegistry::getInstance()->loadInstances(gameRef, pm))) {
|
2012-08-07 11:32:26 +00:00
|
|
|
// Restore random-seed:
|
|
|
|
BaseEngine::instance().getRandomSource()->setSeed(pm->getDWORD());
|
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
// data initialization after load
|
|
|
|
SaveLoad::initAfterLoad();
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
gameRef->applyEvent("AfterLoad", true);
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
gameRef->displayContent(true, false);
|
|
|
|
//_renderer->flip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
delete pm;
|
|
|
|
gameRef->_loadInProgress = false;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
gameRef->_renderer->endSaveLoad();
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
//_gameRef->LOG(0, "Load end %d", BaseUtils::GetUsedMemMB());
|
|
|
|
// AdGame:
|
|
|
|
if (DID_SUCCEED(ret)) {
|
|
|
|
SystemClassRegistry::getInstance()->enumInstances(SaveLoad::afterLoadRegion, "AdRegion", NULL);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SaveLoad::saveGame(int slot, const char *desc, bool quickSave, BaseGame *gameRef) {
|
|
|
|
Common::String filename = SaveLoad::getSaveSlotFilename(slot);
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
gameRef->LOG(0, "Saving game '%s'...", filename.c_str());
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
gameRef->applyEvent("BeforeSave", true);
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
bool ret;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
BasePersistenceManager *pm = new BasePersistenceManager();
|
|
|
|
if (DID_SUCCEED(ret = pm->initSave(desc))) {
|
|
|
|
gameRef->_renderer->initSaveLoad(true, quickSave); // TODO: The original code inited the indicator before the conditionals
|
|
|
|
if (DID_SUCCEED(ret = SystemClassRegistry::getInstance()->saveTable(gameRef, pm, quickSave))) {
|
|
|
|
if (DID_SUCCEED(ret = SystemClassRegistry::getInstance()->saveInstances(gameRef, pm, quickSave))) {
|
2012-08-07 11:32:26 +00:00
|
|
|
pm->putDWORD(BaseEngine::instance().getRandomSource()->getSeed());
|
2012-07-29 19:35:11 +00:00
|
|
|
if (DID_SUCCEED(ret = pm->saveFile(filename))) {
|
|
|
|
ConfMan.setInt("most_recent_saveslot", slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
delete pm;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
gameRef->_renderer->endSaveLoad();
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
bool SaveLoad::initAfterLoad() {
|
|
|
|
SystemClassRegistry::getInstance()->enumInstances(afterLoadRegion, "BaseRegion", NULL);
|
|
|
|
SystemClassRegistry::getInstance()->enumInstances(afterLoadSubFrame, "BaseSubFrame", NULL);
|
|
|
|
SystemClassRegistry::getInstance()->enumInstances(afterLoadSound, "BaseSound", NULL);
|
|
|
|
SystemClassRegistry::getInstance()->enumInstances(afterLoadFont, "BaseFontTT", NULL);
|
|
|
|
SystemClassRegistry::getInstance()->enumInstances(afterLoadScript, "ScScript", NULL);
|
|
|
|
// AdGame:
|
|
|
|
SystemClassRegistry::getInstance()->enumInstances(afterLoadScene, "AdScene", NULL);
|
|
|
|
return STATUS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
void SaveLoad::afterLoadScene(void *scene, void *data) {
|
|
|
|
((AdScene *)scene)->afterLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
void SaveLoad::afterLoadRegion(void *region, void *data) {
|
|
|
|
((BaseRegion *)region)->createRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
void SaveLoad::afterLoadSubFrame(void *subframe, void *data) {
|
|
|
|
((BaseSubFrame *)subframe)->setSurfaceSimple();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
void SaveLoad::afterLoadSound(void *sound, void *data) {
|
|
|
|
((BaseSound *)sound)->setSoundSimple();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
void SaveLoad::afterLoadFont(void *font, void *data) {
|
|
|
|
((BaseFont *)font)->afterLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
void SaveLoad::afterLoadScript(void *script, void *data) {
|
|
|
|
((ScScript *)script)->afterLoad();
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String SaveLoad::getSaveSlotFilename(int slot) {
|
|
|
|
BasePersistenceManager *pm = new BasePersistenceManager();
|
|
|
|
Common::String filename = pm->getFilenameForSlot(slot);
|
|
|
|
delete pm;
|
2012-08-13 01:42:30 +00:00
|
|
|
debugC(kWintermuteDebugSaveGame, "getSaveSlotFileName(%d) = %s", slot, filename.c_str());
|
2012-07-29 19:35:11 +00:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SaveLoad::getSaveSlotDescription(int slot, char *buffer) {
|
|
|
|
buffer[0] = '\0';
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
Common::String filename = getSaveSlotFilename(slot);
|
|
|
|
BasePersistenceManager *pm = new BasePersistenceManager();
|
|
|
|
if (!pm) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
if (!(pm->initLoad(filename))) {
|
|
|
|
delete pm;
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
strcpy(buffer, pm->_savedDescription);
|
|
|
|
delete pm;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2012-07-29 19:35:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SaveLoad::isSaveSlotUsed(int slot) {
|
|
|
|
Common::String filename = getSaveSlotFilename(slot);
|
|
|
|
BasePersistenceManager *pm = new BasePersistenceManager();
|
|
|
|
bool ret = pm->getSaveExists(slot);
|
|
|
|
delete pm;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SaveLoad::emptySaveSlot(int slot) {
|
|
|
|
Common::String filename = getSaveSlotFilename(slot);
|
|
|
|
BasePersistenceManager *pm = new BasePersistenceManager();
|
2012-08-13 01:42:30 +00:00
|
|
|
((WintermuteEngine *)g_engine)->getSaveFileMan()->removeSavefile(pm->getFilenameForSlot(slot));
|
2012-07-29 19:35:11 +00:00
|
|
|
delete pm;
|
|
|
|
return true;
|
|
|
|
}
|
2012-09-26 02:17:31 +00:00
|
|
|
|
|
|
|
|
2012-08-13 01:42:30 +00:00
|
|
|
} // end of namespace Wintermute
|