Files
@ r22022:571e71b3a177
Branch filter:
Location: cpp/openttd-patchpack/source/src/blitter/factory.hpp - annotation
r22022:571e71b3a177
5.5 KiB
text/x-c++hdr
(svn r27179) -Update from WebTranslator v3.0:
afrikaans - 10 changes by telanus
croatian - 4 changes by VoyagerOne
finnish - 4 changes by jpx_
hebrew - 9 changes by oofnik
italian - 3 changes by lorenzodv
korean - 11 changes by Gimel3830, telk5093
lithuanian - 4 changes by Stabilitronas
polish - 4 changes by wojteks86
romanian - 29 changes by kneekoo
gaelic - 4 changes by GunChleoc
slovak - 17 changes by Milsa
spanish - 4 changes by SilverSurferZzZ
afrikaans - 10 changes by telanus
croatian - 4 changes by VoyagerOne
finnish - 4 changes by jpx_
hebrew - 9 changes by oofnik
italian - 3 changes by lorenzodv
korean - 11 changes by Gimel3830, telk5093
lithuanian - 4 changes by Stabilitronas
polish - 4 changes by wojteks86
romanian - 29 changes by kneekoo
gaelic - 4 changes by GunChleoc
slovak - 17 changes by Milsa
spanish - 4 changes by SilverSurferZzZ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | r6937:bea726150bf3 r6937:bea726150bf3 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r9111:983de9c5a848 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r7568:fc1eeb32558c r8214:9a3935f9ef4e r10985:c2507f106432 r6937:bea726150bf3 r6937:bea726150bf3 r9884:3e8f194db218 r9884:3e8f194db218 r9884:3e8f194db218 r9884:3e8f194db218 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r21124:6022cb131374 r6937:bea726150bf3 r21124:6022cb131374 r21124:6022cb131374 r17617:7646682fc2c9 r21124:6022cb131374 r9582:cb7711765a81 r17617:7646682fc2c9 r17617:7646682fc2c9 r17617:7646682fc2c9 r17617:7646682fc2c9 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r17617:7646682fc2c9 r17617:7646682fc2c9 r17617:7646682fc2c9 r17617:7646682fc2c9 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r21125:bef7b6aba27b r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r6937:bea726150bf3 r21125:bef7b6aba27b r21410:ae5961f02724 r6937:bea726150bf3 r21125:bef7b6aba27b r21125:bef7b6aba27b r21125:bef7b6aba27b r21125:bef7b6aba27b r21125:bef7b6aba27b r21125:bef7b6aba27b r21125:bef7b6aba27b r21125:bef7b6aba27b r21125:bef7b6aba27b r21125:bef7b6aba27b r21125:bef7b6aba27b r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r21124:6022cb131374 r9294:d468ad712ebe r9294:d468ad712ebe r9294:d468ad712ebe r21124:6022cb131374 r18352:6c15d75d1ab9 r21124:6022cb131374 r9294:d468ad712ebe r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r21130:9cc482d59226 r10620:842b08a1d426 r10620:842b08a1d426 r10620:842b08a1d426 r7567:345990e41454 r7567:345990e41454 r9884:3e8f194db218 r9884:3e8f194db218 r9884:3e8f194db218 r9884:3e8f194db218 r9884:3e8f194db218 r9884:3e8f194db218 r9561:373f1b581232 r9561:373f1b581232 r9884:3e8f194db218 r10620:842b08a1d426 r6937:bea726150bf3 r7567:345990e41454 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r21124:6022cb131374 r7567:345990e41454 r21130:9cc482d59226 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r17617:7646682fc2c9 r17617:7646682fc2c9 r17617:7646682fc2c9 r17617:7646682fc2c9 r17617:7646682fc2c9 r17617:7646682fc2c9 r6937:bea726150bf3 r6937:bea726150bf3 r10299:def8dff34f3b r6937:bea726150bf3 r6937:bea726150bf3 r21124:6022cb131374 r10299:def8dff34f3b r6937:bea726150bf3 r10299:def8dff34f3b r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r6937:bea726150bf3 r6937:bea726150bf3 r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r21124:6022cb131374 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r6937:bea726150bf3 r10615:151b5d3fccb0 r18161:7dcc16c70ffe r8275:5932486ddd21 r6937:bea726150bf3 | /* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file factory.hpp Factory to 'query' all available blitters. */
#ifndef BLITTER_FACTORY_HPP
#define BLITTER_FACTORY_HPP
#include "base.hpp"
#include "../debug.h"
#include "../string_func.h"
#include "../core/string_compare_type.hpp"
#include <map>
#if defined(WITH_COCOA)
bool QZ_CanDisplay8bpp();
#endif /* defined(WITH_COCOA) */
/**
* The base factory, keeping track of all blitters.
*/
class BlitterFactory {
private:
const char *name; ///< The name of the blitter factory.
const char *description; ///< The description of the blitter.
typedef std::map<const char *, BlitterFactory *, 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;
return &s_blitter;
}
protected:
/**
* Construct the blitter, and register it.
* @param name The name of the blitter.
* @param description A longer description for the blitter.
* @param usable Whether the blitter is usable (on the current computer). For example for disabling SSE blitters when the CPU can't handle them.
* @pre name != NULL.
* @pre description != NULL.
* @pre There is no blitter registered with this name.
*/
BlitterFactory(const char *name, const char *description, bool usable = true) :
name(stredup(name)), description(stredup(description))
{
if (usable) {
/*
* Only add when the blitter is usable. Do not bail out or
* do more special things since the blitters are always
* instantiated upon start anyhow and freed upon shutdown.
*/
std::pair<Blitters::iterator, bool> P = GetBlitters().insert(Blitters::value_type(this->name, this));
assert(P.second);
} else {
DEBUG(driver, 1, "Not registering blitter %s as it is not usable", name);
}
}
public:
virtual ~BlitterFactory()
{
GetBlitters().erase(this->name);
if (GetBlitters().empty()) delete &GetBlitters();
free(this->name);
free(this->description);
}
/**
* Find the requested blitter and return his class.
* @param name the blitter to select.
* @post Sets the blitter so GetCurrentBlitter() returns it too.
*/
static Blitter *SelectBlitter(const char *name)
{
BlitterFactory *b = GetBlitterFactory(name);
if (b == NULL) return NULL;
Blitter *newb = b->CreateInstance();
delete *GetActiveBlitter();
*GetActiveBlitter() = newb;
DEBUG(driver, 1, "Successfully %s blitter '%s'", StrEmpty(name) ? "probed" : "loaded", newb->GetName());
return newb;
}
/**
* Get the blitter factory with the given name.
* @param name the blitter factory to select.
* @return The blitter factory, or NULL when there isn't one with the wanted name.
*/
static BlitterFactory *GetBlitterFactory(const char *name)
{
#if defined(DEDICATED)
const char *default_blitter = "null";
#else
const char *default_blitter = "8bpp-optimized";
#if defined(WITH_COCOA)
/* Some people reported lack of fullscreen support in 8 bpp mode.
* While we prefer 8 bpp since it's faster, we will still have to test for support. */
if (!QZ_CanDisplay8bpp()) {
/* The main display can't go to 8 bpp fullscreen mode.
* We will have to switch to 32 bpp by default. */
default_blitter = "32bpp-anim";
}
#endif /* defined(WITH_COCOA) */
#endif /* defined(DEDICATED) */
if (GetBlitters().size() == 0) return NULL;
const char *bname = (StrEmpty(name)) ? default_blitter : name;
Blitters::iterator it = GetBlitters().begin();
for (; it != GetBlitters().end(); it++) {
BlitterFactory *b = (*it).second;
if (strcasecmp(bname, b->name) == 0) {
return b;
}
}
return NULL;
}
/**
* Get the current active blitter (always set by calling SelectBlitter).
*/
static Blitter *GetCurrentBlitter()
{
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");
Blitters::iterator it = GetBlitters().begin();
for (; it != GetBlitters().end(); it++) {
BlitterFactory *b = (*it).second;
p += seprintf(p, last, "%18s: %s\n", b->name, b->GetDescription());
}
p += seprintf(p, last, "\n");
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.
*/
const char *GetDescription() const
{
return this->description;
}
/**
* Create an instance of this Blitter-class.
*/
virtual Blitter *CreateInstance() = 0;
};
extern char *_ini_blitter;
extern bool _blitter_autodetected;
#endif /* BLITTER_FACTORY_HPP */
|