mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Pass replacement blitter name as string_view instead char *.
This commit is contained in:
parent
6771dbe62b
commit
8e881471c1
|
@ -93,7 +93,7 @@ public:
|
||||||
* @param name the blitter to select.
|
* @param name the blitter to select.
|
||||||
* @post Sets the blitter so GetCurrentBlitter() returns it too.
|
* @post Sets the blitter so GetCurrentBlitter() returns it too.
|
||||||
*/
|
*/
|
||||||
static Blitter *SelectBlitter(const std::string &name)
|
static Blitter *SelectBlitter(const std::string_view name)
|
||||||
{
|
{
|
||||||
BlitterFactory *b = GetBlitterFactory(name);
|
BlitterFactory *b = GetBlitterFactory(name);
|
||||||
if (b == nullptr) return nullptr;
|
if (b == nullptr) return nullptr;
|
||||||
|
@ -111,17 +111,17 @@ public:
|
||||||
* @param name the blitter factory to select.
|
* @param name the blitter factory to select.
|
||||||
* @return The blitter factory, or nullptr when there isn't one with the wanted name.
|
* @return The blitter factory, or nullptr when there isn't one with the wanted name.
|
||||||
*/
|
*/
|
||||||
static BlitterFactory *GetBlitterFactory(const std::string &name)
|
static BlitterFactory *GetBlitterFactory(const std::string_view name)
|
||||||
{
|
{
|
||||||
#if defined(DEDICATED)
|
#if defined(DEDICATED)
|
||||||
const char *default_blitter = "null";
|
const std::string_view default_blitter = "null";
|
||||||
#elif defined(WITH_COCOA)
|
#elif defined(WITH_COCOA)
|
||||||
const char *default_blitter = "32bpp-anim";
|
const std::string_view default_blitter = "32bpp-anim";
|
||||||
#else
|
#else
|
||||||
const char *default_blitter = "8bpp-optimized";
|
const std::string_view default_blitter = "8bpp-optimized";
|
||||||
#endif
|
#endif
|
||||||
if (GetBlitters().empty()) return nullptr;
|
if (GetBlitters().empty()) return nullptr;
|
||||||
const char *bname = name.empty() ? default_blitter : name.c_str();
|
const std::string_view bname = name.empty() ? default_blitter : name;
|
||||||
|
|
||||||
for (auto &it : GetBlitters()) {
|
for (auto &it : GetBlitters()) {
|
||||||
BlitterFactory *b = it.second;
|
BlitterFactory *b = it.second;
|
||||||
|
|
|
@ -219,10 +219,10 @@ static void LoadSpriteTables()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void RealChangeBlitter(const char *repl_blitter)
|
static void RealChangeBlitter(const std::string_view repl_blitter)
|
||||||
{
|
{
|
||||||
const char *cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
|
const std::string_view cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
|
||||||
if (strcmp(cur_blitter, repl_blitter) == 0) return;
|
if (cur_blitter == repl_blitter) return;
|
||||||
|
|
||||||
Debug(driver, 1, "Switching blitter from '{}' to '{}'... ", cur_blitter, repl_blitter);
|
Debug(driver, 1, "Switching blitter from '{}' to '{}'... ", cur_blitter, repl_blitter);
|
||||||
Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter);
|
Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter);
|
||||||
|
@ -270,7 +270,7 @@ static bool SwitchNewGRFBlitter()
|
||||||
|
|
||||||
/* Search the best blitter. */
|
/* Search the best blitter. */
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *name;
|
const std::string_view name;
|
||||||
uint animation; ///< 0: no support, 1: do support, 2: both
|
uint animation; ///< 0: no support, 1: do support, 2: both
|
||||||
uint min_base_depth, max_base_depth, min_grf_depth, max_grf_depth;
|
uint min_base_depth, max_base_depth, min_grf_depth, max_grf_depth;
|
||||||
} replacement_blitters[] = {
|
} replacement_blitters[] = {
|
||||||
|
@ -290,7 +290,7 @@ static bool SwitchNewGRFBlitter()
|
||||||
};
|
};
|
||||||
|
|
||||||
const bool animation_wanted = HasBit(_display_opt, DO_FULL_ANIMATION);
|
const bool animation_wanted = HasBit(_display_opt, DO_FULL_ANIMATION);
|
||||||
const char *cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
|
const std::string_view cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
|
||||||
|
|
||||||
for (const auto &replacement_blitter : replacement_blitters) {
|
for (const auto &replacement_blitter : replacement_blitters) {
|
||||||
if (animation_wanted && (replacement_blitter.animation == 0)) continue;
|
if (animation_wanted && (replacement_blitter.animation == 0)) continue;
|
||||||
|
@ -298,15 +298,14 @@ static bool SwitchNewGRFBlitter()
|
||||||
|
|
||||||
if (!IsInsideMM(depth_wanted_by_base, replacement_blitter.min_base_depth, replacement_blitter.max_base_depth + 1)) continue;
|
if (!IsInsideMM(depth_wanted_by_base, replacement_blitter.min_base_depth, replacement_blitter.max_base_depth + 1)) continue;
|
||||||
if (!IsInsideMM(depth_wanted_by_grf, replacement_blitter.min_grf_depth, replacement_blitter.max_grf_depth + 1)) continue;
|
if (!IsInsideMM(depth_wanted_by_grf, replacement_blitter.min_grf_depth, replacement_blitter.max_grf_depth + 1)) continue;
|
||||||
const char *repl_blitter = replacement_blitter.name;
|
|
||||||
|
|
||||||
if (strcmp(repl_blitter, cur_blitter) == 0) {
|
if (replacement_blitter.name == cur_blitter) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (BlitterFactory::GetBlitterFactory(repl_blitter) == nullptr) continue;
|
if (BlitterFactory::GetBlitterFactory(replacement_blitter.name) == nullptr) continue;
|
||||||
|
|
||||||
/* Inform the video driver we want to switch blitter as soon as possible. */
|
/* Inform the video driver we want to switch blitter as soon as possible. */
|
||||||
VideoDriver::GetInstance()->QueueOnMainThread(std::bind(&RealChangeBlitter, repl_blitter));
|
VideoDriver::GetInstance()->QueueOnMainThread(std::bind(&RealChangeBlitter, replacement_blitter.name));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue