mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-24 19:45:07 +00:00
AGI: Kill the timer based counter
Using the timer mechanism for just a simple counter is not just overkill, its also inaccurate. When using a call frequency of x, and waiting for y callbacks, the passed time will not be x*y. The problem amplifies on slower platforms and/or fair thread schedulers. Use absolute times instead. Most notably, the walking speed of the avatar is now smooth on android, but probably on all other handhelds we support too.
This commit is contained in:
parent
83b00526d0
commit
69a026192e
@ -273,23 +273,16 @@ void AgiEngine::processEvents() {
|
||||
}
|
||||
|
||||
void AgiEngine::pollTimer() {
|
||||
uint32 dm;
|
||||
_lastTick += 50;
|
||||
|
||||
if (_tickTimer < _lastTickTimer)
|
||||
_lastTickTimer = 0;
|
||||
|
||||
while ((dm = _tickTimer - _lastTickTimer) < 5) {
|
||||
while (_system->getMillis() < _lastTick) {
|
||||
processEvents();
|
||||
_console->onFrame();
|
||||
_system->delayMillis(10);
|
||||
_system->updateScreen();
|
||||
}
|
||||
_lastTickTimer = _tickTimer;
|
||||
}
|
||||
|
||||
void AgiEngine::agiTimerFunctionLow(void *refCon) {
|
||||
AgiEngine *self = (AgiEngine *)refCon;
|
||||
self->_tickTimer++;
|
||||
_lastTick = _system->getMillis();
|
||||
}
|
||||
|
||||
void AgiEngine::pause(uint32 msec) {
|
||||
@ -532,9 +525,6 @@ AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBas
|
||||
|
||||
_allowSynthetic = false;
|
||||
|
||||
_tickTimer = 0;
|
||||
_lastTickTimer = 0;
|
||||
|
||||
_intobj = NULL;
|
||||
|
||||
_menu = NULL;
|
||||
@ -646,11 +636,10 @@ void AgiEngine::initialize() {
|
||||
|
||||
_lastSaveTime = 0;
|
||||
|
||||
_timer->installTimerProc(agiTimerFunctionLow, 10 * 1000, this);
|
||||
_lastTick = _system->getMillis();
|
||||
|
||||
debugC(2, kDebugLevelMain, "Detect game");
|
||||
|
||||
|
||||
if (agiDetectGame() == errOK) {
|
||||
_game.state = STATE_LOADED;
|
||||
debugC(2, kDebugLevelMain, "game loaded");
|
||||
@ -662,8 +651,6 @@ void AgiEngine::initialize() {
|
||||
}
|
||||
|
||||
AgiEngine::~AgiEngine() {
|
||||
_timer->removeTimerProc(agiTimerFunctionLow);
|
||||
|
||||
// If the engine hasn't been initialized yet via AgiEngine::initialize(), don't attempt to free any resources,
|
||||
// as they haven't been allocated. Fixes bug #1742432 - AGI: Engine crashes if no game is detected
|
||||
if (_game.state == STATE_INIT) {
|
||||
|
@ -810,9 +810,7 @@ public:
|
||||
Common::Error saveGameState(int slot, const char *desc);
|
||||
|
||||
private:
|
||||
|
||||
uint32 _tickTimer;
|
||||
uint32 _lastTickTimer;
|
||||
uint32 _lastTick;
|
||||
|
||||
int _keyQueue[KEY_QUEUE_SIZE];
|
||||
int _keyQueueStart;
|
||||
@ -883,7 +881,6 @@ public:
|
||||
virtual bool isKeypress();
|
||||
virtual void clearKeyQueue();
|
||||
|
||||
static void agiTimerFunctionLow(void *refCon);
|
||||
void initPriTable();
|
||||
|
||||
void newInputMode(InputMode mode);
|
||||
|
@ -122,9 +122,6 @@ void PreAgiEngine::initialize() {
|
||||
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_speakerHandle,
|
||||
_speakerStream, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
|
||||
|
||||
|
||||
//_timer->installTimerProc(agiTimerFunctionLow, 10 * 1000, NULL);
|
||||
|
||||
debugC(2, kDebugLevelMain, "Detect game");
|
||||
|
||||
// clear all resources and events
|
||||
|
Loading…
x
Reference in New Issue
Block a user