aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorjohndoe1232014-03-19 23:18:25 +0100
committerEugene Sandulenko2018-07-20 06:43:33 +0000
commitc99f40c13d945060f489693d3f533b6ce0b54adb (patch)
treefa4f8c4e973350d5e37d62d3aad5ba0f2b409c01 /engines
parent48ef46c02dfeb34706f1060f9443bb31c1a56093 (diff)
downloadscummvm-rg350-c99f40c13d945060f489693d3f533b6ce0b54adb.tar.gz
scummvm-rg350-c99f40c13d945060f489693d3f533b6ce0b54adb.tar.bz2
scummvm-rg350-c99f40c13d945060f489693d3f533b6ce0b54adb.zip
ILLUSIONS: Implement TimerThread and script opcode
Diffstat (limited to 'engines')
-rw-r--r--engines/illusions/module.mk1
-rw-r--r--engines/illusions/scriptman.cpp21
-rw-r--r--engines/illusions/scriptman.h3
-rw-r--r--engines/illusions/scriptopcodes.cpp13
-rw-r--r--engines/illusions/scriptopcodes.h1
-rw-r--r--engines/illusions/scriptthread.cpp1
-rw-r--r--engines/illusions/thread.cpp9
-rw-r--r--engines/illusions/time.cpp13
-rw-r--r--engines/illusions/time.h1
-rw-r--r--engines/illusions/timerthread.cpp75
-rw-r--r--engines/illusions/timerthread.h50
11 files changed, 179 insertions, 9 deletions
diff --git a/engines/illusions/module.mk b/engines/illusions/module.mk
index eab667ee1b..de801b3abe 100644
--- a/engines/illusions/module.mk
+++ b/engines/illusions/module.mk
@@ -22,6 +22,7 @@ MODULE_OBJS := \
spritedrawqueue.o \
thread.o \
time.o \
+ timerthread.o \
updatefunctions.o
# This module can be built as a plugin
diff --git a/engines/illusions/scriptman.cpp b/engines/illusions/scriptman.cpp
index 95e4ec4454..d94a32316a 100644
--- a/engines/illusions/scriptman.cpp
+++ b/engines/illusions/scriptman.cpp
@@ -24,6 +24,7 @@
#include "illusions/scriptman.h"
#include "illusions/scriptthread.h"
#include "illusions/scriptopcodes.h"
+#include "illusions/timerthread.h"
namespace Illusions {
@@ -157,6 +158,14 @@ uint32 ScriptMan::startTempScriptThread(byte *scriptCodeIp, uint32 callingThread
return tempThreadId;
}
+uint32 ScriptMan::startAbortableTimerThread(uint32 duration, uint32 threadId) {
+ return newTimerThread(duration, threadId, true);
+}
+
+uint32 ScriptMan::startTimerThread(uint32 duration, uint32 threadId) {
+ return newTimerThread(duration, threadId, false);
+}
+
void ScriptMan::setCurrFontId(uint32 fontId) {
_fontId = fontId;
}
@@ -173,8 +182,8 @@ bool ScriptMan::enterScene(uint32 sceneId, uint32 threadId) {
void ScriptMan::newScriptThread(uint32 threadId, uint32 callingThreadId, uint notifyFlags,
byte *scriptCodeIp, uint32 value8, uint32 valueC, uint32 value10) {
- ScriptThread *scriptThread = new ScriptThread(_vm, threadId, callingThreadId,
- notifyFlags, scriptCodeIp, value8, valueC, value10);
+ ScriptThread *scriptThread = new ScriptThread(_vm, threadId, callingThreadId, notifyFlags,
+ scriptCodeIp, value8, valueC, value10);
_threads->startThread(scriptThread);
if (_pauseCtr > 0)
scriptThread->pause();
@@ -185,6 +194,14 @@ void ScriptMan::newScriptThread(uint32 threadId, uint32 callingThreadId, uint no
}
}
+uint32 ScriptMan::newTimerThread(uint32 duration, uint32 callingThreadId, bool isAbortable) {
+ uint32 tempThreadId = newTempThreadId();
+ TimerThread *timerThread = new TimerThread(_vm, tempThreadId, callingThreadId, 0,
+ duration, isAbortable);
+ _threads->startThread(timerThread);
+ return tempThreadId;
+}
+
uint32 ScriptMan::newTempThreadId() {
uint32 threadId = _nextTempThreadId + 2 * _scriptResource->_codeCount;
if (threadId > 65535) {
diff --git a/engines/illusions/scriptman.h b/engines/illusions/scriptman.h
index 61ad18e86f..f80101fe10 100644
--- a/engines/illusions/scriptman.h
+++ b/engines/illusions/scriptman.h
@@ -77,6 +77,8 @@ public:
uint32 value8, uint32 valueC, uint32 value10);
uint32 startTempScriptThread(byte *scriptCodeIp, uint32 callingThreadId,
uint32 value8, uint32 valueC, uint32 value10);
+ uint32 startAbortableTimerThread(uint32 duration, uint32 threadId);
+ uint32 startTimerThread(uint32 duration, uint32 threadId);
void setCurrFontId(uint32 fontId);
bool enterScene(uint32 sceneId, uint32 threadId);
public:
@@ -101,6 +103,7 @@ public:
void newScriptThread(uint32 threadId, uint32 callingThreadId, uint notifyFlags,
byte *scriptCodeIp, uint32 value8, uint32 valueC, uint32 value10);
+ uint32 newTimerThread(uint32 duration, uint32 callingThreadId, bool isAbortable);
uint32 newTempThreadId();
};
diff --git a/engines/illusions/scriptopcodes.cpp b/engines/illusions/scriptopcodes.cpp
index 1f6c354eb4..13cb8aa557 100644
--- a/engines/illusions/scriptopcodes.cpp
+++ b/engines/illusions/scriptopcodes.cpp
@@ -82,6 +82,7 @@ void ScriptOpcodes::initOpcodes() {
OPCODE(2, opSuspend);
OPCODE(3, opYield);
OPCODE(6, opStartScriptThread);
+ OPCODE(9, opStartTimerThread);
OPCODE(16, opLoadResource);
OPCODE(20, opEnterScene);
OPCODE(39, opSetDisplay);
@@ -124,6 +125,18 @@ void ScriptOpcodes::opStartScriptThread(ScriptThread *scriptThread, OpCall &opCa
scriptThread->_value8, scriptThread->_valueC, scriptThread->_value10);
}
+void ScriptOpcodes::opStartTimerThread(ScriptThread *scriptThread, OpCall &opCall) {
+ ARG_INT16(isAbortable);
+ ARG_INT16(duration);
+ ARG_INT16(maxDuration);
+ if (maxDuration)
+ duration += _vm->getRandom(maxDuration);
+ if (isAbortable)
+ _vm->_scriptMan->startAbortableTimerThread(duration, opCall._threadId);
+ else
+ _vm->_scriptMan->startTimerThread(duration, opCall._threadId);
+}
+
void ScriptOpcodes::opLoadResource(ScriptThread *scriptThread, OpCall &opCall) {
ARG_SKIP(2);
ARG_UINT32(resourceId);
diff --git a/engines/illusions/scriptopcodes.h b/engines/illusions/scriptopcodes.h
index 008108ee1c..d812d58c26 100644
--- a/engines/illusions/scriptopcodes.h
+++ b/engines/illusions/scriptopcodes.h
@@ -60,6 +60,7 @@ protected:
void opSuspend(ScriptThread *scriptThread, OpCall &opCall);
void opYield(ScriptThread *scriptThread, OpCall &opCall);
void opStartScriptThread(ScriptThread *scriptThread, OpCall &opCall);
+ void opStartTimerThread(ScriptThread *scriptThread, OpCall &opCall);
void opLoadResource(ScriptThread *scriptThread, OpCall &opCall);
void opEnterScene(ScriptThread *scriptThread, OpCall &opCall);
void opSetDisplay(ScriptThread *scriptThread, OpCall &opCall);
diff --git a/engines/illusions/scriptthread.cpp b/engines/illusions/scriptthread.cpp
index 7a37633f94..0f32a6ffb9 100644
--- a/engines/illusions/scriptthread.cpp
+++ b/engines/illusions/scriptthread.cpp
@@ -34,6 +34,7 @@ ScriptThread::ScriptThread(IllusionsEngine *vm, uint32 threadId, uint32 callingT
: Thread(vm, threadId, callingThreadId, notifyFlags), _scriptCodeIp(scriptCodeIp), _value8(value8),
_valueC(valueC), _value10(value10), _sequenceStalled(0) {
_type = kTTScriptThread;
+ _tag = _vm->_scriptMan->_activeScenes.getCurrentScene();
}
int ScriptThread::onUpdate() {
diff --git a/engines/illusions/thread.cpp b/engines/illusions/thread.cpp
index a875585898..e398c33ba5 100644
--- a/engines/illusions/thread.cpp
+++ b/engines/illusions/thread.cpp
@@ -102,12 +102,9 @@ int Thread::update() {
void Thread::terminate() {
if (!_terminated) {
- if (_callingThreadId) {
- if (!(_notifyFlags & 1)) {
- // TODO scrmgrNotifyID(_callingThreadId);
- }
- _callingThreadId = 0;
- }
+ if (!(_notifyFlags & 1))
+ _vm->notifyThreadId(_callingThreadId);
+ _callingThreadId = 0;
onTerminated();
// TODO _vm->removeThread(_threadId, this);
_terminated = true;
diff --git a/engines/illusions/time.cpp b/engines/illusions/time.cpp
index f190035b10..34ceaf4b37 100644
--- a/engines/illusions/time.cpp
+++ b/engines/illusions/time.cpp
@@ -26,7 +26,7 @@
namespace Illusions {
uint32 getCurrentTime() {
- return g_system->getMillis() / 60;
+ return g_system->getMillis() / 16;
}
bool isTimerExpired(uint32 startTime, uint32 endTime) {
@@ -36,4 +36,15 @@ bool isTimerExpired(uint32 startTime, uint32 endTime) {
(startTime < endTime && currTime <= endTime && currTime >= startTime));
}
+uint32 getDurationElapsed(uint32 startTime, uint32 endTime) {
+ uint32 currTime = getCurrentTime();
+ uint32 elapsed = endTime - startTime;
+ if (isTimerExpired(startTime, endTime))
+ return elapsed;
+ else if (startTime < endTime || currTime > startTime)
+ return currTime - startTime;
+ else
+ return currTime + elapsed - endTime;
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/time.h b/engines/illusions/time.h
index c09b43628e..67ff4274b2 100644
--- a/engines/illusions/time.h
+++ b/engines/illusions/time.h
@@ -29,6 +29,7 @@ namespace Illusions {
uint32 getCurrentTime();
bool isTimerExpired(uint32 startTime, uint32 endTime);
+uint32 getDurationElapsed(uint32 startTime, uint32 endTime);
} // End of namespace Illusions
diff --git a/engines/illusions/timerthread.cpp b/engines/illusions/timerthread.cpp
new file mode 100644
index 0000000000..5263305412
--- /dev/null
+++ b/engines/illusions/timerthread.cpp
@@ -0,0 +1,75 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "illusions/illusions.h"
+#include "illusions/timerthread.h"
+#include "illusions/input.h"
+#include "illusions/time.h"
+
+namespace Illusions {
+
+// TimerThread
+
+TimerThread::TimerThread(IllusionsEngine *vm, uint32 threadId, uint32 callingThreadId, uint notifyFlags,
+ uint32 duration, bool isAbortable)
+ : Thread(vm, threadId, callingThreadId, notifyFlags), _duration(duration), _isAbortable(isAbortable) {
+ _type = kTTTimerThread;
+ _startTime = getCurrentTime();
+ _endTime = _startTime + _duration;
+ // TODO _tag = *(_DWORD *)(krndictGetIDValue(callingThreadId) + 20);
+}
+
+int TimerThread::onUpdate() {
+debug("startTime: %d; endTime: %d; currTime: %d", _startTime, _endTime, getCurrentTime());
+ if (isTimerExpired(_startTime, _endTime) ||
+ (_isAbortable && _vm->_input->pollButton(8)))
+ return kTSTerminate;
+ return kTSYield;
+}
+
+void TimerThread::onSuspend() {
+ _durationElapsed = getDurationElapsed(_startTime, _endTime);
+}
+
+void TimerThread::onNotify() {
+ uint32 currTime = getCurrentTime();
+ _startTime = currTime;
+ if (_duration <= _durationElapsed)
+ _endTime = currTime;
+ else
+ _endTime = currTime + _duration - _durationElapsed;
+ _durationElapsed = 0;
+}
+
+void TimerThread::onPause() {
+ onSuspend();
+}
+
+void TimerThread::onResume() {
+ onNotify();
+}
+
+void TimerThread::onTerminated() {
+ // Empty
+}
+
+} // End of namespace Illusions
diff --git a/engines/illusions/timerthread.h b/engines/illusions/timerthread.h
new file mode 100644
index 0000000000..d283dc40ba
--- /dev/null
+++ b/engines/illusions/timerthread.h
@@ -0,0 +1,50 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ILLUSIONS_TIMERTHREAD_H
+#define ILLUSIONS_TIMERTHREAD_H
+
+#include "illusions/thread.h"
+
+namespace Illusions {
+
+class IllusionsEngine;
+
+class TimerThread : public Thread {
+public:
+ TimerThread(IllusionsEngine *vm, uint32 threadId, uint32 callingThreadId, uint notifyFlags,
+ uint32 duration, bool isAbortable);
+ virtual int onUpdate();
+ virtual void onSuspend();
+ virtual void onNotify();
+ virtual void onPause();
+ virtual void onResume();
+ virtual void onTerminated();
+public:
+ uint32 _startTime, _endTime;
+ uint32 _duration, _durationElapsed;
+ bool _isAbortable;
+};
+
+} // End of namespace Illusions
+
+#endif // ILLUSIONS_TIMERTHREAD_H