mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Create repositories in OpenRCT2.c
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,4 +70,4 @@ interface IPlatformEnvironment
|
||||
virtual std::string GetFilePath(PATHID pathid) const abstract;
|
||||
};
|
||||
|
||||
IPlatformEnvironment * CreatePlatformEnvironment();
|
||||
IPlatformEnvironment * CreatePlatformEnvironment(const std::string basePaths[4]);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user