diff options
Diffstat (limited to 'engines/wintermute/base')
-rw-r--r-- | engines/wintermute/base/base_engine.cpp | 16 | ||||
-rw-r--r-- | engines/wintermute/base/base_engine.h | 3 | ||||
-rw-r--r-- | engines/wintermute/base/base_fader.cpp | 6 | ||||
-rw-r--r-- | engines/wintermute/base/base_game.cpp | 33 | ||||
-rw-r--r-- | engines/wintermute/base/base_game.h | 14 | ||||
-rw-r--r-- | engines/wintermute/base/base_game_music.cpp | 4 | ||||
-rw-r--r-- | engines/wintermute/base/base_parser.cpp | 2 | ||||
-rw-r--r-- | engines/wintermute/base/base_sprite.cpp | 4 | ||||
-rw-r--r-- | engines/wintermute/base/base_surface_storage.cpp | 6 | ||||
-rw-r--r-- | engines/wintermute/base/gfx/base_surface.cpp | 2 | ||||
-rw-r--r-- | engines/wintermute/base/particles/part_emitter.cpp | 4 | ||||
-rw-r--r-- | engines/wintermute/base/scriptables/script.cpp | 2 | ||||
-rw-r--r-- | engines/wintermute/base/scriptables/script_engine.cpp | 2 | ||||
-rw-r--r-- | engines/wintermute/base/timer.cpp | 74 | ||||
-rw-r--r-- | engines/wintermute/base/timer.h | 57 |
15 files changed, 181 insertions, 48 deletions
diff --git a/engines/wintermute/base/base_engine.cpp b/engines/wintermute/base/base_engine.cpp index f8dc5dff8a..2dcf2d6cdc 100644 --- a/engines/wintermute/base/base_engine.cpp +++ b/engines/wintermute/base/base_engine.cpp @@ -106,4 +106,20 @@ BaseRenderer *BaseEngine::getRenderer() { } } +const Timer *BaseEngine::getTimer() { + if (instance()._gameRef) { + return instance()._gameRef->getTimer(); + } else { + return nullptr; + } +} + +const Timer *BaseEngine::getLiveTimer() { + if (instance()._gameRef) { + return instance()._gameRef->getLiveTimer(); + } else { + return nullptr; + } +} + } // end of namespace Wintermute diff --git a/engines/wintermute/base/base_engine.h b/engines/wintermute/base/base_engine.h index aa23cdd3e5..e460711d22 100644 --- a/engines/wintermute/base/base_engine.h +++ b/engines/wintermute/base/base_engine.h @@ -42,6 +42,7 @@ class BaseGame; class BaseSoundMgr; class BaseRenderer; class SystemClassRegistry; +class Timer; class BaseEngine : public Common::Singleton<Wintermute::BaseEngine> { void init(Common::Language lang); BaseFileManager *_fileManager; @@ -64,6 +65,8 @@ public: BaseFileManager *getFileManager() { return _fileManager; } BaseSoundMgr *getSoundMgr(); BaseRenderer *getRenderer(); + static const Timer *getTimer(); + static const Timer *getLiveTimer(); static void LOG(bool res, const char *fmt, ...); const char *getGameId() { return _gameId.c_str(); } }; diff --git a/engines/wintermute/base/base_fader.cpp b/engines/wintermute/base/base_fader.cpp index 8f74d71caf..079304520b 100644 --- a/engines/wintermute/base/base_fader.cpp +++ b/engines/wintermute/base/base_fader.cpp @@ -71,7 +71,7 @@ bool BaseFader::update() { if (_system) { time = g_system->getMillis() - _startTime; } else { - time = _gameRef->_timer - _startTime; + time = _gameRef->getTimer()->getTime() - _startTime; } if (time >= _duration) { @@ -129,7 +129,7 @@ bool BaseFader::fadeIn(uint32 sourceColor, uint32 duration, bool system) { if (_system) { _startTime = g_system->getMillis(); } else { - _startTime = _gameRef->_timer; + _startTime = _gameRef->getTimer()->getTime(); } return STATUS_OK; @@ -155,7 +155,7 @@ bool BaseFader::fadeOut(uint32 targetColor, uint32 duration, bool system) { if (_system) { _startTime = g_system->getMillis(); } else { - _startTime = _gameRef->_timer; + _startTime = _gameRef->getTimer()->getTime(); } diff --git a/engines/wintermute/base/base_game.cpp b/engines/wintermute/base/base_game.cpp index 9ae44173e4..4f8d099506 100644 --- a/engines/wintermute/base/base_game.cpp +++ b/engines/wintermute/base/base_game.cpp @@ -81,7 +81,7 @@ IMPLEMENT_PERSISTENT(BaseGame, true) ////////////////////////////////////////////////////////////////////// -BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gameId) { +BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gameId), _timerNormal(), _timerLive() { _shuttingDown = false; _state = GAME_RUNNING; @@ -122,14 +122,6 @@ BaseGame::BaseGame(const Common::String &gameId) : BaseObject(this), _gameId(gam _subtitles = true; _videoSubtitles = true; - _timer = 0; - _timerDelta = 0; - _timerLast = 0; - - _liveTimer = 0; - _liveTimerDelta = 0; - _liveTimerLast = 0; - _sequence = 0; _mousePos.x = _mousePos.y = 0; @@ -561,16 +553,12 @@ bool BaseGame::initLoop() { _lastTime = _currentTime; _fpsTime += _deltaTime; - _liveTimerDelta = _liveTimer - _liveTimerLast; - _liveTimerLast = _liveTimer; - _liveTimer += MIN((uint32)1000, _deltaTime); + _timerLive.updateTime(_deltaTime, 1000); if (_state != GAME_FROZEN) { - _timerDelta = _timer - _timerLast; - _timerLast = _timer; - _timer += MIN((uint32)1000, _deltaTime); + _timerNormal.updateTime(_deltaTime, 1000); } else { - _timerDelta = 0; + _timerNormal.setTimeDelta(0); } _framesRendered++; @@ -1985,7 +1973,7 @@ ScValue *BaseGame::scGetProperty(const Common::String &name) { // CurrentTime (RO) ////////////////////////////////////////////////////////////////////////// else if (name == "CurrentTime") { - _scValue->setInt((int)_timer); + _scValue->setInt((int)getTimer()->getTime()); return _scValue; } @@ -3104,13 +3092,8 @@ bool BaseGame::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_videoFont)); persistMgr->transfer(TMEMBER(_videoSubtitles)); - persistMgr->transfer(TMEMBER(_timer)); - persistMgr->transfer(TMEMBER(_timerDelta)); - persistMgr->transfer(TMEMBER(_timerLast)); - - persistMgr->transfer(TMEMBER(_liveTimer)); - persistMgr->transfer(TMEMBER(_liveTimerDelta)); - persistMgr->transfer(TMEMBER(_liveTimerLast)); + _timerNormal.persist(persistMgr); + _timerLive.persist(persistMgr); _renderer->persistSaveLoadImages(persistMgr); @@ -3777,7 +3760,7 @@ bool BaseGame::displayDebugInfo() { _systemFont->drawText((byte *)str, 0, 70, _renderer->getWidth(), TAL_RIGHT); - sprintf(str, "Timer: %d", _timer); + sprintf(str, "Timer: %d", getTimer()->getTime()); _gameRef->_systemFont->drawText((byte *)str, 0, 130, _renderer->getWidth(), TAL_RIGHT); if (_activeObject != nullptr) { diff --git a/engines/wintermute/base/base_game.h b/engines/wintermute/base/base_game.h index f3496f7dd0..a0af2164b1 100644 --- a/engines/wintermute/base/base_game.h +++ b/engines/wintermute/base/base_game.h @@ -30,6 +30,7 @@ #define WINTERMUTE_BASE_GAME_H #include "engines/wintermute/base/base_object.h" +#include "engines/wintermute/base/timer.h" #include "engines/wintermute/persistent.h" #include "engines/wintermute/coll_templ.h" #include "engines/wintermute/math/rect32.h" @@ -214,14 +215,13 @@ public: TGameState _state; TGameState _origState; bool _origInteractive; - uint32 _timer; - uint32 _timerDelta; - uint32 _timerLast; - - uint32 _liveTimer; - uint32 _liveTimerDelta; - uint32 _liveTimerLast; + const Timer *getTimer() const { return &_timerNormal; } + const Timer *getLiveTimer() const { return &_timerLive; } +private: + Timer _timerNormal; + Timer _timerLive; +public: BaseObject *_capturedObject; Point32 _mousePos; bool validObject(BaseObject *object); diff --git a/engines/wintermute/base/base_game_music.cpp b/engines/wintermute/base/base_game_music.cpp index 8dff41d854..a39deb8d8d 100644 --- a/engines/wintermute/base/base_game_music.cpp +++ b/engines/wintermute/base/base_game_music.cpp @@ -177,7 +177,7 @@ bool BaseGameMusic::updateMusicCrossfade() { _music[_musicCrossfadeChannel2]->play(); } - uint32 currentTime = _gameRef->_liveTimer - _musicCrossfadeStartTime; + uint32 currentTime = _gameRef->getLiveTimer()->getTime() - _musicCrossfadeStartTime; if (currentTime >= _musicCrossfadeLength) { _musicCrossfadeRunning = false; @@ -469,7 +469,7 @@ bool BaseGameMusic::scCallMethod(ScScript *script, ScStack *stack, ScStack *this return STATUS_OK; } - _musicCrossfadeStartTime = _gameRef->_liveTimer; + _musicCrossfadeStartTime = _gameRef->getLiveTimer()->getTime(); _musicCrossfadeChannel1 = channel1; _musicCrossfadeChannel2 = channel2; _musicCrossfadeLength = fadeLength; diff --git a/engines/wintermute/base/base_parser.cpp b/engines/wintermute/base/base_parser.cpp index 7f18c1f0cf..aaa376fe56 100644 --- a/engines/wintermute/base/base_parser.cpp +++ b/engines/wintermute/base/base_parser.cpp @@ -27,8 +27,8 @@ */ #include "engines/wintermute/base/base_parser.h" -#include "engines/wintermute/base/base_game.h" #include "engines/wintermute/base/base_engine.h" +#include "engines/wintermute/base/base_game.h" #include "engines/wintermute/platform_osystem.h" #include "common/str.h" #include "common/util.h" diff --git a/engines/wintermute/base/base_sprite.cpp b/engines/wintermute/base/base_sprite.cpp index 4f55e47c05..ecc878d415 100644 --- a/engines/wintermute/base/base_sprite.cpp +++ b/engines/wintermute/base/base_sprite.cpp @@ -365,9 +365,9 @@ bool BaseSprite::getCurrentFrame(float zoomX, float zoomY) { uint32 timer; if (_owner && _owner->_freezable) { - timer = _gameRef->_timer; + timer = _gameRef->getTimer()->getTime(); } else { - timer = _gameRef->_liveTimer; + timer = _gameRef->getLiveTimer()->getTime(); } int lastFrame = _currentFrame; diff --git a/engines/wintermute/base/base_surface_storage.cpp b/engines/wintermute/base/base_surface_storage.cpp index 08d2d2f767..9c9b7dc937 100644 --- a/engines/wintermute/base/base_surface_storage.cpp +++ b/engines/wintermute/base/base_surface_storage.cpp @@ -66,15 +66,15 @@ bool BaseSurfaceStorage::cleanup(bool warn) { ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceStorage::initLoop() { - if (_gameRef->_smartCache && _gameRef->_liveTimer - _lastCleanupTime >= _gameRef->_surfaceGCCycleTime) { - _lastCleanupTime = _gameRef->_liveTimer; + if (_gameRef->_smartCache && _gameRef->getLiveTimer()->getTime() - _lastCleanupTime >= _gameRef->_surfaceGCCycleTime) { + _lastCleanupTime = _gameRef->getLiveTimer()->getTime(); sortSurfaces(); for (uint32 i = 0; i < _surfaces.size(); i++) { if (_surfaces[i]->_lifeTime <= 0) { break; } - if (_surfaces[i]->_lifeTime > 0 && _surfaces[i]->_valid && (int)(_gameRef->_liveTimer - _surfaces[i]->_lastUsedTime) >= _surfaces[i]->_lifeTime) { + if (_surfaces[i]->_lifeTime > 0 && _surfaces[i]->_valid && (int)(_gameRef->getLiveTimer()->getTime() - _surfaces[i]->_lastUsedTime) >= _surfaces[i]->_lifeTime) { //_gameRef->QuickMessageForm("Invalidating: %s", _surfaces[i]->_filename); _surfaces[i]->invalidate(); } diff --git a/engines/wintermute/base/gfx/base_surface.cpp b/engines/wintermute/base/gfx/base_surface.cpp index d882adf5ad..2002463ea4 100644 --- a/engines/wintermute/base/gfx/base_surface.cpp +++ b/engines/wintermute/base/gfx/base_surface.cpp @@ -129,7 +129,7 @@ bool BaseSurface::invalidate() { ////////////////////////////////////////////////////////////////////////// bool BaseSurface::prepareToDraw() { - _lastUsedTime = _gameRef->_liveTimer; + _lastUsedTime = _gameRef->getLiveTimer()->getTime(); if (!_valid) { //_gameRef->LOG(0, "Reviving: %s", _filename); diff --git a/engines/wintermute/base/particles/part_emitter.cpp b/engines/wintermute/base/particles/part_emitter.cpp index 1026969055..1a8941747f 100644 --- a/engines/wintermute/base/particles/part_emitter.cpp +++ b/engines/wintermute/base/particles/part_emitter.cpp @@ -252,7 +252,7 @@ bool PartEmitter::update() { if (!_running) { return STATUS_OK; } else { - return updateInternal(_gameRef->_timer, _gameRef->_timerDelta); + return updateInternal(_gameRef->getTimer()->getTime(), _gameRef->getTimer()->getTimeDelta()); } } @@ -353,7 +353,7 @@ bool PartEmitter::start() { if (_overheadTime > 0) { uint32 delta = 500; int steps = _overheadTime / delta; - uint32 currentTime = _gameRef->_timer - _overheadTime; + uint32 currentTime = _gameRef->getTimer()->getTime() - _overheadTime; for (int i = 0; i < steps; i++) { updateInternal(currentTime, delta); diff --git a/engines/wintermute/base/scriptables/script.cpp b/engines/wintermute/base/scriptables/script.cpp index 23c452b73c..56ffbf75c5 100644 --- a/engines/wintermute/base/scriptables/script.cpp +++ b/engines/wintermute/base/scriptables/script.cpp @@ -1194,7 +1194,7 @@ bool ScScript::sleep(uint32 duration) { _waitTime = g_system->getMillis() + duration; _waitFrozen = true; } else { - _waitTime = _gameRef->_timer + duration; + _waitTime = _gameRef->getTimer()->getTime() + duration; _waitFrozen = false; } return STATUS_OK; diff --git a/engines/wintermute/base/scriptables/script_engine.cpp b/engines/wintermute/base/scriptables/script_engine.cpp index d5c5797a39..d8f38f2f4d 100644 --- a/engines/wintermute/base/scriptables/script_engine.cpp +++ b/engines/wintermute/base/scriptables/script_engine.cpp @@ -285,7 +285,7 @@ bool ScEngine::tick() { _scripts[i]->run(); } } else { - if (_scripts[i]->_waitTime <= _gameRef->_timer) { + if (_scripts[i]->_waitTime <= _gameRef->getTimer()->getTime()) { _scripts[i]->run(); } } diff --git a/engines/wintermute/base/timer.cpp b/engines/wintermute/base/timer.cpp new file mode 100644 index 0000000000..590dba4655 --- /dev/null +++ b/engines/wintermute/base/timer.cpp @@ -0,0 +1,74 @@ +/* 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. + * + */ + +/* + * This file is based on WME Lite. + * http://dead-code.org/redir.php?target=wmelite + * Copyright (c) 2011 Jan Nedoma + */ + +#include "engines/wintermute/base/timer.h" +#include "engines/wintermute/base/base_persistence_manager.h" +#include "engines/wintermute/persistent.h" + +namespace Wintermute { +Timer::Timer() : _timer(0), _timerDelta(0), _timerLast(0) { + +} + +void Timer::setTime(uint32 time) { + _timer = time; +} + +void Timer::setTimeDelta(uint32 timeDelta) { + _timerDelta = timeDelta; +} + +void Timer::setTimeLast(uint32 timeLast) { + _timerLast = timeLast; +} + +void Timer::updateTime(uint32 delta, uint32 max) { + _timerDelta = _timer - _timerLast; + _timerLast = _timer; + _timer += MIN((uint32)max, delta); +} + +uint32 Timer::getTime() const { + return _timer; +} + +uint32 Timer::getTimeDelta() const { + return _timerDelta; +} + +uint32 Timer::getTimeLast() const { + return _timerLast; +} + +void Timer::persist(BasePersistenceManager *persistMgr) { + persistMgr->transfer(TMEMBER(_timer)); + persistMgr->transfer(TMEMBER(_timerDelta)); + persistMgr->transfer(TMEMBER(_timerLast)); +} + +} // End of namespace Wintermute
\ No newline at end of file diff --git a/engines/wintermute/base/timer.h b/engines/wintermute/base/timer.h new file mode 100644 index 0000000000..8353b08abc --- /dev/null +++ b/engines/wintermute/base/timer.h @@ -0,0 +1,57 @@ +/* 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. + * + */ + +/* + * This file is based on WME Lite. + * http://dead-code.org/redir.php?target=wmelite + * Copyright (c) 2011 Jan Nedoma + */ + +#ifndef WINTERMUTE_TIMER_H +#define WINTERMUTE_TIMER_H + +#include "common/scummsys.h" + +namespace Wintermute { + +class BasePersistenceManager; + +class Timer { + uint32 _timer; + uint32 _timerDelta; + uint32 _timerLast; +public: + Timer(); + void setTime(uint32 time); + void setTimeDelta(uint32 timeDelta); + void setTimeLast(uint32 timeLast); + void updateTime(uint32 delta, uint32 max); + uint32 getTime() const; + uint32 getTimeDelta() const; + uint32 getTimeLast() const; + void persist(BasePersistenceManager *persistMgr); +}; + + +} // End of namespace Wintermute + +#endif
\ No newline at end of file |