summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-06-17 20:30:28 +0000
committertruelight <truelight@openttd.org>2007-06-17 20:30:28 +0000
commit003375d3755fe06227894e941b177491770c17fe (patch)
treee0105857aa1562ca3ca15a5e7df7e49bfc939456 /src
parentb0b4820387ec6f0214b43dc61b452fa73ca8a09a (diff)
downloadopenttd-003375d3755fe06227894e941b177491770c17fe.tar.xz
(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
Diffstat (limited to 'src')
-rw-r--r--src/blitter/32bpp_base.cpp125
-rw-r--r--src/blitter/32bpp_base.hpp (renamed from src/renderer/32bpp.hpp)24
-rw-r--r--src/blitter/32bpp_simple.cpp5
-rw-r--r--src/blitter/32bpp_simple.hpp13
-rw-r--r--src/blitter/8bpp_base.cpp129
-rw-r--r--src/blitter/8bpp_base.hpp (renamed from src/renderer/8bpp.hpp)24
-rw-r--r--src/blitter/8bpp_debug.cpp10
-rw-r--r--src/blitter/8bpp_debug.hpp14
-rw-r--r--src/blitter/8bpp_optimized.cpp10
-rw-r--r--src/blitter/8bpp_optimized.hpp14
-rw-r--r--src/blitter/8bpp_simple.cpp10
-rw-r--r--src/blitter/8bpp_simple.hpp14
-rw-r--r--src/blitter/base.hpp (renamed from src/renderer/renderer.hpp)145
-rw-r--r--src/blitter/factory.hpp (renamed from src/blitter/blitter.hpp)73
-rw-r--r--src/blitter/null.cpp12
-rw-r--r--src/blitter/null.hpp23
-rw-r--r--src/fontcache.cpp2
-rw-r--r--src/gfx.cpp51
-rw-r--r--src/gfx.h2
-rw-r--r--src/openttd.cpp2
-rw-r--r--src/renderer/32bpp.cpp77
-rw-r--r--src/renderer/8bpp.cpp71
-rw-r--r--src/renderer/null.cpp39
-rw-r--r--src/renderer/null.hpp29
-rw-r--r--src/screenshot.cpp7
-rw-r--r--src/smallmap_gui.cpp39
-rw-r--r--src/spritecache.cpp2
-rw-r--r--src/texteff.cpp7
-rw-r--r--src/video/cocoa_v.mm3
-rw-r--r--src/video/dedicated_v.cpp4
-rw-r--r--src/video/null_v.cpp4
-rw-r--r--src/video/sdl_v.cpp5
-rw-r--r--src/video/win32_v.cpp2
-rw-r--r--src/viewport.cpp3
-rw-r--r--src/window.cpp3
35 files changed, 441 insertions, 556 deletions
diff --git a/src/blitter/32bpp_base.cpp b/src/blitter/32bpp_base.cpp
new file mode 100644
index 000000000..a3211a02a
--- /dev/null
+++ b/src/blitter/32bpp_base.cpp
@@ -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);
+}
diff --git a/src/renderer/32bpp.hpp b/src/blitter/32bpp_base.hpp
index 7f0283754..85ce07062 100644
--- a/src/renderer/32bpp.hpp
+++ b/src/blitter/32bpp_base.hpp
@@ -1,18 +1,23 @@
/* $Id$ */
-/** @file 32bpp.hpp */
+/** @file 32bpp_base.hpp */
-#ifndef RENDERER_32BPP_HPP
-#define RENDERER_32BPP_HPP
+#ifndef BLITTER_32BPP_BASE_HPP
+#define BLITTER_32BPP_BASE_HPP
-#include "renderer.hpp"
+#include "base.hpp"
-class Renderer_32bpp : public Renderer {
+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);
@@ -25,11 +30,4 @@ public:
}
};
-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 */
+#endif /* BLITTER_32BPP_BASE_HPP */
diff --git a/src/blitter/32bpp_simple.cpp b/src/blitter/32bpp_simple.cpp
index c858736cf..3dc5ee096 100644
--- a/src/blitter/32bpp_simple.cpp
+++ b/src/blitter/32bpp_simple.cpp
@@ -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::BlitterParams *bp, BlitterMode mode, Zoo
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(SpriteLoader::Sprite *sprite, Blitter::Alloc
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);
diff --git a/src/blitter/32bpp_simple.hpp b/src/blitter/32bpp_simple.hpp
index cafaaab00..a8d6d1d58 100644
--- a/src/blitter/32bpp_simple.hpp
+++ b/src/blitter/32bpp_simple.hpp
@@ -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(); }
};
diff --git a/src/blitter/8bpp_base.cpp b/src/blitter/8bpp_base.cpp
new file mode 100644
index 000000000..e745ee627
--- /dev/null
+++ b/src/blitter/8bpp_base.cpp
@@ -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;
+}
diff --git a/src/renderer/8bpp.hpp b/src/blitter/8bpp_base.hpp
index a8bb27a48..7ed862ca0 100644
--- a/src/renderer/8bpp.hpp
+++ b/src/blitter/8bpp_base.hpp
@@ -1,29 +1,27 @@
/* $Id$ */
-/** @file 8bpp.hpp */
+/** @file 8bpp_base.hpp */
-#ifndef RENDERER_8BPP_HPP
-#define RENDERER_8BPP_HPP
+#ifndef BLITTER_8BPP_BASE_HPP
+#define BLITTER_8BPP_BASE_HPP
-#include "renderer.hpp"
+#include "base.hpp"
-class Renderer_8bpp : public Renderer {
+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);
};
-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 */
+#endif /* BLITTER_8BPP_BASE_HPP */
diff --git a/src/blitter/8bpp_debug.cpp b/src/blitter/8bpp_debug.cpp
index e1ad988d3..3a9b52d2a 100644
--- a/src/blitter/8bpp_debug.cpp
+++ b/src/blitter/8bpp_debug.cpp
@@ -35,16 +35,6 @@ void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL
}
}
-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;
diff --git a/src/blitter/8bpp_debug.hpp b/src/blitter/8bpp_debug.hpp
index d3b52988b..9fd2a2d8e 100644
--- a/src/blitter/8bpp_debug.hpp
+++ b/src/blitter/8bpp_debug.hpp
@@ -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(); }
};
diff --git a/src/blitter/8bpp_optimized.cpp b/src/blitter/8bpp_optimized.cpp
index 09c5886f0..9af922e30 100644
--- a/src/blitter/8bpp_optimized.cpp
+++ b/src/blitter/8bpp_optimized.cpp
@@ -102,16 +102,6 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
}
}
-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;
diff --git a/src/blitter/8bpp_optimized.hpp b/src/blitter/8bpp_optimized.hpp
index 0c9cb2dee..bbade0080 100644
--- a/src/blitter/8bpp_optimized.hpp
+++ b/src/blitter/8bpp_optimized.hpp
@@ -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(); }
};
diff --git a/src/blitter/8bpp_simple.cpp b/src/blitter/8bpp_simple.cpp
index 47ebe8fc4..010066f8a 100644
--- a/src/blitter/8bpp_simple.cpp
+++ b/src/blitter/8bpp_simple.cpp
@@ -48,16 +48,6 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom
}
}
-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;
diff --git a/src/blitter/8bpp_simple.hpp b/src/blitter/8bpp_simple.hpp
index 2c848d7c1..589df29f3 100644
--- a/src/blitter/8bpp_simple.hpp
+++ b/src/blitter/8bpp_simple.hpp
@@ -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(); }
};
diff --git a/src/renderer/renderer.hpp b/src/blitter/base.hpp
index 7b7ad0f4f..66550d42d 100644
--- a/src/renderer/renderer.hpp
+++ b/src/blitter/base.hpp
@@ -1,16 +1,64 @@
/* $Id$ */
-/** @file renderer.hpp */
+#ifndef BLITTER_BASE_HPP
+#define BLITTER_BASE_HPP
-#ifndef RENDERER_HPP
-#define RENDERER_HPP
+#include "../spritecache.h"
+#include "../spriteloader/spriteloader.hpp"
-#include <string>
-#include <map>
+enum BlitterMode {
+ BM_NORMAL,
+ BM_COLOUR_REMAP,
+ BM_TRANSPARENT,
+};
-class Renderer {
+/**
+ * How all blitters should look like. Extend this class to make your own.
+ */
+class Blitter {
public:
- virtual ~Renderer() { }
+ 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
@@ -49,6 +97,11 @@ public:
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.
@@ -84,82 +137,8 @@ public:
* @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;
+ virtual ~Blitter() { }
};
-/**
- * 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 */
+#endif /* BLITTER_BASE_HPP */
diff --git a/src/blitter/blitter.hpp b/src/blitter/factory.hpp
index 175533df6..a55250071 100644
--- a/src/blitter/blitter.hpp
+++ b/src/blitter/factory.hpp
@@ -1,77 +1,12 @@
/* $Id$ */
-/** @file blitter.hpp */
+#ifndef BLITTER_FACTORY_HPP
+#define BLITTER_FACTORY_HPP
-#ifndef BLITTER_HPP
-#define BLITTER_HPP
-
-#include "../spriteloader/spriteloader.hpp"
-#include "../spritecache.h"
+#include "base.hpp"
#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.
*/
@@ -183,4 +118,4 @@ public:
const char *GetName();
};
-#endif /* BLITTER_HPP */
+#endif /* BLITTER_FACTORY_HPP */
diff --git a/src/blitter/null.cpp b/src/blitter/null.cpp
index ae1133b20..87b456c4a 100644
--- a/src/blitter/null.cpp
+++ b/src/blitter/null.cpp
@@ -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;
diff --git a/src/blitter/null.hpp b/src/blitter/null.hpp
index 5db182cb6..98374f1de 100644
--- a/src/blitter/null.hpp
+++ b/src/blitter/null.hpp
@@ -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(); }
};
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index 7363e4ef8..6ae3dd456 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -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
diff --git a/src/gfx.cpp b/src/gfx.cpp
index f04524fd0..d34aae7a0 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -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_PER_LINE * MAX_SCREEN_HEIGHT / 8];
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 width, int height, int xo, int yo)
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 width, int height, int xo, int yo)
/* 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 width, int height, int xo, int yo)
/* 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 width, int height, int xo, int yo)
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 right, int bottom, int color)
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, int left, int top, int width, int heigh
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) {
diff --git a/src/gfx.h b/src/gfx.h
index c91cce4b6..ef369d953 100644
--- a/src/gfx.h
+++ b/src/gfx.h
@@ -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 {
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 87e4d55c3..4a26c3199 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -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"
diff --git a/src/renderer/32bpp.cpp b/src/renderer/32bpp.cpp
deleted file mode 100644
index 1d1d78e6a..000000000
--- a/src/renderer/32bpp.cpp
+++ /dev/null
@@ -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);
-}
diff --git a/src/renderer/8bpp.cpp b/src/renderer/8bpp.cpp
deleted file mode 100644
index 2f595c6c9..000000000
--- a/src/renderer/8bpp.cpp
+++ /dev/null
@@ -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;
-}
diff --git a/src/renderer/null.cpp b/src/renderer/null.cpp
deleted file mode 100644
index fc68feaf2..000000000
--- a/src/renderer/null.cpp
+++ /dev/null
@@ -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;
-}
diff --git a/src/renderer/null.hpp b/src/renderer/null.hpp
deleted file mode 100644
index 1eb95bbdd..000000000
--- a/src/renderer/null.hpp
+++ /dev/null
@@ -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 */
diff --git a/src/screenshot.cpp b/src/screenshot.cpp
index 78235553d..c03eab59a 100644
--- a/src/screenshot.cpp
+++ b/src/screenshot.cpp
@@ -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 */
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 25b6e1468..585913c5b 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -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 _legend_table[] = {
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(TileIndex tile); // typedef callthrough functio
*/
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, uint xc, uint yc, int pitch, int reps,
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, int y, int x2, int y2)
*/
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 *dpi, Window *w, int type, bool show_town
}
}
- 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);
}
}
}
diff --git a/src/spritecache.cpp b/src/spritecache.cpp
index 135c7d834..4b46b224b 100644
--- a/src/spritecache.cpp
+++ b/src/spritecache.cpp
@@ -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;
diff --git a/src/texteff.cpp b/src/texteff.cpp
index dd73f509d..30f94884b 100644
--- a/src/texteff.cpp
+++ b/src/texteff.cpp
@@ -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
diff --git a/src/video/cocoa_v.mm b/src/video/cocoa_v.mm
index 950aa2b28..5317ecfa2 100644
--- a/src/video/cocoa_v.mm
+++ b/src/video/cocoa_v.mm
@@ -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();
}
diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp
index 596e55497..cbcbaef3b 100644
--- a/src/video/dedicated_v.cpp
+++ b/src/video/dedicated_v.cpp
@@ -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(const char * const *parm)
_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");
diff --git a/src/video/null_v.cpp b/src/video/null_v.cpp
index 0c1f4715e..d6afc7af4 100644
--- a/src/video/null_v.cpp
+++ b/src/video/null_v.cpp
@@ -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 char* const* parm)
/* 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;
}
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index 8b851e2d6..3a1f2229e 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -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 h)
_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();
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 53d02c69f..8d32daab1 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -653,8 +653,6 @@ static bool AllocateDibSection(int w, int h)
_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);
diff --git a/src/viewport.cpp b/src/viewport.cpp
index e23c69622..11f97db7d 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -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, int left, int top, int right, int bottom
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);
diff --git a/src/window.cpp b/src/window.cpp
index bdc8a75f5..ecc18bd40 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -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* const *wz, int left, int top, int right
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);
}