mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-13 21:31:53 +00:00
Implementing saving/loading for Fascination. Tested in the DOS floppy versions and the Amiga version
svn-id: r47845
This commit is contained in:
parent
e7d5849ac8
commit
9cad13957d
@ -378,8 +378,7 @@ bool GobEngine::initGameParts() {
|
||||
_map = new Map_v2(this);
|
||||
_goblin = new Goblin_v2(this);
|
||||
_scenery = new Scenery_v2(this);
|
||||
_saveLoad = new SaveLoad_v2(this, _targetName.c_str());
|
||||
// _saveLoad = new SaveLoad_Fascination(this, _targetName.c_str());
|
||||
_saveLoad = new SaveLoad_Fascination(this, _targetName.c_str());
|
||||
break;
|
||||
|
||||
case kGameTypeWeen:
|
||||
|
@ -66,6 +66,7 @@ MODULE_OBJS := \
|
||||
save/saveload_v3.o \
|
||||
save/saveload_v4.o \
|
||||
save/saveload_v6.o \
|
||||
save/saveload_fascin.o \
|
||||
save/saveload_playtoons.o \
|
||||
save/saveconverter.o \
|
||||
save/saveconverter_v2.o \
|
||||
|
@ -153,6 +153,7 @@ protected:
|
||||
struct SaveFile {
|
||||
const char *sourceName;
|
||||
SaveMode mode;
|
||||
int slot;
|
||||
SaveHandler *handler;
|
||||
const char *description;
|
||||
};
|
||||
@ -160,7 +161,7 @@ protected:
|
||||
/** Handles the save slots. */
|
||||
class GameHandler : public SaveHandler {
|
||||
public:
|
||||
GameHandler(GobEngine *vm, const char *target);
|
||||
GameHandler(GobEngine *vm, const char *target, int slot, byte *index, bool *hasIndex);
|
||||
~GameHandler();
|
||||
|
||||
int32 getSize();
|
||||
@ -178,17 +179,20 @@ protected:
|
||||
int getSlotRemainder(int32 offset) const;
|
||||
};
|
||||
|
||||
byte _index[kIndexSize];
|
||||
bool _hasIndex;
|
||||
byte *_index;
|
||||
bool *_hasIndex;
|
||||
int _slot;
|
||||
|
||||
File *_slotFile;
|
||||
|
||||
void buildIndex(byte *buffer) const;
|
||||
};
|
||||
|
||||
byte _index[kIndexSize];
|
||||
bool _hasIndex;
|
||||
|
||||
static SaveFile _saveFiles[];
|
||||
|
||||
GameHandler *_gameHandler;
|
||||
NotesHandler *_notesHandler;
|
||||
TempSpriteHandler *_tempSpriteHandler;
|
||||
|
||||
|
@ -31,22 +31,22 @@
|
||||
namespace Gob {
|
||||
|
||||
SaveLoad_Fascination::SaveFile SaveLoad_Fascination::_saveFiles[] = {
|
||||
{ "cat.cat", kSaveModeSave, 0, "savegame catalog"},
|
||||
{ "save0.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save1.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save2.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save3.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save4.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save5.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save6.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save7.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save8.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save9.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save10.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save11.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save12.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save13.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "save14.inf", kSaveModeSave, 0, "savegame"},
|
||||
{ "cat.cat", kSaveModeSave, -1, 0, "savegame catalog"},
|
||||
{ "save0.inf", kSaveModeSave, 0, 0, "savegame"},
|
||||
{ "save1.inf", kSaveModeSave, 1, 0, "savegame"},
|
||||
{ "save2.inf", kSaveModeSave, 2, 0, "savegame"},
|
||||
{ "save3.inf", kSaveModeSave, 3, 0, "savegame"},
|
||||
{ "save4.inf", kSaveModeSave, 4, 0, "savegame"},
|
||||
{ "save5.inf", kSaveModeSave, 5, 0, "savegame"},
|
||||
{ "save6.inf", kSaveModeSave, 6, 0, "savegame"},
|
||||
{ "save7.inf", kSaveModeSave, 7, 0, "savegame"},
|
||||
{ "save8.inf", kSaveModeSave, 8, 0, "savegame"},
|
||||
{ "save9.inf", kSaveModeSave, 9, 0, "savegame"},
|
||||
{ "save10.inf", kSaveModeSave, 10, 0, "savegame"},
|
||||
{ "save11.inf", kSaveModeSave, 11, 0, "savegame"},
|
||||
{ "save12.inf", kSaveModeSave, 12, 0, "savegame"},
|
||||
{ "save13.inf", kSaveModeSave, 13, 0, "savegame"},
|
||||
{ "save14.inf", kSaveModeSave, 14, 0, "savegame"},
|
||||
};
|
||||
|
||||
|
||||
@ -58,27 +58,21 @@ SaveLoad_Fascination::GameHandler::File::~File() {
|
||||
}
|
||||
|
||||
int SaveLoad_Fascination::GameHandler::File::getSlot(int32 offset) const {
|
||||
uint32 varSize = SaveHandler::getVarSize(_vm);
|
||||
|
||||
if (varSize == 0)
|
||||
return -1;
|
||||
|
||||
return ((offset - kIndexSize) / varSize);
|
||||
return ((offset - kIndexSize) / 320);
|
||||
}
|
||||
|
||||
int SaveLoad_Fascination::GameHandler::File::getSlotRemainder(int32 offset) const {
|
||||
uint32 varSize = SaveHandler::getVarSize(_vm);
|
||||
|
||||
if (varSize == 0)
|
||||
return -1;
|
||||
|
||||
return ((offset - kIndexSize) % varSize);
|
||||
return ((offset - kIndexSize) % 320);
|
||||
}
|
||||
|
||||
|
||||
SaveLoad_Fascination::GameHandler::GameHandler(GobEngine *vm, const char *target) : SaveHandler(vm) {
|
||||
memset(_index, 0, kIndexSize);
|
||||
_hasIndex = false;
|
||||
SaveLoad_Fascination::GameHandler::GameHandler(GobEngine *vm, const char *target,
|
||||
int slot, byte *index, bool *hasIndex) : SaveHandler(vm) {
|
||||
|
||||
_index = index;
|
||||
_hasIndex = hasIndex;
|
||||
|
||||
_slot = slot;
|
||||
|
||||
_slotFile = new File(vm, target);
|
||||
}
|
||||
@ -108,7 +102,7 @@ bool SaveLoad_Fascination::GameHandler::load(int16 dataVar, int32 size, int32 of
|
||||
size = varSize;
|
||||
}
|
||||
|
||||
if (offset == 0) {
|
||||
if ((offset == 0) && (_slot == -1)) {
|
||||
// Save index
|
||||
|
||||
if (((uint32) size) != kIndexSize) {
|
||||
@ -120,16 +114,18 @@ bool SaveLoad_Fascination::GameHandler::load(int16 dataVar, int32 size, int32 of
|
||||
buildIndex(_vm->_inter->_variables->getAddressOff8(dataVar));
|
||||
|
||||
} else {
|
||||
// Save slot, whole variable block
|
||||
// Load slot
|
||||
|
||||
uint32 slot = _slotFile->getSlot(offset);
|
||||
int slotRem = _slotFile->getSlotRemainder(offset);
|
||||
uint32 slot = _slot;
|
||||
int slotRem = 0;
|
||||
if (_slot == -1) {
|
||||
slot = _slotFile->getSlot(offset);
|
||||
slotRem = _slotFile->getSlotRemainder(offset);
|
||||
}
|
||||
|
||||
debugC(2, kDebugSaveLoad, "Loading from slot %d", slot);
|
||||
|
||||
if ((slot >= kSlotCount) || (slotRem != 0) ||
|
||||
(dataVar != 0) || (((uint32) size) != varSize)) {
|
||||
|
||||
if ((slot >= kSlotCount) || (slotRem != 0) || (size != 320)) {
|
||||
warning("Invalid loading procedure (%d, %d, %d, %d, %d)",
|
||||
dataVar, size, offset, slot, slotRem);
|
||||
return false;
|
||||
@ -144,7 +140,7 @@ bool SaveLoad_Fascination::GameHandler::load(int16 dataVar, int32 size, int32 of
|
||||
|
||||
SavePartInfo info(kSlotNameLength, (uint32) _vm->getGameType(), 0,
|
||||
_vm->getEndianness(), varSize);
|
||||
SavePartVars vars(_vm, varSize);
|
||||
SavePartVars vars(_vm, size);
|
||||
|
||||
if (!reader->load()) {
|
||||
delete reader;
|
||||
@ -161,7 +157,7 @@ bool SaveLoad_Fascination::GameHandler::load(int16 dataVar, int32 size, int32 of
|
||||
}
|
||||
|
||||
// Get all variables
|
||||
if (!vars.writeInto(0, 0, varSize)) {
|
||||
if (!vars.writeInto(dataVar, 0, size)) {
|
||||
delete reader;
|
||||
return false;
|
||||
}
|
||||
@ -173,6 +169,10 @@ bool SaveLoad_Fascination::GameHandler::load(int16 dataVar, int32 size, int32 of
|
||||
}
|
||||
|
||||
bool SaveLoad_Fascination::GameHandler::save(int16 dataVar, int32 size, int32 offset) {
|
||||
if ((_slot == -1) && (offset == 0) && (size == 5400))
|
||||
// Initialize empty file
|
||||
return true;
|
||||
|
||||
uint32 varSize = SaveHandler::getVarSize(_vm);
|
||||
|
||||
if (varSize == 0)
|
||||
@ -184,7 +184,7 @@ bool SaveLoad_Fascination::GameHandler::save(int16 dataVar, int32 size, int32 of
|
||||
size = varSize;
|
||||
}
|
||||
|
||||
if (offset == 0) {
|
||||
if ((offset == 0) && (_slot == -1)) {
|
||||
// Save index
|
||||
|
||||
if (((uint32) size) != kIndexSize) {
|
||||
@ -194,43 +194,45 @@ bool SaveLoad_Fascination::GameHandler::save(int16 dataVar, int32 size, int32 of
|
||||
|
||||
// Just copy the index into our buffer
|
||||
_vm->_inter->_variables->copyTo(dataVar, _index, kIndexSize);
|
||||
_hasIndex = true;
|
||||
*_hasIndex = true;
|
||||
|
||||
} else {
|
||||
// Save slot, whole variable block
|
||||
// Save slot
|
||||
|
||||
uint32 slot = _slotFile->getSlot(offset);
|
||||
int slotRem = _slotFile->getSlotRemainder(offset);
|
||||
uint32 slot = _slot;
|
||||
int slotRem = 0;
|
||||
if (_slot == -1) {
|
||||
slot = _slotFile->getSlot(offset);
|
||||
slotRem = _slotFile->getSlotRemainder(offset);
|
||||
}
|
||||
|
||||
debugC(2, kDebugSaveLoad, "Saving to slot %d", slot);
|
||||
|
||||
if ((slot >= kSlotCount) || (slotRem != 0) ||
|
||||
(dataVar != 0) || (((uint32) size) != varSize)) {
|
||||
|
||||
if ((slot >= kSlotCount) || (slotRem != 0) || (size != 320)) {
|
||||
warning("Invalid saving procedure (%d, %d, %d, %d, %d)",
|
||||
dataVar, size, offset, slot, slotRem);
|
||||
return false;
|
||||
}
|
||||
|
||||
// An index is needed for the save slot description
|
||||
if (!_hasIndex) {
|
||||
if (!*_hasIndex) {
|
||||
warning("No index written yet");
|
||||
return false;
|
||||
}
|
||||
|
||||
_hasIndex = false;
|
||||
*_hasIndex = false;
|
||||
|
||||
Common::String slotFile = _slotFile->build(slot);
|
||||
|
||||
SaveWriter writer(2, slot, slotFile);
|
||||
SavePartInfo info(kSlotNameLength, (uint32) _vm->getGameType(), 0,
|
||||
_vm->getEndianness(), varSize);
|
||||
SavePartVars vars(_vm, varSize);
|
||||
SavePartVars vars(_vm, size);
|
||||
|
||||
// Write the description
|
||||
info.setDesc(_index + (slot * kSlotNameLength), kSlotNameLength);
|
||||
// Write all variables
|
||||
if (!vars.readFrom(0, 0, varSize))
|
||||
if (!vars.readFrom(dataVar, 0, size))
|
||||
return false;
|
||||
|
||||
if (!writer.writePart(0, &info))
|
||||
@ -258,28 +260,16 @@ void SaveLoad_Fascination::GameHandler::buildIndex(byte *buffer) const {
|
||||
SaveLoad_Fascination::SaveLoad_Fascination(GobEngine *vm, const char *targetName) :
|
||||
SaveLoad(vm) {
|
||||
|
||||
_gameHandler = new GameHandler(vm, targetName);
|
||||
memset(_index, 0, kIndexSize);
|
||||
_hasIndex = false;
|
||||
|
||||
_saveFiles[0].handler = _gameHandler;
|
||||
_saveFiles[1].handler = _gameHandler;
|
||||
_saveFiles[2].handler = _gameHandler;
|
||||
_saveFiles[3].handler = _gameHandler;
|
||||
_saveFiles[4].handler = _gameHandler;
|
||||
_saveFiles[5].handler = _gameHandler;
|
||||
_saveFiles[6].handler = _gameHandler;
|
||||
_saveFiles[7].handler = _gameHandler;
|
||||
_saveFiles[8].handler = _gameHandler;
|
||||
_saveFiles[9].handler = _gameHandler;
|
||||
_saveFiles[10].handler = _gameHandler;
|
||||
_saveFiles[11].handler = _gameHandler;
|
||||
_saveFiles[12].handler = _gameHandler;
|
||||
_saveFiles[13].handler = _gameHandler;
|
||||
_saveFiles[14].handler = _gameHandler;
|
||||
_saveFiles[15].handler = _gameHandler;
|
||||
for (int i = 0; i < 16; i++)
|
||||
_saveFiles[i].handler = new GameHandler(vm, targetName, _saveFiles[i].slot, _index, &_hasIndex);
|
||||
}
|
||||
|
||||
SaveLoad_Fascination::~SaveLoad_Fascination() {
|
||||
delete _gameHandler;
|
||||
for (int i = 0; i < 16; i++)
|
||||
delete _saveFiles[i].handler;
|
||||
}
|
||||
|
||||
const SaveLoad_Fascination::SaveFile *SaveLoad_Fascination::getSaveFile(const char *fileName) const {
|
||||
|
Loading…
Reference in New Issue
Block a user