[Scummvm-cvs-logs] SF.net SVN: scummvm: [30035] scummvm/branches/branch-0-11-0

sev at users.sourceforge.net sev at users.sourceforge.net
Fri Dec 28 08:44:40 CET 2007


Revision: 30035
          http://scummvm.svn.sourceforge.net/scummvm/?rev=30035&view=rev
Author:   sev
Date:     2007-12-27 23:44:40 -0800 (Thu, 27 Dec 2007)

Log Message:
-----------
Backport patch #1859448: Add OSystem::getTimeAndDate API

Modified Paths:
--------------
    scummvm/branches/branch-0-11-0/backends/platform/ps2/ps2time.cpp
    scummvm/branches/branch-0-11-0/common/system.cpp
    scummvm/branches/branch-0-11-0/common/system.h
    scummvm/branches/branch-0-11-0/engines/gob/inter.cpp
    scummvm/branches/branch-0-11-0/engines/scumm/saveload.cpp
    scummvm/branches/branch-0-11-0/engines/scumm/script_v6.cpp

Modified: scummvm/branches/branch-0-11-0/backends/platform/ps2/ps2time.cpp
===================================================================
--- scummvm/branches/branch-0-11-0/backends/platform/ps2/ps2time.cpp	2007-12-28 07:43:52 UTC (rev 30034)
+++ scummvm/branches/branch-0-11-0/backends/platform/ps2/ps2time.cpp	2007-12-28 07:44:40 UTC (rev 30035)
@@ -104,10 +104,15 @@
 }
 
 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);

Modified: scummvm/branches/branch-0-11-0/common/system.cpp
===================================================================
--- scummvm/branches/branch-0-11-0/common/system.cpp	2007-12-28 07:43:52 UTC (rev 30034)
+++ scummvm/branches/branch-0-11-0/common/system.cpp	2007-12-28 07:44:40 UTC (rev 30035)
@@ -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 @@
 	memset(screen->pixels, 0, screen->h * screen->pitch);
 	unlockScreen();
 }
+
+void OSystem::getTimeAndDate(struct tm &t) const {
+	time_t curTime = time(0);
+	t = *localtime(&curTime);
+}

Modified: scummvm/branches/branch-0-11-0/common/system.h
===================================================================
--- scummvm/branches/branch-0-11-0/common/system.h	2007-12-28 07:43:52 UTC (rev 30034)
+++ scummvm/branches/branch-0-11-0/common/system.h	2007-12-28 07:44:40 UTC (rev 30035)
@@ -724,6 +724,9 @@
 
 	/** 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

Modified: scummvm/branches/branch-0-11-0/engines/gob/inter.cpp
===================================================================
--- scummvm/branches/branch-0-11-0/engines/gob/inter.cpp	2007-12-28 07:43:52 UTC (rev 30034)
+++ scummvm/branches/branch-0-11-0/engines/gob/inter.cpp	2007-12-28 07:44:40 UTC (rev 30035)
@@ -125,18 +125,16 @@
 }
 
 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() {

Modified: scummvm/branches/branch-0-11-0/engines/scumm/saveload.cpp
===================================================================
--- scummvm/branches/branch-0-11-0/engines/scumm/saveload.cpp	2007-12-28 07:43:52 UTC (rev 30034)
+++ scummvm/branches/branch-0-11-0/engines/scumm/saveload.cpp	2007-12-28 07:44:40 UTC (rev 30035)
@@ -23,8 +23,6 @@
  *
  */
 
-
-
 #include "common/config-manager.h"
 #include "common/savefile.h"
 #include "common/system.h"
@@ -555,10 +553,12 @@
 
 	// 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,12 +588,13 @@
 	// still save old format for older versions
 	section.timeTValue = time(0);
 	section.playtime = _system->getMillis() / 1000 - _engineStartTime;
+	
+	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;
 
-	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;
-
 	file->writeUint32BE(section.type);
 	file->writeUint32BE(section.version);
 	file->writeUint32BE(section.size);

Modified: scummvm/branches/branch-0-11-0/engines/scumm/script_v6.cpp
===================================================================
--- scummvm/branches/branch-0-11-0/engines/scumm/script_v6.cpp	2007-12-28 07:43:52 UTC (rev 30034)
+++ scummvm/branches/branch-0-11-0/engines/scumm/script_v6.cpp	2007-12-28 07:44:40 UTC (rev 30035)
@@ -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_getDateTime() {
-	struct tm *t;
-	time_t now = time(NULL);
+	struct tm t;
+	_system->getTimeAndDate(t);
 
-	t = localtime(&now);
+	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() {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list