Skip to content

Commit

Permalink
wip Immersive ladder climbing
Browse files Browse the repository at this point in the history
  • Loading branch information
fholger committed Aug 26, 2023
1 parent 4822c18 commit 0189d4b
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 42 deletions.
3 changes: 2 additions & 1 deletion Sources/CryGame C++/Solution1/CryGame/GameShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ typedef unsigned char ACTIONTYPE;
#define ACTION_MOVEMODE_TOGGLE 63
#define ACTION_AIM_TOGGLE 64
#define ACTION_MOVEMODE_SWITCH 65
#define ACTION_TWOHAND_GRIP 66
#define ACTION_GRIP_LEFT 66
#define ACTION_GRIP_RIGHT 67

#define PLAYER_MAX_WEAPONS 9

Expand Down
23 changes: 17 additions & 6 deletions Sources/CryGame C++/Solution1/CryGame/ScriptObjectPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "ScriptObjectVector.h"
#include <ICryAnimation.h>

#include "VRManager.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -2285,8 +2287,9 @@ int CScriptObjectPlayer::UseLadder(IFunctionHandler *pH)
}
else
{
if(onLadder!=0)
if(onLadder!=0 && !m_pPlayer->m_stats.onLadder)
{
m_pPlayer->m_insideLadderVolume = true;
m_pPlayer->m_PrevWeaponID=m_pPlayer->GetSelectedWeaponId();
m_pPlayer->SelectWeapon(-1);
m_pPlayer->m_stats.onLadder = true;
Expand Down Expand Up @@ -2319,20 +2322,28 @@ int CScriptObjectPlayer::UseLadder(IFunctionHandler *pH)

m_pPlayer->m_vLadderAngles.Set(0,0,0);
}
else
else if (onLadder == 0)
{
// restore speeds only if saved before
if(m_fSpeedRun)
if (m_fSpeedRun)
{
m_pPlayer->SetRunSpeed(m_fSpeedRun);
m_pPlayer->SetWalkSpeed(m_fSpeedWalk);
m_pPlayer->SetCrouchSpeed(m_fSpeedCrouch);
m_pPlayer->SetProneSpeed(m_fSpeedProne);
}

m_pPlayer->m_stats.onLadder = false;
if (m_pPlayer->m_PrevWeaponID>=0)
m_pPlayer->SelectWeapon(m_pPlayer->m_PrevWeaponID);
if (gVR->vr_immersive_ladders && m_pPlayer->m_activeHandGrabbingLadder != -1)
{
// stick to ladder until player lets go
m_pPlayer->m_insideLadderVolume = false;
}
else
{
m_pPlayer->m_stats.onLadder = false;
if (m_pPlayer->m_PrevWeaponID >= 0)
m_pPlayer->SelectWeapon(m_pPlayer->m_PrevWeaponID);
}
}

m_pPlayer->InitCameraTransition( CPlayer::PCM_CASUAL, true );
Expand Down
12 changes: 7 additions & 5 deletions Sources/CryGame C++/Solution1/CryGame/VRInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ bool VRInput::Init(CXGame* game)
vr::VRInput()->GetActionHandle("/actions/default/in/binoculars", &m_defaultBinoculars);
vr::VRInput()->GetActionHandle("/actions/default/in/zoomin", &m_defaultZoomIn);
vr::VRInput()->GetActionHandle("/actions/default/in/zoomout", &m_defaultZoomOut);
vr::VRInput()->GetActionHandle("/actions/default/in/grip", &m_defaultGrip);

vr::VRInput()->GetActionHandle("/actions/move/in/move", &m_moveMove);
vr::VRInput()->GetActionHandle("/actions/move/in/continuousturn", &m_moveTurn);
Expand All @@ -73,7 +74,6 @@ bool VRInput::Init(CXGame* game)
vr::VRInput()->GetActionHandle("/actions/weapons/in/fire", &m_weaponsFire);
InitDoubleBindAction(m_weaponsReloadFireMode, "/actions/weapons/in/reload");
InitDoubleBindAction(m_weaponsNextDrop, "/actions/weapons/in/next");
vr::VRInput()->GetActionHandle("/actions/weapons/in/grip", &m_weaponsGrip);
InitDoubleBindAction(m_weaponsGrenades, "/actions/weapons/in/grenades");

m_pGame = game;
Expand Down Expand Up @@ -176,7 +176,8 @@ void VRInput::ProcessInputOnFoot()
HandleAnalogAction(m_moveMove, 1, &CXClient::TriggerMoveFB);
HandleBooleanAction(m_weaponsFire, &CXClient::TriggerFire0);
HandleDoubleBindAction(m_weaponsReloadFireMode, &CXClient::TriggerReload, &CXClient::TriggerFireMode, false);
HandleBooleanAction(m_weaponsGrip, &CXClient::TriggerTwoHandedGrip);
HandleBooleanAction(m_defaultGrip, &CXClient::TriggerLeftGrip, true, m_handHandle[0]);
HandleBooleanAction(m_defaultGrip, &CXClient::TriggerRightGrip, true, m_handHandle[1]);
}

void VRInput::ProcessInputInVehicles()
Expand Down Expand Up @@ -205,8 +206,9 @@ void VRInput::ProcessInputInVehicles()
HandleBooleanAction(m_weaponsFire, &CXClient::TriggerFire0);
HandleDoubleBindAction(m_weaponsReloadFireMode, &CXClient::TriggerReload, &CXClient::TriggerFireMode, false);
HandleDoubleBindAction(m_weaponsNextDrop, &CXClient::TriggerNextWeapon, &CXClient::TriggerDropWeapon, false);
HandleBooleanAction(m_weaponsGrip, &CXClient::TriggerTwoHandedGrip);
HandleDoubleBindAction(m_weaponsGrenades, &CXClient::CycleGrenade, &CXClient::TriggerFireGrenade, false);
HandleBooleanAction(m_defaultGrip, &CXClient::TriggerLeftGrip, true, m_handHandle[0]);
HandleBooleanAction(m_defaultGrip, &CXClient::TriggerRightGrip, true, m_handHandle[1]);
}

HandleBooleanAction(m_vehiclesLeave, &CXClient::TriggerUse, false);
Expand Down Expand Up @@ -248,10 +250,10 @@ Matrix34 VRInput::GetControllerTransform(int hand)
return OpenVRToFarCry(data.pose.mDeviceToAbsoluteTracking) * correction;
}

void VRInput::HandleBooleanAction(vr::VRActionHandle_t actionHandle, TriggerFn trigger, bool continuous)
void VRInput::HandleBooleanAction(vr::VRActionHandle_t actionHandle, TriggerFn trigger, bool continuous, vr::VRInputValueHandle_t restrictToDevice)
{
vr::InputDigitalActionData_t actionData;
vr::VRInput()->GetDigitalActionData(actionHandle, &actionData, sizeof(vr::InputDigitalActionData_t), vr::k_ulInvalidInputValueHandle);
vr::VRInput()->GetDigitalActionData(actionHandle, &actionData, sizeof(vr::InputDigitalActionData_t), restrictToDevice);
if (actionData.bActive && actionData.bState && (continuous || actionData.bChanged))
{
(m_pGame->GetClient()->*trigger)(1.f, XActivationEvent());
Expand Down
4 changes: 2 additions & 2 deletions Sources/CryGame C++/Solution1/CryGame/VRInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class VRInput
vr::VRActionHandle_t m_defaultBinoculars = vr::k_ulInvalidActionHandle;
vr::VRActionHandle_t m_defaultZoomIn = vr::k_ulInvalidActionHandle;
vr::VRActionHandle_t m_defaultZoomOut = vr::k_ulInvalidActionHandle;
vr::VRActionHandle_t m_defaultGrip = vr::k_ulInvalidActionHandle;

vr::VRActionHandle_t m_moveMove = vr::k_ulInvalidActionHandle;
vr::VRActionHandle_t m_moveTurn = vr::k_ulInvalidActionHandle;
Expand All @@ -61,12 +62,11 @@ class VRInput
vr::VRActionHandle_t m_weaponsFire = vr::k_ulInvalidActionHandle;
DoubleBindAction m_weaponsReloadFireMode;
DoubleBindAction m_weaponsNextDrop;
vr::VRActionHandle_t m_weaponsGrip = vr::k_ulInvalidActionHandle;
DoubleBindAction m_weaponsGrenades;

using TriggerFn = void (CXClient::*)(float value, XActivationEvent ae);

void HandleBooleanAction(vr::VRActionHandle_t actionHandle, TriggerFn trigger, bool continuous = true);
void HandleBooleanAction(vr::VRActionHandle_t actionHandle, TriggerFn trigger, bool continuous = true, vr::VRInputValueHandle_t restrictToDevice = vr::k_ulInvalidInputValueHandle);
void HandleAnalogAction(vr::VRActionHandle_t actionHandle, int axis, TriggerFn trigger);
float GetFloatValue(vr::VRActionHandle_t actionHandle, int axis = 0, bool *isActive = nullptr);

Expand Down
1 change: 1 addition & 0 deletions Sources/CryGame C++/Solution1/CryGame/VRManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ void VRManager::RegisterCVars()
console->Register("vr_crosshair", &vr_crosshair, 1, VF_DUMPTODISK, "VR crosshair type. 0 - none, 1 - ball, 2 - laser");
console->Register("vr_movement_dir", &vr_movement_dir, -1, VF_DUMPTODISK, "Movement direction reference: -1 = head, 0 = left hand, 1 = right hand");
console->Register("vr_show_empty_hands", &vr_show_empty_hands, 1, VF_DUMPTODISK, "If enabled, draws empty player hands when appropriate");
console->Register("vr_immersive_ladders", &vr_immersive_ladders, 1, VF_DUMPTODISK, "Climb ladders by grabbing with your hands");
vr_debug_override_rh_offset = console->CreateVariable("vr_debug_override_rh_offset", "0.0 -0.1 -0.018", VF_CHEAT);
vr_debug_override_lh_offset = console->CreateVariable("vr_debug_override_lh_offset", "0.0 -0.1 -0.018", VF_CHEAT);
vr_debug_override_rh_angles = console->CreateVariable("vr_debug_override_rh_angles", "0.0 0.0 0.0", VF_CHEAT);
Expand Down
1 change: 1 addition & 0 deletions Sources/CryGame C++/Solution1/CryGame/VRManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class VRManager
int vr_crosshair;
int vr_movement_dir;
int vr_show_empty_hands;
int vr_immersive_ladders;
ICVar* vr_debug_override_rh_offset = nullptr;
ICVar* vr_debug_override_rh_angles = nullptr;
ICVar* vr_debug_override_lh_offset = nullptr;
Expand Down
9 changes: 7 additions & 2 deletions Sources/CryGame C++/Solution1/CryGame/XClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1975,9 +1975,14 @@ void CXClient::CycleGrenade(float fValue,XActivationEvent ae)
m_PlayerProcessingCmd.AddAction( ACTION_CYCLE_GRENADE );
}

void CXClient::TriggerTwoHandedGrip(float fValue, XActivationEvent ae)
void CXClient::TriggerLeftGrip(float fValue, XActivationEvent ae)
{
m_PlayerProcessingCmd.AddAction(ACTION_TWOHAND_GRIP);
m_PlayerProcessingCmd.AddAction(ACTION_GRIP_LEFT);
}

void CXClient::TriggerRightGrip(float fValue, XActivationEvent ae)
{
m_PlayerProcessingCmd.AddAction(ACTION_GRIP_RIGHT);
}

void CXClient::TriggerScoreBoard(float fValue, XActivationEvent ae)
Expand Down
3 changes: 2 additions & 1 deletion Sources/CryGame C++/Solution1/CryGame/XClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ public IEntitySystemSink
void TriggerWeapon14(float fValue,XActivationEvent ae);
void TriggerDropWeapon(float fValue,XActivationEvent ae);
void CycleGrenade(float fValue,XActivationEvent ae);
void TriggerTwoHandedGrip(float fValue, XActivationEvent ae);
void TriggerLeftGrip(float fValue, XActivationEvent ae);
void TriggerRightGrip(float fValue, XActivationEvent ae);
void TriggerScoreBoard(float fValue, XActivationEvent ae);

//client side
Expand Down
48 changes: 46 additions & 2 deletions Sources/CryGame C++/Solution1/CryGame/XPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,46 @@ void CPlayer::ProcessMovements(CXEntityProcessingCmd &cmd, bool bScheduled)
else
m_stats.back_pressed = false;

if (m_stats.onLadder && gVR->vr_immersive_ladders)
{
speedxyz[2] = 0;

bool grabbing[2] = { cmd.CheckAction(ACTION_GRIP_LEFT), cmd.CheckAction(ACTION_GRIP_RIGHT) };
bool newActive[2] = { grabbing[0] && !m_wasGrabbingLadder[0], grabbing[1] && !m_wasGrabbingLadder[1] };
for (int i = 0; i < 2; ++i)
{
if (newActive[i])
{
m_activeHandGrabbingLadder = i;
m_prevLadderGrabPos = GetWorldControllerTransform(i).GetTranslation();
}
if (m_activeHandGrabbingLadder == i)
{
Vec3 curGrabPos = GetWorldControllerTransform(i).GetTranslation();
Vec3 diff = curGrabPos - m_prevLadderGrabPos;
speedxyz[2] = -diff.z / m_pGame->GetSystem()->GetITimer()->GetFrameTime() * 5;
if (speedxyz[2] > 0)
{
// add a bit of forward movement for dismounts at the top
speedxyz[0] = -m_psin * 0.50f;
speedxyz[1] = m_pcos * 0.50f;
}
m_prevLadderGrabPos = curGrabPos;
}
m_wasGrabbingLadder[i] = grabbing[i];
}
if (!grabbing[0] && !grabbing[1])
m_activeHandGrabbingLadder = -1;

if (m_activeHandGrabbingLadder == -1 && !m_insideLadderVolume)
{
// no longer inside ladder volume and not grabbing, so let go
m_stats.onLadder = false;
if (m_PrevWeaponID >= 0)
SelectWeapon(m_PrevWeaponID);
}
}

bool bStrafe = false;
if (cmd.CheckAction(ACTION_MOVE_LEFT)) //&& !m_stats.onLadder)
{
Expand Down Expand Up @@ -2040,6 +2080,9 @@ void CPlayer::ProcessMovements(CXEntityProcessingCmd &cmd, bool bScheduled)
else
inputspeed *= fSpeedScale;

if (m_stats.onLadder && gVR->vr_immersive_ladders && m_activeHandGrabbingLadder != -1)
inputspeed = speedxyz.Length();

speedxyz.Normalize();
speedxyz*=inputspeed;
}
Expand Down Expand Up @@ -2250,7 +2293,8 @@ void CPlayer::ProcessWeapons(CXEntityProcessingCmd &cmd)
// do not allow to use weapons and move when underwater or in a water volume, and
// he is actively swimming

bool twoHandGrip = cmd.CheckAction(ACTION_TWOHAND_GRIP);
unsigned offhandGrip = m_offHand == 0 ? ACTION_GRIP_LEFT : ACTION_GRIP_RIGHT;
bool twoHandGrip = cmd.CheckAction(offhandGrip);
if (m_wasTwoHandGrip != twoHandGrip && twoHandGrip)
{
TryEnableTwoHandedWeaponMode();
Expand Down Expand Up @@ -2448,7 +2492,7 @@ void CPlayer::ProcessRoomscaleMovement(CXEntityProcessingCmd& ProcessingCmd)
if (!ProcessingCmd.UseMotionControls())
return;

if (GetVehicle() || m_pMountedWeapon)
if (GetVehicle() || m_pMountedWeapon || (m_stats.onLadder && gVR->vr_immersive_ladders))
return;

Ang3 angles = m_pEntity->GetAngles();
Expand Down
6 changes: 6 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/XPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,12 @@ enum eInVehiclestate

// visible bare hands
CHand* m_handModel[2] = { nullptr };

public:
bool m_wasGrabbingLadder[2] = { false, false };
int m_activeHandGrabbingLadder = -1;
Vec3 m_prevLadderGrabPos;
bool m_insideLadderVolume = false;
};

#endif // __GAME_PLAYER_H__
8 changes: 4 additions & 4 deletions steamvr/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
"name" : "/actions/default/in/ZoomOut",
"type" : "boolean"
},
{
"name": "/actions/default/in/Grip",
"type": "boolean"
},
{
"name" : "/actions/move/in/Move",
"type" : "vector2"
Expand Down Expand Up @@ -135,10 +139,6 @@
"name": "/actions/weapons/in/Next",
"type": "boolean"
},
{
"name": "/actions/weapons/in/Grip",
"type": "boolean"
},
{
"name": "/actions/weapons/in/Grenades",
"type": "boolean"
Expand Down
2 changes: 1 addition & 1 deletion steamvr/actions_en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"/actions/default/in/Binoculars": "Activate binoculars",
"/actions/default/in/ZoomIn": "Zoom in",
"/actions/default/in/ZoomOut": "Zoom out",
"/actions/default/in/Grip": "Grab",
"/actions/move": "Movement",
"/actions/move/in/Move": "Move",
"/actions/move/in/ContinuousTurn": "Smooth turn",
Expand All @@ -21,7 +22,6 @@
"/actions/weapons/in/Fire": "Fire weapon",
"/actions/weapons/in/Reload": "Reload weapon",
"/actions/weapons/in/Next": "Next weapon / drop weapon",
"/actions/weapons/in/Grip": "Activate two-hand mode",
"/actions/weapons/in/Grenades": "Cycle / throw grenades",
"/actions/vehicles": "Vehicles",
"/actions/vehicles/in/Steer": "Steer vehicle",
Expand Down
27 changes: 18 additions & 9 deletions steamvr/bindings_knuckles.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@
}
}
},
{
"path": "/user/hand/left/input/grip",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/default/in/grip"
}
}
},
{
"path": "/user/hand/right/input/grip",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/default/in/grip"
}
}
},
{
"inputs" : {
"north" : {
Expand Down Expand Up @@ -269,15 +287,6 @@
}
}
},
{
"path": "/user/hand/left/input/grip",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/weapons/in/grip"
}
}
},
{
"path": "/user/hand/right/input/b",
"mode": "button",
Expand Down
27 changes: 18 additions & 9 deletions steamvr/bindings_touch.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@
}
}
},
{
"path": "/user/hand/left/input/grip",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/default/in/grip"
}
}
},
{
"path": "/user/hand/right/input/grip",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/default/in/grip"
}
}
},
{
"inputs" : {
"north" : {
Expand Down Expand Up @@ -269,15 +287,6 @@
}
}
},
{
"path": "/user/hand/left/input/grip",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/weapons/in/grip"
}
}
},
{
"path": "/user/hand/right/input/b",
"mode": "button",
Expand Down

0 comments on commit 0189d4b

Please sign in to comment.