aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2016-09-16 22:14:51 +0200
committerEugene Sandulenko2016-09-16 22:15:24 +0200
commit60e3b9fd646a3ea7c3fb783ea5b249929b5f289f (patch)
treec0992c68b57641270374ea4f19848bb663f18a77
parent1b335b6c751a45d4ec25e0084737ea84ffda9fca (diff)
downloadscummvm-rg350-60e3b9fd646a3ea7c3fb783ea5b249929b5f289f.tar.gz
scummvm-rg350-60e3b9fd646a3ea7c3fb783ea5b249929b5f289f.tar.bz2
scummvm-rg350-60e3b9fd646a3ea7c3fb783ea5b249929b5f289f.zip
FULLPIPE: Further work on game saving
-rw-r--r--engines/fullpipe/gameloader.cpp102
-rw-r--r--engines/fullpipe/gameloader.h4
-rw-r--r--engines/fullpipe/inventory.cpp5
-rw-r--r--engines/fullpipe/inventory.h1
-rw-r--r--engines/fullpipe/module.mk1
-rw-r--r--engines/fullpipe/objects.h1
-rw-r--r--engines/fullpipe/stateloader.cpp2
-rw-r--r--engines/fullpipe/statesaver.cpp51
8 files changed, 107 insertions, 60 deletions
diff --git a/engines/fullpipe/gameloader.cpp b/engines/fullpipe/gameloader.cpp
index 0c5fe92ff6..7a862eec19 100644
--- a/engines/fullpipe/gameloader.cpp
+++ b/engines/fullpipe/gameloader.cpp
@@ -66,7 +66,7 @@ GameLoader::GameLoader() {
_field_F8 = 0;
_sceneSwitcher = 0;
_preloadCallback = 0;
- _readSavegameCallback = 0;
+ _savegameCallback = 0;
_gameVar = 0;
_preloadSceneId = 0;
_preloadEntranceId = 0;
@@ -614,7 +614,7 @@ void GameLoader::writeSavegame(Scene *sc, const char *fname) {
GameVar *v = _gameVar->getSubVarByName("OBJSTATES")->getSubVarByName("SAVEGAME");
if (!v) {
-// v = _gameVar->getSubVarByName("OBJSTATES")->getSubVarAsInt("SAVEGAME", 0);
+ v = _gameVar->getSubVarByName("OBJSTATES")->addSubVarAsInt("SAVEGAME", 0);
if (!v) {
warning("No state to save");
@@ -626,8 +626,7 @@ void GameLoader::writeSavegame(Scene *sc, const char *fname) {
v->setSubVarAsInt("Scene", sc->_sceneId);
-#if 0
- saveScenePicAniInfos(this, sc->_sceneId);
+ saveScenePicAniInfos(sc->_sceneId);
memset(&header, 0, sizeof(header));
header.saveSize = 48;
@@ -636,68 +635,55 @@ void GameLoader::writeSavegame(Scene *sc, const char *fname) {
header.unkField = 1;
// open save for reading
- v = _gameVar->getSubVarByName("OBJSTATES");
+ Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(fname);
- MfcArchive archive;
+ v = _gameVar->getSubVarByName("OBJSTATES");
- sca = 0;
- filenamea = 0;
+ GameVar *nxt = 0;
+ GameVar *prv = 0;
+ GameVar *par;
if (v) {
- v12 = v11->_nextVarObj;
- v13 = (char *)v11->prevVarObj;
- v9 = v11->parentVarObj;
- v11->parentVarObj = 0;
- sca = (Scene *)v12;
- v11->_nextVarObj = 0;
- filenamea = v13;
- v11->prevVarObj = 0;
+ nxt = v->_nextVarObj;
+ prv = v->_prevVarObj;
+ par = v->_parentVarObj;
+ v->_parentVarObj = 0;
+ v->_nextVarObj = 0;
+ v->_prevVarObj = 0;
}
- carchive->writeObject(v);
- if (v11) {
- v11->parentVarObj = v9;
- v11->_nextVarObj = (GameVar *)sca;
- v11->prevVarObj = (GameVar *)filenamea;
+ writeObject(saveFile, v);
+
+ if (v) {
+ v->_parentVarObj = par;
+ v->_nextVarObj = nxt;
+ v->_prevVarObj = prv;
}
- v14 = getGameLoaderInventory();
- Inventory2_SerializePartially(v14, &carchive);
- v15 = this->_sc2array.objs.m_nSize;
- if (unsigned int)(carchive.m_lpBufCur + 4) > carchive.m_lpBufMax)
- CArchive::Flush(&carchive);
- *(_DWORD *)carchive.m_lpBufCur = v15;
- v16 = 0;
- carchive.m_lpBufCur += 4;
- while (1) {
- scb = (Scene *)v16;
- if ( v16 >= this->_sc2array.objs.m_nSize )
- break;
- v17 = v16;
- v18 = this->_sc2array.objs.m_pData[v16].picAniInfosCount;
- if ( (unsigned int)(carchive.m_lpBufCur + 4) > carchive.m_lpBufMax ) {
- CArchive::Flush(&carchive);
- v16 = (int)scb;
- }
- *(_DWORD *)carchive.m_lpBufCur = v18;
- v19 = &this->_sc2array.objs.m_pData[v17];
- carchive.m_lpBufCur += 4;
- v20 = v19->picAniInfosCount;
- if ( v20 > 0 ) {
- CArchive::Write(&carchive, v19->picAniInfos, 44 * v20);
- v16 = (int)scb;
+
+ getGameLoaderInventory()->writePartial(saveFile);
+
+ saveFile->writeUint32LE(_sc2array.size());
+
+ for (uint i = 0; i < _sc2array.size(); i++) {
+ saveFile->writeUint32LE(_sc2array[i]._picAniInfosCount);
+
+ for (uint j = 0; j < _sc2array[i]._picAniInfosCount; j++) {
+ _sc2array[i]._picAniInfos[j]->save(saveFile);
}
- ++v16;
}
- CArchive::Close(&carchive);
- header.encSize = GameLoader_encryptSavegame((GameLoader *)header.unkField, (int)&cmemfile);
- CFile::Write((int)&cfile, (int)&header, header.saveSize);
- v21 = (void *)CMemFile::Detach(&cmemfile);
- CFile::Write((int)&cfile, (int)v21, header.encSize);
- free(v21);
- v22 = (void (__fastcall *)(char *, signed int))this->_readSavegameCallback;
- if ( v22 )
- v22(&cfile, 1);
- CFile::Close(&cfile);
-#endif
+
+ //header.encSize = GameLoader_encryptSavegame((GameLoader *)header.unkField, (int)&cmemfile);
+ //CFile::Write((int)&cfile, (int)&header, header.saveSize);
+
+ //if (_savegameCallback)
+ // _savegameCallback(saveFile, 1);
+
+ saveFile->finalize();
+
+ delete saveFile;
+}
+
+void GameLoader::writeObject(Common::WriteStream *stream, GameVar *) {
+ warning("STUB: GameLoader::writeObject()");
}
Sc2::Sc2() {
diff --git a/engines/fullpipe/gameloader.h b/engines/fullpipe/gameloader.h
index bb9b934b59..a11c0aab0b 100644
--- a/engines/fullpipe/gameloader.h
+++ b/engines/fullpipe/gameloader.h
@@ -101,6 +101,8 @@ class GameLoader : public CObject {
void readSavegame(const char *fname);
void writeSavegame(Scene *sc, const char *fname);
+ void writeObject(Common::WriteStream *stream, GameVar *);
+
void restoreDefPicAniInfos();
GameProject *_gameProject;
@@ -110,7 +112,7 @@ class GameLoader : public CObject {
Sc2Array _sc2array;
void *_sceneSwitcher;
bool (*_preloadCallback)(PreloadItem &pre, int flag);
- void *_readSavegameCallback;
+ void *_savegameCallback;
int16 _field_F8;
int16 _field_FA;
PreloadItems _preloadItems;
diff --git a/engines/fullpipe/inventory.cpp b/engines/fullpipe/inventory.cpp
index 13ac78a358..10a584782b 100644
--- a/engines/fullpipe/inventory.cpp
+++ b/engines/fullpipe/inventory.cpp
@@ -106,6 +106,11 @@ bool Inventory2::loadPartial(MfcArchive &file) { // Inventory2_SerializePartiall
return true;
}
+bool Inventory2::writePartial(Common::WriteStream *file) {
+ warning("STUB: nventory2::writePartial()");
+ return true;
+}
+
void Inventory2::addItem(int itemId, int count) {
if (getInventoryPoolItemIndexById(itemId) >= 0)
_inventoryItems.push_back(new InventoryItem(itemId, count));
diff --git a/engines/fullpipe/inventory.h b/engines/fullpipe/inventory.h
index 46b55c5669..6f6e349eea 100644
--- a/engines/fullpipe/inventory.h
+++ b/engines/fullpipe/inventory.h
@@ -101,6 +101,7 @@ class Inventory2 : public Inventory {
virtual ~Inventory2();
bool loadPartial(MfcArchive &file);
+ bool writePartial(Common::WriteStream *file);
void addItem(int itemId, int count);
void addItem2(StaticANIObject *obj);
void removeItem(int itemId, int count);
diff --git a/engines/fullpipe/module.mk b/engines/fullpipe/module.mk
index 01aba1bd82..62f9c5f77a 100644
--- a/engines/fullpipe/module.mk
+++ b/engines/fullpipe/module.mk
@@ -23,6 +23,7 @@ MODULE_OBJS = \
scenes.o \
sound.o \
stateloader.o \
+ statesaver.o \
statics.o \
utils.o \
scenes/sceneIntro.o \
diff --git a/engines/fullpipe/objects.h b/engines/fullpipe/objects.h
index c9da43986c..a138fe811a 100644
--- a/engines/fullpipe/objects.h
+++ b/engines/fullpipe/objects.h
@@ -61,6 +61,7 @@ struct PicAniInfo {
int32 someDynamicPhaseIndex;
bool load(MfcArchive &file);
+ bool save(Common::WriteStream *file);
PicAniInfo() { memset(this, 0, sizeof(PicAniInfo)); }
};
diff --git a/engines/fullpipe/stateloader.cpp b/engines/fullpipe/stateloader.cpp
index 02053aa94e..1e1cf35abd 100644
--- a/engines/fullpipe/stateloader.cpp
+++ b/engines/fullpipe/stateloader.cpp
@@ -60,7 +60,7 @@ bool FullpipeEngine::loadGam(const char *fname, int scene) {
// _sceneSwitcher = sceneSwitcher; // substituted with direct call
_gameLoader->_preloadCallback = preloadCallback;
- // _readSavegameCallback = gameLoaderReadSavegameCallback; // TODO
+ // _savegameCallback = gameLoaderSavegameCallback; // TODO
_aniMan = accessScene(SC_COMMON)->getAniMan();
_scene2 = 0;
diff --git a/engines/fullpipe/statesaver.cpp b/engines/fullpipe/statesaver.cpp
new file mode 100644
index 0000000000..8ffdc1513d
--- /dev/null
+++ b/engines/fullpipe/statesaver.cpp
@@ -0,0 +1,51 @@
+/* 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.
+ *
+ */
+
+#include "fullpipe/fullpipe.h"
+
+#include "fullpipe/objects.h"
+
+namespace Fullpipe {
+
+bool PicAniInfo::save(Common::WriteStream *file) {
+ debugC(5, kDebugLoading, "PicAniInfo::save()");
+
+ file->writeUint32LE(type);
+ file->writeUint16LE(objectId);
+ file->writeUint16LE(field_6);
+ file->writeUint32LE(field_8);
+ file->writeUint16LE(sceneId);
+ file->writeUint16LE(field_E);
+ file->writeSint32LE(ox);
+ file->writeSint32LE(oy);
+ file->writeUint32LE(priority);
+ file->writeUint16LE(staticsId);
+ file->writeUint16LE(movementId);
+ file->writeUint16LE(dynamicPhaseIndex);
+ file->writeUint16LE(flags);
+ file->writeUint32LE(field_24);
+ file->writeUint32LE(someDynamicPhaseIndex);
+
+ return true;
+}
+
+} // End of namespace Fullpipe