src/blitter/blitter.hpp
author truelight
Wed, 13 Jun 2007 10:31:40 +0000
changeset 7385 dc6e404283bc
parent 7374 54c06f06ecc8
permissions -rw-r--r--
(svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
-Add: added a new renderer and blitter to make room for some optimized bpp
-Fix: fill the alpha channel in the grf-spriteloader
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     1
/* $Id$ */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     2
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     3
/** @file blitter.hpp */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     4
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     5
#ifndef BLITTER_HPP
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     6
#define BLITTER_HPP
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     7
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     8
#include "../spriteloader/spriteloader.hpp"
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     9
#include "../spritecache.h"
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    10
#include <string>
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    11
#include <map>
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    12
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    13
enum BlitterMode {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    14
	BM_NORMAL,
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    15
	BM_COLOUR_REMAP,
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    16
	BM_TRANSPARENT,
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    17
};
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    18
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    19
/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    20
 * How all blitters should look like. Extend this class to make your own.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    21
 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    22
class Blitter {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    23
public:
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    24
	struct BlitterParams {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    25
		const void *sprite;      ///< Pointer to the sprite how ever the encoder stored it
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    26
		const byte *remap;       ///< XXX -- Temporary storage for remap array
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    27
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    28
		int skip_left, skip_top; ///< How much pixels of the source to skip on the left and top (based on zoom of dst)
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    29
		int width, height;       ///< The width and height in pixels that needs to be drawn to dst
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    30
		int sprite_width;        ///< Real width of the sprite
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    31
		int sprite_height;       ///< Real height of the sprite
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    32
		int left, top;           ///< The offset in the 'dst' in pixels to start drawing
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    33
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    34
		void *dst;               ///< Destination buffer
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    35
		int pitch;               ///< The pitch of the destination buffer
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    36
	};
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    37
7352
e2e8432018f6 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents: 7348
diff changeset
    38
	typedef void *AllocatorProc(size_t size);
e2e8432018f6 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents: 7348
diff changeset
    39
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    40
	/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    41
	 * Get the screen depth this blitter works for.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    42
	 *  This is either: 8, 16, 24 or 32.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    43
	 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    44
	virtual uint8 GetScreenDepth() = 0;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    45
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    46
	/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    47
	 * Draw an image to the screen, given an amount of params defined above.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    48
	 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    49
	virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    50
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    51
	/**
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    52
	 * Draw a colortable to the screen. This is: the color of the screen is read
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    53
	 *  and is looked-up in the palette to match a new color, which then is put
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    54
	 *  on the screen again.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    55
	 * @param dst the destination pointer (video-buffer).
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    56
	 * @param width the width of the buffer.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    57
	 * @param height the height of the buffer.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    58
	 * @param pal the palette to use.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    59
	 */
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    60
	virtual void DrawColorMappingRect(void *dst, int width, int height, int pal) = 0;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    61
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    62
	/**
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    63
	 * Convert a sprite from the loader to our own format.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    64
	 */
7352
e2e8432018f6 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents: 7348
diff changeset
    65
	virtual Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) = 0;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    66
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7352
diff changeset
    67
	/**
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7352
diff changeset
    68
	 * Get the renderer this class depends on.
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7352
diff changeset
    69
	 */
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7352
diff changeset
    70
	virtual const char *GetRenderer() = 0;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7352
diff changeset
    71
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    72
	virtual ~Blitter() { }
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    73
};
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    74
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    75
/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    76
 * The base factory, keeping track of all blitters.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    77
 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    78
class BlitterFactoryBase {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    79
private:
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    80
	char *name;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    81
	typedef std::map<std::string, BlitterFactoryBase *> Blitters;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    82
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    83
	static Blitters &GetBlitters()
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    84
	{
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    85
		static Blitters &s_blitters = *new Blitters();
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    86
		return s_blitters;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    87
	}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    88
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    89
	static Blitter **GetActiveBlitter()
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    90
	{
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    91
		static Blitter *s_blitter = NULL;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    92
		return &s_blitter;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    93
	}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    94
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    95
protected:
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    96
	/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    97
	 * Register a blitter internally, based on his name.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    98
	 * @param name the name of the blitter.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    99
	 * @note an assert() will be trigger if 2 blitters with the same name try to register.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   100
	 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   101
	void RegisterBlitter(const char *name)
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   102
	{
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   103
		/* Don't register nameless Blitters */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   104
		if (name == NULL) return;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   105
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   106
		this->name = strdup(name);
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   107
		std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(name, this));
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   108
		assert(P.second);
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   109
	}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   110
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   111
public:
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   112
	BlitterFactoryBase() :
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   113
		name(NULL)
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   114
	{}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   115
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   116
	virtual ~BlitterFactoryBase() { if (this->name != NULL) GetBlitters().erase(this->name); free(this->name); }
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   117
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   118
	/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   119
	 * Find the requested blitter and return his class.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   120
	 * @param name the blitter to select.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   121
	 * @post Sets the blitter so GetCurrentBlitter() returns it too.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   122
	 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   123
	static Blitter *SelectBlitter(const char *name)
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   124
	{
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   125
		if (GetBlitters().size() == 0) return NULL;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   126
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   127
		Blitters::iterator it = GetBlitters().begin();
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   128
		for (; it != GetBlitters().end(); it++) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   129
			BlitterFactoryBase *b = (*it).second;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   130
			if (strcasecmp(name, b->name) == 0) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   131
				Blitter *newb = b->CreateInstance();
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   132
				*GetActiveBlitter() = newb;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   133
				return newb;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   134
			}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   135
		}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   136
		return NULL;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   137
	}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   138
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   139
	/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   140
	 * Get the current active blitter (always set by calling SelectBlitter).
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   141
	 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   142
	static Blitter *GetCurrentBlitter()
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   143
	{
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   144
		return *GetActiveBlitter();
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   145
	}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   146
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   147
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   148
	static char *GetBlittersInfo(char *p, const char *last)
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   149
	{
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   150
		p += snprintf(p, last - p, "List of blitters:\n");
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   151
		Blitters::iterator it = GetBlitters().begin();
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   152
		for (; it != GetBlitters().end(); it++) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   153
			BlitterFactoryBase *b = (*it).second;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   154
			p += snprintf(p, last - p, "%18s: %s\n", b->name, b->GetDescription());
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   155
		}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   156
		p += snprintf(p, last - p, "\n");
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   157
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   158
		return p;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   159
	}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   160
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   161
	/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   162
	 * Get a nice description of the blitter-class.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   163
	 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   164
	virtual const char *GetDescription() = 0;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   165
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   166
	/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   167
	 * Create an instance of this Blitter-class.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   168
	 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   169
	virtual Blitter *CreateInstance() = 0;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   170
};
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   171
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   172
/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   173
 * A template factory, so ->GetName() works correctly. This because else some compiler will complain.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   174
 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   175
template <class T>
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   176
class BlitterFactory: public BlitterFactoryBase {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   177
public:
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   178
	BlitterFactory() { this->RegisterBlitter(((T *)this)->GetName()); }
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   179
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   180
	/**
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   181
	 * Get the long, human readable, name for the Blitter-class.
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   182
	 */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   183
	const char *GetName();
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   184
};
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   185
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
   186
#endif /* BLITTER_HPP */