aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorsluicebox2019-07-14 18:46:34 -0700
committerFilippos Karapetis2019-07-21 18:20:07 +0300
commit954f5142cb9b1f8b6ea4e608a71b07fdfcc4e8ca (patch)
tree9788aa1977f6a5dd3f00065104c36c1c29e01292 /engines/sci/engine
parent39551526b18f0f8b4ed0e460ead96f0b8b9d62c8 (diff)
downloadscummvm-rg350-954f5142cb9b1f8b6ea4e608a71b07fdfcc4e8ca.tar.gz
scummvm-rg350-954f5142cb9b1f8b6ea4e608a71b07fdfcc4e8ca.tar.bz2
scummvm-rg350-954f5142cb9b1f8b6ea4e608a71b07fdfcc4e8ca.zip
SCI: Implement full kWait behavior
Fixes PQ3 bug #11020
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/kgraphics.cpp4
-rw-r--r--engines/sci/engine/state.cpp18
-rw-r--r--engines/sci/engine/state.h3
3 files changed, 19 insertions, 6 deletions
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 1e380e2573..a05031059c 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -394,9 +394,9 @@ reg_t kTextSize(EngineState *s, int argc, reg_t *argv) {
}
reg_t kWait(EngineState *s, int argc, reg_t *argv) {
- int sleep_time = argv[0].toUint16();
+ uint16 ticks = argv[0].toUint16();
- const int delta = s->wait(sleep_time);
+ const uint16 delta = s->wait(ticks);
if (g_sci->_guestAdditions->kWaitHook()) {
return NULL_REG;
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index f1c656688c..65d5562ab9 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -134,14 +134,26 @@ void EngineState::speedThrottler(uint32 neededSleep) {
}
}
-int EngineState::wait(int16 ticks) {
+uint16 EngineState::wait(uint16 ticks) {
uint32 time = g_system->getMillis();
- const int tickDelta = ((long)time - (long)lastWaitTime) * 60 / 1000;
+
+ uint32 ms = ticks * 1000 / 60;
+ uint32 duration = time - lastWaitTime;
+ if (ms > duration) {
+ uint32 sleepTime = ms - duration;
+ sleepTime *= g_debug_sleeptime_factor;
+ g_sci->sleep(sleepTime);
+ time += sleepTime;
+ }
+
+ uint16 tickDelta = (uint16)(((long)time - lastWaitTime) * 60 / 1000);
lastWaitTime = time;
+ return tickDelta;
+}
+void EngineState::sleep(uint16 ticks) {
ticks *= g_debug_sleeptime_factor;
g_sci->sleep(ticks * 1000 / 60);
- return tickDelta;
}
void EngineState::initGlobals() {
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h
index a299d89446..0ad50a6818 100644
--- a/engines/sci/engine/state.h
+++ b/engines/sci/engine/state.h
@@ -114,7 +114,8 @@ public:
uint32 _screenUpdateTime; /**< The last time the game updated the screen */
void speedThrottler(uint32 neededSleep);
- int wait(int16 ticks);
+ uint16 wait(uint16 ticks);
+ void sleep(uint16 ticks);
#ifdef ENABLE_SCI32
uint32 _eventCounter; /**< total times kGetEvent was invoked since the last call to kFrameOut */