aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorjohndoe1232014-03-13 14:31:02 +0100
committerEugene Sandulenko2018-07-20 06:43:33 +0000
commitfc47ac41ae0b5a7fab6a7dfa29b3e33e1e5df2ac (patch)
tree4e4c95d4ac35ebced2ad593d674744b3e0dfc28c /engines
parentbb67c2c2ffdb8794d08fd1937a533caec2465a62 (diff)
downloadscummvm-rg350-fc47ac41ae0b5a7fab6a7dfa29b3e33e1e5df2ac.tar.gz
scummvm-rg350-fc47ac41ae0b5a7fab6a7dfa29b3e33e1e5df2ac.tar.bz2
scummvm-rg350-fc47ac41ae0b5a7fab6a7dfa29b3e33e1e5df2ac.zip
ILLUSIONS: More work on the script system
Diffstat (limited to 'engines')
-rw-r--r--engines/illusions/illusions.cpp1
-rw-r--r--engines/illusions/module.mk1
-rw-r--r--engines/illusions/scriptman.cpp126
-rw-r--r--engines/illusions/scriptman.h85
-rw-r--r--engines/illusions/scriptresource.cpp19
-rw-r--r--engines/illusions/scriptresource.h6
6 files changed, 238 insertions, 0 deletions
diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp
index 17fb730a50..3ff6750718 100644
--- a/engines/illusions/illusions.cpp
+++ b/engines/illusions/illusions.cpp
@@ -33,6 +33,7 @@
#include "illusions/actorresource.h"
#include "illusions/thread.h"
#include "illusions/scriptresource.h"
+#include "illusions/scriptman.h"
#include "audio/audiostream.h"
#include "common/config-manager.h"
diff --git a/engines/illusions/module.mk b/engines/illusions/module.mk
index e8d83eff88..5ba65d7e9d 100644
--- a/engines/illusions/module.mk
+++ b/engines/illusions/module.mk
@@ -11,6 +11,7 @@ MODULE_OBJS := \
illusions.o \
input.o \
resourcesystem.o \
+ scriptman.o \
scriptresource.o \
spritedecompressqueue.o \
spritedrawqueue.o \
diff --git a/engines/illusions/scriptman.cpp b/engines/illusions/scriptman.cpp
new file mode 100644
index 0000000000..922ce605bb
--- /dev/null
+++ b/engines/illusions/scriptman.cpp
@@ -0,0 +1,126 @@
+/* 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/scriptman.h"
+
+namespace Illusions {
+
+// ActiveScenes
+
+void ActiveScenes::clear() {
+ _stack.clear();
+}
+
+void ActiveScenes::push(uint32 sceneId) {
+ ActiveScene activeScene;
+ activeScene._sceneId = sceneId;
+ activeScene._pauseCtr = 0;
+ _stack.push(activeScene);
+}
+
+void ActiveScenes::pop() {
+ _stack.pop();
+}
+
+void ActiveScenes::pauseActiveScene() {
+ ++_stack.top()._pauseCtr;
+}
+
+void ActiveScenes::unpauseActiveScene() {
+ --_stack.top()._pauseCtr;
+}
+
+int ActiveScenes::getActiveScenesCount() {
+ return _stack.size();
+}
+
+void ActiveScenes::getActiveSceneInfo(uint index, uint32 *sceneId, int *pauseCtr) {
+ if (sceneId)
+ *sceneId = _stack[index]._sceneId;
+ if (pauseCtr)
+ *pauseCtr = _stack[index]._pauseCtr;
+}
+
+uint32 ActiveScenes::getCurrentScene() {
+ if (_stack.size() > 0)
+ return _stack.top()._sceneId;
+ return 0;
+}
+
+bool ActiveScenes::isSceneActive(uint32 sceneId) {
+ for (uint i = 0; i < _stack.size(); ++i)
+ if (_stack[i]._sceneId == sceneId && _stack[i]._pauseCtr <= 0)
+ return true;
+ return false;
+}
+
+// ScriptStack
+
+ScriptStack::ScriptStack() {
+ clear();
+}
+
+void ScriptStack::clear() {
+ for (uint i = 0; i < 256; ++i)
+ _stack[i] = (int16)0xEEEE;
+ _stackPos = 256;
+}
+
+void ScriptStack::push(int16 value) {
+ --_stackPos;
+ if (_stackPos > 0)
+ _stack[_stackPos] = value;
+}
+
+int16 ScriptStack::pop() {
+ int16 value = 0;
+ if (_stackPos < 256) {
+ value = _stack[_stackPos];
+ _stack[_stackPos] = (int16)0xEEEE;
+ ++_stackPos;
+ }
+ return value;
+}
+
+int16 ScriptStack::peek() {
+ int16 value = 0;
+ if (_stackPos < 256)
+ value = _stack[_stackPos];
+ return value;
+}
+
+// ScriptMan
+
+ScriptMan::ScriptMan(IllusionsEngine *vm)
+ : _vm(vm) {
+}
+
+ScriptMan::~ScriptMan() {
+}
+
+void ScriptMan::setSceneIdThreadId(uint32 theSceneId, uint32 theThreadId) {
+ _theSceneId = theSceneId;
+ _theThreadId = theThreadId;
+}
+
+} // End of namespace Illusions
diff --git a/engines/illusions/scriptman.h b/engines/illusions/scriptman.h
new file mode 100644
index 0000000000..18b6090fa2
--- /dev/null
+++ b/engines/illusions/scriptman.h
@@ -0,0 +1,85 @@
+/* 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_SCRIPTMAN_H
+#define ILLUSIONS_SCRIPTMAN_H
+
+#include "illusions/scriptresource.h"
+#include "common/algorithm.h"
+#include "common/stack.h"
+
+namespace Illusions {
+
+class IllusionsEngine;
+
+struct ActiveScene {
+ uint32 _sceneId;
+ int _pauseCtr;
+};
+
+class ActiveScenes {
+public:
+ ActiveScenes();
+ void clear();
+ void push(uint32 sceneId);
+ void pop();
+ void pauseActiveScene();
+ void unpauseActiveScene();
+ int getActiveScenesCount();
+ void getActiveSceneInfo(uint index, uint32 *sceneId, int *pauseCtr);
+ uint32 getCurrentScene();
+ bool isSceneActive(uint32 sceneId);
+protected:
+ Common::FixedStack<ActiveScene, 16> _stack;
+};
+
+class ScriptStack {
+public:
+ ScriptStack();
+ void clear();
+ void push(int16 value);
+ int16 pop();
+ int16 peek();
+protected:
+ int _stackPos;
+ int16 _stack[256];
+};
+
+class ScriptMan {
+public:
+ ScriptMan(IllusionsEngine *vm);
+ ~ScriptMan();
+ void setSceneIdThreadId(uint32 theSceneId, uint32 theThreadId);
+public:
+
+ IllusionsEngine *_vm;
+ ActiveScenes _activeScenes;
+ ScriptStack _stack;
+
+ uint32 _theSceneId;
+ uint32 _theThreadId;
+
+};
+
+} // End of namespace Illusions
+
+#endif // ILLUSIONS_SCRIPTMAN_H
diff --git a/engines/illusions/scriptresource.cpp b/engines/illusions/scriptresource.cpp
index 27f5cad5e1..5d9b86a36e 100644
--- a/engines/illusions/scriptresource.cpp
+++ b/engines/illusions/scriptresource.cpp
@@ -71,6 +71,18 @@ void BlockCounters::init(uint count, byte *blockCounters) {
_blockCounters = blockCounters;
}
+void BlockCounters::clear() {
+ for (uint i = 0; i < _count; ++i)
+ _blockCounters[i] = 0;
+}
+
+byte BlockCounters::get(uint index) {
+ return _blockCounters[index] & 0x3F;
+}
+
+void BlockCounters::set(uint index, byte value) {
+ _blockCounters[index] = (get(index) ^ value) & 0x3F;
+}
// TriggerCause
@@ -159,6 +171,9 @@ ScriptResource::~ScriptResource() {
void ScriptResource::load(byte *data, uint32 dataSize) {
Common::MemoryReadStream stream(data, dataSize, DisposeAfterUse::NO);
+ _data = data;
+ _dataSize = dataSize;
+
stream.skip(4); // Skip unused
uint propertiesCount = stream.readUint16LE();
uint blockCountersCount = stream.readUint16LE();
@@ -194,4 +209,8 @@ void ScriptResource::load(byte *data, uint32 dataSize) {
}
+byte *ScriptResource::getThreadCode(uint32 threadId) {
+ return _data + _codeOffsets[threadId & 0xFFFF];
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/scriptresource.h b/engines/illusions/scriptresource.h
index 4e010e975b..206aa4b77d 100644
--- a/engines/illusions/scriptresource.h
+++ b/engines/illusions/scriptresource.h
@@ -54,6 +54,9 @@ class BlockCounters {
public:
BlockCounters();
void init(uint count, byte *blockCounters);
+ void clear();
+ byte get(uint index);
+ void set(uint index, byte value);
public:
uint _count;
byte *_blockCounters;
@@ -95,7 +98,10 @@ public:
ScriptResource();
~ScriptResource();
void load(byte *data, uint32 dataSize);
+ byte *getThreadCode(uint32 threadId);
public:
+ byte *_data;
+ uint32 _dataSize;
Properties _properties;
BlockCounters _blockCounters;
uint32 *_codeOffsets;