aboutsummaryrefslogtreecommitdiff
path: root/scumm
diff options
context:
space:
mode:
authorMax Horn2005-04-10 15:13:40 +0000
committerMax Horn2005-04-10 15:13:40 +0000
commite79c168d35d9c3633e3dfb618bd05466b0efc307 (patch)
treefe4fa01fd852546eaa3229f62069109d98eb8a67 /scumm
parente03861fdd4ca4cb676788c4ae4ea19647107fd6b (diff)
downloadscummvm-rg350-e79c168d35d9c3633e3dfb618bd05466b0efc307.tar.gz
scummvm-rg350-e79c168d35d9c3633e3dfb618bd05466b0efc307.tar.bz2
scummvm-rg350-e79c168d35d9c3633e3dfb618bd05466b0efc307.zip
split SaveFileManager::openSavefile and class SaveFile into two, each, one for loading and one for saving
svn-id: r17517
Diffstat (limited to 'scumm')
-rw-r--r--scumm/saveload.cpp36
-rw-r--r--scumm/saveload.h16
-rw-r--r--scumm/script_v5.cpp10
3 files changed, 31 insertions, 31 deletions
diff --git a/scumm/saveload.cpp b/scumm/saveload.cpp
index f63b0e667f..e41e6df51c 100644
--- a/scumm/saveload.cpp
+++ b/scumm/saveload.cpp
@@ -68,12 +68,12 @@ void ScummEngine::requestLoad(int slot) {
bool ScummEngine::saveState(int slot, bool compat) {
char filename[256];
- SaveFile *out;
+ OutSaveFile *out;
SaveGameHeader hdr;
makeSavegameName(filename, slot, compat);
- if (!(out = _saveFileMan->openSavefile(filename, true)))
+ if (!(out = _saveFileMan->openForSaving(filename)))
return false;
memcpy(hdr.name, _saveLoadName, sizeof(hdr.name));
@@ -84,7 +84,7 @@ bool ScummEngine::saveState(int slot, bool compat) {
out->write(&hdr, sizeof(hdr));
- Serializer ser(out, true, CURRENT_VER);
+ Serializer ser(0, out, CURRENT_VER);
saveOrLoad(&ser, CURRENT_VER);
delete out;
debug(1, "State saved as '%s'", filename);
@@ -93,14 +93,14 @@ bool ScummEngine::saveState(int slot, bool compat) {
bool ScummEngine::loadState(int slot, bool compat) {
char filename[256];
- SaveFile *in;
+ InSaveFile *in;
int i, j;
SaveGameHeader hdr;
int sb, sh;
byte *roomptr;
makeSavegameName(filename, slot, compat);
- if (!(in = _saveFileMan->openSavefile(filename, false)))
+ if (!(in = _saveFileMan->openForLoading(filename)))
return false;
in->read(&hdr, sizeof(hdr));
@@ -179,7 +179,7 @@ bool ScummEngine::loadState(int slot, bool compat) {
//
// Now do the actual loading
//
- Serializer ser(in, false, hdr.ver);
+ Serializer ser(in, 0, hdr.ver);
saveOrLoad(&ser, hdr.ver);
delete in;
@@ -349,17 +349,17 @@ void ScummEngine::listSavegames(bool *marks, int num) {
bool ScummEngine::getSavegameName(int slot, char *desc) {
char filename[256];
- SaveFile *out;
+ InSaveFile *in;
SaveGameHeader hdr;
int len;
makeSavegameName(filename, slot, false);
- if (!(out = _saveFileMan->openSavefile(filename, false))) {
+ if (!(in = _saveFileMan->openForLoading(filename))) {
strcpy(desc, "");
return false;
}
- len = out->read(&hdr, sizeof(hdr));
- delete out;
+ len = in->read(&hdr, sizeof(hdr));
+ delete in;
if (len != sizeof(hdr) || hdr.type != MKID('SCVM')) {
strcpy(desc, "Invalid savegame");
@@ -1010,35 +1010,35 @@ void ScummEngine::loadResource(Serializer *ser, int type, int idx) {
}
void Serializer::saveBytes(void *b, int len) {
- _saveLoadStream->write(b, len);
+ _saveStream->write(b, len);
}
void Serializer::loadBytes(void *b, int len) {
- _saveLoadStream->read(b, len);
+ _loadStream->read(b, len);
}
void Serializer::saveUint32(uint32 d) {
- _saveLoadStream->writeUint32LE(d);
+ _saveStream->writeUint32LE(d);
}
void Serializer::saveUint16(uint16 d) {
- _saveLoadStream->writeUint16LE(d);
+ _saveStream->writeUint16LE(d);
}
void Serializer::saveByte(byte b) {
- _saveLoadStream->writeByte(b);
+ _saveStream->writeByte(b);
}
uint32 Serializer::loadUint32() {
- return _saveLoadStream->readUint32LE();
+ return _loadStream->readUint32LE();
}
uint16 Serializer::loadUint16() {
- return _saveLoadStream->readUint16LE();
+ return _loadStream->readUint16LE();
}
byte Serializer::loadByte() {
- return _saveLoadStream->readByte();
+ return _loadStream->readByte();
}
void Serializer::saveArrayOf(void *b, int len, int datasize, byte filetype) {
diff --git a/scumm/saveload.h b/scumm/saveload.h
index bc6cfa8522..2d9fbced8f 100644
--- a/scumm/saveload.h
+++ b/scumm/saveload.h
@@ -24,7 +24,8 @@
#include "common/scummsys.h"
-class SaveFile;
+class InSaveFile;
+class OutSaveFile;
namespace Scumm {
@@ -94,9 +95,8 @@ typedef void *SerializerLoadReference(void *me, byte type, int ref);
class Serializer {
public:
- Serializer(SaveFile *stream, bool saveOrLoad, uint32 savegameVersion)
- : _save_ref(0), _load_ref(0), _ref_me(0),
- _saveLoadStream(stream), _saveOrLoad(saveOrLoad),
+ Serializer(InSaveFile *in, OutSaveFile *out, uint32 savegameVersion)
+ : _loadStream(in), _saveStream(out), _save_ref(0), _load_ref(0), _ref_me(0),
_savegameVersion(savegameVersion)
{ }
@@ -108,8 +108,8 @@ public:
void saveLoadArrayOf(void *b, int num, int datasize, const SaveLoadEntry *sle);
void saveLoadEntries(void *d, const SaveLoadEntry *sle);
- bool isSaving() { return _saveOrLoad; }
- bool isLoading() { return !_saveOrLoad; }
+ bool isSaving() { return (_saveStream != 0); }
+ bool isLoading() { return (_loadStream != 0); }
uint32 getVersion() { return _savegameVersion; }
void saveUint32(uint32 d);
@@ -124,8 +124,8 @@ public:
void loadBytes(void *b, int len);
protected:
- SaveFile *_saveLoadStream;
- bool _saveOrLoad;
+ InSaveFile *_loadStream;
+ OutSaveFile *_saveStream;
uint32 _savegameVersion;
void saveArrayOf(void *b, int len, int datasize, byte filetype);
diff --git a/scumm/script_v5.cpp b/scumm/script_v5.cpp
index 5e4a45ede5..71b006ff00 100644
--- a/scumm/script_v5.cpp
+++ b/scumm/script_v5.cpp
@@ -1176,7 +1176,7 @@ void ScummEngine_v5::o5_saveLoadGame() {
listSavegames(avail_saves, ARRAYSIZE(avail_saves));
makeSavegameName(filename, slot, false);
- if (avail_saves[slot] && (_saveFileMan->openSavefile(filename, false)))
+ if (avail_saves[slot] && (_saveFileMan->openForLoading(filename)))
result = 6; // save file exists
else
result = 7; // save file does not exist
@@ -1948,14 +1948,14 @@ void ScummEngine_v5::o5_roomOps() {
case 13: // SO_SAVE_STRING
{
- SaveFile *file;
+ OutSaveFile *file;
char filename[256], *s;
a = getVarOrDirectByte(PARAM_1);
s = filename;
while ((*s++ = fetchScriptByte()));
- file = _saveFileMan->openSavefile(filename, true);
+ file = _saveFileMan->openForSaving(filename);
if (file != NULL) {
byte *ptr;
ptr = getResourceAddress(rtString, a);
@@ -1967,14 +1967,14 @@ void ScummEngine_v5::o5_roomOps() {
}
case 14: // SO_LOAD_STRING
{
- SaveFile *file;
+ InSaveFile *file;
char filename[256], *s;
a = getVarOrDirectByte(PARAM_1);
s = filename;
while ((*s++ = fetchScriptByte()));
- file = _saveFileMan->openSavefile(filename, false);
+ file = _saveFileMan->openForLoading(filename);
if (file != NULL) {
byte *ptr;
int len = 256, cnt = 0;