aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorjohndoe1232014-04-15 13:50:05 +0200
committerEugene Sandulenko2018-07-20 06:43:33 +0000
commit60600191a07fe8e7f4945b5dab63b5b374111ed4 (patch)
tree02b0a8e0db3dc5e095b2b93fedb0e1f576048f1a /engines
parent1f74de6a4679cecba4fd77e9c79cfaee9c3dd0f6 (diff)
downloadscummvm-rg350-60600191a07fe8e7f4945b5dab63b5b374111ed4.tar.gz
scummvm-rg350-60600191a07fe8e7f4945b5dab63b5b374111ed4.tar.bz2
scummvm-rg350-60600191a07fe8e7f4945b5dab63b5b374111ed4.zip
ILLUSIONS: Use the UpdateFunctions class for update routines
Diffstat (limited to 'engines')
-rw-r--r--engines/illusions/illusions.cpp16
-rw-r--r--engines/illusions/illusions.h13
-rw-r--r--engines/illusions/illusions_bbdou.cpp31
-rw-r--r--engines/illusions/illusions_bbdou.h3
-rw-r--r--engines/illusions/illusions_duckman.cpp30
-rw-r--r--engines/illusions/illusions_duckman.h3
-rw-r--r--engines/illusions/updatefunctions.cpp7
-rw-r--r--engines/illusions/updatefunctions.h9
8 files changed, 91 insertions, 21 deletions
diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp
index afaaa00a3a..5031f5e11f 100644
--- a/engines/illusions/illusions.cpp
+++ b/engines/illusions/illusions.cpp
@@ -88,6 +88,10 @@ void IllusionsEngine::updateEvents() {
}
}
+void IllusionsEngine::runUpdateFunctions() {
+ _updateFunctions->update();
+}
+
Common::Point *IllusionsEngine::getObjectActorPositionPtr(uint32 objectId) {
Control *control = getObjectControl(objectId);
if (control && control->_actor)
@@ -113,7 +117,7 @@ uint32 IllusionsEngine::getElapsedUpdateTime() {
return result;
}
-int IllusionsEngine::updateActors() {
+int IllusionsEngine::updateActors(uint flags) {
// TODO Move to Controls class
uint32 deltaTime = getElapsedUpdateTime();
for (Controls::ItemsIterator it = _controls->_controls.begin(); it != _controls->_controls.end(); ++it) {
@@ -124,7 +128,7 @@ int IllusionsEngine::updateActors() {
return 1;
}
-int IllusionsEngine::updateSequences() {
+int IllusionsEngine::updateSequences(uint flags) {
// TODO Move to Controls class
for (Controls::ItemsIterator it = _controls->_controls.begin(); it != _controls->_controls.end(); ++it) {
Control *control = *it;
@@ -135,7 +139,7 @@ int IllusionsEngine::updateSequences() {
return 1;
}
-int IllusionsEngine::updateGraphics() {
+int IllusionsEngine::updateGraphics(uint flags) {
Common::Point panPoint(0, 0);
uint32 currTime = getCurrentTime();
@@ -194,6 +198,12 @@ int IllusionsEngine::updateGraphics() {
return 1;
}
+int IllusionsEngine::updateSprites(uint flags) {
+ _screen->updateSprites();
+ _screen->updatePalette();
+ return 1;
+}
+
int IllusionsEngine::getRandom(int max) {
return _random->getRandomNumber(max - 1);
}
diff --git a/engines/illusions/illusions.h b/engines/illusions/illusions.h
index 4ef193156d..ae7b4af7b1 100644
--- a/engines/illusions/illusions.h
+++ b/engines/illusions/illusions.h
@@ -72,6 +72,7 @@ class Sequence;
class SpecialCode;
class TalkItems;
class ThreadList;
+class UpdateFunctions;
enum {
kGameIdBBDOU = 1,
@@ -96,6 +97,7 @@ public:
Common::RandomSource *_random;
Dictionary *_dict;
ResourceSystem *_resSys;
+ UpdateFunctions *_updateFunctions;
void updateEvents();
@@ -133,11 +135,14 @@ public:
return _gameDescription->gameId;
}
- Common::Point *getObjectActorPositionPtr(uint32 objectId);
+ void runUpdateFunctions();
+ int updateActors(uint flags);
+ int updateSequences(uint flags);
+ int updateGraphics(uint flags);
+ int updateSprites(uint flags);
+
uint32 getElapsedUpdateTime();
- int updateActors();
- int updateSequences();
- int updateGraphics();
+ Common::Point *getObjectActorPositionPtr(uint32 objectId);
int getRandom(int max);
int convertPanXCoord(int16 x);
bool calcPointDirection(Common::Point &srcPt, Common::Point &dstPt, uint &facing);
diff --git a/engines/illusions/illusions_bbdou.cpp b/engines/illusions/illusions_bbdou.cpp
index 3b78e1ab7f..f2cb4fddd0 100644
--- a/engines/illusions/illusions_bbdou.cpp
+++ b/engines/illusions/illusions_bbdou.cpp
@@ -64,6 +64,8 @@
namespace Illusions {
+//typedef Common::Functor2Mem<ScriptThread*, OpCall&, void, ScriptOpcodes_BBDOU> UpdateFunctionI;
+
// TriggerFunction
TriggerFunction::TriggerFunction(uint32 sceneId, uint32 verbId, uint32 objectId2, uint32 objectId, TriggerFunctionCallback *callback)
@@ -213,6 +215,9 @@ Common::Error IllusionsEngine_BBDOU::run() {
_talkItems = new TalkItems(this);
_triggerFunctions = new TriggerFunctions();
_threads = new ThreadList(this);
+ _updateFunctions = new UpdateFunctions();
+
+ initUpdateFunctions();
_fader = 0;
@@ -240,11 +245,7 @@ Common::Error IllusionsEngine_BBDOU::run() {
_doScriptThreadInit = true;
while (!shouldQuit()) {
- _threads->updateThreads();
- updateActors();
- updateSequences();
- updateGraphics();
- _screen->updateSprites();
+ runUpdateFunctions();
_system->updateScreen();
updateEvents();
_system->delayMillis(10);
@@ -253,6 +254,7 @@ Common::Error IllusionsEngine_BBDOU::run() {
delete _stack;
delete _scriptOpcodes;
+ delete _updateFunctions;
delete _threads;
delete _triggerFunctions;
delete _talkItems;
@@ -283,6 +285,25 @@ bool IllusionsEngine_BBDOU::hasFeature(EngineFeature f) const {
*/
}
+#define UPDATEFUNCTION(priority, tag, callback) \
+ _updateFunctions->add(priority, tag, new Common::Functor1Mem<uint, int, IllusionsEngine_BBDOU> \
+ (this, &IllusionsEngine_BBDOU::callback));
+
+void IllusionsEngine_BBDOU::initUpdateFunctions() {
+ UPDATEFUNCTION(30, 0, updateScript);
+ UPDATEFUNCTION(50, 0, updateActors);
+ UPDATEFUNCTION(60, 0, updateSequences);
+ UPDATEFUNCTION(70, 0, updateGraphics);
+ UPDATEFUNCTION(90, 0, updateSprites);
+}
+
+#undef UPDATEFUNCTION
+
+int IllusionsEngine_BBDOU::updateScript(uint flags) {
+ _threads->updateThreads();
+ return 1;
+}
+
bool IllusionsEngine_BBDOU::causeIsDeclared(uint32 sceneId, uint32 verbId, uint32 objectId2, uint32 objectId) {
uint32 codeOffs;
return
diff --git a/engines/illusions/illusions_bbdou.h b/engines/illusions/illusions_bbdou.h
index addd06cac4..ea46fb949a 100644
--- a/engines/illusions/illusions_bbdou.h
+++ b/engines/illusions/illusions_bbdou.h
@@ -104,6 +104,9 @@ public:
uint32 _nextTempThreadId;
+ void initUpdateFunctions();
+ int updateScript(uint flags);
+
bool causeIsDeclared(uint32 sceneId, uint32 verbId, uint32 objectId2, uint32 objectId);
void causeDeclare(uint32 verbId, uint32 objectId2, uint32 objectId, TriggerFunctionCallback *callback);
uint32 causeTrigger(uint32 sceneId, uint32 verbId, uint32 objectId2, uint32 objectId, uint32 callingThreadId);
diff --git a/engines/illusions/illusions_duckman.cpp b/engines/illusions/illusions_duckman.cpp
index 1c9d30a535..f9d0360792 100644
--- a/engines/illusions/illusions_duckman.cpp
+++ b/engines/illusions/illusions_duckman.cpp
@@ -104,9 +104,12 @@ Common::Error IllusionsEngine_Duckman::run() {
_controls = new Controls(this);
_talkItems = new TalkItems(this);
_threads = new ThreadList(this);
+ _updateFunctions = new UpdateFunctions();
_fader = new Fader();
+ initUpdateFunctions();
+
_scriptOpcodes = new ScriptOpcodes_Duckman(this);
_stack = new ScriptStack();
@@ -138,12 +141,7 @@ Common::Error IllusionsEngine_Duckman::run() {
_doScriptThreadInit = true;
while (!shouldQuit()) {
- _threads->updateThreads();
- updateActors();
- updateSequences();
- updateGraphics();
- _screen->updateSprites();
- _screen->updatePalette();
+ runUpdateFunctions();
_system->updateScreen();
updateEvents();
_system->delayMillis(10);
@@ -154,6 +152,7 @@ Common::Error IllusionsEngine_Duckman::run() {
delete _fader;
+ delete _updateFunctions;
delete _threads;
delete _talkItems;
delete _controls;
@@ -181,6 +180,25 @@ bool IllusionsEngine_Duckman::hasFeature(EngineFeature f) const {
*/
}
+#define UPDATEFUNCTION(priority, tag, callback) \
+ _updateFunctions->add(priority, tag, new Common::Functor1Mem<uint, int, IllusionsEngine_Duckman> \
+ (this, &IllusionsEngine_Duckman::callback));
+
+void IllusionsEngine_Duckman::initUpdateFunctions() {
+ UPDATEFUNCTION(30, 0, updateScript);
+ UPDATEFUNCTION(50, 0, updateActors);
+ UPDATEFUNCTION(60, 0, updateSequences);
+ UPDATEFUNCTION(70, 0, updateGraphics);
+ UPDATEFUNCTION(90, 0, updateSprites);
+}
+
+#undef UPDATEFUNCTION
+
+int IllusionsEngine_Duckman::updateScript(uint flags) {
+ // TODO Some more stuff
+ _threads->updateThreads();
+ return 1;
+}
void IllusionsEngine_Duckman::startFader(int duration, int minValue, int maxValue, int firstIndex, int lastIndex, uint32 threadId) {
_fader->_active = true;
diff --git a/engines/illusions/illusions_duckman.h b/engines/illusions/illusions_duckman.h
index 0502089479..ca48bc676b 100644
--- a/engines/illusions/illusions_duckman.h
+++ b/engines/illusions/illusions_duckman.h
@@ -109,6 +109,9 @@ public:
Common::Array<DMInventoryItem> _inventoyItems;
SpecialCodeMap _specialCodeMap;
+
+ void initUpdateFunctions();
+ int updateScript(uint flags);
void startFader(int duration, int minValue, int maxValue, int firstIndex, int lastIndex, uint32 threadId);
diff --git a/engines/illusions/updatefunctions.cpp b/engines/illusions/updatefunctions.cpp
index 3a3aadf872..e0cc775eb9 100644
--- a/engines/illusions/updatefunctions.cpp
+++ b/engines/illusions/updatefunctions.cpp
@@ -73,4 +73,11 @@ void UpdateFunctions::update() {
}
+void UpdateFunctions::terminateByScene(uint32 sceneId) {
+ UpdateFunctionListIterator it = _updateFunctions.begin();
+ while (it != _updateFunctions.end())
+ if ((*it)->_tag == sceneId)
+ (*it)->terminate();
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/updatefunctions.h b/engines/illusions/updatefunctions.h
index bd8aef3548..877bbc117e 100644
--- a/engines/illusions/updatefunctions.h
+++ b/engines/illusions/updatefunctions.h
@@ -33,16 +33,18 @@ enum {
kUFTerminate = 2 // Terminate update function
};
-typedef Common::Functor0<int> UpdateFunctionCallback;
+typedef Common::Functor1<uint, int> UpdateFunctionCallback;
class UpdateFunction {
public:
int _priority;
uint32 _tag;
+ uint _flags;
UpdateFunctionCallback *_callback;
- UpdateFunction() : _priority(0), _tag(0), _callback(0) {}
+ UpdateFunction() : _priority(0), _tag(0), _flags(0), _callback(0) {}
~UpdateFunction() { delete _callback; }
- int run() { return (*_callback)(); }
+ void terminate() { _flags |= 1; }
+ int run() { return (*_callback)(_flags); }
};
class UpdateFunctions {
@@ -51,6 +53,7 @@ public:
~UpdateFunctions();
void add(int priority, uint32 tag, UpdateFunctionCallback *callback);
void update();
+ void terminateByScene(uint32 sceneId);
protected:
typedef Common::List<UpdateFunction*> UpdateFunctionList;
typedef UpdateFunctionList::iterator UpdateFunctionListIterator;