Skip to content

Commit

Permalink
Add option for FPS counter
Browse files Browse the repository at this point in the history
  • Loading branch information
thekovic committed Feb 11, 2023
1 parent d61ea3c commit 21ae4c4
Show file tree
Hide file tree
Showing 5 changed files with 469 additions and 316 deletions.
4 changes: 4 additions & 0 deletions Source/Core/Config/ProgramConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class ProgramConfiguration
private bool toolbargeometry;
private bool toolbartesting;
private bool toolbarfile;
private bool showfps;

// These are not stored in the configuration, only used at runtime
private string defaulttexture;
Expand Down Expand Up @@ -155,6 +156,7 @@ public class ProgramConfiguration
public bool ToolbarGeometry { get { return toolbargeometry; } internal set { toolbargeometry = value; } }
public bool ToolbarTesting { get { return toolbartesting; } internal set { toolbartesting = value; } }
public bool ToolbarFile { get { return toolbarfile; } internal set { toolbarfile = value; } }
public bool ShowFPS { get { return showfps; } internal set { showfps = value; } }

public string DefaultTexture { get { return defaulttexture; } set { defaulttexture = value; } }
public string DefaultFloorTexture { get { return defaultfloortexture; } set { defaultfloortexture = value; } }
Expand Down Expand Up @@ -234,6 +236,7 @@ internal bool Load(string cfgfilepathname, string defaultfilepathname)
toolbargeometry = cfg.ReadSetting("toolbargeometry", true);
toolbartesting = cfg.ReadSetting("toolbartesting", true);
toolbarfile = cfg.ReadSetting("toolbarfile", true);
showfps = cfg.ReadSetting("showfps", false);

// Success
return true;
Expand Down Expand Up @@ -295,6 +298,7 @@ internal void Save(string filepathname)
cfg.WriteSetting("toolbargeometry", toolbargeometry);
cfg.WriteSetting("toolbartesting", toolbartesting);
cfg.WriteSetting("toolbarfile", toolbarfile);
cfg.WriteSetting("showfps", showfps);

// Save settings configuration
General.WriteLogLine("Saving program configuration...");
Expand Down
22 changes: 14 additions & 8 deletions Source/Core/Rendering/Renderer3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public void ApplyMatrices2D()
// This starts rendering
public bool Start()
{
if (!fpsWatch.IsRunning)
if (General.Settings.ShowFPS && !fpsWatch.IsRunning)
{
fpsWatch.Start();
}
Expand Down Expand Up @@ -566,13 +566,16 @@ public void FinishGeometry()
graphics.Shaders.World3D.End();
geometry = null;

fps++;
if (fpsWatch.ElapsedMilliseconds > 1000)
if (General.Settings.ShowFPS)
{
fpsLabel.Text = string.Format("{0} FPS", fps);
fps = 0;
fpsWatch.Reset();
fpsWatch.Start();
fps++;
if (fpsWatch.ElapsedMilliseconds > 1000)
{
fpsLabel.Text = string.Format("{0} FPS", fps);
fps = 0;
fpsWatch.Reset();
fpsWatch.Start();
}
}
}

Expand Down Expand Up @@ -1015,7 +1018,10 @@ public void RenderCrosshair()
graphics.Shaders.Display2D.EndPass();
graphics.Shaders.Display2D.End();

General.Map.Renderer2D.RenderText(fpsLabel);
if (General.Settings.ShowFPS)
{
General.Map.Renderer2D.RenderText(fpsLabel);
}
}

// This switches fog on and off
Expand Down
Loading

0 comments on commit 21ae4c4

Please sign in to comment.