aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra
diff options
context:
space:
mode:
authorMax Horn2009-04-11 09:57:57 +0000
committerMax Horn2009-04-11 09:57:57 +0000
commit5749b363d58d49c79db0a63f7eb136b34e3c641f (patch)
tree558f31601b4eee6c753a196f65c5af05b7c806e4 /engines/kyra
parent728745767294ecc3abf7fcb730370ff8951999ed (diff)
downloadscummvm-rg350-5749b363d58d49c79db0a63f7eb136b34e3c641f.tar.gz
scummvm-rg350-5749b363d58d49c79db0a63f7eb136b34e3c641f.tar.bz2
scummvm-rg350-5749b363d58d49c79db0a63f7eb136b34e3c641f.zip
KYRA: Replaced Rect class by Common::Rect; replaced dirty rect handling code by code similiar to the one used in SAGA and the frontend GUI code
svn-id: r39929
Diffstat (limited to 'engines/kyra')
-rw-r--r--engines/kyra/items_lok.cpp30
-rw-r--r--engines/kyra/kyra_lok.h2
-rw-r--r--engines/kyra/screen.cpp72
-rw-r--r--engines/kyra/screen.h10
-rw-r--r--engines/kyra/screen_lok.cpp19
-rw-r--r--engines/kyra/screen_lok.h6
6 files changed, 66 insertions, 73 deletions
diff --git a/engines/kyra/items_lok.cpp b/engines/kyra/items_lok.cpp
index 2c2903d0b3..34b76c7086 100644
--- a/engines/kyra/items_lok.cpp
+++ b/engines/kyra/items_lok.cpp
@@ -57,12 +57,12 @@ int KyraEngine_LoK::findDuplicateItemShape(int shape) {
void KyraEngine_LoK::addToNoDropRects(int x, int y, int w, int h) {
debugC(9, kDebugLevelMain, "KyraEngine_LoK::addToNoDropRects(%d, %d, %d, %d)", x, y, w, h);
- for (int rect = 0; rect < 11; ++rect) {
- if (_noDropRects[rect].x == -1) {
- _noDropRects[rect].x = x;
- _noDropRects[rect].y = y;
- _noDropRects[rect].x2 = x + w - 1;
- _noDropRects[rect].y2 = y + h - 1;
+ for (int rect = 0; rect < ARRAYSIZE(_noDropRects); ++rect) {
+ if (_noDropRects[rect].top == -1) {
+ _noDropRects[rect].left = x;
+ _noDropRects[rect].top = y;
+ _noDropRects[rect].right = x + w;
+ _noDropRects[rect].bottom = y + h;
break;
}
}
@@ -466,25 +466,25 @@ int KyraEngine_LoK::checkNoDropRects(int x, int y) {
debugC(9, kDebugLevelMain, "KyraEngine_LoK::checkNoDropRects(%d, %d)", x, y);
if (_lastProcessedItemHeight < 1 || _lastProcessedItemHeight > 16)
_lastProcessedItemHeight = 16;
- if (_noDropRects[0].x == -1)
+ if (_noDropRects[0].left == -1)
return 0;
- for (int i = 0; i < 11; ++i) {
- if (_noDropRects[i].x == -1)
+ for (int i = 0; i < ARRAYSIZE(_noDropRects); ++i) {
+ if (_noDropRects[i].left == -1)
break;
- int xpos = _noDropRects[i].x;
- int ypos = _noDropRects[i].y;
- int xpos2 = _noDropRects[i].x2;
- int ypos2 = _noDropRects[i].y2;
+ int xpos = _noDropRects[i].left;
+ int ypos = _noDropRects[i].top;
+ int xpos2 = _noDropRects[i].right;
+ int ypos2 = _noDropRects[i].bottom;
if (xpos > x + 16)
continue;
- if (xpos2 < x)
+ if (xpos2 <= x)
continue;
if (y < ypos)
continue;
- if (ypos2 < y - _lastProcessedItemHeight)
+ if (ypos2 <= y - _lastProcessedItemHeight)
continue;
return 1;
}
diff --git a/engines/kyra/kyra_lok.h b/engines/kyra/kyra_lok.h
index ebe110981e..a0f38c3acc 100644
--- a/engines/kyra/kyra_lok.h
+++ b/engines/kyra/kyra_lok.h
@@ -422,7 +422,7 @@ protected:
int32 _scaleMode;
int16 _scaleTable[145];
- Rect _noDropRects[11];
+ Common::Rect _noDropRects[11];
int8 _birthstoneGemTable[4];
int8 _idolGemsTable[3];
diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp
index 6178552450..26b8e3a922 100644
--- a/engines/kyra/screen.cpp
+++ b/engines/kyra/screen.cpp
@@ -62,8 +62,6 @@ Screen::~Screen() {
delete[] _palettes[i];
}
- delete[] _dirtyRects;
-
CursorMan.popAllCursors();
}
@@ -162,9 +160,6 @@ bool Screen::init() {
CursorMan.showMouse(false);
_forceFullUpdate = false;
- _numDirtyRects = 0;
- _dirtyRects = new Rect[kMaxDirtyRects];
- assert(_dirtyRects);
return true;
}
@@ -234,13 +229,13 @@ void Screen::updateDirtyRects() {
_system->copyRectToScreen(getCPagePtr(0), SCREEN_W, 0, 0, SCREEN_W, SCREEN_H);
} else {
const byte *page0 = getCPagePtr(0);
- for (int i = 0; i < _numDirtyRects; ++i) {
- Rect &cur = _dirtyRects[i];
- _system->copyRectToScreen(page0 + cur.y * SCREEN_W + cur.x, SCREEN_W, cur.x, cur.y, cur.x2, cur.y2);
+ Common::List<Common::Rect>::iterator it;
+ for (it = _dirtyRects.begin(); it != _dirtyRects.end(); ++it) {
+ _system->copyRectToScreen(page0 + it->top * SCREEN_W + it->left, SCREEN_W, it->left, it->top, it->width(), it->height());
}
}
_forceFullUpdate = false;
- _numDirtyRects = 0;
+ _dirtyRects.clear();
}
void Screen::updateDirtyRectsOvl() {
@@ -255,18 +250,18 @@ void Screen::updateDirtyRectsOvl() {
const byte *page0 = getCPagePtr(0);
byte *ovl0 = _sjisOverlayPtrs[0];
- for (int i = 0; i < _numDirtyRects; ++i) {
- Rect &cur = _dirtyRects[i];
- byte *dst = ovl0 + cur.y * 1280 + (cur.x<<1);
- const byte *src = page0 + cur.y * SCREEN_W + cur.x;
+ Common::List<Common::Rect>::iterator it;
+ for (it = _dirtyRects.begin(); it != _dirtyRects.end(); ++it) {
+ byte *dst = ovl0 + it->top * 1280 + (it->left<<1);
+ const byte *src = page0 + it->top * SCREEN_W + it->left;
- scale2x(dst, 640, src, SCREEN_W, cur.x2, cur.y2);
- mergeOverlay(cur.x<<1, cur.y<<1, cur.x2<<1, cur.y2<<1);
- _system->copyRectToScreen(dst, 640, cur.x<<1, cur.y<<1, cur.x2<<1, cur.y2<<1);
+ scale2x(dst, 640, src, SCREEN_W, it->width(), it->height());
+ mergeOverlay(it->left<<1, it->top<<1, it->width()<<1, it->height()<<1);
+ _system->copyRectToScreen(dst, 640, it->left<<1, it->top<<1, it->width()<<1, it->height()<<1);
}
}
_forceFullUpdate = false;
- _numDirtyRects = 0;
+ _dirtyRects.clear();
}
void Screen::scale2x(byte *dst, int dstPitch, const byte *src, int srcPitch, int w, int h) {
@@ -2835,35 +2830,38 @@ void Screen::loadPalette(const byte *data, uint8 *palData, int bytes) {
// dirty rect handling
void Screen::addDirtyRect(int x, int y, int w, int h) {
- if (_numDirtyRects == kMaxDirtyRects || _forceFullUpdate) {
+ if (_dirtyRects.size() >= kMaxDirtyRects || _forceFullUpdate) {
_forceFullUpdate = true;
return;
}
- if (w == 0 || h == 0 || x >= SCREEN_W || y >= SCREEN_H || x + w < 0 || y + h < 0)
- return;
+ Common::Rect r(x, y, x + w, y + h);
- if (x < 0) {
- w += x;
- x = 0;
- }
+ // Clip rectangle
+ r.clip(SCREEN_W, SCREEN_H);
- if (x + w >= 320)
- w = 320 - x;
+ // If it is empty after clipping, we are done
+ if (r.isEmpty())
+ return;
- if (y < 0) {
- h += y;
- y = 0;
- }
+ // Check if the new rectangle is contained within another in the list
+ Common::List<Common::Rect>::iterator it;
+ for (it = _dirtyRects.begin(); it != _dirtyRects.end(); ) {
+ // If we find a rectangle which fully contains the new one,
+ // we can abort the search.
+ if (it->contains(r))
+ return;
- if (y + h >= 200)
- h = 200 - y;
+ // Conversely, if we find rectangles which are contained in
+ // the new one, we can remove them
+ if (r.contains(*it))
+ it = _dirtyRects.erase(it);
+ else
+ ++it;
+ }
- Rect &cur = _dirtyRects[_numDirtyRects++];
- cur.x = x;
- cur.x2 = w;
- cur.y = y;
- cur.y2 = h;
+ // If we got here, we can safely add r to the list of dirty rects.
+ _dirtyRects.push_back(r);
}
// overlay functions
diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h
index 779887004c..15f0ab2079 100644
--- a/engines/kyra/screen.h
+++ b/engines/kyra/screen.h
@@ -28,6 +28,8 @@
#include "common/util.h"
#include "common/func.h"
+#include "common/list.h"
+#include "common/rect.h"
class OSystem;
@@ -37,11 +39,6 @@ typedef Common::Functor0<void> UpdateFunctor;
class KyraEngine_v1;
-struct Rect {
- int x, y;
- int x2, y2;
-};
-
struct ScreenDim {
uint16 sx;
uint16 sy;
@@ -300,8 +297,7 @@ protected:
};
bool _forceFullUpdate;
- int _numDirtyRects;
- Rect *_dirtyRects;
+ Common::List<Common::Rect> _dirtyRects;
void addDirtyRect(int x, int y, int w, int h);
diff --git a/engines/kyra/screen_lok.cpp b/engines/kyra/screen_lok.cpp
index da88abc61f..314e4c46ae 100644
--- a/engines/kyra/screen_lok.cpp
+++ b/engines/kyra/screen_lok.cpp
@@ -28,7 +28,6 @@
namespace Kyra {
-#define BITBLIT_RECTS 10
Screen_LoK::Screen_LoK(KyraEngine_LoK *vm, OSystem *system)
: Screen(vm, system) {
@@ -36,8 +35,6 @@ Screen_LoK::Screen_LoK(KyraEngine_LoK *vm, OSystem *system)
}
Screen_LoK::~Screen_LoK() {
- delete[] _bitBlitRects;
-
for (int i = 0; i < ARRAYSIZE(_saveLoadPage); ++i) {
delete[] _saveLoadPage[i];
_saveLoadPage[i] = 0;
@@ -56,9 +53,7 @@ bool Screen_LoK::init() {
if (!Screen::init())
return false;
- _bitBlitRects = new Rect[BITBLIT_RECTS];
- assert(_bitBlitRects);
- memset(_bitBlitRects, 0, sizeof(Rect)*BITBLIT_RECTS);
+ memset(_bitBlitRects, 0, sizeof(_bitBlitRects));
_bitBlitNum = 0;
memset(_saveLoadPage, 0, sizeof(_saveLoadPage));
memset(_saveLoadPageOvl, 0, sizeof(_saveLoadPageOvl));
@@ -104,19 +99,19 @@ void Screen_LoK::addBitBlitRect(int x, int y, int w, int h) {
if (_bitBlitNum >= BITBLIT_RECTS)
error("too many bit blit rects");
- _bitBlitRects[_bitBlitNum].x = x;
- _bitBlitRects[_bitBlitNum].y = y;
- _bitBlitRects[_bitBlitNum].x2 = w;
- _bitBlitRects[_bitBlitNum].y2 = h;
+ _bitBlitRects[_bitBlitNum].left = x;
+ _bitBlitRects[_bitBlitNum].top = y;
+ _bitBlitRects[_bitBlitNum].right = x + w;
+ _bitBlitRects[_bitBlitNum].bottom = y + h;
++_bitBlitNum;
}
void Screen_LoK::bitBlitRects() {
debugC(9, kDebugLevelScreen, "Screen_LoK::bitBlitRects()");
- Rect *cur = _bitBlitRects;
+ Common::Rect *cur = _bitBlitRects;
while (_bitBlitNum) {
_bitBlitNum--;
- copyRegion(cur->x, cur->y, cur->x, cur->y, cur->x2, cur->y2, 2, 0);
+ copyRegion(cur->left, cur->top, cur->left, cur->top, cur->width(), cur->height(), 2, 0);
++cur;
}
}
diff --git a/engines/kyra/screen_lok.h b/engines/kyra/screen_lok.h
index 136c098160..9250f1863c 100644
--- a/engines/kyra/screen_lok.h
+++ b/engines/kyra/screen_lok.h
@@ -32,6 +32,10 @@ namespace Kyra {
class KyraEngine_LoK;
+enum {
+ BITBLIT_RECTS = 10
+};
+
class Screen_LoK : public Screen {
public:
Screen_LoK(KyraEngine_LoK *vm, OSystem *system);
@@ -65,7 +69,7 @@ protected:
static const ScreenDim _screenDimTable[];
static const int _screenDimTableCount;
- Rect *_bitBlitRects;
+ Common::Rect _bitBlitRects[BITBLIT_RECTS];
int _bitBlitNum;
uint8 *_unkPtr1, *_unkPtr2;