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

svn-id: r38701
This commit is contained in:
Andre Heider 2009-02-21 15:40:14 +00:00
parent 03769a6d56
commit e514d9780a
5 changed files with 28 additions and 47 deletions

View file

@ -23,6 +23,8 @@
* *
*/ */
#include "common/system.h"
#include "sci/include/sciresource.h" #include "sci/include/sciresource.h"
#include "sci/include/engine.h" #include "sci/include/engine.h"
#include "sci/include/versions.h" #include "sci/include/versions.h"
@ -627,9 +629,7 @@ int game_init(EngineState *s) {
sys_string_acquire(s->sys_strings, SYS_STRING_PARSER_BASE, "parser-base", MAX_PARSER_BASE); 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); s->parser_base = make_reg(s->sys_strings_segment, SYS_STRING_PARSER_BASE);
sci_get_current_time(&(s->game_start_time)); // Get start time s->last_wait_time = g_system->getMillis();
memcpy(&(s->last_wait_time), &(s->game_start_time), sizeof(GTimeVal));
// Use start time as last_wait_time
s->debug_mode = 0x0; // Disable all debugging s->debug_mode = 0x0; // Disable all debugging
s->onscreen_console = 0; // No onscreen console unless explicitly requested s->onscreen_console = 0; // No onscreen console unless explicitly requested

View file

@ -29,6 +29,8 @@
# undef ARRAYSIZE # undef ARRAYSIZE
#endif #endif
#include "common/system.h"
#include "sci/sci.h" #include "sci/sci.h"
#include "sci/engine/gc.h" #include "sci/engine/gc.h"
#include "sci/include/sciresource.h" #include "sci/include/sciresource.h"
@ -495,9 +497,8 @@ reg_t kSetDebug(EngineState *s, int funct_nr, int argc, reg_t *argv) {
#define _K_NEW_GETTIME_DATE 3 #define _K_NEW_GETTIME_DATE 3
reg_t kGetTime(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kGetTime(EngineState *s, int funct_nr, int argc, reg_t *argv) {
struct tm* loc_time; tm loc_time;
GTimeVal time_prec; uint32 start_time;
time_t the_time;
int retval = 0; // Avoid spurious warning int retval = 0; // Avoid spurious warning
#if 0 #if 0
@ -506,30 +507,16 @@ reg_t kGetTime(EngineState *s, int funct_nr, int argc, reg_t *argv) {
s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT | KERNEL_OPT_FLAG_GOT_2NDEVENT); s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT | KERNEL_OPT_FLAG_GOT_2NDEVENT);
#endif #endif
#ifdef WIN32 g_system->getTimeAndDate(loc_time);
if (TIMERR_NOERROR != timeBeginPeriod(1)) { start_time = g_system->getMillis() / 1000;
fprintf(stderr, "timeBeginPeriod(1) failed in kGetTime!\n");
}
#endif // WIN32
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 (s->version < SCI_VERSION_FTU_NEW_GETTIME) { // Use old semantics
if (argc) { // Get seconds since last am/pm switch 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 // FIXME: remove the Sci:: bit once this belongs to the Sci namespace
debugC(2, Sci::kDebugLevelTime, "GetTime(timeofday) returns %d", retval); debugC(2, Sci::kDebugLevelTime, "GetTime(timeofday) returns %d", retval);
} else { // Get time since game started } else { // Get time since game started
sci_get_current_time(&time_prec); retval = start_time * 60;
retval = ((time_prec.tv_usec - s->game_start_time.tv_usec) * 60 / 1000000) +
(time_prec.tv_sec - s->game_start_time.tv_sec) * 60;
// FIXME: remove the Sci:: bit once this belongs to the Sci namespace // FIXME: remove the Sci:: bit once this belongs to the Sci namespace
debugC(2, Sci::kDebugLevelTime, "GetTime(elapsed) returns %d", retval); debugC(2, Sci::kDebugLevelTime, "GetTime(elapsed) returns %d", retval);
} }
@ -540,28 +527,26 @@ reg_t kGetTime(EngineState *s, int funct_nr, int argc, reg_t *argv) {
switch (mode) { switch (mode) {
case _K_NEW_GETTIME_TICKS : { case _K_NEW_GETTIME_TICKS : {
sci_get_current_time(&time_prec); retval = start_time * 60;
retval = ((time_prec.tv_usec - s->game_start_time.tv_usec) * 60 / 1000000) +
(time_prec.tv_sec - s->game_start_time.tv_sec) * 60;
// FIXME: remove the Sci:: bit once this belongs to the Sci namespace // FIXME: remove the Sci:: bit once this belongs to the Sci namespace
debugC(2, Sci::kDebugLevelTime, "GetTime(elapsed) returns %d", retval); debugC(2, Sci::kDebugLevelTime, "GetTime(elapsed) returns %d", retval);
break; break;
} }
case _K_NEW_GETTIME_TIME_12HOUR : { case _K_NEW_GETTIME_TIME_12HOUR : {
loc_time->tm_hour %= 12; loc_time.tm_hour %= 12;
retval = (loc_time->tm_min << 6) | (loc_time->tm_hour << 12) | (loc_time->tm_sec); 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 // FIXME: remove the Sci:: bit once this belongs to the Sci namespace
debugC(2, Sci::kDebugLevelTime, "GetTime(12h) returns %d", retval); debugC(2, Sci::kDebugLevelTime, "GetTime(12h) returns %d", retval);
break; break;
} }
case _K_NEW_GETTIME_TIME_24HOUR : { 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 // FIXME: remove the Sci:: bit once this belongs to the Sci namespace
debugC(2, Sci::kDebugLevelTime, "GetTime(24h) returns %d", retval); debugC(2, Sci::kDebugLevelTime, "GetTime(24h) returns %d", retval);
break; break;
} }
case _K_NEW_GETTIME_DATE : { 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 // FIXME: remove the Sci:: bit once this belongs to the Sci namespace
debugC(2, Sci::kDebugLevelTime, "GetTime(date) returns %d", retval); debugC(2, Sci::kDebugLevelTime, "GetTime(date) returns %d", retval);
break; break;

View file

@ -23,6 +23,8 @@
* *
*/ */
#include "common/system.h"
#include "sci/include/sciresource.h" #include "sci/include/sciresource.h"
#include "sci/include/engine.h" #include "sci/include/engine.h"
#include "sci/include/gfx_widgets.h" #include "sci/include/gfx_widgets.h"
@ -645,14 +647,12 @@ reg_t kTextSize(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int debug_sleeptime_factor = 1; int debug_sleeptime_factor = 1;
reg_t kWait(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kWait(EngineState *s, int funct_nr, int argc, reg_t *argv) {
GTimeVal time; uint32 time;
int sleep_time = UKPV(0); 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->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); s->last_wait_time = time;
memcpy(&(s->last_wait_time), &time, sizeof(GTimeVal));
// Reset optimization flags: Game is playing along nicely anyway // Reset optimization flags: Game is playing along nicely anyway
s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT | KERNEL_OPT_FLAG_GOT_2NDEVENT); s->kernel_opt_flags &= ~(KERNEL_OPT_FLAG_GOT_EVENT | KERNEL_OPT_FLAG_GOT_2NDEVENT);

View file

@ -745,7 +745,7 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename
} }
*/ */
// Calculate the time spent with this game // 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 SavegameMetadata meta INTO fh;
%CFSMLWRITE EngineState s INTO fh; %CFSMLWRITE EngineState s INTO fh;
@ -1082,9 +1082,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
sys_strings_restore(retval->sys_strings, s->sys_strings); sys_strings_restore(retval->sys_strings, s->sys_strings);
// Time state: // Time state:
sci_get_current_time(&(retval->last_wait_time)); retval->last_wait_time = g_system->getMillis();
retval->game_start_time.tv_sec = time(NULL) - retval->game_time;
retval->game_start_time.tv_usec = 0;
// File IO state: // File IO state:
retval->file_handles_nr = 2; retval->file_handles_nr = 2;

View file

@ -4686,7 +4686,7 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename
} }
*/ */
// Calculate the time spent with this game // 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" #line 814 "engines/sci/engine/savegame.cfsml"
// Auto-generated CFSML data writer code // Auto-generated CFSML data writer code
@ -5091,9 +5091,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
sys_strings_restore(retval->sys_strings, s->sys_strings); sys_strings_restore(retval->sys_strings, s->sys_strings);
// Time state: // Time state:
sci_get_current_time(&(retval->last_wait_time)); retval->last_wait_time = g_system->getMillis();
retval->game_start_time.tv_sec = time(NULL) - retval->game_time;
retval->game_start_time.tv_usec = 0;
// File IO state: // File IO state:
retval->file_handles_nr = 2; retval->file_handles_nr = 2;
@ -5180,7 +5178,7 @@ bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata*
} }
} }
// End of auto-generated CFSML data reader code // 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) if (read_eof)
return false; return false;