mirror of https://github.com/OpenRCT2/OpenRCT2.git
Use shared_ptr for long-life objects
Use unique_ptr and shared_ptr for IContext, IPlatformEnvironment, IUiContext, and IAudioContext.
This commit is contained in:
parent
c7b40cec7c
commit
7dc170ef85
|
@ -31,7 +31,8 @@
|
|||
"includePath": [
|
||||
"/usr/include",
|
||||
"/usr/local/include",
|
||||
"${workspaceRoot}"
|
||||
"${workspaceRoot}",
|
||||
"${workspaceRoot}/src"
|
||||
],
|
||||
"defines": [],
|
||||
"intelliSenseMode": "clang-x64",
|
||||
|
|
|
@ -36,7 +36,6 @@ int main(int argc, const char * * argv)
|
|||
// Run OpenRCT2 with a plain context
|
||||
auto context = CreateContext();
|
||||
context->RunOpenRCT2(argc, argv);
|
||||
delete context;
|
||||
}
|
||||
return gExitCode;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,12 @@ using namespace OpenRCT2;
|
|||
using namespace OpenRCT2::Audio;
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
template<typename T>
|
||||
static std::shared_ptr<T> to_shared(std::unique_ptr<T>&& src)
|
||||
{
|
||||
return std::shared_ptr<T>(std::move(src));
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point for non-Windows systems. Windows instead uses its own DLL proxy.
|
||||
*/
|
||||
|
@ -47,21 +53,16 @@ int main(int argc, const char * * argv)
|
|||
// Run OpenRCT2 with a plain context
|
||||
auto context = CreateContext();
|
||||
context->RunOpenRCT2(argc, argv);
|
||||
delete context;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Run OpenRCT2 with a UI context
|
||||
auto env = CreatePlatformEnvironment();
|
||||
auto audioContext = CreateAudioContext();
|
||||
auto uiContext = CreateUiContext(env);
|
||||
auto env = to_shared(CreatePlatformEnvironment());
|
||||
auto audioContext = to_shared(CreateAudioContext());
|
||||
auto uiContext = to_shared(CreateUiContext(env));
|
||||
auto context = CreateContext(env, audioContext, uiContext);
|
||||
|
||||
context->RunOpenRCT2(argc, argv);
|
||||
|
||||
delete context;
|
||||
delete uiContext;
|
||||
delete audioContext;
|
||||
}
|
||||
}
|
||||
return gExitCode;
|
||||
|
|
|
@ -94,7 +94,7 @@ private:
|
|||
public:
|
||||
InGameConsole& GetInGameConsole() { return _inGameConsole; }
|
||||
|
||||
explicit UiContext(IPlatformEnvironment * env)
|
||||
explicit UiContext(std::shared_ptr<IPlatformEnvironment> env)
|
||||
: _platformUiContext(CreatePlatformUiContext()),
|
||||
_windowManager(CreateWindowManager()),
|
||||
_keyboardShortcuts(env)
|
||||
|
@ -814,9 +814,9 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
IUiContext * OpenRCT2::Ui::CreateUiContext(IPlatformEnvironment * env)
|
||||
std::unique_ptr<IUiContext> OpenRCT2::Ui::CreateUiContext(std::shared_ptr<IPlatformEnvironment> env)
|
||||
{
|
||||
return new UiContext(env);
|
||||
return std::make_unique<UiContext>(env);
|
||||
}
|
||||
|
||||
InGameConsole& OpenRCT2::Ui::GetInGameConsole()
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <openrct2/common.h>
|
||||
|
||||
|
@ -43,7 +44,7 @@ namespace OpenRCT2
|
|||
virtual std::string ShowDirectoryDialog(SDL_Window * window, const std::string &title) abstract;
|
||||
};
|
||||
|
||||
IUiContext * CreateUiContext(IPlatformEnvironment * env);
|
||||
std::unique_ptr<IUiContext> CreateUiContext(std::shared_ptr<IPlatformEnvironment> env);
|
||||
IPlatformUiContext * CreatePlatformUiContext();
|
||||
|
||||
InGameConsole& GetInGameConsole();
|
||||
|
|
|
@ -94,8 +94,8 @@ namespace OpenRCT2::Audio
|
|||
void StopVehicleSounds() override { }
|
||||
};
|
||||
|
||||
IAudioContext * CreateAudioContext()
|
||||
std::unique_ptr<IAudioContext> CreateAudioContext()
|
||||
{
|
||||
return new AudioContext();
|
||||
return std::make_unique<AudioContext>();
|
||||
}
|
||||
} // namespace OpenRCT2::Audio
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <openrct2/common.h>
|
||||
#include <openrct2/audio/AudioChannel.h>
|
||||
|
@ -69,5 +70,6 @@ namespace OpenRCT2::Audio
|
|||
IAudioMixer * Create();
|
||||
}
|
||||
|
||||
IAudioContext * CreateAudioContext();
|
||||
std::unique_ptr<IAudioContext> CreateAudioContext();
|
||||
|
||||
} // namespace OpenRCT2::Audio
|
||||
|
|
|
@ -32,7 +32,7 @@ using namespace OpenRCT2::Input;
|
|||
// Remove when the C calls are removed
|
||||
static KeyboardShortcuts * _instance;
|
||||
|
||||
KeyboardShortcuts::KeyboardShortcuts(IPlatformEnvironment * env)
|
||||
KeyboardShortcuts::KeyboardShortcuts(std::shared_ptr<IPlatformEnvironment> env)
|
||||
: _env(env)
|
||||
{
|
||||
_instance = this;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <openrct2/common.h>
|
||||
|
||||
#define SHIFT 0x100
|
||||
|
@ -119,11 +120,11 @@ namespace OpenRCT2
|
|||
constexpr static sint32 CURRENT_FILE_VERSION = 1;
|
||||
static const uint16 DefaultKeys[SHORTCUT_COUNT];
|
||||
|
||||
IPlatformEnvironment * const _env;
|
||||
std::shared_ptr<IPlatformEnvironment> const _env;
|
||||
uint16 _keys[SHORTCUT_COUNT];
|
||||
|
||||
public:
|
||||
KeyboardShortcuts(IPlatformEnvironment * env);
|
||||
KeyboardShortcuts(std::shared_ptr<IPlatformEnvironment> env);
|
||||
|
||||
void Reset();
|
||||
bool Load();
|
||||
|
|
|
@ -82,9 +82,9 @@ namespace OpenRCT2
|
|||
{
|
||||
private:
|
||||
// Dependencies
|
||||
IPlatformEnvironment * const _env = nullptr;
|
||||
IAudioContext * const _audioContext = nullptr;
|
||||
IUiContext * const _uiContext = nullptr;
|
||||
std::shared_ptr<IPlatformEnvironment> const _env;
|
||||
std::shared_ptr<IAudioContext> const _audioContext;
|
||||
std::shared_ptr<IUiContext> const _uiContext;
|
||||
|
||||
// Services
|
||||
IObjectRepository * _objectRepository = nullptr;
|
||||
|
@ -116,7 +116,10 @@ namespace OpenRCT2
|
|||
static Context * Instance;
|
||||
|
||||
public:
|
||||
Context(IPlatformEnvironment * env, IAudioContext * audioContext, IUiContext * uiContext)
|
||||
Context(
|
||||
std::shared_ptr<IPlatformEnvironment> env,
|
||||
std::shared_ptr<IAudioContext> audioContext,
|
||||
std::shared_ptr<IUiContext> uiContext)
|
||||
: _env(env),
|
||||
_audioContext(audioContext),
|
||||
_uiContext(uiContext)
|
||||
|
@ -153,17 +156,17 @@ namespace OpenRCT2
|
|||
|
||||
IAudioContext * GetAudioContext() override
|
||||
{
|
||||
return _audioContext;
|
||||
return _audioContext.get();
|
||||
}
|
||||
|
||||
IUiContext * GetUiContext() override
|
||||
{
|
||||
return _uiContext;
|
||||
return _uiContext.get();
|
||||
}
|
||||
|
||||
IPlatformEnvironment * GetPlatformEnvironment() override
|
||||
{
|
||||
return _env;
|
||||
return _env.get();
|
||||
}
|
||||
|
||||
IObjectManager * GetObjectManager() override
|
||||
|
@ -548,7 +551,7 @@ namespace OpenRCT2
|
|||
|
||||
bool LoadBaseGraphics()
|
||||
{
|
||||
if (!gfx_load_g1(_env))
|
||||
if (!gfx_load_g1(*_env))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -902,9 +905,9 @@ namespace OpenRCT2
|
|||
|
||||
class PlainContext final : public Context
|
||||
{
|
||||
std::unique_ptr<IPlatformEnvironment> _env;
|
||||
std::unique_ptr<IAudioContext> _audioContext;
|
||||
std::unique_ptr<IUiContext> _uiContext;
|
||||
std::shared_ptr<IPlatformEnvironment> _env;
|
||||
std::shared_ptr<IAudioContext> _audioContext;
|
||||
std::shared_ptr<IUiContext> _uiContext;
|
||||
|
||||
public:
|
||||
PlainContext()
|
||||
|
@ -912,25 +915,31 @@ namespace OpenRCT2
|
|||
{
|
||||
}
|
||||
|
||||
PlainContext(IPlatformEnvironment * env, IAudioContext * audioContext, IUiContext * uiContext)
|
||||
: Context(env, audioContext, uiContext)
|
||||
PlainContext(
|
||||
std::shared_ptr<IPlatformEnvironment> env,
|
||||
std::shared_ptr<IAudioContext> audioContext,
|
||||
std::shared_ptr<IUiContext> uiContext)
|
||||
: Context(env, audioContext, uiContext),
|
||||
_env(env),
|
||||
_audioContext(audioContext),
|
||||
_uiContext(uiContext)
|
||||
{
|
||||
_env = std::unique_ptr<IPlatformEnvironment>(env);
|
||||
_audioContext = std::unique_ptr<IAudioContext>(audioContext);
|
||||
_uiContext = std::unique_ptr<IUiContext>(uiContext);
|
||||
}
|
||||
};
|
||||
|
||||
Context * Context::Instance = nullptr;
|
||||
|
||||
IContext * CreateContext()
|
||||
std::unique_ptr<IContext> CreateContext()
|
||||
{
|
||||
return new PlainContext();
|
||||
return std::make_unique<PlainContext>();
|
||||
}
|
||||
|
||||
IContext * CreateContext(IPlatformEnvironment * env, Audio::IAudioContext * audioContext, IUiContext * uiContext)
|
||||
std::unique_ptr<IContext> CreateContext(
|
||||
std::shared_ptr<IPlatformEnvironment> env,
|
||||
std::shared_ptr<Audio::IAudioContext> audioContext,
|
||||
std::shared_ptr<IUiContext> uiContext)
|
||||
{
|
||||
return new Context(env, audioContext, uiContext);
|
||||
return std::make_unique<Context>(env, audioContext, uiContext);
|
||||
}
|
||||
|
||||
IContext * GetContext()
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
interface IObjectManager;
|
||||
|
@ -111,8 +112,11 @@ namespace OpenRCT2
|
|||
virtual std::string GetPathLegacy(sint32 pathId) abstract;
|
||||
};
|
||||
|
||||
IContext * CreateContext();
|
||||
IContext * CreateContext(IPlatformEnvironment * env, Audio::IAudioContext * audioContext, Ui::IUiContext * uiContext);
|
||||
std::unique_ptr<IContext> CreateContext();
|
||||
std::unique_ptr<IContext> CreateContext(
|
||||
std::shared_ptr<IPlatformEnvironment> env,
|
||||
std::shared_ptr<Audio::IAudioContext> audioContext,
|
||||
std::shared_ptr<Ui::IUiContext> uiContext);
|
||||
IContext * GetContext();
|
||||
} // namespace OpenRCT2
|
||||
|
||||
|
|
|
@ -109,9 +109,9 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment(DIRBASE_VALUES basePaths)
|
||||
std::unique_ptr<IPlatformEnvironment> OpenRCT2::CreatePlatformEnvironment(DIRBASE_VALUES basePaths)
|
||||
{
|
||||
return new PlatformEnvironment(basePaths);
|
||||
return std::make_unique<PlatformEnvironment>(basePaths);
|
||||
}
|
||||
|
||||
static std::string GetOpenRCT2DirectoryName()
|
||||
|
@ -123,7 +123,7 @@ static std::string GetOpenRCT2DirectoryName()
|
|||
#endif
|
||||
}
|
||||
|
||||
IPlatformEnvironment * OpenRCT2::CreatePlatformEnvironment()
|
||||
std::unique_ptr<IPlatformEnvironment> OpenRCT2::CreatePlatformEnvironment()
|
||||
{
|
||||
auto subDirectory = GetOpenRCT2DirectoryName();
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "common.h"
|
||||
|
||||
|
@ -82,6 +83,7 @@ namespace OpenRCT2
|
|||
virtual void SetBasePath(DIRBASE base, const std::string &path) abstract;
|
||||
};
|
||||
|
||||
IPlatformEnvironment * CreatePlatformEnvironment(DIRBASE_VALUES basePaths);
|
||||
IPlatformEnvironment * CreatePlatformEnvironment();
|
||||
std::unique_ptr<IPlatformEnvironment> CreatePlatformEnvironment(DIRBASE_VALUES basePaths);
|
||||
std::unique_ptr<IPlatformEnvironment> CreatePlatformEnvironment();
|
||||
|
||||
} // namespace OpenRCT2
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../common.h"
|
||||
|
@ -59,5 +60,6 @@ namespace OpenRCT2::Audio
|
|||
virtual void StopVehicleSounds() abstract;
|
||||
};
|
||||
|
||||
IAudioContext * CreateDummyAudioContext();
|
||||
std::unique_ptr<IAudioContext> CreateDummyAudioContext();
|
||||
|
||||
} // namespace OpenRCT2::Audio
|
||||
|
|
|
@ -45,8 +45,8 @@ namespace OpenRCT2::Audio
|
|||
void StopVehicleSounds() override { }
|
||||
};
|
||||
|
||||
IAudioContext * CreateDummyAudioContext()
|
||||
std::unique_ptr<IAudioContext> CreateDummyAudioContext()
|
||||
{
|
||||
return new DummyAudioContext();
|
||||
return std::make_unique<DummyAudioContext>();
|
||||
}
|
||||
} // namespace OpenRCT2::Audio
|
||||
|
|
|
@ -399,7 +399,7 @@ static exitcode_t HandleCommandScanObjects([[maybe_unused]] CommandLineArgEnumer
|
|||
|
||||
auto context = std::unique_ptr<OpenRCT2::IContext>(OpenRCT2::CreateContext());
|
||||
auto env = context->GetPlatformEnvironment();
|
||||
auto objectRepository = std::unique_ptr<IObjectRepository>(CreateObjectRepository(env));
|
||||
auto objectRepository = CreateObjectRepository(env);
|
||||
|
||||
// HACK: set gCurrentLanguage otherwise it be wrong for the index file
|
||||
gCurrentLanguage = gConfigGeneral.language;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -52,6 +53,15 @@ namespace Guard
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void ArgumentNotNull(const std::shared_ptr<T>& argument, const char * message = nullptr, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
Assert_VA(argument != nullptr, message, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void ArgumentInRange(T argument, T min, T max, const char * message = nullptr, ...)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,11 @@
|
|||
#include "../common.h"
|
||||
#include "../interface/Colour.h"
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
interface IPlatformEnvironment;
|
||||
}
|
||||
|
||||
struct rct_g1_element {
|
||||
uint8* offset; // 0x00
|
||||
sint16 width; // 0x04
|
||||
|
@ -281,7 +286,7 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, sint16 left, sint16 top, sint16
|
|||
void gfx_filter_rect(rct_drawpixelinfo *dpi, sint32 left, sint32 top, sint32 right, sint32 bottom, FILTER_PALETTE_ID palette);
|
||||
|
||||
// sprite
|
||||
bool gfx_load_g1(void * platformEnvironment);
|
||||
bool gfx_load_g1(const OpenRCT2::IPlatformEnvironment& env);
|
||||
bool gfx_load_g2();
|
||||
bool gfx_load_csg();
|
||||
void gfx_unload_g1();
|
||||
|
|
|
@ -227,14 +227,12 @@ bool gTinyFontAntiAliased = false;
|
|||
*
|
||||
* rct2: 0x00678998
|
||||
*/
|
||||
bool gfx_load_g1(void * platformEnvironment)
|
||||
bool gfx_load_g1(const IPlatformEnvironment& env)
|
||||
{
|
||||
auto env = (IPlatformEnvironment *)platformEnvironment;
|
||||
|
||||
log_verbose("gfx_load_g1(...)");
|
||||
try
|
||||
{
|
||||
auto path = Path::Combine(env->GetDirectoryPath(DIRBASE::RCT2, DIRID::DATA), "g1.dat");
|
||||
auto path = Path::Combine(env.GetDirectoryPath(DIRBASE::RCT2, DIRID::DATA), "g1.dat");
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
_g1.header = fs.ReadValue<rct_g1_header>();
|
||||
|
||||
|
|
|
@ -448,7 +448,6 @@ sint32 cmdline_for_screenshot(const char * * argv, sint32 argc, ScreenshotOption
|
|||
{
|
||||
std::printf("%s\n", e.what());
|
||||
drawing_engine_dispose();
|
||||
delete context;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -518,7 +517,6 @@ sint32 cmdline_for_screenshot(const char * * argv, sint32 argc, ScreenshotOption
|
|||
{
|
||||
std::printf("Weather can only be set to an integer value from 1 till 6.");
|
||||
drawing_engine_dispose();
|
||||
delete context;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -583,6 +581,5 @@ sint32 cmdline_for_screenshot(const char * * argv, sint32 argc, ScreenshotOption
|
|||
free(dpi.bits);
|
||||
drawing_engine_dispose();
|
||||
}
|
||||
delete context;
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ Network::~Network()
|
|||
CloseConnection();
|
||||
}
|
||||
|
||||
void Network::SetEnvironment(IPlatformEnvironment * env)
|
||||
void Network::SetEnvironment(std::shared_ptr<IPlatformEnvironment> env)
|
||||
{
|
||||
_env = env;
|
||||
}
|
||||
|
@ -2545,9 +2545,9 @@ void Network::Client_Handle_GAMEINFO(NetworkConnection& connection, NetworkPacke
|
|||
network_chat_show_server_greeting();
|
||||
}
|
||||
|
||||
void network_set_env(void * env)
|
||||
void network_set_env(std::shared_ptr<IPlatformEnvironment> env)
|
||||
{
|
||||
gNetwork.SetEnvironment((IPlatformEnvironment *)env);
|
||||
gNetwork.SetEnvironment(env);
|
||||
}
|
||||
|
||||
void network_close()
|
||||
|
@ -3327,7 +3327,7 @@ sint32 network_get_pickup_peep_old_x(uint8 playerid) { return _pickup_peep_old_x
|
|||
void network_send_chat(const char* text) {}
|
||||
void network_send_password(const char* password) {}
|
||||
void network_close() {}
|
||||
void network_set_env(void * env) {}
|
||||
void network_set_env(std::shared_ptr<OpenRCT2::IPlatformEnvironment>) {}
|
||||
void network_shutdown_client() {}
|
||||
void network_set_password(const char* password) {}
|
||||
uint8 network_get_current_player_id() { return 0; }
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
enum {
|
||||
|
@ -49,12 +50,16 @@ struct GameAction;
|
|||
struct rct_peep;
|
||||
struct LocationXYZ16;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
interface IPlatformEnvironment;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_NETWORK
|
||||
|
||||
#include <array>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <fstream>
|
||||
|
@ -79,17 +84,12 @@ enum {
|
|||
|
||||
struct ObjectRepositoryItem;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
interface IPlatformEnvironment;
|
||||
}
|
||||
|
||||
class Network
|
||||
{
|
||||
public:
|
||||
Network();
|
||||
~Network();
|
||||
void SetEnvironment(OpenRCT2::IPlatformEnvironment * env);
|
||||
void SetEnvironment(std::shared_ptr<OpenRCT2::IPlatformEnvironment> env);
|
||||
bool Init();
|
||||
void Close();
|
||||
bool BeginClient(const char* host, uint16 port);
|
||||
|
@ -259,7 +259,7 @@ private:
|
|||
std::string _chatLogFilenameFormat = "%Y%m%d-%H%M%S.txt";
|
||||
std::string _serverLogPath;
|
||||
std::string _serverLogFilenameFormat = "%Y%m%d-%H%M%S.txt";
|
||||
OpenRCT2::IPlatformEnvironment * _env = nullptr;
|
||||
std::shared_ptr<OpenRCT2::IPlatformEnvironment> _env;
|
||||
|
||||
void UpdateServer();
|
||||
void UpdateClient();
|
||||
|
@ -301,7 +301,7 @@ private:
|
|||
|
||||
#endif /* DISABLE_NETWORK */
|
||||
|
||||
void network_set_env(void * env);
|
||||
void network_set_env(std::shared_ptr<OpenRCT2::IPlatformEnvironment> env);
|
||||
void network_close();
|
||||
void network_shutdown_client();
|
||||
sint32 network_begin_client(const char *host, sint32 port);
|
||||
|
|
|
@ -86,15 +86,15 @@ private:
|
|||
IObjectRepository& _objectRepository;
|
||||
|
||||
public:
|
||||
explicit ObjectFileIndex(IObjectRepository& objectRepository, IPlatformEnvironment * env) :
|
||||
explicit ObjectFileIndex(IObjectRepository& objectRepository, const IPlatformEnvironment& env) :
|
||||
FileIndex("object index",
|
||||
MAGIC_NUMBER,
|
||||
VERSION,
|
||||
env->GetFilePath(PATHID::CACHE_OBJECTS),
|
||||
env.GetFilePath(PATHID::CACHE_OBJECTS),
|
||||
std::string(PATTERN),
|
||||
std::vector<std::string>({
|
||||
env->GetDirectoryPath(DIRBASE::OPENRCT2, DIRID::OBJECT),
|
||||
env->GetDirectoryPath(DIRBASE::USER, DIRID::OBJECT) })),
|
||||
env.GetDirectoryPath(DIRBASE::OPENRCT2, DIRID::OBJECT),
|
||||
env.GetDirectoryPath(DIRBASE::USER, DIRID::OBJECT) })),
|
||||
_objectRepository(objectRepository)
|
||||
{
|
||||
}
|
||||
|
@ -208,15 +208,15 @@ private:
|
|||
|
||||
class ObjectRepository final : public IObjectRepository
|
||||
{
|
||||
IPlatformEnvironment * const _env = nullptr;
|
||||
ObjectFileIndex const _fileIndex;
|
||||
std::vector<ObjectRepositoryItem> _items;
|
||||
ObjectEntryMap _itemMap;
|
||||
std::shared_ptr<IPlatformEnvironment> const _env;
|
||||
ObjectFileIndex const _fileIndex;
|
||||
std::vector<ObjectRepositoryItem> _items;
|
||||
ObjectEntryMap _itemMap;
|
||||
|
||||
public:
|
||||
explicit ObjectRepository(IPlatformEnvironment * env)
|
||||
explicit ObjectRepository(std::shared_ptr<IPlatformEnvironment> env)
|
||||
: _env(env),
|
||||
_fileIndex(*this, env)
|
||||
_fileIndex(*this, *env)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -637,7 +637,7 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
IObjectRepository * CreateObjectRepository(IPlatformEnvironment * env)
|
||||
IObjectRepository * CreateObjectRepository(std::shared_ptr<IPlatformEnvironment> env)
|
||||
{
|
||||
return new ObjectRepository(env);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "../common.h"
|
||||
#include "../object/Object.h"
|
||||
|
@ -77,7 +78,7 @@ interface IObjectRepository
|
|||
virtual void WritePackedObjects(IStream * stream, std::vector<const ObjectRepositoryItem *> &objects) abstract;
|
||||
};
|
||||
|
||||
IObjectRepository * CreateObjectRepository(OpenRCT2::IPlatformEnvironment * env);
|
||||
IObjectRepository * CreateObjectRepository(std::shared_ptr<OpenRCT2::IPlatformEnvironment> env);
|
||||
|
||||
bool IsObjectCustom(const ObjectRepositoryItem * object);
|
||||
|
||||
|
|
|
@ -66,16 +66,16 @@ private:
|
|||
static constexpr auto PATTERN = "*.td4;*.td6";
|
||||
|
||||
public:
|
||||
explicit TrackDesignFileIndex(IPlatformEnvironment * env) :
|
||||
explicit TrackDesignFileIndex(const IPlatformEnvironment &env) :
|
||||
FileIndex("track design index",
|
||||
MAGIC_NUMBER,
|
||||
VERSION,
|
||||
env->GetFilePath(PATHID::CACHE_TRACKS),
|
||||
env.GetFilePath(PATHID::CACHE_TRACKS),
|
||||
std::string(PATTERN),
|
||||
std::vector<std::string>({
|
||||
env->GetDirectoryPath(DIRBASE::RCT1, DIRID::TRACK),
|
||||
env->GetDirectoryPath(DIRBASE::RCT2, DIRID::TRACK),
|
||||
env->GetDirectoryPath(DIRBASE::USER, DIRID::TRACK) }))
|
||||
env.GetDirectoryPath(DIRBASE::RCT1, DIRID::TRACK),
|
||||
env.GetDirectoryPath(DIRBASE::RCT2, DIRID::TRACK),
|
||||
env.GetDirectoryPath(DIRBASE::USER, DIRID::TRACK) }))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -137,14 +137,14 @@ private:
|
|||
class TrackDesignRepository final : public ITrackDesignRepository
|
||||
{
|
||||
private:
|
||||
IPlatformEnvironment * const _env;
|
||||
std::shared_ptr<IPlatformEnvironment> const _env;
|
||||
TrackDesignFileIndex const _fileIndex;
|
||||
std::vector<TrackRepositoryItem> _items;
|
||||
|
||||
public:
|
||||
explicit TrackDesignRepository(IPlatformEnvironment * env)
|
||||
explicit TrackDesignRepository(std::shared_ptr<IPlatformEnvironment> env)
|
||||
: _env(env),
|
||||
_fileIndex(env)
|
||||
_fileIndex(*env)
|
||||
{
|
||||
Guard::ArgumentNotNull(env);
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
ITrackDesignRepository * CreateTrackDesignRepository(IPlatformEnvironment * env)
|
||||
ITrackDesignRepository * CreateTrackDesignRepository(std::shared_ptr<IPlatformEnvironment> env)
|
||||
{
|
||||
return new TrackDesignRepository(env);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "../common.h"
|
||||
#include "RideGroupManager.h"
|
||||
|
||||
|
@ -51,7 +52,7 @@ interface ITrackDesignRepository
|
|||
virtual std::string Install(const std::string &path) abstract;
|
||||
};
|
||||
|
||||
ITrackDesignRepository * CreateTrackDesignRepository(OpenRCT2::IPlatformEnvironment * env);
|
||||
ITrackDesignRepository * CreateTrackDesignRepository(std::shared_ptr<OpenRCT2::IPlatformEnvironment> env);
|
||||
std::string GetNameFromTrackPath(const std::string &path);
|
||||
|
||||
void track_repository_scan();
|
||||
|
|
|
@ -128,16 +128,16 @@ private:
|
|||
static constexpr auto PATTERN = "*.sc4;*.sc6";
|
||||
|
||||
public:
|
||||
explicit ScenarioFileIndex(IPlatformEnvironment * env) :
|
||||
explicit ScenarioFileIndex(const IPlatformEnvironment& env) :
|
||||
FileIndex("scenario index",
|
||||
MAGIC_NUMBER,
|
||||
VERSION,
|
||||
env->GetFilePath(PATHID::CACHE_SCENARIOS),
|
||||
env.GetFilePath(PATHID::CACHE_SCENARIOS),
|
||||
std::string(PATTERN),
|
||||
std::vector<std::string>({
|
||||
env->GetDirectoryPath(DIRBASE::RCT1, DIRID::SCENARIO),
|
||||
env->GetDirectoryPath(DIRBASE::RCT2, DIRID::SCENARIO),
|
||||
env->GetDirectoryPath(DIRBASE::USER, DIRID::SCENARIO) }))
|
||||
env.GetDirectoryPath(DIRBASE::RCT1, DIRID::SCENARIO),
|
||||
env.GetDirectoryPath(DIRBASE::RCT2, DIRID::SCENARIO),
|
||||
env.GetDirectoryPath(DIRBASE::USER, DIRID::SCENARIO) }))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -322,15 +322,15 @@ class ScenarioRepository final : public IScenarioRepository
|
|||
private:
|
||||
static constexpr uint32 HighscoreFileVersion = 1;
|
||||
|
||||
IPlatformEnvironment * const _env;
|
||||
std::shared_ptr<IPlatformEnvironment> const _env;
|
||||
ScenarioFileIndex const _fileIndex;
|
||||
std::vector<scenario_index_entry> _scenarios;
|
||||
std::vector<scenario_highscore_entry*> _highscores;
|
||||
|
||||
public:
|
||||
explicit ScenarioRepository(IPlatformEnvironment * env)
|
||||
explicit ScenarioRepository(std::shared_ptr<IPlatformEnvironment> env)
|
||||
: _env(env),
|
||||
_fileIndex(env)
|
||||
_fileIndex(*env)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -729,7 +729,7 @@ private:
|
|||
|
||||
static ScenarioRepository * _scenarioRepository;
|
||||
|
||||
IScenarioRepository * CreateScenarioRepository(IPlatformEnvironment * env)
|
||||
IScenarioRepository * CreateScenarioRepository(std::shared_ptr<IPlatformEnvironment> env)
|
||||
{
|
||||
_scenarioRepository = new ScenarioRepository(env);
|
||||
return _scenarioRepository;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "../common.h"
|
||||
|
||||
struct rct_object_entry;
|
||||
|
@ -77,7 +78,7 @@ interface IScenarioRepository
|
|||
virtual bool TryRecordHighscore(const utf8 * scenarioFileName, money32 companyValue, const utf8 * name) abstract;
|
||||
};
|
||||
|
||||
IScenarioRepository * CreateScenarioRepository(OpenRCT2::IPlatformEnvironment * env);
|
||||
IScenarioRepository * CreateScenarioRepository(std::shared_ptr<OpenRCT2::IPlatformEnvironment> env);
|
||||
IScenarioRepository * GetScenarioRepository();
|
||||
|
||||
void scenario_repository_scan();
|
||||
|
|
|
@ -92,8 +92,8 @@ namespace OpenRCT2::Ui
|
|||
~DummyUiContext() { delete _windowManager; }
|
||||
};
|
||||
|
||||
IUiContext * CreateDummyUiContext()
|
||||
std::shared_ptr<IUiContext> CreateDummyUiContext()
|
||||
{
|
||||
return new DummyUiContext();
|
||||
return std::make_unique<DummyUiContext>();
|
||||
}
|
||||
} // namespace OpenRCT2::Ui
|
||||
|
|
|
@ -149,6 +149,6 @@ namespace OpenRCT2
|
|||
virtual bool SetClipboardText(const utf8* target) abstract;
|
||||
};
|
||||
|
||||
IUiContext * CreateDummyUiContext();
|
||||
std::shared_ptr<IUiContext> CreateDummyUiContext();
|
||||
} // namespace Ui
|
||||
} // namespace OpenRCT2
|
||||
|
|
|
@ -46,8 +46,6 @@ TEST(MultiLaunchTest, all)
|
|||
|
||||
// Check ride count again
|
||||
ASSERT_EQ(gRideCount, 134);
|
||||
|
||||
delete context;
|
||||
}
|
||||
SUCCEED();
|
||||
}
|
||||
|
|
|
@ -91,6 +91,4 @@ TEST_F(RideRatings, all)
|
|||
expI++;
|
||||
}
|
||||
}
|
||||
|
||||
delete context;
|
||||
}
|
||||
|
|
|
@ -28,18 +28,11 @@ protected:
|
|||
SUCCEED();
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
delete _context;
|
||||
_context = nullptr;
|
||||
SUCCEED();
|
||||
}
|
||||
|
||||
private:
|
||||
static IContext * _context;
|
||||
static std::shared_ptr<IContext> _context;
|
||||
};
|
||||
|
||||
IContext * TileElementWantsFootpathConnection::_context = nullptr;
|
||||
std::shared_ptr<IContext> TileElementWantsFootpathConnection::_context;
|
||||
|
||||
TEST_F(TileElementWantsFootpathConnection, FlatPath)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue