Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply deadzones to vector inputs #476

Merged
merged 2 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NomaiVR/Assets/AssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private T LoadModAssetFromJson<T>(string modAssetPath)
return JsonConvert.DeserializeObject<T>(File.ReadAllText(fullPath));
}

private T LoadAsset<T>(AssetBundle bundle, string prefabName) where T : UnityEngine.Object
private T LoadAsset<T>(AssetBundle bundle, string prefabName) where T : Object
{
return bundle.LoadAsset<T>($"assets/{prefabName}");
}
Expand Down
4 changes: 2 additions & 2 deletions NomaiVR/Assets/ShaderLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private Shader GetCachedShader(string shaderName)
return shaderCache[shaderName];
}

public static Shader GetShader(string shaderName) => ShaderLoader.Instance.GetCachedShader(shaderName);
public static void LoadBundle(AssetBundle bundle) => ShaderLoader.Instance.LoadAllFromBundle(bundle);
public static Shader GetShader(string shaderName) => Instance.GetCachedShader(shaderName);
public static void LoadBundle(AssetBundle bundle) => Instance.LoadAllFromBundle(bundle);
}
}
12 changes: 6 additions & 6 deletions NomaiVR/EffectFixes/FogFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public class Patch : NomaiVRPatch
{
public override void ApplyPatches()
{
Prefix<PlanetaryFogController>(nameof(PlanetaryFogController.ResetFogSettings), nameof(Patch.PatchResetFog));
Prefix<PlanetaryFogController>(nameof(PlanetaryFogController.UpdateFogSettings), nameof(Patch.PatchUpdateFog));
Prefix<FogOverrideVolume>(nameof(FogOverrideVolume.OverrideFogSettings), nameof(Patch.PatchOverrideFog));
Prefix<PlanetaryFogImageEffect>(nameof(PlanetaryFogImageEffect.OnRenderImage), nameof(Patch.PreFogImageEffectRenderImage));
Prefix<PlanetaryFogRenderer>(nameof(PlanetaryFogRenderer.CalcFrustumCorners), nameof(Patch.PreCalcFrustumCorners));
Prefix<HeightmapAmbientLightRenderer>(nameof(HeightmapAmbientLightRenderer.CalcFrustumCorners), nameof(Patch.Prefix_HeightmapAmbientLightRenderer_CalcFrustumCorners));
Prefix<PlanetaryFogController>(nameof(PlanetaryFogController.ResetFogSettings), nameof(PatchResetFog));
Prefix<PlanetaryFogController>(nameof(PlanetaryFogController.UpdateFogSettings), nameof(PatchUpdateFog));
Prefix<FogOverrideVolume>(nameof(FogOverrideVolume.OverrideFogSettings), nameof(PatchOverrideFog));
Prefix<PlanetaryFogImageEffect>(nameof(PlanetaryFogImageEffect.OnRenderImage), nameof(PreFogImageEffectRenderImage));
Prefix<PlanetaryFogRenderer>(nameof(PlanetaryFogRenderer.CalcFrustumCorners), nameof(PreCalcFrustumCorners));
Prefix<HeightmapAmbientLightRenderer>(nameof(HeightmapAmbientLightRenderer.CalcFrustumCorners), nameof(Prefix_HeightmapAmbientLightRenderer_CalcFrustumCorners));
}

private static readonly Vector3[] frustumCornersBuffer = new Vector3[4];
Expand Down
2 changes: 1 addition & 1 deletion NomaiVR/EffectFixes/LoopTransitionFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ref float ____reverseScreenStartDist
____origScreenScale *= 0.5f;
var scale = ____origScreenScale;

var uplinkTrigger = GameObject.FindObjectOfType<MemoryUplinkTrigger>();
var uplinkTrigger = Object.FindObjectOfType<MemoryUplinkTrigger>();
var statue = uplinkTrigger._lockOnTransform;
var eye = statue.Find("Props_NOM_StatueHead/eyelid_mid");
focus = new GameObject().transform;
Expand Down
2 changes: 1 addition & 1 deletion NomaiVR/EffectFixes/ProjectionStoneCameraFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Patch : NomaiVRPatch
{
public override void ApplyPatches()
{
Postfix<NomaiRemoteCameraPlatform>("SwitchToRemoteCamera", nameof(Patch.SwitchToRemoteCamera));
Postfix<NomaiRemoteCameraPlatform>("SwitchToRemoteCamera", nameof(SwitchToRemoteCamera));
}

private static void SwitchToRemoteCamera(NomaiRemoteCameraPlatform ____slavePlatform, Transform ____playerHologram)
Expand Down
34 changes: 17 additions & 17 deletions NomaiVR/EffectFixes/ShadowsFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ public class Patch : NomaiVRPatch
public override void ApplyPatches()
{
//Solve (1x)PreCull->(2x)PostRender conflicts
Prefix<CSMTextureCacher>(nameof(CSMTextureCacher.OnAnyCameraPostRender), nameof(Patch.PreOnAnyCameraPostRender));
Prefix<RingworldShadowsOverride>(nameof(RingworldShadowsOverride.OnCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<CloudEffectBubbleController>(nameof(CloudEffectBubbleController.OnTargetCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<FogWarpEffectBubbleController>(nameof(FogWarpEffectBubbleController.OnTargetCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<QuantumFogEffectBubbleController>(nameof(QuantumFogEffectBubbleController.OnTargetCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<SandEffectBubbleController>(nameof(SandEffectBubbleController.OnTargetCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<UnderwaterEffectBubbleController>(nameof(UnderwaterEffectBubbleController.OnTargetCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<PerCameraRendererState>(nameof(PerCameraRendererState.OnOWCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<GeyserWaterVillageHack>(nameof(GeyserWaterVillageHack.OnPlayerCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<LightLOD>(nameof(LightLOD.RevertLODSettings), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<RingworldSunController>(nameof(RingworldSunController.OnOWCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<IPExteriorVisualsManager>(nameof(IPExteriorVisualsManager.OnOWCameraPostRender), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<TessellatedSphereRenderer>(nameof(TessellatedSphereRenderer.Clear), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<TessellatedPlaneRenderer>(nameof(TessellatedPlaneRenderer.Clear), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<TessellatedRingRenderer>(nameof(TessellatedRingRenderer.Clear), nameof(Patch.OwCameraPostRenderDisabler));
Prefix<UnderwaterCurrentFadeController>(nameof(UnderwaterCurrentFadeController.OnAnyPrerender), nameof(Patch.Pre_UnderwaterCurrentFadeController_OnAnyPrerender));
Prefix<UnderwaterCurrentFadeController>(nameof(UnderwaterCurrentFadeController.OnAnyPostrender), nameof(Patch.Pre_UnderwaterCurrentFadeController_OnAnyPostRender));
Prefix<CSMTextureCacher>(nameof(CSMTextureCacher.OnAnyCameraPostRender), nameof(PreOnAnyCameraPostRender));
Prefix<RingworldShadowsOverride>(nameof(RingworldShadowsOverride.OnCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<CloudEffectBubbleController>(nameof(CloudEffectBubbleController.OnTargetCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<FogWarpEffectBubbleController>(nameof(FogWarpEffectBubbleController.OnTargetCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<QuantumFogEffectBubbleController>(nameof(QuantumFogEffectBubbleController.OnTargetCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<SandEffectBubbleController>(nameof(SandEffectBubbleController.OnTargetCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<UnderwaterEffectBubbleController>(nameof(UnderwaterEffectBubbleController.OnTargetCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<PerCameraRendererState>(nameof(PerCameraRendererState.OnOWCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<GeyserWaterVillageHack>(nameof(GeyserWaterVillageHack.OnPlayerCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<LightLOD>(nameof(LightLOD.RevertLODSettings), nameof(OwCameraPostRenderDisabler));
Prefix<RingworldSunController>(nameof(RingworldSunController.OnOWCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<IPExteriorVisualsManager>(nameof(IPExteriorVisualsManager.OnOWCameraPostRender), nameof(OwCameraPostRenderDisabler));
Prefix<TessellatedSphereRenderer>(nameof(TessellatedSphereRenderer.Clear), nameof(OwCameraPostRenderDisabler));
Prefix<TessellatedPlaneRenderer>(nameof(TessellatedPlaneRenderer.Clear), nameof(OwCameraPostRenderDisabler));
Prefix<TessellatedRingRenderer>(nameof(TessellatedRingRenderer.Clear), nameof(OwCameraPostRenderDisabler));
Prefix<UnderwaterCurrentFadeController>(nameof(UnderwaterCurrentFadeController.OnAnyPrerender), nameof(Pre_UnderwaterCurrentFadeController_OnAnyPrerender));
Prefix<UnderwaterCurrentFadeController>(nameof(UnderwaterCurrentFadeController.OnAnyPostrender), nameof(Pre_UnderwaterCurrentFadeController_OnAnyPostRender));
}

private static bool OwCameraPostRenderDisabler(OWCamera owCamera)
Expand Down
4 changes: 2 additions & 2 deletions NomaiVR/Hands/NomaiVR_Hand_Skeleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public override void SetBoneRotation(int boneIndex, Quaternion localRotation)
public void BlendBonePosition(int boneIndex, Vector3 blendPosition, float ammount)
{
blendPosition = Vector3.Lerp(bones[boneIndex].localPosition, blendPosition, ammount);
this.SetBonePosition(boneIndex, blendPosition);
SetBonePosition(boneIndex, blendPosition);
}

public void BlendBoneRotation(int boneIndex, Quaternion blendRotation, float ammount)
{
blendRotation = Quaternion.Lerp(bones[boneIndex].localRotation, blendRotation, ammount);
this.SetBoneRotation(boneIndex, blendRotation);
SetBoneRotation(boneIndex, blendRotation);
}
}
}
12 changes: 11 additions & 1 deletion NomaiVR/Helpers/InputHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace NomaiVR.Helpers
using UnityEngine;

namespace NomaiVR.Helpers
{
public static class InputHelper
{
Expand Down Expand Up @@ -26,5 +28,13 @@ public static bool IsHandheldTool()
InputMode.ScopeZoom
);
}

public static Vector2 ApplyDeadzones(Vector2 rawInputValue)
{
// These hardcoded values are copied from the Outer Wilds source code.
return OWInputProcessorUtil.ApplyOWDoubleAxisDeadzones(rawInputValue,
0.2f * OWInputProcessorUtil.InnerDeadZoneMultiplier,
0.05f * OWInputProcessorUtil.OuterDeadZoneMultiplier);
}
}
}
2 changes: 1 addition & 1 deletion NomaiVR/Helpers/LayerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static List<GameObject> GetObjectsInLayer(string layerName)
{
var layer = LayerMask.NameToLayer(layerName);
var ret = new List<GameObject>();
var all = GameObject.FindObjectsOfType<GameObject>();
var all = Object.FindObjectsOfType<GameObject>();

foreach (var t in all)
{
Expand Down
8 changes: 4 additions & 4 deletions NomaiVR/Helpers/MenuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public static void AddPauseMenuAction(this PauseMenuManager pauseMenu, string na
{
var pauseItems = pauseMenu._pauseMenu.transform.Find("PauseMenuItemsLayout");
var buttonTemplate = pauseItems.Find("Button-Options").gameObject;
var newPauseMenuButton = GameObject.Instantiate(buttonTemplate);
var newPauseMenuButton = Object.Instantiate(buttonTemplate);
newPauseMenuButton.transform.SetParent(pauseItems);
newPauseMenuButton.transform.SetSiblingIndex(order);

var text = newPauseMenuButton.GetComponentInChildren<Text>(true);
GameObject.Destroy(newPauseMenuButton.GetComponent<Menu>());
GameObject.Destroy(newPauseMenuButton.GetComponent<SubmitActionMenu>());
GameObject.Destroy(text.gameObject.GetComponent<LocalizedText>());
Object.Destroy(newPauseMenuButton.GetComponent<Menu>());
Object.Destroy(newPauseMenuButton.GetComponent<SubmitActionMenu>());
Object.Destroy(text.gameObject.GetComponent<LocalizedText>());
var submitAction = newPauseMenuButton.AddComponent<SubmitAction>();
submitAction.OnSubmitAction += onSubmit;
text.text = name;
Expand Down
2 changes: 1 addition & 1 deletion NomaiVR/Helpers/PlayerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static Transform PlayerHead
get {
if (playerHead == null)
{
playerHead = GameObject.FindObjectOfType<ToolModeUI>().transform;
playerHead = Object.FindObjectOfType<ToolModeUI>().transform;
}
return playerHead;
}
Expand Down
5 changes: 3 additions & 2 deletions NomaiVR/Input/ActionInputs/SingleActionInput.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using UnityEngine;
using NomaiVR.Helpers;
using UnityEngine;
using Valve.VR;

namespace NomaiVR.Input.ActionInputs
{
public class SingleActionInput : ActionInput<SteamVR_Action_Single>
{
public override Vector2 Value => new Vector2(SpecificAction.axis, 0f);
public override Vector2 Value => InputHelper.ApplyDeadzones(new Vector2(SpecificAction.axis, 0f));

public override bool Active => SpecificAction.active;

Expand Down
13 changes: 7 additions & 6 deletions NomaiVR/Input/ActionInputs/Vector2ActionInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using NomaiVR.Helpers;
using UnityEngine;
using Valve.VR;

namespace NomaiVR.Input.ActionInputs
Expand All @@ -10,16 +11,15 @@ public class Vector2ActionInput : ActionInput<SteamVR_Action_Vector2>
private readonly bool yOnly;
private readonly bool yZero;
private readonly bool isEitherHand;
private readonly string textureModifier;

public Vector2ActionInput(SteamVR_Action_Vector2 action, bool optional = false, bool yOnly = false, bool invert = false, bool clamp = false, bool yZero = false, bool eitherHand = false, string textureModifier = null): base(action, optional)
{
this.yOnly = yOnly;
this.invert = invert;
this.clamp = clamp;
this.yZero = yZero;
this.isEitherHand = eitherHand;
this.textureModifier = textureModifier;
isEitherHand = eitherHand;
TextureModifier = textureModifier;
}

public override Vector2 Value
Expand All @@ -29,7 +29,8 @@ public override Vector2 Value
var axis = yOnly ? SpecificAction.axis.y : SpecificAction.axis.x;
var rawValue = invert ? -axis : axis;
var clampedValue = clamp ? Mathf.Clamp(rawValue, 0f, 1f) : rawValue;
return new Vector2(clampedValue, (yOnly || yZero) ? 0f : SpecificAction.axis.y);
var preDeadzoneValue = new Vector2(clampedValue, yOnly || yZero ? 0f : SpecificAction.axis.y);
return InputHelper.ApplyDeadzones(preDeadzoneValue);
}
}

Expand Down Expand Up @@ -57,6 +58,6 @@ public override SteamVR_Input_Sources ActiveSource
}
}

public string TextureModifier => this.textureModifier;
public string TextureModifier { get; }
}
}
2 changes: 1 addition & 1 deletion NomaiVR/Loaders/NomaiVRLoaderOWML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal void Start()
public override void Configure(IModConfig config)
{
Helper = ModHelper;
var settingsProvider = new ModConfig.OwmlSettingsProvider(config);
var settingsProvider = new OwmlSettingsProvider(config);
ModSettings.SetProvider(settingsProvider);
}
}
Expand Down
8 changes: 4 additions & 4 deletions NomaiVR/Player/PlayerBodyPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public class Patch : NomaiVRPatch
{
public override void ApplyPatches()
{
Postfix<PlayerCharacterController>("UpdateTurning", nameof(Patch.PostCharacterTurning));
Postfix<JetpackThrusterController>("FixedUpdate", nameof(Patch.PostThrusterUpdate));
Prefix<OWCamera>("set_fieldOfView", nameof(Patch.PatchOwCameraFOV));
Prefix<OWCamera>("get_fieldOfView", nameof(Patch.GetOwCameraFOVScaled));
Postfix<PlayerCharacterController>("UpdateTurning", nameof(PostCharacterTurning));
Postfix<JetpackThrusterController>("FixedUpdate", nameof(PostThrusterUpdate));
Prefix<OWCamera>("set_fieldOfView", nameof(PatchOwCameraFOV));
Prefix<OWCamera>("get_fieldOfView", nameof(GetOwCameraFOVScaled));
}

private static void PostThrusterUpdate(Vector3 ____rotationalInput)
Expand Down
Loading