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         gameWindowThumbnail(nullptr) {
00046 }
00047 
00048 void SaveMetadata::saveLoad(ResourceSerializer *s) {
00049     s->syncAsString32(description);
00050     syncResourceIndexAsString(s, levelIndex);
00051     syncResourceIndexAsString(s, locationIndex);
00052     _readErrorCode = syncVersion(s);
00053 
00054     if (_readErrorCode != Common::kNoError) {
00055         return;
00056     }
00057 
00058     if (version >= 9) {
00059         s->syncAsByte(saveDay);
00060         s->syncAsByte(saveMonth);
00061         s->syncAsUint16BE(saveYear);
00062         s->syncAsByte(saveHour);
00063         s->syncAsByte(saveMinute);
00064         s->syncAsSint32LE(totalPlayTime);
00065     }
00066 
00067     if (version >= 10) {
00068         s->syncAsByte(saveSecond);
00069     }
00070 }
00071 
00072 Common::ErrorCode SaveMetadata::read(Common::SeekableReadStream *stream, const Common::String &filename) {
00073     _readFilename = filename;
00074     ResourceSerializer s(stream, nullptr, 0);
00075     saveLoad(&s);
00076     return _readErrorCode;
00077 }
00078 
00079 void SaveMetadata::write(Common::WriteStream *stream) {
00080     ResourceSerializer s(nullptr, stream, 0);
00081     saveLoad(&s);
00082 }
00083 
00084 void SaveMetadata::syncResourceIndexAsString(ResourceSerializer *s, uint &index) {
00085     Common::String indexRaw = Common::String::format("%02x", index);
00086     s->syncAsString32(indexRaw);
00087     if (s->isLoading()) {
00088         index = strtol(indexRaw.c_str(), nullptr, 16);
00089     }
00090 }
00091 
00092 Common::ErrorCode SaveMetadata::syncVersion(ResourceSerializer *s) {
00093     Common::String versionRaw = Common::String::format("Version:\t%02d", version);
00094     s->syncAsString32(versionRaw);
00095 
00096     if (s->isLoading()) {
00097         if (!versionRaw.hasPrefix("Version:\t")) {
00098             warning("The save file '%s' does not match the expected format", _readFilename.c_str());
00099             return Common::kReadingFailed;
00100         }
00101 
00102         version = atoi(&(versionRaw.c_str()[8]));
00103         if (version < StateProvider::kMinSaveVersion || version > StateProvider::kSaveVersion) {
00104             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.",
00105                     _readFilename.c_str(), version, StateProvider::kMinSaveVersion, StateProvider::kSaveVersion);
00106             return Common::kReadingFailed;
00107         }
00108     }
00109 
00110     return Common::kNoError;
00111 }
00112 
00113 void SaveMetadata::setSaveTime(const TimeDate &timeDate) {
00114     saveDay = timeDate.tm_mday;
00115     saveMonth = timeDate.tm_mon + 1;
00116     saveYear = timeDate.tm_year + 1900;
00117     saveHour = timeDate.tm_hour;
00118     saveMinute = timeDate.tm_min;
00119     saveSecond = timeDate.tm_sec;
00120 }
00121 
00122 void SaveMetadata::writeGameScreenThumbnail(Common::WriteStream *stream) {
00123     assert(gameWindowThumbnail);
00124     assert(gameWindowThumbnail->pitch * gameWindowThumbnail->h == UserInterface::kThumbnailSize);
00125 
00126     stream->write((const byte *)gameWindowThumbnail->getPixels(), UserInterface::kThumbnailSize);
00127 }
00128 
00129 void SaveMetadata::skipGameScreenThumbnail(Common::SeekableReadStream *stream) {
00130     stream->skip(UserInterface::kThumbnailSize);
00131 }
00132 
00133 Graphics::Surface *SaveMetadata::readGameScreenThumbnail(Common::SeekableReadStream *stream) {
00134     Graphics::Surface *thumb = new Graphics::Surface();
00135     thumb->create(UserInterface::kThumbnailWidth, UserInterface::kThumbnailHeight, Gfx::Driver::getRGBAPixelFormat());
00136 
00137     stream->read(thumb->getPixels(), UserInterface::kThumbnailSize);
00138 
00139     return thumb;
00140 }
00141 
00142 } // End of namespace Stark


Generated on Sat Feb 23 2019 05:01:15 for ResidualVM by doxygen 1.7.1
curved edge   curved edge