aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/gui
diff options
context:
space:
mode:
authorFilippos Karapetis2009-10-30 17:38:11 +0000
committerFilippos Karapetis2009-10-30 17:38:11 +0000
commit8bf3e5b5499d53235912bb6082424eae9ca6efcd (patch)
tree7ce4556f29119f37d4d68482423c9d9c3ae001ae /engines/sci/gui
parent371097d27cca28c1d7163f288fe8b229841d9b8d (diff)
downloadscummvm-rg350-8bf3e5b5499d53235912bb6082424eae9ca6efcd.tar.gz
scummvm-rg350-8bf3e5b5499d53235912bb6082424eae9ca6efcd.tar.bz2
scummvm-rg350-8bf3e5b5499d53235912bb6082424eae9ca6efcd.zip
Added caching of views
svn-id: r45542
Diffstat (limited to 'engines/sci/gui')
-rw-r--r--engines/sci/gui/gui.cpp39
-rw-r--r--engines/sci/gui/gui_animate.cpp14
-rw-r--r--engines/sci/gui/gui_gfx.cpp35
-rw-r--r--engines/sci/gui/gui_gfx.h13
4 files changed, 46 insertions, 55 deletions
diff --git a/engines/sci/gui/gui.cpp b/engines/sci/gui/gui.cpp
index fa73d3510a..15087adf4d 100644
--- a/engines/sci/gui/gui.cpp
+++ b/engines/sci/gui/gui.cpp
@@ -644,13 +644,12 @@ bool SciGui::canBeHere(reg_t curObject, reg_t listReference) {
}
bool SciGui::isItSkip(GuiResourceId viewId, int16 loopNo, int16 celNo, Common::Point position) {
- SciGuiView *tmpView = new SciGuiView(_s->resMan, NULL, NULL, viewId);
+ SciGuiView *tmpView = _gfx->getView(viewId);
sciViewCelInfo *celInfo = tmpView->getCelInfo(loopNo, celNo);
position.x = CLIP<int>(position.x, 0, celInfo->width - 1);
position.y = CLIP<int>(position.y, 0, celInfo->height - 1);
byte *celData = tmpView->getBitmap(loopNo, celNo);
bool result = (celData[position.y * celInfo->width + position.x] == celInfo->clearKey);
- delete tmpView;
return result;
}
@@ -664,7 +663,7 @@ void SciGui::baseSetter(reg_t object) {
int16 loopNo = GET_SEL32V(_s->_segMan, object, loop);
int16 celNo = GET_SEL32V(_s->_segMan, object, cel);
- SciGuiView *tmpView = new SciGuiView(_s->resMan, NULL, NULL, viewId);
+ SciGuiView *tmpView = _gfx->getView(viewId);
sciViewCelInfo *celInfo = tmpView->getCelInfo(loopNo, celNo);
int16 left = x + celInfo->displaceX - (celInfo->width >> 1);
int16 right = left + celInfo->width;
@@ -674,8 +673,6 @@ void SciGui::baseSetter(reg_t object) {
debugC(2, kDebugLevelBaseSetter, "(%d,%d)+/-(%d,%d), (%d x %d) -> (%d, %d) to (%d, %d)\n",
x, y, celInfo->displaceX, celInfo->displaceY, celInfo->width, celInfo->height, left, top, bottom, right);
- delete tmpView;
-
PUT_SEL32V(_s->_segMan, object, brLeft, left);
PUT_SEL32V(_s->_segMan, object, brRight, right);
PUT_SEL32V(_s->_segMan, object, brTop, top);
@@ -725,43 +722,19 @@ void SciGui::moveCursor(Common::Point pos) {
}
int16 SciGui::getCelWidth(GuiResourceId viewId, int16 loopNo, int16 celNo) {
- SciGuiView *tmpView = new SciGuiView(_s->resMan, _screen, _palette, viewId);
- sciViewCelInfo *celInfo = tmpView->getCelInfo(loopNo, celNo);
- int16 celWidth = celInfo->width;
- delete tmpView;
-
- return celWidth;
+ return _gfx->getView(viewId)->getCelInfo(loopNo, celNo)->width;
}
int16 SciGui::getCelHeight(GuiResourceId viewId, int16 loopNo, int16 celNo) {
- SciGuiView *tmpView = new SciGuiView(_s->resMan, _screen, _palette, viewId);
- sciViewCelInfo *celInfo = tmpView->getCelInfo(loopNo, celNo);
- int16 celHeight = celInfo->height;
- delete tmpView;
-
- return celHeight;
+ return _gfx->getView(viewId)->getCelInfo(loopNo, celNo)->height;
}
int16 SciGui::getLoopCount(GuiResourceId viewId) {
- SciGuiView *tmpView = new SciGuiView(_s->resMan, _screen, _palette, viewId);
- if (!tmpView)
- return -1;
-
- uint16 loopCount = tmpView->getLoopCount();
- delete tmpView;
-
- return loopCount;
+ return _gfx->getView(viewId)->getLoopCount();
}
int16 SciGui::getCelCount(GuiResourceId viewId, int16 loopNo) {
- SciGuiView *tmpView = new SciGuiView(_s->resMan, _screen, _palette, viewId);
- if (!tmpView)
- return -1;
-
- uint16 celCount = tmpView->getLoopInfo(loopNo)->celCount;
- delete tmpView;
-
- return celCount;
+ return _gfx->getView(viewId)->getLoopInfo(loopNo)->celCount;
}
bool SciGui::debugUndither(bool flag) {
diff --git a/engines/sci/gui/gui_animate.cpp b/engines/sci/gui/gui_animate.cpp
index a130e44eea..f88f2dc0d2 100644
--- a/engines/sci/gui/gui_animate.cpp
+++ b/engines/sci/gui/gui_animate.cpp
@@ -196,7 +196,7 @@ void SciGuiAnimate::fill(byte &old_picNotValid) {
curObject = listEntry->object;
// Get the corresponding view
- view = new SciGuiView(_s->resMan, _screen, _palette, listEntry->viewId);
+ view = _gfx->getView(listEntry->viewId);
// adjust loop and cel, if any of those is invalid
if (listEntry->loopNo >= view->getLoopCount()) {
@@ -238,8 +238,6 @@ void SciGuiAnimate::fill(byte &old_picNotValid) {
listEntry->signal = signal;
listIterator++;
-
- delete view;
}
}
@@ -544,7 +542,7 @@ void SciGuiAnimate::addToPicDrawCels() {
listEntry->priority = _gfx->CoordinateToPriority(listEntry->y);
// Get the corresponding view
- view = new SciGuiView(_s->resMan, _screen, _palette, listEntry->viewId);
+ view = _gfx->getView(listEntry->viewId);
// Create rect according to coordinates and given cel
view->getCelRect(listEntry->loopNo, listEntry->celNo, listEntry->x, listEntry->y, listEntry->z, &listEntry->celRect);
@@ -557,22 +555,16 @@ void SciGuiAnimate::addToPicDrawCels() {
}
listIterator++;
-
- delete view;
}
}
void SciGuiAnimate::addToPicDrawView(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, int16 leftPos, int16 topPos, int16 priority, int16 control) {
- SciGuiView *view = NULL;
+ SciGuiView *view = _gfx->getView(viewId);
Common::Rect celRect;
- view = new SciGuiView(_s->resMan, _screen, _palette, viewId);
-
// Create rect according to coordinates and given cel
view->getCelRect(loopNo, celNo, leftPos, topPos, priority, &celRect);
_gfx->drawCel(view, loopNo, celNo, celRect, priority, 0);
-
- delete view;
}
} // End of namespace Sci
diff --git a/engines/sci/gui/gui_gfx.cpp b/engines/sci/gui/gui_gfx.cpp
index 1df394c302..1719b6d845 100644
--- a/engines/sci/gui/gui_gfx.cpp
+++ b/engines/sci/gui/gui_gfx.cpp
@@ -45,6 +45,8 @@ SciGuiGfx::SciGuiGfx(EngineState *state, SciGuiScreen *screen, SciGuiPalette *pa
}
SciGuiGfx::~SciGuiGfx() {
+ purgeCache();
+
delete _mainPort;
delete _menuPort;
}
@@ -66,6 +68,25 @@ void SciGuiGfx::init(SciGuiText *text) {
_menuRect = Common::Rect(0, 0, _screen->_width, 9);
}
+void SciGuiGfx::purgeCache() {
+ for (ViewCache::iterator iter = _cachedViews.begin(); iter != _cachedViews.end(); ++iter) {
+ delete iter->_value;
+ iter->_value = 0;
+ }
+
+ _cachedViews.clear();
+}
+
+SciGuiView *SciGuiGfx::getView(GuiResourceId viewNum) {
+ if (_cachedViews.size() >= MAX_CACHED_VIEWS)
+ purgeCache();
+
+ if (!_cachedViews.contains(viewNum))
+ _cachedViews[viewNum] = new SciGuiView(_s->resMan, _screen, _palette, viewNum);
+
+ return _cachedViews[viewNum];
+}
+
GuiPort *SciGuiGfx::SetPort(GuiPort *newPort) {
GuiPort *oldPort = _curPort;
_curPort = newPort;
@@ -309,7 +330,7 @@ void SciGuiGfx::drawPicture(GuiResourceId pictureId, int16 animationNr, bool mir
// This one is the only one that updates screen!
void SciGuiGfx::drawCel(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, uint16 leftPos, uint16 topPos, byte priority, uint16 paletteNo) {
- SciGuiView *view = new SciGuiView(_s->resMan, _screen, _palette, viewId);
+ SciGuiView *view = getView(viewId);
Common::Rect rect;
Common::Rect clipRect;
if (view) {
@@ -320,7 +341,6 @@ void SciGuiGfx::drawCel(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo
clipRect = rect;
clipRect.clip(_curPort->rect);
if (clipRect.isEmpty()) { // nothing to draw
- delete view;
return;
}
@@ -330,19 +350,16 @@ void SciGuiGfx::drawCel(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo
if (!_screen->_picNotValid)
BitsShow(rect);
}
-
- delete view;
}
// This version of drawCel is not supposed to call BitsShow()!
void SciGuiGfx::drawCel(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo celNo, Common::Rect celRect, byte priority, uint16 paletteNo) {
- SciGuiView *view = new SciGuiView(_s->resMan, _screen, _palette, viewId);
+ SciGuiView *view = getView(viewId);
Common::Rect clipRect;
if (view) {
clipRect = celRect;
clipRect.clip(_curPort->rect);
if (clipRect.isEmpty()) { // nothing to draw
- delete view;
return;
}
@@ -350,8 +367,6 @@ void SciGuiGfx::drawCel(GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo
OffsetRect(clipRectTranslated);
view->draw(celRect, clipRect, clipRectTranslated, loopNo, celNo, priority, paletteNo);
}
-
- delete view;
}
// This version of drawCel is not supposed to call BitsShow()!
@@ -504,7 +519,7 @@ void SciGuiGfx::SetNowSeen(reg_t objectReference) {
}
// now get cel rectangle
- view = new SciGuiView(_s->resMan, _screen, _palette, viewId);
+ view = getView(viewId);
view->getCelRect(loopNo, celNo, x, y, z, &celRect);
// TODO: sometimes loop is negative. Check what it means
@@ -514,8 +529,6 @@ void SciGuiGfx::SetNowSeen(reg_t objectReference) {
PUT_SEL32V(segMan, objectReference, nsTop, celRect.top);
PUT_SEL32V(segMan, objectReference, nsBottom, celRect.bottom);
}
-
- delete view;
}
} // End of namespace Sci
diff --git a/engines/sci/gui/gui_gfx.h b/engines/sci/gui/gui_gfx.h
index 257f2a6609..c5e7f99d9a 100644
--- a/engines/sci/gui/gui_gfx.h
+++ b/engines/sci/gui/gui_gfx.h
@@ -28,17 +28,24 @@
#include "sci/gui/gui.h"
+#include "common/hashmap.h"
+
namespace Sci {
#define SCI_TEXT_ALIGNMENT_RIGHT -1
#define SCI_TEXT_ALIGNMENT_CENTER 1
#define SCI_TEXT_ALIGNMENT_LEFT 0
+#define MAX_CACHED_VIEWS 50
+
class SciGuiScreen;
class SciGuiPalette;
class SciGuiFont;
class SciGuiPicture;
class SciGuiView;
+
+typedef Common::HashMap<int, SciGuiView *> ViewCache;
+
class SciGuiGfx {
public:
SciGuiGfx(EngineState *state, SciGuiScreen *screen, SciGuiPalette *palette);
@@ -99,7 +106,11 @@ public:
Common::Rect _menuRect;
GuiPort *_curPort;
+ SciGuiView *getView(GuiResourceId viewNum);
+
private:
+ void purgeCache();
+
EngineState *_s;
SciGuiScreen *_screen;
SciGuiPalette *_palette;
@@ -111,6 +122,8 @@ private:
// Priority Bands related variables
int16 _priorityTop, _priorityBottom, _priorityBandCount;
byte _priorityBands[200];
+
+ ViewCache _cachedViews;
};
} // End of namespace Sci