diff options
author | Andrei Prykhodko | 2018-06-26 16:01:38 +0300 |
---|---|---|
committer | Eugene Sandulenko | 2018-06-28 23:51:32 +0200 |
commit | 98e7bdee4b3a3e527d4e5e2a38c3757cc9622ec9 (patch) | |
tree | a87b611a9e50ce1cc8c450f225438770505ae4c1 | |
parent | 8293b97e76f41bfd570b1f80041b73443b2546bd (diff) | |
download | scummvm-rg350-98e7bdee4b3a3e527d4e5e2a38c3757cc9622ec9.tar.gz scummvm-rg350-98e7bdee4b3a3e527d4e5e2a38c3757cc9622ec9.tar.bz2 scummvm-rg350-98e7bdee4b3a3e527d4e5e2a38c3757cc9622ec9.zip |
PINK: move save/load engine functions to separate file
-rw-r--r-- | engines/pink/module.mk | 1 | ||||
-rw-r--r-- | engines/pink/pink.cpp | 87 | ||||
-rw-r--r-- | engines/pink/saveload.cpp | 117 |
3 files changed, 118 insertions, 87 deletions
diff --git a/engines/pink/module.mk b/engines/pink/module.mk index 002159aac7..ab9cc89624 100644 --- a/engines/pink/module.mk +++ b/engines/pink/module.mk @@ -12,6 +12,7 @@ MODULE_OBJS = \ pda_mgr.o \ pink.o \ resource_mgr.o \ + saveload.o \ sound.o \ objects/object.o \ objects/module.o \ diff --git a/engines/pink/pink.cpp b/engines/pink/pink.cpp index 358dce6958..dd7b1cf51f 100644 --- a/engines/pink/pink.cpp +++ b/engines/pink/pink.cpp @@ -260,62 +260,10 @@ void PinkEngine::setCursor(uint cursorIndex) { _system->updateScreen(); } -Common::Error PinkEngine::loadGameState(int slot) { - Common::SeekableReadStream *in = _saveFileMan->openForLoading(generateSaveName(slot, _targetName.c_str())); - if (!in) - return Common::kNoGameDataFoundError; - - SaveStateDescriptor desc; - if (!readSaveHeader(*in, desc)) - return Common::kUnknownError; - - Archive archive(in); - _variables.deserialize(archive); - _nextModule = archive.readString(); - _nextPage = archive.readString(); - initModule(archive.readString(), "", &archive); - - delete in; - return Common::kNoError; -} - bool PinkEngine::canLoadGameStateCurrently() { return true; } -Common::Error PinkEngine::saveGameState(int slot, const Common::String &desc) { - Common::OutSaveFile *out = _saveFileMan->openForSaving(generateSaveName(slot, _targetName.c_str())); - if (!out) - return Common::kUnknownError; - - Archive archive(out); - - out->write("pink", 4); - archive.writeString(desc); - - TimeDate curTime; - _system->getTimeAndDate(curTime); - - out->writeUint32LE(((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF)); - out->writeUint16LE(((curTime.tm_hour & 0xFF) << 8) | ((curTime.tm_min) & 0xFF)); - - out->writeUint32LE(getTotalPlayTime() / 1000); - - if (!Graphics::saveThumbnail(*out)) - return Common::kUnknownError; - - _variables.serialize(archive); - archive.writeString(_nextModule); - archive.writeString(_nextPage); - - archive.writeString(_module->getName()); - _module->saveState(archive); - - delete out; - - return Common::kNoError; -} - bool PinkEngine::canSaveGameStateCurrently() { return true; } @@ -336,39 +284,4 @@ bool PinkEngine::isPeril() { return !strcmp(_desc.gameId, "peril"); } -Common::String generateSaveName(int slot, const char *gameId) { - return Common::String::format("%s.s%02d", gameId, slot); -} - -bool readSaveHeader(Common::InSaveFile &in, SaveStateDescriptor &desc) { - if (in.readUint32BE() != MKTAG('p', 'i', 'n', 'k')) - return false; - - const Common::String description = in.readPascalString(); - uint32 date = in.readUint32LE(); - uint16 time = in.readUint16LE(); - uint32 playTime = in.readUint32LE(); - if (!Graphics::checkThumbnailHeader(in)) - return false; - - Graphics::Surface *thumbnail; - if (!Graphics::loadThumbnail(in, thumbnail)) - return false; - - int day = (date >> 24) & 0xFF; - int month = (date >> 16) & 0xFF; - int year = date & 0xFFFF; - - int hour = (time >> 8) & 0xFF; - int minutes = time & 0xFF; - - desc.setSaveDate(year, month, day); - desc.setSaveTime(hour, minutes); - desc.setPlayTime(playTime * 1000); - desc.setDescription(description); - desc.setThumbnail(thumbnail); - - return true; -} - } diff --git a/engines/pink/saveload.cpp b/engines/pink/saveload.cpp new file mode 100644 index 0000000000..506eacab69 --- /dev/null +++ b/engines/pink/saveload.cpp @@ -0,0 +1,117 @@ +/* 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 "graphics/thumbnail.h" + +#include "pink/pink.h" +#include "pink/objects/module.h" + +namespace Pink { + +Common::Error PinkEngine::loadGameState(int slot) { + Common::SeekableReadStream *in = _saveFileMan->openForLoading(generateSaveName(slot, _targetName.c_str())); + if (!in) + return Common::kNoGameDataFoundError; + + SaveStateDescriptor desc; + if (!readSaveHeader(*in, desc)) + return Common::kUnknownError; + + Archive archive(in); + _variables.deserialize(archive); + _nextModule = archive.readString(); + _nextPage = archive.readString(); + initModule(archive.readString(), "", &archive); + + delete in; + return Common::kNoError; +} + +Common::Error PinkEngine::saveGameState(int slot, const Common::String &desc) { + Common::OutSaveFile *out = _saveFileMan->openForSaving(generateSaveName(slot, _targetName.c_str())); + if (!out) + return Common::kUnknownError; + + Archive archive(out); + + out->write("pink", 4); + archive.writeString(desc); + + TimeDate curTime; + _system->getTimeAndDate(curTime); + + out->writeUint32LE(((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF)); + out->writeUint16LE(((curTime.tm_hour & 0xFF) << 8) | ((curTime.tm_min) & 0xFF)); + + out->writeUint32LE(getTotalPlayTime() / 1000); + + if (!Graphics::saveThumbnail(*out)) + return Common::kUnknownError; + + _variables.serialize(archive); + archive.writeString(_nextModule); + archive.writeString(_nextPage); + + archive.writeString(_module->getName()); + _module->saveState(archive); + + delete out; + + return Common::kNoError; +} + +Common::String generateSaveName(int slot, const char *gameId) { + return Common::String::format("%s.s%02d", gameId, slot); +} + +bool readSaveHeader(Common::InSaveFile &in, SaveStateDescriptor &desc) { + if (in.readUint32BE() != MKTAG('p', 'i', 'n', 'k')) + return false; + + const Common::String description = in.readPascalString(); + uint32 date = in.readUint32LE(); + uint16 time = in.readUint16LE(); + uint32 playTime = in.readUint32LE(); + if (!Graphics::checkThumbnailHeader(in)) + return false; + + Graphics::Surface *thumbnail; + if (!Graphics::loadThumbnail(in, thumbnail)) + return false; + + int day = (date >> 24) & 0xFF; + int month = (date >> 16) & 0xFF; + int year = date & 0xFFFF; + + int hour = (time >> 8) & 0xFF; + int minutes = time & 0xFF; + + desc.setSaveDate(year, month, day); + desc.setSaveTime(hour, minutes); + desc.setPlayTime(playTime * 1000); + desc.setDescription(description); + desc.setThumbnail(thumbnail); + + return true; +} + +} |