[Scummvm-cvs-logs] SF.net SVN: scummvm:[53151] scummvm/trunk/engines/toon
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Mon Oct 11 23:27:28 CEST 2010
Revision: 53151
http://scummvm.svn.sourceforge.net/scummvm/?rev=53151&view=rev
Author: thebluegr
Date: 2010-10-11 21:27:28 +0000 (Mon, 11 Oct 2010)
Log Message:
-----------
TOON: Reduced CPU usage by about 40%
Modified Paths:
--------------
scummvm/trunk/engines/toon/character.cpp
scummvm/trunk/engines/toon/script.cpp
scummvm/trunk/engines/toon/toon.cpp
scummvm/trunk/engines/toon/toon.h
Modified: scummvm/trunk/engines/toon/character.cpp
===================================================================
--- scummvm/trunk/engines/toon/character.cpp 2010-10-11 19:54:55 UTC (rev 53150)
+++ scummvm/trunk/engines/toon/character.cpp 2010-10-11 21:27:28 UTC (rev 53151)
@@ -123,7 +123,7 @@
_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;
Modified: scummvm/trunk/engines/toon/script.cpp
===================================================================
--- scummvm/trunk/engines/toon/script.cpp 2010-10-11 19:54:55 UTC (rev 53150)
+++ scummvm/trunk/engines/toon/script.cpp 2010-10-11 21:27:28 UTC (rev 53151)
@@ -175,7 +175,7 @@
}
bool EMCInterpreter::isValid(EMCState *script) {
- if (!script->ip || !script->dataPtr || _vm->shouldQuit())
+ if (!script->ip || !script->dataPtr || _vm->shouldQuitGame())
return false;
return true;
}
Modified: scummvm/trunk/engines/toon/toon.cpp
===================================================================
--- scummvm/trunk/engines/toon/toon.cpp 2010-10-11 19:54:55 UTC (rev 53150)
+++ scummvm/trunk/engines/toon/toon.cpp 2010-10-11 21:27:28 UTC (rev 53151)
@@ -76,6 +76,9 @@
_conversationData = new int16[4096];
memset(_conversationData, 0, 4096 * sizeof(int16));
+ _shouldQuit = false;
+ _scriptStep = 0;
+
_cursorOffsetX = 0;
_cursorOffsetY = 0;
_currentHotspotItem = 0;
@@ -154,6 +157,15 @@
_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 @@
_script->start(status, 7);
while (_script->run(status))
- ;
+ waitForScriptStep();
_currentScriptRegion--;
@@ -395,8 +407,10 @@
_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 @@
if (clickingOn != MAINMENUHOTSPOT_NONE)
clickRelease = true;
}
- if (shouldQuit()) {
+ if (_shouldQuit) {
clickingOn = MAINMENUHOTSPOT_NONE;
clickRelease = true;
doExit = true;
@@ -634,7 +648,7 @@
// 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 @@
!_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 @@
if (_lastProcessedSceneScript >= state()->_locations[state()->_currentScene]._numSceneAnimations)
_lastProcessedSceneScript = 0;
- } while (_lastProcessedSceneScript != startScript && !shouldQuit());
+ } while (_lastProcessedSceneScript != startScript && !_shouldQuit);
_updatingSceneScriptRunFlag = false;
@@ -978,12 +994,12 @@
_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 @@
_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 @@
_script->init(&status, &data);
_script->start(&status, 0);
while (_script->run(&status))
- ;
+ waitForScriptStep();
setupGeneralPalette();
@@ -1142,7 +1158,7 @@
_script->start(status, 1);
while (_script->run(status))
- ;
+ waitForScriptStep();
_currentScriptRegion--;
@@ -1632,7 +1648,7 @@
if (!characterTalk(currentLine))
break;
- while (_audioManager->voiceStillPlaying() && !shouldQuit())
+ while (_audioManager->voiceStillPlaying() && !_shouldQuit)
doFrame();
// find next line
@@ -1757,7 +1773,7 @@
// 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 @@
cc -= 4;
waitChar = getCharacterById(listenerId);
if (waitChar) {
- while ((waitChar->getAnimFlag() & 0x10) == 0x10 && !shouldQuit())
+ while ((waitChar->getAnimFlag() & 0x10) == 0x10 && !_shouldQuit)
doFrame();
}
@@ -1777,7 +1793,7 @@
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 @@
}
if (blocking) {
- while (_audioManager->voiceStillPlaying() && !shouldQuit())
+ while (_audioManager->voiceStillPlaying() && !_shouldQuit)
doFrame();
_gameState->_mouseHidden = oldMouseHidden && _gameState->_mouseHidden;
}
@@ -1864,11 +1880,11 @@
_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 @@
a++;
}
}
- if (shouldQuit()) return;
+ if (_shouldQuit) return;
_gameState->_showConversationIcons = false;
_gameState->_mouseHidden = 1;
@@ -2314,7 +2330,7 @@
int32 justPressedButton = 0;
_firstFrame = true;
- while (!shouldQuit()) {
+ while (!_shouldQuit) {
getMouseEvent();
justPressedButton = _mouseButton & ~oldMouseButton;
@@ -2409,7 +2425,7 @@
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 @@
int32 oldScrollValue = _gameState->_currentScrollValue;
_gameState->_currentScrollValue = 0;
- while (!shouldQuit()) {
+ while (!_shouldQuit) {
getMouseEvent();
justPressedButton = _mouseButton & ~oldMouseButton;
Modified: scummvm/trunk/engines/toon/toon.h
===================================================================
--- scummvm/trunk/engines/toon/toon.h 2010-10-11 19:54:55 UTC (rev 53150)
+++ scummvm/trunk/engines/toon/toon.h 2010-10-11 21:27:28 UTC (rev 53151)
@@ -185,6 +185,7 @@
void restorePalette();
const char *getSpecialConversationMusic(int32 locationId);
void playRoomMusic();
+ void waitForScriptStep();
Resources *resources() {
return _resources;
@@ -286,6 +287,10 @@
return _saveBufferStream;
}
+ bool shouldQuitGame() const {
+ return _shouldQuit;
+ }
+
protected:
OSystem *_system;
int32 _tickLength;
@@ -349,6 +354,8 @@
Hotspots *_hotspots;
int32 _currentHotspotItem;
+ bool _shouldQuit;
+ int32 _scriptStep;
int32 _mouseX;
int32 _mouseY;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list