(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
authortruelight
Sun, 17 Jun 2007 20:30:28 +0000
changeset 7433 8e410e7ec0d7
parent 7432 2c1075bc97d3
child 7434 062b9e494412
(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
projects/generate
projects/openttd.vcproj
projects/openttd_vs80.vcproj
source.list
src/blitter/32bpp_base.cpp
src/blitter/32bpp_base.hpp
src/blitter/32bpp_simple.cpp
src/blitter/32bpp_simple.hpp
src/blitter/8bpp_base.cpp
src/blitter/8bpp_base.hpp
src/blitter/8bpp_debug.cpp
src/blitter/8bpp_debug.hpp
src/blitter/8bpp_optimized.cpp
src/blitter/8bpp_optimized.hpp
src/blitter/8bpp_simple.cpp
src/blitter/8bpp_simple.hpp
src/blitter/base.hpp
src/blitter/blitter.hpp
src/blitter/factory.hpp
src/blitter/null.cpp
src/blitter/null.hpp
src/fontcache.cpp
src/gfx.cpp
src/gfx.h
src/openttd.cpp
src/renderer/32bpp.cpp
src/renderer/32bpp.hpp
src/renderer/8bpp.cpp
src/renderer/8bpp.hpp
src/renderer/null.cpp
src/renderer/null.hpp
src/renderer/renderer.hpp
src/screenshot.cpp
src/smallmap_gui.cpp
src/spritecache.cpp
src/texteff.cpp
src/video/cocoa_v.mm
src/video/dedicated_v.cpp
src/video/null_v.cpp
src/video/sdl_v.cpp
src/video/win32_v.cpp
src/viewport.cpp
src/window.cpp
--- a/projects/generate	Sun Jun 17 20:14:38 2007 +0000
+++ b/projects/generate	Sun Jun 17 20:30:28 2007 +0000
@@ -40,7 +40,7 @@
 
 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 ""
--- a/projects/openttd.vcproj	Sun Jun 17 20:14:38 2007 +0000
+++ b/projects/openttd.vcproj	Sun Jun 17 20:30:28 2007 +0000
@@ -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
--- a/projects/openttd_vs80.vcproj	Sun Jun 17 20:14:38 2007 +0000
+++ b/projects/openttd_vs80.vcproj	Sun Jun 17 20:30:28 2007 +0000
@@ -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
--- a/source.list	Sun Jun 17 20:14:38 2007 +0000
+++ b/source.list	Sun Jun 17 20:30:28 2007 +0000
@@ -293,15 +293,20 @@
 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 @@
 #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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/blitter/32bpp_base.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -0,0 +1,125 @@
+#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);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/blitter/32bpp_base.hpp	Sun Jun 17 20:30:28 2007 +0000
@@ -0,0 +1,33 @@
+/* $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 */
--- a/src/blitter/32bpp_simple.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/32bpp_simple.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 @@
 					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 @@
 	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);
--- a/src/blitter/32bpp_simple.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/32bpp_simple.hpp	Sun Jun 17 20:30:28 2007 +0000
@@ -5,27 +5,20 @@
 #ifndef BLITTER_32BPP_SIMPLE_HPP
 #define BLITTER_32BPP_SIMPLE_HPP
 
-#include "blitter.hpp"
-
-class Blitter_32bppSimple : public Blitter {
-public:
-	/* virtual */ uint8 GetScreenDepth() { return 32; }
+#include "32bpp_base.hpp"
+#include "factory.hpp"
 
+class Blitter_32bppSimple : public Blitter_32bppBase {
+public:
 	/* 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(); }
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/blitter/8bpp_base.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -0,0 +1,129 @@
+#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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/blitter/8bpp_base.hpp	Sun Jun 17 20:30:28 2007 +0000
@@ -0,0 +1,27 @@
+/* $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 */
--- a/src/blitter/8bpp_debug.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/8bpp_debug.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -35,16 +35,6 @@
 	}
 }
 
-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;
--- a/src/blitter/8bpp_debug.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/8bpp_debug.hpp	Sun Jun 17 20:30:28 2007 +0000
@@ -5,27 +5,19 @@
 #ifndef BLITTER_8BPP_DEBUG_HPP
 #define BLITTER_8BPP_DEBUG_HPP
 
-#include "blitter.hpp"
-
-class Blitter_8bppDebug : public Blitter {
-public:
-	/* virtual */ uint8 GetScreenDepth() { return 8; }
+#include "8bpp_base.hpp"
+#include "factory.hpp"
 
+class Blitter_8bppDebug : public Blitter_8bppBase {
+public:
 	/* 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(); }
 };
 
--- a/src/blitter/8bpp_optimized.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/8bpp_optimized.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -102,16 +102,6 @@
 	}
 }
 
-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;
--- a/src/blitter/8bpp_optimized.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/8bpp_optimized.hpp	Sun Jun 17 20:30:28 2007 +0000
@@ -5,27 +5,19 @@
 #ifndef BLITTER_8BPP_OPTIMIZED_HPP
 #define BLITTER_8BPP_OPTIMIZED_HPP
 
-#include "blitter.hpp"
-
-class Blitter_8bppOptimized : public Blitter {
-public:
-	/* virtual */ uint8 GetScreenDepth() { return 8; }
+#include "8bpp_base.hpp"
+#include "factory.hpp"
 
+class Blitter_8bppOptimized : public Blitter_8bppBase {
+public:
 	/* 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(); }
 };
 
--- a/src/blitter/8bpp_simple.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/8bpp_simple.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -48,16 +48,6 @@
 	}
 }
 
-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;
--- a/src/blitter/8bpp_simple.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/8bpp_simple.hpp	Sun Jun 17 20:30:28 2007 +0000
@@ -5,27 +5,19 @@
 #ifndef BLITTER_8BPP_SIMPLE_HPP
 #define BLITTER_8BPP_SIMPLE_HPP
 
-#include "blitter.hpp"
-
-class Blitter_8bppSimple : public Blitter {
-public:
-	/* virtual */ uint8 GetScreenDepth() { return 8; }
+#include "8bpp_base.hpp"
+#include "factory.hpp"
 
+class Blitter_8bppSimple : public Blitter_8bppBase {
+public:
 	/* 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(); }
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/blitter/base.hpp	Sun Jun 17 20:30:28 2007 +0000
@@ -0,0 +1,144 @@
+/* $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 */
--- a/src/blitter/blitter.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,186 +0,0 @@
-/* $Id$ */
-
-/** @file blitter.hpp */
-
-#ifndef BLITTER_HPP
-#define BLITTER_HPP
-
-#include "../spriteloader/spriteloader.hpp"
-#include "../spritecache.h"
-#include <string>
-#include <map>
-
-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;
-
-	/**
-	 * Get the renderer this class depends on.
-	 */
-	virtual const char *GetRenderer() = 0;
-
-	virtual ~Blitter() { }
-};
-
-/**
- * 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_HPP */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/blitter/factory.hpp	Sun Jun 17 20:30:28 2007 +0000
@@ -0,0 +1,121 @@
+/* $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 */
--- a/src/blitter/null.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/null.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -1,19 +1,9 @@
 #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;
--- a/src/blitter/null.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/blitter/null.hpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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(); }
 };
 
--- a/src/fontcache.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/fontcache.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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
 
--- a/src/gfx.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/gfx.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 @@
 
 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 @@
 
 	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 @@
 
 		/* 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 @@
 
 		/* 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 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 @@
 	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 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 @@
 	_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 @@
  * 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 @@
 		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) {
--- a/src/gfx.h	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/gfx.h	Sun Jun 17 20:30:28 2007 +0000
@@ -7,7 +7,6 @@
 
 #include "openttd.h"
 #include "zoom.hpp"
-#include "renderer/renderer.hpp"
 
 enum WindowKeyCodes {
 	WKC_SHIFT = 0x8000,
@@ -138,7 +137,6 @@
 	int left, top, width, height;
 	int pitch;
 	ZoomLevel zoom;
-	Renderer *renderer;
 };
 
 struct Colour {
--- a/src/openttd.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/openttd.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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"
--- a/src/renderer/32bpp.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-#include "../stdafx.h"
-#include "../gfx.h"
-#include "32bpp.hpp"
-
-static FRenderer_32bpp iFRenderer_32bpp;
-
-void *Renderer_32bpp::MoveTo(const void *video, int x, int y)
-{
-	return (uint32 *)video + x + y * _screen.pitch;
-}
-
-void Renderer_32bpp::SetPixel(void *video, int x, int y, uint8 color)
-{
-	*((uint32 *)video + x + y * _screen.pitch) = LookupColourInPalette(color);
-}
-
-void Renderer_32bpp::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
-{
-	uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
-	if (*dst == 0) *dst = LookupColourInPalette(color);
-}
-
-void Renderer_32bpp::SetHorizontalLine(void *video, int width, uint8 color)
-{
-	uint32 *dst = (uint32 *)video;
-	uint32 color32 = LookupColourInPalette(color);
-
-	for (; width > 0; width--) {
-		*dst = color32;
-		dst++;
-	}
-}
-
-void Renderer_32bpp::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 Renderer_32bpp::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 Renderer_32bpp::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 Renderer_32bpp::BufferSize(int width, int height)
-{
-	return width * height * sizeof(uint32);
-}
--- a/src/renderer/32bpp.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/* $Id$ */
-
-/** @file 32bpp.hpp */
-
-#ifndef RENDERER_32BPP_HPP
-#define RENDERER_32BPP_HPP
-
-#include "renderer.hpp"
-
-class Renderer_32bpp : public Renderer {
-public:
-	/* 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 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);
-	}
-};
-
-class FRenderer_32bpp: public RendererFactory<FRenderer_32bpp> {
-public:
-	/* virtual */ const char *GetName() { return "32bpp"; }
-
-	/* virtual */ Renderer *CreateInstance() { return new Renderer_32bpp(); }
-};
-
-#endif /* RENDERER_32BPP_HPP */
--- a/src/renderer/8bpp.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-#include "../stdafx.h"
-#include "../gfx.h"
-#include "8bpp.hpp"
-
-static FRenderer_8bpp iFRenderer_8bpp;
-
-void *Renderer_8bpp::MoveTo(const void *video, int x, int y)
-{
-	return (uint8 *)video + x + y * _screen.pitch;
-}
-
-void Renderer_8bpp::SetPixel(void *video, int x, int y, uint8 color)
-{
-	*((uint8 *)video + x + y * _screen.pitch) = color;
-}
-
-void Renderer_8bpp::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
-{
-	uint8 *dst = (uint8 *)video + x + y * _screen.pitch;
-	if (*dst == 0) *dst = color;
-}
-
-void Renderer_8bpp::SetHorizontalLine(void *video, int width, uint8 color)
-{
-	memset(video, color, width);
-}
-
-void Renderer_8bpp::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 Renderer_8bpp::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 Renderer_8bpp::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 Renderer_8bpp::BufferSize(int width, int height)
-{
-	return width * height;
-}
--- a/src/renderer/8bpp.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/* $Id$ */
-
-/** @file 8bpp.hpp */
-
-#ifndef RENDERER_8BPP_HPP
-#define RENDERER_8BPP_HPP
-
-#include "renderer.hpp"
-
-class Renderer_8bpp : public Renderer {
-public:
-	/* 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 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);
-};
-
-class FRenderer_8bpp: public RendererFactory<FRenderer_8bpp> {
-public:
-	/* virtual */ const char *GetName() { return "8bpp"; }
-
-	/* virtual */ Renderer *CreateInstance() { return new Renderer_8bpp(); }
-};
-
-#endif /* RENDERER_8BPP_HPP */
--- a/src/renderer/null.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-#include "../stdafx.h"
-#include "../gfx.h"
-#include "null.hpp"
-
-static FRenderer_Null iFRenderer_Null;
-
-void *Renderer_Null::MoveTo(const void *video, int x, int y)
-{
-	return NULL;
-}
-
-void Renderer_Null::SetPixel(void *video, int x, int y, uint8 color)
-{
-}
-
-void Renderer_Null::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
-{
-}
-
-void Renderer_Null::SetHorizontalLine(void *video, int width, uint8 color)
-{
-}
-
-void Renderer_Null::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
-{
-}
-
-void Renderer_Null::CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
-{
-}
-
-void Renderer_Null::MoveBuffer(void *video_dst, const void *video_src, int width, int height)
-{
-}
-
-int Renderer_Null::BufferSize(int width, int height)
-{
-	return 0;
-}
--- a/src/renderer/null.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/* $Id$ */
-
-/** @file null.hpp */
-
-#ifndef RENDERER_NULL_HPP
-#define RENDERER_NULL_HPP
-
-#include "renderer.hpp"
-
-class Renderer_Null : public Renderer {
-public:
-	/* 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 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);
-};
-
-class FRenderer_Null: public RendererFactory<FRenderer_Null> {
-public:
-	/* virtual */ const char *GetName() { return "null"; }
-
-	/* virtual */ Renderer *CreateInstance() { return new Renderer_Null(); }
-};
-
-#endif /* RENDERER_NULL_HPP */
--- a/src/renderer/renderer.hpp	Sun Jun 17 20:14:38 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,165 +0,0 @@
-/* $Id$ */
-
-/** @file renderer.hpp */
-
-#ifndef RENDERER_HPP
-#define RENDERER_HPP
-
-#include <string>
-#include <map>
-
-class Renderer {
-public:
-	virtual ~Renderer() { }
-
-	/**
-	 * 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;
-
-	/**
-	 * 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;
-};
-
-/**
- * The factory, keeping track of all renderers.
- */
-class RendererFactoryBase {
-private:
-	char *name;
-	typedef std::map<std::string, RendererFactoryBase *> Renderers;
-
-	static Renderers &GetRenderers()
-	{
-		static Renderers &s_renderers = *new Renderers();
-		return s_renderers;
-	}
-
-protected:
-	/**
-	 * Register a renderer internally, based on his bpp.
-	 * @param name the name of the renderer.
-	 * @note an assert() will be trigger if 2 renderers with the same bpp try to register.
-	 */
-	void RegisterRenderer(const char *name)
-	{
-		/* Don't register nameless Renderers */
-		if (name == NULL) return;
-
-		this->name = strdup(name);
-		std::pair<Renderers::iterator, bool> P = GetRenderers().insert(Renderers::value_type(name, this));
-		assert(P.second);
-	}
-
-public:
-	RendererFactoryBase() :
-		name(NULL)
-	{ }
-
-	virtual ~RendererFactoryBase() { if (this->name != NULL) GetRenderers().erase(this->name); free(this->name); }
-
-	/**
-	 * Find the requested renderer and return his class-instance.
-	 * @param name the renderer to select.
-	 */
-	static Renderer *SelectRenderer(const char *name)
-	{
-		if (GetRenderers().size() == 0) return NULL;
-
-		Renderers::iterator it = GetRenderers().begin();
-		for (; it != GetRenderers().end(); it++) {
-			RendererFactoryBase *r = (*it).second;
-			if (strcasecmp(name, r->name) == 0) {
-				return r->CreateInstance();
-			}
-		}
-		return NULL;
-	}
-
-	/**
-	 * Create an instance of this Renderer-class.
-	 */
-	virtual Renderer *CreateInstance() = 0;
-};
-
-/**
- * A template factory, so ->GetBpp() works correctly. This because else some compiler will complain.
- */
-template <class T>
-class RendererFactory: public RendererFactoryBase {
-public:
-	RendererFactory() { this->RegisterRenderer(((T *)this)->GetName()); }
-
-	/**
-	 * Get the name for this renderer.
-	 */
-	const char *GetName();
-};
-
-
-#endif /* RENDERER_HPP */
--- a/src/screenshot.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/screenshot.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 @@
 /* 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 */
--- a/src/smallmap_gui.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/smallmap_gui.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 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 @@
  */
 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 @@
 				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 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 @@
 		}
 	}
 
-	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 @@
 		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 @@
 				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);
 			}
 		}
 	}
--- a/src/spritecache.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/spritecache.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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;
--- a/src/texteff.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/texteff.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 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 @@
 
 		_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 @@
 /** Draw the textmessage-box */
 void DrawTextMessage()
 {
+	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 	if (!_textmessage_dirty) return;
 
 	/* First undraw if needed */
@@ -221,7 +224,7 @@
 	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
 
--- a/src/video/cocoa_v.mm	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/video/cocoa_v.mm	Sun Jun 17 20:30:28 2007 +0000
@@ -1763,9 +1763,6 @@
 
 	_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();
 }
--- a/src/video/dedicated_v.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/video/dedicated_v.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 @@
 
 	_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");
 
--- a/src/video/null_v.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/video/null_v.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 @@
 	/* 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;
 }
 
--- a/src/video/sdl_v.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/video/sdl_v.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 @@
 	_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();
 
--- a/src/video/win32_v.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/video/win32_v.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -653,8 +653,6 @@
 	_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);
--- a/src/viewport.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/viewport.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 @@
 	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);
--- a/src/window.cpp	Sun Jun 17 20:14:38 2007 +0000
+++ b/src/window.cpp	Sun Jun 17 20:30:28 2007 +0000
@@ -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 @@
 		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);
 	}