- Fixed kGetTime() again

- Removed the odd way of calculating elapsed time in SciGui(). We got _system->getMillis() for that purpose
- Replaced the code in SciGui::wait() with the one in SciGui32::wait (which works fine, and is correct). The code in SciGui() was not polling for events while waiting, either

svn-id: r44712
This commit is contained in:
Filippos Karapetis 2009-10-06 17:45:57 +00:00
parent b8f18e8ddd
commit c17495d895
6 changed files with 20 additions and 37 deletions

View File

@ -116,11 +116,11 @@ enum {
reg_t kGetTime(EngineState *s, int argc, reg_t *argv) {
tm loc_time;
uint32 start_time;
uint32 elapsedTime;
int retval = 0; // Avoid spurious warning
g_system->getTimeAndDate(loc_time);
start_time = g_system->getMillis() - s->game_start_time;
elapsedTime = g_system->getMillis() - s->game_start_time;
if ((s->_flags & GF_SCI0_OLDGETTIME) && argc) { // Use old semantics
retval = (loc_time.tm_hour % 12) * 3600 + loc_time.tm_min * 60 + loc_time.tm_sec;
@ -132,8 +132,7 @@ reg_t kGetTime(EngineState *s, int argc, reg_t *argv) {
switch (mode) {
case K_NEW_GETTIME_TICKS :
retval = s->gui->getTimeTicks(); // FIXME
//retval = start_time * 60 / 1000;
retval = elapsedTime * 60 / 1000;
debugC(2, kDebugLevelTime, "GetTime(elapsed) returns %d", retval);
break;
case K_NEW_GETTIME_TIME_12HOUR :

View File

@ -27,6 +27,7 @@
#include "common/util.h"
#include "sci/sci.h"
#include "sci/debug.h" // for g_debug_sleeptime_factor
#include "sci/engine/state.h"
#include "sci/tools.h"
#include "sci/gui/gui.h"
@ -43,7 +44,6 @@ namespace Sci {
SciGui::SciGui(OSystem *system, EngineState *state, SciGuiScreen *screen)
: _system(system), _s(state), _screen(screen) {
_picNotValid = 0;
_sysTicks = 0;
_palette = new SciGuiPalette(_s, this, _screen);
_gfx = new SciGuiGfx(_s, _screen, _palette);
@ -54,30 +54,26 @@ SciGui::SciGui() {
}
SciGui::~SciGui() {
_system->getTimerManager()->removeTimerProc(&timerHandler);
}
void SciGui::init(bool usesOldGfxFunctions) {
_sysSpeed = 1000000 / 60;
Common::TimerManager *tm = _system->getTimerManager();
tm->removeTimerProc(&timerHandler);
tm->installTimerProc(&timerHandler, _sysSpeed, this);
}
void SciGui::timerHandler(void *ref) {
((SciGui *)ref)->_sysTicks++;
}
int16 SciGui::getTimeTicks() {
return _sysTicks;
}
void SciGui::wait(int16 ticks) {
uint32 waitto = _sysTicks + ticks;
do {
//eventMgr->pollEvents();
_system->delayMillis(_sysSpeed >> 11);
} while (_sysTicks < waitto);
uint32 time;
time = g_system->getMillis();
_s->r_acc = make_reg(0, ((long)time - (long)_s->last_wait_time) * 60 / 1000);
_s->last_wait_time = time;
ticks *= g_debug_sleeptime_factor;
gfxop_sleep(_s->gfx_state, ticks * 1000 / 60);
// Reset speed throttler: Game is playing along nicely anyway
if (ticks > 0)
_s->speedThrottler->reset();
}
void SciGui::setPort(uint16 portPtr) {

View File

@ -46,7 +46,6 @@ public:
virtual void init(bool usesOldGfxFunctions);
virtual int16 getTimeTicks();
virtual void wait(int16 ticks);
virtual void setPort(uint16 portPtr);
virtual void setPortPic(Common::Rect rect, int16 picTop, int16 picLeft);
@ -93,8 +92,6 @@ public:
int _picNotValid; // possible values 0, 1 and 2
private:
static void timerHandler(void*ref);
OSystem *_system;
EngineState *_s;
SciGuiScreen *_screen;
@ -102,8 +99,6 @@ private:
SciGuiGfx *_gfx;
SciGuiresources *_resources;
SciGuiWindowMgr *_windowMgr;
uint32 _sysTicks;
int32 _sysSpeed; // ticker timer in ms
};
} // End of namespace Sci

View File

@ -229,10 +229,10 @@ void SciGuiPalette::merge(GuiPalette *pFrom, GuiPalette *pTo, uint16 flag) {
pTo->colors[res & 0xFF].used |= 0x10;
}
}
pTo->timestamp = _gui->getTimeTicks();
pTo->timestamp = (g_system->getMillis() - _s->game_start_time) * 60 / 1000;;
}
uint16 SciGuiPalette::matchColor(GuiPalette*pPal, byte r, byte g, byte b) {
uint16 SciGuiPalette::matchColor(GuiPalette *pPal, byte r, byte g, byte b) {
byte found = 0xFF;
int diff = 0x2FFFF, cdiff;
int16 dr,dg,db;
@ -275,7 +275,7 @@ void SciGuiPalette::setIntensity(int fromColor, int toColor, int intensity, GuiP
void SciGuiPalette::animate(byte fromColor, byte toColor, int speed) {
GuiColor col;
int len = toColor - fromColor - 1;
uint32 now = _gui->getTimeTicks();
uint32 now = (g_system->getMillis() - _s->game_start_time) * 60 / 1000;;
// search for sheduled animations with the same 'from' value
int sz = _palSchedules.size();
for (int i = 0; i < sz; i++) {

View File

@ -79,12 +79,6 @@ void SciGui32::init(bool oldGfxFunctions) {
port_origin_y = 0;
}
int16 SciGui32::getTimeTicks() {
uint32 start_time;
start_time = _system->getMillis() - s->game_start_time;
return start_time * 60 / 1000;
}
void SciGui32::wait(int16 ticks) {
uint32 time;

View File

@ -40,7 +40,6 @@ public:
void init(bool oldGfxFunctions);
int16 getTimeTicks();
void wait(int16 ticks);
void setPort(uint16 portPtr);
void setPortPic(Common::Rect rect, int16 picTop, int16 picLeft);