commit 6677c4e4e86fadc41ed4d09c28a80f1d2b1bc7e8
parent d00a86d13ad9b4678c1939300bc42c5ef655407d
Author: Mikolaj Lenczewski <33129490+EnderRifter@users.noreply.github.com>
Date: Fri, 11 Oct 2019 21:11:20 +0100
Improved simulation logging to take into account active simulation frames only.
Diffstat:
6 files changed, 52 insertions(+), 26 deletions(-)
diff --git a/StarSim/StarSimGui/Views/MainWindow.xaml.cs b/StarSim/StarSimGui/Views/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
-using Avalonia.Controls;
+using Avalonia;
+using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace StarSimGui.Views
diff --git a/StarSim/StarSimLib/Data Structures/Body.cs b/StarSim/StarSimLib/Data Structures/Body.cs
@@ -196,7 +196,6 @@ namespace StarSimLib.Data_Structures
{
mass += otherBody.mass;
velocity += otherBody.velocity;
- force += otherBody.force;
}
/// <summary>
diff --git a/StarSim/StarSimLib/StarSimLib.xml b/StarSim/StarSimLib/StarSimLib.xml
@@ -2002,6 +2002,13 @@
<param name="renderTarget">The <see cref="T:SFML.Graphics.RenderTarget"/> to which to draw this instance.</param>
<param name="renderStates">The <see cref="T:SFML.Graphics.RenderStates"/> to use for the drawing.</param>
</member>
+ <member name="M:StarSimLib.UI.Screen.Log(System.String,System.Boolean)">
+ <summary>
+ Logs the given message to the console.
+ </summary>
+ <param name="message">The message to log.</param>
+ <param name="debugOnly">Whether this message should only be shown if in debug mode.</param>
+ </member>
<member name="M:StarSimLib.UI.Screen.Run">
<summary>
Displays the screen until it is closed.
@@ -2132,7 +2139,7 @@
Counts the frames elapsed since the last timer pulse, so that the FPS can be tracked.
</summary>
</member>
- <member name="F:StarSimLib.UI.SimulationScreen.totalFramesElapsed">
+ <member name="F:StarSimLib.UI.SimulationScreen.simulationFramesElapsed">
<summary>
Counts the number of frames elapsed since the beginning of the simulation.
</summary>
diff --git a/StarSim/StarSimLib/UI/Screen.cs b/StarSim/StarSimLib/UI/Screen.cs
@@ -1,4 +1,5 @@
-using SFML.Graphics;
+using System;
+using SFML.Graphics;
namespace StarSimLib.UI
{
@@ -70,6 +71,25 @@ namespace StarSimLib.UI
protected abstract void SetupScreen(RenderTarget renderTarget, RenderStates renderStates);
/// <summary>
+ /// Logs the given message to the console.
+ /// </summary>
+ /// <param name="message">The message to log.</param>
+ /// <param name="debugOnly">Whether this message should only be shown if in debug mode.</param>
+ internal void Log(string message, bool debugOnly = true)
+ {
+ if (debugOnly)
+ {
+#if DEBUG
+ Console.WriteLine(message);
+#endif
+ }
+ else
+ {
+ Console.WriteLine(message);
+ }
+ }
+
+ /// <summary>
/// Displays the screen until it is closed.
/// </summary>
public void Run()
diff --git a/StarSim/StarSimLib/UI/SimulationInputHandler.cs b/StarSim/StarSimLib/UI/SimulationInputHandler.cs
@@ -131,7 +131,7 @@ namespace StarSimLib.UI
if (!msg.Equals(""))
{
- Console.WriteLine(msg);
+ HandledScreen.Log(msg);
}
}
@@ -148,26 +148,26 @@ namespace StarSimLib.UI
if (!msg.Equals(""))
{
- Console.WriteLine(msg);
+ HandledScreen.Log(msg);
}
}
/// <inheritdoc />
public void HandleMouseMoved(object sender, MouseMoveEventArgs eventArgs)
{
- //Console.WriteLine($"Mouse moved: {eventArgs.X} {eventArgs.Y}");
+ HandledScreen.Log($"Mouse moved: {eventArgs.X} {eventArgs.Y}");
}
/// <inheritdoc />
public void HandleMousePressed(object sender, MouseButtonEventArgs eventArgs)
{
- //Console.WriteLine($"Mouse pressed: {eventArgs.X} {eventArgs.Y}, {eventArgs.Button}");
+ HandledScreen.Log($"Mouse pressed: {eventArgs.X} {eventArgs.Y}, {eventArgs.Button}");
}
/// <inheritdoc />
public void HandleMouseReleased(object sender, MouseButtonEventArgs eventArgs)
{
- //Console.WriteLine($"Mouse released: {eventArgs.X} {eventArgs.Y}, {eventArgs.Button}");
+ HandledScreen.Log($"Mouse released: {eventArgs.X} {eventArgs.Y}, {eventArgs.Button}");
}
/// <inheritdoc />
@@ -181,8 +181,6 @@ namespace StarSimLib.UI
{
simulationDrawer.Scale(1 - Constants.ZoomStep);
}
-
- Console.WriteLine($"Current field of view (zoom level): {simulationDrawer.FOV} ({simulationDrawer.ZoomLevel})");
}
/// <inheritdoc />
diff --git a/StarSim/StarSimLib/UI/SimulationScreen.cs b/StarSim/StarSimLib/UI/SimulationScreen.cs
@@ -72,7 +72,7 @@ namespace StarSimLib.UI
/// <summary>
/// Counts the number of frames elapsed since the beginning of the simulation.
/// </summary>
- private ulong totalFramesElapsed;
+ private ulong simulationFramesElapsed;
/// <summary>
/// Initialises a new instance of the <see cref="SimulationScreen"/> class.
@@ -195,31 +195,32 @@ namespace StarSimLib.UI
/// <inheritdoc />
protected override void DrawFrame(RenderTarget renderTarget, RenderStates renderStates)
{
- if (fileWriter != null)
+ if (!simulationInputHandler.IsSimulationPaused)
{
- fileWriter.WriteLine($"FRAME: {totalFramesElapsed}, ELAPSED TIME: {totalFramesElapsed * Constants.TimeStep}");
-
- // write out the unique id of the body and its state to the currently open file
- foreach (Body body in bodies)
+ if (fileWriter != null)
{
- fileWriter.WriteLine($"{body.Generation,2:D}.{body.Id,-4:D}\t" +
- $"{body.Mass,21}\t" +
- $"[{body.Position.X,21}, {body.Position.Y,21}, {body.Position.Z,21}]\t" +
- $"[{body.Velocity.X,21}, {body.Velocity.Y,21}, {body.Velocity.Z,21}]\t" +
- $"[{body.Force.X,21}, {body.Force.Y,21}, {body.Force.Z,21}]");
+ fileWriter.WriteLine($"FRAME: {simulationFramesElapsed}, ELAPSED TIME: {simulationFramesElapsed * Constants.TimeStep}");
+
+ // write out the unique id of the body and its state to the currently open file
+ foreach (Body body in bodies)
+ {
+ fileWriter.WriteLine($"{body.Generation,2:D}.{body.Id,-4:D}\t" +
+ $"{body.Mass,21}\t" +
+ $"[{body.Position.X,21}, {body.Position.Y,21}, {body.Position.Z,21}]\t" +
+ $"[{body.Velocity.X,21}, {body.Velocity.Y,21}, {body.Velocity.Z,21}]\t" +
+ $"[{body.Force.X,21}, {body.Force.Y,21}, {body.Force.Z,21}]");
+ }
}
- }
- if (!simulationInputHandler.IsSimulationPaused)
- {
bodyPositionUpdater(bodies, Constants.TimeStep);
+
+ simulationFramesElapsed++;
}
simulationDrawer.DrawBodies();
// increment the fps counter and global frame counter
framesElapsed++;
- totalFramesElapsed++;
}
/// <inheritdoc />