Changeset - r6937:bea726150bf3
[Not reviewed]
master
8 29 6
truelight - 17 years ago 2007-06-17 20:30:28
truelight@openttd.org
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
-Codechange: introduced a hierachy of blitters to avoid a lot of code duplication
Note: this allows much easier adding other types of video-drivers, like OpenGL
43 files changed with 722 insertions and 863 deletions:
0 comments (0 inline, 0 general)
projects/generate
Show inline comments
 
@@ -40,7 +40,7 @@ file_prefix="..\\\\src\\\\"
 

	
 
safety_check() {
 
	li=""
 
	for i in `cat $1 | grep -v "#" | xargs -n 1 basename | sort`; do
 
	for i in `cat $1 | grep -v "#\|ottdres.rc\|win32.cpp\|win32_v.cpp" | xargs -n 1 basename | sort`; do
 
		if [ "$li" = "$i" ]; then
 
			echo " !! ERROR !!"
 
			echo ""
projects/openttd.vcproj
Show inline comments
 
@@ -968,12 +968,24 @@
 
			Name="Blitters"
 
			Filter="">
 
			<File
 
				RelativePath=".\..\src\blitter\32bpp_base.cpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\32bpp_base.hpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\32bpp_simple.cpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\32bpp_simple.hpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\8bpp_base.cpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\8bpp_base.hpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\8bpp_debug.cpp">
 
			</File>
 
			<File
 
@@ -992,7 +1004,10 @@
 
				RelativePath=".\..\src\blitter\8bpp_simple.hpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\blitter.hpp">
 
				RelativePath=".\..\src\blitter\base.hpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\factory.hpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\null.cpp">
 
@@ -1021,31 +1036,6 @@
 
			</File>
 
		</Filter>
 
		<Filter
 
			Name="Renderer"
 
			Filter="">
 
			<File
 
				RelativePath=".\..\src\renderer\32bpp.cpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\32bpp.hpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\8bpp.cpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\8bpp.hpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\null.cpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\null.hpp">
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\renderer.hpp">
 
			</File>
 
		</Filter>
 
		<Filter
 
			Name="NewGRF"
 
			Filter="">
 
			<File
projects/openttd_vs80.vcproj
Show inline comments
 
@@ -1512,6 +1512,14 @@
 
			Name="Blitters"
 
			>
 
			<File
 
				RelativePath=".\..\src\blitter\32bpp_base.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\32bpp_base.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\32bpp_simple.cpp"
 
				>
 
			</File>
 
@@ -1520,6 +1528,14 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\8bpp_base.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\8bpp_base.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\8bpp_debug.cpp"
 
				>
 
			</File>
 
@@ -1544,7 +1560,11 @@
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\blitter.hpp"
 
				RelativePath=".\..\src\blitter\base.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\blitter\factory.hpp"
 
				>
 
			</File>
 
			<File
 
@@ -1581,38 +1601,6 @@
 
			</File>
 
		</Filter>
 
		<Filter
 
			Name="Renderer"
 
			>
 
			<File
 
				RelativePath=".\..\src\renderer\32bpp.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\32bpp.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\8bpp.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\8bpp.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\null.cpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\null.hpp"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\..\src\renderer\renderer.hpp"
 
				>
 
			</File>
 
		</Filter>
 
		<Filter
 
			Name="NewGRF"
 
			>
 
			<File
source.list
Show inline comments
 
@@ -293,15 +293,20 @@ ai/trolly/shared.cpp
 
ai/trolly/trolly.cpp
 

	
 
# Blitters
 
blitter/32bpp_base.cpp
 
blitter/32bpp_base.hpp
 
blitter/32bpp_simple.cpp
 
blitter/32bpp_simple.hpp
 
blitter/8bpp_base.cpp
 
blitter/8bpp_base.hpp
 
blitter/8bpp_debug.cpp
 
blitter/8bpp_debug.hpp
 
blitter/8bpp_optimized.cpp
 
blitter/8bpp_optimized.hpp
 
blitter/8bpp_simple.cpp
 
blitter/8bpp_simple.hpp
 
blitter/blitter.hpp
 
blitter/base.hpp
 
blitter/factory.hpp
 
blitter/null.cpp
 
blitter/null.hpp
 

	
 
@@ -314,15 +319,6 @@ spriteloader/png.hpp
 
#end
 
spriteloader/spriteloader.hpp
 

	
 
# Renderer
 
renderer/32bpp.cpp
 
renderer/32bpp.hpp
 
renderer/8bpp.cpp
 
renderer/8bpp.hpp
 
renderer/null.cpp
 
renderer/null.hpp
 
renderer/renderer.hpp
 

	
 
# NewGRF
 
newgrf.cpp
 
newgrf_canal.cpp
src/blitter/32bpp_base.cpp
Show inline comments
 
new file 100644
 
#include "../stdafx.h"
 
#include "../gfx.h"
 
#include "32bpp_base.hpp"
 

	
 
void *Blitter_32bppBase::MoveTo(const void *video, int x, int y)
 
{
 
	return (uint32 *)video + x + y * _screen.pitch;
 
}
 

	
 
void Blitter_32bppBase::SetPixel(void *video, int x, int y, uint8 color)
 
{
 
	*((uint32 *)video + x + y * _screen.pitch) = LookupColourInPalette(color);
 
}
 

	
 
void Blitter_32bppBase::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
 
{
 
	uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
 
	if (*dst == 0) *dst = LookupColourInPalette(color);
 
}
 

	
 
void Blitter_32bppBase::SetHorizontalLine(void *video, int width, uint8 color)
 
{
 
	uint32 *dst = (uint32 *)video;
 
	uint32 color32 = LookupColourInPalette(color);
 

	
 
	for (; width > 0; width--) {
 
		*dst = color32;
 
		dst++;
 
	}
 
}
 

	
 
void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, uint8 color)
 
{
 
	int dy;
 
	int dx;
 
	int stepx;
 
	int stepy;
 
	int frac;
 

	
 
	dy = (y2 - y) * 2;
 
	if (dy < 0) {
 
		dy = -dy;
 
		stepy = -1;
 
	} else {
 
		stepy = 1;
 
	}
 

	
 
	dx = (x2 - x) * 2;
 
	if (dx < 0) {
 
		dx = -dx;
 
		stepx = -1;
 
	} else {
 
		stepx = 1;
 
	}
 

	
 
	this->SetPixel(video, x, y, color);
 
	if (dx > dy) {
 
		frac = dy - (dx >> 1);
 
		while (x != x2) {
 
			if (frac >= 0) {
 
				y += stepy;
 
				frac -= dx;
 
			}
 
			x += stepx;
 
			frac += dy;
 
			this->SetPixel(video, x, y, color);
 
		}
 
	} else {
 
		frac = dx - (dy >> 1);
 
		while (y != y2) {
 
			if (frac >= 0) {
 
				x += stepx;
 
				frac -= dy;
 
			}
 
			y += stepy;
 
			frac += dx;
 
			this->SetPixel(video, x, y, color);
 
		}
 
	}
 
}
 

	
 
void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
 
{
 
	int direction = (height < 0) ? -1 : 1;
 
	uint32 *dst = (uint32 *)video;
 
	uint32 *usrc = (uint32 *)src;
 

	
 
	height = abs(height);
 
	for (; height > 0; height--) {
 
		memcpy(dst, usrc, width * sizeof(uint32));
 
		usrc += src_pitch * direction;
 
		dst += _screen.pitch * direction;
 
	}
 
}
 

	
 
void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
 
{
 
	int direction = (height < 0) ? -1 : 1;
 
	uint32 *udst = (uint32 *)dst;
 
	uint32 *src = (uint32 *)video;
 

	
 
	height = abs(height);
 
	for (; height > 0; height--) {
 
		memcpy(udst, src, width * sizeof(uint32));
 
		src += _screen.pitch * direction;
 
		udst += dst_pitch * direction;
 
	}
 
}
 

	
 
void Blitter_32bppBase::MoveBuffer(void *video_dst, const void *video_src, int width, int height)
 
{
 
	uint32 *dst = (uint32 *)video_dst;
 
	uint32 *src = (uint32 *)video_src;
 

	
 
	for (; height > 0; height--) {
 
		memmove(dst, src, width * sizeof(uint32));
 
		src += _screen.pitch;
 
		dst += _screen.pitch;
 
	}
 
}
 

	
 
int Blitter_32bppBase::BufferSize(int width, int height)
 
{
 
	return width * height * sizeof(uint32);
 
}
src/blitter/32bpp_base.hpp
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file 32bpp_base.hpp */
 

	
 
#ifndef BLITTER_32BPP_BASE_HPP
 
#define BLITTER_32BPP_BASE_HPP
 

	
 
#include "base.hpp"
 

	
 
class Blitter_32bppBase : public Blitter {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 32; }
 
//	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 
//	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 
//	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 
	/* virtual */ void *MoveTo(const void *video, int x, int y);
 
	/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
 
	/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
 
	/* virtual */ void SetHorizontalLine(void *video, int width, uint8 color);
 
	/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, uint8 color);
 
	/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch);
 
	/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
 
	/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height);
 
	/* virtual */ int BufferSize(int width, int height);
 

	
 
	static inline uint32 LookupColourInPalette(uint8 index) {
 
		#define ARGB(a, r, g, b) ((((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF))
 
		if (index == 0) return 0x00000000;
 
		return ARGB(0xFF, _cur_palette[index].r, _cur_palette[index].g, _cur_palette[index].b);
 
	}
 
};
 

	
 
#endif /* BLITTER_32BPP_BASE_HPP */
src/blitter/32bpp_simple.cpp
Show inline comments
 
@@ -3,7 +3,6 @@
 
#include "../gfx.h"
 
#include "../debug.h"
 
#include "../table/sprites.h"
 
#include "../renderer/32bpp.hpp"
 
#include "32bpp_simple.hpp"
 

	
 
static FBlitter_32bppSimple iFBlitter_32bppSimple;
 
@@ -108,7 +107,7 @@ void Blitter_32bppSimple::Draw(Blitter::
 
					if (src->m == 0) {
 
						if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst);
 
					} else {
 
						if (bp->remap[src->m] != 0) *dst = ComposeColorPA(Renderer_32bpp::LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
 
						if (bp->remap[src->m] != 0) *dst = ComposeColorPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
 
					}
 
					break;
 

	
 
@@ -176,7 +175,7 @@ Sprite *Blitter_32bppSimple::Encode(Spri
 
	for (int i = 0; i < sprite->height * sprite->width; i++) {
 
		if (dst[i].m != 0) {
 
			/* Pre-convert the mapping channel to a RGB value */
 
			uint color = Renderer_32bpp::LookupColourInPalette(dst[i].m);
 
			uint color = this->LookupColourInPalette(dst[i].m);
 
			dst[i].r = GB(color, 16, 8);
 
			dst[i].g = GB(color, 8,  8);
 
			dst[i].b = GB(color, 0,  8);
src/blitter/32bpp_simple.hpp
Show inline comments
 
@@ -5,27 +5,20 @@
 
#ifndef BLITTER_32BPP_SIMPLE_HPP
 
#define BLITTER_32BPP_SIMPLE_HPP
 

	
 
#include "blitter.hpp"
 
#include "32bpp_base.hpp"
 
#include "factory.hpp"
 

	
 
class Blitter_32bppSimple : public Blitter {
 
class Blitter_32bppSimple : public Blitter_32bppBase {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 32; }
 

	
 
	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 

	
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 

	
 
	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 

	
 
	/* virtual */ const char *GetRenderer() { return "32bpp"; }
 
};
 

	
 
class FBlitter_32bppSimple: public BlitterFactory<FBlitter_32bppSimple> {
 
public:
 
	/* virtual */ const char *GetName() { return "32bpp-simple"; }
 

	
 
	/* virtual */ const char *GetDescription() { return "32bpp Simple Blitter (no palette animation)"; }
 

	
 
	/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSimple(); }
 
};
 

	
src/blitter/8bpp_base.cpp
Show inline comments
 
new file 100644
 
#include "../stdafx.h"
 
#include "../gfx.h"
 
#include "8bpp_base.hpp"
 

	
 
void Blitter_8bppBase::DrawColorMappingRect(void *dst, int width, int height, int pal)
 
{
 
	const uint8 *ctab = GetNonSprite(pal) + 1;
 

	
 
	do {
 
		for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]];
 
		dst = (uint8 *)dst + _screen.pitch;
 
	} while (height--);
 
}
 

	
 
void *Blitter_8bppBase::MoveTo(const void *video, int x, int y)
 
{
 
	return (uint8 *)video + x + y * _screen.pitch;
 
}
 

	
 
void Blitter_8bppBase::SetPixel(void *video, int x, int y, uint8 color)
 
{
 
	*((uint8 *)video + x + y * _screen.pitch) = color;
 
}
 

	
 
void Blitter_8bppBase::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
 
{
 
	uint8 *dst = (uint8 *)video + x + y * _screen.pitch;
 
	if (*dst == 0) *dst = color;
 
}
 

	
 
void Blitter_8bppBase::SetHorizontalLine(void *video, int width, uint8 color)
 
{
 
	memset(video, color, width);
 
}
 

	
 
void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, uint8 color)
 
{
 
	int dy;
 
	int dx;
 
	int stepx;
 
	int stepy;
 
	int frac;
 

	
 
	dy = (y2 - y) * 2;
 
	if (dy < 0) {
 
		dy = -dy;
 
		stepy = -1;
 
	} else {
 
		stepy = 1;
 
	}
 

	
 
	dx = (x2 - x) * 2;
 
	if (dx < 0) {
 
		dx = -dx;
 
		stepx = -1;
 
	} else {
 
		stepx = 1;
 
	}
 

	
 
	this->SetPixel(video, x, y, color);
 
	if (dx > dy) {
 
		frac = dy - (dx / 2);
 
		while (x != x2) {
 
			if (frac >= 0) {
 
				y += stepy;
 
				frac -= dx;
 
			}
 
			x += stepx;
 
			frac += dy;
 
			this->SetPixel(video, x, y, color);
 
		}
 
	} else {
 
		frac = dx - (dy / 2);
 
		while (y != y2) {
 
			if (frac >= 0) {
 
				x += stepx;
 
				frac -= dy;
 
			}
 
			y += stepy;
 
			frac += dx;
 
			this->SetPixel(video, x, y, color);
 
		}
 
	}
 
}
 

	
 
void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
 
{
 
	int direction = (height < 0) ? -1 : 1;
 
	uint8 *dst = (uint8 *)video;
 
	uint8 *usrc = (uint8 *)src;
 

	
 
	height = abs(height);
 
	for (; height > 0; height--) {
 
		memcpy(dst, usrc, width);
 
		usrc += src_pitch * direction;
 
		dst += _screen.pitch * direction;
 
	}
 
}
 

	
 
void Blitter_8bppBase::CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
 
{
 
	int direction = (height < 0) ? -1 : 1;
 
	uint8 *udst = (uint8 *)dst;
 
	uint8 *src = (uint8 *)video;
 

	
 
	height = abs(height);
 
	for (; height > 0; height--) {
 
		memcpy(udst, src, width);
 
		src += _screen.pitch * direction;
 
		udst += dst_pitch * direction;
 
	}
 
}
 

	
 
void Blitter_8bppBase::MoveBuffer(void *video_dst, const void *video_src, int width, int height)
 
{
 
	uint8 *dst = (uint8 *)video_dst;
 
	uint8 *src = (uint8 *)video_src;
 

	
 
	for (; height > 0; height--) {
 
		memmove(dst, src, width);
 
		src += _screen.pitch;
 
		dst += _screen.pitch;
 
	}
 
}
 

	
 
int Blitter_8bppBase::BufferSize(int width, int height)
 
{
 
	return width * height;
 
}
src/blitter/8bpp_base.hpp
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file 8bpp_base.hpp */
 

	
 
#ifndef BLITTER_8BPP_BASE_HPP
 
#define BLITTER_8BPP_BASE_HPP
 

	
 
#include "base.hpp"
 

	
 
class Blitter_8bppBase : public Blitter {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 8; }
 
//	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 
//	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 
	/* virtual */ void *MoveTo(const void *video, int x, int y);
 
	/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
 
	/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
 
	/* virtual */ void SetHorizontalLine(void *video, int width, uint8 color);
 
	/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, uint8 color);
 
	/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch);
 
	/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
 
	/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height);
 
	/* virtual */ int BufferSize(int width, int height);
 
};
 

	
 
#endif /* BLITTER_8BPP_BASE_HPP */
src/blitter/8bpp_debug.cpp
Show inline comments
 
@@ -35,16 +35,6 @@ void Blitter_8bppDebug::Draw(Blitter::Bl
 
	}
 
}
 

	
 
void Blitter_8bppDebug::DrawColorMappingRect(void *dst, int width, int height, int pal)
 
{
 
	const uint8 *ctab = GetNonSprite(pal) + 1;
 

	
 
	do {
 
		for (int i = 0; i != width; i++) _screen.renderer->SetPixel(dst, i, 0, ctab[((uint8 *)dst)[i]]);
 
		dst = _screen.renderer->MoveTo(dst, 0, 1);
 
	} while (height--);
 
}
 

	
 
Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
 
{
 
	Sprite *dest_sprite;
src/blitter/8bpp_debug.hpp
Show inline comments
 
@@ -5,27 +5,19 @@
 
#ifndef BLITTER_8BPP_DEBUG_HPP
 
#define BLITTER_8BPP_DEBUG_HPP
 

	
 
#include "blitter.hpp"
 
#include "8bpp_base.hpp"
 
#include "factory.hpp"
 

	
 
class Blitter_8bppDebug : public Blitter {
 
class Blitter_8bppDebug : public Blitter_8bppBase {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 8; }
 

	
 
	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 

	
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 

	
 
	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 

	
 
	/* virtual */ const char *GetRenderer() { return "8bpp"; }
 
};
 

	
 
class FBlitter_8bppDebug: public BlitterFactory<FBlitter_8bppDebug> {
 
public:
 
	/* virtual */ const char *GetName() { return "8bpp-debug"; }
 

	
 
	/* virtual */ const char *GetDescription() { return "8bpp Debug Blitter (testing only)"; }
 

	
 
	/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppDebug(); }
 
};
 

	
src/blitter/8bpp_optimized.cpp
Show inline comments
 
@@ -102,16 +102,6 @@ void Blitter_8bppOptimized::Draw(Blitter
 
	}
 
}
 

	
 
void Blitter_8bppOptimized::DrawColorMappingRect(void *dst, int width, int height, int pal)
 
{
 
	const uint8 *ctab = GetNonSprite(pal) + 1;
 

	
 
	do {
 
		for (int i = 0; i != width; i++) _screen.renderer->SetPixel(dst, i, 0, ctab[((uint8 *)dst)[i]]);
 
		dst = _screen.renderer->MoveTo(dst, 0, 1);
 
	} while (height--);
 
}
 

	
 
Sprite *Blitter_8bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
 
{
 
	Sprite *dest_sprite;
src/blitter/8bpp_optimized.hpp
Show inline comments
 
@@ -5,27 +5,19 @@
 
#ifndef BLITTER_8BPP_OPTIMIZED_HPP
 
#define BLITTER_8BPP_OPTIMIZED_HPP
 

	
 
#include "blitter.hpp"
 
#include "8bpp_base.hpp"
 
#include "factory.hpp"
 

	
 
class Blitter_8bppOptimized : public Blitter {
 
class Blitter_8bppOptimized : public Blitter_8bppBase {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 8; }
 

	
 
	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 

	
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 

	
 
	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 

	
 
	/* virtual */ const char *GetRenderer() { return "8bpp"; }
 
};
 

	
 
class FBlitter_8bppOptimized: public BlitterFactory<FBlitter_8bppOptimized> {
 
public:
 
	/* virtual */ const char *GetName() { return "8bpp-optimized"; }
 

	
 
	/* virtual */ const char *GetDescription() { return "8bpp Optimized Blitter (compression + all-ZoomLevel cache)"; }
 

	
 
	/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppOptimized(); }
 
};
 

	
src/blitter/8bpp_simple.cpp
Show inline comments
 
@@ -48,16 +48,6 @@ void Blitter_8bppSimple::Draw(Blitter::B
 
	}
 
}
 

	
 
void Blitter_8bppSimple::DrawColorMappingRect(void *dst, int width, int height, int pal)
 
{
 
	const uint8 *ctab = GetNonSprite(pal) + 1;
 

	
 
	do {
 
		for (int i = 0; i != width; i++) _screen.renderer->SetPixel(dst, i, 0, ctab[((uint8 *)dst)[i]]);
 
		dst = _screen.renderer->MoveTo(dst, 0, 1);
 
	} while (height--);
 
}
 

	
 
Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
 
{
 
	Sprite *dest_sprite;
src/blitter/8bpp_simple.hpp
Show inline comments
 
@@ -5,27 +5,19 @@
 
#ifndef BLITTER_8BPP_SIMPLE_HPP
 
#define BLITTER_8BPP_SIMPLE_HPP
 

	
 
#include "blitter.hpp"
 
#include "8bpp_base.hpp"
 
#include "factory.hpp"
 

	
 
class Blitter_8bppSimple : public Blitter {
 
class Blitter_8bppSimple : public Blitter_8bppBase {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 8; }
 

	
 
	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 

	
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 

	
 
	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 

	
 
	/* virtual */ const char *GetRenderer() { return "8bpp"; }
 
};
 

	
 
class FBlitter_8bppSimple: public BlitterFactory<FBlitter_8bppSimple> {
 
public:
 
	/* virtual */ const char *GetName() { return "8bpp-simple"; }
 

	
 
	/* virtual */ const char *GetDescription() { return "8bpp Simple Blitter (relative slow, but never wrong)"; }
 

	
 
	/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppSimple(); }
 
};
 

	
src/blitter/base.hpp
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
#ifndef BLITTER_BASE_HPP
 
#define BLITTER_BASE_HPP
 

	
 
#include "../spritecache.h"
 
#include "../spriteloader/spriteloader.hpp"
 

	
 
enum BlitterMode {
 
	BM_NORMAL,
 
	BM_COLOUR_REMAP,
 
	BM_TRANSPARENT,
 
};
 

	
 
/**
 
 * How all blitters should look like. Extend this class to make your own.
 
 */
 
class Blitter {
 
public:
 
	struct BlitterParams {
 
		const void *sprite;      ///< Pointer to the sprite how ever the encoder stored it
 
		const byte *remap;       ///< XXX -- Temporary storage for remap array
 

	
 
		int skip_left, skip_top; ///< How much pixels of the source to skip on the left and top (based on zoom of dst)
 
		int width, height;       ///< The width and height in pixels that needs to be drawn to dst
 
		int sprite_width;        ///< Real width of the sprite
 
		int sprite_height;       ///< Real height of the sprite
 
		int left, top;           ///< The offset in the 'dst' in pixels to start drawing
 

	
 
		void *dst;               ///< Destination buffer
 
		int pitch;               ///< The pitch of the destination buffer
 
	};
 

	
 
	typedef void *AllocatorProc(size_t size);
 

	
 
	/**
 
	 * Get the screen depth this blitter works for.
 
	 *  This is either: 8, 16, 24 or 32.
 
	 */
 
	virtual uint8 GetScreenDepth() = 0;
 

	
 
	/**
 
	 * Draw an image to the screen, given an amount of params defined above.
 
	 */
 
	virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0;
 

	
 
	/**
 
	 * Draw a colortable to the screen. This is: the color of the screen is read
 
	 *  and is looked-up in the palette to match a new color, which then is put
 
	 *  on the screen again.
 
	 * @param dst the destination pointer (video-buffer).
 
	 * @param width the width of the buffer.
 
	 * @param height the height of the buffer.
 
	 * @param pal the palette to use.
 
	 */
 
	virtual void DrawColorMappingRect(void *dst, int width, int height, int pal) = 0;
 

	
 
	/**
 
	 * Convert a sprite from the loader to our own format.
 
	 */
 
	virtual Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) = 0;
 

	
 
	/**
 
	 * Move the destination pointer the requested amount x and y, keeping in mind
 
	 *  any pitch and bpp of the renderer.
 
	 * @param video The destination pointer (video-buffer) to scroll.
 
	 * @param x How much you want to scroll to the right.
 
	 * @param y How much you want to scroll to the bottom.
 
	 * @return A new destination pointer moved the the requested place.
 
	 */
 
	virtual void *MoveTo(const void *video, int x, int y) = 0;
 

	
 
	/**
 
	 * Draw a pixel with a given color on the video-buffer.
 
	 * @param video The destination pointer (video-buffer).
 
	 * @param x The x position within video-buffer.
 
	 * @param y The y position within video-buffer.
 
	 * @param color A 8bpp mapping color.
 
	 */
 
	virtual void SetPixel(void *video, int x, int y, uint8 color) = 0;
 

	
 
	/**
 
	 * Draw a pixel with a given color on the video-buffer if there is currently a black pixel.
 
	 * @param video The destination pointer (video-buffer).
 
	 * @param x The x position within video-buffer.
 
	 * @param y The y position within video-buffer.
 
	 * @param color A 8bpp mapping color.
 
	 */
 
	virtual void SetPixelIfEmpty(void *video, int x, int y, uint8 color) = 0;
 

	
 
	/**
 
	 * Make a single horizontal line in a single color on the video-buffer.
 
	 * @param video The destination pointer (video-buffer).
 
	 * @param width The lenght of the line.
 
	 * @param color A 8bpp mapping color.
 
	 */
 
	virtual void SetHorizontalLine(void *video, int width, uint8 color) = 0;
 

	
 
	/**
 
	 * Draw a line in which ever direction.
 
	 */
 
	virtual void DrawLine(void *video, int x, int y, int x2, int y2, uint8 color) = 0;
 

	
 
	/**
 
	 * Copy from a buffer to the screen.
 
	 * @param video The destionation pointer (video-buffer).
 
	 * @param src The buffer from which the data will be read.
 
	 * @param width The width of the buffer.
 
	 * @param height The height of the buffer.
 
	 * @param src_pitch The pitch (byte per line) of the source buffer.
 
	 */
 
	virtual void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch) = 0;
 

	
 
	/**
 
	 * Copy from the screen to a buffer.
 
	 * @param video The destination pointer (video-buffer).
 
	 * @param dst The buffer in which the data will be stored.
 
	 * @param width The width of the buffer.
 
	 * @param height The height of the buffer.
 
	 * @param dst_pitch The pitch (byte per line) of the destination buffer.
 
	 */
 
	virtual void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0;
 

	
 
	/**
 
	 * Move the videobuffer some places (via memmove).
 
	 * @param video_dst The destination pointer (video-buffer).
 
	 * @param video_src The source pointer (video-buffer).
 
	 * @param width The width of the buffer to move.
 
	 * @param height The height of the buffer to move.
 
	 */
 
	virtual void MoveBuffer(void *video_dst, const void *video_src, int width, int height) = 0;
 

	
 
	/**
 
	 * Calculate how much memory there is needed for an image of this size in the video-buffer.
 
	 * @param width The width of the buffer-to-be.
 
	 * @param height The height of the buffer-to-be.
 
	 * @return The size needed for the buffer.
 
	 */
 
	virtual int BufferSize(int width, int height) = 0;
 

	
 
	virtual ~Blitter() { }
 
};
 

	
 
#endif /* BLITTER_BASE_HPP */
src/blitter/blitter.hpp
Show inline comments
 
deleted file
src/blitter/factory.hpp
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
#ifndef BLITTER_FACTORY_HPP
 
#define BLITTER_FACTORY_HPP
 

	
 
#include "base.hpp"
 
#include <string>
 
#include <map>
 

	
 
/**
 
 * The base factory, keeping track of all blitters.
 
 */
 
class BlitterFactoryBase {
 
private:
 
	char *name;
 
	typedef std::map<std::string, BlitterFactoryBase *> Blitters;
 

	
 
	static Blitters &GetBlitters()
 
	{
 
		static Blitters &s_blitters = *new Blitters();
 
		return s_blitters;
 
	}
 

	
 
	static Blitter **GetActiveBlitter()
 
	{
 
		static Blitter *s_blitter = NULL;
 
		return &s_blitter;
 
	}
 

	
 
protected:
 
	/**
 
	 * Register a blitter internally, based on his name.
 
	 * @param name the name of the blitter.
 
	 * @note an assert() will be trigger if 2 blitters with the same name try to register.
 
	 */
 
	void RegisterBlitter(const char *name)
 
	{
 
		/* Don't register nameless Blitters */
 
		if (name == NULL) return;
 

	
 
		this->name = strdup(name);
 
		std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(name, this));
 
		assert(P.second);
 
	}
 

	
 
public:
 
	BlitterFactoryBase() :
 
		name(NULL)
 
	{}
 

	
 
	virtual ~BlitterFactoryBase() { if (this->name != NULL) GetBlitters().erase(this->name); free(this->name); }
 

	
 
	/**
 
	 * Find the requested blitter and return his class.
 
	 * @param name the blitter to select.
 
	 * @post Sets the blitter so GetCurrentBlitter() returns it too.
 
	 */
 
	static Blitter *SelectBlitter(const char *name)
 
	{
 
		if (GetBlitters().size() == 0) return NULL;
 

	
 
		Blitters::iterator it = GetBlitters().begin();
 
		for (; it != GetBlitters().end(); it++) {
 
			BlitterFactoryBase *b = (*it).second;
 
			if (strcasecmp(name, b->name) == 0) {
 
				Blitter *newb = b->CreateInstance();
 
				*GetActiveBlitter() = newb;
 
				return newb;
 
			}
 
		}
 
		return NULL;
 
	}
 

	
 
	/**
 
	 * Get the current active blitter (always set by calling SelectBlitter).
 
	 */
 
	static Blitter *GetCurrentBlitter()
 
	{
 
		return *GetActiveBlitter();
 
	}
 

	
 

	
 
	static char *GetBlittersInfo(char *p, const char *last)
 
	{
 
		p += snprintf(p, last - p, "List of blitters:\n");
 
		Blitters::iterator it = GetBlitters().begin();
 
		for (; it != GetBlitters().end(); it++) {
 
			BlitterFactoryBase *b = (*it).second;
 
			p += snprintf(p, last - p, "%18s: %s\n", b->name, b->GetDescription());
 
		}
 
		p += snprintf(p, last - p, "\n");
 

	
 
		return p;
 
	}
 

	
 
	/**
 
	 * Get a nice description of the blitter-class.
 
	 */
 
	virtual const char *GetDescription() = 0;
 

	
 
	/**
 
	 * Create an instance of this Blitter-class.
 
	 */
 
	virtual Blitter *CreateInstance() = 0;
 
};
 

	
 
/**
 
 * A template factory, so ->GetName() works correctly. This because else some compiler will complain.
 
 */
 
template <class T>
 
class BlitterFactory: public BlitterFactoryBase {
 
public:
 
	BlitterFactory() { this->RegisterBlitter(((T *)this)->GetName()); }
 

	
 
	/**
 
	 * Get the long, human readable, name for the Blitter-class.
 
	 */
 
	const char *GetName();
 
};
 

	
 
#endif /* BLITTER_FACTORY_HPP */
src/blitter/null.cpp
Show inline comments
 
#include "../stdafx.h"
 
#include "../zoom.hpp"
 
#include "../gfx.h"
 
#include "../functions.h"
 
#include "../variables.h"
 
#include "null.hpp"
 

	
 
static FBlitter_Null iFBlitter_Null;
 

	
 
void Blitter_Null::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
 
{
 
}
 

	
 
void Blitter_Null::DrawColorMappingRect(void *dst, int width, int height, int pal)
 
{
 
}
 

	
 
Sprite *Blitter_Null::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
 
{
 
	Sprite *dest_sprite;
src/blitter/null.hpp
Show inline comments
 
@@ -5,27 +5,30 @@
 
#ifndef BLITTER_NULL_HPP
 
#define BLITTER_NULL_HPP
 

	
 
#include "blitter.hpp"
 
#include "base.hpp"
 
#include "factory.hpp"
 

	
 
class Blitter_Null : public Blitter {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 0; }
 

	
 
	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 

	
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 

	
 
	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) {};
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal) {};
 
	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 

	
 
	/* virtual */ const char *GetRenderer() { return "null"; }
 
	/* virtual */ void *MoveTo(const void *video, int x, int y) { return NULL; };
 
	/* virtual */ void SetPixel(void *video, int x, int y, uint8 color) {};
 
	/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color) {};
 
	/* virtual */ void SetHorizontalLine(void *video, int width, uint8 color) {};
 
	/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, uint8 color) {};
 
	/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch) {};
 
	/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) {};
 
	/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height) {};
 
	/* virtual */ int BufferSize(int width, int height) { return 0; };
 
};
 

	
 
class FBlitter_Null: public BlitterFactory<FBlitter_Null> {
 
public:
 
	/* virtual */ const char *GetName() { return "null"; }
 

	
 
	/* virtual */ const char *GetDescription() { return "Null Blitter (does nothing)"; }
 

	
 
	/* virtual */ Blitter *CreateInstance() { return new Blitter_Null(); }
 
};
 

	
src/fontcache.cpp
Show inline comments
 
@@ -15,7 +15,7 @@
 
#include "fontcache.h"
 
#include "helpers.hpp"
 
#include "spriteloader/spriteloader.hpp"
 
#include "blitter/blitter.hpp"
 
#include "blitter/factory.hpp"
 

	
 
#ifdef WITH_FREETYPE
 

	
src/gfx.cpp
Show inline comments
 
@@ -19,7 +19,7 @@
 
#include "genworld.h"
 
#include "debug.h"
 
#include "zoom.hpp"
 
#include "blitter/blitter.hpp"
 
#include "blitter/factory.hpp"
 

	
 
#ifdef _DEBUG
 
bool _dbg_screen_rect;
 
@@ -60,6 +60,7 @@ static byte _dirty_blocks[DIRTY_BYTES_PE
 

	
 
void GfxScroll(int left, int top, int width, int height, int xo, int yo)
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	const void *src;
 
	void *dst;
 

	
 
@@ -70,8 +71,8 @@ void GfxScroll(int left, int top, int wi
 

	
 
	if (yo > 0) {
 
		/*Calculate pointers */
 
		dst = _screen.renderer->MoveTo(_screen.dst_ptr, left, top + height - 1);
 
		src = _screen.renderer->MoveTo(dst, 0, -yo);
 
		dst = blitter->MoveTo(_screen.dst_ptr, left, top + height - 1);
 
		src = blitter->MoveTo(dst, 0, -yo);
 

	
 
		/* Decrease height and increase top */
 
		top += yo;
 
@@ -80,20 +81,20 @@ void GfxScroll(int left, int top, int wi
 

	
 
		/* Adjust left & width */
 
		if (xo >= 0) {
 
			dst = _screen.renderer->MoveTo(dst, xo, 0);
 
			dst = blitter->MoveTo(dst, xo, 0);
 
			left += xo;
 
			width -= xo;
 
		} else {
 
			src = _screen.renderer->MoveTo(src, -xo, 0);
 
			src = blitter->MoveTo(src, -xo, 0);
 
			width += xo;
 
		}
 

	
 
		/* Negative height as we want to copy from bottom to top */
 
		_screen.renderer->CopyFromBuffer(dst, src, width, -height, _screen.pitch);
 
		blitter->CopyFromBuffer(dst, src, width, -height, _screen.pitch);
 
	} else {
 
		/* Calculate pointers */
 
		dst = _screen.renderer->MoveTo(_screen.dst_ptr, left, top);
 
		src = _screen.renderer->MoveTo(dst, 0, -yo);
 
		dst = blitter->MoveTo(_screen.dst_ptr, left, top);
 
		src = blitter->MoveTo(dst, 0, -yo);
 

	
 
		/* Decrese height. (yo is <=0). */
 
		height += yo;
 
@@ -101,17 +102,17 @@ void GfxScroll(int left, int top, int wi
 

	
 
		/* Adjust left & width */
 
		if (xo >= 0) {
 
			dst = _screen.renderer->MoveTo(dst, xo, 0);
 
			dst = blitter->MoveTo(dst, xo, 0);
 
			left += xo;
 
			width -= xo;
 
		} else {
 
			src = _screen.renderer->MoveTo(src, -xo, 0);
 
			src = blitter->MoveTo(src, -xo, 0);
 
			width += xo;
 
		}
 

	
 
		/* the y-displacement may be 0 therefore we have to use memmove,
 
		 * because source and destination may overlap */
 
		_screen.renderer->MoveBuffer(dst, src, width, height);
 
		blitter->MoveBuffer(dst, src, width, height);
 
	}
 
	/* This part of the screen is now dirty. */
 
	_video_driver->make_dirty(left, top, width, height);
 
@@ -120,6 +121,7 @@ void GfxScroll(int left, int top, int wi
 

	
 
void GfxFillRect(int left, int top, int right, int bottom, int color)
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	const DrawPixelInfo *dpi = _cur_dpi;
 
	void *dst;
 
	const int otop = top;
 
@@ -142,31 +144,33 @@ void GfxFillRect(int left, int top, int 
 
	bottom -= top;
 
	assert(bottom > 0);
 

	
 
	dst = _screen.renderer->MoveTo(dpi->dst_ptr, left, top);
 
	dst = blitter->MoveTo(dpi->dst_ptr, left, top);
 

	
 
	if (!HASBIT(color, PALETTE_MODIFIER_GREYOUT)) {
 
		if (!HASBIT(color, USE_COLORTABLE)) {
 
			do {
 
				_screen.renderer->SetHorizontalLine(dst, right, (uint8)color);
 
				dst = _screen.renderer->MoveTo(dst, 0, 1);
 
				blitter->SetHorizontalLine(dst, right, (uint8)color);
 
				dst = blitter->MoveTo(dst, 0, 1);
 
			} while (--bottom);
 
		} else {
 
			BlitterFactoryBase::GetCurrentBlitter()->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH));
 
			blitter->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH));
 
		}
 
	} else {
 
		byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
 
		do {
 
			for (int i = (bo ^= 1); i < right; i += 2) _screen.renderer->SetPixel(dst, i, 0, (uint8)color);
 
			dst = _screen.renderer->MoveTo(dst, 0, 1);
 
			for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)color);
 
			dst = blitter->MoveTo(dst, 0, 1);
 
		} while (--bottom > 0);
 
	}
 
}
 

	
 
static void GfxSetPixel(int x, int y, int color)
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	const DrawPixelInfo *dpi = _cur_dpi;
 

	
 
	if ((x -= dpi->left) < 0 || x >= dpi->width || (y -= dpi->top) < 0 || y >= dpi->height) return;
 
	_screen.renderer->SetPixel(dpi->dst_ptr, x, y, color);
 
	blitter->SetPixel(dpi->dst_ptr, x, y, color);
 
}
 

	
 
void GfxDrawLine(int x, int y, int x2, int y2, int color)
 
@@ -934,14 +938,16 @@ void ScreenSizeChanged()
 
void UndrawMouseCursor()
 
{
 
	if (_cursor.visible) {
 
		Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
		_cursor.visible = false;
 
		_screen.renderer->CopyFromBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
 
		_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
 
	}
 
}
 

	
 
void DrawMouseCursor()
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	int x;
 
	int y;
 
	int w;
 
@@ -978,10 +984,10 @@ void DrawMouseCursor()
 
	_cursor.draw_pos.y = y;
 
	_cursor.draw_size.y = h;
 

	
 
	assert(_screen.renderer->BufferSize(w, h) < (int)sizeof(_cursor_backup));
 
	assert(blitter->BufferSize(w, h) < (int)sizeof(_cursor_backup));
 

	
 
	/* Make backup of stuff below cursor */
 
	_screen.renderer->CopyToBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
 
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
 

	
 
	/* Draw cursor on screen */
 
	_cur_dpi = &_screen;
 
@@ -1171,6 +1177,7 @@ void MarkWholeScreenDirty()
 
 * get some nasty results */
 
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	const DrawPixelInfo *o = _cur_dpi;
 

	
 
	n->zoom = ZOOM_LVL_NORMAL;
 
@@ -1202,7 +1209,7 @@ bool FillDrawPixelInfo(DrawPixelInfo *n,
 
		n->top = 0;
 
	}
 

	
 
	n->dst_ptr = _screen.renderer->MoveTo(o->dst_ptr, left, top);
 
	n->dst_ptr = blitter->MoveTo(o->dst_ptr, left, top);
 
	n->pitch = o->pitch;
 

	
 
	if (height > o->height - top) {
src/gfx.h
Show inline comments
 
@@ -7,7 +7,6 @@
 

	
 
#include "openttd.h"
 
#include "zoom.hpp"
 
#include "renderer/renderer.hpp"
 

	
 
enum WindowKeyCodes {
 
	WKC_SHIFT = 0x8000,
 
@@ -138,7 +137,6 @@ struct DrawPixelInfo {
 
	int left, top, width, height;
 
	int pitch;
 
	ZoomLevel zoom;
 
	Renderer *renderer;
 
};
 

	
 
struct Colour {
src/openttd.cpp
Show inline comments
 
@@ -64,7 +64,7 @@
 
#include "newgrf_commons.h"
 
#include "player_face.h"
 
#include "group.h"
 
#include "blitter/blitter.hpp"
 
#include "blitter/factory.hpp"
 

	
 
#include "bridge_map.h"
 
#include "clear_map.h"
src/renderer/32bpp.cpp
Show inline comments
 
deleted file
src/renderer/32bpp.hpp
Show inline comments
 
deleted file
src/renderer/8bpp.cpp
Show inline comments
 
deleted file
src/renderer/8bpp.hpp
Show inline comments
 
deleted file
src/renderer/null.cpp
Show inline comments
 
deleted file
src/renderer/null.hpp
Show inline comments
 
deleted file
src/renderer/renderer.hpp
Show inline comments
 
deleted file
src/screenshot.cpp
Show inline comments
 
@@ -16,7 +16,7 @@
 
#include "date.h"
 
#include "string.h"
 
#include "helpers.hpp"
 
#include "blitter/blitter.hpp"
 
#include "blitter/factory.hpp"
 
#include "fileio.h"
 

	
 
char _screenshot_format_name[8];
 
@@ -483,8 +483,9 @@ void SetScreenshotFormat(int i)
 
/* screenshot generator that dumps the current video buffer */
 
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
 
{
 
	void *src = _screen.renderer->MoveTo(_screen.dst_ptr, 0, y);
 
	_screen.renderer->CopyToBuffer(src, buf, _screen.width, n, pitch);
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
 
	blitter->CopyToBuffer(src, buf, _screen.width, n, pitch);
 
}
 

	
 
/* generate a large piece of the world */
src/smallmap_gui.cpp
Show inline comments
 
@@ -25,6 +25,7 @@
 
#include "town.h"
 
#include "sound.h"
 
#include "variables.h"
 
#include "blitter/factory.hpp"
 

	
 
static const Widget _smallmap_widgets[] = {
 
{  WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
 
@@ -169,20 +170,24 @@ static const LegendAndColour * const _le
 

	
 
static inline void WRITE_PIXELS(void *d, uint32 val)
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	uint8 *val8 = (uint8 *)&val;
 
	_screen.renderer->SetPixel(d, 0, 0, val8[0]);
 
	_screen.renderer->SetPixel(d, 1, 0, val8[1]);
 
	_screen.renderer->SetPixel(d, 2, 0, val8[2]);
 
	_screen.renderer->SetPixel(d, 3, 0, val8[3]);
 

	
 
	blitter->SetPixel(d, 0, 0, val8[0]);
 
	blitter->SetPixel(d, 1, 0, val8[1]);
 
	blitter->SetPixel(d, 2, 0, val8[2]);
 
	blitter->SetPixel(d, 3, 0, val8[3]);
 
}
 

	
 
static inline void WRITE_PIXELS_OR(void *d, uint32 val)
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	uint8 *val8 = (uint8 *)&val;
 
	_screen.renderer->SetPixelIfEmpty(d, 0, 0, val8[0]);
 
	_screen.renderer->SetPixelIfEmpty(d, 1, 0, val8[1]);
 
	_screen.renderer->SetPixelIfEmpty(d, 2, 0, val8[2]);
 
	_screen.renderer->SetPixelIfEmpty(d, 3, 0, val8[3]);
 

	
 
	blitter->SetPixelIfEmpty(d, 0, 0, val8[0]);
 
	blitter->SetPixelIfEmpty(d, 1, 0, val8[1]);
 
	blitter->SetPixelIfEmpty(d, 2, 0, val8[2]);
 
	blitter->SetPixelIfEmpty(d, 3, 0, val8[3]);
 
}
 

	
 
#define MKCOLOR(x) TO_LE32X(x)
 
@@ -280,7 +285,8 @@ typedef uint32 GetSmallMapPixels(TileInd
 
 */
 
static void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
 
{
 
	void *dst_ptr_end = _screen.renderer->MoveTo(_screen.dst_ptr, _screen.width, _screen.height - 1);
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	void *dst_ptr_end = blitter->MoveTo(_screen.dst_ptr, _screen.width, _screen.height - 1);
 

	
 
	do {
 
		/* check if the tile (xc,yc) is within the map range */
 
@@ -290,7 +296,7 @@ static void DrawSmallMapStuff(void *dst,
 
				WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
 
		}
 
	/* switch to next tile in the column */
 
	} while (xc++, yc++, dst = _screen.renderer->MoveTo(dst, pitch, 0), --reps != 0);
 
	} while (xc++, yc++, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
 
}
 

	
 

	
 
@@ -510,6 +516,7 @@ static void DrawHorizMapIndicator(int x,
 
 */
 
static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_towns)
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	DrawPixelInfo *old_dpi;
 
	int dx,dy, x, y, x2, y2;
 
	void *ptr;
 
@@ -564,7 +571,7 @@ static void DrawSmallMap(DrawPixelInfo *
 
		}
 
	}
 

	
 
	ptr = _screen.renderer->MoveTo(dpi->dst_ptr, -dx - 4, 0);
 
	ptr = blitter->MoveTo(dpi->dst_ptr, -dx - 4, 0);
 
	x = - dx - 4;
 
	y = 0;
 

	
 
@@ -598,13 +605,13 @@ skip_column:
 
		if (y == 0) {
 
			tile_y++;
 
			y++;
 
			ptr = _screen.renderer->MoveTo(ptr, 0, 1);
 
			ptr = blitter->MoveTo(ptr, 0, 1);
 
		} else {
 
			tile_x--;
 
			y--;
 
			ptr = _screen.renderer->MoveTo(ptr, 0, -1);
 
			ptr = blitter->MoveTo(ptr, 0, -1);
 
		}
 
		ptr = _screen.renderer->MoveTo(ptr, 2, 0);
 
		ptr = blitter->MoveTo(ptr, 2, 0);
 
		x += 2;
 
	}
 

	
 
@@ -650,8 +657,8 @@ skip_column:
 
				color = (type == 1) ? _vehicle_type_colors[v->type] : 0xF;
 

	
 
				/* And draw either one or two pixels depending on clipping */
 
				_screen.renderer->SetPixel(dpi->dst_ptr, x, y, color);
 
				if (!skip) _screen.renderer->SetPixel(dpi->dst_ptr, x + 1, y, color);;
 
				blitter->SetPixel(dpi->dst_ptr, x, y, color);
 
				if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, color);
 
			}
 
		}
 
	}
src/spritecache.cpp
Show inline comments
 
@@ -17,7 +17,7 @@
 
#ifdef WITH_PNG
 
#include "spriteloader/png.hpp"
 
#endif /* WITH_PNG */
 
#include "blitter/blitter.hpp"
 
#include "blitter/factory.hpp"
 

	
 
/* Default of 4MB spritecache */
 
uint _sprite_cache_size = 4;
src/texteff.cpp
Show inline comments
 
@@ -16,6 +16,7 @@
 
#include "string.h"
 
#include "variables.h"
 
#include "table/sprites.h"
 
#include "blitter/factory.hpp"
 
#include <stdarg.h> /* va_list */
 
#include "date.h"
 

	
 
@@ -126,6 +127,7 @@ void InitTextMessage()
 
void UndrawTextMessage()
 
{
 
	if (_textmessage_visible) {
 
		Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
		/* Sometimes we also need to hide the cursor
 
		 *   This is because both textmessage and the cursor take a shot of the
 
		 *   screen before drawing.
 
@@ -161,7 +163,7 @@ void UndrawTextMessage()
 

	
 
		_textmessage_visible = false;
 
		/* Put our 'shot' back to the screen */
 
		_screen.renderer->CopyFromBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
 
		/* And make sure it is updated next time */
 
		_video_driver->make_dirty(x, y, width, height);
 

	
 
@@ -196,6 +198,7 @@ void TextMessageDailyLoop()
 
/** Draw the textmessage-box */
 
void DrawTextMessage()
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	if (!_textmessage_dirty) return;
 

	
 
	/* First undraw if needed */
 
@@ -221,7 +224,7 @@ void DrawTextMessage()
 
	if (width <= 0 || height <= 0) return;
 

	
 
	/* Make a copy of the screen as it is before painting (for undraw) */
 
	_screen.renderer->CopyToBuffer(_screen.renderer->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
 
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
 

	
 
	_cur_dpi = &_screen; // switch to _screen painting
 

	
src/video/cocoa_v.mm
Show inline comments
 
@@ -1763,9 +1763,6 @@ static void QZ_VideoInit()
 

	
 
	_cocoa_video_data.cursor_visible = true;
 

	
 
	_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 
	if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 

	
 
	/* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
 
//	QZ_RegisterForSleepNotifications();
 
}
src/video/dedicated_v.cpp
Show inline comments
 
@@ -14,7 +14,7 @@
 
#include "../variables.h"
 
#include "../genworld.h"
 
#include "../fileio.h"
 
#include "../blitter/blitter.hpp"
 
#include "../blitter/factory.hpp"
 
#include "dedicated_v.h"
 

	
 
#ifdef BEOS_NET_SERVER
 
@@ -128,8 +128,6 @@ static const char *DedicatedVideoStart(c
 

	
 
	_screen.width = _screen.pitch = _cur_resolution[0];
 
	_screen.height = _cur_resolution[1];
 
	_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 
	if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 

	
 
	SetDebugString("net=6");
 

	
src/video/null_v.cpp
Show inline comments
 
@@ -6,7 +6,7 @@
 
#include "../variables.h"
 
#include "../window.h"
 
#include "../debug.h"
 
#include "../blitter/blitter.hpp"
 
#include "../blitter/factory.hpp"
 
#include "null_v.h"
 

	
 
static const char* NullVideoStart(const char* const* parm)
 
@@ -16,8 +16,6 @@ static const char* NullVideoStart(const 
 
	/* Do not render, nor blit */
 
	DEBUG(misc, 1, "Forcing blitter 'null'...");
 
	BlitterFactoryBase::SelectBlitter("null");
 
	_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 
	if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 
	return NULL;
 
}
 

	
src/video/sdl_v.cpp
Show inline comments
 
@@ -13,8 +13,7 @@
 
#include "../window.h"
 
#include "../network/network.h"
 
#include "../variables.h"
 
#include "../blitter/blitter.hpp"
 
#include "../renderer/renderer.hpp"
 
#include "../blitter/factory.hpp"
 
#include "sdl_v.h"
 
#include <SDL.h>
 

	
 
@@ -205,8 +204,6 @@ static bool CreateMainSurface(int w, int
 
	_screen.width = newscreen->w;
 
	_screen.height = newscreen->h;
 
	_screen.pitch = newscreen->pitch / (bpp / 8);
 
	_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 
	if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 
	_sdl_screen = newscreen;
 
	InitPalette();
 

	
src/video/win32_v.cpp
Show inline comments
 
@@ -653,8 +653,6 @@ static bool AllocateDibSection(int w, in
 
	_screen.width = w;
 
	_screen.pitch = ALIGN(w, 4);
 
	_screen.height = h;
 
	_screen.renderer = RendererFactoryBase::SelectRenderer(BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 
	if (_screen.renderer == NULL) error("Couldn't load the renderer '%s' the selected blitter depends on", BlitterFactoryBase::GetCurrentBlitter()->GetRenderer());
 
	bi = (BITMAPINFO*)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
 
	memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
 
	bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
src/viewport.cpp
Show inline comments
 
@@ -24,6 +24,7 @@
 
#include "variables.h"
 
#include "train.h"
 
#include "roadveh.h"
 
#include "blitter/factory.hpp"
 

	
 
#define VIEWPORT_DRAW_MEM (65536 * 2)
 

	
 
@@ -1269,7 +1270,7 @@ void ViewportDoDraw(const ViewPort *vp, 
 
	x = UnScaleByZoom(vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left;
 
	y = UnScaleByZoom(vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
 

	
 
	vd.dpi.dst_ptr = _screen.renderer->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
 
	vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
 

	
 
	vd.parent_list = parent_list;
 
	vd.eof_parent_list = endof(parent_list);
src/window.cpp
Show inline comments
 
@@ -17,6 +17,7 @@
 
#include "table/sprites.h"
 
#include "genworld.h"
 
#include "helpers.hpp"
 
#include "blitter/factory.hpp"
 

	
 
/* delta between mouse cursor and upper left corner of dragged window */
 
static Point _drag_delta;
 
@@ -270,7 +271,7 @@ static void DrawOverlappedWindow(Window*
 
		dp->left = left - (*wz)->left;
 
		dp->top = top - (*wz)->top;
 
		dp->pitch = _screen.pitch;
 
		dp->dst_ptr = _screen.renderer->MoveTo(_screen.dst_ptr, left, top);
 
		dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
 
		dp->zoom = ZOOM_LVL_NORMAL;
 
		CallWindowEventNP(*wz, WE_PAINT);
 
	}
0 comments (0 inline, 0 general)