1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/* 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.
* 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.
* 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"
#include "engines/wintermute/base/base_engine.h"
#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"
#include "engines/wintermute/base/gfx/base_renderer.h"
#include "engines/wintermute/base/sound/base_sound.h"
#include "engines/wintermute/base/scriptables/script.h"
#include "common/savefile.h"
#include "common/config-manager.h"
namespace Wintermute {
bool SaveLoad::loadGame(const Common::String &filename, BaseGame *gameRef) {
gameRef->LOG(0, "Loading game '%s'...", filename.c_str());
bool ret;
gameRef->_renderer->initSaveLoad(false);
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))) {
// Restore random-seed:
BaseEngine::instance().getRandomSource()->setSeed(pm->getDWORD());
// data initialization after load
SaveLoad::initAfterLoad();
gameRef->applyEvent("AfterLoad", true);
gameRef->displayContent(true, false);
//_renderer->flip();
}
}
}
delete pm;
gameRef->_loadInProgress = false;
gameRef->_renderer->endSaveLoad();
//BaseEngine::LOG(0, "Load end %d", BaseUtils::GetUsedMemMB());
// AdGame:
if (DID_SUCCEED(ret)) {
SystemClassRegistry::getInstance()->enumInstances(SaveLoad::afterLoadRegion, "AdRegion", nullptr);
}
return ret;
}
bool SaveLoad::saveGame(int slot, const char *desc, bool quickSave, BaseGame *gameRef) {
Common::String filename = SaveLoad::getSaveSlotFilename(slot);
gameRef->LOG(0, "Saving game '%s'...", filename.c_str());
gameRef->applyEvent("BeforeSave", true);
bool ret;
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))) {
pm->putDWORD(BaseEngine::instance().getRandomSource()->getSeed());
if (DID_SUCCEED(ret = pm->saveFile(filename))) {
ConfMan.setInt("most_recent_saveslot", slot);
}
}
}
}
delete pm;
gameRef->_renderer->endSaveLoad();
return ret;
}
//////////////////////////////////////////////////////////////////////////
bool SaveLoad::initAfterLoad() {
SystemClassRegistry::getInstance()->enumInstances(afterLoadRegion, "BaseRegion", nullptr);
SystemClassRegistry::getInstance()->enumInstances(afterLoadSubFrame, "BaseSubFrame", nullptr);
SystemClassRegistry::getInstance()->enumInstances(afterLoadSound, "BaseSound", nullptr);
SystemClassRegistry::getInstance()->enumInstances(afterLoadFont, "BaseFontTT", nullptr);
SystemClassRegistry::getInstance()->enumInstances(afterLoadScript, "ScScript", nullptr);
// AdGame:
SystemClassRegistry::getInstance()->enumInstances(afterLoadScene, "AdScene", nullptr);
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;
debugC(kWintermuteDebugSaveGame, "getSaveSlotFileName(%d) = %s", slot, filename.c_str());
return filename;
}
bool SaveLoad::getSaveSlotDescription(int slot, char *buffer) {
buffer[0] = '\0';
Common::String filename = getSaveSlotFilename(slot);
BasePersistenceManager *pm = new BasePersistenceManager();
if (!pm) {
return false;
}
if (!(pm->initLoad(filename))) {
delete pm;
return false;
}
strcpy(buffer, pm->_savedDescription);
delete pm;
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();
((WintermuteEngine *)g_engine)->getSaveFileMan()->removeSavefile(pm->getFilenameForSlot(slot));
delete pm;
return true;
}
} // End of namespace Wintermute
|