Skip to content

Commit

Permalink
Performance improvements:
Browse files Browse the repository at this point in the history
-  locking to 25 fps max the cameras rendering and streaming
-  locking  cameras FOV to 50
-  Reducing desktop client refresh rate
  • Loading branch information
jrodrigv committed Apr 21, 2021
1 parent 6d49744 commit cd76051
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion OfCourseIStillLoveYou.DesktopClient/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions OfCourseIStillLoveYou/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ public static List<MuMechModuleHullCamera> GetAllTrackingCameras()

void LateUpdate()
{
RenderCameras();
UpdateTelemetry();
}


private void RenderCameras()
private void UpdateTelemetry()
{
foreach (var trackedCamerasValue in TrackedCameras.Values)
{
if (trackedCamerasValue.Enabled)
{
trackedCamerasValue.RenderCameras();
trackedCamerasValue.CalculateSpeedAltitude();
}
}
Expand Down
15 changes: 11 additions & 4 deletions OfCourseIStillLoveYou/TrackingCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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--)
{
Expand Down

0 comments on commit cd76051

Please # to comment.