Do not return shared_ptr for LocalisationService

GetLocalisationService is currently used a lot, so remove overhead of shared_ptr copy.
This commit is contained in:
Ted John 2018-04-27 18:38:59 +01:00
parent ad6ebd646c
commit d1cbf998a0
5 changed files with 16 additions and 16 deletions

View File

@ -171,9 +171,9 @@ namespace OpenRCT2
return _env;
}
std::shared_ptr<LocalisationService> GetLocalisationService() override
Localisation::LocalisationService& GetLocalisationService() override
{
return _localisationService;
return *_localisationService;
}
IObjectManager * GetObjectManager() override

View File

@ -97,7 +97,7 @@ namespace OpenRCT2
virtual std::shared_ptr<Audio::IAudioContext> GetAudioContext() abstract;
virtual std::shared_ptr<Ui::IUiContext> GetUiContext() abstract;
virtual std::shared_ptr<IPlatformEnvironment> GetPlatformEnvironment() abstract;
virtual std::shared_ptr<Localisation::LocalisationService> GetLocalisationService() abstract;
virtual Localisation::LocalisationService& GetLocalisationService() abstract;
virtual IObjectManager * GetObjectManager() abstract;
virtual IObjectRepository * GetObjectRepository() abstract;
virtual ITrackDesignRepository * GetTrackDesignRepository() abstract;

View File

@ -95,17 +95,17 @@ uint8 language_get_id_from_locale(const char * locale)
const char * language_get_string(rct_string_id id)
{
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
return localisationService->GetString(id);
return localisationService.GetString(id);
}
bool language_open(sint32 id)
{
auto context = OpenRCT2::GetContext();
const auto& localisationService = context->GetLocalisationService();
auto& localisationService = context->GetLocalisationService();
auto objectManager = context->GetObjectManager();
try
{
localisationService->OpenLanguage(id, *objectManager);
localisationService.OpenLanguage(id, *objectManager);
return true;
}
catch (const std::exception&)
@ -117,7 +117,7 @@ bool language_open(sint32 id)
bool language_get_localised_scenario_strings(const utf8 *scenarioFilename, rct_string_id *outStringIds)
{
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
auto result = localisationService->GetLocalisedScenarioStrings(scenarioFilename);
auto result = localisationService.GetLocalisedScenarioStrings(scenarioFilename);
outStringIds[0] = std::get<0>(result);
outStringIds[1] = std::get<1>(result);
outStringIds[2] = std::get<2>(result);
@ -129,18 +129,18 @@ bool language_get_localised_scenario_strings(const utf8 *scenarioFilename, rct_s
void language_free_object_string(rct_string_id stringId)
{
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
localisationService->FreeObjectString(stringId);
auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
localisationService.FreeObjectString(stringId);
}
rct_string_id language_get_object_override_string_id(const char * identifier, uint8 index)
{
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
return localisationService->GetObjectOverrideStringId(identifier, index);
return localisationService.GetObjectOverrideStringId(identifier, index);
}
rct_string_id language_allocate_object_string(const std::string &target)
{
const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
return localisationService->AllocateObjectString(target);
auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService();
return localisationService.AllocateObjectString(target);
}

View File

@ -156,11 +156,11 @@ void LocalisationService::FreeObjectString(rct_string_id stringId)
sint32 LocalisationService_GetCurrentLanguage()
{
const auto& localisationService = GetContext()->GetLocalisationService();
return localisationService->GetCurrentLanguage();
return localisationService.GetCurrentLanguage();
}
bool LocalisationService_UseTrueTypeFont()
{
const auto& localisationService = GetContext()->GetLocalisationService();
return localisationService->UseTrueTypeFont();
return localisationService.UseTrueTypeFont();
}

View File

@ -667,9 +667,9 @@ const rct_object_entry * object_list_find(rct_object_entry * entry)
void object_list_load()
{
auto context = GetContext();
const auto localisationService = context->GetLocalisationService();
const auto& localisationService = context->GetLocalisationService();
auto objectRepository = context->GetObjectRepository();
objectRepository->LoadOrConstruct(localisationService->GetCurrentLanguage());
objectRepository->LoadOrConstruct(localisationService.GetCurrentLanguage());
IObjectManager * objectManager = context->GetObjectManager();
objectManager->UnloadAll();