Codechange: Pass replacement blitter name as string_view instead char *.

This commit is contained in:
Peter Nelson 2024-04-05 19:46:53 +01:00 committed by Peter Nelson
parent 6771dbe62b
commit 8e881471c1
2 changed files with 14 additions and 15 deletions

View File

@ -93,7 +93,7 @@ public:
* @param name the blitter to select.
* @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);
if (b == nullptr) return nullptr;
@ -111,17 +111,17 @@ public:
* @param name the blitter factory to select.
* @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)
const char *default_blitter = "null";
const std::string_view default_blitter = "null";
#elif defined(WITH_COCOA)
const char *default_blitter = "32bpp-anim";
const std::string_view default_blitter = "32bpp-anim";
#else
const char *default_blitter = "8bpp-optimized";
const std::string_view default_blitter = "8bpp-optimized";
#endif
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()) {
BlitterFactory *b = it.second;

View File

@ -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();
if (strcmp(cur_blitter, repl_blitter) == 0) return;
const std::string_view cur_blitter = BlitterFactory::GetCurrentBlitter()->GetName();
if (cur_blitter == repl_blitter) return;
Debug(driver, 1, "Switching blitter from '{}' to '{}'... ", cur_blitter, repl_blitter);
Blitter *new_blitter = BlitterFactory::SelectBlitter(repl_blitter);
@ -270,7 +270,7 @@ static bool SwitchNewGRFBlitter()
/* Search the best blitter. */
static const struct {
const char *name;
const std::string_view name;
uint animation; ///< 0: no support, 1: do support, 2: both
uint min_base_depth, max_base_depth, min_grf_depth, max_grf_depth;
} replacement_blitters[] = {
@ -290,7 +290,7 @@ static bool SwitchNewGRFBlitter()
};
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) {
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_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;
}
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. */
VideoDriver::GetInstance()->QueueOnMainThread(std::bind(&RealChangeBlitter, repl_blitter));
VideoDriver::GetInstance()->QueueOnMainThread(std::bind(&RealChangeBlitter, replacement_blitter.name));
break;
}