mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Use more dependency injection
This commit is contained in:
committed by
Michał Janiszewski
parent
3003393c87
commit
b9e9ddfc1c
@@ -455,7 +455,7 @@ namespace OpenRCT2
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
parkImporter.reset(ParkImporter::CreateS6());
|
parkImporter.reset(ParkImporter::CreateS6(_objectRepository, _objectManager));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.Type == FILE_TYPE::SAVED_GAME)
|
if (info.Type == FILE_TYPE::SAVED_GAME)
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include "core/Path.hpp"
|
#include "core/Path.hpp"
|
||||||
#include "core/String.hpp"
|
#include "core/String.hpp"
|
||||||
|
#include "object/ObjectManager.h"
|
||||||
|
#include "object/ObjectRepository.h"
|
||||||
#include "ParkImporter.h"
|
#include "ParkImporter.h"
|
||||||
|
|
||||||
namespace ParkImporter
|
namespace ParkImporter
|
||||||
@@ -31,7 +33,7 @@ namespace ParkImporter
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
parkImporter = CreateS6();
|
parkImporter = CreateS6(GetObjectRepository(), GetObjectManager());
|
||||||
}
|
}
|
||||||
return parkImporter;
|
return parkImporter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "scenario/ScenarioRepository.h"
|
#include "scenario/ScenarioRepository.h"
|
||||||
|
|
||||||
|
interface IObjectManager;
|
||||||
|
interface IObjectRepository;
|
||||||
interface IStream;
|
interface IStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +46,7 @@ namespace ParkImporter
|
|||||||
{
|
{
|
||||||
IParkImporter * Create(const std::string &hintPath);
|
IParkImporter * Create(const std::string &hintPath);
|
||||||
IParkImporter * CreateS4();
|
IParkImporter * CreateS4();
|
||||||
IParkImporter * CreateS6();
|
IParkImporter * CreateS6(IObjectRepository * objectRepository, IObjectManager * objectManager);
|
||||||
|
|
||||||
bool ExtensionIsRCT1(const std::string &extension);
|
bool ExtensionIsRCT1(const std::string &extension);
|
||||||
bool ExtensionIsScenario(const std::string &extension);
|
bool ExtensionIsScenario(const std::string &extension);
|
||||||
|
|||||||
@@ -1869,7 +1869,8 @@ bool Network::LoadMap(IStream * stream)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto importer = std::unique_ptr<IParkImporter>(ParkImporter::CreateS6());
|
auto importer = std::unique_ptr<IParkImporter>(
|
||||||
|
ParkImporter::CreateS6(GetObjectRepository(), GetObjectManager()));
|
||||||
importer->LoadFromStream(stream, false);
|
importer->LoadFromStream(stream, false);
|
||||||
importer->Import();
|
importer->Import();
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,6 @@ assert_struct_size(rct_object_filters, 3);
|
|||||||
extern const rct_object_entry_group object_entry_groups[];
|
extern const rct_object_entry_group object_entry_groups[];
|
||||||
|
|
||||||
void object_list_load();
|
void object_list_load();
|
||||||
bool object_load_entries(rct_object_entry* entries);
|
|
||||||
|
|
||||||
bool object_entry_is_empty(const rct_object_entry *entry);
|
bool object_entry_is_empty(const rct_object_entry *entry);
|
||||||
bool object_entry_compare(const rct_object_entry *a, const rct_object_entry *b);
|
bool object_entry_compare(const rct_object_entry *a, const rct_object_entry *b);
|
||||||
|
|||||||
@@ -754,17 +754,6 @@ extern "C"
|
|||||||
objectManager->UnloadAll();
|
objectManager->UnloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool object_load_entries(rct_object_entry * entries)
|
|
||||||
{
|
|
||||||
log_verbose("loading required objects");
|
|
||||||
|
|
||||||
IObjectManager * objectManger = GetObjectManager();
|
|
||||||
bool result = objectManger->LoadObjects(entries, OBJECT_ENTRY_COUNT);
|
|
||||||
|
|
||||||
log_verbose("finished loading required objects");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void * object_repository_load_object(const rct_object_entry * objectEntry)
|
void * object_repository_load_object(const rct_object_entry * objectEntry)
|
||||||
{
|
{
|
||||||
Object * object = nullptr;
|
Object * object = nullptr;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "../core/String.hpp"
|
#include "../core/String.hpp"
|
||||||
#include "../management/award.h"
|
#include "../management/award.h"
|
||||||
#include "../network/network.h"
|
#include "../network/network.h"
|
||||||
|
#include "../object/ObjectManager.h"
|
||||||
#include "../object/ObjectRepository.h"
|
#include "../object/ObjectRepository.h"
|
||||||
#include "../ParkImporter.h"
|
#include "../ParkImporter.h"
|
||||||
#include "../rct12/SawyerChunkReader.h"
|
#include "../rct12/SawyerChunkReader.h"
|
||||||
@@ -64,12 +65,17 @@ public:
|
|||||||
class S6Importer final : public IParkImporter
|
class S6Importer final : public IParkImporter
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
IObjectRepository * const _objectRepository;
|
||||||
|
IObjectManager * const _objectManager;
|
||||||
|
|
||||||
const utf8 * _s6Path = nullptr;
|
const utf8 * _s6Path = nullptr;
|
||||||
rct_s6_data _s6;
|
rct_s6_data _s6;
|
||||||
uint8 _gameVersion = 0;
|
uint8 _gameVersion = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
S6Importer()
|
S6Importer(IObjectRepository * objectRepository, IObjectManager * objectManager)
|
||||||
|
: _objectRepository(objectRepository),
|
||||||
|
_objectManager(objectManager)
|
||||||
{
|
{
|
||||||
Memory::Set(&_s6, 0, sizeof(_s6));
|
Memory::Set(&_s6, 0, sizeof(_s6));
|
||||||
}
|
}
|
||||||
@@ -134,10 +140,9 @@ public:
|
|||||||
|
|
||||||
// Read packed objects
|
// Read packed objects
|
||||||
// TODO try to contain this more and not store objects until later
|
// TODO try to contain this more and not store objects until later
|
||||||
IObjectRepository * objectRepo = GetObjectRepository();
|
|
||||||
for (uint16 i = 0; i < _s6.header.num_packed_objects; i++)
|
for (uint16 i = 0; i < _s6.header.num_packed_objects; i++)
|
||||||
{
|
{
|
||||||
objectRepo->ExportPackedObject(stream);
|
_objectRepository->ExportPackedObject(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isScenario)
|
if (isScenario)
|
||||||
@@ -390,7 +395,7 @@ public:
|
|||||||
// pad_13CE778
|
// pad_13CE778
|
||||||
|
|
||||||
// Fix and set dynamic variables
|
// Fix and set dynamic variables
|
||||||
if (!object_load_entries(_s6.objects))
|
if (!_objectManager->LoadObjects(_s6.objects, OBJECT_ENTRY_COUNT))
|
||||||
{
|
{
|
||||||
throw ObjectLoadException();
|
throw ObjectLoadException();
|
||||||
}
|
}
|
||||||
@@ -406,9 +411,9 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IParkImporter * ParkImporter::CreateS6()
|
IParkImporter * ParkImporter::CreateS6(IObjectRepository * objectRepository, IObjectManager * objectManager)
|
||||||
{
|
{
|
||||||
return new S6Importer();
|
return new S6Importer(objectRepository, objectManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@@ -416,7 +421,7 @@ extern "C"
|
|||||||
bool game_load_sv6_path(const char * path)
|
bool game_load_sv6_path(const char * path)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
auto s6Importer = new S6Importer();
|
auto s6Importer = new S6Importer(GetObjectRepository(), GetObjectManager());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
s6Importer->LoadSavedGame(path);
|
s6Importer->LoadSavedGame(path);
|
||||||
@@ -456,7 +461,7 @@ extern "C"
|
|||||||
sint32 scenario_load(const char * path)
|
sint32 scenario_load(const char * path)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
auto s6Importer = new S6Importer();
|
auto s6Importer = new S6Importer(GetObjectRepository(), GetObjectManager());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
s6Importer->LoadScenario(path);
|
s6Importer->LoadScenario(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user