diff --git a/src/openrct2/localisation/LocalisationService.cpp b/src/openrct2/localisation/LocalisationService.cpp index 15a1a23db6..db3683d51f 100644 --- a/src/openrct2/localisation/LocalisationService.cpp +++ b/src/openrct2/localisation/LocalisationService.cpp @@ -23,13 +23,13 @@ using namespace OpenRCT2; using namespace OpenRCT2::Localisation; -static constexpr rct_string_id NONSTEX_BASE_STRING_ID = 3463; -static constexpr uint16_t MAX_OBJECT_CACHED_STRINGS = 2048; +static constexpr uint16_t BASE_OBJECT_STRING_ID = 0x2000; +static constexpr uint16_t MAX_OBJECT_CACHED_STRINGS = 0x5000 - BASE_OBJECT_STRING_ID; LocalisationService::LocalisationService(const std::shared_ptr& env) : _env(env) { - for (rct_string_id stringId = NONSTEX_BASE_STRING_ID + MAX_OBJECT_CACHED_STRINGS; stringId >= NONSTEX_BASE_STRING_ID; + for (rct_string_id stringId = BASE_OBJECT_STRING_ID + MAX_OBJECT_CACHED_STRINGS; stringId >= BASE_OBJECT_STRING_ID; stringId--) { _availableObjectStringIds.push(stringId); @@ -48,6 +48,18 @@ const char* LocalisationService::GetString(rct_string_id id) const { result = ""; } + else if (id >= BASE_OBJECT_STRING_ID && id < BASE_OBJECT_STRING_ID + MAX_OBJECT_CACHED_STRINGS) + { + size_t index = id - BASE_OBJECT_STRING_ID; + if (index < _objectStrings.size()) + { + return _objectStrings[index].c_str(); + } + else + { + result = "(unallocated string)"; + } + } else if (id != STR_NONE) { if (_languageCurrent != nullptr) @@ -130,9 +142,21 @@ rct_string_id LocalisationService::GetObjectOverrideStringId(std::string_view le rct_string_id LocalisationService::AllocateObjectString(const std::string& target) { + if (_availableObjectStringIds.empty()) + { + return STR_EMPTY; + } + auto stringId = _availableObjectStringIds.top(); _availableObjectStringIds.pop(); - _languageCurrent->SetString(stringId, target); + + size_t index = stringId - BASE_OBJECT_STRING_ID; + if (index >= _objectStrings.size()) + { + _objectStrings.resize(index + 1); + } + _objectStrings[index] = target; + return stringId; } @@ -140,9 +164,10 @@ void LocalisationService::FreeObjectString(rct_string_id stringId) { if (stringId != STR_EMPTY) { - if (_languageCurrent != nullptr) + size_t index = stringId - BASE_OBJECT_STRING_ID; + if (index < _objectStrings.size()) { - _languageCurrent->RemoveString(stringId); + _objectStrings[index] = {}; } _availableObjectStringIds.push(stringId); } diff --git a/src/openrct2/localisation/LocalisationService.h b/src/openrct2/localisation/LocalisationService.h index c0fdef973c..565a7e2fb2 100644 --- a/src/openrct2/localisation/LocalisationService.h +++ b/src/openrct2/localisation/LocalisationService.h @@ -16,6 +16,7 @@ #include #include #include +#include struct ILanguagePack; struct IObjectManager; @@ -36,6 +37,7 @@ namespace OpenRCT2::Localisation std::unique_ptr _languageFallback; std::unique_ptr _languageCurrent; std::stack _availableObjectStringIds; + std::vector _objectStrings; public: int32_t GetCurrentLanguage() const