1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-18 04:23:20 +01:00

Improve object string handling, allow more strings

This commit is contained in:
Ted John
2021-04-27 19:36:43 +01:00
parent f6b119a4df
commit d617b13ec9
2 changed files with 33 additions and 6 deletions

View File

@@ -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<IPlatformEnvironment>& 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);
}

View File

@@ -16,6 +16,7 @@
#include <string>
#include <string_view>
#include <tuple>
#include <vector>
struct ILanguagePack;
struct IObjectManager;
@@ -36,6 +37,7 @@ namespace OpenRCT2::Localisation
std::unique_ptr<ILanguagePack> _languageFallback;
std::unique_ptr<ILanguagePack> _languageCurrent;
std::stack<rct_string_id> _availableObjectStringIds;
std::vector<std::string> _objectStrings;
public:
int32_t GetCurrentLanguage() const