From 2ccbd2a6f5d0e3b9000122fe1845482241334f41 Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 8 Dec 2011 18:13:29 +0000 Subject: (svn r23446) -Codechange: move _cur_palette and it's related first/count dirty variables into a single structure --- src/blitter/32bpp_base.hpp | 2 +- src/fontcache.cpp | 1 - src/gfx.cpp | 18 ++++++------------ src/gfx_func.h | 4 +--- src/gfx_type.h | 7 +++++++ src/os/macosx/osx_stdafx.h | 5 ++++- src/os/macosx/splash.cpp | 20 ++++++++++---------- src/screenshot.cpp | 6 +++--- src/table/palettes.h | 6 +++++- src/video/allegro_v.cpp | 14 +++++++------- src/video/cocoa/cocoa_v.h | 2 -- src/video/cocoa/event.mm | 8 ++++---- src/video/cocoa/fullscreen.mm | 6 +++--- src/video/cocoa/wnd_quartz.mm | 6 +++--- src/video/cocoa/wnd_quickdraw.mm | 12 ++++++------ src/video/sdl_v.cpp | 14 +++++++------- src/video/win32_v.cpp | 26 +++++++++++++------------- 17 files changed, 80 insertions(+), 77 deletions(-) (limited to 'src') diff --git a/src/blitter/32bpp_base.hpp b/src/blitter/32bpp_base.hpp index ed3c24549..5706d39cd 100644 --- a/src/blitter/32bpp_base.hpp +++ b/src/blitter/32bpp_base.hpp @@ -45,7 +45,7 @@ public: */ static inline uint32 LookupColourInPalette(uint index) { - return _cur_palette[index].data; + return _cur_palette.palette[index].data; } /** diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 3c7634e1f..3e3aaf02b 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -440,7 +440,6 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i * ======================================================================================== */ #include "os/macosx/macos.h" -#include FT_Error GetFontByFaceName(const char *font_name, FT_Face *face) { diff --git a/src/gfx.cpp b/src/gfx.cpp index b840fed3e..0cbead9af 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -44,10 +44,7 @@ bool _exit_game; GameMode _game_mode; SwitchMode _switch_mode; ///< The next mainloop command. PauseModeByte _pause_mode; -int _pal_first_dirty; -int _pal_count_dirty; - -Colour _cur_palette[256]; +Palette _cur_palette; 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 @@ -1401,11 +1398,8 @@ void DoPaletteAnimations(); void GfxInitPalettes() { - memcpy(_cur_palette, _palette, sizeof(_cur_palette)); - + memcpy(&_cur_palette, &_palette, sizeof(_cur_palette)); DoPaletteAnimations(); - _pal_first_dirty = 0; - _pal_count_dirty = 256; } #define EXTR(p, q) (((uint16)(palette_animation_counter * (p)) * (q)) >> 16) @@ -1429,7 +1423,7 @@ void DoPaletteAnimations() 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, * 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)); @@ -1513,10 +1507,10 @@ void DoPaletteAnimations() if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) { palette_animation_counter = old_tc; } 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 */ - _pal_first_dirty = PALETTE_ANIM_START; - _pal_count_dirty = PALETTE_ANIM_SIZE; + _cur_palette.first_dirty = PALETTE_ANIM_START; + _cur_palette.count_dirty = PALETTE_ANIM_SIZE; } } } diff --git a/src/gfx_func.h b/src/gfx_func.h index 2061c9310..dee878915 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -64,12 +64,10 @@ extern bool _right_button_clicked; extern DrawPixelInfo _screen; 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 Dimension _resolutions[32]; 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 HandleCtrlChanged(); diff --git a/src/gfx_type.h b/src/gfx_type.h index c31c61e70..466612755 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -266,4 +266,11 @@ enum SpriteType { /** The number of milliseconds per game tick. */ 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 */ diff --git a/src/os/macosx/osx_stdafx.h b/src/os/macosx/osx_stdafx.h index ef09fb6a9..688762be9 100644 --- a/src/os/macosx/osx_stdafx.h +++ b/src/os/macosx/osx_stdafx.h @@ -42,14 +42,17 @@ #define Rect OTTDRect #define Point OTTDPoint #define WindowClass OTTDWindowClass -#define ScriptOrder OTTDScriptOrder +#define ScriptOrder OTTDScriptOrder +#define Palette OTTDPalette #include +#include #undef Rect #undef Point #undef WindowClass #undef ScriptOrder +#undef Palette /* remove the variables that CoreServices defines, but we define ourselves too */ #undef bool diff --git a/src/os/macosx/splash.cpp b/src/os/macosx/splash.cpp index a711bfd80..79bb0a022 100644 --- a/src/os/macosx/splash.cpp +++ b/src/os/macosx/splash.cpp @@ -136,19 +136,19 @@ void DisplaySplashImage() } for (int i = 0; i < num_palette; i++) { - _cur_palette[i].a = i == 0 ? 0 : 0xff; - _cur_palette[i].r = palette[i].red; - _cur_palette[i].g = palette[i].green; - _cur_palette[i].b = palette[i].blue; + _cur_palette.palette[i].a = i == 0 ? 0 : 0xff; + _cur_palette.palette[i].r = palette[i].red; + _cur_palette.palette[i].g = palette[i].green; + _cur_palette.palette[i].b = palette[i].blue; } - _cur_palette[0xff].a = 0xff; - _cur_palette[0xff].r = 0; - _cur_palette[0xff].g = 0; - _cur_palette[0xff].b = 0; + _cur_palette.palette[0xff].a = 0xff; + _cur_palette.palette[0xff].r = 0; + _cur_palette.palette[0xff].g = 0; + _cur_palette.palette[0xff].b = 0; - _pal_first_dirty = 0; - _pal_count_dirty = 256; + _cur_palette.first_dirty = 0; + _cur_palette.count_dirty = 256; break; } case 32: { diff --git a/src/screenshot.cpp b/src/screenshot.cpp index d5d63d113..5e8bf5971 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -725,7 +725,7 @@ static bool MakeSmallScreenshot() { const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; 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. */ @@ -746,7 +746,7 @@ static bool MakeZoomedInScreenshot() const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; 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. */ @@ -772,7 +772,7 @@ static bool MakeWorldScreenshot() sf = _screenshot_formats + _cur_screenshot_format; 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); } /** diff --git a/src/table/palettes.h b/src/table/palettes.h index 6f246ba68..8e720fca8 100644 --- a/src/table/palettes.h +++ b/src/table/palettes.h @@ -14,7 +14,8 @@ #define M(r, g, b) { 0xFF000000U | (r) << 16 | (g) << 8 | (b) } /** Colour palette (DOS) */ -static const Colour _palette[256] = { +static const Palette _palette = { + { /* transparent */ { 0}, /* grey scale */ @@ -89,6 +90,9 @@ static const Colour _palette[256] = { M( 0, 0, 0), M( 0, 0, 0), M( 0, 0, 0), /* pure white */ M(252, 252, 252) + }, + 0, // First dirty + 256 // Dirty count }; /** Description of the length of the palette cycle animations */ diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp index 0154cb519..7f8b4304c 100644 --- a/src/video/allegro_v.cpp +++ b/src/video/allegro_v.cpp @@ -75,9 +75,9 @@ static void UpdatePalette(uint start, uint count) uint end = start + count; for (uint i = start; i != end; i++) { - pal[i].r = _cur_palette[i].r / 4; - pal[i].g = _cur_palette[i].g / 4; - pal[i].b = _cur_palette[i].b / 4; + pal[i].r = _cur_palette.palette[i].r / 4; + pal[i].g = _cur_palette.palette[i].g / 4; + pal[i].b = _cur_palette.palette[i].b / 4; pal[i].filler = 0; } @@ -91,16 +91,16 @@ static void InitPalette() static void CheckPaletteAnim() { - if (_pal_count_dirty != 0) { + if (_cur_palette.count_dirty != 0) { Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); switch (blitter->UsePaletteAnimation()) { case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: - UpdatePalette(_pal_first_dirty, _pal_count_dirty); + UpdatePalette(_cur_palette.first_dirty, _cur_palette.count_dirty); break; case Blitter::PALETTE_ANIMATION_BLITTER: - blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); + blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty); break; case Blitter::PALETTE_ANIMATION_NONE: @@ -109,7 +109,7 @@ static void CheckPaletteAnim() default: NOT_REACHED(); } - _pal_count_dirty = 0; + _cur_palette.count_dirty = 0; } } diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h index 157b285c8..a27b3c204 100644 --- a/src/video/cocoa/cocoa_v.h +++ b/src/video/cocoa/cocoa_v.h @@ -12,8 +12,6 @@ #ifndef VIDEO_COCOA_H #define VIDEO_COCOA_H -#include - #include "../video_driver.hpp" class VideoDriver_Cocoa: public VideoDriver { diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm index a0d79a529..3a9a62595 100644 --- a/src/video/cocoa/event.mm +++ b/src/video/cocoa/event.mm @@ -90,16 +90,16 @@ static void QZ_WarpCursor(int x, int y) static void QZ_CheckPaletteAnim() { - if (_pal_count_dirty != 0) { + if (_cur_palette.count_dirty != 0) { Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); switch (blitter->UsePaletteAnimation()) { 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; case Blitter::PALETTE_ANIMATION_BLITTER: - blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); + blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty); break; case Blitter::PALETTE_ANIMATION_NONE: @@ -108,7 +108,7 @@ static void QZ_CheckPaletteAnim() default: NOT_REACHED(); } - _pal_count_dirty = 0; + _cur_palette.count_dirty = 0; } } diff --git a/src/video/cocoa/fullscreen.mm b/src/video/cocoa/fullscreen.mm index db793a6b1..bd55852c3 100644 --- a/src/video/cocoa/fullscreen.mm +++ b/src/video/cocoa/fullscreen.mm @@ -494,9 +494,9 @@ public: for (uint32_t index = first_color; index < first_color + num_colors; index++) { /* Clamp colors between 0.0 and 1.0 */ CGDeviceColor color; - color.red = _cur_palette[index].r / 255.0; - color.blue = _cur_palette[index].b / 255.0; - color.green = _cur_palette[index].g / 255.0; + color.red = _cur_palette.palette[index].r / 255.0; + color.blue = _cur_palette.palette[index].b / 255.0; + color.green = _cur_palette.palette[index].g / 255.0; CGPaletteSetColorAtIndex(this->palette, color, index); } diff --git a/src/video/cocoa/wnd_quartz.mm b/src/video/cocoa/wnd_quartz.mm index 1fb85e011..5d45dcbab 100644 --- a/src/video/cocoa/wnd_quartz.mm +++ b/src/video/cocoa/wnd_quartz.mm @@ -468,9 +468,9 @@ void WindowQuartzSubdriver::UpdatePalette(uint first_color, uint num_colors) for (uint i = first_color; i < first_color + num_colors; i++) { uint32 clr = 0xff000000; - clr |= (uint32)_cur_palette[i].r << 16; - clr |= (uint32)_cur_palette[i].g << 8; - clr |= (uint32)_cur_palette[i].b; + clr |= (uint32)_cur_palette.palette[i].r << 16; + clr |= (uint32)_cur_palette.palette[i].g << 8; + clr |= (uint32)_cur_palette.palette[i].b; this->palette[i] = clr; } diff --git a/src/video/cocoa/wnd_quickdraw.mm b/src/video/cocoa/wnd_quickdraw.mm index b8eafc620..97dfac7d5 100644 --- a/src/video/cocoa/wnd_quickdraw.mm +++ b/src/video/cocoa/wnd_quickdraw.mm @@ -416,18 +416,18 @@ void WindowQuickdrawSubdriver::UpdatePalette(uint first_color, uint num_colors) case 32: for (uint i = first_color; i < first_color + num_colors; i++) { uint32 clr32 = 0xff000000; - clr32 |= (uint32)_cur_palette[i].r << 16; - clr32 |= (uint32)_cur_palette[i].g << 8; - clr32 |= (uint32)_cur_palette[i].b; + clr32 |= (uint32)_cur_palette.palette[i].r << 16; + clr32 |= (uint32)_cur_palette.palette[i].g << 8; + clr32 |= (uint32)_cur_palette.palette[i].b; this->palette[i] = clr32; } break; case 16: for (uint i = first_color; i < first_color + num_colors; i++) { uint16 clr16 = 0x0000; - clr16 |= (uint16)((_cur_palette[i].r >> 3) & 0x1f) << 10; - clr16 |= (uint16)((_cur_palette[i].g >> 3) & 0x1f) << 5; - clr16 |= (uint16)((_cur_palette[i].b >> 3) & 0x1f); + clr16 |= (uint16)((_cur_palette.palette[i].r >> 3) & 0x1f) << 10; + clr16 |= (uint16)((_cur_palette.palette[i].g >> 3) & 0x1f) << 5; + clr16 |= (uint16)((_cur_palette.palette[i].b >> 3) & 0x1f); this->palette[i] = clr16; } break; diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index ebb0ca757..1b579cc51 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -60,9 +60,9 @@ static void UpdatePalette(uint start, uint count) SDL_Color pal[256]; for (uint i = 0; i != count; i++) { - pal[i].r = _cur_palette[start + i].r; - pal[i].g = _cur_palette[start + i].g; - pal[i].b = _cur_palette[start + i].b; + pal[i].r = _cur_palette.palette[start + i].r; + pal[i].g = _cur_palette.palette[start + i].g; + pal[i].b = _cur_palette.palette[start + i].b; pal[i].unused = 0; } @@ -76,16 +76,16 @@ static void InitPalette() static void CheckPaletteAnim() { - if (_pal_count_dirty != 0) { + if (_cur_palette.count_dirty != 0) { Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); switch (blitter->UsePaletteAnimation()) { case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: - UpdatePalette(_pal_first_dirty, _pal_count_dirty); + UpdatePalette(_cur_palette.first_dirty, _cur_palette.count_dirty); break; case Blitter::PALETTE_ANIMATION_BLITTER: - blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); + blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty); break; case Blitter::PALETTE_ANIMATION_NONE: @@ -94,7 +94,7 @@ static void CheckPaletteAnim() default: NOT_REACHED(); } - _pal_count_dirty = 0; + _cur_palette.count_dirty = 0; } } diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index f571638b8..5cd9f64da 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -56,9 +56,9 @@ static void MakePalette() pal->palNumEntries = 256; for (i = 0; i != 256; i++) { - pal->palPalEntry[i].peRed = _cur_palette[i].r; - pal->palPalEntry[i].peGreen = _cur_palette[i].g; - pal->palPalEntry[i].peBlue = _cur_palette[i].b; + pal->palPalEntry[i].peRed = _cur_palette.palette[i].r; + pal->palPalEntry[i].peGreen = _cur_palette.palette[i].g; + pal->palPalEntry[i].peBlue = _cur_palette.palette[i].b; pal->palPalEntry[i].peFlags = 0; } @@ -72,9 +72,9 @@ static void UpdatePalette(HDC dc, uint start, uint count) uint i; for (i = 0; i != count; i++) { - rgb[i].rgbRed = _cur_palette[start + i].r; - rgb[i].rgbGreen = _cur_palette[start + i].g; - rgb[i].rgbBlue = _cur_palette[start + i].b; + rgb[i].rgbRed = _cur_palette.palette[start + i].r; + rgb[i].rgbGreen = _cur_palette.palette[start + i].g; + rgb[i].rgbBlue = _cur_palette.palette[start + i].b; rgb[i].rgbReserved = 0; } @@ -162,8 +162,8 @@ static void ClientSizeChanged(int w, int h) /* allocate new dib section of the new size */ if (AllocateDibSection(w, h)) { /* mark all palette colors dirty */ - _pal_first_dirty = 0; - _pal_count_dirty = 256; + _cur_palette.first_dirty = 0; + _cur_palette.count_dirty = 256; 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_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE); - if (_pal_count_dirty != 0) { + if (_cur_palette.count_dirty != 0) { Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); switch (blitter->UsePaletteAnimation()) { 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; case Blitter::PALETTE_ANIMATION_BLITTER: - blitter->PaletteAnimate(_pal_first_dirty, _pal_count_dirty); + blitter->PaletteAnimate(_cur_palette.first_dirty, _cur_palette.count_dirty); break; case Blitter::PALETTE_ANIMATION_NONE: @@ -368,7 +368,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP default: NOT_REACHED(); } - _pal_count_dirty = 0; + _cur_palette.count_dirty = 0; } 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() { - if (_pal_count_dirty == 0) return; + if (_cur_palette.count_dirty == 0) return; InvalidateRect(_wnd.main_wnd, NULL, FALSE); } -- cgit v1.2.3-54-g00ecf