aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjörn Andersson2008-05-29 20:32:27 +0000
committerTorbjörn Andersson2008-05-29 20:32:27 +0000
commit7833dd87a5f3247681d6f51e45ee2f6da1ab91fd (patch)
treef6273db663c74e443cd2bd57f2acc403a32bc80e
parent3a43916e2022210b4de9a865f44df67157a0e004 (diff)
downloadscummvm-rg350-7833dd87a5f3247681d6f51e45ee2f6da1ab91fd.tar.gz
scummvm-rg350-7833dd87a5f3247681d6f51e45ee2f6da1ab91fd.tar.bz2
scummvm-rg350-7833dd87a5f3247681d6f51e45ee2f6da1ab91fd.zip
Rewrote dimPalette() so that the dimming is now a "filter" between the Screen
class and the backend, i.e. as far as the game engine is concerned the palette remains unchanged. (This is similar how to the SCUMM engine handles the "noir" mode in Sam & Max.) This is one small step towards allowing the game to be paused anywhere. svn-id: r32369
-rw-r--r--engines/sword2/palette.cpp35
-rw-r--r--engines/sword2/screen.cpp2
-rw-r--r--engines/sword2/screen.h5
-rw-r--r--engines/sword2/sword2.cpp22
-rw-r--r--engines/sword2/sword2.h1
5 files changed, 32 insertions, 33 deletions
diff --git a/engines/sword2/palette.cpp b/engines/sword2/palette.cpp
index 1b9cd28d25..81f93c77ae 100644
--- a/engines/sword2/palette.cpp
+++ b/engines/sword2/palette.cpp
@@ -156,22 +156,17 @@ void Screen::setPalette(int16 startEntry, int16 noEntries, byte *colourTable, ui
memcpy(&_palette[4 * startEntry], colourTable, noEntries * 4);
if (fadeNow == RDPAL_INSTANT) {
- _vm->_system->setPalette(_palette, startEntry, noEntries);
+ setSystemPalette(_palette, startEntry, noEntries);
setNeedFullRedraw();
}
}
-void Screen::dimPalette() {
- byte *p = _palette;
-
- for (int i = 0; i < 256; i++) {
- p[i * 4 + 0] /= 2;
- p[i * 4 + 1] /= 2;
- p[i * 4 + 2] /= 2;
+void Screen::dimPalette(bool dim) {
+ if (dim != _dimPalette) {
+ _dimPalette = dim;
+ setSystemPalette(_palette, 0, 256);
+ setNeedFullRedraw();
}
-
- _vm->_system->setPalette(p, 0, 256);
- setNeedFullRedraw();
}
/**
@@ -269,8 +264,24 @@ void Screen::fadeServer() {
}
}
- _vm->_system->setPalette(newPalette, 0, 256);
+ setSystemPalette(newPalette, 0, 256);
setNeedFullRedraw();
}
+void Screen::setSystemPalette(const byte *colors, uint start, uint num) {
+ const byte *palette;
+
+ if (_dimPalette) {
+ byte pal[256 * 4];
+
+ for (uint i = start * 4; i < 4 * (start + num); i++)
+ pal[i] = colors[i] / 2;
+
+ palette = pal;
+ } else
+ palette = colors;
+
+ _vm->_system->setPalette(palette, start, num);
+}
+
} // End of namespace Sword2
diff --git a/engines/sword2/screen.cpp b/engines/sword2/screen.cpp
index 1f6eb1b22d..fdabb3ee6f 100644
--- a/engines/sword2/screen.cpp
+++ b/engines/sword2/screen.cpp
@@ -97,6 +97,8 @@ Screen::Screen(Sword2Engine *vm, int16 width, int16 height) {
_renderAverageTime = 60;
_layer = 0;
+
+ _dimPalette = false;
}
Screen::~Screen() {
diff --git a/engines/sword2/screen.h b/engines/sword2/screen.h
index d59a6ef3df..93cc5e40ce 100644
--- a/engines/sword2/screen.h
+++ b/engines/sword2/screen.h
@@ -350,6 +350,8 @@ private:
uint16 _layer;
+ bool _dimPalette;
+
public:
Screen(Sword2Engine *vm, int16 width, int16 height);
~Screen();
@@ -400,11 +402,12 @@ public:
void setFullPalette(int32 palRes);
void setPalette(int16 startEntry, int16 noEntries, byte *palette, uint8 setNow);
+ void setSystemPalette(const byte *colors, uint start, uint num);
uint8 quickMatch(uint8 r, uint8 g, uint8 b);
int32 fadeUp(float time = 0.75);
int32 fadeDown(float time = 0.75);
uint8 getFadeStatus();
- void dimPalette();
+ void dimPalette(bool dim);
void waitForFade();
void fadeServer();
diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp
index 26fd598d9d..7331d1f761 100644
--- a/engines/sword2/sword2.cpp
+++ b/engines/sword2/sword2.cpp
@@ -225,7 +225,6 @@ Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst) {
#endif
_gamePaused = false;
- _graphicsLevelFudged = false;
_gameCycle = 0;
_gameSpeed = 1;
@@ -701,22 +700,14 @@ void Sword2Engine::pauseEngineIntern(bool pause) {
_sound->pauseAllSound();
_mouse->pauseEngine(true);
- // If render level is at max, turn it down because palette-
- // matching won't work when the palette is dimmed.
-
- if (_screen->getRenderLevel() == 3) {
- _screen->setRenderLevel(2);
- _graphicsLevelFudged = true;
- }
-
#ifdef SWORD2_DEBUG
// Don't dim it if we're single-stepping through frames
// dim the palette during the pause
if (!_stepOneCycle)
- _screen->dimPalette();
+ _screen->dimPalette(true);
#else
- _screen->dimPalette();
+ _screen->dimPalette(true);
#endif
_gamePaused = true;
@@ -724,14 +715,7 @@ void Sword2Engine::pauseEngineIntern(bool pause) {
_mouse->pauseEngine(false);
_sound->unpauseAllSound();
- // Put back game screen palette; see screen.cpp
- _screen->setFullPalette(-1);
-
- // If graphics level at max, turn up again
- if (_graphicsLevelFudged) {
- _screen->setRenderLevel(3);
- _graphicsLevelFudged = false;
- }
+ _screen->dimPalette(false);
_gamePaused = false;
diff --git a/engines/sword2/sword2.h b/engines/sword2/sword2.h
index ba59772a71..05c5d7fa47 100644
--- a/engines/sword2/sword2.h
+++ b/engines/sword2/sword2.h
@@ -207,7 +207,6 @@ public:
uint32 findBufferSize();
bool _gamePaused;
- bool _graphicsLevelFudged;
void startGame();
void gameCycle();