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/engine.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);
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

View File

@ -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 @@ reg_t kSetDebug(EngineState *s, int funct_nr, int argc, reg_t *argv) {
#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 @@ 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);
#endif
#ifdef WIN32
if (TIMERR_NOERROR != timeBeginPeriod(1)) {
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
g_system->getTimeAndDate(loc_time);
start_time = g_system->getMillis() / 1000;
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;

View File

@ -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,14 +647,12 @@ reg_t kTextSize(EngineState *s, int funct_nr, int argc, reg_t *argv) {
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);
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));
time = g_system->getMillis();
s->r_acc = make_reg(0, ((time - s->last_wait_time) / 1000) * 60);
s->last_wait_time = time;
// Reset optimization flags: Game is playing along nicely anyway
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
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 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
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;

View File

@ -4686,7 +4686,7 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename
}
*/
// 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 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
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 @@ bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata*
}
}
// 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;