diff options
Diffstat (limited to 'engines/sci/engine/state.h')
-rw-r--r-- | engines/sci/engine/state.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index 3db926ab3d..a814a20df8 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -119,6 +119,46 @@ public: bool isOpen() const; }; + +class SpeedThrottler { +public: + enum { + kSegmentLength = 20 /**< Time segment length in ms */ + }; + + SpeedThrottler(sci_version_t version) { + if (version >= SCI_VERSION_1_1) + _maxInstructions = 3300; + else if (version >= SCI_VERSION_1) + _maxInstructions = 2200; + else + _maxInstructions = 1100; + reset(); + } + + void postInstruction() { + if (++_curInstructions >= _maxInstructions) { + uint32 time = g_system->getMillis(); + uint32 elapsed = time - _timestamp; + + if (elapsed < kSegmentLength) + g_system->delayMillis(kSegmentLength - elapsed); + + reset(); + } + } + + void reset() { + _timestamp = g_system->getMillis(); + _curInstructions = 0; + } + +private: + uint32 _timestamp; /**< Timestamp of current time segment */ + uint32 _maxInstructions; /**< Maximum amount of instructions per time segment */ + uint32 _curInstructions; /**< Amount of instructions executed in current time segment */ +}; + struct EngineState : public Common::Serializable { public: EngineState(ResourceManager *res, sci_version_t version, uint32 flags); @@ -258,6 +298,8 @@ public: MessageState _msgState; + SpeedThrottler *speedThrottler; + EngineState *successor; /**< Successor of this state: Used for restoring */ private: |