[Scummvm-cvs-logs] SF.net SVN: scummvm:[38701] scummvm/trunk/engines/sci/engine

dhewg at users.sourceforge.net dhewg at users.sourceforge.net
Sat Feb 21 16:40:14 CET 2009


Revision: 38701
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38701&view=rev
Author:   dhewg
Date:     2009-02-21 15:40:14 +0000 (Sat, 21 Feb 2009)

Log Message:
-----------
use OSystem::getMillis() for last_wait_time and get rid of game_start_time

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/kernel.cpp
    scummvm/trunk/engines/sci/engine/kgraphics.cpp
    scummvm/trunk/engines/sci/engine/savegame.cfsml
    scummvm/trunk/engines/sci/engine/savegame.cpp

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2009-02-21 15:30:47 UTC (rev 38700)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2009-02-21 15:40:14 UTC (rev 38701)
@@ -23,6 +23,8 @@
  *
  */
 
+#include "common/system.h"
+
 #include "sci/include/sciresource.h"
 #include "sci/include/engine.h"
 #include "sci/include/versions.h"
@@ -627,9 +629,7 @@
 	sys_string_acquire(s->sys_strings, SYS_STRING_PARSER_BASE, "parser-base", MAX_PARSER_BASE);
 	s->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
 
-	sci_get_current_time(&(s->game_start_time)); // Get start time
-	memcpy(&(s->last_wait_time), &(s->game_start_time), sizeof(GTimeVal));
-	// Use start time as last_wait_time
+	s->last_wait_time = g_system->getMillis();
 
 	s->debug_mode = 0x0; // Disable all debugging
 	s->onscreen_console = 0; // No onscreen console unless explicitly requested

Modified: scummvm/trunk/engines/sci/engine/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.cpp	2009-02-21 15:30:47 UTC (rev 38700)
+++ scummvm/trunk/engines/sci/engine/kernel.cpp	2009-02-21 15:40:14 UTC (rev 38701)
@@ -29,6 +29,8 @@
 #	undef ARRAYSIZE
 #endif
 
+#include "common/system.h"
+
 #include "sci/sci.h"
 #include "sci/engine/gc.h"
 #include "sci/include/sciresource.h"
@@ -495,9 +497,8 @@
 #define _K_NEW_GETTIME_DATE 3
 
 reg_t kGetTime(EngineState *s, int funct_nr, int argc, reg_t *argv) {
-	struct tm* loc_time;
-	GTimeVal time_prec;
-	time_t the_time;
+	tm loc_time;
+	uint32 start_time;
 	int retval = 0; // Avoid spurious warning
 
 #if 0
@@ -506,62 +507,46 @@
 	s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT | KERNEL_OPT_FLAG_GOT_2NDEVENT);
 #endif
 
-#ifdef WIN32
-	if (TIMERR_NOERROR != timeBeginPeriod(1)) {
-		fprintf(stderr, "timeBeginPeriod(1) failed in kGetTime!\n");
-	}
-#endif // WIN32
+	g_system->getTimeAndDate(loc_time);
+	start_time = g_system->getMillis() / 1000;
 
-	the_time = time(NULL);
-	loc_time = localtime(&the_time);
-
-#ifdef WIN32
-	if (TIMERR_NOERROR != timeEndPeriod(1)) {
-		fprintf(stderr, "timeEndPeriod(1) failed in kGetTime!\n");
-	}
-#endif // WIN32
-
 	if (s->version < SCI_VERSION_FTU_NEW_GETTIME) { // Use old semantics
 		if (argc) { // Get seconds since last am/pm switch
-			retval = loc_time->tm_sec + loc_time->tm_min * 60 + (loc_time->tm_hour % 12) * 3600;
+			retval = loc_time.tm_sec + loc_time.tm_min * 60 + (loc_time.tm_hour % 12) * 3600;
 			// FIXME: remove the Sci:: bit once this belongs to the Sci namespace
 			debugC(2, Sci::kDebugLevelTime, "GetTime(timeofday) returns %d", retval);
 		} else { // Get time since game started
-			sci_get_current_time(&time_prec);
-			retval = ((time_prec.tv_usec - s->game_start_time.tv_usec) * 60 / 1000000) +
-			         (time_prec.tv_sec - s->game_start_time.tv_sec) * 60;
+			retval = start_time * 60;
 			// FIXME: remove the Sci:: bit once this belongs to the Sci namespace
 			debugC(2, Sci::kDebugLevelTime, "GetTime(elapsed) returns %d", retval);
 		}
 	} else {
-		int mode = UKPV_OR_ALT(0, 0);	
+		int mode = UKPV_OR_ALT(0, 0);
 		// The same strange method is still used for distinguishing
 		// mode 0 and the others. We assume that this is safe, though
 
 		switch (mode) {
 		case _K_NEW_GETTIME_TICKS : {
-			sci_get_current_time(&time_prec);
-			retval = ((time_prec.tv_usec - s->game_start_time.tv_usec) * 60 / 1000000) +
-			         (time_prec.tv_sec - s->game_start_time.tv_sec) * 60;
+			retval = start_time * 60;
 			// FIXME: remove the Sci:: bit once this belongs to the Sci namespace
 			debugC(2, Sci::kDebugLevelTime, "GetTime(elapsed) returns %d", retval);
 			break;
 		}
 		case _K_NEW_GETTIME_TIME_12HOUR : {
-			loc_time->tm_hour %= 12;
-			retval = (loc_time->tm_min << 6) | (loc_time->tm_hour << 12) | (loc_time->tm_sec);
+			loc_time.tm_hour %= 12;
+			retval = (loc_time.tm_min << 6) | (loc_time.tm_hour << 12) | (loc_time.tm_sec);
 			// FIXME: remove the Sci:: bit once this belongs to the Sci namespace
 			debugC(2, Sci::kDebugLevelTime, "GetTime(12h) returns %d", retval);
 			break;
 		}
 		case _K_NEW_GETTIME_TIME_24HOUR : {
-			retval = (loc_time->tm_min << 5) | (loc_time->tm_sec >> 1) | (loc_time->tm_hour << 11);
+			retval = (loc_time.tm_min << 5) | (loc_time.tm_sec >> 1) | (loc_time.tm_hour << 11);
 			// FIXME: remove the Sci:: bit once this belongs to the Sci namespace
 			debugC(2, Sci::kDebugLevelTime, "GetTime(24h) returns %d", retval);
 			break;
 		}
 		case _K_NEW_GETTIME_DATE : {
-			retval = (loc_time->tm_mon << 5) | loc_time->tm_mday | (loc_time->tm_year << 9);
+			retval = (loc_time.tm_mon << 5) | loc_time.tm_mday | (loc_time.tm_year << 9);
 			// FIXME: remove the Sci:: bit once this belongs to the Sci namespace
 			debugC(2, Sci::kDebugLevelTime, "GetTime(date) returns %d", retval);
 			break;

Modified: scummvm/trunk/engines/sci/engine/kgraphics.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-02-21 15:30:47 UTC (rev 38700)
+++ scummvm/trunk/engines/sci/engine/kgraphics.cpp	2009-02-21 15:40:14 UTC (rev 38701)
@@ -23,6 +23,8 @@
  *
  */
 
+#include "common/system.h"
+
 #include "sci/include/sciresource.h"
 #include "sci/include/engine.h"
 #include "sci/include/gfx_widgets.h"
@@ -645,15 +647,13 @@
 int debug_sleeptime_factor = 1;
 
 reg_t kWait(EngineState *s, int funct_nr, int argc, reg_t *argv) {
-	GTimeVal time;
+	uint32 time;
 	int sleep_time = UKPV(0);
 
-	sci_get_current_time(&time);
+	time = g_system->getMillis();
+	s->r_acc = make_reg(0, ((time - s->last_wait_time) / 1000) * 60);
+	s->last_wait_time = time;
 
-	s->r_acc = make_reg(0, ((time.tv_usec - s->last_wait_time.tv_usec) * 60 / 1000000) + (time.tv_sec - s->last_wait_time.tv_sec) * 60);
-
-	memcpy(&(s->last_wait_time), &time, sizeof(GTimeVal));
-
 	// Reset optimization flags: Game is playing along nicely anyway
 	s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT | KERNEL_OPT_FLAG_GOT_2NDEVENT);
 

Modified: scummvm/trunk/engines/sci/engine/savegame.cfsml
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cfsml	2009-02-21 15:30:47 UTC (rev 38700)
+++ scummvm/trunk/engines/sci/engine/savegame.cfsml	2009-02-21 15:40:14 UTC (rev 38701)
@@ -745,7 +745,7 @@
 	}
 */
 	// Calculate the time spent with this game
-	s->game_time = time(NULL) - s->game_start_time.tv_sec;
+	s->game_time = g_system->getMillis() / 1000;
 
 	%CFSMLWRITE SavegameMetadata meta INTO fh;
 	%CFSMLWRITE EngineState s INTO fh;
@@ -1082,9 +1082,7 @@
 	sys_strings_restore(retval->sys_strings, s->sys_strings);
 
 	// Time state:
-	sci_get_current_time(&(retval->last_wait_time));
-	retval->game_start_time.tv_sec = time(NULL) - retval->game_time;
-	retval->game_start_time.tv_usec = 0;
+	retval->last_wait_time = g_system->getMillis();
 
 	// File IO state:
 	retval->file_handles_nr = 2;

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2009-02-21 15:30:47 UTC (rev 38700)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2009-02-21 15:40:14 UTC (rev 38701)
@@ -4686,7 +4686,7 @@
 	}
 */
 	// Calculate the time spent with this game
-	s->game_time = time(NULL) - s->game_start_time.tv_sec;
+	s->game_time = g_system->getMillis() / 1000;
 
 #line 814 "engines/sci/engine/savegame.cfsml"
 // Auto-generated CFSML data writer code
@@ -5091,9 +5091,7 @@
 	sys_strings_restore(retval->sys_strings, s->sys_strings);
 
 	// Time state:
-	sci_get_current_time(&(retval->last_wait_time));
-	retval->game_start_time.tv_sec = time(NULL) - retval->game_time;
-	retval->game_start_time.tv_usec = 0;
+	retval->last_wait_time = g_system->getMillis();
 
 	// File IO state:
 	retval->file_handles_nr = 2;
@@ -5180,7 +5178,7 @@
 		}
 	}
 // End of auto-generated CFSML data reader code
-#line 1146 "engines/sci/engine/savegame.cfsml"
+#line 1144 "engines/sci/engine/savegame.cfsml"
 
 	if (read_eof)
 		return false;


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