diff --git a/Directory.Build.props b/Directory.Build.props index 3696dc7..da32ca2 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ 3D Game Engine for C# written in C# using OpenTK bindings for OpenGL. MIT-0 README.md - 0.2.0-beta.7 + 0.2.0-beta.8 diff --git a/JAngine/Log.cs b/JAngine/Log.cs index eef399c..97150ba 100644 --- a/JAngine/Log.cs +++ b/JAngine/Log.cs @@ -279,6 +279,13 @@ private static void LogMessage(LogMessage message) } // TODO: Make sure this has as little overhead as possible. + /// + /// Starts a timer and optionally logs the time at the end. + /// If the time is not logged at the end you can instead call with the same name. + /// + /// The name of the timer to log. + /// If true the timer will be logged when stopped. Otherwise you will have to manually log it using + /// The LogTimer keeping track of the current time. Call dispose on it to stop the timer again. public static LogTimer Time(string timerName, bool logAtEnd = true) { if (!_timers.TryGetValue(timerName, out TimerRecord? record)) @@ -296,6 +303,10 @@ internal static void LogTimer(TimerRecord record) Info($"Timer {record.Name} has completed {record.Runs} runs with {average.ToStringFormatted()}/run and {record.TotalTime.ToStringFormatted()} total"); } + /// + /// Logs the value of a timer by name. + /// + /// The name of the timer to log. public static void LogTimer(string timerName) { if (!_timers.TryGetValue(timerName, out TimerRecord? record)) @@ -305,6 +316,18 @@ public static void LogTimer(string timerName) } LogTimer(record); } + + /// + /// Reset the value of a timer by name. + /// + /// The name of the timer to reset. + public static void ResetTimer(string timerName) + { + if (_timers.TryGetValue(timerName, out TimerRecord? record)) + { + record.Reset(); + } + } /// /// Sends a log message with a run-time specified message. diff --git a/JAngine/Rendering/Window.cs b/JAngine/Rendering/Window.cs index 860e5e6..fe518bc 100644 --- a/JAngine/Rendering/Window.cs +++ b/JAngine/Rendering/Window.cs @@ -285,6 +285,7 @@ private void RenderThread() } Gl.Clear(Gl.ClearBufferMask.ColorBuffer | Gl.ClearBufferMask.DepthBuffer); + LogTimer timer = Log.Time("Frame", false); List<(IGlObject, IGlEvent, StackTrace?)> objects; lock (_updateQueue) @@ -306,7 +307,8 @@ private void RenderThread() Gl.DrawElementsInstanced(Gl.PrimitiveType.Triangles, vao.PointCount, Gl.DrawElementsType.UnsignedInt, 0, vao.InstanceCount); } } - + + timer.Dispose(); Glfw.SwapBuffers(_handle); } }