aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFabio Battaglia2009-03-16 23:10:50 +0000
committerFabio Battaglia2009-03-16 23:10:50 +0000
commit88ff058bd7d7c5e77ddd774d9996206733fa7717 (patch)
tree40121f9bba09fb3a08ae47b5cb5e01e1356a6446 /engines
parentc40d2d2f50e83b5c3b10a6599ffe17557e0a4114 (diff)
downloadscummvm-rg350-88ff058bd7d7c5e77ddd774d9996206733fa7717.tar.gz
scummvm-rg350-88ff058bd7d7c5e77ddd774d9996206733fa7717.tar.bz2
scummvm-rg350-88ff058bd7d7c5e77ddd774d9996206733fa7717.zip
sword1: cache decompressed psx version backgrounds, to avoid uncompressing them at every screen update.
svn-id: r39462
Diffstat (limited to 'engines')
-rw-r--r--engines/sword1/screen.cpp52
-rw-r--r--engines/sword1/screen.h9
2 files changed, 40 insertions, 21 deletions
diff --git a/engines/sword1/screen.cpp b/engines/sword1/screen.cpp
index 7f86c6525c..985c62b52d 100644
--- a/engines/sword1/screen.cpp
+++ b/engines/sword1/screen.cpp
@@ -53,7 +53,8 @@ Screen::Screen(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan) {
_fadingStep = 0;
_currentScreen = 0xFFFF;
_updatePalette = false;
- _extPlxCache = NULL;
+ _psxCache.decodedBackground = NULL;
+ _psxCache.extPlxCache = NULL;
}
Screen::~Screen(void) {
@@ -317,10 +318,10 @@ void Screen::newScreen(uint32 screen) {
free(_screenBuf);
if (_screenGrid)
free(_screenGrid);
- if (_extPlxCache) {
- free(_extPlxCache);
- _extPlxCache = NULL;
- }
+
+ if (SwordEngine::isPsx())
+ flushPsxCache();
+
_screenBuf = (uint8*)malloc(_scrnSizeX * _scrnSizeY);
_screenGrid = (uint8*)malloc(_gridSizeX * _gridSizeY);
memset(_screenGrid, 0, _gridSizeX * _gridSizeY);
@@ -347,10 +348,8 @@ void Screen::newScreen(uint32 screen) {
void Screen::quitScreen(void) {
uint8 cnt;
- if (_extPlxCache) {
- free(_extPlxCache);
- _extPlxCache = NULL;
- }
+ if (SwordEngine::isPsx())
+ flushPsxCache();
for (cnt = 0; cnt < _roomDefTable[_currentScreen].totalLayers; cnt++)
_resMan->resClose(_roomDefTable[_currentScreen].layers[cnt]);
for (cnt = 0; cnt < _roomDefTable[_currentScreen].totalLayers - 1; cnt++)
@@ -394,14 +393,15 @@ void Screen::draw(void) {
} else if (!(SwordEngine::isPsx())) {
memcpy(_screenBuf, _layerBlocks[0], _scrnSizeX * _scrnSizeY);
} else { //We are using PSX version
- uint8 *indxScreen;
if(_currentScreen == 45 || _currentScreen == 55 ||
- _currentScreen == 57 || _currentScreen == 63 || _currentScreen == 71) // Width shrinked backgrounds
- indxScreen = psxShrinkedBackgroundToIndexed(_layerBlocks[0], _scrnSizeX, _scrnSizeY);
- else
- indxScreen = psxBackgroundToIndexed(_layerBlocks[0], _scrnSizeX, _scrnSizeY);
- memcpy(_screenBuf, indxScreen, _scrnSizeX * _scrnSizeY);
- free(indxScreen);
+ _currentScreen == 57 || _currentScreen == 63 || _currentScreen == 71) { // Width shrinked backgrounds
+ if (!_psxCache.decodedBackground)
+ _psxCache.decodedBackground = psxShrinkedBackgroundToIndexed(_layerBlocks[0], _scrnSizeX, _scrnSizeY);
+ } else {
+ if (!_psxCache.decodedBackground)
+ _psxCache.decodedBackground = psxBackgroundToIndexed(_layerBlocks[0], _scrnSizeX, _scrnSizeY);
+ }
+ memcpy(_screenBuf, _psxCache.decodedBackground, _scrnSizeX * _scrnSizeY);
}
for (cnt = 0; cnt < _backLength; cnt++)
@@ -423,14 +423,14 @@ void Screen::draw(void) {
// PSX version has parallax layer for this room in an external file (TRAIN.PLX)
if(SwordEngine::isPsx() && _currentScreen == 63) {
// FIXME: this should be handled in a cleaner way...
- if (!_extPlxCache) {
+ if (!_psxCache.extPlxCache) {
Common::File parallax;
parallax.open("TRAIN.PLX");
- _extPlxCache = (uint8*) malloc(parallax.size());
- parallax.read(_extPlxCache, parallax.size());
+ _psxCache.extPlxCache = (uint8*) malloc(parallax.size());
+ parallax.read(_psxCache.extPlxCache, parallax.size());
parallax.close();
}
- renderParallax(_extPlxCache);
+ renderParallax(_psxCache.extPlxCache);
}
for (cnt = 0; cnt < _foreLength; cnt++)
@@ -1107,6 +1107,18 @@ void Screen::decompressHIF(uint8 *src, uint8 *dest) {
}
}
+void Screen::flushPsxCache(void) {
+ if (_psxCache.decodedBackground) {
+ free(_psxCache.decodedBackground);
+ _psxCache.decodedBackground = NULL;
+ }
+
+ if (_psxCache.extPlxCache) {
+ free(_psxCache.extPlxCache);
+ _psxCache.extPlxCache = NULL;
+ }
+}
+
void Screen::fadePalette(void) {
if (_fadingStep == 16)
memcpy(_currentPalette, _targetPalette, 256 * 4);
diff --git a/engines/sword1/screen.h b/engines/sword1/screen.h
index 42aa77b3dc..72a55b94d3 100644
--- a/engines/sword1/screen.h
+++ b/engines/sword1/screen.h
@@ -51,6 +51,11 @@ struct RoomDef {
uint32 parallax[2];
};
+struct PSXDataCache { // Cache for PSX screen, to avoid decompressing background at every screen update
+ uint8 *decodedBackground;
+ uint8 *extPlxCache; // If this screen requires an external parallax, save it here
+};
+
#define SCRNGRID_X 16
#define SCRNGRID_Y 8
#define SHRINK_BUFFER_SIZE 50000
@@ -127,6 +132,8 @@ private:
int32 inRange(int32 a, int32 b, int32 c);
void fadePalette(void);
+ void flushPsxCache(void);
+
OSystem *_system;
ResMan *_resMan;
ObjectMan *_objMan;
@@ -144,7 +151,7 @@ private:
bool _updatePalette;
uint16 _oldScrollX, _oldScrollY; // for drawing additional frames
- uint8 *_extPlxCache; // Cache used for external PLX file in PSX version
+ PSXDataCache _psxCache; // Cache used for PSX backgrounds
uint32 _foreList[MAX_FORE];
uint32 _backList[MAX_BACK];