diff options
Diffstat (limited to 'engines')
-rwxr-xr-x | engines/pegasus/timers.cpp | 47 | ||||
-rwxr-xr-x | engines/pegasus/timers.h | 39 |
2 files changed, 84 insertions, 2 deletions
diff --git a/engines/pegasus/timers.cpp b/engines/pegasus/timers.cpp index fe487e90d2..03e7a64784 100755 --- a/engines/pegasus/timers.cpp +++ b/engines/pegasus/timers.cpp @@ -332,4 +332,51 @@ void NotificationCallBack::callBack() { _notifier->setNotificationFlags(_callBackFlag, _callBackFlag); } +static const tNotificationFlags kFuseExpiredFlag = 1; + +Fuse::Fuse() : _fuseNotification(0, (NotificationManager *)((PegasusEngine *)g_engine)) { + _fuseNotification.notifyMe(this, kFuseExpiredFlag, kFuseExpiredFlag); + _fuseCallBack.setNotification(&_fuseNotification); + _fuseCallBack.initCallBack(&_fuseTimer, kCallBackAtExtremes); + _fuseCallBack.setCallBackFlag(kFuseExpiredFlag); +} + +void Fuse::primeFuse(const TimeValue frequency, const TimeScale scale) { + stopFuse(); + _fuseTimer.setScale(scale); + _fuseTimer.setSegment(0, frequency); + _fuseTimer.setTime(0); +} + +void Fuse::lightFuse() { + if (!_fuseTimer.isRunning()) { + _fuseCallBack.scheduleCallBack(kTriggerAtStop, 0, 0); + _fuseTimer.start(); + } +} + +void Fuse::stopFuse() { + _fuseTimer.stop(); + _fuseCallBack.cancelCallBack(); + // Make sure the fuse has not triggered but not been caught yet... + _fuseNotification.setNotificationFlags(0, 0xffffffff); +} + +void Fuse::advanceFuse(const TimeValue time) { + if (_fuseTimer.isRunning()) { + _fuseTimer.stop(); + _fuseTimer.setTime(_fuseTimer.getTime() + time); + _fuseTimer.start(); + } +} + +TimeValue Fuse::getTimeRemaining() { + return _fuseTimer.getStop() - _fuseTimer.getTime(); +} + +void Fuse::receiveNotification(Notification *, const tNotificationFlags) { + stopFuse(); + invokeAction(); +} + } // End of namespace Pegasus diff --git a/engines/pegasus/timers.h b/engines/pegasus/timers.h index 52f420eb90..55c2ba0ca0 100755 --- a/engines/pegasus/timers.h +++ b/engines/pegasus/timers.h @@ -30,6 +30,8 @@ #include "common/rational.h" #include "pegasus/constants.h" +#include "pegasus/notification.h" +#include "pegasus/util.h" namespace Pegasus { @@ -188,8 +190,6 @@ protected: }; -class Notification; - class NotificationCallBack : public TimeBaseCallBack { public: NotificationCallBack(); @@ -212,6 +212,41 @@ public: TimeValue percentSeconds(const uint32 percent) { return getScale() * percent / 100; } }; +class Fuse : private NotificationReceiver { +public: + Fuse(); + virtual ~Fuse() {} + + void primeFuse(const TimeValue, const TimeScale = 1); // An appropriately named function :P + void lightFuse(); + void stopFuse(); + bool isFuseLit() { return _fuseTimer.isRunning() || _fuseTimer.isPaused(); } + void advanceFuse(const TimeValue); + TimeValue getTimeRemaining(); + TimeScale getFuseScale() { return _fuseTimer.getScale(); } + + void pauseFuse() { _fuseTimer.pause(); } + void resumeFuse() { _fuseTimer.resume(); } + bool isFusePaused() { return _fuseTimer.isPaused(); } + +protected: + virtual void receiveNotification(Notification *, const tNotificationFlags); + virtual void invokeAction() {} + + TimeBase _fuseTimer; + NotificationCallBack _fuseCallBack; + Notification _fuseNotification; +}; + +class FuseFunction : public Fuse, public FunctionPtr { +public: + FuseFunction(); + virtual ~FuseFunction(); + +protected: + virtual void invokeAction() { callFunction(); } +}; + } // End of namespace Pegasus #endif |