Skip to content

Commit

Permalink
Basic performance metrics and server log truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Nov 23, 2023
1 parent dbef3bd commit 4202cd1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CentrED/Map/MapManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,10 @@ private MouseDirection ProcessMouseMovement(ref MouseState mouseState, out float
private MouseState _prevMouseState = Mouse.GetState();
private Rectangle _prevViewRange;

public TimeSpan UpdateTime { get; private set; } = TimeSpan.Zero;
public void Update(GameTime gameTime, bool isActive, bool processMouse, bool processKeyboard)
{
var startTime = DateTime.Now;
if (!Client.Initialized)
return;
if (isActive && processMouse)
Expand Down Expand Up @@ -507,6 +509,7 @@ public void Update(GameTime gameTime, bool isActive, bool processMouse, bool pro
}

_prevMouseState = Mouse.GetState();
UpdateTime = DateTime.Now - startTime;
}

public void Reset()
Expand Down Expand Up @@ -714,8 +717,11 @@ private void DrawLand(LandObject lo, Vector3 hueOverride = default)
_mapRenderer.DrawMapObject(lo, hueOverride);
}

public TimeSpan DrawTime { get; private set; } = TimeSpan.Zero;

public void Draw()
{
var startTime = DateTime.Now;
if (!Client.Initialized)
{
DrawBackground();
Expand All @@ -736,6 +742,7 @@ public void Draw()
DrawLand();
DrawStatics();
DrawVirtualLayer();
DrawTime = DateTime.Now - startTime;
}

private void DrawBackground()
Expand Down
6 changes: 6 additions & 0 deletions CentrED/UI/UIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ public UIManager(GraphicsDevice gd)
_debugWindow = new DebugWindow();
}

public TimeSpan UpdateTime { get; private set; } = TimeSpan.Zero;
public void Update(GameTime gameTime, bool isActive)
{
var startTime = DateTime.Now;
var io = ImGui.GetIO();

io.DeltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
Expand Down Expand Up @@ -116,18 +118,22 @@ public void Update(GameTime gameTime, bool isActive)
_graphicsDevice.PresentationParameters.BackBufferHeight
);
io.DisplayFramebufferScale = new Vector2(1f, 1f);
UpdateTime = DateTime.Now - startTime;
}

internal double _framesPerSecond;

public TimeSpan DrawTime { get; private set; } = TimeSpan.Zero;
public void Draw(GameTime gameTime)
{
var startTime = DateTime.Now;
_framesPerSecond = 1 / gameTime.ElapsedGameTime.TotalSeconds;
ImGui.NewFrame();
DrawUI();
ImGui.Render();

_uiRenderer.RenderDrawData(ImGui.GetDrawData());
DrawTime = DateTime.Now - startTime;
}

public bool CapturingMouse => ImGui.GetIO().WantCaptureMouse;
Expand Down
4 changes: 4 additions & 0 deletions CentrED/UI/Windows/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public override void Draw()
var mapManager = Application.CEDGame.MapManager;
ImGui.Begin(Name, ref _show, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoResize);
ImGui.Text($"FPS: {uiManager._framesPerSecond:F1}");
ImGui.Text($"Map UpdateTime: {mapManager.UpdateTime.TotalMilliseconds}ms");
ImGui.Text($"Map DrawTime: {mapManager.DrawTime.TotalMilliseconds}ms");
ImGui.Text($"UI UpdateTime: {uiManager.UpdateTime.TotalMilliseconds}ms");
ImGui.Text($"UI DrawTime: {uiManager.DrawTime.TotalMilliseconds}ms");
ImGui.Text
(
$"Resolution: {uiManager._graphicsDevice.PresentationParameters.BackBufferWidth}x{uiManager._graphicsDevice.PresentationParameters.BackBufferHeight}"
Expand Down
6 changes: 6 additions & 0 deletions CentrED/UI/Windows/ServerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ServerWindow : Window
private string _statusText = "Stopped";
private StreamReader? _logReader;
private StringBuilder _log = new();
private const int LOG_BUFFER_SIZE = 10000;

public override void Draw()
{
Expand Down Expand Up @@ -106,8 +107,13 @@ public override void Draw()
if (line == null)
break;
_log.AppendLine(line);
ImGui.SetScrollY(ImGui.GetScrollMaxY());
} while (true);
}
if (_log.Length > LOG_BUFFER_SIZE)
{
_log.Remove(0, _log.Length - LOG_BUFFER_SIZE);
}
ImGui.TextUnformatted(_log.ToString());
ImGui.EndChild();

Expand Down

0 comments on commit 4202cd1

Please sign in to comment.