Own Win32 startup flow in runtime layer
This commit is contained in:
@@ -2,9 +2,123 @@
|
||||
|
||||
#include "platform_windows/windows_runtime_flow.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "platform_windows/windows_bootstrap_helpers.h"
|
||||
#include "platform_windows/windows_main_window_session.h"
|
||||
#include "platform_windows/windows_platform_services.h"
|
||||
#include "platform_windows/windows_runtime_state.h"
|
||||
#include "platform_windows/windows_stylus_input.h"
|
||||
#include "platform_windows/windows_runtime_session.h"
|
||||
#include "platform_windows/windows_window_shell.h"
|
||||
|
||||
namespace pp::platform::windows {
|
||||
namespace {
|
||||
|
||||
struct BoundWindowsRuntimeFlow final {
|
||||
explicit BoundWindowsRuntimeFlow(HINSTANCE instance_handle)
|
||||
: splash(instance_handle),
|
||||
app(initialize_bound_app_runtime())
|
||||
{
|
||||
bind_main_window_session(&session);
|
||||
|
||||
app.set_platform_services(&pp::platform::windows::platform_services());
|
||||
app.initLog();
|
||||
|
||||
pp::platform::windows::init_shcore_API();
|
||||
pp::platform::windows::initialize_stylus_input();
|
||||
|
||||
if (pp::platform::windows::SetProcessDpiAwareness_fn)
|
||||
pp::platform::windows::SetProcessDpiAwareness_fn(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
|
||||
pp::platform::windows::ensure_runtime_data_directory();
|
||||
pp::platform::windows::initialize_retained_input_state();
|
||||
pp::platform::windows::setup_exception_handler(app);
|
||||
pp::platform::windows::read_WMI_info();
|
||||
|
||||
app.create();
|
||||
}
|
||||
|
||||
~BoundWindowsRuntimeFlow()
|
||||
{
|
||||
release_bound_app();
|
||||
bind_main_window_session(nullptr);
|
||||
}
|
||||
|
||||
BoundWindowsRuntimeFlow(const BoundWindowsRuntimeFlow&) = delete;
|
||||
BoundWindowsRuntimeFlow& operator=(const BoundWindowsRuntimeFlow&) = delete;
|
||||
|
||||
MainWindowSession session{};
|
||||
SplashScreen splash;
|
||||
App& app;
|
||||
};
|
||||
|
||||
[[nodiscard]] int failure_exit_code(MainStartupResult result) noexcept
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case MainStartupResult::Ok:
|
||||
return 0;
|
||||
case MainStartupResult::GladLoadFailure:
|
||||
return 0;
|
||||
case MainStartupResult::MissingCoreContextSupport:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool handle_runtime_mode(
|
||||
App& app,
|
||||
int argc,
|
||||
char** argv,
|
||||
bool& start_in_vr)
|
||||
{
|
||||
if (argc <= 1)
|
||||
return false;
|
||||
|
||||
switch (const_hash(argv[1]))
|
||||
{
|
||||
case const_hash("convert"):
|
||||
app.initShaders();
|
||||
app.cmd_convert(argv[2], argv[3]);
|
||||
return true;
|
||||
case const_hash("-vrmode"):
|
||||
start_in_vr = true;
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int run_main_application_flow(int argc, char** argv)
|
||||
{
|
||||
const auto instance = GetModuleHandle(NULL);
|
||||
auto runtime = BoundWindowsRuntimeFlow { instance };
|
||||
|
||||
auto startup = pp::platform::windows::initialize_main_window_startup_state(runtime.app);
|
||||
auto context = pp::platform::windows::OpenGlWindowContext {};
|
||||
const auto startup_result = pp::platform::windows::initialize_main_window_and_gl(
|
||||
startup,
|
||||
runtime.session,
|
||||
instance,
|
||||
context);
|
||||
if (startup_result != pp::platform::windows::MainStartupResult::Ok)
|
||||
return failure_exit_code(startup_result);
|
||||
|
||||
bool start_in_vr = false;
|
||||
if (handle_runtime_mode(runtime.app, argc, argv, start_in_vr))
|
||||
return 0;
|
||||
|
||||
pp::platform::windows::run_bound_main_window_runtime(
|
||||
startup,
|
||||
runtime.session,
|
||||
start_in_vr,
|
||||
instance,
|
||||
runtime.splash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void run_bound_main_window_runtime(
|
||||
const MainWindowStartupState& startup,
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
namespace pp::platform::windows {
|
||||
|
||||
int run_main_application_flow(int argc, char** argv);
|
||||
|
||||
void run_bound_main_window_runtime(
|
||||
const MainWindowStartupState& startup,
|
||||
MainWindowSession& session,
|
||||
|
||||
@@ -2,90 +2,13 @@
|
||||
|
||||
#include "platform_windows/windows_runtime_shell.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "platform_windows/windows_bootstrap_helpers.h"
|
||||
#include "platform_windows/windows_main_window_session.h"
|
||||
#include "platform_windows/windows_platform_services.h"
|
||||
#include "platform_windows/windows_runtime_flow.h"
|
||||
#include "platform_windows/windows_runtime_state.h"
|
||||
#include "platform_windows/windows_stylus_input.h"
|
||||
#include "platform_windows/windows_window_shell.h"
|
||||
|
||||
namespace pp::platform::windows {
|
||||
|
||||
int run_main_application(int argc, char** argv)
|
||||
{
|
||||
const auto instance = GetModuleHandle(NULL);
|
||||
auto session = MainWindowSession {};
|
||||
bind_main_window_session(&session);
|
||||
|
||||
auto& app = initialize_bound_app_runtime();
|
||||
app.set_platform_services(&pp::platform::windows::platform_services());
|
||||
app.initLog();
|
||||
|
||||
pp::platform::windows::init_shcore_API();
|
||||
pp::platform::windows::initialize_stylus_input();
|
||||
|
||||
if (pp::platform::windows::SetProcessDpiAwareness_fn)
|
||||
pp::platform::windows::SetProcessDpiAwareness_fn(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
|
||||
pp::platform::windows::ensure_runtime_data_directory();
|
||||
|
||||
pp::platform::windows::SplashScreen splash(instance);
|
||||
|
||||
pp::platform::windows::initialize_retained_input_state();
|
||||
|
||||
pp::platform::windows::setup_exception_handler(app);
|
||||
|
||||
pp::platform::windows::read_WMI_info();
|
||||
|
||||
app.create();
|
||||
|
||||
auto startup = pp::platform::windows::initialize_main_window_startup_state(app);
|
||||
auto context = pp::platform::windows::OpenGlWindowContext {};
|
||||
switch (pp::platform::windows::initialize_main_window_and_gl(
|
||||
startup,
|
||||
session,
|
||||
instance,
|
||||
context))
|
||||
{
|
||||
case pp::platform::windows::MainStartupResult::Ok:
|
||||
break;
|
||||
case pp::platform::windows::MainStartupResult::GladLoadFailure:
|
||||
release_bound_app();
|
||||
bind_main_window_session(nullptr);
|
||||
return 0;
|
||||
case pp::platform::windows::MainStartupResult::MissingCoreContextSupport:
|
||||
release_bound_app();
|
||||
bind_main_window_session(nullptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//wglSwapIntervalEXT(1);
|
||||
|
||||
bool start_in_vr = false;
|
||||
if (argc > 1)
|
||||
{
|
||||
switch (const_hash(argv[1]))
|
||||
{
|
||||
case const_hash("convert"):
|
||||
app.initShaders();
|
||||
app.cmd_convert(argv[2], argv[3]);
|
||||
release_bound_app();
|
||||
bind_main_window_session(nullptr);
|
||||
return 0;
|
||||
case const_hash("-vrmode"):
|
||||
start_in_vr = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pp::platform::windows::run_bound_main_window_runtime(startup, session, start_in_vr, instance, splash);
|
||||
release_bound_app();
|
||||
bind_main_window_session(nullptr);
|
||||
return 0;
|
||||
return run_main_application_flow(argc, argv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user