aboutsummaryrefslogtreecommitdiff
path: root/engines/toltecs/toltecs.cpp
diff options
context:
space:
mode:
authorBenjamin Haisch2008-09-20 19:06:41 +0000
committerWillem Jan Palenstijn2011-11-20 22:43:06 +0100
commit7b97e8cd9370095b999b22371c1aef606a8464a1 (patch)
tree5b498423cef9e27432934da0b19794fbc1f2c038 /engines/toltecs/toltecs.cpp
parent37a5f9e9ef9039808b225f598d02c1c48bc9fa95 (diff)
downloadscummvm-rg350-7b97e8cd9370095b999b22371c1aef606a8464a1.tar.gz
scummvm-rg350-7b97e8cd9370095b999b22371c1aef606a8464a1.tar.bz2
scummvm-rg350-7b97e8cd9370095b999b22371c1aef606a8464a1.zip
TOLTECS: A lot of changes in the graphics code:
- Optimized drawing code; now only items (sprites, text, screen masks) which have changed from the previous frame are redrawn, this speeds up things a lot - Implemented dirty rectangles using a microtile array - The previously committed Microtile Array implementation from SEL seemed buggy so I wrote my own version which works nicely so far (and is less code and GPL), only MicroTileArray::getRectangles uses parts from the old version, this will be changed later - One known bug related to dirty rectangles remains: Sometimes the background isn't restored correctly and gfx artifacts are visible
Diffstat (limited to 'engines/toltecs/toltecs.cpp')
-rw-r--r--engines/toltecs/toltecs.cpp78
1 files changed, 28 insertions, 50 deletions
diff --git a/engines/toltecs/toltecs.cpp b/engines/toltecs/toltecs.cpp
index f9ebb416c6..3c9f1dbda9 100644
--- a/engines/toltecs/toltecs.cpp
+++ b/engines/toltecs/toltecs.cpp
@@ -42,11 +42,11 @@
#include "toltecs/menu.h"
#include "toltecs/movie.h"
#include "toltecs/palette.h"
+#include "toltecs/render.h"
#include "toltecs/resource.h"
#include "toltecs/script.h"
#include "toltecs/screen.h"
#include "toltecs/segmap.h"
-
#include "toltecs/microtiles.h"
namespace Toltecs {
@@ -89,8 +89,6 @@ int ToltecsEngine::init() {
int ToltecsEngine::go() {
- _system->setFeatureState(OSystem::kFeatureAutoComputeDirtyRects, true);
-
_quitGame = false;
_counter01 = 0;
_counter02 = 0;
@@ -162,23 +160,6 @@ int ToltecsEngine::go() {
}
#endif
-//#define TEST_MICROTILES
-#ifdef TEST_MICROTILES
- MicroTileArray *uta = new MicroTileArray(0, 0, 640, 480);
- uta->unite(Common::Rect(10, 10, 50, 50));
- uta->unite(Common::Rect(45, 45, 60, 60));
- Common::Rect *rects;
- int n_rects;
- n_rects = uta->getRectangles(rects);
- printf("n_rects = %d\n", n_rects); fflush(stdout);
- for (int i = 0; i < n_rects; i++) {
- printf("%d, %d, %d, %d\n", rects[i].left, rects[i].top, rects[i].right, rects[i].bottom);
- fflush(stdout);
- }
- _system->quit();
- delete uta;
-#endif
-
#if 1
_script->loadScript(0, 0);
_script->runScript(0);
@@ -231,6 +212,9 @@ void ToltecsEngine::loadScene(uint resIndex) {
// Load scene segmap
_segmap->load(scene + imageSize + 4);
+ _screen->_fullRefresh = true;
+ _screen->_renderQueue->clear();
+
}
void ToltecsEngine::updateScreen() {
@@ -238,21 +222,19 @@ void ToltecsEngine::updateScreen() {
// FIXME: Quick hack, sometimes cameraY was negative (the code in updateCamera was at fault)
if (_cameraY < 0) _cameraY = 0;
- // TODO: Optimize redraw by using dirty rectangles
- byte *destp = _screen->_frontScreen;
- byte *srcp = _screen->_backScreen + _cameraX + _cameraY * _sceneWidth;
- for (uint y = 0; y < MIN<uint>(_cameraHeight, 400); y++) {
- memcpy(destp, srcp, MIN<uint>(_sceneWidth, 640));
- destp += 640;
- srcp += _sceneWidth;
- }
+ _segmap->addMasksToRenderQueue();
+ _screen->addTalkTextItemsToRenderQueue();
- _screen->drawSprites();
- _screen->clearSprites();
+ _screen->_renderQueue->update();
+
+ //printf("_guiHeight = %d\n", _guiHeight); fflush(stdout);
- _screen->drawTalkTextItems();
+ if (_screen->_guiRefresh && _guiHeight > 0 && _cameraHeight > 0) {
+ _system->copyRectToScreen((const byte *)_screen->_frontScreen + _cameraHeight * 640,
+ 640, 0, _cameraHeight, 640, _guiHeight);
+ _screen->_guiRefresh = false;
+ }
- _system->copyRectToScreen((const byte *)_screen->_frontScreen, 640, 0, 0, 640, 400);
_system->updateScreen();
updateCamera();
@@ -268,7 +250,7 @@ void ToltecsEngine::updateInput() {
// FIXME: This is just for debugging
switch (event.kbd.keycode) {
- case Common::KEYCODE_F5:
+ case Common::KEYCODE_F7:
savegame("toltecs.001");
break;
case Common::KEYCODE_F9:
@@ -342,6 +324,15 @@ void ToltecsEngine::updateInput() {
}
+void ToltecsEngine::setGuiHeight(int16 guiHeight) {
+ if (guiHeight != _guiHeight) {
+ _guiHeight = guiHeight;
+ _cameraHeight = 400 - _guiHeight;
+ debug(0, "ToltecsEngine::setGuiHeight() _guiHeight = %d; _cameraHeight = %d", _guiHeight, _cameraHeight);
+ // TODO: clearScreen();
+ }
+}
+
void ToltecsEngine::setCamera(int16 x, int16 y) {
_screen->finishTextDrawItems();
@@ -356,8 +347,6 @@ void ToltecsEngine::setCamera(int16 x, int16 y) {
y = _sceneHeight - _cameraHeight;
*/
- // TODO DirtyRect clearing stuff
-
_screen->clearSprites();
_cameraX = x;
@@ -366,17 +355,6 @@ void ToltecsEngine::setCamera(int16 x, int16 y) {
_cameraY = y;
_newCameraY = y;
- // TODO More DirtyRect clearing stuff
-
-}
-
-void ToltecsEngine::setGuiHeight(int16 guiHeight) {
- if (guiHeight != _guiHeight) {
- _guiHeight = guiHeight;
- _cameraHeight = 400 - _guiHeight;
- debug(0, "ToltecsEngine::setGuiHeight() _guiHeight = %d; _cameraHeight = %d", _guiHeight, _cameraHeight);
- // TODO: clearScreen();
- }
}
void ToltecsEngine::scrollCameraUp(int16 delta) {
@@ -385,7 +363,6 @@ void ToltecsEngine::scrollCameraUp(int16 delta) {
_newCameraY = 0;
else
_newCameraY -= delta;
- _screen->finishTextDrawItems();
}
}
@@ -396,7 +373,6 @@ void ToltecsEngine::scrollCameraDown(int16 delta) {
delta += (_sceneHeight - _cameraHeight) - (delta + _newCameraY);
_newCameraY += delta;
debug(0, "ToltecsEngine::scrollCameraDown() _newCameraY = %d; delta = %d", _newCameraY, delta);
- _screen->finishTextDrawItems();
}
}
@@ -406,7 +382,6 @@ void ToltecsEngine::scrollCameraLeft(int16 delta) {
_newCameraX = 0;
else
_newCameraX -= delta;
- _screen->finishTextDrawItems();
}
}
@@ -417,7 +392,6 @@ void ToltecsEngine::scrollCameraRight(int16 delta) {
delta += (_sceneWidth - 640) - (delta + _newCameraX);
_newCameraX += delta;
debug(0, "ToltecsEngine::scrollCameraRight() _newCameraX = %d; delta = %d", _newCameraY, delta);
- _screen->finishTextDrawItems();
}
}
@@ -426,11 +400,15 @@ void ToltecsEngine::updateCamera() {
if (_cameraX != _newCameraX) {
//dirtyFullRefresh = -1;
_cameraX = _newCameraX;
+ _screen->_fullRefresh = true;
+ _screen->finishTextDrawItems();
}
if (_cameraY != _newCameraY) {
//dirtyFullRefresh = -1;
_cameraY = _newCameraY;
+ _screen->_fullRefresh = true;
+ _screen->finishTextDrawItems();
}
debug(0, "ToltecsEngine::updateCamera() _cameraX = %d; _cameraY = %d", _cameraX, _cameraY);