mirror of https://github.com/OpenRCT2/OpenRCT2.git
Use more smart ptrs and u8strings (#17611)
* Use smart ptr for PlatformUiContext and WindowManager * Remove more delete calls * Apply PR feedback
This commit is contained in:
parent
e5d2e3001d
commit
7399163a3c
|
@ -88,9 +88,9 @@ namespace OpenRCT2::Ui
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IPlatformUiContext* CreatePlatformUiContext()
|
std::unique_ptr<IPlatformUiContext> CreatePlatformUiContext()
|
||||||
{
|
{
|
||||||
return new AndroidContext();
|
return std::make_unique<AndroidContext>();
|
||||||
}
|
}
|
||||||
} // namespace OpenRCT2::Ui
|
} // namespace OpenRCT2::Ui
|
||||||
|
|
||||||
|
|
|
@ -417,9 +417,9 @@ namespace OpenRCT2::Ui
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IPlatformUiContext* CreatePlatformUiContext()
|
std::unique_ptr<IPlatformUiContext> CreatePlatformUiContext()
|
||||||
{
|
{
|
||||||
return new LinuxContext();
|
return std::make_unique<LinuxContext>();
|
||||||
}
|
}
|
||||||
} // namespace OpenRCT2::Ui
|
} // namespace OpenRCT2::Ui
|
||||||
|
|
||||||
|
|
|
@ -241,9 +241,9 @@ namespace OpenRCT2::Ui
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IPlatformUiContext* CreatePlatformUiContext()
|
std::unique_ptr<IPlatformUiContext> CreatePlatformUiContext()
|
||||||
{
|
{
|
||||||
return new Win32Context();
|
return std::make_unique<Win32Context>();
|
||||||
}
|
}
|
||||||
} // namespace OpenRCT2::Ui
|
} // namespace OpenRCT2::Ui
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,8 @@ class UiContext final : public IUiContext
|
||||||
private:
|
private:
|
||||||
constexpr static uint32_t TOUCH_DOUBLE_TIMEOUT = 300;
|
constexpr static uint32_t TOUCH_DOUBLE_TIMEOUT = 300;
|
||||||
|
|
||||||
IPlatformUiContext* const _platformUiContext;
|
const std::unique_ptr<IPlatformUiContext> _platformUiContext;
|
||||||
IWindowManager* const _windowManager;
|
const std::unique_ptr<IWindowManager> _windowManager;
|
||||||
|
|
||||||
CursorRepository _cursorRepository;
|
CursorRepository _cursorRepository;
|
||||||
|
|
||||||
|
@ -126,9 +126,7 @@ public:
|
||||||
~UiContext() override
|
~UiContext() override
|
||||||
{
|
{
|
||||||
UiContext::CloseWindow();
|
UiContext::CloseWindow();
|
||||||
delete _windowManager;
|
|
||||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||||
delete _platformUiContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Initialise() override
|
void Initialise() override
|
||||||
|
@ -679,7 +677,7 @@ public:
|
||||||
|
|
||||||
IWindowManager* GetWindowManager() override
|
IWindowManager* GetWindowManager() override
|
||||||
{
|
{
|
||||||
return _windowManager;
|
return _windowManager.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetClipboardText(const utf8* target) override
|
bool SetClipboardText(const utf8* target) override
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace OpenRCT2
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] std::unique_ptr<IUiContext> CreateUiContext(const std::shared_ptr<IPlatformEnvironment>& env);
|
[[nodiscard]] std::unique_ptr<IUiContext> CreateUiContext(const std::shared_ptr<IPlatformEnvironment>& env);
|
||||||
[[nodiscard]] IPlatformUiContext* CreatePlatformUiContext();
|
[[nodiscard]] std::unique_ptr<IPlatformUiContext> CreatePlatformUiContext();
|
||||||
|
|
||||||
[[nodiscard]] InGameConsole& GetInGameConsole();
|
[[nodiscard]] InGameConsole& GetInGameConsole();
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
|
@ -220,9 +220,9 @@ namespace OpenRCT2::Ui
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IPlatformUiContext* CreatePlatformUiContext()
|
std::unique_ptr<IPlatformUiContext> CreatePlatformUiContext()
|
||||||
{
|
{
|
||||||
return new macOSContext();
|
return std::make_unique<macOSContext>();
|
||||||
}
|
}
|
||||||
} // namespace OpenRCT2::Ui
|
} // namespace OpenRCT2::Ui
|
||||||
|
|
||||||
|
|
|
@ -592,7 +592,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IWindowManager* OpenRCT2::Ui::CreateWindowManager()
|
std::unique_ptr<IWindowManager> OpenRCT2::Ui::CreateWindowManager()
|
||||||
{
|
{
|
||||||
return new WindowManager();
|
return std::make_unique<WindowManager>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,12 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <openrct2/common.h>
|
#include <openrct2/common.h>
|
||||||
|
|
||||||
namespace OpenRCT2::Ui
|
namespace OpenRCT2::Ui
|
||||||
{
|
{
|
||||||
struct IWindowManager;
|
struct IWindowManager;
|
||||||
|
|
||||||
IWindowManager* CreateWindowManager();
|
std::unique_ptr<IWindowManager> CreateWindowManager();
|
||||||
} // namespace OpenRCT2::Ui
|
} // namespace OpenRCT2::Ui
|
||||||
|
|
|
@ -348,9 +348,8 @@ static ScreenCoordsXY WindowMultiplayerInformationGetSize()
|
||||||
|
|
||||||
// Server name is displayed word-wrapped, so figure out how high it will be.
|
// Server name is displayed word-wrapped, so figure out how high it will be.
|
||||||
{
|
{
|
||||||
utf8* buffer = String::Duplicate(network_get_server_name());
|
u8string buffer = network_get_server_name();
|
||||||
gfx_wrap_string(buffer, width, FontSpriteBase::MEDIUM, &numLines);
|
gfx_wrap_string(buffer.data(), width, FontSpriteBase::MEDIUM, &numLines);
|
||||||
delete buffer;
|
|
||||||
height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2);
|
height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,9 +357,8 @@ static ScreenCoordsXY WindowMultiplayerInformationGetSize()
|
||||||
const utf8* descString = network_get_server_description();
|
const utf8* descString = network_get_server_description();
|
||||||
if (!str_is_null_or_empty(descString))
|
if (!str_is_null_or_empty(descString))
|
||||||
{
|
{
|
||||||
utf8* buffer = String::Duplicate(descString);
|
u8string buffer = descString;
|
||||||
gfx_wrap_string(buffer, width, FontSpriteBase::MEDIUM, &numLines);
|
gfx_wrap_string(buffer.data(), width, FontSpriteBase::MEDIUM, &numLines);
|
||||||
delete buffer;
|
|
||||||
height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2);
|
height += ++numLines * lineHeight + (LIST_ROW_HEIGHT / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace OpenRCT2::Ui
|
||||||
class DummyUiContext final : public IUiContext
|
class DummyUiContext final : public IUiContext
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
IWindowManager* const _windowManager = CreateDummyWindowManager();
|
std::unique_ptr<IWindowManager> const _windowManager = CreateDummyWindowManager();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Initialise() override
|
void Initialise() override
|
||||||
|
@ -190,7 +190,7 @@ namespace OpenRCT2::Ui
|
||||||
// In-game UI
|
// In-game UI
|
||||||
IWindowManager* GetWindowManager() override
|
IWindowManager* GetWindowManager() override
|
||||||
{
|
{
|
||||||
return _windowManager;
|
return _windowManager.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clipboard
|
// Clipboard
|
||||||
|
@ -204,11 +204,6 @@ namespace OpenRCT2::Ui
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
~DummyUiContext()
|
|
||||||
{
|
|
||||||
delete _windowManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HasFilePicker() const override
|
bool HasFilePicker() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -70,8 +70,8 @@ namespace OpenRCT2::Ui
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IWindowManager* CreateDummyWindowManager()
|
std::unique_ptr<IWindowManager> CreateDummyWindowManager()
|
||||||
{
|
{
|
||||||
return new DummyWindowManager();
|
return std::make_unique<DummyWindowManager>();
|
||||||
}
|
}
|
||||||
} // namespace OpenRCT2::Ui
|
} // namespace OpenRCT2::Ui
|
||||||
|
|
|
@ -44,5 +44,5 @@ namespace OpenRCT2::Ui
|
||||||
virtual rct_window* GetOwner(const rct_viewport* viewport) abstract;
|
virtual rct_window* GetOwner(const rct_viewport* viewport) abstract;
|
||||||
};
|
};
|
||||||
|
|
||||||
IWindowManager* CreateDummyWindowManager();
|
std::unique_ptr<IWindowManager> CreateDummyWindowManager();
|
||||||
} // namespace OpenRCT2::Ui
|
} // namespace OpenRCT2::Ui
|
||||||
|
|
Loading…
Reference in New Issue