Update to 14.0-beta1
This commit is contained in:
@@ -14,13 +14,15 @@
|
||||
#include "string_type.h"
|
||||
#include "gfx_type.h"
|
||||
#include "core/bitmath_func.hpp"
|
||||
#include "core/strong_typedef_type.hpp"
|
||||
#include "vehicle_type.h"
|
||||
|
||||
/**
|
||||
* Extract the StringTab from a StringID.
|
||||
* @param str String identifier
|
||||
* @return StringTab from \a str
|
||||
*/
|
||||
static inline StringTab GetStringTab(StringID str)
|
||||
inline StringTab GetStringTab(StringID str)
|
||||
{
|
||||
StringTab result = (StringTab)(str >> TAB_SIZE_BITS);
|
||||
if (result >= TEXT_TAB_NEWGRF_START) return TEXT_TAB_NEWGRF_START;
|
||||
@@ -33,7 +35,7 @@ static inline StringTab GetStringTab(StringID str)
|
||||
* @param str String identifier
|
||||
* @return StringIndex from \a str
|
||||
*/
|
||||
static inline uint GetStringIndex(StringID str)
|
||||
inline uint GetStringIndex(StringID str)
|
||||
{
|
||||
return str - (GetStringTab(str) << TAB_SIZE_BITS);
|
||||
}
|
||||
@@ -44,7 +46,7 @@ static inline uint GetStringIndex(StringID str)
|
||||
* @param index StringIndex
|
||||
* @return StringID composed from \a tab and \a index
|
||||
*/
|
||||
static inline StringID MakeStringID(StringTab tab, uint index)
|
||||
inline StringID MakeStringID(StringTab tab, uint index)
|
||||
{
|
||||
if (tab == TEXT_TAB_NEWGRF_START) {
|
||||
assert(index < TAB_SIZE_NEWGRF);
|
||||
@@ -57,199 +59,69 @@ static inline StringID MakeStringID(StringTab tab, uint index)
|
||||
return (tab << TAB_SIZE_BITS) + index;
|
||||
}
|
||||
|
||||
class StringParameters {
|
||||
StringParameters *parent; ///< If not nullptr, this instance references data from this parent instance.
|
||||
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.
|
||||
|
||||
public:
|
||||
uint offset; ///< Current offset in the data/type arrays.
|
||||
uint num_param; ///< Length of the data array.
|
||||
|
||||
/** Create a new StringParameters instance. */
|
||||
StringParameters(uint64 *data, uint num_param, WChar *type) :
|
||||
parent(nullptr),
|
||||
data(data),
|
||||
type(type),
|
||||
offset(0),
|
||||
num_param(num_param)
|
||||
{ }
|
||||
|
||||
/** Create a new StringParameters instance. */
|
||||
template <size_t Tnum_param>
|
||||
StringParameters(int64 (&data)[Tnum_param]) :
|
||||
parent(nullptr),
|
||||
data((uint64 *)data),
|
||||
type(nullptr),
|
||||
offset(0),
|
||||
num_param(Tnum_param)
|
||||
{
|
||||
static_assert(sizeof(data[0]) == sizeof(uint64));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new StringParameters instance that can reference part of the data of
|
||||
* the given partent instance.
|
||||
*/
|
||||
StringParameters(StringParameters &parent, uint size) :
|
||||
parent(&parent),
|
||||
data(parent.data + parent.offset),
|
||||
offset(0),
|
||||
num_param(size)
|
||||
{
|
||||
assert(size <= parent.GetDataLeft());
|
||||
if (parent.type == nullptr) {
|
||||
this->type = nullptr;
|
||||
} else {
|
||||
this->type = parent.type + parent.offset;
|
||||
}
|
||||
}
|
||||
|
||||
~StringParameters()
|
||||
{
|
||||
if (this->parent != nullptr) {
|
||||
this->parent->offset += this->num_param;
|
||||
}
|
||||
}
|
||||
|
||||
void ClearTypeInformation();
|
||||
|
||||
int64 GetInt64(WChar type = 0);
|
||||
|
||||
/** Read an int32 from the argument array. @see GetInt64. */
|
||||
int32 GetInt32(WChar type = 0)
|
||||
{
|
||||
return (int32)this->GetInt64(type);
|
||||
}
|
||||
|
||||
/** Get a pointer to the current element in the data array. */
|
||||
uint64 *GetDataPointer() const
|
||||
{
|
||||
return &this->data[this->offset];
|
||||
}
|
||||
|
||||
/** Return the amount of elements which can still be read. */
|
||||
uint GetDataLeft() const
|
||||
{
|
||||
return this->num_param - this->offset;
|
||||
}
|
||||
|
||||
/** Get a pointer to a specific element in the data array. */
|
||||
uint64 *GetPointerToOffset(uint offset) const
|
||||
{
|
||||
assert(offset < this->num_param);
|
||||
return &this->data[offset];
|
||||
}
|
||||
|
||||
/** Does this instance store information about the type of the parameters. */
|
||||
bool HasTypeInformation() const
|
||||
{
|
||||
return this->type != nullptr;
|
||||
}
|
||||
|
||||
/** Get the type of a specific element. */
|
||||
WChar GetTypeAtOffset(uint offset) const
|
||||
{
|
||||
assert(offset < this->num_param);
|
||||
assert(this->HasTypeInformation());
|
||||
return this->type[offset];
|
||||
}
|
||||
|
||||
void SetParam(uint n, uint64 v)
|
||||
{
|
||||
assert(n < this->num_param);
|
||||
this->data[n] = v;
|
||||
}
|
||||
|
||||
uint64 GetParam(uint n) const
|
||||
{
|
||||
assert(n < this->num_param);
|
||||
return this->data[n];
|
||||
}
|
||||
};
|
||||
extern StringParameters _global_string_params;
|
||||
|
||||
char *GetString(char *buffr, StringID string, const char *last);
|
||||
std::string GetString(StringID string);
|
||||
char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index = 0, bool game_script = false);
|
||||
const char *GetStringPtr(StringID string);
|
||||
|
||||
uint ConvertKmhishSpeedToDisplaySpeed(uint speed);
|
||||
uint ConvertDisplaySpeedToKmhishSpeed(uint speed);
|
||||
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type);
|
||||
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type);
|
||||
|
||||
/**
|
||||
* Set a string parameter \a v at index \a n in a given array \a s.
|
||||
* @param s Array of string parameters.
|
||||
* @param n Index of the string parameter.
|
||||
* @param v Value of the string parameter.
|
||||
* Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
|
||||
* @param speed Display speed for parameter.
|
||||
* @param type Type of vehicle for parameter.
|
||||
* @return Bit-packed velocity and vehicle type, for use with SetDParam().
|
||||
*/
|
||||
static inline void SetDParamX(uint64 *s, uint n, uint64 v)
|
||||
inline int64_t PackVelocity(uint speed, VehicleType type)
|
||||
{
|
||||
s[n] = v;
|
||||
/* Vehicle type is a byte, so packed into the top 8 bits of the 64-bit
|
||||
* parameter, although only values from 0-3 are relevant. */
|
||||
return speed | (static_cast<uint64_t>(type) << 56);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a string parameter \a v at index \a n in the global string parameter array.
|
||||
* @param n Index of the string parameter.
|
||||
* @param v Value of the string parameter.
|
||||
*/
|
||||
static inline void SetDParam(uint n, uint64 v)
|
||||
void SetDParam(size_t n, uint64_t v);
|
||||
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count = 0, FontSize size = FS_NORMAL);
|
||||
void SetDParamMaxDigits(size_t n, uint count, FontSize size = FS_NORMAL);
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
||||
void SetDParam(size_t n, T v)
|
||||
{
|
||||
_global_string_params.SetParam(n, v);
|
||||
SetDParam(n, v.base());
|
||||
}
|
||||
|
||||
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count = 0, FontSize size = FS_NORMAL);
|
||||
void SetDParamMaxDigits(uint n, uint count, FontSize size = FS_NORMAL);
|
||||
|
||||
void SetDParamStr(uint n, const char *str);
|
||||
void SetDParamStr(uint n, const std::string &str);
|
||||
void SetDParamStr(uint n, std::string &&str) = delete; // block passing temporaries to SetDParamStr
|
||||
|
||||
void CopyInDParam(int offs, const uint64 *src, int num);
|
||||
void CopyOutDParam(uint64 *dst, int offs, int num);
|
||||
void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
|
||||
|
||||
/**
|
||||
* Get the current string parameter at index \a n from parameter array \a s.
|
||||
* @param s Array of string parameters.
|
||||
* @param n Index of the string parameter.
|
||||
* @return Value of the requested string parameter.
|
||||
*/
|
||||
static inline uint64 GetDParamX(const uint64 *s, uint n)
|
||||
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
||||
void SetDParamMaxValue(size_t n, T max_value, uint min_count = 0, FontSize size = FS_NORMAL)
|
||||
{
|
||||
return s[n];
|
||||
SetDParamMaxValue(n, max_value.base(), min_count, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current string parameter at index \a n from the global string parameter array.
|
||||
* @param n Index of the string parameter.
|
||||
* @return Value of the requested string parameter.
|
||||
*/
|
||||
static inline uint64 GetDParam(uint n)
|
||||
{
|
||||
return _global_string_params.GetParam(n);
|
||||
}
|
||||
void SetDParamStr(size_t n, const char *str);
|
||||
void SetDParamStr(size_t n, const std::string &str);
|
||||
void SetDParamStr(size_t n, std::string &&str);
|
||||
|
||||
void CopyInDParam(const std::span<const StringParameterBackup> backup);
|
||||
void CopyOutDParam(std::vector<StringParameterBackup> &backup, size_t num);
|
||||
bool HaveDParamChanged(const std::vector<StringParameterBackup> &backup);
|
||||
|
||||
uint64_t GetDParam(size_t n);
|
||||
|
||||
extern TextDirection _current_text_dir; ///< Text direction of the currently selected language
|
||||
|
||||
void InitializeLanguagePacks();
|
||||
const char *GetCurrentLanguageIsoCode();
|
||||
|
||||
bool StringIDSorter(const StringID &a, const StringID &b);
|
||||
|
||||
/**
|
||||
* A searcher for missing glyphs.
|
||||
*/
|
||||
class MissingGlyphSearcher {
|
||||
public:
|
||||
/** Make sure everything gets destructed right. */
|
||||
virtual ~MissingGlyphSearcher() {}
|
||||
virtual ~MissingGlyphSearcher() = default;
|
||||
|
||||
/**
|
||||
* Get the next string to search through.
|
||||
* @return The next string or nullptr if there is none.
|
||||
* @return The next string or nullopt if there is none.
|
||||
*/
|
||||
virtual const char *NextString() = 0;
|
||||
virtual std::optional<std::string_view> NextString() = 0;
|
||||
|
||||
/**
|
||||
* Get the default (font) size of the string.
|
||||
|
||||
Reference in New Issue
Block a user