diff options
| author | Filippos Karapetis | 2010-10-11 21:27:28 +0000 | 
|---|---|---|
| committer | Filippos Karapetis | 2010-10-11 21:27:28 +0000 | 
| commit | 576d6429bcf2c7be379c1d3a6d9b916f93b90924 (patch) | |
| tree | 17c2e8cc95b909d4a9ebf8d6a2df207a7c3d1256 | |
| parent | 8b144960f86cf430ef344ab90226fbdddb37fefa (diff) | |
| download | scummvm-rg350-576d6429bcf2c7be379c1d3a6d9b916f93b90924.tar.gz scummvm-rg350-576d6429bcf2c7be379c1d3a6d9b916f93b90924.tar.bz2 scummvm-rg350-576d6429bcf2c7be379c1d3a6d9b916f93b90924.zip  | |
TOON: Reduced CPU usage by about 40%
svn-id: r53151
| -rw-r--r-- | engines/toon/character.cpp | 2 | ||||
| -rw-r--r-- | engines/toon/script.cpp | 2 | ||||
| -rw-r--r-- | engines/toon/toon.cpp | 62 | ||||
| -rw-r--r-- | engines/toon/toon.h | 7 | 
4 files changed, 48 insertions, 25 deletions
diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp index 614cc9c05c..6f7258d43c 100644 --- a/engines/toon/character.cpp +++ b/engines/toon/character.cpp @@ -123,7 +123,7 @@ bool Character::walkTo(int32 newPosX, int32 newPosY) {  		_numPixelToWalk = 0;  		if (_blockingWalk) { -			while ((_x != newPosX || _y != newPosY) && _currentPathNode < _currentPathNodeCount && !_vm->shouldQuit()) { +			while ((_x != newPosX || _y != newPosY) && _currentPathNode < _currentPathNodeCount && !_vm->shouldQuitGame()) {  				if (_currentPathNode < _currentPathNodeCount - 10) {  					int32 delta = MIN(10, _currentPathNodeCount - _currentPathNode);  					int32 dx = _currentPathX[_currentPathNode+delta] - _x; diff --git a/engines/toon/script.cpp b/engines/toon/script.cpp index efd100db61..06d482f4e2 100644 --- a/engines/toon/script.cpp +++ b/engines/toon/script.cpp @@ -175,7 +175,7 @@ bool EMCInterpreter::start(EMCState *script, int function) {  }  bool EMCInterpreter::isValid(EMCState *script) { -	if (!script->ip || !script->dataPtr || _vm->shouldQuit()) +	if (!script->ip || !script->dataPtr || _vm->shouldQuitGame())  		return false;  	return true;  } diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp index 84b404d7f2..e9616e9f9a 100644 --- a/engines/toon/toon.cpp +++ b/engines/toon/toon.cpp @@ -76,6 +76,9 @@ void ToonEngine::init() {  	_conversationData = new int16[4096];  	memset(_conversationData, 0, 4096 * sizeof(int16)); +	_shouldQuit = false; +	_scriptStep = 0; +  	_cursorOffsetX = 0;  	_cursorOffsetY = 0;  	_currentHotspotItem = 0; @@ -154,6 +157,15 @@ void ToonEngine::init() {  	_mouseButton = 0;  } +void ToonEngine::waitForScriptStep() { +	// Wait after a specified number of script steps when executing a script +	// to lower CPU usage +	if (++_scriptStep >= 40) { +		g_system->delayMillis(10); +		_scriptStep = 0; +	} +} +  void ToonEngine::parseInput() {  	Common::EventManager *_event = _system->getEventManager(); @@ -268,7 +280,7 @@ void ToonEngine::updateTimers() {  					_script->start(status, 7);  					while (_script->run(status)) -						; +						waitForScriptStep();  					_currentScriptRegion--; @@ -395,8 +407,10 @@ void ToonEngine::copyToVirtualScreen(bool updateScreen) {  		_cursorAnimationInstance->render();  	}  	_system->copyRectToScreen((byte *)_mainSurface->pixels + state()->_currentScrollValue, 1280, 0, 0, 640, 400); -	if (updateScreen) +	if (updateScreen) {  		_system->updateScreen(); +		_shouldQuit = shouldQuit();	// update game quit flag - this shouldn't be called all the time, as it's a virtual function +	}  }  void ToonEngine::doFrame() { @@ -548,7 +562,7 @@ bool ToonEngine::showMainmenu(bool &loadedGame) {  				if (clickingOn != MAINMENUHOTSPOT_NONE)  					clickRelease = true;  			} -			if (shouldQuit()) { +			if (_shouldQuit) {  				clickingOn = MAINMENUHOTSPOT_NONE;  				clickRelease = true;  				doExit = true; @@ -634,7 +648,7 @@ Common::Error ToonEngine::run() {  // Strangerke - Commented (not used)  //	int32 oldTimer = _system->getMillis(); -	while (!shouldQuit() && _gameState->_currentScene != -1) +	while (!_shouldQuit && _gameState->_currentScene != -1)  		doFrame();  	return Common::kNoError;  } @@ -757,10 +771,12 @@ void ToonEngine::updateAnimationSceneScripts(int32 timeElapsed) {  		        !_sceneAnimationScripts[_lastProcessedSceneScript]._frozen) {  			_animationSceneScriptRunFlag = true; -			while (_animationSceneScriptRunFlag && _sceneAnimationScripts[_lastProcessedSceneScript]._lastTimer <= _system->getMillis() && !shouldQuit()) { +			while (_animationSceneScriptRunFlag && _sceneAnimationScripts[_lastProcessedSceneScript]._lastTimer <= _system->getMillis() && !_shouldQuit) {  				if (!_script->run(&_sceneAnimationScripts[_lastProcessedSceneScript]._state))  					_animationSceneScriptRunFlag = false; +				waitForScriptStep(); +  				if (_sceneAnimationScripts[_lastProcessedSceneScript]._frozen)  					break;  			} @@ -776,7 +792,7 @@ void ToonEngine::updateAnimationSceneScripts(int32 timeElapsed) {  		if (_lastProcessedSceneScript >= state()->_locations[state()->_currentScene]._numSceneAnimations)  			_lastProcessedSceneScript = 0; -	} while (_lastProcessedSceneScript != startScript && !shouldQuit()); +	} while (_lastProcessedSceneScript != startScript && !_shouldQuit);  	_updatingSceneScriptRunFlag = false; @@ -978,12 +994,12 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) {  		_script->start(&_scriptState[0], 0);  		while (_script->run(&_scriptState[0])) -			; +			waitForScriptStep();  		_script->start(&_scriptState[0], 8);  		while (_script->run(&_scriptState[0])) -			; +			waitForScriptStep();  		if (_gameState->_nextSpecialEnterX != -1 && _gameState->_nextSpecialEnterY != -1) {  			_drew->setPosition(_gameState->_nextSpecialEnterX, _gameState->_nextSpecialEnterY); @@ -994,12 +1010,12 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) {  		_script->start(&_scriptState[0], 3);  		while (_script->run(&_scriptState[0])) -			; +			waitForScriptStep();  		_script->start(&_scriptState[0], 4);  		while (_script->run(&_scriptState[0])) -			; +			waitForScriptStep();  	} @@ -1061,7 +1077,7 @@ void ToonEngine::initChapter() {  	_script->init(&status, &data);  	_script->start(&status, 0);  	while (_script->run(&status)) -		; +		waitForScriptStep();  	setupGeneralPalette(); @@ -1142,7 +1158,7 @@ int32 ToonEngine::runEventScript(int32 x, int32 y, int32 mode, int32 id, int32 s  	_script->start(status, 1);  	while (_script->run(status)) -		; +		waitForScriptStep();  	_currentScriptRegion--; @@ -1632,7 +1648,7 @@ void ToonEngine::sayLines(int numLines, int dialogId) {  		if (!characterTalk(currentLine))  			break; -		while (_audioManager->voiceStillPlaying() && !shouldQuit()) +		while (_audioManager->voiceStillPlaying() && !_shouldQuit)  			doFrame();  		// find next line @@ -1757,7 +1773,7 @@ int32 ToonEngine::characterTalk(int32 dialogid, bool blocking) {  	// if one voice is still playing, wait !  	if (blocking) { -		while (_audioManager->voiceStillPlaying() && !shouldQuit()) +		while (_audioManager->voiceStillPlaying() && !_shouldQuit)  			doFrame();  		char *cc = c; @@ -1768,7 +1784,7 @@ int32 ToonEngine::characterTalk(int32 dialogid, bool blocking) {  			cc -= 4;  			waitChar = getCharacterById(listenerId);  			if (waitChar) { -				while ((waitChar->getAnimFlag() & 0x10) == 0x10 && !shouldQuit()) +				while ((waitChar->getAnimFlag() & 0x10) == 0x10 && !_shouldQuit)  					doFrame();  			} @@ -1777,7 +1793,7 @@ int32 ToonEngine::characterTalk(int32 dialogid, bool blocking) {  		waitChar = getCharacterById(talkerId);  		if (waitChar && !_gameState->_inInventory) { -			while ((waitChar->getAnimFlag() & 0x10) == 0x10 && !shouldQuit()) +			while ((waitChar->getAnimFlag() & 0x10) == 0x10 && !_shouldQuit)  				doFrame();  		}  	} else { @@ -1822,7 +1838,7 @@ int32 ToonEngine::characterTalk(int32 dialogid, bool blocking) {  	}  	if (blocking) { -		while (_audioManager->voiceStillPlaying() && !shouldQuit()) +		while (_audioManager->voiceStillPlaying() && !_shouldQuit)  			doFrame();  		_gameState->_mouseHidden = oldMouseHidden && _gameState->_mouseHidden;  	} @@ -1864,11 +1880,11 @@ void ToonEngine::haveAConversation(int32 convId) {  	_mouseButton = 0;  	_gameState->_firstConverstationLine = true; -	while (!_gameState->_exitConversation && !shouldQuit()) { +	while (!_gameState->_exitConversation && !_shouldQuit) {  		_gameState->_mouseHidden = false;  		_gameState->_showConversationIcons = true;  		int32 oldMouseButton = _mouseButton; -		while (!shouldQuit()) { +		while (!_shouldQuit) {  			doFrame();  			if (_mouseButton != 0) { @@ -1889,7 +1905,7 @@ void ToonEngine::haveAConversation(int32 convId) {  				a++;  			}  		} -		if (shouldQuit()) return; +		if (_shouldQuit) return;  		_gameState->_showConversationIcons = false;  		_gameState->_mouseHidden = 1; @@ -2314,7 +2330,7 @@ int32 ToonEngine::showInventory() {  	int32 justPressedButton = 0;  	_firstFrame = true; -	while (!shouldQuit()) { +	while (!_shouldQuit) {  		getMouseEvent();  		justPressedButton = _mouseButton & ~oldMouseButton; @@ -2409,7 +2425,7 @@ void ToonEngine::getMouseEvent() {  	Common::EventManager *_event = _system->getEventManager();  	Common::Event event; -	while (_event->pollEvent(event) && !shouldQuit()) +	while (_event->pollEvent(event) && !_shouldQuit)  		;  	_mouseX = _event->getMousePos().x; @@ -3072,7 +3088,7 @@ void ToonEngine::viewInventoryItem(Common::String str, int32 lineId, int32 itemD  	int32 oldScrollValue = _gameState->_currentScrollValue;  	_gameState->_currentScrollValue = 0; -	while (!shouldQuit()) { +	while (!_shouldQuit) {  		getMouseEvent();  		justPressedButton = _mouseButton & ~oldMouseButton; diff --git a/engines/toon/toon.h b/engines/toon/toon.h index 2d6b315bca..30aa344517 100644 --- a/engines/toon/toon.h +++ b/engines/toon/toon.h @@ -185,6 +185,7 @@ public:  	void restorePalette();  	const char *getSpecialConversationMusic(int32 locationId);   	void playRoomMusic(); +	void waitForScriptStep();  	Resources *resources() {  		return _resources; @@ -286,6 +287,10 @@ public:  		return _saveBufferStream;  	} +	bool shouldQuitGame() const { +		return _shouldQuit; +	} +  protected:  	OSystem *_system;  	int32 _tickLength; @@ -349,6 +354,8 @@ protected:  	Hotspots *_hotspots;  	int32 _currentHotspotItem; +	bool _shouldQuit; +	int32 _scriptStep;  	int32 _mouseX;  	int32 _mouseY;  | 
