Skip to content

Commit

Permalink
Change free cam culling
Browse files Browse the repository at this point in the history
- Now only toggles with a key press
  • Loading branch information
Lacyway committed Jun 20, 2024
1 parent 1043600 commit 0768635
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
18 changes: 16 additions & 2 deletions Fika.Core/Coop/FreeCamera/FreeCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class FreeCamera : MonoBehaviour
private bool showOverlay;
private NightVision nightVision;
private ThermalVision thermalVision;
private FreeCameraController freeCameraController;

private KeyCode forwardKey = KeyCode.W;
private KeyCode backKey = KeyCode.S;
Expand Down Expand Up @@ -57,6 +58,8 @@ protected void Start()

nightVision = CameraClass.Instance.NightVision;
thermalVision = CameraClass.Instance.ThermalVision;

freeCameraController = Singleton<GameWorld>.Instance.gameObject.GetComponent<FreeCameraController>();
}

private void KeybindOverlay_SettingChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -88,6 +91,7 @@ protected void OnGUI()
GUILayout.Label($"Spacebar + Left/Right Mouse Button: Jump and spectate in head cam");
GUILayout.Label($"T: Teleport to cam position");
GUILayout.Label($"N: {visionText}");
GUILayout.Label($"M: Disable culling");
GUILayout.Label($"HOME: {(disableInput ? "Enable Input" : "Disable Input")}");
GUILayout.Label($"Shift + Ctrl: Turbo Speed");

Expand All @@ -103,11 +107,11 @@ protected void Update()
return;
}

// Toggle input
if (Input.GetKeyDown(KeyCode.Home))
{
disableInput = !disableInput;
string status = disableInput == true ? "disabled" : "enabled";
NotificationManagerClass.DisplayMessageNotification($"Free cam input is now {status}.");
NotificationManagerClass.DisplayMessageNotification($"Free cam input is now {(disableInput ? "disabled" : "enabled")}.");
}

if (disableInput)
Expand Down Expand Up @@ -289,11 +293,21 @@ protected void Update()
}
}

// Toggle vision
if (Input.GetKeyDown(KeyCode.N))
{
ToggleVision();
}

// Disable culling
if (Input.GetKeyDown(KeyCode.M))
{
if (freeCameraController != null)
{
freeCameraController.DisableAllCullingObjects();
}
}

if (isFollowing)
{
if (CurrentPlayer != null)
Expand Down
48 changes: 34 additions & 14 deletions Fika.Core/Coop/FreeCamera/FreeCameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class FreeCameraController : MonoBehaviour
private bool deathFadeEnabled;
private DisablerCullingObjectBase[] allCullingObjects;
private List<PerfectCullingBakeGroup> previouslyActiveBakeGroups;
private bool hasEnabledCulling = false;

protected void Awake()
{
Expand Down Expand Up @@ -368,7 +369,29 @@ private void SetPlayerToFreecamMode(Player localPlayer)

_gamePlayerOwner.enabled = false;
_freeCamScript.SetActive(true);
}

/// <summary>
/// A helper method to reset the player view back to First Person
/// </summary>
/// <param name="localPlayer"></param>
private void SetPlayerToFirstPersonMode(Player localPlayer)
{
// re-enable _gamePlayerOwner
_gamePlayerOwner.enabled = true;
_freeCamScript.SetActive(false);

localPlayer.PointOfView = EPointOfView.FirstPerson;
CameraClass.Instance.SetOcclusionCullingEnabled(true);

if (hasEnabledCulling)
{
EnableAllCullingObjects();
}
}

public void DisableAllCullingObjects()
{
int count = 0;
foreach (DisablerCullingObjectBase cullingObject in allCullingObjects)
{
Expand All @@ -379,7 +402,9 @@ private void SetPlayerToFreecamMode(Player localPlayer)
count++;
cullingObject.SetComponentsEnabled(true);
}
FikaPlugin.Instance.FikaLogger.LogDebug($"Enabled {count} Culling Triggers.");
#if DEBUG
FikaPlugin.Instance.FikaLogger.LogWarning($"Enabled {count} Culling Triggers.");
#endif

PerfectCullingAdaptiveGrid perfectCullingAdaptiveGrid = FindObjectOfType<PerfectCullingAdaptiveGrid>();
if (perfectCullingAdaptiveGrid != null)
Expand All @@ -404,21 +429,12 @@ private void SetPlayerToFreecamMode(Player localPlayer)
}
}
}

hasEnabledCulling = true;
}

/// <summary>
/// A helper method to reset the player view back to First Person
/// </summary>
/// <param name="localPlayer"></param>
private void SetPlayerToFirstPersonMode(Player localPlayer)
public void EnableAllCullingObjects()
{
// re-enable _gamePlayerOwner
_gamePlayerOwner.enabled = true;
_freeCamScript.SetActive(false);

localPlayer.PointOfView = EPointOfView.FirstPerson;
CameraClass.Instance.SetOcclusionCullingEnabled(true);

int count = 0;
foreach (DisablerCullingObjectBase cullingObject in allCullingObjects)
{
Expand All @@ -429,7 +445,9 @@ private void SetPlayerToFirstPersonMode(Player localPlayer)
count++;
cullingObject.SetComponentsEnabled(false);
}
FikaPlugin.Instance.FikaLogger.LogDebug($"Disabled {count} Culling Triggers.");
#if DEBUG
FikaPlugin.Instance.FikaLogger.LogWarning($"Disabled {count} Culling Triggers.");
#endif

PerfectCullingAdaptiveGrid perfectCullingAdaptiveGrid = FindObjectOfType<PerfectCullingAdaptiveGrid>();
if (perfectCullingAdaptiveGrid != null)
Expand All @@ -456,6 +474,8 @@ private void SetPlayerToFirstPersonMode(Player localPlayer)
}
}
}

hasEnabledCulling = false;
}

/// <summary>
Expand Down

0 comments on commit 0768635

Please sign in to comment.