1
0
Fork 0

(svn r26209) -Codechange: remove some template magic and simplify some code

release/1.4
rubidium 2014-01-02 22:41:58 +00:00
parent 456dba4889
commit 2618d960e3
28 changed files with 100 additions and 112 deletions

View File

@ -56,10 +56,9 @@ public:
}; };
/** Factory for the 32bpp blitter with animation. */ /** Factory for the 32bpp blitter with animation. */
class FBlitter_32bppAnim : public BlitterFactory<FBlitter_32bppAnim> { class FBlitter_32bppAnim : public BlitterFactory {
public: public:
/* virtual */ const char *GetName() { return "32bpp-anim"; } FBlitter_32bppAnim() : BlitterFactory("32bpp-anim", "32bpp Animation Blitter (palette animation)") {}
/* virtual */ const char *GetDescription() { return "32bpp Animation Blitter (palette animation)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppAnim(); } /* virtual */ Blitter *CreateInstance() { return new Blitter_32bppAnim(); }
}; };

View File

@ -32,10 +32,9 @@ public:
}; };
/** Factory for the optimised 32 bpp blitter (without palette animation). */ /** Factory for the optimised 32 bpp blitter (without palette animation). */
class FBlitter_32bppOptimized : public BlitterFactory<FBlitter_32bppOptimized> { class FBlitter_32bppOptimized : public BlitterFactory {
public: public:
/* virtual */ const char *GetName() { return "32bpp-optimized"; } FBlitter_32bppOptimized() : BlitterFactory("32bpp-optimized", "32bpp Optimized Blitter (no palette animation)") {}
/* virtual */ const char *GetDescription() { return "32bpp Optimized Blitter (no palette animation)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppOptimized(); } /* virtual */ Blitter *CreateInstance() { return new Blitter_32bppOptimized(); }
}; };

View File

@ -34,10 +34,9 @@ public:
}; };
/** Factory for the simple 32 bpp blitter. */ /** Factory for the simple 32 bpp blitter. */
class FBlitter_32bppSimple : public BlitterFactory<FBlitter_32bppSimple> { class FBlitter_32bppSimple : public BlitterFactory {
public: public:
/* virtual */ const char *GetName() { return "32bpp-simple"; } FBlitter_32bppSimple() : BlitterFactory("32bpp-simple", "32bpp Simple Blitter (no palette animation)") {}
/* virtual */ const char *GetDescription() { return "32bpp Simple Blitter (no palette animation)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSimple(); } /* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSimple(); }
}; };

View File

@ -31,10 +31,9 @@ public:
}; };
/** Factory for the 8bpp blitter optimised for speed. */ /** Factory for the 8bpp blitter optimised for speed. */
class FBlitter_8bppOptimized : public BlitterFactory<FBlitter_8bppOptimized> { class FBlitter_8bppOptimized : public BlitterFactory {
public: public:
/* virtual */ const char *GetName() { return "8bpp-optimized"; } FBlitter_8bppOptimized() : BlitterFactory("8bpp-optimized", "8bpp Optimized Blitter (compression + all-ZoomLevel cache)") {}
/* virtual */ const char *GetDescription() { return "8bpp Optimized Blitter (compression + all-ZoomLevel cache)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppOptimized(); } /* virtual */ Blitter *CreateInstance() { return new Blitter_8bppOptimized(); }
}; };

View File

@ -25,10 +25,9 @@ public:
}; };
/** Factory for the most trivial 8bpp blitter. */ /** Factory for the most trivial 8bpp blitter. */
class FBlitter_8bppSimple : public BlitterFactory<FBlitter_8bppSimple> { class FBlitter_8bppSimple : public BlitterFactory {
public: public:
/* virtual */ const char *GetName() { return "8bpp-simple"; } FBlitter_8bppSimple() : BlitterFactory("8bpp-simple", "8bpp Simple Blitter (relative slow, but never wrong)") {}
/* virtual */ const char *GetDescription() { return "8bpp Simple Blitter (relative slow, but never wrong)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_8bppSimple(); } /* virtual */ Blitter *CreateInstance() { return new Blitter_8bppSimple(); }
}; };

View File

@ -25,11 +25,12 @@ bool QZ_CanDisplay8bpp();
/** /**
* The base factory, keeping track of all blitters. * The base factory, keeping track of all blitters.
*/ */
class BlitterFactoryBase { class BlitterFactory {
private: private:
const char *name; ///< The name of the blitter factory. const char *name; ///< The name of the blitter factory.
const char *description; ///< The description of the blitter.
typedef std::map<const char *, BlitterFactoryBase *, StringCompare> Blitters; ///< Map of blitter factories. typedef std::map<const char *, BlitterFactory *, StringCompare> Blitters; ///< Map of blitter factories.
/** /**
* Get the map with currently known blitters. * Get the map with currently known blitters.
@ -53,32 +54,28 @@ private:
protected: protected:
/** /**
* Register a blitter internally, based on his name. * Construct the blitter, and register it.
* @param name the name of the blitter. * @param name The name of the blitter.
* @note an assert() will be trigger if 2 blitters with the same name try to register. * @param description A longer description for the blitter.
* @pre name != NULL.
* @pre description != NULL.
* @pre There is no blitter registered with this name.
*/ */
void RegisterBlitter(const char *name) BlitterFactory(const char *name, const char *description) :
name(strdup(name)), description(strdup(description))
{ {
/* Don't register nameless Blitters */ std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(this->name, this));
if (name == NULL) return;
this->name = strdup(name);
std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(name, this));
assert(P.second); assert(P.second);
} }
public: public:
BlitterFactoryBase() : virtual ~BlitterFactory()
name(NULL)
{}
virtual ~BlitterFactoryBase()
{ {
if (this->name == NULL) return;
GetBlitters().erase(this->name); GetBlitters().erase(this->name);
if (GetBlitters().empty()) delete &GetBlitters(); if (GetBlitters().empty()) delete &GetBlitters();
free(this->name); free(this->name);
free(this->description);
} }
/** /**
@ -108,7 +105,7 @@ public:
Blitters::iterator it = GetBlitters().begin(); Blitters::iterator it = GetBlitters().begin();
for (; it != GetBlitters().end(); it++) { for (; it != GetBlitters().end(); it++) {
BlitterFactoryBase *b = (*it).second; BlitterFactory *b = (*it).second;
if (strcasecmp(bname, b->name) == 0) { if (strcasecmp(bname, b->name) == 0) {
Blitter *newb = b->CreateInstance(); Blitter *newb = b->CreateInstance();
delete *GetActiveBlitter(); delete *GetActiveBlitter();
@ -140,7 +137,7 @@ public:
p += seprintf(p, last, "List of blitters:\n"); p += seprintf(p, last, "List of blitters:\n");
Blitters::iterator it = GetBlitters().begin(); Blitters::iterator it = GetBlitters().begin();
for (; it != GetBlitters().end(); it++) { for (; it != GetBlitters().end(); it++) {
BlitterFactoryBase *b = (*it).second; BlitterFactory *b = (*it).second;
p += seprintf(p, last, "%18s: %s\n", b->name, b->GetDescription()); p += seprintf(p, last, "%18s: %s\n", b->name, b->GetDescription());
} }
p += seprintf(p, last, "\n"); p += seprintf(p, last, "\n");
@ -148,10 +145,21 @@ public:
return p; return p;
} }
/**
* Get the long, human readable, name for the Blitter-class.
*/
const char *GetName() const
{
return this->name;
}
/** /**
* Get a nice description of the blitter-class. * Get a nice description of the blitter-class.
*/ */
virtual const char *GetDescription() = 0; const char *GetDescription() const
{
return this->description;
}
/** /**
* Create an instance of this Blitter-class. * Create an instance of this Blitter-class.
@ -159,20 +167,6 @@ public:
virtual Blitter *CreateInstance() = 0; virtual Blitter *CreateInstance() = 0;
}; };
/**
* A template factory, so ->GetName() works correctly. This because else some compiler will complain.
*/
template <class T>
class BlitterFactory : public BlitterFactoryBase {
public:
BlitterFactory() { this->RegisterBlitter(((T *)this)->GetName()); }
/**
* Get the long, human readable, name for the Blitter-class.
*/
const char *GetName();
};
extern char *_ini_blitter; extern char *_ini_blitter;
extern bool _blitter_autodetected; extern bool _blitter_autodetected;

View File

@ -38,10 +38,9 @@ public:
}; };
/** Factory for the blitter that does nothing. */ /** Factory for the blitter that does nothing. */
class FBlitter_Null : public BlitterFactory<FBlitter_Null> { class FBlitter_Null : public BlitterFactory {
public: public:
/* virtual */ const char *GetName() { return "null"; } FBlitter_Null() : BlitterFactory("null", "Null Blitter (does nothing)") {}
/* virtual */ const char *GetDescription() { return "Null Blitter (does nothing)"; }
/* virtual */ Blitter *CreateInstance() { return new Blitter_Null(); } /* virtual */ Blitter *CreateInstance() { return new Blitter_Null(); }
}; };

View File

@ -215,7 +215,7 @@ bool HandleBootstrap()
if (BaseGraphics::GetUsedSet() != NULL) return true; if (BaseGraphics::GetUsedSet() != NULL) return true;
/* No user interface, bail out with an error. */ /* No user interface, bail out with an error. */
if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure; if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) goto failure;
/* If there is no network or no freetype, then there is nothing we can do. Go straight to failure. */ /* If there is no network or no freetype, then there is nothing we can do. Go straight to failure. */
#if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(WIN32) || defined(__APPLE__)) #if defined(ENABLE_NETWORK) && defined(WITH_FREETYPE) && (defined(WITH_FONTCONFIG) || defined(WIN32) || defined(__APPLE__))

View File

@ -134,7 +134,7 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const
" Sound driver: %s\n" " Sound driver: %s\n"
" Sound set: %s (%u)\n" " Sound set: %s (%u)\n"
" Video driver: %s\n\n", " Video driver: %s\n\n",
BlitterFactoryBase::GetCurrentBlitter() == NULL ? "none" : BlitterFactoryBase::GetCurrentBlitter()->GetName(), BlitterFactory::GetCurrentBlitter() == NULL ? "none" : BlitterFactory::GetCurrentBlitter()->GetName(),
BaseGraphics::GetUsedSet() == NULL ? "none" : BaseGraphics::GetUsedSet()->name, BaseGraphics::GetUsedSet() == NULL ? "none" : BaseGraphics::GetUsedSet()->name,
BaseGraphics::GetUsedSet() == NULL ? UINT32_MAX : BaseGraphics::GetUsedSet()->version, BaseGraphics::GetUsedSet() == NULL ? UINT32_MAX : BaseGraphics::GetUsedSet()->version,
_current_language == NULL ? "none" : _current_language->file, _current_language == NULL ? "none" : _current_language->file,

View File

@ -439,7 +439,7 @@ static void *AllocateFont(size_t size)
static bool GetFontAAState(FontSize size) static bool GetFontAAState(FontSize size)
{ {
/* AA is only supported for 32 bpp */ /* AA is only supported for 32 bpp */
if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 32) return false; if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 32) return false;
switch (size) { switch (size) {
default: NOT_REACHED(); default: NOT_REACHED();
@ -494,7 +494,7 @@ const Sprite *FreeTypeFontCache::GetGlyph(GlyphID key)
builtin_questionmark_data builtin_questionmark_data
}; };
Sprite *spr = BlitterFactoryBase::GetCurrentBlitter()->Encode(&builtin_questionmark, AllocateFont); Sprite *spr = BlitterFactory::GetCurrentBlitter()->Encode(&builtin_questionmark, AllocateFont);
assert(spr != NULL); assert(spr != NULL);
new_glyph.sprite = spr; new_glyph.sprite = spr;
new_glyph.width = spr->width + (this->fs != FS_NORMAL); new_glyph.width = spr->width + (this->fs != FS_NORMAL);
@ -551,7 +551,7 @@ const Sprite *FreeTypeFontCache::GetGlyph(GlyphID key)
} }
} }
new_glyph.sprite = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, AllocateFont); new_glyph.sprite = BlitterFactory::GetCurrentBlitter()->Encode(&sprite, AllocateFont);
new_glyph.width = slot->advance.x >> 6; new_glyph.width = slot->advance.x >> 6;
this->SetGlyphPtr(key, &new_glyph); this->SetGlyphPtr(key, &new_glyph);

View File

@ -73,7 +73,7 @@ extern uint _dirty_block_colour;
void GfxScroll(int left, int top, int width, int height, int xo, int yo) void GfxScroll(int left, int top, int width, int height, int xo, int yo)
{ {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
if (xo == 0 && yo == 0) return; if (xo == 0 && yo == 0) return;
@ -105,7 +105,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 colour, FillRectMode mode) void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
{ {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
const DrawPixelInfo *dpi = _cur_dpi; const DrawPixelInfo *dpi = _cur_dpi;
void *dst; void *dst;
const int otop = top; const int otop = top;
@ -166,7 +166,7 @@ void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectM
*/ */
static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash = 0) static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash = 0)
{ {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
assert(width > 0); assert(width > 0);
@ -929,7 +929,7 @@ static void GfxBlitter(const Sprite * const sprite, int x, int y, BlitterMode mo
/* We do not want to catch the mouse. However we also use that spritenumber for unknown (text) sprites. */ /* We do not want to catch the mouse. However we also use that spritenumber for unknown (text) sprites. */
if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW && sprite_id != SPR_CURSOR_MOUSE) { if (_newgrf_debug_sprite_picker.mode == SPM_REDRAW && sprite_id != SPR_CURSOR_MOUSE) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
void *topleft = blitter->MoveTo(bp.dst, bp.left, bp.top); void *topleft = blitter->MoveTo(bp.dst, bp.left, bp.top);
void *bottomright = blitter->MoveTo(topleft, bp.width - 1, bp.height - 1); void *bottomright = blitter->MoveTo(topleft, bp.width - 1, bp.height - 1);
@ -943,7 +943,7 @@ static void GfxBlitter(const Sprite * const sprite, int x, int y, BlitterMode mo
} }
} }
BlitterFactoryBase::GetCurrentBlitter()->Draw(&bp, mode, zoom); BlitterFactory::GetCurrentBlitter()->Draw(&bp, mode, zoom);
} }
static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub, SpriteID sprite_id) static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub, SpriteID sprite_id)
@ -973,7 +973,7 @@ void DoPaletteAnimations()
static int palette_animation_counter = 0; static int palette_animation_counter = 0;
palette_animation_counter += 8; palette_animation_counter += 8;
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
const Colour *s; const Colour *s;
const ExtraPaletteValues *ev = &_extra_palette_values; const ExtraPaletteValues *ev = &_extra_palette_values;
Colour old_val[PALETTE_ANIM_SIZE]; Colour old_val[PALETTE_ANIM_SIZE];
@ -1173,7 +1173,7 @@ void UndrawMouseCursor()
if (_screen.dst_ptr == NULL) return; if (_screen.dst_ptr == NULL) return;
if (_cursor.visible) { if (_cursor.visible) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
_cursor.visible = false; _cursor.visible = false;
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup.GetBuffer(), _cursor.draw_size.x, _cursor.draw_size.y); blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup.GetBuffer(), _cursor.draw_size.x, _cursor.draw_size.y);
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); _video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
@ -1190,7 +1190,7 @@ void DrawMouseCursor()
/* Don't draw the mouse cursor if the screen is not ready */ /* Don't draw the mouse cursor if the screen is not ready */
if (_screen.dst_ptr == NULL) return; if (_screen.dst_ptr == NULL) return;
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
int x; int x;
int y; int y;
int w; int w;
@ -1443,7 +1443,7 @@ void MarkWholeScreenDirty()
*/ */
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height) bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
{ {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
const DrawPixelInfo *o = _cur_dpi; const DrawPixelInfo *o = _cur_dpi;
n->zoom = ZOOM_LVL_NORMAL; n->zoom = ZOOM_LVL_NORMAL;

View File

@ -239,12 +239,12 @@ static void SwitchNewGRFBlitter()
} }
/* A GRF would like a 32 bpp blitter, switch blitter if needed. Never switch if the blitter was specified by the user. */ /* A GRF would like a 32 bpp blitter, switch blitter if needed. Never switch if the blitter was specified by the user. */
if (_blitter_autodetected && is_32bpp && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 0 && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() < 16) { if (_blitter_autodetected && is_32bpp && BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 0 && BlitterFactory::GetCurrentBlitter()->GetScreenDepth() < 16) {
const char *cur_blitter = BlitterFactoryBase::GetCurrentBlitter()->GetName(); const char *cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
if (BlitterFactoryBase::SelectBlitter("32bpp-anim") != NULL) { if (BlitterFactory::SelectBlitter("32bpp-anim") != NULL) {
if (!_video_driver->AfterBlitterChange()) { if (!_video_driver->AfterBlitterChange()) {
/* Failed to switch blitter, let's hope we can return to the old one. */ /* Failed to switch blitter, let's hope we can return to the old one. */
if (BlitterFactoryBase::SelectBlitter(cur_blitter) == NULL || !_video_driver->AfterBlitterChange()) usererror("Failed to reinitialize video driver for 32 bpp blitter. Specify a fixed blitter in the config"); if (BlitterFactory::SelectBlitter(cur_blitter) == NULL || !_video_driver->AfterBlitterChange()) usererror("Failed to reinitialize video driver for 32 bpp blitter. Specify a fixed blitter in the config");
} }
} }
} }

View File

@ -108,7 +108,7 @@ void NetworkReInitChatBoxSize()
{ {
_chatmsg_box.y = 3 * FONT_HEIGHT_NORMAL; _chatmsg_box.y = 3 * FONT_HEIGHT_NORMAL;
_chatmsg_box.height = MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING) + 2; _chatmsg_box.height = MAX_CHAT_MESSAGES * (FONT_HEIGHT_NORMAL + NETWORK_CHAT_LINE_SPACING) + 2;
_chatmessage_backup = ReallocT(_chatmessage_backup, _chatmsg_box.width * _chatmsg_box.height * BlitterFactoryBase::GetCurrentBlitter()->GetBytesPerPixel()); _chatmessage_backup = ReallocT(_chatmessage_backup, _chatmsg_box.width * _chatmsg_box.height * BlitterFactory::GetCurrentBlitter()->GetBytesPerPixel());
} }
/** Initialize all buffers of the chat visualisation. */ /** Initialize all buffers of the chat visualisation. */
@ -149,7 +149,7 @@ void NetworkUndrawChatMessage()
} }
if (_chatmessage_visible) { if (_chatmessage_visible) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
int x = _chatmsg_box.x; int x = _chatmsg_box.x;
int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height; int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height;
int width = _chatmsg_box.width; int width = _chatmsg_box.width;
@ -198,7 +198,7 @@ void NetworkChatMessageLoop()
/** Draw the chat message-box */ /** Draw the chat message-box */
void NetworkDrawChatMessage() void NetworkDrawChatMessage()
{ {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
if (!_chatmessage_dirty) return; if (!_chatmessage_dirty) return;
/* First undraw if needed */ /* First undraw if needed */

View File

@ -192,7 +192,7 @@ static void ShowHelp()
p = DriverFactoryBase::GetDriversInfo(p, lastof(buf)); p = DriverFactoryBase::GetDriversInfo(p, lastof(buf));
/* List the blitters */ /* List the blitters */
p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf)); p = BlitterFactory::GetBlittersInfo(p, lastof(buf));
/* List the debug facilities. */ /* List the debug facilities. */
p = DumpDebugFacilityNames(p, lastof(buf)); p = DumpDebugFacilityNames(p, lastof(buf));
@ -756,8 +756,8 @@ int openttd_main(int argc, char *argv[])
if (blitter == NULL && _ini_blitter != NULL) blitter = strdup(_ini_blitter); if (blitter == NULL && _ini_blitter != NULL) blitter = strdup(_ini_blitter);
_blitter_autodetected = StrEmpty(blitter); _blitter_autodetected = StrEmpty(blitter);
/* If we have a 32 bpp base set, try to select the 32 bpp blitter first, but only if we autoprobe the blitter. */ /* If we have a 32 bpp base set, try to select the 32 bpp blitter first, but only if we autoprobe the blitter. */
if (!_blitter_autodetected || BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP || BlitterFactoryBase::SelectBlitter("32bpp-anim") == NULL) { if (!_blitter_autodetected || BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP || BlitterFactory::SelectBlitter("32bpp-anim") == NULL) {
if (BlitterFactoryBase::SelectBlitter(blitter) == NULL) { if (BlitterFactory::SelectBlitter(blitter) == NULL) {
StrEmpty(blitter) ? StrEmpty(blitter) ?
usererror("Failed to autoprobe blitter") : usererror("Failed to autoprobe blitter") :
usererror("Failed to select requested blitter '%s'; does it exist?", blitter); usererror("Failed to select requested blitter '%s'; does it exist?", blitter);

View File

@ -122,7 +122,7 @@ void DisplaySplashImage()
uint xoff = (_screen.width - width) / 2; uint xoff = (_screen.width - width) / 2;
uint yoff = (_screen.height - height) / 2; uint yoff = (_screen.height - height) / 2;
switch (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) { switch (BlitterFactory::GetCurrentBlitter()->GetScreenDepth()) {
case 8: { case 8: {
uint8 *dst_ptr = (uint8 *)_screen.dst_ptr; uint8 *dst_ptr = (uint8 *)_screen.dst_ptr;
/* Initialize buffer */ /* Initialize buffer */

View File

@ -634,7 +634,7 @@ void SetScreenshotFormat(uint i)
*/ */
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n) static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
{ {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
void *src = blitter->MoveTo(_screen.dst_ptr, 0, y); void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch); blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch);
} }
@ -740,7 +740,7 @@ static bool MakeSmallScreenshot(bool crashlog)
{ {
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension, crashlog), CurrentScreenCallback, NULL, _screen.width, _screen.height, return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension, crashlog), CurrentScreenCallback, NULL, _screen.width, _screen.height,
BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette); BlitterFactory::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
} }
/** /**
@ -796,7 +796,7 @@ static bool MakeLargeWorldScreenshot(ScreenshotType t)
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), LargeWorldCallback, &vp, vp.width, vp.height,
BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette); BlitterFactory::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
} }
/** /**

View File

@ -276,7 +276,7 @@ struct GameOptionsWindow : Window {
list = new DropDownList(); list = new DropDownList();
*selected_index = _cur_screenshot_format; *selected_index = _cur_screenshot_format;
for (uint i = 0; i < _num_screenshot_formats; i++) { for (uint i = 0; i < _num_screenshot_formats; i++) {
if (!GetScreenshotFormatSupports_32bpp(i) && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) continue; if (!GetScreenshotFormatSupports_32bpp(i) && BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 32) continue;
*list->Append() = new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false); *list->Append() = new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false);
} }
break; break;

View File

@ -941,7 +941,7 @@ void SmallMapWindow::DrawMapIndicators() const
*/ */
void SmallMapWindow::DrawSmallMap(DrawPixelInfo *dpi) const void SmallMapWindow::DrawSmallMap(DrawPixelInfo *dpi) const
{ {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
DrawPixelInfo *old_dpi; DrawPixelInfo *old_dpi;
old_dpi = _cur_dpi; old_dpi = _cur_dpi;

View File

@ -394,7 +394,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
sprite[ZOOM_LVL_NORMAL].type = sprite_type; sprite[ZOOM_LVL_NORMAL].type = sprite_type;
SpriteLoaderGrf sprite_loader(sc->container_ver); SpriteLoaderGrf sprite_loader(sc->container_ver);
if (sprite_type != ST_MAPGEN && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) { if (sprite_type != ST_MAPGEN && BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 32) {
/* Try for 32bpp sprites first. */ /* Try for 32bpp sprites first. */
sprite_avail = sprite_loader.LoadSprite(sprite, file_slot, file_pos, sprite_type, true); sprite_avail = sprite_loader.LoadSprite(sprite, file_slot, file_pos, sprite_type, true);
} }
@ -442,7 +442,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator); return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator);
} }
} }
return BlitterFactoryBase::GetCurrentBlitter()->Encode(sprite, allocator); return BlitterFactory::GetCurrentBlitter()->Encode(sprite, allocator);
} }
@ -847,7 +847,7 @@ void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator)
static void GfxInitSpriteCache() static void GfxInitSpriteCache()
{ {
/* initialize sprite cache heap */ /* initialize sprite cache heap */
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
uint target_size = (bpp > 0 ? _sprite_cache_size * bpp / 8 : 1) * 1024 * 1024; uint target_size = (bpp > 0 ? _sprite_cache_size * bpp / 8 : 1) * 1024 * 1024;
/* Remember 'target_size' from the previous allocation attempt, so we do not try to reach the target_size multiple times in case of failure. */ /* Remember 'target_size' from the previous allocation attempt, so we do not try to reach the target_size multiple times in case of failure. */

View File

@ -92,7 +92,7 @@ static void InitPalette()
static void CheckPaletteAnim() static void CheckPaletteAnim()
{ {
if (_cur_palette.count_dirty != 0) { if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
switch (blitter->UsePaletteAnimation()) { switch (blitter->UsePaletteAnimation()) {
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
@ -191,7 +191,7 @@ static void GetAvailableVideoMode(uint *w, uint *h)
static bool CreateMainSurface(uint w, uint h) static bool CreateMainSurface(uint w, uint h)
{ {
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals"); if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
set_color_depth(bpp); set_color_depth(bpp);
@ -217,7 +217,7 @@ static bool CreateMainSurface(uint w, uint h)
_cursor.pos.x = mouse_x; _cursor.pos.x = mouse_x;
_cursor.pos.y = mouse_y; _cursor.pos.y = mouse_y;
BlitterFactoryBase::GetCurrentBlitter()->PostResize(); BlitterFactory::GetCurrentBlitter()->PostResize();
InitPalette(); InitPalette();

View File

@ -333,7 +333,7 @@ void QZ_GameSizeChanged()
_screen.dst_ptr = _cocoa_subdriver->GetPixelBuffer(); _screen.dst_ptr = _cocoa_subdriver->GetPixelBuffer();
_fullscreen = _cocoa_subdriver->IsFullscreen(); _fullscreen = _cocoa_subdriver->IsFullscreen();
BlitterFactoryBase::GetCurrentBlitter()->PostResize(); BlitterFactory::GetCurrentBlitter()->PostResize();
GameSizeChanged(); GameSizeChanged();
} }
@ -461,7 +461,7 @@ const char *VideoDriver_Cocoa::Start(const char * const *parm)
int width = _cur_resolution.width; int width = _cur_resolution.width;
int height = _cur_resolution.height; int height = _cur_resolution.height;
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true); _cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true);
if (_cocoa_subdriver == NULL) { if (_cocoa_subdriver == NULL) {
@ -514,7 +514,7 @@ bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
{ {
assert(_cocoa_subdriver != NULL); assert(_cocoa_subdriver != NULL);
bool ret = _cocoa_subdriver->ChangeResolution(w, h, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()); bool ret = _cocoa_subdriver->ChangeResolution(w, h, BlitterFactory::GetCurrentBlitter()->GetScreenDepth());
QZ_GameSizeChanged(); QZ_GameSizeChanged();
QZ_UpdateVideoModes(); QZ_UpdateVideoModes();
@ -539,7 +539,7 @@ bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
if (full_screen != oldfs) { if (full_screen != oldfs) {
int width = _cocoa_subdriver->GetWidth(); int width = _cocoa_subdriver->GetWidth();
int height = _cocoa_subdriver->GetHeight(); int height = _cocoa_subdriver->GetHeight();
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
delete _cocoa_subdriver; delete _cocoa_subdriver;
_cocoa_subdriver = NULL; _cocoa_subdriver = NULL;

View File

@ -110,7 +110,7 @@ static void QZ_WarpCursor(int x, int y)
static void QZ_CheckPaletteAnim() static void QZ_CheckPaletteAnim()
{ {
if (_cur_palette.count_dirty != 0) { if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
switch (blitter->UsePaletteAnimation()) { switch (blitter->UsePaletteAnimation()) {
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:

View File

@ -144,14 +144,14 @@ static FVideoDriver_Dedicated iFVideoDriver_Dedicated;
const char *VideoDriver_Dedicated::Start(const char * const *parm) const char *VideoDriver_Dedicated::Start(const char * const *parm)
{ {
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
_dedicated_video_mem = (bpp == 0) ? NULL : MallocT<byte>(_cur_resolution.width * _cur_resolution.height * (bpp / 8)); _dedicated_video_mem = (bpp == 0) ? NULL : MallocT<byte>(_cur_resolution.width * _cur_resolution.height * (bpp / 8));
_screen.width = _screen.pitch = _cur_resolution.width; _screen.width = _screen.pitch = _cur_resolution.width;
_screen.height = _cur_resolution.height; _screen.height = _cur_resolution.height;
_screen.dst_ptr = _dedicated_video_mem; _screen.dst_ptr = _dedicated_video_mem;
ScreenSizeChanged(); ScreenSizeChanged();
BlitterFactoryBase::GetCurrentBlitter()->PostResize(); BlitterFactory::GetCurrentBlitter()->PostResize();
#if defined(WINCE) #if defined(WINCE)
/* WinCE doesn't support console stuff */ /* WinCE doesn't support console stuff */

View File

@ -32,7 +32,7 @@ const char *VideoDriver_Null::Start(const char * const *parm)
/* Do not render, nor blit */ /* Do not render, nor blit */
DEBUG(misc, 1, "Forcing blitter 'null'..."); DEBUG(misc, 1, "Forcing blitter 'null'...");
BlitterFactoryBase::SelectBlitter("null"); BlitterFactory::SelectBlitter("null");
return NULL; return NULL;
} }

View File

@ -123,7 +123,7 @@ static void InitPalette()
static void CheckPaletteAnim() static void CheckPaletteAnim()
{ {
if (_cur_palette.count_dirty != 0) { if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
switch (blitter->UsePaletteAnimation()) { switch (blitter->UsePaletteAnimation()) {
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
@ -270,7 +270,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
{ {
SDL_Surface *newscreen, *icon; SDL_Surface *newscreen, *icon;
char caption[50]; char caption[50];
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
bool want_hwpalette; bool want_hwpalette;
GetAvailableVideoMode(&w, &h); GetAvailableVideoMode(&w, &h);
@ -398,7 +398,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
* appropriate event to know this. */ * appropriate event to know this. */
if (_fullscreen) _cursor.in_window = true; if (_fullscreen) _cursor.in_window = true;
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
blitter->PostResize(); blitter->PostResize();
InitPalette(); InitPalette();

View File

@ -190,7 +190,7 @@ static void ClientSizeChanged(int w, int h)
_cur_palette.count_dirty = 256; _cur_palette.count_dirty = 256;
_local_palette = _cur_palette; _local_palette = _cur_palette;
BlitterFactoryBase::GetCurrentBlitter()->PostResize(); BlitterFactory::GetCurrentBlitter()->PostResize();
GameSizeChanged(); GameSizeChanged();
@ -279,7 +279,7 @@ bool VideoDriver_Win32::MakeWindow(bool full_screen)
DEVMODE settings; DEVMODE settings;
/* Make sure we are always at least the screen-depth of the blitter */ /* Make sure we are always at least the screen-depth of the blitter */
if (_fullscreen_bpp < BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) _fullscreen_bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); if (_fullscreen_bpp < BlitterFactory::GetCurrentBlitter()->GetScreenDepth()) _fullscreen_bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
memset(&settings, 0, sizeof(settings)); memset(&settings, 0, sizeof(settings));
settings.dmSize = sizeof(settings); settings.dmSize = sizeof(settings);
@ -360,7 +360,7 @@ bool VideoDriver_Win32::MakeWindow(bool full_screen)
} }
} }
BlitterFactoryBase::GetCurrentBlitter()->PostResize(); BlitterFactory::GetCurrentBlitter()->PostResize();
GameSizeChanged(); // invalidate all windows, force redraw GameSizeChanged(); // invalidate all windows, force redraw
return true; // the request succeeded return true; // the request succeeded
@ -374,7 +374,7 @@ static void PaintWindow(HDC dc)
HPALETTE old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE); HPALETTE old_palette = SelectPalette(dc, _wnd.gdi_palette, FALSE);
if (_cur_palette.count_dirty != 0) { if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
switch (blitter->UsePaletteAnimation()) { switch (blitter->UsePaletteAnimation()) {
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
@ -1060,7 +1060,7 @@ static bool AllocateDibSection(int w, int h, bool force)
{ {
BITMAPINFO *bi; BITMAPINFO *bi;
HDC dc; HDC dc;
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
w = max(w, 64); w = max(w, 64);
h = max(h, 64); h = max(h, 64);
@ -1080,7 +1080,7 @@ static bool AllocateDibSection(int w, int h, bool force)
bi->bmiHeader.biHeight = -(_wnd.height = h); bi->bmiHeader.biHeight = -(_wnd.height = h);
bi->bmiHeader.biPlanes = 1; bi->bmiHeader.biPlanes = 1;
bi->bmiHeader.biBitCount = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); bi->bmiHeader.biBitCount = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
bi->bmiHeader.biCompression = BI_RGB; bi->bmiHeader.biCompression = BI_RGB;
if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect); if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect);
@ -1121,7 +1121,7 @@ static void FindResolutions()
* Doesn't really matter since we don't pass a string anyways, but still * Doesn't really matter since we don't pass a string anyways, but still
* a letdown */ * a letdown */
for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) { for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) {
if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() && if (dm.dmBitsPerPel == BlitterFactory::GetCurrentBlitter()->GetScreenDepth() &&
dm.dmPelsWidth >= 640 && dm.dmPelsHeight >= 480) { dm.dmPelsWidth >= 640 && dm.dmPelsHeight >= 480) {
uint j; uint j;

View File

@ -1372,7 +1372,7 @@ static void ViewportDrawBoundingBoxes(const ParentSpriteToSortVector *psd)
*/ */
static void ViewportDrawDirtyBlocks() static void ViewportDrawDirtyBlocks()
{ {
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
const DrawPixelInfo *dpi = _cur_dpi; const DrawPixelInfo *dpi = _cur_dpi;
void *dst; void *dst;
int right = UnScaleByZoom(dpi->width, dpi->zoom); int right = UnScaleByZoom(dpi->width, dpi->zoom);
@ -1446,7 +1446,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
int x = UnScaleByZoom(_vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left; int x = UnScaleByZoom(_vd.dpi.left - (vp->virtual_left & mask), vp->zoom) + vp->left;
int y = UnScaleByZoom(_vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top; int y = UnScaleByZoom(_vd.dpi.top - (vp->virtual_top & mask), vp->zoom) + vp->top;
_vd.dpi.dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top); _vd.dpi.dst_ptr = BlitterFactory::GetCurrentBlitter()->MoveTo(old_dpi->dst_ptr, x - old_dpi->left, y - old_dpi->top);
ViewportAddLandscape(); ViewportAddLandscape();
ViewportAddVehicles(&_vd.dpi); ViewportAddVehicles(&_vd.dpi);

View File

@ -895,7 +895,7 @@ static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bo
dp->left = left - w->left; dp->left = left - w->left;
dp->top = top - w->top; dp->top = top - w->top;
dp->pitch = _screen.pitch; dp->pitch = _screen.pitch;
dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top); dp->dst_ptr = BlitterFactory::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
dp->zoom = ZOOM_LVL_NORMAL; dp->zoom = ZOOM_LVL_NORMAL;
w->OnPaint(); w->OnPaint();
} }
@ -2902,7 +2902,7 @@ void HandleMouseEvents()
if (click == MC_LEFT && _newgrf_debug_sprite_picker.mode == SPM_WAIT_CLICK) { if (click == MC_LEFT && _newgrf_debug_sprite_picker.mode == SPM_WAIT_CLICK) {
/* Mark whole screen dirty, and wait for the next realtime tick, when drawing is finished. */ /* Mark whole screen dirty, and wait for the next realtime tick, when drawing is finished. */
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); Blitter *blitter = BlitterFactory::GetCurrentBlitter();
_newgrf_debug_sprite_picker.clicked_pixel = blitter->MoveTo(_screen.dst_ptr, _cursor.pos.x, _cursor.pos.y); _newgrf_debug_sprite_picker.clicked_pixel = blitter->MoveTo(_screen.dst_ptr, _cursor.pos.x, _cursor.pos.y);
_newgrf_debug_sprite_picker.click_time = _realtime_tick; _newgrf_debug_sprite_picker.click_time = _realtime_tick;
_newgrf_debug_sprite_picker.sprites.Clear(); _newgrf_debug_sprite_picker.sprites.Clear();