Bind Win32 app shell and move more legacy platform state
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
|
||||
namespace pp::platform::windows {
|
||||
|
||||
[[nodiscard]] App* bound_app() noexcept;
|
||||
|
||||
struct VrShellState final {
|
||||
std::mutex snapshot_mutex;
|
||||
VrSessionSnapshot session;
|
||||
@@ -72,9 +74,10 @@ inline bool start_vr_shell(VrShellState& state, bool sandboxed, std::atomic<int>
|
||||
if (sandboxed)
|
||||
return false;
|
||||
|
||||
auto* app = bound_app();
|
||||
state.vive = std::make_unique<Vive>();
|
||||
state.vive->on_draw = [](const glm::mat4& proj, const glm::mat4& view, const glm::mat4& pose) {
|
||||
App::I->vr_draw(proj, view, pose);
|
||||
state.vive->on_draw = [app](const glm::mat4& proj, const glm::mat4& view, const glm::mat4& pose) {
|
||||
app->vr_draw(proj, view, pose);
|
||||
};
|
||||
if (!state.vive->Initialize())
|
||||
{
|
||||
@@ -89,7 +92,7 @@ inline bool start_vr_shell(VrShellState& state, bool sandboxed, std::atomic<int>
|
||||
state.hmd_renderer.join();
|
||||
}
|
||||
|
||||
state.hmd_renderer = std::jthread([&state, &running](std::stop_token stop_token) {
|
||||
state.hmd_renderer = std::jthread([app, &state, &running](std::stop_token stop_token) {
|
||||
if (!state.vive)
|
||||
return;
|
||||
|
||||
@@ -98,13 +101,13 @@ inline bool start_vr_shell(VrShellState& state, bool sandboxed, std::atomic<int>
|
||||
clear_vr_session_snapshot(state, true);
|
||||
state.vr_running.store(true, std::memory_order_relaxed);
|
||||
|
||||
state.vive->on_analog_button = std::bind(&App::vr_analog, App::I, std::placeholders::_1,
|
||||
state.vive->on_analog_button = std::bind(&App::vr_analog, app, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
|
||||
state.vive->on_button = std::bind(&App::vr_digital, App::I, std::placeholders::_1,
|
||||
state.vive->on_button = std::bind(&App::vr_digital, app, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
|
||||
|
||||
App::I->render_task([] {
|
||||
App::I->vr_draw_ui();
|
||||
app->render_task([app] {
|
||||
app->vr_draw_ui();
|
||||
});
|
||||
|
||||
const float target_tick_rate = 90;
|
||||
@@ -136,11 +139,11 @@ inline bool start_vr_shell(VrShellState& state, bool sandboxed, std::atomic<int>
|
||||
state.vive->m_active,
|
||||
state.vive->m_controllers[0],
|
||||
state.vive->m_pose);
|
||||
App::I->vr_update(dt);
|
||||
app->vr_update(dt);
|
||||
|
||||
if (state.vr_running.load(std::memory_order_relaxed) && state.vive->m_active)
|
||||
{
|
||||
App::I->render_task([&state] {
|
||||
app->render_task([&state] {
|
||||
state.vive->Draw();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user