mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
Codechange: let AllocatedStringParameters allocated types too
This commit is contained in:
parent
f23249f8f1
commit
428333aeba
@ -58,9 +58,7 @@ TextDirection _current_text_dir; ///< Text direction of the currently selected l
|
|||||||
std::unique_ptr<icu::Collator> _current_collator; ///< Collator for the language currently in use.
|
std::unique_ptr<icu::Collator> _current_collator; ///< Collator for the language currently in use.
|
||||||
#endif /* WITH_ICU_I18N */
|
#endif /* WITH_ICU_I18N */
|
||||||
|
|
||||||
static uint64 _global_string_params_data[20]; ///< Global array of string parameters. To access, use #SetDParam.
|
AllocatedStringParameters _global_string_params(20);
|
||||||
static WChar _global_string_params_type[20]; ///< Type of parameters stored in #_global_string_params
|
|
||||||
StringParameters _global_string_params(_global_string_params_data, 20, _global_string_params_type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the string parameters for the next formatting run. This means
|
* Prepare the string parameters for the next formatting run. This means
|
||||||
@ -905,12 +903,8 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
|
|||||||
args.SetTypeOfNextParameter(b);
|
args.SetTypeOfNextParameter(b);
|
||||||
switch (b) {
|
switch (b) {
|
||||||
case SCC_ENCODED: {
|
case SCC_ENCODED: {
|
||||||
uint64 sub_args_data[20];
|
|
||||||
WChar sub_args_type[20];
|
|
||||||
bool sub_args_need_free[20];
|
bool sub_args_need_free[20];
|
||||||
StringParameters sub_args(sub_args_data, 20, sub_args_type);
|
AllocatedStringParameters sub_args(20);
|
||||||
|
|
||||||
sub_args.PrepareForNextRun(); // Needed to reset the currently undefined types
|
|
||||||
memset(sub_args_need_free, 0, sizeof(sub_args_need_free));
|
memset(sub_args_need_free, 0, sizeof(sub_args_need_free));
|
||||||
|
|
||||||
char *p;
|
char *p;
|
||||||
@ -1400,9 +1394,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
|
|||||||
case SCC_DEPOT_NAME: { // {DEPOT}
|
case SCC_DEPOT_NAME: { // {DEPOT}
|
||||||
VehicleType vt = (VehicleType)args.GetInt32();
|
VehicleType vt = (VehicleType)args.GetInt32();
|
||||||
if (vt == VEH_AIRCRAFT) {
|
if (vt == VEH_AIRCRAFT) {
|
||||||
uint64 args_array[] = {(uint64)args.GetInt32()};
|
StringParameters tmp_params = StringParameters(args, 1);
|
||||||
WChar types_array[] = {SCC_STATION_NAME};
|
|
||||||
StringParameters tmp_params(args_array, 1, types_array);
|
|
||||||
GetStringWithArgs(builder, STR_FORMAT_DEPOT_NAME_AIRCRAFT, tmp_params);
|
GetStringWithArgs(builder, STR_FORMAT_DEPOT_NAME_AIRCRAFT, tmp_params);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1437,9 +1429,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
|
|||||||
assert(grffile != nullptr);
|
assert(grffile != nullptr);
|
||||||
|
|
||||||
StartTextRefStackUsage(grffile, 6);
|
StartTextRefStackUsage(grffile, 6);
|
||||||
uint64 tmp_dparam[6] = { 0 };
|
AllocatedStringParameters tmp_params(6);
|
||||||
WChar tmp_type[6] = { 0 };
|
|
||||||
StringParameters tmp_params(tmp_dparam, 6, tmp_type);
|
|
||||||
GetStringWithArgs(builder, GetGRFStringID(grffile->grfid, 0xD000 + callback), tmp_params);
|
GetStringWithArgs(builder, GetGRFStringID(grffile->grfid, 0xD000 + callback), tmp_params);
|
||||||
StopTextRefStackUsage();
|
StopTextRefStackUsage();
|
||||||
|
|
||||||
@ -1536,9 +1526,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 args_array[] = {STR_TOWN_NAME, st->town->index, st->index};
|
auto tmp_params = MakeParameters(STR_TOWN_NAME, st->town->index, st->index);
|
||||||
WChar types_array[] = {0, SCC_TOWN_NAME, SCC_NUM};
|
|
||||||
StringParameters tmp_params(args_array, 3, types_array);
|
|
||||||
GetStringWithArgs(builder, string_id, tmp_params);
|
GetStringWithArgs(builder, string_id, tmp_params);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -15,24 +15,23 @@
|
|||||||
|
|
||||||
class StringParameters {
|
class StringParameters {
|
||||||
protected:
|
protected:
|
||||||
StringParameters *parent; ///< If not nullptr, this instance references data from this parent instance.
|
StringParameters *parent = nullptr; ///< If not nullptr, this instance references data from this parent instance.
|
||||||
uint64 *data; ///< Array with the actual data.
|
uint64 *data; ///< Array with the actual data.
|
||||||
WChar *type; ///< Array with type information about the data. Can be nullptr when no type information is needed. See #StringControlCode.
|
WChar *type; ///< Array with type information about the data. Can be nullptr when no type information is needed. See #StringControlCode.
|
||||||
|
|
||||||
WChar next_type = 0; ///< The type of the next data that is retrieved.
|
WChar next_type = 0; ///< The type of the next data that is retrieved.
|
||||||
size_t offset = 0; ///< Current offset in the data/type arrays.
|
size_t offset = 0; ///< Current offset in the data/type arrays.
|
||||||
|
|
||||||
public:
|
|
||||||
size_t num_param; ///< Length of the data array.
|
|
||||||
|
|
||||||
/** Create a new StringParameters instance. */
|
/** Create a new StringParameters instance. */
|
||||||
StringParameters(uint64 *data, size_t num_param, WChar *type) :
|
StringParameters(uint64 *data, size_t num_param, WChar *type) :
|
||||||
parent(nullptr),
|
|
||||||
data(data),
|
data(data),
|
||||||
type(type),
|
type(type),
|
||||||
num_param(num_param)
|
num_param(num_param)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
public:
|
||||||
|
size_t num_param; ///< Length of the data array.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new StringParameters instance that can reference part of the data of
|
* Create a new StringParameters instance that can reference part of the data of
|
||||||
* the given partent instance.
|
* the given partent instance.
|
||||||
@ -169,11 +168,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
class AllocatedStringParameters : public StringParameters {
|
class AllocatedStringParameters : public StringParameters {
|
||||||
std::vector<uint64_t> params; ///< The actual parameters
|
std::vector<uint64_t> params; ///< The actual parameters
|
||||||
|
std::vector<WChar> types; ///< The actual types.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AllocatedStringParameters(size_t parameters = 0) : StringParameters(nullptr, parameters, nullptr), params(parameters)
|
AllocatedStringParameters(size_t parameters = 0) : StringParameters(nullptr, parameters, nullptr), params(parameters), types(parameters)
|
||||||
{
|
{
|
||||||
this->data = params.data();
|
this->data = params.data();
|
||||||
|
this->type = types.data();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user