aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/sword1/control.cpp16
-rw-r--r--engines/sword1/control.h2
-rw-r--r--engines/sword1/detection.cpp18
-rw-r--r--engines/sword1/sword1.cpp1
-rw-r--r--engines/sword1/sword1.h4
5 files changed, 32 insertions, 9 deletions
diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp
index ce237fe9f9..40854e1b4e 100644
--- a/engines/sword1/control.cpp
+++ b/engines/sword1/control.cpp
@@ -1117,7 +1117,9 @@ void Control::saveGameToFile(uint8 slot) {
outf->writeUint32BE(saveDate);
outf->writeUint16BE(saveTime);
- // TODO: played time
+
+ uint32 currentTime = _system->getMillis() / 1000;
+ outf->writeUint32BE(currentTime - SwordEngine::_systemVars.engineStartTime);
_objMan->saveLiveList(liveBuf);
for (cnt = 0; cnt < TOTAL_SECTIONS; cnt++)
@@ -1165,7 +1167,7 @@ bool Control::restoreGameFromFile(uint8 slot) {
inf->skip(40); // skip description
uint8 saveVersion = inf->readByte();
- if (saveVersion != SAVEGAME_VERSION) {
+ if (saveVersion > SAVEGAME_VERSION) {
warning("Different save game version");
return false;
}
@@ -1183,7 +1185,13 @@ bool Control::restoreGameFromFile(uint8 slot) {
inf->readUint32BE(); // save date
inf->readUint16BE(); // save time
- // TODO: played time
+
+ if (saveVersion < 2) { // Before version 2 we didn't had play time feature
+ SwordEngine::_systemVars.engineStartTime = _system->getMillis() / 1000; // Start counting
+ } else {
+ uint32 currentTime = _system->getMillis() / 1000;
+ SwordEngine::_systemVars.engineStartTime = currentTime - inf->readUint32BE(); // Engine start time
+ }
_restoreBuf = (uint8*)malloc(
TOTAL_SECTIONS * 2 +
@@ -1281,7 +1289,7 @@ bool Control::convertSaveGame(uint8 slot, char* desc) {
newSave->writeUint32BE(saveDate);
newSave->writeUint16BE(saveTime);
- // TODO: played time
+ newSave->writeUint32BE(0); // We don't have playtime info when converting, so we start from 0.
newSave->write(saveData, dataSize);
diff --git a/engines/sword1/control.h b/engines/sword1/control.h
index 1fbc7fdeba..9170a140eb 100644
--- a/engines/sword1/control.h
+++ b/engines/sword1/control.h
@@ -44,7 +44,7 @@ class Music;
class Sound;
#define SAVEGAME_HEADER MKID_BE('BS_1')
-#define SAVEGAME_VERSION 1
+#define SAVEGAME_VERSION 2
#define HAS_THUMBNAIL 1
#define NO_THUMBNAIL 0
diff --git a/engines/sword1/detection.cpp b/engines/sword1/detection.cpp
index 17ae871099..b086f2eb0b 100644
--- a/engines/sword1/detection.cpp
+++ b/engines/sword1/detection.cpp
@@ -102,7 +102,8 @@ bool SwordMetaEngine::hasFeature(MetaEngineFeature f) const {
(f == kSupportsDeleteSave) ||
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportThumbnail) ||
- (f == kSavesSupportCreationDate);
+ (f == kSavesSupportCreationDate) ||
+ (f == kSavesSupportPlayTime);
}
bool Sword1::SwordEngine::hasFeature(EngineFeature f) const {
@@ -244,13 +245,15 @@ SaveStateDescriptor SwordMetaEngine::querySaveMetaInfos(const char *target, int
char fileName[12];
snprintf(fileName, 12, "sword1.%03d", slot);
char name[40];
+ uint32 playTime;
+ byte versionSave;
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(fileName);
if (in) {
in->skip(4); // header
in->read(name, sizeof(name));
- in->skip(1); // version
+ in->read(&versionSave, 1); // version
SaveStateDescriptor desc(slot, name);
@@ -271,6 +274,8 @@ SaveStateDescriptor SwordMetaEngine::querySaveMetaInfos(const char *target, int
uint32 saveDate = in->readUint32BE();
uint16 saveTime = in->readUint16BE();
+ if (versionSave > 1) // Previous versions did not have playtime data
+ playTime = in->readUint32BE();
int day = (saveDate >> 24) & 0xFF;
int month = (saveDate >> 16) & 0xFF;
@@ -283,7 +288,14 @@ SaveStateDescriptor SwordMetaEngine::querySaveMetaInfos(const char *target, int
desc.setSaveTime(hour, minutes);
- // TODO: played time
+ if (versionSave > 1) {
+ minutes = playTime / 60;
+ hour = minutes / 60;
+ minutes %= 60;
+ desc.setPlayTime(hour, minutes);
+ } else { //We have no playtime data
+ desc.setPlayTime(0, 0);
+ }
delete in;
diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp
index 6c33dfab4d..28cc1a51d2 100644
--- a/engines/sword1/sword1.cpp
+++ b/engines/sword1/sword1.cpp
@@ -546,6 +546,7 @@ void SwordEngine::checkCdFiles(void) { // check if we're running from cd, hdd or
Common::Error SwordEngine::go() {
_control->checkForOldSaveGames();
+ SwordEngine::_systemVars.engineStartTime = _system->getMillis() / 1000;
uint16 startPos = ConfMan.getInt("boot_param");
_control->readSavegameDescriptions();
diff --git a/engines/sword1/sword1.h b/engines/sword1/sword1.h
index c4cbbcf394..8563946196 100644
--- a/engines/sword1/sword1.h
+++ b/engines/sword1/sword1.h
@@ -66,6 +66,7 @@ struct SystemVars {
uint8 showText;
uint8 language;
bool isDemo;
+ uint32 engineStartTime; // Used for playtime
Common::Platform platform;
};
@@ -75,7 +76,7 @@ public:
virtual ~SwordEngine();
static SystemVars _systemVars;
void reinitialize(void);
-
+
uint32 _features;
bool mouseIsActive();
@@ -96,6 +97,7 @@ protected:
}
virtual bool hasFeature(EngineFeature f) const;
virtual void syncSoundSettings();
+
// FIXME: Loading a game through the GMM crashes the game
#if 0
Common::Error loadGameState(int slot);