[Scummvm-cvs-logs] SF.net SVN: scummvm:[39462] scummvm/trunk/engines/sword1
Hkz at users.sourceforge.net
Hkz at users.sourceforge.net
Tue Mar 17 00:10:50 CET 2009
Revision: 39462
http://scummvm.svn.sourceforge.net/scummvm/?rev=39462&view=rev
Author: Hkz
Date: 2009-03-16 23:10:50 +0000 (Mon, 16 Mar 2009)
Log Message:
-----------
sword1: cache decompressed psx version backgrounds, to avoid uncompressing them at every screen update.
Modified Paths:
--------------
scummvm/trunk/engines/sword1/screen.cpp
scummvm/trunk/engines/sword1/screen.h
Modified: scummvm/trunk/engines/sword1/screen.cpp
===================================================================
--- scummvm/trunk/engines/sword1/screen.cpp 2009-03-16 22:25:37 UTC (rev 39461)
+++ scummvm/trunk/engines/sword1/screen.cpp 2009-03-16 23:10:50 UTC (rev 39462)
@@ -53,7 +53,8 @@
_fadingStep = 0;
_currentScreen = 0xFFFF;
_updatePalette = false;
- _extPlxCache = NULL;
+ _psxCache.decodedBackground = NULL;
+ _psxCache.extPlxCache = NULL;
}
Screen::~Screen(void) {
@@ -317,10 +318,10 @@
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::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 @@
} 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 @@
// 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::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);
Modified: scummvm/trunk/engines/sword1/screen.h
===================================================================
--- scummvm/trunk/engines/sword1/screen.h 2009-03-16 22:25:37 UTC (rev 39461)
+++ scummvm/trunk/engines/sword1/screen.h 2009-03-16 23:10:50 UTC (rev 39462)
@@ -51,6 +51,11 @@
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 @@
int32 inRange(int32 a, int32 b, int32 c);
void fadePalette(void);
+ void flushPsxCache(void);
+
OSystem *_system;
ResMan *_resMan;
ObjectMan *_objMan;
@@ -144,7 +151,7 @@
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];
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