Skip to content

Commit

Permalink
V0.2.0-beta.8
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikja163 committed Apr 20, 2024
1 parent 3054b90 commit 7e5bed4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description>3D Game Engine for C# written in C# using OpenTK bindings for OpenGL.</Description>
<PackageLicenseExpression>MIT-0</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>0.2.0-beta.7</Version>
<Version>0.2.0-beta.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
23 changes: 23 additions & 0 deletions JAngine/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ private static void LogMessage(LogMessage message)
}

// TODO: Make sure this has as little overhead as possible.
/// <summary>
/// Starts a timer and optionally logs the time at the end.
/// If the time is not logged at the end you can instead call <see cref="LogTimer(System.String)"/> with the same name.
/// </summary>
/// <param name="timerName">The name of the timer to log.</param>
/// <param name="logAtEnd">If true the timer will be logged when stopped. Otherwise you will have to manually log it using <see cref="LogTimer(System.String)"/></param>
/// <returns>The LogTimer keeping track of the current time. Call dispose on it to stop the timer again.</returns>
public static LogTimer Time(string timerName, bool logAtEnd = true)
{
if (!_timers.TryGetValue(timerName, out TimerRecord? record))
Expand All @@ -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");
}

/// <summary>
/// Logs the value of a timer by name.
/// </summary>
/// <param name="timerName">The name of the timer to log.</param>
public static void LogTimer(string timerName)
{
if (!_timers.TryGetValue(timerName, out TimerRecord? record))
Expand All @@ -305,6 +316,18 @@ public static void LogTimer(string timerName)
}
LogTimer(record);
}

/// <summary>
/// Reset the value of a timer by name.
/// </summary>
/// <param name="timerName">The name of the timer to reset.</param>
public static void ResetTimer(string timerName)
{
if (_timers.TryGetValue(timerName, out TimerRecord? record))
{
record.Reset();
}
}

/// <summary>
/// Sends a log message with a run-time specified message.
Expand Down
4 changes: 3 additions & 1 deletion JAngine/Rendering/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 7e5bed4

Please sign in to comment.