From cd76051a84f11453121dfbc849a6714b07436d58 Mon Sep 17 00:00:00 2001 From: Jesus Rodriguez Valencia Date: Wed, 21 Apr 2021 16:47:22 +0200 Subject: [PATCH] Performance improvements: - locking to 25 fps max the cameras rendering and streaming - locking cameras FOV to 50 - Reducing desktop client refresh rate --- .../MainWindow.axaml.cs | 2 +- OfCourseIStillLoveYou/Core.cs | 5 ++--- OfCourseIStillLoveYou/TrackingCamera.cs | 15 +++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OfCourseIStillLoveYou.DesktopClient/MainWindow.axaml.cs b/OfCourseIStillLoveYou.DesktopClient/MainWindow.axaml.cs index bf374c2..cbf5e3c 100644 --- a/OfCourseIStillLoveYou.DesktopClient/MainWindow.axaml.cs +++ b/OfCourseIStillLoveYou.DesktopClient/MainWindow.axaml.cs @@ -17,7 +17,7 @@ namespace OfCourseIStillLoveYou.DesktopClient { public class MainWindow : Window { - private const int Delay = 20; + private const int Delay = 30; private const string SettingPath = "settings.json"; private const string Endpoint = "localhost"; private const int Port = 5077; diff --git a/OfCourseIStillLoveYou/Core.cs b/OfCourseIStillLoveYou/Core.cs index 060bebf..84e3331 100644 --- a/OfCourseIStillLoveYou/Core.cs +++ b/OfCourseIStillLoveYou/Core.cs @@ -43,17 +43,16 @@ public static List GetAllTrackingCameras() void LateUpdate() { - RenderCameras(); + UpdateTelemetry(); } - private void RenderCameras() + private void UpdateTelemetry() { foreach (var trackedCamerasValue in TrackedCameras.Values) { if (trackedCamerasValue.Enabled) { - trackedCamerasValue.RenderCameras(); trackedCamerasValue.CalculateSpeedAltitude(); } } diff --git a/OfCourseIStillLoveYou/TrackingCamera.cs b/OfCourseIStillLoveYou/TrackingCamera.cs index 3871d39..1900ebf 100644 --- a/OfCourseIStillLoveYou/TrackingCamera.cs +++ b/OfCourseIStillLoveYou/TrackingCamera.cs @@ -36,6 +36,7 @@ public class TrackingCamera private float _windowWidth; private readonly WaitForEndOfFrame frameEnd = new WaitForEndOfFrame(); + private readonly WaitForSeconds fixedDelay = new WaitForSeconds(0.030f); private byte[] jpgTexture; public RenderTexture TargetCamRenderTexture; private readonly Texture2D texture2D = new Texture2D(768, 768, TextureFormat.ARGB32, false); @@ -94,10 +95,15 @@ public IEnumerator SendCameraImage() { while (Enabled) { + yield return fixedDelay; + + if (!Enabled) yield return null; + + RenderCameras(); + yield return frameEnd; if (!StreamingEnabled) continue; - if (!Enabled) yield return null; Graphics.CopyTexture(TargetCamRenderTexture, texture2D); @@ -135,7 +141,7 @@ private void SetCameras() partNearCamera.transform.localRotation = Quaternion.LookRotation(_hullcamera.cameraForward, _hullcamera.cameraUp); partNearCamera.transform.localPosition = _hullcamera.cameraPosition; - partNearCamera.fieldOfView = _hullcamera.cameraFoV; + partNearCamera.fieldOfView = 50; partNearCamera.targetTexture = TargetCamRenderTexture; _cameras[0] = partNearCamera; @@ -157,6 +163,7 @@ private void SetCameras() partScaledCamera.transform.localRotation = Quaternion.identity; partScaledCamera.transform.localPosition = Vector3.zero; partScaledCamera.transform.localScale = Vector3.one; + partScaledCamera.fieldOfView = 50; partScaledCamera.targetTexture = TargetCamRenderTexture; _cameras[1] = partScaledCamera; @@ -176,7 +183,7 @@ private void SetCameras() galaxyCam.transform.position = Vector3.zero; galaxyCam.transform.localRotation = Quaternion.identity; galaxyCam.transform.localScale = Vector3.one; - galaxyCam.fieldOfView = 60; + galaxyCam.fieldOfView = 50; galaxyCam.targetTexture = TargetCamRenderTexture; _cameras[2] = galaxyCam; @@ -367,7 +374,7 @@ internal static void RepositionWindow(ref Rect windowPosition) windowPosition.y = Screen.height - windowPosition.height; } - public void RenderCameras() + private void RenderCameras() { for (var i = _cameras.Length - 1; i >= 0; i--) {