Skip to content

Commit

Permalink
GE: sway/centering tweaks, feels much better now
Browse files Browse the repository at this point in the history
Delayed centering a tiny bit, forced aim-mode to finish centering before allowing more sway, made sway-centering slower than aim-mode centering...
  • Loading branch information
emoose committed Feb 15, 2021
1 parent 2a5f1d7 commit 07231f8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 33 deletions.
86 changes: 53 additions & 33 deletions src/xenia/hid/winkey/hookables/goldeneye.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DEFINE_double(aim_turn_distance, 0.4f,
DEFINE_double(ge_menu_sensitivity, 0.5f,
"(GoldenEye) Mouse sensitivity when in menus", "MouseHook");

DEFINE_bool(ge_gun_sway, true, "(GoldenEye) Sway gun as camera is turned",
DEFINE_bool(ge_gun_sway, true, "(GoldenEye) Enable gun sway as camera is turned",
"MouseHook");

const uint32_t kTitleIdGoldenEye = 0x584108A9;
Expand Down Expand Up @@ -62,6 +62,8 @@ bool GoldeneyeGame::DoHooks(uint32_t user_index, RawInputState& input_state,
return false;
}

auto time = xe::kernel::XClock::now();

// Move menu selection crosshair
// TODO: detect if we're actually in the menu first
auto menuX_ptr =
Expand Down Expand Up @@ -226,34 +228,49 @@ bool GoldeneyeGame::DoHooks(uint32_t user_index, RawInputState& input_state,
camY -= (chY * aim_multiplier);
*player_cam_y = camY;
}

time_start_center_ = time + std::chrono::milliseconds(50);
start_centering_ = true;
force_centering_ = true; // skip weapon sway until we've centered
centering_speed_ = 0.05f; // speed up centering from aim-mode
} else {
// Start centering gun if we aren't currently moving it
if (!input_state.mouse.x_delta && !input_state.mouse.y_delta) {
if (gX != 0 || gY != 0) {
if (gX > 0) {
gX -= std::min(0.05f, gX);
}
if (gX < 0) {
gX += std::min(0.05f, -gX);
}
if (gY > 0) {
gY -= std::min(0.05f, gY);
if ((!input_state.mouse.x_delta && !input_state.mouse.y_delta) ||
force_centering_) {
if (start_centering_ && time >= time_start_center_) {
if (gX != 0 || gY != 0) {
if (gX > 0) {
gX -= std::min(centering_speed_, gX);
}
if (gX < 0) {
gX += std::min(centering_speed_, -gX);
}
if (gY > 0) {
gY -= std::min(centering_speed_, gY);
}
if (gY < 0) {
gY += std::min(centering_speed_, -gY);
}
}
if (gY < 0) {
gY += std::min(0.05f, -gY);
if (gX == 0 && gY == 0) {
start_centering_ = false;
centering_speed_ = 0.0125f;
force_centering_ = false;
}
}
} else {
float camX = (float)*player_cam_x;
float camY = (float)*player_cam_y;
}

if (input_state.mouse.x_delta || input_state.mouse.y_delta) {
float camX = *player_cam_x;
float camY = *player_cam_y;

camX += (((float)input_state.mouse.x_delta) / 10.f) *
(float)cvars::sensitivity;

// Add 'sway' to gun if we're moving
float gun_sway_x = (((float)input_state.mouse.x_delta) / 2000.f) *
float gun_sway_x = (((float)input_state.mouse.x_delta) / 4000.f) *
(float)cvars::sensitivity;
float gun_sway_y = (((float)input_state.mouse.y_delta) / 2000.f) *
float gun_sway_y = (((float)input_state.mouse.y_delta) / 4000.f) *
(float)cvars::sensitivity;

float gun_sway_x_changed = gX + gun_sway_x;
Expand All @@ -271,24 +288,27 @@ bool GoldeneyeGame::DoHooks(uint32_t user_index, RawInputState& input_state,
*player_cam_x = camX;
*player_cam_y = camY;

// Bound the 'sway' movement to [0.5:-0.5] to make it look a bit better
// (but only if the sway would make it go further OOB)
if (gun_sway_x_changed > 0.5f && gun_sway_x > 0) {
gun_sway_x_changed = gX;
}
if (gun_sway_x_changed < -0.5f && gun_sway_x < 0) {
gun_sway_x_changed = gX;
}
if (gun_sway_y_changed > 0.5f && gun_sway_y > 0) {
gun_sway_y_changed = gY;
}
if (gun_sway_y_changed < -0.5f && gun_sway_y < 0) {
gun_sway_y_changed = gY;
}
if (cvars::ge_gun_sway && !force_centering_) {
// Bound the 'sway' movement to [0.2:-0.2] to make it look a bit
// better (but only if the sway would make it go further OOB)
if (gun_sway_x_changed > 0.2f && gun_sway_x > 0) {
gun_sway_x_changed = gX;
}
if (gun_sway_x_changed < -0.2f && gun_sway_x < 0) {
gun_sway_x_changed = gX;
}
if (gun_sway_y_changed > 0.2f && gun_sway_y > 0) {
gun_sway_y_changed = gY;
}
if (gun_sway_y_changed < -0.2f && gun_sway_y < 0) {
gun_sway_y_changed = gY;
}

if (cvars::ge_gun_sway) {
gX = gun_sway_x_changed;
gY = gun_sway_y_changed;

time_start_center_ = time + std::chrono::milliseconds(50);
start_centering_ = true;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/xenia/hid/winkey/hookables/goldeneye.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define XENIA_HID_WINKEY_GOLDENEYE_H_

#include "xenia/hid/winkey/hookables/hookable_game.h"
#include "xenia/kernel/xclock.h"

namespace xe {
namespace hid {
Expand All @@ -28,6 +29,11 @@ class GoldeneyeGame : public HookableGame {
uint32_t prev_aim_mode_ = 0;
uint32_t prev_game_pause_flag_ = -1;
uint32_t prev_game_control_active_ = -1;

float centering_speed_ = 0.0125f;
xe::kernel::XClock::time_point time_start_center_;
bool start_centering_ = false;
bool force_centering_ = false; // prevents sway being applied
};

} // namespace winkey
Expand Down

0 comments on commit 07231f8

Please sign in to comment.