diff options
author | rubidium <rubidium@openttd.org> | 2014-01-02 22:41:58 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2014-01-02 22:41:58 +0000 |
commit | 2618d960e30882c097ba8b68249bbae974700ac8 (patch) | |
tree | 3d5a349c6a13f6f843d5f6b56456faf91010af5b /src/blitter | |
parent | 456dba4889108027f8af9c94514978d06012b6e7 (diff) | |
download | openttd-2618d960e30882c097ba8b68249bbae974700ac8.tar.xz |
(svn r26209) -Codechange: remove some template magic and simplify some code
Diffstat (limited to 'src/blitter')
-rw-r--r-- | src/blitter/32bpp_anim.hpp | 5 | ||||
-rw-r--r-- | src/blitter/32bpp_optimized.hpp | 5 | ||||
-rw-r--r-- | src/blitter/32bpp_simple.hpp | 5 | ||||
-rw-r--r-- | src/blitter/8bpp_optimized.hpp | 5 | ||||
-rw-r--r-- | src/blitter/8bpp_simple.hpp | 5 | ||||
-rw-r--r-- | src/blitter/factory.hpp | 66 | ||||
-rw-r--r-- | src/blitter/null.hpp | 5 |
7 files changed, 42 insertions, 54 deletions
diff --git a/src/blitter/32bpp_anim.hpp b/src/blitter/32bpp_anim.hpp index b0582e6ce..db5d614a0 100644 --- a/src/blitter/32bpp_anim.hpp +++ b/src/blitter/32bpp_anim.hpp @@ -56,10 +56,9 @@ public: }; /** Factory for the 32bpp blitter with animation. */ -class FBlitter_32bppAnim : public BlitterFactory<FBlitter_32bppAnim> { +class FBlitter_32bppAnim : public BlitterFactory { public: - /* virtual */ const char *GetName() { return "32bpp-anim"; } - /* virtual */ const char *GetDescription() { return "32bpp Animation Blitter (palette animation)"; } + FBlitter_32bppAnim() : BlitterFactory("32bpp-anim", "32bpp Animation Blitter (palette animation)") {} /* virtual */ Blitter *CreateInstance() { return new Blitter_32bppAnim(); } }; diff --git a/src/blitter/32bpp_optimized.hpp b/src/blitter/32bpp_optimized.hpp index f290f6cf6..c261aa33d 100644 --- a/src/blitter/32bpp_optimized.hpp +++ b/src/blitter/32bpp_optimized.hpp @@ -32,10 +32,9 @@ public: }; /** Factory for the optimised 32 bpp blitter (without palette animation). */ -class FBlitter_32bppOptimized : public BlitterFactory<FBlitter_32bppOptimized> { +class FBlitter_32bppOptimized : public BlitterFactory { public: - /* virtual */ const char *GetName() { return "32bpp-optimized"; } - /* virtual */ const char *GetDescription() { return "32bpp Optimized Blitter (no palette animation)"; } + FBlitter_32bppOptimized() : BlitterFactory("32bpp-optimized", "32bpp Optimized Blitter (no palette animation)") {} /* virtual */ Blitter *CreateInstance() { return new Blitter_32bppOptimized(); } }; diff --git a/src/blitter/32bpp_simple.hpp b/src/blitter/32bpp_simple.hpp index 49eaab56d..0751f6f75 100644 --- a/src/blitter/32bpp_simple.hpp +++ b/src/blitter/32bpp_simple.hpp @@ -34,10 +34,9 @@ public: }; /** Factory for the simple 32 bpp blitter. */ -class FBlitter_32bppSimple : public BlitterFactory<FBlitter_32bppSimple> { +class FBlitter_32bppSimple : public BlitterFactory { public: - /* virtual */ const char *GetName() { return "32bpp-simple"; } - /* virtual */ const char *GetDescription() { return "32bpp Simple Blitter (no palette animation)"; } + FBlitter_32bppSimple() : BlitterFactory("32bpp-simple", "32bpp Simple Blitter (no palette animation)") {} /* virtual */ Blitter *CreateInstance() { return new Blitter_32bppSimple(); } }; diff --git a/src/blitter/8bpp_optimized.hpp b/src/blitter/8bpp_optimized.hpp index 320e2b829..b5b5324b9 100644 --- a/src/blitter/8bpp_optimized.hpp +++ b/src/blitter/8bpp_optimized.hpp @@ -31,10 +31,9 @@ public: }; /** Factory for the 8bpp blitter optimised for speed. */ -class FBlitter_8bppOptimized : public BlitterFactory<FBlitter_8bppOptimized> { +class FBlitter_8bppOptimized : public BlitterFactory { public: - /* virtual */ const char *GetName() { return "8bpp-optimized"; } - /* virtual */ const char *GetDescription() { return "8bpp Optimized Blitter (compression + all-ZoomLevel cache)"; } + FBlitter_8bppOptimized() : BlitterFactory("8bpp-optimized", "8bpp Optimized Blitter (compression + all-ZoomLevel cache)") {} /* virtual */ Blitter *CreateInstance() { return new Blitter_8bppOptimized(); } }; diff --git a/src/blitter/8bpp_simple.hpp b/src/blitter/8bpp_simple.hpp index 28b33a280..c00c75ac0 100644 --- a/src/blitter/8bpp_simple.hpp +++ b/src/blitter/8bpp_simple.hpp @@ -25,10 +25,9 @@ public: }; /** Factory for the most trivial 8bpp blitter. */ -class FBlitter_8bppSimple : public BlitterFactory<FBlitter_8bppSimple> { +class FBlitter_8bppSimple : public BlitterFactory { public: - /* virtual */ const char *GetName() { return "8bpp-simple"; } - /* virtual */ const char *GetDescription() { return "8bpp Simple Blitter (relative slow, but never wrong)"; } + FBlitter_8bppSimple() : BlitterFactory("8bpp-simple", "8bpp Simple Blitter (relative slow, but never wrong)") {} /* virtual */ Blitter *CreateInstance() { return new Blitter_8bppSimple(); } }; diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp index eb8d0ce85..7fe498a67 100644 --- a/src/blitter/factory.hpp +++ b/src/blitter/factory.hpp @@ -25,11 +25,12 @@ bool QZ_CanDisplay8bpp(); /** * The base factory, keeping track of all blitters. */ -class BlitterFactoryBase { +class BlitterFactory { 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. @@ -53,32 +54,28 @@ private: protected: /** - * Register a blitter internally, based on his name. - * @param name the name of the blitter. - * @note an assert() will be trigger if 2 blitters with the same name try to register. + * Construct the blitter, and register it. + * @param name The name of the blitter. + * @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 */ - if (name == NULL) return; - - this->name = strdup(name); - - std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(name, this)); + std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(this->name, this)); assert(P.second); } public: - BlitterFactoryBase() : - name(NULL) - {} - - virtual ~BlitterFactoryBase() + virtual ~BlitterFactory() { - if (this->name == NULL) return; GetBlitters().erase(this->name); if (GetBlitters().empty()) delete &GetBlitters(); + free(this->name); + free(this->description); } /** @@ -108,7 +105,7 @@ public: Blitters::iterator it = GetBlitters().begin(); for (; it != GetBlitters().end(); it++) { - BlitterFactoryBase *b = (*it).second; + BlitterFactory *b = (*it).second; if (strcasecmp(bname, b->name) == 0) { Blitter *newb = b->CreateInstance(); delete *GetActiveBlitter(); @@ -140,7 +137,7 @@ public: p += seprintf(p, last, "List of blitters:\n"); Blitters::iterator it = GetBlitters().begin(); 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, "\n"); @@ -149,28 +146,25 @@ public: } /** - * Get a nice description of the blitter-class. + * Get the long, human readable, name for the Blitter-class. */ - virtual const char *GetDescription() = 0; + const char *GetName() const + { + return this->name; + } /** - * Create an instance of this Blitter-class. + * Get a nice description of the blitter-class. */ - virtual Blitter *CreateInstance() = 0; -}; - -/** - * A template factory, so ->GetName() works correctly. This because else some compiler will complain. - */ -template <class T> -class BlitterFactory : public BlitterFactoryBase { -public: - BlitterFactory() { this->RegisterBlitter(((T *)this)->GetName()); } + const char *GetDescription() const + { + return this->description; + } /** - * Get the long, human readable, name for the Blitter-class. + * Create an instance of this Blitter-class. */ - const char *GetName(); + virtual Blitter *CreateInstance() = 0; }; extern char *_ini_blitter; diff --git a/src/blitter/null.hpp b/src/blitter/null.hpp index f703cbd67..a6fed2ebc 100644 --- a/src/blitter/null.hpp +++ b/src/blitter/null.hpp @@ -38,10 +38,9 @@ public: }; /** Factory for the blitter that does nothing. */ -class FBlitter_Null : public BlitterFactory<FBlitter_Null> { +class FBlitter_Null : public BlitterFactory { public: - /* virtual */ const char *GetName() { return "null"; } - /* virtual */ const char *GetDescription() { return "Null Blitter (does nothing)"; } + FBlitter_Null() : BlitterFactory("null", "Null Blitter (does nothing)") {} /* virtual */ Blitter *CreateInstance() { return new Blitter_Null(); } }; |