Skip to content

Commit

Permalink
Backport: (svn r22397) -Document: some tidbits of the blitter code
Browse files Browse the repository at this point in the history
  • Loading branch information
rubidium42 authored and ticky committed Oct 28, 2020
1 parent 27b1bd9 commit 6d31b3d
Show file tree
Hide file tree
Showing 20 changed files with 83 additions and 56 deletions.
1 change: 1 addition & 0 deletions src/blitter/32bpp_anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "../safeguards.h"

/** Instantiation of the 32bpp with animation blitter factory. */
static FBlitter_32bppAnim iFBlitter_32bppAnim;

template <BlitterMode mode>
Expand Down
8 changes: 5 additions & 3 deletions src/blitter/32bpp_anim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
#include "32bpp_optimized.hpp"
#include "factory.hpp"

/** The optimised 32 bpp blitter with palette animation. */
class Blitter_32bppAnim : public Blitter_32bppOptimized {
private:
uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation
int anim_buf_width;
int anim_buf_height;
uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation
int anim_buf_width; ///< The width of the animation buffer.
int anim_buf_height; ///< The height of the animation buffer.

public:
Blitter_32bppAnim() :
Expand All @@ -38,6 +39,7 @@ class Blitter_32bppAnim : public Blitter_32bppOptimized {
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
};

/** Factory for the 32bpp blitter with animation. */
class FBlitter_32bppAnim: public BlitterFactory<FBlitter_32bppAnim> {
public:
/* virtual */ const char *GetName() { return "32bpp-anim"; }
Expand Down
4 changes: 1 addition & 3 deletions src/blitter/32bpp_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
#include "base.hpp"
#include "../core/bitmath_func.hpp"

/** Base for all 32bpp blitters. */
class Blitter_32bppBase : public Blitter {
public:
/* virtual */ uint8 GetScreenDepth() { return 32; }
// /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
// /* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal);
// /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, 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 DrawRect(void *video, int width, int height, uint8 color);
Expand Down
1 change: 1 addition & 0 deletions src/blitter/32bpp_optimized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "../safeguards.h"

/** Instantiation of the optimized 32bpp blitter factory. */
static FBlitter_32bppOptimized iFBlitter_32bppOptimized;

/**
Expand Down
7 changes: 5 additions & 2 deletions src/blitter/32bpp_optimized.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
#include "32bpp_simple.hpp"
#include "factory.hpp"

/** The optimised 32 bpp blitter (without palette animation). */
class Blitter_32bppOptimized : public Blitter_32bppSimple {
public:
/** Data stored about a (single) sprite. */
struct SpriteData {
uint32 offset[ZOOM_LVL_COUNT][2];
byte data[VARARRAY_SIZE];
uint32 offset[ZOOM_LVL_COUNT][2]; ///< Offsets (from .data) to streams for different zoom levels, and the normal and remap image information.
byte data[VARARRAY_SIZE]; ///< Data, all zoomlevels.
};

/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
Expand All @@ -23,6 +25,7 @@ class Blitter_32bppOptimized : public Blitter_32bppSimple {
template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
};

/** Factory for the optimised 32 bpp blitter (without palette animation). */
class FBlitter_32bppOptimized: public BlitterFactory<FBlitter_32bppOptimized> {
public:
/* virtual */ const char *GetName() { return "32bpp-optimized"; }
Expand Down
1 change: 1 addition & 0 deletions src/blitter/32bpp_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "../safeguards.h"

/** Instantiation of the simple 32bpp blitter factory. */
static FBlitter_32bppSimple iFBlitter_32bppSimple;

void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
Expand Down
2 changes: 2 additions & 0 deletions src/blitter/32bpp_simple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "32bpp_base.hpp"
#include "factory.hpp"

/** The most trivial 32 bpp blitter (without palette animation). */
class Blitter_32bppSimple : public Blitter_32bppBase {
public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
Expand All @@ -17,6 +18,7 @@ class Blitter_32bppSimple : public Blitter_32bppBase {
/* virtual */ const char *GetName() { return "32bpp-simple"; }
};

/** Factory for the simple 32 bpp blitter. */
class FBlitter_32bppSimple: public BlitterFactory<FBlitter_32bppSimple> {
public:
/* virtual */ const char *GetName() { return "32bpp-simple"; }
Expand Down
3 changes: 1 addition & 2 deletions src/blitter/8bpp_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

#include "base.hpp"

/** Base for all 8bpp blitters. */
class Blitter_8bppBase : public Blitter {
public:
/* virtual */ uint8 GetScreenDepth() { return 8; }
// /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
/* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal);
// /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, 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 DrawRect(void *video, int width, int height, uint8 color);
Expand Down
1 change: 1 addition & 0 deletions src/blitter/8bpp_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../core/random_func.hpp"
#include "8bpp_debug.hpp"

/** Instantiation of the 8bpp debug blitter factory. */
static FBlitter_8bppDebug iFBlitter_8bppDebug;

void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
Expand Down
2 changes: 2 additions & 0 deletions src/blitter/8bpp_debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "8bpp_base.hpp"
#include "factory.hpp"

/** 8bpp debug blitter; colours each sprite differently. */
class Blitter_8bppDebug : public Blitter_8bppBase {
public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
Expand All @@ -16,6 +17,7 @@ class Blitter_8bppDebug : public Blitter_8bppBase {
/* virtual */ const char *GetName() { return "8bpp-debug"; }
};

/** Factory for the 8bpp debug blitter. */
class FBlitter_8bppDebug: public BlitterFactory<FBlitter_8bppDebug> {
public:
/* virtual */ const char *GetName() { return "8bpp-debug"; }
Expand Down
1 change: 1 addition & 0 deletions src/blitter/8bpp_optimized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "../safeguards.h"

/** Instantiation of the 8bpp optimised blitter factory. */
static FBlitter_8bppOptimized iFBlitter_8bppOptimized;

void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
Expand Down
7 changes: 5 additions & 2 deletions src/blitter/8bpp_optimized.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
#include "8bpp_base.hpp"
#include "factory.hpp"

/** 8bpp blitter optimised for speed. */
class Blitter_8bppOptimized : public Blitter_8bppBase {
public:
/** Data stored about a (single) sprite. */
struct SpriteData {
uint32 offset[ZOOM_LVL_COUNT]; ///< offsets (from .data) to streams for different zoom levels
byte data[VARARRAY_SIZE]; ///< data, all zoomlevels
uint32 offset[ZOOM_LVL_COUNT]; ///< Offsets (from .data) to streams for different zoom levels.
byte data[VARARRAY_SIZE]; ///< Data, all zoomlevels.
};

/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
Expand All @@ -21,6 +23,7 @@ class Blitter_8bppOptimized : public Blitter_8bppBase {
/* virtual */ const char *GetName() { return "8bpp-optimized"; }
};

/** Factory for the 8bpp blitter optimised for speed. */
class FBlitter_8bppOptimized: public BlitterFactory<FBlitter_8bppOptimized> {
public:
/* virtual */ const char *GetName() { return "8bpp-optimized"; }
Expand Down
1 change: 1 addition & 0 deletions src/blitter/8bpp_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../safeguards.h"

/** Instantiation of the simple 8bpp blitter factory. */
static FBlitter_8bppSimple iFBlitter_8bppSimple;

void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
Expand Down
2 changes: 2 additions & 0 deletions src/blitter/8bpp_simple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "8bpp_base.hpp"
#include "factory.hpp"

/** Most trivial 8bpp blitter. */
class Blitter_8bppSimple : public Blitter_8bppBase {
public:
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
Expand All @@ -16,6 +17,7 @@ class Blitter_8bppSimple : public Blitter_8bppBase {
/* virtual */ const char *GetName() { return "8bpp-simple"; }
};

/** Factory for the most trivial 8bpp blitter. */
class FBlitter_8bppSimple: public BlitterFactory<FBlitter_8bppSimple> {
public:
/* virtual */ const char *GetName() { return "8bpp-simple"; }
Expand Down
12 changes: 0 additions & 12 deletions src/blitter/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@
#include "base.hpp"
#include "../core/math_func.hpp"

/**
* Draw a line with a given colour.
* @param video The destination pointer (video-buffer).
* @param x The x coordinate from where the line starts.
* @param y The y coordinate from where the line starts.
* @param x2 The x coordinate to where the line goes.
* @param y2 The y coordinate to where the lines goes.
* @param screen_width The width of the screen you are drawing in (to avoid buffer-overflows).
* @param screen_height The height of the screen you are drawing in (to avoid buffer-overflows).
* @param colour A 8bpp mapping colour.
* @param width Line width.
*/
void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width)
{
int dy;
Expand Down
38 changes: 22 additions & 16 deletions src/blitter/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,37 @@
#include "../spriteloader/spriteloader.hpp"
#include "../zoom_type.h"

/** The modes of blitting we can do. */
enum BlitterMode {
BM_NORMAL,
BM_COLOUR_REMAP,
BM_TRANSPARENT,
BM_NORMAL, ///< Perform the simple blitting.
BM_COLOUR_REMAP, ///< Perform a colour remapping.
BM_TRANSPARENT, ///< Perform transparency colour remapping.
};

/**
* How all blitters should look like. Extend this class to make your own.
*/
class Blitter {
public:
/** Parameters related to blitting. */
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
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; ///< How much pixels of the source to skip on the left (based on zoom of dst)
int skip_top; ///< How much pixels of the source to skip on the top (based on zoom of dst)
int width; ///< The width in pixels that needs to be drawn to dst
int height; ///< The 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; ///< The left offset in the 'dst' in pixels to start drawing
int top; ///< The top offset in the 'dst' in pixels to start drawing

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

/** Types of palette animation. */
enum PaletteAnimation {
PALETTE_ANIMATION_NONE, ///< No palette animation
PALETTE_ANIMATION_VIDEO_BACKEND, ///< Palette animation should be done by video backend (8bpp only!)
Expand Down Expand Up @@ -104,9 +110,9 @@ class Blitter {
* @param screen_width The width of the screen you are drawing in (to avoid buffer-overflows).
* @param screen_height The height of the screen you are drawing in (to avoid buffer-overflows).
* @param colour A 8bpp mapping colour.
* @param width The width of line to draw.
* @param width Line width.
*/
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width);
virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width);

/**
* Copy from a buffer to the screen.
Expand Down
19 changes: 16 additions & 3 deletions src/blitter/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool QZ_CanDisplay8bpp();
*/
class BlitterFactoryBase {
private:
const char *name;
const char *name; ///< The name of the blitter factory.

struct StringCompare {
bool operator () (const char *a, const char *b) const
Expand All @@ -28,14 +28,22 @@ class BlitterFactoryBase {
}
};

typedef std::map<const char *, BlitterFactoryBase *, StringCompare> Blitters;
typedef std::map<const char *, BlitterFactoryBase *, StringCompare> Blitters; ///< Map of blitter factories.

/**
* Get the map with currently known blitters.
* @return The known blitters.
*/
static Blitters &GetBlitters()
{
static Blitters &s_blitters = *new Blitters();
return s_blitters;
}

/**
* Get the currently active blitter.
* @return The currently active blitter.
*/
static Blitter **GetActiveBlitter()
{
static Blitter *s_blitter = NULL;
Expand Down Expand Up @@ -123,7 +131,12 @@ class BlitterFactoryBase {
return *GetActiveBlitter();
}


/**
* Fill a buffer with information about the blitters.
* @param p The buffer to fill.
* @param last The last element of the buffer.
* @return p The location till where we filled the buffer.
*/
static char *GetBlittersInfo(char *p, const char *last)
{
p += seprintf(p, last, "List of blitters:\n");
Expand Down
1 change: 1 addition & 0 deletions src/blitter/null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "../safeguards.h"

/** Instantiation of the null blitter factory. */
static FBlitter_Null iFBlitter_Null;

Sprite *Blitter_Null::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
Expand Down
8 changes: 5 additions & 3 deletions src/blitter/null.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
#include "base.hpp"
#include "factory.hpp"

/** Blitter that does nothing. */
class Blitter_Null : public Blitter {
public:
/* virtual */ uint8 GetScreenDepth() { return 0; }
/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) {};
/* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) {};
/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator);
/* 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 DrawRect(void *video, int width, int height, uint8 color) {};
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color) {};
/* virtual */ void SetPixel(void *video, int x, int y, uint8 colour) {};
/* virtual */ void DrawRect(void *video, int width, int height, uint8 colour) {};
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width) {};
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height) {};
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height) {};
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) {};
Expand All @@ -29,6 +30,7 @@ class Blitter_Null : public Blitter {
/* virtual */ const char *GetName() { return "null"; }
};

/** Factory for the blitter that doesn nothing. */
class FBlitter_Null: public BlitterFactory<FBlitter_Null> {
public:
/* virtual */ const char *GetName() { return "null"; }
Expand Down
20 changes: 10 additions & 10 deletions src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@

#include "safeguards.h"

VideoDriver *_video_driver;
char *_ini_videodriver;
int _num_resolutions;
uint16 _resolutions[32][2];
uint16 _cur_resolution[2];
VideoDriver *_video_driver; ///< The currently active video driver.
char *_ini_videodriver; ///< The video driver a stored in the configuration file.
int _num_resolutions; ///< The number of resolutions.
uint16 _resolutions[32][2]; ///< List of resolutions.
uint16 _cur_resolution[2]; ///< The current resolution.

SoundDriver *_sound_driver;
char *_ini_sounddriver;
SoundDriver *_sound_driver; ///< The currently active sound driver.
char *_ini_sounddriver; ///< The sound driver a stored in the configuration file.

MusicDriver *_music_driver;
char *_ini_musicdriver;
MusicDriver *_music_driver; ///< The currently active music driver.
char *_ini_musicdriver; ///< The music driver a stored in the configuration file.

char *_ini_blitter;
char *_ini_blitter; ///< The blitter as stored in the configuration file.

static const char* GetDriverParam(const char* const* parm, const char* name)
{
Expand Down

0 comments on commit 6d31b3d

Please sign in to comment.