diff --git a/src/OpenRCT2.cpp b/src/OpenRCT2.cpp index 9f03cf3646..645be04d1b 100644 --- a/src/OpenRCT2.cpp +++ b/src/OpenRCT2.cpp @@ -18,8 +18,12 @@ #include "core/Guard.hpp" #include "core/String.hpp" #include "network/network.h" -#include "platform/crash.h" +#include "object/ObjectRepository.h" #include "OpenRCT2.h" +#include "platform/crash.h" +#include "PlatformEnvironment.h" +#include "ride/TrackDesignRepository.h" +#include "ScenarioRepository.h" extern "C" { @@ -67,6 +71,7 @@ extern "C" namespace OpenRCT2 { + static IPlatformEnvironment * _env = nullptr; static std::string _versionInfo; static bool _isWindowMinimised; static uint32 _isWindowMinimisedLastCheckTick; @@ -76,6 +81,7 @@ namespace OpenRCT2 /** If set, will end the OpenRCT2 game loop. Intentially private to this module so that the flag can not be set back to false. */ static bool _finished; + static void SetupEnvironment(); static void SetVersionInfoString(); static bool ShouldRunVariableFrame(); static void RunGameLoop(); @@ -163,6 +169,19 @@ extern "C" return false; } + // Sets up the environment OpenRCT2 is running in, e.g. directory paths + OpenRCT2::SetupEnvironment(); + + IObjectRepository * objRepo = CreateObjectRepository(OpenRCT2::_env); + + // TODO Ideally we want to delay this until we show the title so that we can + // still open the game window and draw a progress screen for the creation + // of the object cache. + objRepo->LoadOrConstruct(); + + CreateScenarioRepository(OpenRCT2::_env); + GetTrackRepository()->Scan(); + if (!gOpenRCT2Headless) { audio_init(); audio_populate_devices(); @@ -294,6 +313,18 @@ extern "C" namespace OpenRCT2 { + static void SetupEnvironment() + { + utf8 path[260]; + std::string basePaths[4]; + basePaths[(size_t)DIRBASE::RCT2] = std::string(gRCT2AddressAppPath); + platform_get_openrct_data_path(path, sizeof(path)); + basePaths[(size_t)DIRBASE::OPENRCT2] = std::string(path); + platform_get_user_directory(path, nullptr, sizeof(path)); + basePaths[(size_t)DIRBASE::USER] = std::string(path); + OpenRCT2::_env = CreatePlatformEnvironment(basePaths); + } + static void SetVersionInfoString() { utf8 buffer[256]; diff --git a/src/PlatformEnvironment.cpp b/src/PlatformEnvironment.cpp index 23a69eba83..ea585a7f3b 100644 --- a/src/PlatformEnvironment.cpp +++ b/src/PlatformEnvironment.cpp @@ -84,15 +84,8 @@ private: static const char * FileNames[]; }; -IPlatformEnvironment * CreatePlatformEnvironment() +IPlatformEnvironment * CreatePlatformEnvironment(const std::string basePaths[4]) { - utf8 path[260]; - std::string basePaths[4]; - basePaths[(size_t)DIRBASE::RCT2] = std::string(gRCT2AddressAppPath); - platform_get_openrct_data_path(path, sizeof(path)); - basePaths[(size_t)DIRBASE::OPENRCT2] = std::string(path); - platform_get_user_directory(path, nullptr, sizeof(path)); - basePaths[(size_t)DIRBASE::USER] = std::string(path); return new PlatformEnvironment(basePaths); } diff --git a/src/PlatformEnvironment.h b/src/PlatformEnvironment.h index b4afdc1380..751f8ced85 100644 --- a/src/PlatformEnvironment.h +++ b/src/PlatformEnvironment.h @@ -70,4 +70,4 @@ interface IPlatformEnvironment virtual std::string GetFilePath(PATHID pathid) const abstract; }; -IPlatformEnvironment * CreatePlatformEnvironment(); +IPlatformEnvironment * CreatePlatformEnvironment(const std::string basePaths[4]); diff --git a/src/ScenarioRepository.cpp b/src/ScenarioRepository.cpp index 7ec4250e31..85d17fd016 100644 --- a/src/ScenarioRepository.cpp +++ b/src/ScenarioRepository.cpp @@ -550,14 +550,6 @@ IScenarioRepository * CreateScenarioRepository(IPlatformEnvironment * env) IScenarioRepository * GetScenarioRepository() { - if (_scenarioRepository == nullptr) - { - // TODO There should only be one platform environment which needs to be global. - // However it should be not be used here. Instead the object repository should be - // constructed in some initialisation method where it passes this dependency. - IPlatformEnvironment * env = CreatePlatformEnvironment(); - CreateScenarioRepository(env); - } return _scenarioRepository.get(); } diff --git a/src/object/ObjectManager.cpp b/src/object/ObjectManager.cpp index 41346e968c..472b580b04 100644 --- a/src/object/ObjectManager.cpp +++ b/src/object/ObjectManager.cpp @@ -42,7 +42,13 @@ private: public: ObjectManager(IObjectRepository * objectRepository) { + Guard::ArgumentNotNull(objectRepository); + _objectRepository = objectRepository; + + UpdateLegacyLoadedObjectList(); + UpdateSceneryGroupIndexes(); + reset_type_to_ride_entry_index_map(); } ~ObjectManager() override diff --git a/src/object/ObjectRepository.cpp b/src/object/ObjectRepository.cpp index f6e665517b..6b7c524bec 100644 --- a/src/object/ObjectRepository.cpp +++ b/src/object/ObjectRepository.cpp @@ -626,14 +626,6 @@ IObjectRepository * CreateObjectRepository(IPlatformEnvironment * env) IObjectRepository * GetObjectRepository() { - if (_objectRepository == nullptr) - { - // TODO There should only be one platform environment which needs to be global. - // However it should be not be used here. Instead the object repository should be - // constructed in some initialisation method where it passes this dependency. - IPlatformEnvironment * env = CreatePlatformEnvironment(); - CreateObjectRepository(env); - } return _objectRepository.get(); } diff --git a/src/rct2.c b/src/rct2.c index ae9f2daa70..a8cc3d545b 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -171,10 +171,6 @@ bool rct2_init() return false; } - object_list_load(); - scenario_repository_scan(); - track_repository_scan(); - font_sprite_initialise_characters(); if (!gOpenRCT2Headless) { platform_init();