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

Avoid rendering the entire scene twice each frame #909

Merged
merged 1 commit into from
Dec 23, 2024
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
11 changes: 10 additions & 1 deletion Assets/Scripts/Control&Input/OrbitCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,16 @@ private void StartTracking(PlayerManager nextTarget)
{
if (!cameraTransform || !input || MatchController.Singleton.IsShowingScoreboards)
return;
isTracking = true;

camera.enabled = true;
// Improves perf loss when playing splitscreen
var allPlayerCamerasAreDisabled = MatchController.Singleton.Players
.Where(p => p.inputManager != null)
.All(p => p.inputManager.PlayerCamera.enabled);
if (allPlayerCamerasAreDisabled)
MatchController.Singleton.ArenaCamera.enabled = false;

isTracking = true;
target = nextTarget.AiAimSpot;
if (nextTarget != player)
player.HUDController.DisplaySpectatorScreen(nextTarget.identity);
Expand All @@ -106,6 +114,7 @@ private void StopTracking()
{
if (!camera)
return;
MatchController.Singleton.ArenaCamera.enabled = true;
isTracking = false;
camera.enabled = false;
ResetCamera();
Expand Down
13 changes: 12 additions & 1 deletion Assets/Scripts/Gamestate/MatchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class MatchController : NetworkBehaviour
private bool isShowingScoreboards = false;
public bool IsShowingScoreboards => isShowingScoreboards;

private Camera arenaCamera;
public Camera ArenaCamera => arenaCamera;


private void Awake()
{
Expand Down Expand Up @@ -105,6 +108,8 @@ private void Start()

currentMapName ??= SceneManager.GetActiveScene().name;

arenaCamera = FindObjectsOfType<Camera>().FirstOrDefault(x => x.CompareTag("MainCamera"));

var mainLight = GameObject.FindGameObjectsWithTag("MainLight")[0];
RenderSettings.skybox.SetVector("_SunDirection", mainLight.transform.forward);
RenderSettings.skybox.SetFloat("_MaxGradientTreshold", 0.25f);
Expand Down Expand Up @@ -231,6 +236,12 @@ private IEnumerator WaitAndShowResults()
{
// Delay first so we can see who killed who
yield return new WaitForSeconds(delayBeforeRoundResults);

// Ensure arena camera is the only one that is enabled now!
foreach (var p in players.Where(p => p.inputManager != null))
p.inputManager.PlayerCamera.enabled = false;
arenaCamera.enabled = true;

isShowingScoreboards = true;
// Scoreboard subscribes here
onRoundEnd?.Invoke();
Expand Down Expand Up @@ -313,7 +324,7 @@ private void DisplayWinScreen()
foreach (var loser in loserModels.Zip(loserColors, (model, color) => (model, color)))
loser.model.GetComponentInChildren<SkinnedMeshRenderer>().material.color = loser.color;

Camera.main.GetComponent<ArenaCamera>().PlayVictoryAnimation(winner);
arenaCamera.GetComponent<ArenaCamera>().PlayVictoryAnimation(winner);
}

public void WaitAndRestartAfterWinScreen()
Expand Down
4 changes: 4 additions & 0 deletions Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ public void SetPlayerInput(InputManager playerInput)
canvas.worldCamera = inputManager.GetComponentInChildren<Camera>();
canvas.planeDistance = 0.21f;
identity.onChipChange += hudController.OnChipChange;

// Disable arena camera so we don't render the entire scene twice
if (Camera.main)
Camera.main.enabled = false;
}

if (playerIK.TryGetComponent<BiddingPlayer>(out var biddingPlayer))
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/Scoreboard/ScoreboardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public void SetupPosters()
public IEnumerator ShowMatchResults()
{
// Animate the after battle scene
Camera.main.GetComponent<ArenaCamera>().PlayScoreboardAnimation();
var arenaCamera = MatchController.Singleton.ArenaCamera;
arenaCamera.GetComponent<ArenaCamera>().PlayScoreboardAnimation();

for (int i = 0; i < scoreboards.Count; i++)
{
Expand All @@ -113,7 +114,7 @@ public IEnumerator ShowMatchResults()
}

// Do not start adding crimes before the camera has finished the animation
int delay = Mathf.RoundToInt(Camera.main.GetComponent<Animator>().runtimeAnimatorController.animationClips[0].length);
int delay = Mathf.RoundToInt(arenaCamera.GetComponent<Animator>().runtimeAnimatorController.animationClips[0].length);
yield return new WaitForSeconds(delay);

maxSteps = MaxNumberOfCrimes();
Expand Down