Skip to content

Commit

Permalink
Snapturn: Migrate processing code to VR, remove unnecessary statics
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 17, 2023
1 parent d2726ed commit 021c6e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
24 changes: 24 additions & 0 deletions src/mods/VR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <sdk/Globals.hpp>
#include <sdk/CVar.hpp>
#include <sdk/threading/GameThreadWorker.hpp>
#include <sdk/UGameplayStatics.hpp>
#include <sdk/APlayerController.hpp>

#include <tracy/Tracy.hpp>

Expand Down Expand Up @@ -2781,4 +2783,26 @@ void VR::recenter_view() {
const auto new_rotation_offset = glm::normalize(glm::inverse(utility::math::flatten(glm::quat{get_rotation(0)})));

set_rotation_offset(new_rotation_offset);
}

void VR::process_snapturn() {
if (!m_snapturn_on_frame) {
return;
}

const auto world = sdk::UEngine::get()->get_world();
if (const auto controller = sdk::UGameplayStatics::get()->get_player_controller(world, 0); controller != nullptr) {
auto controller_rot = controller->get_control_rotation();
auto turn_degrees = get_snapturn_angle();

if (m_snapturn_left) {
turn_degrees = -turn_degrees;
m_snapturn_left = false;
}

controller_rot.y += turn_degrees;
controller->set_control_rotation(controller_rot);
}

m_snapturn_on_frame = false;
}
8 changes: 5 additions & 3 deletions src/mods/VR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,14 @@ class VR : public Mod {
const ModToggle::Ptr m_roomscale_movement_actor_rotation{ ModToggle::create(generate_name("RoomscaleMovementActorRotation"), false) };

// Snap turn settings and globals
void process_snapturn();

const ModToggle::Ptr m_snapturn{ ModToggle::create(generate_name("SnapTurn"), false) };
const ModSlider::Ptr m_snapturn_joystick_deadzone{ ModSlider::create(generate_name("SnapturnJoystickDeadzone"), 0.01f, 0.99f, 0.2f) };
const ModInt32::Ptr m_snapturn_angle{ ModSliderInt32::create(generate_name("SnapturnTurnAngle"), 1, 359, 45) };
static inline bool m_snapturn_on_frame{false};
static inline bool m_snapturn_left{false};
static inline bool m_was_snapturn_run_on_input{false};
bool m_snapturn_on_frame{false};
bool m_snapturn_left{false};
bool m_was_snapturn_run_on_input{false};

// Aim method and movement orientation are not the same thing, but they can both have the same options
const ModCombo::Ptr m_aim_method{ ModCombo::create(generate_name("AimMethod"), s_aim_method_names, AimMethod::GAME) };
Expand Down
16 changes: 1 addition & 15 deletions src/mods/vr/FFakeStereoRenderingHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4136,21 +4136,7 @@ __forceinline void FFakeStereoRenderingHook::calculate_stereo_view_offset(
}

// Process snapturn
if (vr->m_snapturn_on_frame) {
const auto world = sdk::UEngine::get()->get_world();
if (const auto controller = sdk::UGameplayStatics::get()->get_player_controller(world, 0); controller != nullptr) {
auto controller_rot = controller->get_control_rotation();
auto turn_degrees = vr->get_snapturn_angle();

if (vr->m_snapturn_left) {
turn_degrees = -turn_degrees;
vr->m_snapturn_left = false;
}
controller_rot.y += turn_degrees;
controller->set_control_rotation(controller_rot);
}
vr->m_snapturn_on_frame = false;
}
vr->process_snapturn();
}

if (!is_full_pass) {
Expand Down

0 comments on commit 021c6e6

Please sign in to comment.