mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use cached name for all station/industry/town name formatting. (#10634)
This reuses an existing name caching mechanism to avoid "recalculating" names every time.pull/10639/head
parent
d7f0c5d6d8
commit
3b2eb11fe8
|
@ -35,6 +35,7 @@
|
|||
#include "game/game_text.hpp"
|
||||
#include "network/network_content_gui.h"
|
||||
#include "newgrf_engine.h"
|
||||
#include "core/backup_type.hpp"
|
||||
#include <stack>
|
||||
|
||||
#include "table/strings.h"
|
||||
|
@ -1456,7 +1457,11 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
|||
const Industry *i = Industry::GetIfValid(args->GetInt32(SCC_INDUSTRY_NAME));
|
||||
if (i == nullptr) break;
|
||||
|
||||
if (_scan_for_gender_data) {
|
||||
static bool use_cache = true;
|
||||
if (use_cache) { // Use cached version if first call
|
||||
AutoRestoreBackup cache_backup(use_cache, false);
|
||||
buff = strecpy(buff, i->GetCachedName(), last);
|
||||
} else if (_scan_for_gender_data) {
|
||||
/* Gender is defined by the industry type.
|
||||
* STR_FORMAT_INDUSTRY_NAME may have the town first, so it would result in the gender of the town name */
|
||||
StringParameters tmp_params(nullptr, 0, nullptr);
|
||||
|
@ -1501,7 +1506,11 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
|||
break;
|
||||
}
|
||||
|
||||
if (!st->name.empty()) {
|
||||
static bool use_cache = true;
|
||||
if (use_cache) { // Use cached version if first call
|
||||
AutoRestoreBackup cache_backup(use_cache, false);
|
||||
buff = strecpy(buff, st->GetCachedName(), last);
|
||||
} else if (!st->name.empty()) {
|
||||
int64 args_array[] = {(int64)(size_t)st->name.c_str()};
|
||||
StringParameters tmp_params(args_array);
|
||||
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
|
||||
|
@ -1531,7 +1540,11 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
|||
const Town *t = Town::GetIfValid(args->GetInt32(SCC_TOWN_NAME));
|
||||
if (t == nullptr) break;
|
||||
|
||||
if (!t->name.empty()) {
|
||||
static bool use_cache = true;
|
||||
if (use_cache) { // Use cached version if first call
|
||||
AutoRestoreBackup cache_backup(use_cache, false);
|
||||
buff = strecpy(buff, t->GetCachedName(), last);
|
||||
} else if (!t->name.empty()) {
|
||||
int64 args_array[] = {(int64)(size_t)t->name.c_str()};
|
||||
StringParameters tmp_params(args_array);
|
||||
buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last);
|
||||
|
|
Loading…
Reference in New Issue