Extract Win32 lifecycle state

This commit is contained in:
2026-06-17 11:24:27 +02:00
parent 45f3d501e7
commit 8a4d611b07
6 changed files with 83 additions and 34 deletions

View File

@@ -4,42 +4,13 @@
#include "app.h"
#include "legacy_preference_storage.h"
#include "platform_windows/windows_lifecycle_state.h"
#include "platform_windows/windows_main_window_session.h"
#include "platform_windows/windows_runtime_shell.h"
#include "platform_windows/windows_stylus_input.h"
namespace pp::platform::windows {
namespace {
[[nodiscard]] std::atomic<int>& retained_running_state() noexcept
{
static std::atomic<int> running{-1};
return running;
}
}
std::atomic<int>& lifecycle_running_state() noexcept
{
return retained_running_state();
}
void mark_lifecycle_running() noexcept
{
retained_running_state().store(1, std::memory_order_relaxed);
}
void mark_lifecycle_stopped() noexcept
{
retained_running_state().store(0, std::memory_order_relaxed);
}
bool lifecycle_is_running() noexcept
{
return retained_running_state().load(std::memory_order_relaxed) == 1;
}
void request_window_close(HWND hWnd)
{
PostMessage(hWnd, kUserCloseMessage, 0, 0);
@@ -64,12 +35,12 @@ void update_stylus_frame(float dt)
void update_window_fps(HWND hWnd, const wchar_t* window_title, VrShellState& vr, int frames)
{
static wchar_t title_fps[512];
auto* title_fps = retained_window_fps_title_buffer();
const int vr_fps = current_vr_fps(vr);
if (read_vr_session_snapshot(vr).vr_active)
swprintf_s(title_fps, L"%s - %d fps - %d vr fps", window_title, frames, vr_fps);
swprintf_s(title_fps, 512, L"%s - %d fps - %d vr fps", window_title, frames, vr_fps);
else
swprintf_s(title_fps, L"%s - %d fps", window_title, frames);
swprintf_s(title_fps, 512, L"%s - %d fps", window_title, frames);
SetWindowText(hWnd, title_fps);
PostMessage(hWnd, kUserWakeupMessage, 0, 0);
@@ -88,7 +59,7 @@ void save_window_preferences(HWND hWnd)
bool start_window_vr(VrShellState& vr, bool sandboxed)
{
return start_vr_shell(vr, sandboxed, retained_running_state());
return start_vr_shell(vr, sandboxed, retained_lifecycle_running_state());
}
void stop_window_vr(VrShellState& vr)

View File

@@ -0,0 +1,51 @@
#include "pch.h"
#include "platform_windows/windows_lifecycle_state.h"
namespace pp::platform::windows {
namespace {
struct RetainedWindowLifecycleState final {
std::atomic<int> running{-1};
wchar_t title_fps[512]{};
};
[[nodiscard]] RetainedWindowLifecycleState& retained_window_lifecycle_state() noexcept
{
static RetainedWindowLifecycleState state;
return state;
}
}
std::atomic<int>& lifecycle_running_state() noexcept
{
return retained_lifecycle_running_state();
}
void mark_lifecycle_running() noexcept
{
retained_lifecycle_running_state().store(1, std::memory_order_relaxed);
}
void mark_lifecycle_stopped() noexcept
{
retained_lifecycle_running_state().store(0, std::memory_order_relaxed);
}
bool lifecycle_is_running() noexcept
{
return retained_lifecycle_running_state().load(std::memory_order_relaxed) == 1;
}
std::atomic<int>& retained_lifecycle_running_state() noexcept
{
return retained_window_lifecycle_state().running;
}
wchar_t* retained_window_fps_title_buffer() noexcept
{
return retained_window_lifecycle_state().title_fps;
}
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include <Windows.h>
#include <atomic>
namespace pp::platform::windows {
[[nodiscard]] std::atomic<int>& lifecycle_running_state() noexcept;
void mark_lifecycle_running() noexcept;
void mark_lifecycle_stopped() noexcept;
[[nodiscard]] bool lifecycle_is_running() noexcept;
[[nodiscard]] std::atomic<int>& retained_lifecycle_running_state() noexcept;
[[nodiscard]] wchar_t* retained_window_fps_title_buffer() noexcept;
}