mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 02:19:41 +00:00
(svn r23446) -Codechange: move _cur_palette and it's related first/count dirty variables into a single structure
This commit is contained in:
parent
9e8b76650a
commit
2ccbd2a6f5
@ -45,7 +45,7 @@ public:
|
||||
*/
|
||||
static inline uint32 LookupColourInPalette(uint index)
|
||||
{
|
||||
return _cur_palette[index].data;
|
||||
return _cur_palette.palette[index].data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -440,7 +440,6 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
|
||||
* ======================================================================================== */
|
||||
|
||||
#include "os/macosx/macos.h"
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
|
||||
{
|
||||
|
18
src/gfx.cpp
18
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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 */
|
||||
|
@ -42,14 +42,17 @@
|
||||
#define Rect OTTDRect
|
||||
#define Point OTTDPoint
|
||||
#define WindowClass OTTDWindowClass
|
||||
#define ScriptOrder OTTDScriptOrder
|
||||
#define ScriptOrder OTTDScriptOrder
|
||||
#define Palette OTTDPalette
|
||||
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
#undef Rect
|
||||
#undef Point
|
||||
#undef WindowClass
|
||||
#undef ScriptOrder
|
||||
#undef Palette
|
||||
|
||||
/* remove the variables that CoreServices defines, but we define ourselves too */
|
||||
#undef bool
|
||||
|
@ -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: {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
||||
#ifndef VIDEO_COCOA_H
|
||||
#define VIDEO_COCOA_H
|
||||
|
||||
#include <AvailabilityMacros.h>
|
||||
|
||||
#include "../video_driver.hpp"
|
||||
|
||||
class VideoDriver_Cocoa: public VideoDriver {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user