aboutsummaryrefslogtreecommitdiff
path: root/engines/agi/global.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/agi/global.cpp')
-rw-r--r--engines/agi/global.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/engines/agi/global.cpp b/engines/agi/global.cpp
index 0f10976988..fe3beccb33 100644
--- a/engines/agi/global.cpp
+++ b/engines/agi/global.cpp
@@ -23,6 +23,7 @@
#include "common/config-manager.h"
#include "agi/agi.h"
+#include "agi/graphics.h"
namespace Agi {
@@ -61,6 +62,8 @@ void AgiEngine::setVar(int16 varNr, byte newValue) {
byte AgiEngine::getVar(int16 varNr) {
switch (varNr) {
case VM_VAR_SECONDS:
+ getVarSecondsTrigger();
+ // is supposed to fall through
case VM_VAR_MINUTES:
case VM_VAR_HOURS:
case VM_VAR_DAYS:
@@ -135,6 +138,35 @@ void AgiEngine::setVolumeViaSystemSetting() {
_game.vars[VM_VAR_VOLUME] = internalVolume;
}
+void AgiEngine::resetGetVarSecondsHeuristic() {
+ _getVarSecondsHeuristicLastInstructionCounter = 0;
+ _getVarSecondsHeuristicCounter = 0;
+}
+
+// Called, when the scripts read VM_VAR_SECONDS
+void AgiEngine::getVarSecondsTrigger() {
+ uint32 counterDifference = _instructionCounter - _getVarSecondsHeuristicLastInstructionCounter;
+
+ if (counterDifference <= 3) {
+ // Seconds were read within 3 instructions
+ _getVarSecondsHeuristicCounter++;
+ if (_getVarSecondsHeuristicCounter > 20) {
+ // More than 20 times in a row? This really seems to be an inner loop waiting for seconds to change
+ // This happens in at least:
+ // Police Quest 1 - Poker game
+
+ // Wait a few milliseconds, get events and update screen
+ // We MUST NOT process AGI events in here
+ wait(10);
+ processScummVMEvents();
+ _gfx->updateScreen();
+
+ _getVarSecondsHeuristicCounter = 0;
+ }
+ }
+ _getVarSecondsHeuristicLastInstructionCounter = _instructionCounter;
+}
+
// In-Game timer, used for timer VM Variables
void AgiEngine::inGameTimerReset(uint32 newPlayTime) {
_lastUsedPlayTimeInCycles = newPlayTime / 50;