1
0
Fork 0

(svn r23448) -Fix: keep a local copy of the palette in the 32bpp animated blitter so changes of the palette data during the game don't influence drawing (with SDL)

release/1.2
rubidium 2011-12-08 19:37:33 +00:00
parent 8630e97b4f
commit 61625e53c9
12 changed files with 36 additions and 34 deletions

View File

@ -410,14 +410,15 @@ int Blitter_32bppAnim::BufferSize(int width, int height)
return width * height * (sizeof(uint32) + sizeof(uint8)); return width * height * (sizeof(uint32) + sizeof(uint8));
} }
void Blitter_32bppAnim::PaletteAnimate(uint start, uint count) void Blitter_32bppAnim::PaletteAnimate(const Palette &palette)
{ {
assert(!_screen_disable_anim); assert(!_screen_disable_anim);
this->palette = palette;
/* Never repaint the transparency pixel */ /* Never repaint the transparency pixel */
if (start == 0) { if (this->palette.first_dirty == 0) {
start++; this->palette.first_dirty++;
count--; this->palette.count_dirty--;
} }
const uint8 *anim = this->anim_buf; const uint8 *anim = this->anim_buf;
@ -427,7 +428,7 @@ void Blitter_32bppAnim::PaletteAnimate(uint start, uint count)
for (int y = this->anim_buf_height; y != 0 ; y--) { for (int y = this->anim_buf_height; y != 0 ; y--) {
for (int x = this->anim_buf_width; x != 0 ; x--) { for (int x = this->anim_buf_width; x != 0 ; x--) {
uint colour = *anim; uint colour = *anim;
if (IsInsideBS(colour, start, count)) { if (IsInsideBS(colour, this->palette.first_dirty, this->palette.count_dirty)) {
/* Update this pixel */ /* Update this pixel */
*dst = LookupColourInPalette(colour); *dst = LookupColourInPalette(colour);
} }

View File

@ -20,6 +20,7 @@ private:
uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation
int anim_buf_width; ///< The width of the animation buffer. int anim_buf_width; ///< The width of the animation buffer.
int anim_buf_height; ///< The height of the animation buffer. int anim_buf_height; ///< The height of the animation buffer.
Palette palette; ///< The current palette.
public: public:
Blitter_32bppAnim() : Blitter_32bppAnim() :
@ -36,13 +37,21 @@ public:
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height); /* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y); /* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
/* virtual */ int BufferSize(int width, int height); /* virtual */ int BufferSize(int width, int height);
/* virtual */ void PaletteAnimate(uint start, uint count); /* virtual */ void PaletteAnimate(const Palette &palette);
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation(); /* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
/* virtual */ const char *GetName() { return "32bpp-anim"; } /* virtual */ const char *GetName() { return "32bpp-anim"; }
/* virtual */ int GetBytesPerPixel() { return 5; } /* virtual */ int GetBytesPerPixel() { return 5; }
/* virtual */ void PostResize(); /* virtual */ void PostResize();
/**
* Look up the colour in the current palette.
*/
inline uint32 LookupColourInPalette(uint index)
{
return this->palette.palette[index].data;
}
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom); template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
}; };

View File

@ -136,7 +136,7 @@ int Blitter_32bppBase::BufferSize(int width, int height)
return width * height * sizeof(uint32); return width * height * sizeof(uint32);
} }
void Blitter_32bppBase::PaletteAnimate(uint start, uint count) void Blitter_32bppBase::PaletteAnimate(const Palette &palette)
{ {
/* By default, 32bpp doesn't have palette animation */ /* By default, 32bpp doesn't have palette animation */
} }

View File

@ -28,7 +28,7 @@ public:
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch); /* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y); /* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
/* virtual */ int BufferSize(int width, int height); /* virtual */ int BufferSize(int width, int height);
/* virtual */ void PaletteAnimate(uint start, uint count); /* virtual */ void PaletteAnimate(const Palette &palette);
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation(); /* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
/* virtual */ int GetBytesPerPixel() { return 4; } /* virtual */ int GetBytesPerPixel() { return 4; }

View File

@ -141,7 +141,7 @@ int Blitter_8bppBase::BufferSize(int width, int height)
return width * height; return width * height;
} }
void Blitter_8bppBase::PaletteAnimate(uint start, uint count) void Blitter_8bppBase::PaletteAnimate(const Palette &palette)
{ {
/* Video backend takes care of the palette animation */ /* Video backend takes care of the palette animation */
} }

View File

@ -27,7 +27,7 @@ public:
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch); /* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y); /* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
/* virtual */ int BufferSize(int width, int height); /* virtual */ int BufferSize(int width, int height);
/* virtual */ void PaletteAnimate(uint start, uint count); /* virtual */ void PaletteAnimate(const Palette &palette);
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation(); /* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
/* virtual */ int GetBytesPerPixel() { return 1; } /* virtual */ int GetBytesPerPixel() { return 1; }
}; };

View File

@ -173,11 +173,10 @@ public:
/** /**
* Called when the 8bpp palette is changed; you should redraw all pixels on the screen that * Called when the 8bpp palette is changed; you should redraw all pixels on the screen that
* are equal to the 8bpp palette indexes 'start' to 'start + count'. * are equal to the 8bpp palette indexes 'first_dirty' to 'first_dirty + count_dirty'.
* @param start The start index in the 8bpp palette. * @param palette The new palette.
* @param count The amount of indexes that are (possible) changed.
*/ */
virtual void PaletteAnimate(uint start, uint count) = 0; virtual void PaletteAnimate(const Palette &palette) = 0;
/** /**
* Check if the blitter uses palette animation at all. * Check if the blitter uses palette animation at all.

View File

@ -30,7 +30,7 @@ public:
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) {}; /* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) {};
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) {}; /* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) {};
/* virtual */ int BufferSize(int width, int height) { return 0; }; /* virtual */ int BufferSize(int width, int height) { return 0; };
/* virtual */ void PaletteAnimate(uint start, uint count) { }; /* virtual */ void PaletteAnimate(const Palette &palette) { };
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation() { return Blitter::PALETTE_ANIMATION_NONE; }; /* virtual */ Blitter::PaletteAnimation UsePaletteAnimation() { return Blitter::PALETTE_ANIMATION_NONE; };
/* virtual */ const char *GetName() { return "null"; } /* virtual */ const char *GetName() { return "null"; }

View File

@ -100,7 +100,7 @@ static void CheckPaletteAnim()
break; break;
case Blitter::PALETTE_ANIMATION_BLITTER: case Blitter::PALETTE_ANIMATION_BLITTER:
blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty); blitter->PaletteAnimate(_cur_palette);
break; break;
case Blitter::PALETTE_ANIMATION_NONE: case Blitter::PALETTE_ANIMATION_NONE:
@ -487,7 +487,8 @@ void VideoDriver_Allegro::MainLoop()
uint32 cur_ticks = GetTime(); uint32 cur_ticks = GetTime();
uint32 last_cur_ticks = cur_ticks; uint32 last_cur_ticks = cur_ticks;
uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK; uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
uint32 pal_tick = 0;
CheckPaletteAnim();
for (;;) { for (;;) {
uint32 prev_cur_ticks = cur_ticks; // to check for wrapping uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
@ -532,10 +533,7 @@ void VideoDriver_Allegro::MainLoop()
GameLoop(); GameLoop();
UpdateWindows(); UpdateWindows();
if (++pal_tick > 4) {
CheckPaletteAnim(); CheckPaletteAnim();
pal_tick = 1;
}
DrawSurfaceToScreen(); DrawSurfaceToScreen();
} else { } else {
CSleep(1); CSleep(1);

View File

@ -99,7 +99,7 @@ static void QZ_CheckPaletteAnim()
break; break;
case Blitter::PALETTE_ANIMATION_BLITTER: case Blitter::PALETTE_ANIMATION_BLITTER:
blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty); blitter->PaletteAnimate(_cur_palette);
break; break;
case Blitter::PALETTE_ANIMATION_NONE: case Blitter::PALETTE_ANIMATION_NONE:
@ -555,7 +555,6 @@ void QZ_GameLoop()
uint32 cur_ticks = GetTick(); uint32 cur_ticks = GetTick();
uint32 last_cur_ticks = cur_ticks; uint32 last_cur_ticks = cur_ticks;
uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK; uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
uint32 pal_tick = 0;
#ifdef _DEBUG #ifdef _DEBUG
uint32 et0 = GetTick(); uint32 et0 = GetTick();
@ -615,10 +614,7 @@ void QZ_GameLoop()
GameLoop(); GameLoop();
UpdateWindows(); UpdateWindows();
if (++pal_tick > 4) {
QZ_CheckPaletteAnim(); QZ_CheckPaletteAnim();
pal_tick = 1;
}
_cocoa_subdriver->Draw(); _cocoa_subdriver->Draw();
} else { } else {
#ifdef _DEBUG #ifdef _DEBUG

View File

@ -85,7 +85,7 @@ static void CheckPaletteAnim()
break; break;
case Blitter::PALETTE_ANIMATION_BLITTER: case Blitter::PALETTE_ANIMATION_BLITTER:
blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty); blitter->PaletteAnimate(_cur_palette);
break; break;
case Blitter::PALETTE_ANIMATION_NONE: case Blitter::PALETTE_ANIMATION_NONE:
@ -503,11 +503,12 @@ void VideoDriver_SDL::MainLoop()
uint32 cur_ticks = SDL_CALL SDL_GetTicks(); uint32 cur_ticks = SDL_CALL SDL_GetTicks();
uint32 last_cur_ticks = cur_ticks; uint32 last_cur_ticks = cur_ticks;
uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK; uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
uint32 pal_tick = 0;
uint32 mod; uint32 mod;
int numkeys; int numkeys;
Uint8 *keys; Uint8 *keys;
CheckPaletteAnim();
if (_draw_threaded) { if (_draw_threaded) {
/* Initialise the mutex first, because that's the thing we *need* /* Initialise the mutex first, because that's the thing we *need*
* directly in the newly created thread. */ * directly in the newly created thread. */
@ -584,10 +585,7 @@ void VideoDriver_SDL::MainLoop()
if (_draw_threaded) _draw_mutex->BeginCritical(); if (_draw_threaded) _draw_mutex->BeginCritical();
UpdateWindows(); UpdateWindows();
if (++pal_tick > 4) {
CheckPaletteAnim(); CheckPaletteAnim();
pal_tick = 1;
}
} else { } else {
/* Release the thread while sleeping */ /* Release the thread while sleeping */
if (_draw_threaded) _draw_mutex->EndCritical(); if (_draw_threaded) _draw_mutex->EndCritical();

View File

@ -359,7 +359,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
break; break;
case Blitter::PALETTE_ANIMATION_BLITTER: case Blitter::PALETTE_ANIMATION_BLITTER:
blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty); blitter->PaletteAnimate(_cur_palette);
break; break;
case Blitter::PALETTE_ANIMATION_NONE: case Blitter::PALETTE_ANIMATION_NONE:
@ -853,6 +853,7 @@ void VideoDriver_Win32::MainLoop()
_wnd.running = true; _wnd.running = true;
CheckPaletteAnim();
for (;;) { for (;;) {
uint32 prev_cur_ticks = cur_ticks; // to check for wrapping uint32 prev_cur_ticks = cur_ticks; // to check for wrapping