Skip to content

Commit

Permalink
Keybinds: Add "Disable VR Key" (Fixes #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jan 2, 2024
1 parent fea6c7e commit 4f9f362
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src/mods/VR.cpp
Expand Up @@ -1630,15 +1630,9 @@ void VR::on_pre_imgui_frame() {
}
}

void VR::on_frame() {
void VR::handle_keybinds() {
ZoneScopedN(__FUNCTION__);

m_cvar_manager->on_frame();

if (!get_runtime()->ready()) {
return;
}

if (m_keybind_recenter->is_key_down_once()) {
recenter_view();
}
Expand All @@ -1663,6 +1657,21 @@ void VR::on_frame() {
m_2d_screen_mode->toggle();
}

if (m_keybind_disable_vr->is_key_down_once()) {
m_disable_vr = !m_disable_vr; // definitely should not be persistent
}
}

void VR::on_frame() {
ZoneScopedN(__FUNCTION__);

m_cvar_manager->on_frame();
handle_keybinds();

if (!get_runtime()->ready()) {
return;
}

const auto now = std::chrono::steady_clock::now();
const auto is_allowed_draw_window = now - m_last_xinput_update < std::chrono::seconds(2);

Expand Down Expand Up @@ -2236,8 +2245,9 @@ void VR::on_draw_sidebar_entry(std::string_view name) {
}

ImGui::SetNextItemOpen(true, ImGuiCond_::ImGuiCond_Once);
if (ImGui::TreeNode("Overlay Keys")) {
if (ImGui::TreeNode("Overlay/Runtime Keys")) {
m_keybind_toggle_2d_screen->draw("Toggle 2D Screen Mode Key");
m_keybind_disable_vr->draw("Disable VR Key");

ImGui::TreePop();
}
Expand Down Expand Up @@ -2277,6 +2287,7 @@ void VR::on_draw_sidebar_entry(std::string_view name) {
ImGui::Checkbox("Disable View Matrix Override", &m_disable_view_matrix_override);
ImGui::Checkbox("Disable Backbuffer Size Override", &m_disable_backbuffer_size_override);
ImGui::Checkbox("Disable VR Overlay", &m_disable_overlay);
ImGui::Checkbox("Disable VR Entirely", &m_disable_vr);
ImGui::Checkbox("Stereo Emulation Mode", &m_stereo_emulation_mode);
ImGui::Checkbox("Wait for Present", &m_wait_for_present);
ImGui::Checkbox("Controllers allowed", &m_controllers_allowed);
Expand Down
8 changes: 7 additions & 1 deletion src/mods/VR.hpp
Expand Up @@ -106,7 +106,10 @@ class VR : public Mod {
void on_draw_ui() override;
void on_draw_sidebar_entry(std::string_view name) override;
void on_pre_imgui_frame() override;

void handle_keybinds();
void on_frame() override;

void on_present() override;
void on_post_present() override;

Expand Down Expand Up @@ -231,7 +234,7 @@ class VR : public Mod {
}

bool is_hmd_active() const {
return get_runtime()->ready() || (m_stereo_emulation_mode && get_runtime()->loaded);
return !m_disable_vr && (get_runtime()->ready() || (m_stereo_emulation_mode && get_runtime()->loaded));
}

auto get_hmd() const {
Expand Down Expand Up @@ -806,6 +809,8 @@ class VR : public Mod {
const ModKey::Ptr m_keybind_load_camera_2{ ModKey::create(generate_name("LoadCamera2Key")) };

const ModKey::Ptr m_keybind_toggle_2d_screen{ ModKey::create(generate_name("Toggle2DScreenKey")) };
const ModKey::Ptr m_keybind_disable_vr{ ModKey::create(generate_name("DisableVRKey")) };
bool m_disable_vr{false}; // definitely should not be persistent

struct DecoupledPitchData {
mutable std::shared_mutex mtx{};
Expand Down Expand Up @@ -878,6 +883,7 @@ class VR : public Mod {
*m_keybind_load_camera_1,
*m_keybind_load_camera_2,
*m_keybind_toggle_2d_screen,
*m_keybind_disable_vr,
};


Expand Down

0 comments on commit 4f9f362

Please sign in to comment.