mirror of
https://github.com/izzy2lost/libultraship.git
synced 2026-06-19 01:16:13 -07:00
make Context not need Fast3dWindow (#753)
* make `Context` not need `Fast3dWindow` * change `Init`s from `void` to `bool` * clang format * address init fails in context
This commit is contained in:
+104
-45
@@ -6,7 +6,6 @@
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include "install_config.h"
|
||||
#include "graphic/Fast3D/debug/GfxDebugger.h"
|
||||
#include "graphic/Fast3D/Fast3dWindow.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <tchar.h>
|
||||
@@ -42,16 +41,19 @@ Context::~Context() {
|
||||
spdlog::shutdown();
|
||||
}
|
||||
|
||||
std::shared_ptr<Context> Context::CreateInstance(const std::string name, const std::string shortName,
|
||||
const std::string configFilePath,
|
||||
const std::vector<std::string>& archivePaths,
|
||||
const std::unordered_set<uint32_t>& validHashes,
|
||||
uint32_t reservedThreadCount, AudioSettings audioSettings) {
|
||||
std::shared_ptr<Context>
|
||||
Context::CreateInstance(const std::string name, const std::string shortName, const std::string configFilePath,
|
||||
const std::vector<std::string>& archivePaths, const std::unordered_set<uint32_t>& validHashes,
|
||||
uint32_t reservedThreadCount, AudioSettings audioSettings, std::shared_ptr<Window> window) {
|
||||
if (mContext.expired()) {
|
||||
auto shared = std::make_shared<Context>(name, shortName, configFilePath);
|
||||
mContext = shared;
|
||||
shared->Init(archivePaths, validHashes, reservedThreadCount, audioSettings);
|
||||
return shared;
|
||||
if (shared->Init(archivePaths, validHashes, reservedThreadCount, audioSettings, window)) {
|
||||
return shared;
|
||||
} else {
|
||||
SPDLOG_ERROR("Failed to initialize");
|
||||
return nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("Trying to create a context when it already exists. Returning existing.");
|
||||
@@ -76,23 +78,16 @@ Context::Context(std::string name, std::string shortName, std::string configFile
|
||||
: mConfigFilePath(std::move(configFilePath)), mName(std::move(name)), mShortName(std::move(shortName)) {
|
||||
}
|
||||
|
||||
void Context::Init(const std::vector<std::string>& archivePaths, const std::unordered_set<uint32_t>& validHashes,
|
||||
uint32_t reservedThreadCount, AudioSettings audioSettings) {
|
||||
InitLogging();
|
||||
InitConfiguration();
|
||||
InitConsoleVariables();
|
||||
InitResourceManager(archivePaths, validHashes, reservedThreadCount);
|
||||
InitControlDeck();
|
||||
InitCrashHandler();
|
||||
InitConsole();
|
||||
InitWindow();
|
||||
InitAudio(audioSettings);
|
||||
InitGfxDebugger();
|
||||
bool Context::Init(const std::vector<std::string>& archivePaths, const std::unordered_set<uint32_t>& validHashes,
|
||||
uint32_t reservedThreadCount, AudioSettings audioSettings, std::shared_ptr<Window> window) {
|
||||
return InitLogging() && InitConfiguration() && InitConsoleVariables() &&
|
||||
InitResourceManager(archivePaths, validHashes, reservedThreadCount) && InitControlDeck() &&
|
||||
InitCrashHandler() && InitConsole() && InitWindow(window) && InitAudio(audioSettings) && InitGfxDebugger();
|
||||
}
|
||||
|
||||
void Context::InitLogging() {
|
||||
bool Context::InitLogging() {
|
||||
if (GetLogger() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -162,29 +157,47 @@ void Context::InitLogging() {
|
||||
|
||||
spdlog::register_logger(GetLogger());
|
||||
spdlog::set_default_logger(GetLogger());
|
||||
} catch (const spdlog::spdlog_ex& ex) { std::cout << "Log initialization failed: " << ex.what() << std::endl; }
|
||||
return true;
|
||||
} catch (const spdlog::spdlog_ex& ex) {
|
||||
std::cout << "Log initialization failed: " << ex.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Context::InitConfiguration() {
|
||||
bool Context::InitConfiguration() {
|
||||
if (GetConfig() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mConfig = std::make_shared<Config>(GetPathRelativeToAppDirectory(mConfigFilePath));
|
||||
|
||||
if (GetConfig() == nullptr) {
|
||||
SPDLOG_ERROR("Failed to initialize config");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::InitConsoleVariables() {
|
||||
bool Context::InitConsoleVariables() {
|
||||
if (GetConsoleVariables() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mConsoleVariables = std::make_shared<ConsoleVariable>();
|
||||
|
||||
if (GetConsoleVariables() == nullptr) {
|
||||
SPDLOG_ERROR("Failed to initialize console variables");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::InitResourceManager(const std::vector<std::string>& archivePaths,
|
||||
bool Context::InitResourceManager(const std::vector<std::string>& archivePaths,
|
||||
const std::unordered_set<uint32_t>& validHashes, uint32_t reservedThreadCount) {
|
||||
if (GetResourceManager() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mMainPath = GetConfig()->GetString("Game.Main Archive", GetAppDirectoryPath());
|
||||
@@ -209,59 +222,105 @@ void Context::InitResourceManager(const std::vector<std::string>& archivePaths,
|
||||
// We need this exit to close the app when we dismiss the dialog
|
||||
exit(0);
|
||||
#endif
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::InitControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks) {
|
||||
bool Context::InitControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks) {
|
||||
if (GetControlDeck() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mControlDeck = std::make_shared<ControlDeck>(additionalBitmasks);
|
||||
|
||||
if (GetControlDeck() == nullptr) {
|
||||
SPDLOG_ERROR("Failed to initialize control deck");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::InitCrashHandler() {
|
||||
bool Context::InitCrashHandler() {
|
||||
if (GetCrashHandler() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mCrashHandler = std::make_shared<CrashHandler>();
|
||||
|
||||
if (GetCrashHandler() == nullptr) {
|
||||
SPDLOG_ERROR("Failed to initialize crash handler");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::InitAudio(AudioSettings settings) {
|
||||
bool Context::InitAudio(AudioSettings settings) {
|
||||
if (GetAudio() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mAudio = std::make_shared<Audio>(settings);
|
||||
|
||||
if (GetAudio() == nullptr) {
|
||||
SPDLOG_ERROR("Failed to initialize audio");
|
||||
return false;
|
||||
}
|
||||
|
||||
GetAudio()->Init();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::InitGfxDebugger() {
|
||||
bool Context::InitGfxDebugger() {
|
||||
if (GetGfxDebugger() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mGfxDebugger = std::make_shared<Fast::GfxDebugger>();
|
||||
|
||||
if (GetGfxDebugger() == nullptr) {
|
||||
SPDLOG_ERROR("Failed to initialize gfx debugger");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Context::InitConsole() {
|
||||
bool Context::InitConsole() {
|
||||
if (GetConsole() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mConsole = std::make_shared<Console>();
|
||||
GetConsole()->Init();
|
||||
}
|
||||
|
||||
void Context::InitWindow(std::vector<std::shared_ptr<GuiWindow>> guiWindows) {
|
||||
if (GetConsole() == nullptr) {
|
||||
SPDLOG_ERROR("Failed to initialize console");
|
||||
return false;
|
||||
}
|
||||
|
||||
GetConsole()->Init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Context::InitWindow(std::shared_ptr<Window> window) {
|
||||
if (GetWindow() != nullptr) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
mWindow = window;
|
||||
|
||||
if (GetWindow() == nullptr) {
|
||||
SPDLOG_ERROR("Failed to initialize window");
|
||||
return false;
|
||||
}
|
||||
|
||||
mWindow = std::make_shared<Fast::Fast3dWindow>(guiWindows);
|
||||
GetWindow()->Init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<ConsoleVariable> Context::GetConsoleVariables() {
|
||||
|
||||
+14
-13
@@ -25,7 +25,8 @@ class Context {
|
||||
const std::string configFilePath,
|
||||
const std::vector<std::string>& archivePaths = {},
|
||||
const std::unordered_set<uint32_t>& validHashes = {},
|
||||
uint32_t reservedThreadCount = 1, AudioSettings audioSettings = {});
|
||||
uint32_t reservedThreadCount = 1, AudioSettings audioSettings = {},
|
||||
std::shared_ptr<Window> window = nullptr);
|
||||
static std::shared_ptr<Context> CreateUninitializedInstance(const std::string name, const std::string shortName,
|
||||
const std::string configFilePath);
|
||||
static std::string GetAppBundlePath();
|
||||
@@ -37,8 +38,8 @@ class Context {
|
||||
Context(std::string name, std::string shortName, std::string configFilePath);
|
||||
~Context();
|
||||
|
||||
void Init(const std::vector<std::string>& archivePaths, const std::unordered_set<uint32_t>& validHashes,
|
||||
uint32_t reservedThreadCount, AudioSettings audioSettings);
|
||||
bool Init(const std::vector<std::string>& archivePaths, const std::unordered_set<uint32_t>& validHashes,
|
||||
uint32_t reservedThreadCount, AudioSettings audioSettings, std::shared_ptr<Window> window = nullptr);
|
||||
|
||||
std::shared_ptr<spdlog::logger> GetLogger();
|
||||
std::shared_ptr<Config> GetConfig();
|
||||
@@ -54,17 +55,17 @@ class Context {
|
||||
std::string GetName();
|
||||
std::string GetShortName();
|
||||
|
||||
void InitLogging();
|
||||
void InitConfiguration();
|
||||
void InitConsoleVariables();
|
||||
void InitResourceManager(const std::vector<std::string>& archivePaths = {},
|
||||
bool InitLogging();
|
||||
bool InitConfiguration();
|
||||
bool InitConsoleVariables();
|
||||
bool InitResourceManager(const std::vector<std::string>& archivePaths = {},
|
||||
const std::unordered_set<uint32_t>& validHashes = {}, uint32_t reservedThreadCount = 1);
|
||||
void InitControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks = {});
|
||||
void InitCrashHandler();
|
||||
void InitAudio(AudioSettings settings);
|
||||
void InitGfxDebugger();
|
||||
void InitConsole();
|
||||
void InitWindow(std::vector<std::shared_ptr<GuiWindow>> guiWindows = {});
|
||||
bool InitControlDeck(std::vector<CONTROLLERBUTTONS_T> additionalBitmasks = {});
|
||||
bool InitCrashHandler();
|
||||
bool InitAudio(AudioSettings settings);
|
||||
bool InitGfxDebugger();
|
||||
bool InitConsole();
|
||||
bool InitWindow(std::shared_ptr<Window> window = nullptr);
|
||||
|
||||
protected:
|
||||
Context() = default;
|
||||
|
||||
Reference in New Issue
Block a user