2012-10-24 11:49:32 +00:00
|
|
|
/* 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.
|
2014-02-18 01:34:21 +00:00
|
|
|
*
|
2012-10-24 11:49:32 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:21 +00:00
|
|
|
*
|
2012-10-24 11:49:32 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-02-15 21:20:24 +00:00
|
|
|
#include "hopkins/saveload.h"
|
|
|
|
|
|
|
|
#include "hopkins/files.h"
|
|
|
|
#include "hopkins/globals.h"
|
|
|
|
#include "hopkins/hopkins.h"
|
|
|
|
|
|
|
|
|
2012-10-24 11:49:32 +00:00
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/savefile.h"
|
2012-10-27 09:19:21 +00:00
|
|
|
#include "graphics/surface.h"
|
|
|
|
#include "graphics/scaler.h"
|
|
|
|
#include "graphics/thumbnail.h"
|
2012-10-24 11:49:32 +00:00
|
|
|
|
|
|
|
namespace Hopkins {
|
|
|
|
|
2012-10-27 09:19:21 +00:00
|
|
|
const char *SAVEGAME_STR = "HOPKINS";
|
|
|
|
#define SAVEGAME_STR_SIZE 13
|
|
|
|
|
2013-03-20 07:06:10 +00:00
|
|
|
SaveLoadManager::SaveLoadManager(HopkinsEngine *vm) {
|
2012-10-24 11:49:32 +00:00
|
|
|
_vm = vm;
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:30:01 +00:00
|
|
|
bool SaveLoadManager::save(const Common::String &file, const void *buf, size_t n) {
|
2013-06-26 19:33:30 +00:00
|
|
|
Common::OutSaveFile *savefile = g_system->getSavefileManager()->openForSaving(file);
|
2012-10-24 11:49:32 +00:00
|
|
|
|
2013-06-26 19:33:30 +00:00
|
|
|
if (savefile) {
|
|
|
|
size_t bytesWritten = savefile->write(buf, n);
|
|
|
|
savefile->finalize();
|
|
|
|
delete savefile;
|
2012-10-24 11:49:32 +00:00
|
|
|
|
|
|
|
return bytesWritten == n;
|
2012-12-14 00:49:22 +00:00
|
|
|
} else
|
2012-10-24 11:49:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-01 01:01:04 +00:00
|
|
|
bool SaveLoadManager::saveExists(const Common::String &file) {
|
|
|
|
Common::InSaveFile *savefile = g_system->getSavefileManager()->openForLoading(file);
|
|
|
|
bool result = savefile != NULL;
|
|
|
|
delete savefile;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-10-24 11:49:32 +00:00
|
|
|
// Save File
|
2012-12-19 23:30:01 +00:00
|
|
|
bool SaveLoadManager::saveFile(const Common::String &file, const void *buf, size_t n) {
|
|
|
|
return save(file, buf, n);
|
2012-10-24 11:49:32 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 23:30:01 +00:00
|
|
|
void SaveLoadManager::load(const Common::String &file, byte *buf) {
|
2013-06-26 19:33:30 +00:00
|
|
|
Common::InSaveFile *savefile = g_system->getSavefileManager()->openForLoading(file);
|
|
|
|
if (savefile == NULL)
|
|
|
|
error("Error opening file - %s", file.c_str());
|
2012-10-24 12:20:26 +00:00
|
|
|
|
2013-06-26 19:33:30 +00:00
|
|
|
int32 filesize = savefile->size();
|
|
|
|
savefile->read(buf, filesize);
|
|
|
|
delete savefile;
|
2012-10-24 12:20:26 +00:00
|
|
|
}
|
|
|
|
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-05 22:06:38 +00:00
|
|
|
WARN_UNUSED_RESULT bool SaveLoadManager::readSavegameHeader(Common::InSaveFile *in, hopkinsSavegameHeader &header, bool skipThumbnail) {
|
2012-10-27 09:19:21 +00:00
|
|
|
char saveIdentBuffer[SAVEGAME_STR_SIZE + 1];
|
|
|
|
|
|
|
|
// Validate the header Id
|
|
|
|
in->read(saveIdentBuffer, SAVEGAME_STR_SIZE + 1);
|
|
|
|
if (strncmp(saveIdentBuffer, SAVEGAME_STR, SAVEGAME_STR_SIZE))
|
|
|
|
return false;
|
|
|
|
|
2012-12-19 23:30:01 +00:00
|
|
|
header._version = in->readByte();
|
|
|
|
if (header._version > HOPKINS_SAVEGAME_VERSION)
|
2012-10-27 09:19:21 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Read in the string
|
2012-12-19 23:30:01 +00:00
|
|
|
header._saveName.clear();
|
2012-10-27 09:19:21 +00:00
|
|
|
char ch;
|
2012-12-19 23:30:01 +00:00
|
|
|
while ((ch = (char)in->readByte()) != '\0') header._saveName += ch;
|
2012-10-27 09:19:21 +00:00
|
|
|
|
|
|
|
// Get the thumbnail
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-05 22:06:38 +00:00
|
|
|
if (!Graphics::loadThumbnail(*in, header._thumbnail, skipThumbnail)) {
|
2012-10-27 09:19:21 +00:00
|
|
|
return false;
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-05 22:06:38 +00:00
|
|
|
}
|
2012-10-27 09:19:21 +00:00
|
|
|
|
|
|
|
// Read in save date/time
|
2012-12-19 23:30:01 +00:00
|
|
|
header._year = in->readSint16LE();
|
|
|
|
header._month = in->readSint16LE();
|
|
|
|
header._day = in->readSint16LE();
|
|
|
|
header._hour = in->readSint16LE();
|
|
|
|
header._minute = in->readSint16LE();
|
|
|
|
header._totalFrames = in->readUint32LE();
|
2012-10-27 09:19:21 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveLoadManager::writeSavegameHeader(Common::OutSaveFile *out, hopkinsSavegameHeader &header) {
|
|
|
|
// Write out a savegame header
|
|
|
|
out->write(SAVEGAME_STR, SAVEGAME_STR_SIZE + 1);
|
|
|
|
|
|
|
|
out->writeByte(HOPKINS_SAVEGAME_VERSION);
|
|
|
|
|
|
|
|
// Write savegame name
|
2012-12-19 23:30:01 +00:00
|
|
|
out->write(header._saveName.c_str(), header._saveName.size() + 1);
|
2012-10-27 09:19:21 +00:00
|
|
|
|
|
|
|
// Create a thumbnail and save it
|
|
|
|
Graphics::Surface *thumb = new Graphics::Surface();
|
2012-10-27 11:16:54 +00:00
|
|
|
createThumbnail(thumb);
|
2012-10-27 09:19:21 +00:00
|
|
|
Graphics::saveThumbnail(*out, *thumb);
|
|
|
|
thumb->free();
|
|
|
|
delete thumb;
|
|
|
|
|
|
|
|
// Write out the save date/time
|
|
|
|
TimeDate td;
|
|
|
|
g_system->getTimeAndDate(td);
|
|
|
|
out->writeSint16LE(td.tm_year + 1900);
|
|
|
|
out->writeSint16LE(td.tm_mon + 1);
|
|
|
|
out->writeSint16LE(td.tm_mday);
|
|
|
|
out->writeSint16LE(td.tm_hour);
|
|
|
|
out->writeSint16LE(td.tm_min);
|
2013-04-10 08:27:06 +00:00
|
|
|
out->writeUint32LE(_vm->_events->_gameCounter);
|
2012-10-27 09:19:21 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 23:30:01 +00:00
|
|
|
Common::Error SaveLoadManager::saveGame(int slot, const Common::String &saveName) {
|
2012-10-28 04:46:52 +00:00
|
|
|
/* Pack any necessary data into the savegame data structure */
|
|
|
|
// Set the selected slot number
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->_saveData->_data[svLastSavegameSlot] = slot;
|
2012-10-28 04:46:52 +00:00
|
|
|
|
|
|
|
// Set up the inventory
|
|
|
|
for (int i = 0; i < 35; ++i)
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->_saveData->_inventory[i] = _vm->_globals->_inventory[i];
|
2012-10-28 04:46:52 +00:00
|
|
|
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_globals->_saveData->_mapCarPosX = _vm->_objectsMan->_mapCarPosX;
|
|
|
|
_vm->_globals->_saveData->_mapCarPosY = _vm->_objectsMan->_mapCarPosY;
|
2013-01-14 06:52:24 +00:00
|
|
|
|
2012-10-28 04:46:52 +00:00
|
|
|
/* Create the savegame */
|
2020-02-07 05:54:41 +00:00
|
|
|
Common::OutSaveFile *savefile = g_system->getSavefileManager()->openForSaving(
|
|
|
|
_vm->getSaveStateName(slot));
|
2013-01-02 15:04:15 +00:00
|
|
|
if (!savefile)
|
2012-10-27 11:16:54 +00:00
|
|
|
return Common::kCreatingFileFailed;
|
|
|
|
|
|
|
|
// Set up the serializer
|
2013-01-02 15:04:15 +00:00
|
|
|
Common::Serializer serializer(NULL, savefile);
|
2012-10-27 11:16:54 +00:00
|
|
|
|
|
|
|
// Write out the savegame header
|
|
|
|
hopkinsSavegameHeader header;
|
2012-12-19 23:30:01 +00:00
|
|
|
header._saveName = saveName;
|
|
|
|
header._version = HOPKINS_SAVEGAME_VERSION;
|
2013-01-02 15:04:15 +00:00
|
|
|
writeSavegameHeader(savefile, header);
|
2012-10-27 11:16:54 +00:00
|
|
|
|
|
|
|
// Write out the savegame data
|
2013-01-14 06:52:24 +00:00
|
|
|
syncSavegameData(serializer, header._version);
|
2012-10-27 11:16:54 +00:00
|
|
|
|
|
|
|
// Save file complete
|
2013-01-02 15:04:15 +00:00
|
|
|
savefile->finalize();
|
|
|
|
delete savefile;
|
2012-10-27 11:16:54 +00:00
|
|
|
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:30:01 +00:00
|
|
|
Common::Error SaveLoadManager::loadGame(int slot) {
|
2012-10-27 11:16:54 +00:00
|
|
|
// Try and open the save file for reading
|
2013-01-02 15:04:15 +00:00
|
|
|
Common::InSaveFile *savefile = g_system->getSavefileManager()->openForLoading(
|
2020-02-07 05:54:41 +00:00
|
|
|
_vm->getSaveStateName(slot));
|
2013-01-02 15:04:15 +00:00
|
|
|
if (!savefile)
|
2012-10-27 11:16:54 +00:00
|
|
|
return Common::kReadingFailed;
|
|
|
|
|
|
|
|
// Set up the serializer
|
2013-01-02 15:04:15 +00:00
|
|
|
Common::Serializer serializer(savefile, NULL);
|
2012-10-27 11:16:54 +00:00
|
|
|
|
|
|
|
// Read in the savegame header
|
|
|
|
hopkinsSavegameHeader header;
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-05 22:06:38 +00:00
|
|
|
if (!readSavegameHeader(savefile, header)) {
|
|
|
|
delete savefile;
|
|
|
|
return Common::kReadingFailed;
|
|
|
|
}
|
2012-10-27 11:16:54 +00:00
|
|
|
|
|
|
|
// Read in the savegame data
|
2013-01-14 06:52:24 +00:00
|
|
|
syncSavegameData(serializer, header._version);
|
2012-10-27 11:16:54 +00:00
|
|
|
|
|
|
|
// Loading save file complete
|
2013-01-02 15:04:15 +00:00
|
|
|
delete savefile;
|
2012-10-27 11:16:54 +00:00
|
|
|
|
2012-10-28 00:01:30 +00:00
|
|
|
// Unpack the inventory
|
2012-12-14 00:49:22 +00:00
|
|
|
for (int i = 0; i < 35; ++i)
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->_inventory[i] = _vm->_globals->_saveData->_inventory[i];
|
2012-10-28 00:01:30 +00:00
|
|
|
|
|
|
|
// Set variables from loaded data as necessary
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->_saveData->_data[svLastSavegameSlot] = slot;
|
|
|
|
_vm->_globals->_exitId = _vm->_globals->_saveData->_data[svLastScreenId];
|
|
|
|
_vm->_globals->_saveData->_data[svLastPrevScreenId] = 0;
|
|
|
|
_vm->_globals->_screenId = 0;
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_objectsMan->_mapCarPosX = _vm->_globals->_saveData->_mapCarPosX;
|
|
|
|
_vm->_objectsMan->_mapCarPosY = _vm->_globals->_saveData->_mapCarPosY;
|
2012-10-28 00:01:30 +00:00
|
|
|
|
2012-10-27 11:16:54 +00:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-05 22:06:38 +00:00
|
|
|
WARN_UNUSED_RESULT bool SaveLoadManager::readSavegameHeader(int slot, hopkinsSavegameHeader &header, bool skipThumbnail) {
|
2012-10-27 11:16:54 +00:00
|
|
|
// Try and open the save file for reading
|
2013-06-26 19:33:30 +00:00
|
|
|
Common::InSaveFile *savefile = g_system->getSavefileManager()->openForLoading(
|
2020-02-07 05:54:41 +00:00
|
|
|
_vm->getSaveStateName(slot));
|
2013-06-26 19:33:30 +00:00
|
|
|
if (!savefile)
|
2012-10-27 11:16:54 +00:00
|
|
|
return false;
|
|
|
|
|
ALL: Load savegame thumbnail only when necessary
This commit introduces the following changes:
1. Graphics::loadThumbnail()
Now returns a boolean and takes a new argument skipThumbnail which
defaults to false. In case of true, loadThumbnail() reads past the
thumbnail data in the input stream instead of actually loading the
thumbnail. This simplifies savegame handling where, up until now,
many engines always read the whole savegame metadata (including
the thumbnail) and then threw away the thumbnail when not needed
(which is in almost all cases, the most common exception being
MetaEngine::querySaveMetaInfos() which is responsible for loading
savegame metadata for displaying it in the GUI launcher.
2. readSavegameHeader()
Engines which already implement such a method (name varies) now take
a new argument skipThumbnail (default: true) which is passed
through to loadThumbnail(). This means that the default case for
readSavegameHeader() is now _not_ loading the thumbnail from a
savegame and just reading past it. In those cases, e.g.
querySaveMetaInfos(), where we actually are interested in loading
the thumbnail readSavegameHeader() needs to explicitely be called
with skipThumbnail == false.
Engines whose readSavegameHeader() (name varies) already takes an
argument loadThumbnail have been adapted to have a similar
prototype and semantics.
I.e. readSaveHeader(in, loadThumbnail, header) now is
readSaveHeader(in, header, skipThumbnail).
3. Error handling
Engines which previously did not check the return value of
readSavegameHeader() (name varies) now do so ensuring that possibly
broken savegames (be it a broken thumbnail or something else) don't
make it into the GUI launcher list in the first place.
2018-04-05 22:06:38 +00:00
|
|
|
bool result = readSavegameHeader(savefile, header, skipThumbnail);
|
2013-06-26 19:33:30 +00:00
|
|
|
delete savefile;
|
2012-10-27 11:16:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define REDUCE_AMOUNT 80
|
|
|
|
|
|
|
|
void SaveLoadManager::createThumbnail(Graphics::Surface *s) {
|
2013-04-10 08:27:06 +00:00
|
|
|
int w = _vm->_graphicsMan->zoomOut(SCREEN_WIDTH, REDUCE_AMOUNT);
|
|
|
|
int h = _vm->_graphicsMan->zoomOut(SCREEN_HEIGHT - 40, REDUCE_AMOUNT);
|
2012-10-27 11:16:54 +00:00
|
|
|
|
2012-11-30 12:15:47 +00:00
|
|
|
Graphics::Surface thumb8;
|
|
|
|
thumb8.create(w, h, Graphics::PixelFormat::createFormatCLUT8());
|
2012-10-27 11:16:54 +00:00
|
|
|
|
2013-08-03 00:39:37 +00:00
|
|
|
_vm->_graphicsMan->reduceScreenPart(_vm->_graphicsMan->_frontBuffer, (byte *)thumb8.getPixels(),
|
2013-04-10 08:27:06 +00:00
|
|
|
_vm->_events->_startPos.x, 20, SCREEN_WIDTH, SCREEN_HEIGHT - 40, 80);
|
2012-11-30 12:15:47 +00:00
|
|
|
|
|
|
|
// Convert the 8-bit pixel to 16 bit surface
|
2012-12-14 00:49:22 +00:00
|
|
|
s->create(w, h, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
|
2012-11-30 12:15:47 +00:00
|
|
|
|
2013-08-03 00:39:37 +00:00
|
|
|
const byte *srcP = (const byte *)thumb8.getPixels();
|
|
|
|
uint16 *destP = (uint16 *)s->getPixels();
|
2012-11-30 12:15:47 +00:00
|
|
|
|
|
|
|
for (int yp = 0; yp < h; ++yp) {
|
|
|
|
// Copy over the line, using the source pixels as lookups into the pixels palette
|
|
|
|
const byte *lineSrcP = srcP;
|
|
|
|
uint16 *lineDestP = destP;
|
|
|
|
|
|
|
|
for (int xp = 0; xp < w; ++xp)
|
2013-04-10 08:27:06 +00:00
|
|
|
*lineDestP++ = *(uint16 *)&_vm->_graphicsMan->_palettePixels[*lineSrcP++ * 2];
|
2012-11-30 12:15:47 +00:00
|
|
|
|
|
|
|
// Move to the start of the next line
|
|
|
|
srcP += w;
|
|
|
|
destP += w;
|
|
|
|
}
|
2012-12-08 11:45:11 +00:00
|
|
|
thumb8.free();
|
2012-10-27 11:16:54 +00:00
|
|
|
}
|
|
|
|
|
2013-01-14 06:52:24 +00:00
|
|
|
void SaveLoadManager::syncSavegameData(Common::Serializer &s, int version) {
|
2013-08-01 01:21:29 +00:00
|
|
|
// The brief version 3 had the highscores embedded. They're in a separate file now, so skip
|
|
|
|
if (version == 3 && s.isLoading())
|
|
|
|
s.skip(100);
|
|
|
|
|
2013-03-20 06:27:42 +00:00
|
|
|
s.syncBytes(&_vm->_globals->_saveData->_data[0], 2050);
|
|
|
|
syncCharacterLocation(s, _vm->_globals->_saveData->_cloneHopkins);
|
|
|
|
syncCharacterLocation(s, _vm->_globals->_saveData->_realHopkins);
|
|
|
|
syncCharacterLocation(s, _vm->_globals->_saveData->_samantha);
|
2012-10-27 11:16:54 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 35; ++i)
|
2013-03-20 06:27:42 +00:00
|
|
|
s.syncAsSint16LE(_vm->_globals->_saveData->_inventory[i]);
|
2013-01-14 06:52:24 +00:00
|
|
|
|
|
|
|
if (version > 1) {
|
2013-03-20 06:27:42 +00:00
|
|
|
s.syncAsSint16LE(_vm->_globals->_saveData->_mapCarPosX);
|
|
|
|
s.syncAsSint16LE(_vm->_globals->_saveData->_mapCarPosY);
|
2013-01-14 06:52:24 +00:00
|
|
|
} else {
|
2013-03-20 06:27:42 +00:00
|
|
|
_vm->_globals->_saveData->_mapCarPosX = _vm->_globals->_saveData->_mapCarPosY = 0;
|
2013-01-14 06:52:24 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 11:16:54 +00:00
|
|
|
}
|
|
|
|
|
2012-11-24 11:25:19 +00:00
|
|
|
void SaveLoadManager::syncCharacterLocation(Common::Serializer &s, CharacterLocation &item) {
|
2012-12-16 01:11:36 +00:00
|
|
|
s.syncAsSint16LE(item._pos.x);
|
|
|
|
s.syncAsSint16LE(item._pos.y);
|
2013-01-21 21:25:12 +00:00
|
|
|
s.syncAsSint16LE(item._startSpriteIndex);
|
2012-12-16 01:11:36 +00:00
|
|
|
s.syncAsSint16LE(item._location);
|
2013-01-21 18:15:37 +00:00
|
|
|
s.syncAsSint16LE(item._zoomFactor);
|
2012-10-27 11:16:54 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 12:15:47 +00:00
|
|
|
void SaveLoadManager::convertThumb16To8(Graphics::Surface *thumb16, Graphics::Surface *thumb8) {
|
|
|
|
thumb8->create(thumb16->w, thumb16->h, Graphics::PixelFormat::createFormatCLUT8());
|
|
|
|
Graphics::PixelFormat pixelFormat16(2, 5, 6, 5, 0, 11, 5, 0, 0);
|
|
|
|
|
2013-02-21 17:37:15 +00:00
|
|
|
byte paletteR[PALETTE_SIZE];
|
|
|
|
byte paletteG[PALETTE_SIZE];
|
|
|
|
byte paletteB[PALETTE_SIZE];
|
|
|
|
for (int palIndex = 0; palIndex < PALETTE_SIZE; ++palIndex) {
|
2013-04-17 10:30:38 +00:00
|
|
|
uint16 p = READ_UINT16(&_vm->_graphicsMan->_palettePixels[palIndex * 2]);
|
2013-02-21 17:37:15 +00:00
|
|
|
pixelFormat16.colorToRGB(p, paletteR[palIndex], paletteG[palIndex], paletteB[palIndex]);
|
|
|
|
}
|
2012-11-30 12:15:47 +00:00
|
|
|
|
2013-08-03 00:39:37 +00:00
|
|
|
const uint16 *srcP = (const uint16 *)thumb16->getPixels();
|
|
|
|
byte *destP = (byte *)thumb8->getPixels();
|
2012-11-30 12:15:47 +00:00
|
|
|
|
|
|
|
for (int yp = 0; yp < thumb16->h; ++yp) {
|
|
|
|
const uint16 *lineSrcP = srcP;
|
|
|
|
byte *lineDestP = destP;
|
|
|
|
|
|
|
|
for (int xp = 0; xp < thumb16->w; ++xp) {
|
|
|
|
byte r, g, b;
|
|
|
|
pixelFormat16.colorToRGB(*lineSrcP++, r, g, b);
|
|
|
|
|
2013-05-07 22:24:33 +00:00
|
|
|
// Do like in the original and show thumbnail as a grayscale picture
|
|
|
|
int lum = (r * 21 + g * 72 + b * 7) / 100;
|
|
|
|
r = g = b = lum;
|
|
|
|
|
2012-11-30 12:15:47 +00:00
|
|
|
// Scan the palette for the closest match
|
|
|
|
int difference = 99999, foundIndex = 0;
|
|
|
|
for (int palIndex = 0; palIndex < PALETTE_SIZE; ++palIndex) {
|
2013-02-21 17:37:15 +00:00
|
|
|
byte rCurrent = paletteR[palIndex];
|
|
|
|
byte gCurrent = paletteG[palIndex];
|
|
|
|
byte bCurrent = paletteB[palIndex];
|
2012-12-14 00:49:22 +00:00
|
|
|
|
2012-11-30 12:15:47 +00:00
|
|
|
int diff = ABS((int)r - (int)rCurrent) + ABS((int)g - (int)gCurrent) + ABS((int)b - (int)bCurrent);
|
|
|
|
if (diff < difference) {
|
|
|
|
difference = diff;
|
|
|
|
foundIndex = palIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*lineDestP++ = foundIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move to the start of the next line
|
|
|
|
srcP += thumb16->w;
|
|
|
|
destP += thumb16->w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-24 11:49:32 +00:00
|
|
|
} // End of namespace Hopkins
|