(svn r23446) -Codechange: move _cur_palette and it's related first/count dirty variables into a single structure

This commit is contained in:
rubidium 2011-12-08 18:13:29 +00:00
parent 9e8b76650a
commit 2ccbd2a6f5
17 changed files with 80 additions and 77 deletions

View File

@ -45,7 +45,7 @@ public:
*/ */
static inline uint32 LookupColourInPalette(uint index) static inline uint32 LookupColourInPalette(uint index)
{ {
return _cur_palette[index].data; return _cur_palette.palette[index].data;
} }
/** /**

View File

@ -440,7 +440,6 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
* ======================================================================================== */ * ======================================================================================== */
#include "os/macosx/macos.h" #include "os/macosx/macos.h"
#include <ApplicationServices/ApplicationServices.h>
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
{ {

View File

@ -44,10 +44,7 @@ bool _exit_game;
GameMode _game_mode; GameMode _game_mode;
SwitchMode _switch_mode; ///< The next mainloop command. SwitchMode _switch_mode; ///< The next mainloop command.
PauseModeByte _pause_mode; PauseModeByte _pause_mode;
int _pal_first_dirty; Palette _cur_palette;
int _pal_count_dirty;
Colour _cur_palette[256];
static int _max_char_height; ///< Cache of the height of the largest font static int _max_char_height; ///< Cache of the height of the largest font
static int _max_char_width; ///< Cache of the width of the largest font static int _max_char_width; ///< Cache of the width of the largest font
@ -1401,11 +1398,8 @@ void DoPaletteAnimations();
void GfxInitPalettes() void GfxInitPalettes()
{ {
memcpy(_cur_palette, _palette, sizeof(_cur_palette)); memcpy(&_cur_palette, &_palette, sizeof(_cur_palette));
DoPaletteAnimations(); DoPaletteAnimations();
_pal_first_dirty = 0;
_pal_count_dirty = 256;
} }
#define EXTR(p, q) (((uint16)(palette_animation_counter * (p)) * (q)) >> 16) #define EXTR(p, q) (((uint16)(palette_animation_counter * (p)) * (q)) >> 16)
@ -1429,7 +1423,7 @@ void DoPaletteAnimations()
palette_animation_counter = 0; palette_animation_counter = 0;
} }
Colour *palette_pos = &_cur_palette[PALETTE_ANIM_START]; // Points to where animations are taking place on the palette Colour *palette_pos = &_cur_palette.palette[PALETTE_ANIM_START]; // Points to where animations are taking place on the palette
/* Makes a copy of the current anmation palette in old_val, /* Makes a copy of the current anmation palette in old_val,
* so the work on the current palette could be compared, see if there has been any changes */ * so the work on the current palette could be compared, see if there has been any changes */
memcpy(old_val, palette_pos, sizeof(old_val)); memcpy(old_val, palette_pos, sizeof(old_val));
@ -1513,10 +1507,10 @@ void DoPaletteAnimations()
if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) { if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
palette_animation_counter = old_tc; palette_animation_counter = old_tc;
} else { } else {
if (memcmp(old_val, &_cur_palette[PALETTE_ANIM_START], sizeof(old_val)) != 0) { if (memcmp(old_val, &_cur_palette.palette[PALETTE_ANIM_START], sizeof(old_val)) != 0 && _cur_palette.count_dirty == 0) {
/* Did we changed anything on the palette? Seems so. Mark it as dirty */ /* Did we changed anything on the palette? Seems so. Mark it as dirty */
_pal_first_dirty = PALETTE_ANIM_START; _cur_palette.first_dirty = PALETTE_ANIM_START;
_pal_count_dirty = PALETTE_ANIM_SIZE; _cur_palette.count_dirty = PALETTE_ANIM_SIZE;
} }
} }
} }

View File

@ -64,12 +64,10 @@ extern bool _right_button_clicked;
extern DrawPixelInfo _screen; extern DrawPixelInfo _screen;
extern bool _screen_disable_anim; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot) extern bool _screen_disable_anim; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
extern int _pal_first_dirty;
extern int _pal_count_dirty;
extern int _num_resolutions; extern int _num_resolutions;
extern Dimension _resolutions[32]; extern Dimension _resolutions[32];
extern Dimension _cur_resolution; extern Dimension _cur_resolution;
extern Colour _cur_palette[256]; ///< Current palette. Entry 0 has to be always fully transparent! extern Palette _cur_palette; ///< Current palette
void HandleKeypress(uint32 key); void HandleKeypress(uint32 key);
void HandleCtrlChanged(); void HandleCtrlChanged();

View File

@ -266,4 +266,11 @@ enum SpriteType {
/** The number of milliseconds per game tick. */ /** The number of milliseconds per game tick. */
static const uint MILLISECONDS_PER_TICK = 30; static const uint MILLISECONDS_PER_TICK = 30;
/** Information about the currently used palette. */
struct Palette {
Colour palette[256]; ///< Current palette. Entry 0 has to be always fully transparent!
int first_dirty; ///< The first dirty element.
int count_dirty; ///< The number of dirty elements.
};
#endif /* GFX_TYPE_H */ #endif /* GFX_TYPE_H */

View File

@ -43,13 +43,16 @@
#define Point OTTDPoint #define Point OTTDPoint
#define WindowClass OTTDWindowClass #define WindowClass OTTDWindowClass
#define ScriptOrder OTTDScriptOrder #define ScriptOrder OTTDScriptOrder
#define Palette OTTDPalette
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h>
#undef Rect #undef Rect
#undef Point #undef Point
#undef WindowClass #undef WindowClass
#undef ScriptOrder #undef ScriptOrder
#undef Palette
/* remove the variables that CoreServices defines, but we define ourselves too */ /* remove the variables that CoreServices defines, but we define ourselves too */
#undef bool #undef bool

View File

@ -136,19 +136,19 @@ void DisplaySplashImage()
} }
for (int i = 0; i < num_palette; i++) { for (int i = 0; i < num_palette; i++) {
_cur_palette[i].a = i == 0 ? 0 : 0xff; _cur_palette.palette[i].a = i == 0 ? 0 : 0xff;
_cur_palette[i].r = palette[i].red; _cur_palette.palette[i].r = palette[i].red;
_cur_palette[i].g = palette[i].green; _cur_palette.palette[i].g = palette[i].green;
_cur_palette[i].b = palette[i].blue; _cur_palette.palette[i].b = palette[i].blue;
} }
_cur_palette[0xff].a = 0xff; _cur_palette.palette[0xff].a = 0xff;
_cur_palette[0xff].r = 0; _cur_palette.palette[0xff].r = 0;
_cur_palette[0xff].g = 0; _cur_palette.palette[0xff].g = 0;
_cur_palette[0xff].b = 0; _cur_palette.palette[0xff].b = 0;
_pal_first_dirty = 0; _cur_palette.first_dirty = 0;
_pal_count_dirty = 256; _cur_palette.count_dirty = 256;
break; break;
} }
case 32: { case 32: {

View File

@ -725,7 +725,7 @@ static bool MakeSmallScreenshot()
{ {
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height,
BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
} }
/** Make a zoomed-in screenshot of the currently visible area. */ /** Make a zoomed-in screenshot of the currently visible area. */
@ -746,7 +746,7 @@ static bool MakeZoomedInScreenshot()
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), LargeWorldCallback, &vp, vp.width, vp.height,
BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
} }
/** Make a screenshot of the whole map. */ /** Make a screenshot of the whole map. */
@ -772,7 +772,7 @@ static bool MakeWorldScreenshot()
sf = _screenshot_formats + _cur_screenshot_format; sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), LargeWorldCallback, &vp, vp.width, vp.height,
BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
} }
/** /**

View File

@ -14,7 +14,8 @@
#define M(r, g, b) { 0xFF000000U | (r) << 16 | (g) << 8 | (b) } #define M(r, g, b) { 0xFF000000U | (r) << 16 | (g) << 8 | (b) }
/** Colour palette (DOS) */ /** Colour palette (DOS) */
static const Colour _palette[256] = { static const Palette _palette = {
{
/* transparent */ /* transparent */
{ 0}, { 0},
/* grey scale */ /* grey scale */
@ -89,6 +90,9 @@ static const Colour _palette[256] = {
M( 0, 0, 0), M( 0, 0, 0), M( 0, 0, 0), M( 0, 0, 0), M( 0, 0, 0), M( 0, 0, 0),
/* pure white */ /* pure white */
M(252, 252, 252) M(252, 252, 252)
},
0, // First dirty
256 // Dirty count
}; };
/** Description of the length of the palette cycle animations */ /** Description of the length of the palette cycle animations */

View File

@ -75,9 +75,9 @@ static void UpdatePalette(uint start, uint count)
uint end = start + count; uint end = start + count;
for (uint i = start; i != end; i++) { for (uint i = start; i != end; i++) {
pal[i].r = _cur_palette[i].r / 4; pal[i].r = _cur_palette.palette[i].r / 4;
pal[i].g = _cur_palette[i].g / 4; pal[i].g = _cur_palette.palette[i].g / 4;
pal[i].b = _cur_palette[i].b / 4; pal[i].b = _cur_palette.palette[i].b / 4;
pal[i].filler = 0; pal[i].filler = 0;
} }
@ -91,16 +91,16 @@ static void InitPalette()
static void CheckPaletteAnim() static void CheckPaletteAnim()
{ {
if (_pal_count_dirty != 0) { if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
switch (blitter->UsePaletteAnimation()) { switch (blitter->UsePaletteAnimation()) {
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
UpdatePalette(_pal_first_dirty, _pal_count_dirty); UpdatePalette(_cur_palette.first_dirty, _cur_palette.count_dirty);
break; break;
case Blitter::PALETTE_ANIMATION_BLITTER: case Blitter::PALETTE_ANIMATION_BLITTER:
blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty);
break; break;
case Blitter::PALETTE_ANIMATION_NONE: case Blitter::PALETTE_ANIMATION_NONE:
@ -109,7 +109,7 @@ static void CheckPaletteAnim()
default: default:
NOT_REACHED(); NOT_REACHED();
} }
_pal_count_dirty = 0; _cur_palette.count_dirty = 0;
} }
} }

View File

@ -12,8 +12,6 @@
#ifndef VIDEO_COCOA_H #ifndef VIDEO_COCOA_H
#define VIDEO_COCOA_H #define VIDEO_COCOA_H
#include <AvailabilityMacros.h>
#include "../video_driver.hpp" #include "../video_driver.hpp"
class VideoDriver_Cocoa: public VideoDriver { class VideoDriver_Cocoa: public VideoDriver {

View File

@ -90,16 +90,16 @@ static void QZ_WarpCursor(int x, int y)
static void QZ_CheckPaletteAnim() static void QZ_CheckPaletteAnim()
{ {
if (_pal_count_dirty != 0) { if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
switch (blitter->UsePaletteAnimation()) { switch (blitter->UsePaletteAnimation()) {
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
_cocoa_subdriver->UpdatePalette(_pal_first_dirty, _pal_count_dirty); _cocoa_subdriver->UpdatePalette(_cur_palette.first_dirty, _cur_palette.count_dirty);
break; break;
case Blitter::PALETTE_ANIMATION_BLITTER: case Blitter::PALETTE_ANIMATION_BLITTER:
blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty);
break; break;
case Blitter::PALETTE_ANIMATION_NONE: case Blitter::PALETTE_ANIMATION_NONE:
@ -108,7 +108,7 @@ static void QZ_CheckPaletteAnim()
default: default:
NOT_REACHED(); NOT_REACHED();
} }
_pal_count_dirty = 0; _cur_palette.count_dirty = 0;
} }
} }

View File

@ -494,9 +494,9 @@ public:
for (uint32_t index = first_color; index < first_color + num_colors; index++) { for (uint32_t index = first_color; index < first_color + num_colors; index++) {
/* Clamp colors between 0.0 and 1.0 */ /* Clamp colors between 0.0 and 1.0 */
CGDeviceColor color; CGDeviceColor color;
color.red = _cur_palette[index].r / 255.0; color.red = _cur_palette.palette[index].r / 255.0;
color.blue = _cur_palette[index].b / 255.0; color.blue = _cur_palette.palette[index].b / 255.0;
color.green = _cur_palette[index].g / 255.0; color.green = _cur_palette.palette[index].g / 255.0;
CGPaletteSetColorAtIndex(this->palette, color, index); CGPaletteSetColorAtIndex(this->palette, color, index);
} }

View File

@ -468,9 +468,9 @@ void WindowQuartzSubdriver::UpdatePalette(uint first_color, uint num_colors)
for (uint i = first_color; i < first_color + num_colors; i++) { for (uint i = first_color; i < first_color + num_colors; i++) {
uint32 clr = 0xff000000; uint32 clr = 0xff000000;
clr |= (uint32)_cur_palette[i].r << 16; clr |= (uint32)_cur_palette.palette[i].r << 16;
clr |= (uint32)_cur_palette[i].g << 8; clr |= (uint32)_cur_palette.palette[i].g << 8;
clr |= (uint32)_cur_palette[i].b; clr |= (uint32)_cur_palette.palette[i].b;
this->palette[i] = clr; this->palette[i] = clr;
} }

View File

@ -416,18 +416,18 @@ void WindowQuickdrawSubdriver::UpdatePalette(uint first_color, uint num_colors)
case 32: case 32:
for (uint i = first_color; i < first_color + num_colors; i++) { for (uint i = first_color; i < first_color + num_colors; i++) {
uint32 clr32 = 0xff000000; uint32 clr32 = 0xff000000;
clr32 |= (uint32)_cur_palette[i].r << 16; clr32 |= (uint32)_cur_palette.palette[i].r << 16;
clr32 |= (uint32)_cur_palette[i].g << 8; clr32 |= (uint32)_cur_palette.palette[i].g << 8;
clr32 |= (uint32)_cur_palette[i].b; clr32 |= (uint32)_cur_palette.palette[i].b;
this->palette[i] = clr32; this->palette[i] = clr32;
} }
break; break;
case 16: case 16:
for (uint i = first_color; i < first_color + num_colors; i++) { for (uint i = first_color; i < first_color + num_colors; i++) {
uint16 clr16 = 0x0000; uint16 clr16 = 0x0000;
clr16 |= (uint16)((_cur_palette[i].r >> 3) & 0x1f) << 10; clr16 |= (uint16)((_cur_palette.palette[i].r >> 3) & 0x1f) << 10;
clr16 |= (uint16)((_cur_palette[i].g >> 3) & 0x1f) << 5; clr16 |= (uint16)((_cur_palette.palette[i].g >> 3) & 0x1f) << 5;
clr16 |= (uint16)((_cur_palette[i].b >> 3) & 0x1f); clr16 |= (uint16)((_cur_palette.palette[i].b >> 3) & 0x1f);
this->palette[i] = clr16; this->palette[i] = clr16;
} }
break; break;

View File

@ -60,9 +60,9 @@ static void UpdatePalette(uint start, uint count)
SDL_Color pal[256]; SDL_Color pal[256];
for (uint i = 0; i != count; i++) { for (uint i = 0; i != count; i++) {
pal[i].r = _cur_palette[start + i].r; pal[i].r = _cur_palette.palette[start + i].r;
pal[i].g = _cur_palette[start + i].g; pal[i].g = _cur_palette.palette[start + i].g;
pal[i].b = _cur_palette[start + i].b; pal[i].b = _cur_palette.palette[start + i].b;
pal[i].unused = 0; pal[i].unused = 0;
} }
@ -76,16 +76,16 @@ static void InitPalette()
static void CheckPaletteAnim() static void CheckPaletteAnim()
{ {
if (_pal_count_dirty != 0) { if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
switch (blitter->UsePaletteAnimation()) { switch (blitter->UsePaletteAnimation()) {
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
UpdatePalette(_pal_first_dirty, _pal_count_dirty); UpdatePalette(_cur_palette.first_dirty, _cur_palette.count_dirty);
break; break;
case Blitter::PALETTE_ANIMATION_BLITTER: case Blitter::PALETTE_ANIMATION_BLITTER:
blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty);
break; break;
case Blitter::PALETTE_ANIMATION_NONE: case Blitter::PALETTE_ANIMATION_NONE:
@ -94,7 +94,7 @@ static void CheckPaletteAnim()
default: default:
NOT_REACHED(); NOT_REACHED();
} }
_pal_count_dirty = 0; _cur_palette.count_dirty = 0;
} }
} }

View File

@ -56,9 +56,9 @@ static void MakePalette()
pal->palNumEntries = 256; pal->palNumEntries = 256;
for (i = 0; i != 256; i++) { for (i = 0; i != 256; i++) {
pal->palPalEntry[i].peRed = _cur_palette[i].r; pal->palPalEntry[i].peRed = _cur_palette.palette[i].r;
pal->palPalEntry[i].peGreen = _cur_palette[i].g; pal->palPalEntry[i].peGreen = _cur_palette.palette[i].g;
pal->palPalEntry[i].peBlue = _cur_palette[i].b; pal->palPalEntry[i].peBlue = _cur_palette.palette[i].b;
pal->palPalEntry[i].peFlags = 0; pal->palPalEntry[i].peFlags = 0;
} }
@ -72,9 +72,9 @@ static void UpdatePalette(HDC dc, uint start, uint count)
uint i; uint i;
for (i = 0; i != count; i++) { for (i = 0; i != count; i++) {
rgb[i].rgbRed = _cur_palette[start + i].r; rgb[i].rgbRed = _cur_palette.palette[start + i].r;
rgb[i].rgbGreen = _cur_palette[start + i].g; rgb[i].rgbGreen = _cur_palette.palette[start + i].g;
rgb[i].rgbBlue = _cur_palette[start + i].b; rgb[i].rgbBlue = _cur_palette.palette[start + i].b;
rgb[i].rgbReserved = 0; rgb[i].rgbReserved = 0;
} }
@ -162,8 +162,8 @@ static void ClientSizeChanged(int w, int h)
/* allocate new dib section of the new size */ /* allocate new dib section of the new size */
if (AllocateDibSection(w, h)) { if (AllocateDibSection(w, h)) {
/* mark all palette colors dirty */ /* mark all palette colors dirty */
_pal_first_dirty = 0; _cur_palette.first_dirty = 0;
_pal_count_dirty = 256; _cur_palette.count_dirty = 256;
BlitterFactoryBase::GetCurrentBlitter()->PostResize(); BlitterFactoryBase::GetCurrentBlitter()->PostResize();
@ -350,16 +350,16 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
old_bmp = (HBITMAP)SelectObject(dc2, _wnd.dib_sect); old_bmp = (HBITMAP)SelectObject(dc2, _wnd.dib_sect);
old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE); old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE);
if (_pal_count_dirty != 0) { if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
switch (blitter->UsePaletteAnimation()) { switch (blitter->UsePaletteAnimation()) {
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
UpdatePalette(dc2, _pal_first_dirty, _pal_count_dirty); UpdatePalette(dc2, _cur_palette.first_dirty, _cur_palette.count_dirty);
break; break;
case Blitter::PALETTE_ANIMATION_BLITTER: case Blitter::PALETTE_ANIMATION_BLITTER:
blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty);
break; break;
case Blitter::PALETTE_ANIMATION_NONE: case Blitter::PALETTE_ANIMATION_NONE:
@ -368,7 +368,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
default: default:
NOT_REACHED(); NOT_REACHED();
} }
_pal_count_dirty = 0; _cur_palette.count_dirty = 0;
} }
BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY); BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY);
@ -839,7 +839,7 @@ void VideoDriver_Win32::MakeDirty(int left, int top, int width, int height)
static void CheckPaletteAnim() static void CheckPaletteAnim()
{ {
if (_pal_count_dirty == 0) return; if (_cur_palette.count_dirty == 0) return;
InvalidateRect(_wnd.main_wnd, NULL, FALSE); InvalidateRect(_wnd.main_wnd, NULL, FALSE);
} }