reformat code + level load events

This commit is contained in:
2022-05-05 18:52:53 +03:00
parent 8762138fe3
commit fe443b9f50
38 changed files with 6380 additions and 6408 deletions

View File

@@ -1,108 +1,104 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using FlaxEditor.Content.Settings;
using FlaxEngine;
using FlaxEngine.GUI;
namespace Cabrito
{
[ExecuteInEditMode]
public class FpsScript : Script
{
public UIControl control;
Label label;
[ExecuteInEditMode]
public class FpsScript : Script
{
private const double updateInterval = 0.25;
private const double drawInterval = 0.25;
private const double physicsInterval = 0.25;
Stopwatch sw;
double updateTimeAvg = 0.0;
ulong updateTimeCount;
const double updateInterval = 0.25;
double updateAccumTime = 0.0;
private double conTime;
public UIControl control;
Stopwatch sw2;
double drawTimeAvg = 0.0;
ulong drawTimeCount;
const double drawInterval = 0.25;
double drawAccumTime = 0.0;
private string currentRenderer = "Unknown";
private double drawAccumTime;
private double drawTimeAvg;
private ulong drawTimeCount;
private Label label;
private double physicsAccumTime;
private double physicsTimeAvg;
private ulong physicsTimeCount;
Stopwatch sw3;
double physicsTimeAvg = 0.0;
ulong physicsTimeCount;
const double physicsInterval = 0.25;
double physicsAccumTime = 0.0;
private Stopwatch sw;
Stopwatch sw0;
private Stopwatch sw0;
string currentRenderer = "Unknown";
private Stopwatch sw2;
RenderTask t;
private Stopwatch sw3;
TimeSettings timeSettings;
private RenderTask t;
public override void OnAwake()
{
label = (Label) control.Control;
private TimeSettings timeSettings;
private double updateAccumTime;
private double updateTimeAvg;
private ulong updateTimeCount;
sw = Stopwatch.StartNew();
sw2 = Stopwatch.StartNew();
sw3 = Stopwatch.StartNew();
sw0 = Stopwatch.StartNew();
public override void OnAwake()
{
label = (Label)control.Control;
currentRenderer = GPUDevice.Instance.RendererType.ToString();
sw = Stopwatch.StartNew();
sw2 = Stopwatch.StartNew();
sw3 = Stopwatch.StartNew();
sw0 = Stopwatch.StartNew();
if (t == null)
{
//Destroy(t);
t = new RenderTask();
t.Render += OnDraw;
}
currentRenderer = GPUDevice.Instance.RendererType.ToString();
var settings = FlaxEditor.Content.Settings.GameSettings.Load();
timeSettings = settings.Time.CreateInstance<FlaxEditor.Content.Settings.TimeSettings>();
}
if (t == null)
{
//Destroy(t);
t = new RenderTask();
t.Render += OnDraw;
}
public override void OnDestroy()
{
Destroy(t);
t = null;
}
GameSettings settings = GameSettings.Load();
timeSettings = settings.Time.CreateInstance<TimeSettings>();
}
double conTime = 0.0;
public override void OnDestroy()
{
Destroy(t);
t = null;
}
public override void OnUpdate()
{
updateAccumTime += Time.DeltaTime;
updateTimeCount++;
double elapsed = sw.Elapsed.TotalSeconds;
if (elapsed >= updateInterval)
{
sw.Restart();
updateTimeAvg = elapsed / updateTimeCount;
updateTimeCount = 0;
public override void OnUpdate()
{
updateAccumTime += Time.DeltaTime;
updateTimeCount++;
double elapsed = sw.Elapsed.TotalSeconds;
if (elapsed >= updateInterval)
{
sw.Restart();
updateTimeAvg = elapsed / updateTimeCount;
updateTimeCount = 0;
conTime = ((ConsoleContentTextBox.accumDrawTime / ConsoleContentTextBox.accumDrawTimes) * 1000.0);
ConsoleContentTextBox.accumDrawTime = 0.0;
ConsoleContentTextBox.accumDrawTimes = 0;
}
conTime = ConsoleContentTextBox.accumDrawTime / ConsoleContentTextBox.accumDrawTimes * 1000.0;
ConsoleContentTextBox.accumDrawTime = 0.0;
ConsoleContentTextBox.accumDrawTimes = 0;
}
StringBuilder sb = new StringBuilder();
sb.Append("eFPS: " + Engine.FramesPerSecond);
sb.Append(" uTime: " + sw0.Elapsed.TotalSeconds);
sb.Append("\nuFPS: " + ((int) Math.Round(1.0f / updateTimeAvg)));
sb.Append(" uTime: " + updateAccumTime);
sb.Append("\nrFPS: " + ((int) Math.Round(1.0f / drawTimeAvg)));
sb.Append(" rTime: " + drawAccumTime);
sb.Append("\npFPS: " + ((int) Math.Round(1.0f / physicsTimeAvg)));
sb.Append(" pTime: " + physicsAccumTime);
//sb.Append("\nCon: " + conTime.ToString() + "ms");
//sb.Append("\nGC memory: " + (GC.GetTotalMemory(false) / 1000000.0f).ToString() + "MB");
//sb.Append("\nUpdate profiler: " + updateProfTime.ToString() + "ms");
StringBuilder sb = new StringBuilder();
sb.Append("eFPS: " + Engine.FramesPerSecond);
sb.Append(" uTime: " + sw0.Elapsed.TotalSeconds);
sb.Append("\nuFPS: " + (int)Math.Round(1.0f / updateTimeAvg));
sb.Append(" uTime: " + updateAccumTime);
sb.Append("\nrFPS: " + (int)Math.Round(1.0f / drawTimeAvg));
sb.Append(" rTime: " + drawAccumTime);
sb.Append("\npFPS: " + (int)Math.Round(1.0f / physicsTimeAvg));
sb.Append(" pTime: " + physicsAccumTime);
//sb.Append("\nCon: " + conTime.ToString() + "ms");
//sb.Append("\nGC memory: " + (GC.GetTotalMemory(false) / 1000000.0f).ToString() + "MB");
//sb.Append("\nUpdate profiler: " + updateProfTime.ToString() + "ms");
#if false
#if false
#if BUILD_DEVELOPMENT
var nameOffset = Marshal.OffsetOf(typeof(ProfilerCPU.Event), "Name0");
foreach (var eventsCpu in FlaxEngine.ProfilingTools.EventsCPU)
@@ -132,54 +128,54 @@ namespace Cabrito
#endif
#endif
((Label) control.Control).Text = sb.ToString();
/*if (!Platform.HasFocus)
{
Time.UpdateFPS = 15;
Time.DrawFPS = 15;
Time.PhysicsFPS = 15;
}
((Label)control.Control).Text = sb.ToString();
/*if (!Platform.HasFocus)
{
Time.UpdateFPS = 15;
Time.DrawFPS = 15;
Time.PhysicsFPS = 15;
}
#if FLAX_EDITOR
else if (!FlaxEditor.Editor.IsPlayMode)
{
var editorFPS = FlaxEditor.Editor.Instance.Options.Options.General.EditorFPS;
Time.UpdateFPS = editorFPS;
Time.DrawFPS = editorFPS;
Time.PhysicsFPS = timeSettings.PhysicsFPS;
}
else if (!FlaxEditor.Editor.IsPlayMode)
{
var editorFPS = FlaxEditor.Editor.Instance.Options.Options.General.EditorFPS;
Time.UpdateFPS = editorFPS;
Time.DrawFPS = editorFPS;
Time.PhysicsFPS = timeSettings.PhysicsFPS;
}
#endif
else
{
Time.UpdateFPS = timeSettings.UpdateFPS;
Time.DrawFPS = timeSettings.DrawFPS;
Time.PhysicsFPS = timeSettings.PhysicsFPS;
}*/
}
else
{
Time.UpdateFPS = timeSettings.UpdateFPS;
Time.DrawFPS = timeSettings.DrawFPS;
Time.PhysicsFPS = timeSettings.PhysicsFPS;
}*/
}
public override void OnFixedUpdate()
{
physicsAccumTime += Time.DeltaTime;
physicsTimeCount++;
double elapsed = sw3.Elapsed.TotalSeconds;
if (elapsed >= physicsInterval)
{
sw3.Restart();
physicsTimeAvg = elapsed / physicsTimeCount;
physicsTimeCount = 0;
}
}
public override void OnFixedUpdate()
{
physicsAccumTime += Time.DeltaTime;
physicsTimeCount++;
double elapsed = sw3.Elapsed.TotalSeconds;
if (elapsed >= physicsInterval)
{
sw3.Restart();
physicsTimeAvg = elapsed / physicsTimeCount;
physicsTimeCount = 0;
}
}
void OnDraw(RenderTask tt, GPUContext context)
{
drawAccumTime += Time.DeltaTime;
drawTimeCount++;
double elapsed = sw2.Elapsed.TotalSeconds;
if (elapsed >= drawInterval)
{
sw2.Restart();
drawTimeAvg = elapsed / drawTimeCount;
drawTimeCount = 0;
}
}
}
private void OnDraw(RenderTask tt, GPUContext context)
{
drawAccumTime += Time.DeltaTime;
drawTimeCount++;
double elapsed = sw2.Elapsed.TotalSeconds;
if (elapsed >= drawInterval)
{
sw2.Restart();
drawTimeAvg = elapsed / drawTimeCount;
drawTimeCount = 0;
}
}
}
}