diff options
author | johndoe123 | 2014-12-03 21:29:05 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-07-20 06:43:33 +0000 |
commit | 18553cb17aaa3b0c9e167cb62269896bd1e42fd3 (patch) | |
tree | deb78b01e571ff6926a102982fe898eb69b3b330 | |
parent | 70f83137b142d3158efb5dbcf82e7ab36174693a (diff) | |
download | scummvm-rg350-18553cb17aaa3b0c9e167cb62269896bd1e42fd3.tar.gz scummvm-rg350-18553cb17aaa3b0c9e167cb62269896bd1e42fd3.tar.bz2 scummvm-rg350-18553cb17aaa3b0c9e167cb62269896bd1e42fd3.zip |
ILLUSIONS: Move Duckman property timer code to own class and file
-rw-r--r-- | engines/illusions/duckman/duckman_specialcode.cpp | 10 | ||||
-rw-r--r-- | engines/illusions/duckman/duckman_specialcode.h | 3 | ||||
-rw-r--r-- | engines/illusions/duckman/illusions_duckman.cpp | 90 | ||||
-rw-r--r-- | engines/illusions/duckman/illusions_duckman.h | 22 | ||||
-rw-r--r-- | engines/illusions/duckman/propertytimers.cpp | 129 | ||||
-rw-r--r-- | engines/illusions/duckman/propertytimers.h | 62 | ||||
-rw-r--r-- | engines/illusions/module.mk | 1 |
7 files changed, 203 insertions, 114 deletions
diff --git a/engines/illusions/duckman/duckman_specialcode.cpp b/engines/illusions/duckman/duckman_specialcode.cpp index 8626fd150e..b9204ba706 100644 --- a/engines/illusions/duckman/duckman_specialcode.cpp +++ b/engines/illusions/duckman/duckman_specialcode.cpp @@ -22,6 +22,7 @@ #include "illusions/duckman/illusions_duckman.h" #include "illusions/duckman/duckman_specialcode.h" +#include "illusions/duckman/propertytimers.h" #include "illusions/actor.h" #include "illusions/resources/scriptresource.h" #include "illusions/scriptopcodes_duckman.h" @@ -35,9 +36,12 @@ namespace Illusions { DuckmanSpecialCode::DuckmanSpecialCode(IllusionsEngine_Duckman *vm) : _vm(vm) { + + _propertyTimers = new PropertyTimers(_vm); } DuckmanSpecialCode::~DuckmanSpecialCode() { + delete _propertyTimers; } typedef Common::Functor1Mem<OpCall&, void, DuckmanSpecialCode> SpecialCodeFunctionDM; @@ -188,20 +192,20 @@ void DuckmanSpecialCode::spcClearInventorySlot(OpCall &opCall) { void DuckmanSpecialCode::spcAddPropertyTimer(OpCall &opCall) { ARG_UINT32(propertyId); - _vm->addPropertyTimer(propertyId); + _propertyTimers->addPropertyTimer(propertyId); _vm->notifyThreadId(opCall._threadId); } void DuckmanSpecialCode::spcSetPropertyTimer(OpCall &opCall) { ARG_INT16(propertyNum); ARG_INT16(duration); - _vm->setPropertyTimer(propertyNum | 0xE0000, duration); + _propertyTimers->setPropertyTimer(propertyNum | 0xE0000, duration); _vm->notifyThreadId(opCall._threadId); } void DuckmanSpecialCode::spcRemovePropertyTimer(OpCall &opCall) { ARG_UINT32(propertyId); - _vm->removePropertyTimer(propertyId); + _propertyTimers->removePropertyTimer(propertyId); _vm->notifyThreadId(opCall._threadId); } diff --git a/engines/illusions/duckman/duckman_specialcode.h b/engines/illusions/duckman/duckman_specialcode.h index 366a7366b4..4c956f09d5 100644 --- a/engines/illusions/duckman/duckman_specialcode.h +++ b/engines/illusions/duckman/duckman_specialcode.h @@ -30,6 +30,7 @@ namespace Illusions { class IllusionsEngine_Duckman; +class PropertyTimers; typedef Common::Functor1<OpCall&, void> SpecialCodeFunction; @@ -48,6 +49,8 @@ public: uint _chinesePuzzleIndex; byte _chinesePuzzleAnswers[3]; + + PropertyTimers *_propertyTimers; // Special code interface functions void runSpecialCode(uint32 specialCodeId, OpCall &opCall); diff --git a/engines/illusions/duckman/illusions_duckman.cpp b/engines/illusions/duckman/illusions_duckman.cpp index 600a34777c..345ec639f5 100644 --- a/engines/illusions/duckman/illusions_duckman.cpp +++ b/engines/illusions/duckman/illusions_duckman.cpp @@ -128,9 +128,6 @@ Common::Error IllusionsEngine_Duckman::run() { _fieldA = 0; _fieldE = 240; - _propertyTimersActive = false; - _propertyTimersPaused = false; - _globalSceneId = 0x00010003; initInventory(); @@ -1275,91 +1272,4 @@ DMInventorySlot *IllusionsEngine_Duckman::findClosestInventorySlot(Common::Point return minInventorySlot; } -void IllusionsEngine_Duckman::addPropertyTimer(uint32 propertyId) { - PropertyTimer *propertyTimer; - if (findPropertyTimer(propertyId, propertyTimer) || findPropertyTimer(0, propertyTimer)) { - propertyTimer->_propertyId = propertyId; - propertyTimer->_startTime = 0; - propertyTimer->_duration = 0; - propertyTimer->_endTime = 0; - } -} - -void IllusionsEngine_Duckman::setPropertyTimer(uint32 propertyId, uint32 duration) { - PropertyTimer *propertyTimer; - if (findPropertyTimer(propertyId, propertyTimer)) { - propertyTimer->_startTime = getCurrentTime(); - propertyTimer->_duration = duration; - propertyTimer->_endTime = duration + propertyTimer->_startTime; - } - _scriptResource->_properties.set(propertyId, false); - if (!_propertyTimersActive) { - _updateFunctions->add(29, getCurrentScene(), new Common::Functor1Mem<uint, int, IllusionsEngine_Duckman> - (this, &IllusionsEngine_Duckman::updatePropertyTimers)); - _propertyTimersActive = true; - } -} - -void IllusionsEngine_Duckman::removePropertyTimer(uint32 propertyId) { - PropertyTimer *propertyTimer; - if (findPropertyTimer(propertyId, propertyTimer)) - propertyTimer->_propertyId = 0; - _scriptResource->_properties.set(propertyId, true); -} - -bool IllusionsEngine_Duckman::findPropertyTimer(uint32 propertyId, PropertyTimer *&propertyTimer) { - for (uint i = 0; i < kPropertyTimersCount; ++i) - if (_propertyTimers[i]._propertyId == propertyId) { - propertyTimer = &_propertyTimers[i]; - return true; - } - return false; -} - -int IllusionsEngine_Duckman::updatePropertyTimers(uint flags) { - int result = 1; - uint32 currTime = getCurrentTime(); - if (_pauseCtr <= 0) { - if (_propertyTimersPaused) { - for (uint i = 0; i < kPropertyTimersCount; ++i) { - PropertyTimer &propertyTimer = _propertyTimers[i]; - propertyTimer._startTime = currTime; - propertyTimer._endTime = currTime + propertyTimer._duration; - } - _propertyTimersPaused = false; - } - if (flags & 1) { - _propertyTimersActive = false; - _propertyTimersPaused = false; - result = 2; - } else { - bool timersActive = false; - for (uint i = 0; i < kPropertyTimersCount; ++i) { - PropertyTimer &propertyTimer = _propertyTimers[i]; - if (propertyTimer._propertyId) { - timersActive = true; - if (!_scriptResource->_properties.get(propertyTimer._propertyId) && - isTimerExpired(propertyTimer._startTime, propertyTimer._endTime)) - _scriptResource->_properties.set(propertyTimer._propertyId, true); - } - } - if (!timersActive) { - _propertyTimersActive = false; - _propertyTimersPaused = false; - result = 2; - } - } - } else { - if (!_propertyTimersPaused) { - for (uint i = 0; i < kPropertyTimersCount; ++i) { - PropertyTimer &propertyTimer = _propertyTimers[i]; - propertyTimer._duration -= getDurationElapsed(propertyTimer._startTime, propertyTimer._endTime); - } - _propertyTimersPaused = true; - } - result = 1; - } - return result; -} - } // End of namespace Illusions diff --git a/engines/illusions/duckman/illusions_duckman.h b/engines/illusions/duckman/illusions_duckman.h index b21a83d8be..d2d526f1db 100644 --- a/engines/illusions/duckman/illusions_duckman.h +++ b/engines/illusions/duckman/illusions_duckman.h @@ -91,16 +91,6 @@ struct ScreenShaker { const ScreenShakerPoint *_points; }; -struct PropertyTimer { - uint32 _propertyId; - uint32 _startTime; - uint32 _duration; - uint32 _endTime; - PropertyTimer() : _propertyId(0) {} -}; - -const uint kPropertyTimersCount = 6; - struct OpCall; class IllusionsEngine_Duckman : public IllusionsEngine { @@ -130,11 +120,7 @@ public: Common::Array<DMInventoryItem> _inventoyItems; ScreenShaker *_screenShaker; - - PropertyTimer _propertyTimers[kPropertyTimersCount]; - bool _propertyTimersActive; - bool _propertyTimersPaused; - + void initUpdateFunctions(); int updateScript(uint flags); @@ -225,12 +211,6 @@ public: DMInventoryItem *findInventoryItem(uint32 objectId); DMInventorySlot *findClosestInventorySlot(Common::Point pos); - void addPropertyTimer(uint32 propertyId); - void setPropertyTimer(uint32 propertyId, uint32 duration); - void removePropertyTimer(uint32 propertyId); - bool findPropertyTimer(uint32 propertyId, PropertyTimer *&propertyTimer); - int updatePropertyTimers(uint flags); - }; } // End of namespace Illusions diff --git a/engines/illusions/duckman/propertytimers.cpp b/engines/illusions/duckman/propertytimers.cpp new file mode 100644 index 0000000000..60e58866b2 --- /dev/null +++ b/engines/illusions/duckman/propertytimers.cpp @@ -0,0 +1,129 @@ +/* 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/duckman/illusions_duckman.h" +#include "illusions/duckman/propertytimers.h" +#include "illusions/resources/scriptresource.h" +#include "illusions/time.h" +#include "illusions/updatefunctions.h" +#include "engines/util.h" + +namespace Illusions { + +// PropertyTimers + +PropertyTimers::PropertyTimers(IllusionsEngine_Duckman *vm) { + _propertyTimersActive = false; + _propertyTimersPaused = false; +} + +PropertyTimers::~PropertyTimers() { +} + +void PropertyTimers::addPropertyTimer(uint32 propertyId) { + PropertyTimer *propertyTimer; + if (findPropertyTimer(propertyId, propertyTimer) || findPropertyTimer(0, propertyTimer)) { + propertyTimer->_propertyId = propertyId; + propertyTimer->_startTime = 0; + propertyTimer->_duration = 0; + propertyTimer->_endTime = 0; + } +} + +void PropertyTimers::setPropertyTimer(uint32 propertyId, uint32 duration) { + PropertyTimer *propertyTimer; + if (findPropertyTimer(propertyId, propertyTimer)) { + propertyTimer->_startTime = getCurrentTime(); + propertyTimer->_duration = duration; + propertyTimer->_endTime = duration + propertyTimer->_startTime; + } + _vm->_scriptResource->_properties.set(propertyId, false); + if (!_propertyTimersActive) { + _vm->_updateFunctions->add(29, _vm->getCurrentScene(), new Common::Functor1Mem<uint, int, PropertyTimers> + (this, &PropertyTimers::updatePropertyTimers)); + _propertyTimersActive = true; + } +} + +void PropertyTimers::removePropertyTimer(uint32 propertyId) { + PropertyTimer *propertyTimer; + if (findPropertyTimer(propertyId, propertyTimer)) + propertyTimer->_propertyId = 0; + _vm->_scriptResource->_properties.set(propertyId, true); +} + +bool PropertyTimers::findPropertyTimer(uint32 propertyId, PropertyTimer *&propertyTimer) { + for (uint i = 0; i < kPropertyTimersCount; ++i) + if (_propertyTimers[i]._propertyId == propertyId) { + propertyTimer = &_propertyTimers[i]; + return true; + } + return false; +} + +int PropertyTimers::updatePropertyTimers(uint flags) { + int result = 1; + uint32 currTime = getCurrentTime(); + if (_vm->_pauseCtr <= 0) { + if (_propertyTimersPaused) { + for (uint i = 0; i < kPropertyTimersCount; ++i) { + PropertyTimer &propertyTimer = _propertyTimers[i]; + propertyTimer._startTime = currTime; + propertyTimer._endTime = currTime + propertyTimer._duration; + } + _propertyTimersPaused = false; + } + if (flags & 1) { + _propertyTimersActive = false; + _propertyTimersPaused = false; + result = 2; + } else { + bool timersActive = false; + for (uint i = 0; i < kPropertyTimersCount; ++i) { + PropertyTimer &propertyTimer = _propertyTimers[i]; + if (propertyTimer._propertyId) { + timersActive = true; + if (!_vm->_scriptResource->_properties.get(propertyTimer._propertyId) && + isTimerExpired(propertyTimer._startTime, propertyTimer._endTime)) + _vm->_scriptResource->_properties.set(propertyTimer._propertyId, true); + } + } + if (!timersActive) { + _propertyTimersActive = false; + _propertyTimersPaused = false; + result = 2; + } + } + } else { + if (!_propertyTimersPaused) { + for (uint i = 0; i < kPropertyTimersCount; ++i) { + PropertyTimer &propertyTimer = _propertyTimers[i]; + propertyTimer._duration -= getDurationElapsed(propertyTimer._startTime, propertyTimer._endTime); + } + _propertyTimersPaused = true; + } + result = 1; + } + return result; +} + +} // End of namespace Illusions diff --git a/engines/illusions/duckman/propertytimers.h b/engines/illusions/duckman/propertytimers.h new file mode 100644 index 0000000000..d4b73060ee --- /dev/null +++ b/engines/illusions/duckman/propertytimers.h @@ -0,0 +1,62 @@ +/* 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_DUCKMAN_PROPERTYTIMERS_H +#define ILLUSIONS_DUCKMAN_PROPERTYTIMERS_H + +#include "illusions/illusions.h" +#include "common/algorithm.h" +#include "common/stack.h" + +namespace Illusions { + +class IllusionsEngine_Duckman; + +struct PropertyTimer { + uint32 _propertyId; + uint32 _startTime; + uint32 _duration; + uint32 _endTime; + PropertyTimer() : _propertyId(0) {} +}; + +const uint kPropertyTimersCount = 6; + +class PropertyTimers { +public: + PropertyTimers(IllusionsEngine_Duckman *vm); + ~PropertyTimers(); +public: + IllusionsEngine_Duckman *_vm; + PropertyTimer _propertyTimers[kPropertyTimersCount]; + bool _propertyTimersActive; + bool _propertyTimersPaused; + void addPropertyTimer(uint32 propertyId); + void setPropertyTimer(uint32 propertyId, uint32 duration); + void removePropertyTimer(uint32 propertyId); + bool findPropertyTimer(uint32 propertyId, PropertyTimer *&propertyTimer); + int updatePropertyTimers(uint flags); +}; + +} // End of namespace Illusions + +#endif // ILLUSIONS_ILLUSIONS_H diff --git a/engines/illusions/module.mk b/engines/illusions/module.mk index bf16310fb0..f915e9f931 100644 --- a/engines/illusions/module.mk +++ b/engines/illusions/module.mk @@ -13,6 +13,7 @@ MODULE_OBJS := \ dictionary.o \ duckman/duckman_specialcode.o \ duckman/illusions_duckman.o \ + duckman/propertytimers.o \ fixedpoint.o \ graphics.o \ illusions.o \ |