Skip to content

Commit

Permalink
Merge pull request #1 from thekovic/fps
Browse files Browse the repository at this point in the history
Fix FPS regression in Visual Mode
  • Loading branch information
thekovic authored Feb 11, 2023
2 parents 38064d7 + 21ae4c4 commit f78282f
Show file tree
Hide file tree
Showing 7 changed files with 495 additions and 313 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Source/Plugins/ImageDrawingExample/obj
Build/*.exe
Build/*.pdb
Build/Plugins
Build/Builder.xml
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
35 changes: 34 additions & 1 deletion Source/Core/Rendering/Renderer3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ internal sealed class Renderer3D : Renderer, IRenderer3D
// Things to be rendered, sorted by distance from camera
private BinaryHeap<VisualThing> thingsbydistance;

// FPS-related
private int fps = 0;
private System.Diagnostics.Stopwatch fpsWatch;
private TextLabel fpsLabel;

#endregion

#region ================== Properties
Expand Down Expand Up @@ -135,6 +140,12 @@ internal Renderer3D(D3DDevice graphics) : base(graphics)
frustum = new ProjectedFrustum2D(new Vector2D(), 0.0f, 0.0f, PROJ_NEAR_PLANE,
General.Settings.ViewDistance, Angle2D.DegToRad((float)General.Settings.VisualFOV));

fpsLabel = new TextLabel(7);
fpsLabel.AlignX = TextAlignmentX.Left;
fpsLabel.AlignY = TextAlignmentY.Top;
fpsLabel.Text = "(FPS unavailable)";
fpsWatch = new System.Diagnostics.Stopwatch();

// We have no destructor
GC.SuppressFinalize(this);
}
Expand Down Expand Up @@ -422,6 +433,11 @@ public void ApplyMatrices2D()
// This starts rendering
public bool Start()
{
if (General.Settings.ShowFPS && !fpsWatch.IsRunning)
{
fpsWatch.Start();
}

// Create texture
if (General.Map.Data.ThingBox.Texture == null)
General.Map.Data.ThingBox.CreateTexture();
Expand Down Expand Up @@ -549,6 +565,18 @@ public void FinishGeometry()
// Done
graphics.Shaders.World3D.End();
geometry = null;

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

// villsa 9/15/11
Expand Down Expand Up @@ -989,6 +1017,11 @@ public void RenderCrosshair()
graphics.Device.DrawUserPrimitives<FlatVertex>(PrimitiveType.TriangleStrip, 0, 2, crosshairverts);
graphics.Shaders.Display2D.EndPass();
graphics.Shaders.Display2D.End();

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

// This switches fog on and off
Expand All @@ -997,7 +1030,7 @@ public void SetFogMode(bool usefog)
graphics.Device.SetRenderState(RenderState.FogEnable, usefog);
}

// This siwtches crosshair busy icon on and off
// This switches crosshair busy icon on and off
public void SetCrosshairBusy(bool busy)
{
crosshairbusy = busy;
Expand Down
9 changes: 5 additions & 4 deletions Source/Core/Windows/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,6 @@ public void RedrawDisplay()
{
if ((General.Map != null) && (General.Editing.Mode != null))
{
foreach (Sector s in General.Map.Map.Sectors)
s.UpdateNeeded = true;

General.Map.Map.Update();
General.Editing.Mode.OnRedrawDisplay();
}
else
Expand Down Expand Up @@ -2004,6 +2000,11 @@ public void ToggleFullBrightness()
General.Interface.DisplayStatus(StatusType.Action, "Full Brightness is now " + (Renderer.FullBrightness ? "ON" : "OFF"));

// Redraw display to show changes
foreach (Sector s in General.Map.Map.Sectors)
{
s.UpdateNeeded = true;
}
General.Map.Map.Update();
General.Interface.RedrawDisplay();
}

Expand Down
Loading

0 comments on commit f78282f

Please sign in to comment.