Changeset - r18589:8ea5c6919bb5
[Not reviewed]
master
0 17 0
rubidium - 12 years ago 2011-12-08 18:13:29
rubidium@openttd.org
(svn r23446) -Codechange: move _cur_palette and it's related first/count dirty variables into a single structure
17 files changed with 80 insertions and 77 deletions:
0 comments (0 inline, 0 general)
src/blitter/32bpp_base.hpp
Show inline comments
 
@@ -45,7 +45,7 @@ public:
 
	 */
 
	static inline uint32 LookupColourInPalette(uint index)
 
	{
 
		return _cur_palette[index].data;
 
		return _cur_palette.palette[index].data;
 
	}
 

	
 
	/**
src/fontcache.cpp
Show inline comments
 
@@ -440,7 +440,6 @@ bool SetFallbackFont(FreeTypeSettings *s
 
 * ======================================================================================== */
 

	
 
#include "os/macosx/macos.h"
 
#include <ApplicationServices/ApplicationServices.h>
 

	
 
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
 
{
src/gfx.cpp
Show inline comments
 
@@ -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;
 
		}
 
	}
 
}
src/gfx_func.h
Show inline comments
 
@@ -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();
src/gfx_type.h
Show inline comments
 
@@ -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 */
src/os/macosx/osx_stdafx.h
Show inline comments
 
@@ -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
src/os/macosx/splash.cpp
Show inline comments
 
@@ -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: {
src/screenshot.cpp
Show inline comments
 
@@ -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);
 
}
 

	
 
/**
src/table/palettes.h
Show inline comments
 
@@ -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 */
src/video/allegro_v.cpp
Show inline comments
 
@@ -75,9 +75,9 @@ static void UpdatePalette(uint start, ui
 

	
 
	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;
 
	}
 
}
 

	
src/video/cocoa/cocoa_v.h
Show inline comments
 
@@ -12,8 +12,6 @@
 
#ifndef VIDEO_COCOA_H
 
#define VIDEO_COCOA_H
 

	
 
#include <AvailabilityMacros.h>
 

	
 
#include "../video_driver.hpp"
 

	
 
class VideoDriver_Cocoa: public VideoDriver {
src/video/cocoa/event.mm
Show inline comments
 
@@ -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;
 
	}
 
}
 

	
src/video/cocoa/fullscreen.mm
Show inline comments
 
@@ -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);
 
		}
src/video/cocoa/wnd_quartz.mm
Show inline comments
 
@@ -468,9 +468,9 @@ void WindowQuartzSubdriver::UpdatePalett
 

	
 
	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;
 
	}
 

	
src/video/cocoa/wnd_quickdraw.mm
Show inline comments
 
@@ -416,18 +416,18 @@ void WindowQuickdrawSubdriver::UpdatePal
 
		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;
src/video/sdl_v.cpp
Show inline comments
 
@@ -60,9 +60,9 @@ static void UpdatePalette(uint start, ui
 
	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;
 
	}
 
}
 

	
src/video/win32_v.cpp
Show inline comments
 
@@ -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 s
 
	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
 
	/* 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 
 
			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 
 
					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 le
 

	
 
static void CheckPaletteAnim()
 
{
 
	if (_pal_count_dirty == 0) return;
 
	if (_cur_palette.count_dirty == 0) return;
 

	
 
	InvalidateRect(_wnd.main_wnd, NULL, FALSE);
 
}
0 comments (0 inline, 0 general)