aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/platform/ps2/ps2time.cpp5
-rw-r--r--common/system.cpp7
-rw-r--r--common/system.h3
-rw-r--r--engines/gob/inter.cpp18
-rw-r--r--engines/scumm/saveload.cpp23
-rw-r--r--engines/scumm/script_v6.cpp21
6 files changed, 44 insertions, 33 deletions
diff --git a/backends/platform/ps2/ps2time.cpp b/backends/platform/ps2/ps2time.cpp
index 2e7741bfed..5bd62b640d 100644
--- a/backends/platform/ps2/ps2time.cpp
+++ b/backends/platform/ps2/ps2time.cpp
@@ -104,10 +104,15 @@ void OSystem_PS2::readRtcTime(void) {
}
extern "C" time_t time(time_t *p) {
+ if (p) *p = (time_t)g_timeSecs;
return (time_t)g_timeSecs;
}
extern "C" struct tm *localtime(const time_t *p) {
+ // FIXME: This function should actually use the value in *p!
+ // But the work needed for that is not necessary -- just implement
+ // OSystem::getTimeAndDate using the code provided here, and
+ // ditch the custom time & localtime methods.
uint32 currentSecs = g_timeSecs + (msecCount - g_lastTimeCheck) / 1000;
if (currentSecs >= SECONDS_PER_DAY) {
buildNewDate(+1);
diff --git a/common/system.cpp b/common/system.cpp
index 9444c692d6..786b3cec1a 100644
--- a/common/system.cpp
+++ b/common/system.cpp
@@ -35,6 +35,8 @@
#include "gui/message.h"
#include "sound/mixer.h"
+#include <time.h>
+
OSystem *g_system = 0;
OSystem::OSystem() {
@@ -121,3 +123,8 @@ void OSystem::clearScreen() {
memset(screen->pixels, 0, screen->h * screen->pitch);
unlockScreen();
}
+
+void OSystem::getTimeAndDate(struct tm &t) const {
+ time_t curTime = time(0);
+ t = *localtime(&curTime);
+}
diff --git a/common/system.h b/common/system.h
index 7246389bab..98ea02df20 100644
--- a/common/system.h
+++ b/common/system.h
@@ -724,6 +724,9 @@ public:
/** Delay/sleep for the specified amount of milliseconds. */
virtual void delayMillis(uint msecs) = 0;
+
+ /** Get the current time and date. Correspond to time()+localtime(). */
+ virtual void getTimeAndDate(struct tm &t) const;
/**
* Return the timer manager singleton. For more information, refer
diff --git a/engines/gob/inter.cpp b/engines/gob/inter.cpp
index 3c0127fdbd..2e8e0fead2 100644
--- a/engines/gob/inter.cpp
+++ b/engines/gob/inter.cpp
@@ -125,18 +125,16 @@ bool Inter::evalBoolResult() {
}
void Inter::renewTimeInVars() {
- struct tm *t;
- time_t now = time(NULL);
+ struct tm t;
+ _vm->_system->getTimeAndDate(t);
- t = localtime(&now);
-
- WRITE_VAR(5, 1900 + t->tm_year);
- WRITE_VAR(6, t->tm_mon + 1);
+ WRITE_VAR(5, 1900 + t.tm_year);
+ WRITE_VAR(6, t.tm_mon + 1);
WRITE_VAR(7, 0);
- WRITE_VAR(8, t->tm_mday);
- WRITE_VAR(9, t->tm_hour);
- WRITE_VAR(10, t->tm_min);
- WRITE_VAR(11, t->tm_sec);
+ WRITE_VAR(8, t.tm_mday);
+ WRITE_VAR(9, t.tm_hour);
+ WRITE_VAR(10, t.tm_min);
+ WRITE_VAR(11, t.tm_sec);
}
void Inter::storeMouse() {
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index 629ac31901..9e979cbab9 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -23,8 +23,6 @@
*
*/
-
-
#include "common/config-manager.h"
#include "common/savefile.h"
#include "common/system.h"
@@ -555,10 +553,12 @@ bool ScummEngine::loadInfos(Common::InSaveFile *file, InfoStuff *stuff) {
// For header version 1, we load the data in with our old method
if (section.version == 1) {
- time_t tmp = section.timeTValue;
- tm *curTime = localtime(&tmp);
- stuff->date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF;
- stuff->time = (curTime->tm_hour & 0xFF) << 8 | (curTime->tm_min) & 0xFF;
+ //time_t tmp = section.timeTValue;
+ //tm *curTime = localtime(&tmp);
+ //stuff->date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF;
+ //stuff->time = (curTime->tm_hour & 0xFF) << 8 | (curTime->tm_min) & 0xFF;
+ stuff->date = 0;
+ stuff->time = 0;
}
if (section.version >= 2) {
@@ -588,11 +588,12 @@ void ScummEngine::saveInfos(Common::OutSaveFile* file) {
// still save old format for older versions
section.timeTValue = time(0);
section.playtime = _system->getMillis() / 1000 - _engineStartTime;
-
- time_t curTime_ = time(0);
- tm *curTime = localtime(&curTime_);
- section.date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF;
- section.time = (curTime->tm_hour & 0xFF) << 8 | (curTime->tm_min) & 0xFF;
+
+ tm curTime;
+ _system->getTimeAndDate(curTime);
+
+ section.date = (curTime.tm_mday & 0xFF) << 24 | ((curTime.tm_mon + 1) & 0xFF) << 16 | (curTime.tm_year + 1900) & 0xFFFF;
+ section.time = (curTime.tm_hour & 0xFF) << 8 | (curTime.tm_min) & 0xFF;
file->writeUint32BE(section.type);
file->writeUint32BE(section.version);
diff --git a/engines/scumm/script_v6.cpp b/engines/scumm/script_v6.cpp
index 8696b83fe2..4a2e8fd0bb 100644
--- a/engines/scumm/script_v6.cpp
+++ b/engines/scumm/script_v6.cpp
@@ -23,9 +23,8 @@
*
*/
-
-
#include "common/config-manager.h"
+#include "common/system.h"
#include "scumm/actor.h"
#include "scumm/charset.h"
@@ -3003,19 +3002,17 @@ void ScummEngine_v6::o6_pickVarRandom() {
}
void ScummEngine_v6::o6_getDateTime() {
- struct tm *t;
- time_t now = time(NULL);
-
- t = localtime(&now);
+ struct tm t;
+ _system->getTimeAndDate(t);
- VAR(VAR_TIMEDATE_YEAR) = t->tm_year;
- VAR(VAR_TIMEDATE_MONTH) = t->tm_mon;
- VAR(VAR_TIMEDATE_DAY) = t->tm_mday;
- VAR(VAR_TIMEDATE_HOUR) = t->tm_hour;
- VAR(VAR_TIMEDATE_MINUTE) = t->tm_min;
+ VAR(VAR_TIMEDATE_YEAR) = t.tm_year;
+ VAR(VAR_TIMEDATE_MONTH) = t.tm_mon;
+ VAR(VAR_TIMEDATE_DAY) = t.tm_mday;
+ VAR(VAR_TIMEDATE_HOUR) = t.tm_hour;
+ VAR(VAR_TIMEDATE_MINUTE) = t.tm_min;
if (_game.version == 8)
- VAR(VAR_TIMEDATE_SECOND) = t->tm_sec;
+ VAR(VAR_TIMEDATE_SECOND) = t.tm_sec;
}
void ScummEngine_v6::o6_getPixel() {