Bind Win32 app shell and move more legacy platform state

This commit is contained in:
2026-06-17 01:54:59 +02:00
parent 3cbc88fe78
commit 5c8a87faa0
11 changed files with 185 additions and 123 deletions

View File

@@ -18,6 +18,7 @@ namespace pp::platform::windows {
namespace {
struct RetainedWindowsRuntimeState final {
App* app = nullptr;
AppRuntime* runtime = nullptr;
};
@@ -38,9 +39,11 @@ void register_touch_window(HWND hWnd)
void initialize_runtime_threads()
{
auto* app = bound_app();
auto* runtime = bound_runtime();
mark_lifecycle_running();
App::I->runtime().render_thread_start(*App::I);
App::I->runtime().ui_thread_start(*App::I);
runtime->render_thread_start(*app);
runtime->ui_thread_start(*app);
}
void install_debug_gl_callbacks()
@@ -85,10 +88,11 @@ void restore_window_placement(HWND hWnd, int show_command)
void run_main_message_loop()
{
MSG msg;
auto* app = bound_app();
LOG("start main loop");
while (lifecycle_is_running())
{
auto present = App::I->animate || App::I->redraw ?
auto present = app->animate || app->redraw ?
PeekMessage(&msg, 0, 0, 0, PM_REMOVE) : GetMessage(&msg, 0, 0, 0);
if (msg.message == WM_QUIT)
@@ -113,6 +117,16 @@ void shutdown_main_window_runtime(const MainWindowStartupState& startup, HINSTAN
}
void bind_app(App* app) noexcept
{
retained_runtime_state().app = app;
}
App* bound_app() noexcept
{
return retained_runtime_state().app;
}
void bind_runtime(AppRuntime* runtime) noexcept
{
retained_runtime_state().runtime = runtime;
@@ -128,10 +142,12 @@ int run_main_application(int argc, char** argv)
auto& state = retained_state();
state.hInst = GetModuleHandle(NULL);
App::I = new App();
bind_runtime(&App::I->runtime());
App::I->set_platform_services(&pp::platform::windows::platform_services());
App::I->initLog();
auto* app = new App();
App::I = app;
bind_app(app);
bind_runtime(&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();
@@ -149,7 +165,7 @@ int run_main_application(int argc, char** argv)
pp::platform::windows::read_WMI_info();
App::I->create();
app->create();
auto startup = pp::platform::windows::initialize_main_window_startup_state();
auto context = pp::platform::windows::OpenGlWindowContext {};
@@ -158,9 +174,11 @@ int run_main_application(int argc, char** argv)
case pp::platform::windows::MainStartupResult::Ok:
break;
case pp::platform::windows::MainStartupResult::GladLoadFailure:
bind_app(nullptr);
bind_runtime(nullptr);
return 0;
case pp::platform::windows::MainStartupResult::MissingCoreContextSupport:
bind_app(nullptr);
bind_runtime(nullptr);
return -1;
}
@@ -173,8 +191,9 @@ int run_main_application(int argc, char** argv)
switch (const_hash(argv[1]))
{
case const_hash("convert"):
App::I->initShaders();
App::I->cmd_convert(argv[2], argv[3]);
app->initShaders();
app->cmd_convert(argv[2], argv[3]);
bind_app(nullptr);
bind_runtime(nullptr);
return 0;
case const_hash("-vrmode"):
@@ -192,6 +211,7 @@ int run_main_application(int argc, char** argv)
void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, SplashScreen& splash)
{
auto& state = retained_state();
auto* app = bound_app();
register_touch_window(state.hWnd);
wglMakeCurrent(NULL, NULL);
@@ -201,11 +221,11 @@ void run_main_window_runtime(const MainWindowStartupState& startup, bool start_i
initialize_wintab(state.hWnd, state.sandboxed);
set_main_window_icon(state.hWnd);
App::I->ui_sync();
app->ui_sync();
restore_window_placement(state.hWnd, startup.show_command);
if (start_in_vr)
App::I->vr_start();
app->vr_start();
LOG("show main window");
SetForegroundWindow(state.hWnd);