ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

savemetadata.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/savemetadata.h"
00024 
00025 #include "engines/stark/gfx/driver.h"
00026 #include "engines/stark/services/stateprovider.h"
00027 #include "engines/stark/services/userinterface.h"
00028 
00029 #include "graphics/surface.h"
00030 
00031 namespace Stark {
00032 
00033 SaveMetadata::SaveMetadata() :
00034         _readErrorCode(Common::kNoError),
00035         levelIndex(0),
00036         locationIndex(0),
00037         version(0),
00038         totalPlayTime(0),
00039         saveYear(0),
00040         saveMonth(0),
00041         saveDay(0),
00042         saveHour(0),
00043         saveMinute(0),
00044         saveSecond(0),
00045         isAutoSave(false),
00046         gameWindowThumbnail(nullptr) {
00047 }
00048 
00049 void SaveMetadata::saveLoad(ResourceSerializer *s) {
00050     s->syncAsString32(description);
00051     syncResourceIndexAsString(s, levelIndex);
00052     syncResourceIndexAsString(s, locationIndex);
00053     _readErrorCode = syncVersion(s);
00054 
00055     if (_readErrorCode != Common::kNoError) {
00056         return;
00057     }
00058 
00059     if (version >= 9) {
00060         s->syncAsByte(saveDay);
00061         s->syncAsByte(saveMonth);
00062         s->syncAsUint16BE(saveYear);
00063         s->syncAsByte(saveHour);
00064         s->syncAsByte(saveMinute);
00065         s->syncAsSint32LE(totalPlayTime);
00066     }
00067 
00068     if (version >= 10) {
00069         s->syncAsByte(saveSecond);
00070     }
00071 
00072     if (version >= 13) {
00073         s->syncAsUint32LE(isAutoSave);
00074     }
00075 }
00076 
00077 Common::ErrorCode SaveMetadata::read(Common::SeekableReadStream *stream, const Common::String &filename) {
00078     _readFilename = filename;
00079     ResourceSerializer s(stream, nullptr, 0);
00080     saveLoad(&s);
00081     return _readErrorCode;
00082 }
00083 
00084 void SaveMetadata::write(Common::WriteStream *stream) {
00085     ResourceSerializer s(nullptr, stream, 0);
00086     saveLoad(&s);
00087 }
00088 
00089 void SaveMetadata::syncResourceIndexAsString(ResourceSerializer *s, uint &index) {
00090     Common::String indexRaw = Common::String::format("%02x", index);
00091     s->syncAsString32(indexRaw);
00092     if (s->isLoading()) {
00093         index = strtol(indexRaw.c_str(), nullptr, 16);
00094     }
00095 }
00096 
00097 Common::ErrorCode SaveMetadata::syncVersion(ResourceSerializer *s) {
00098     Common::String versionRaw = Common::String::format("Version:\t%02d", version);
00099     s->syncAsString32(versionRaw);
00100 
00101     if (s->isLoading()) {
00102         if (!versionRaw.hasPrefix("Version:\t")) {
00103             warning("The save file '%s' does not match the expected format", _readFilename.c_str());
00104             return Common::kReadingFailed;
00105         }
00106 
00107         version = atoi(&(versionRaw.c_str()[8]));
00108         if (version < StateProvider::kMinSaveVersion || version > StateProvider::kSaveVersion) {
00109             warning("The save file '%s' version (v%d) is not supported by this version of ResidualVM. Only versions v%d to v%d are allowed.",
00110                     _readFilename.c_str(), version, StateProvider::kMinSaveVersion, StateProvider::kSaveVersion);
00111             return Common::kReadingFailed;
00112         }
00113     }
00114 
00115     return Common::kNoError;
00116 }
00117 
00118 void SaveMetadata::setSaveTime(const TimeDate &timeDate) {
00119     saveDay = timeDate.tm_mday;
00120     saveMonth = timeDate.tm_mon + 1;
00121     saveYear = timeDate.tm_year + 1900;
00122     saveHour = timeDate.tm_hour;
00123     saveMinute = timeDate.tm_min;
00124     saveSecond = timeDate.tm_sec;
00125 }
00126 
00127 void SaveMetadata::writeGameScreenThumbnail(Common::WriteStream *stream) {
00128     assert(gameWindowThumbnail);
00129     assert(gameWindowThumbnail->pitch * gameWindowThumbnail->h == UserInterface::kThumbnailSize);
00130 
00131     stream->write((const byte *)gameWindowThumbnail->getPixels(), UserInterface::kThumbnailSize);
00132 }
00133 
00134 void SaveMetadata::skipGameScreenThumbnail(Common::SeekableReadStream *stream) {
00135     stream->skip(UserInterface::kThumbnailSize);
00136 }
00137 
00138 Graphics::Surface *SaveMetadata::readGameScreenThumbnail(Common::SeekableReadStream *stream) {
00139     Graphics::Surface *thumb = new Graphics::Surface();
00140     thumb->create(UserInterface::kThumbnailWidth, UserInterface::kThumbnailHeight, Gfx::Driver::getRGBAPixelFormat());
00141 
00142     stream->read(thumb->getPixels(), UserInterface::kThumbnailSize);
00143 
00144     return thumb;
00145 }
00146 
00147 } // End of namespace Stark


Generated on Sat Sep 26 2020 05:01:05 for ResidualVM by doxygen 1.7.1
curved edge   curved edge