StarSim

StarSim.git
git clone git://git.lenczewski.org/StarSim.git
Log | Files | Refs | README | LICENSE

commit ef94ee47124a1cbe0bd136620ba4e7ce236a504e
parent 9f2f03178e6d7688ea7cb1bbedb8e910579360a7
Author: Mikolaj Lenczewski <33129490+EnderRifter@users.noreply.github.com>
Date:   Fri, 28 Jun 2019 15:12:49 +0100

Refactored star sim library into proper structure, and encapsulated core functionality into separate classes.

Diffstat:
MStarSim/StarSim/Program.cs | 182+++++++++++++++++++++++++++++++++++--------------------------------------------
MStarSim/StarSimLib/Graphics/Drawer.cs | 68+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
MStarSim/StarSimLib/Physics/Body.cs | 34++++++++++++++++++++++------------
AStarSim/StarSimLib/Physics/BodyGenerator.cs | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AStarSim/StarSimLib/Physics/BodyUpdater.cs | 43+++++++++++++++++++++++++++++++++++++++++++
MStarSim/StarSimLib/Physics/OrbitGenerator.cs | 2+-
MStarSim/StarSimLib/StarSimLib.xml | 113+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
DStarSim/StarSimLib/UpdateDelegate.cs | 13-------------
8 files changed, 371 insertions(+), 145 deletions(-)

diff --git a/StarSim/StarSim/Program.cs b/StarSim/StarSim/Program.cs @@ -1,115 +1,83 @@ using System; using System.Collections.Generic; -using System.Linq; using SFML.Graphics; -using SFML.System; using SFML.Window; using StarSimLib; +using StarSimLib.Graphics; using StarSimLib.Physics; namespace StarSim { + /// <summary> + /// Main program class. + /// </summary> internal class Program { /// <summary> + /// The renderer used to display the <see cref="Body"/> instances on the screen. + /// </summary> + private static readonly Drawer bodyDrawer; + + /// <summary> /// The body position update algorithm to use. /// </summary> - private static readonly UpdateDelegate bodyPositionUpdater = UpdateBodiesBruteForce; + private static readonly UpdateDelegate bodyPositionUpdater; /// <summary> /// Caches a random number generator to use for all randomised positions and velocities. /// </summary> - private static readonly Random Rng = new Random(); + private static readonly Random Rng; /// <summary> - /// Holds all the <see cref="Body"/> instances that should be simulated. + /// The SFML.NET window to which everything is rendered. /// </summary> - private static Body[] _bodies; + private static readonly RenderWindow window; /// <summary> - /// The current generation of <see cref="Body"/>s that we have. Increments each time the bodies are regenerated - /// via <see cref="GenerateBodies(int, bool)"/>. + /// Holds all the <see cref="Body"/> instances that should be simulated. /// </summary> - private static uint _generation; + private static Body[] bodies; /// <summary> /// Maps a <see cref="Body"/> to the <see cref="CircleShape"/> that represents it, and is drawn to the /// screen at the <see cref="Body"/>s position. /// </summary> - private static Dictionary<Body, CircleShape> BodyShapeMap; + private static Dictionary<Body, CircleShape> bodyShapeMap; /// <summary> - /// Draws each <see cref="Body"/> in the given <see cref="IEnumerable{T}"/> to the given window. + /// Initialises a new instance of the <see cref="Program"/> class, /// </summary> - /// <param name="bodies">The collection of <see cref="Body"/>s to draw.</param> - /// <param name="renderTarget">The target to draw the <see cref="Body"/>s to.</param> - /// <param name="originOffset"> - /// The offset that has to be applied to the positions of the <see cref="CircleShape"/>, so that they appear - /// to be in the centre of the screen and not the top left corner. - /// </param> - private static void DrawBodies(IEnumerable<Body> bodies, RenderWindow renderTarget, Vector2u originOffset) + static Program() { - foreach (Body body in bodies) - { - // get the cached shape and projects the current bodies 3D position down to a 2D position, - // which is used as the new position of the shape. - CircleShape shape = BodyShapeMap[body]; - - shape.Position = new Vector2f( - (float)(body.Position.X * Constants.UniverseScalingFactor + originOffset.X), - (float)(body.Position.Y * Constants.UniverseScalingFactor + originOffset.Y) - ); - - shape.Draw(renderTarget, RenderStates.Default); - } - } - - private static void GenerateBodies(int bodyCount = 2, bool centralAttractor = false) - { - _generation++; - - uint id = 0; - _bodies = new Body[bodyCount]; - BodyShapeMap = new Dictionary<Body, CircleShape>(); - - Console.WriteLine($"=========== Generation {_generation} ==========="); - for (int i = 0; i < _bodies.Length; i++) - { - float mass = (float)(Rng.NextDouble() * Constants.SolarMass); - - Vector3d position = OrbitGenerator.RandomPosition(); - Vector3d velocity = OrbitGenerator.RandomOrbit(position); - - _bodies[i] = new Body(position, velocity, mass, _generation, id); - BodyShapeMap.Add(_bodies[i], new CircleShape(1) { FillColor = Color.White }); - - Console.WriteLine(_bodies[i]); - id++; - } - - if (centralAttractor && bodyCount >= 2) - { - BodyShapeMap.Remove(_bodies[0]); - _bodies[0] = new Body(new Vector3d(), new Vector3d(), Constants.CentralBodyMass, _generation, 0); - BodyShapeMap.Add(_bodies[0], new CircleShape(4) { FillColor = Color.Red }); - } + // we construct a new window instance, but immediately hide it so that we can configure the rest of the app + window = new RenderWindow(VideoMode.DesktopMode, "N-Body Simulator", Styles.Default, new ContextSettings()); + window.SetVisible(false); + + (bodies, bodyShapeMap) = BodyGenerator.GenerateBodies(Constants.BodyCount, true); +#if DEBUG + bodyPositionUpdater = BodyUpdater.UpdateBodiesBruteForce; +#else + bodyPositionUpdater = BodyUpdater.UpdateBodiesBruteForce; +#endif + bodyDrawer = new Drawer(window, ref bodies, ref bodyShapeMap); + Rng = new Random(); } /// <summary> /// Handles key presses. /// </summary> - /// <param name="sender">The <see cref="RenderWindow"/> that sent the event.</param> - /// <param name="eventArgs">The <see cref="KeyEventArgs"/> about the key press.</param> + /// <param name="sender">The <see cref="Window"/> that sent the event.</param> + /// <param name="eventArgs">The <see cref="KeyEventArgs"/> associated with the key press.</param> private static void HandleKeyPressed(object sender, KeyEventArgs eventArgs) { switch (eventArgs.Code) { case Keyboard.Key.Space: - UpdateBodiesBruteForce(_bodies, Constants.TimeStep); + bodyPositionUpdater(bodies, Constants.TimeStep); break; case Keyboard.Key.G: - GenerateBodies(10, true); + (bodies, bodyShapeMap) = BodyGenerator.GenerateBodies(Constants.BodyCount, true); break; default: @@ -117,62 +85,72 @@ namespace StarSim } } - private static void Main(string[] args) + /// <summary> + /// Handles motions of the mouse. + /// </summary> + /// <param name="sender">The <see cref="Window"/> that sent the event.</param> + /// <param name="eventArgs">The <see cref="MouseMoveEventArgs"/> associated with the key press.</param> + private static void HandleMouseMoved(object sender, MouseMoveEventArgs eventArgs) { - Console.WriteLine("Hello World!"); + } - GenerateBodies(Constants.BodyCount, true); + /// <summary> + /// Handles key presses of the mouse. + /// </summary> + /// <param name="sender">The <see cref="Window"/> that sent the event.</param> + /// <param name="eventArgs">The <see cref="MouseButtonEventArgs"/> associated with the key press.</param> + private static void HandleMousePressed(object sender, MouseButtonEventArgs eventArgs) + { + } + + /// <summary> + /// Handles key releases of the mouse. + /// </summary> + /// <param name="sender">The <see cref="Window"/> that sent the event.</param> + /// <param name="eventArgs">The <see cref="MouseButtonEventArgs"/> associated with the key press.</param> + private static void HandleMouseReleased(object sender, MouseButtonEventArgs eventArgs) + { + } + /// <summary> + /// Entry point for our application. + /// </summary> + /// <param name="args">Any command line arguments passed to the program.</param> + private static void Main(string[] args) + { + Console.WriteLine("Hello World!"); Console.WriteLine("Press 'enter' to continue..."); Console.ReadLine(); - RenderWindow window = new RenderWindow(VideoMode.DesktopMode, "N-Body Simulator", Styles.Default); + // we reveal the window so that the user may interact with our program + window.SetVisible(true); + + // we configure the window and its close handler, so that we may close the window once we are done with it window.SetFramerateLimit(Constants.FrameRate); window.Closed += (sender, eventArgs) => ((RenderWindow)sender).Close(); - window.KeyPressed += HandleKeyPressed; - // caches the delta between the screen origin (top left corner) and the world origin, - // which should be the centre of the screen - uint wx = window.Size.X, wy = window.Size.Y; - uint dx = wx / 2, dy = wy / 2; - Vector2u originOffset = new Vector2u(dx, dy); + // we apply event handlers to allow for interactivity inside the window + window.KeyPressed += HandleKeyPressed; + window.MouseButtonPressed += HandleMousePressed; + window.MouseButtonReleased += HandleMouseReleased; + window.MouseMoved += HandleMouseMoved; - DrawBodies(_bodies, window, originOffset); + bodyDrawer.DrawBodies(); while (window.IsOpen) { window.Clear(); window.DispatchEvents(); - bodyPositionUpdater(_bodies, Constants.TimeStep); - DrawBodies(_bodies, window, originOffset); + bodyPositionUpdater(bodies, Constants.TimeStep); + bodyDrawer.DrawBodies(); window.Display(); } - } - /// <summary> - /// Updates the positions of all the given <see cref="Body"/>s with O(n^2) time complexity, with the given time step. - /// </summary> - /// <param name="bodies">The collection of <see cref="Body"/>s whose positions to update.</param> - /// <param name="deltaTime">The time step.</param> - private static void UpdateBodiesBruteForce(IEnumerable<Body> bodies, double deltaTime) - { - IEnumerable<Body> bodyEnumerable = bodies as Body[] ?? bodies.ToArray(); - Vector3d forceVector = new Vector3d(); - - foreach (Body body in bodyEnumerable) - { - // resets the force vector to avoid another instantiation and allocation - forceVector.X = 0; - forceVector.Y = 0; - forceVector.Z = 0; - - // use LINQ expression as it is more concise; sum attraction vectors for all other bodies - forceVector = bodyEnumerable.Where(b => b != body).Aggregate(forceVector, (current, b) => current + Body.GetForceBetween(body, b)); - - body.Update(forceVector, deltaTime); - } + Console.WriteLine("Goodbye World!"); + Console.WriteLine("Press 'enter' to quit..."); + Console.ReadLine(); } } } \ No newline at end of file diff --git a/StarSim/StarSimLib/Graphics/Drawer.cs b/StarSim/StarSimLib/Graphics/Drawer.cs @@ -1,9 +1,75 @@ -namespace StarSimLib.Graphics +using System.Collections.Generic; +using SFML.Graphics; +using SFML.System; +using StarSimLib.Physics; + +namespace StarSimLib.Graphics { /// <summary> /// Represents a drawer capable of rendering bodies to a screen. /// </summary> public class Drawer { + /// <summary> + /// Holds all the <see cref="Body"/> instances that should be simulated. + /// </summary> + private readonly Body[] managedBodies; + + /// <summary> + /// Maps a <see cref="Body"/> to the <see cref="CircleShape"/> that represents it, and is drawn to the + /// screen at the <see cref="Body"/>s position. + /// </summary> + private readonly Dictionary<Body, CircleShape> managedBodyShapeMap; + + /// <summary> + /// The offset that has to be applied to the positions of a <see cref="CircleShape"/>, so that they appear + /// to be in the centre of the render target and not the top left corner. + /// </summary> + private readonly Vector2u originOffset; + + /// <summary> + /// The target to which the managed bodies will be drawn. + /// </summary> + private readonly RenderTarget renderTarget; + + /// <summary> + /// Initialises a new instance of the <see cref="Drawer"/> class. + /// </summary> + /// <param name="target">The target to which the managed bodies should be rendered.</param> + /// <param name="bodies">The <see cref="Body"/> instances which should be managed by this instance.</param> + /// <param name="bodyShapeMap"> + /// Maps a <see cref="Body"/> instance to the <see cref="CircleShape"/> that represents it, and is drawn to the + /// screen at the <see cref="Body"/> instances position. + /// </param> + public Drawer(RenderTarget target, ref Body[] bodies, ref Dictionary<Body, CircleShape> bodyShapeMap) + { + renderTarget = target; + originOffset = target.Size / 2; + + managedBodies = bodies; + + managedBodyShapeMap = bodyShapeMap; + } + + /// <summary> + /// Draws each <see cref="Body"/> instance that is managed by this drawer to the <see cref="RenderTarget"/> specified + /// in the constructor. + /// </summary> + public void DrawBodies() + { + foreach (Body body in managedBodies) + { + // get the cached shape and projects the current bodies 3D position down to a 2D position, + // which is used as the new position of the shape. + CircleShape shape = managedBodyShapeMap[body]; + + shape.Position = new Vector2f( + (float)(body.Position.X * Constants.UniverseScalingFactor + originOffset.X), + (float)(body.Position.Y * Constants.UniverseScalingFactor + originOffset.Y) + ); + + shape.Draw(renderTarget, RenderStates.Default); + } + } } } \ No newline at end of file diff --git a/StarSim/StarSimLib/Physics/Body.cs b/StarSim/StarSimLib/Physics/Body.cs @@ -14,34 +14,34 @@ namespace StarSimLib.Physics "Body {0,2}.{1,-4}: Pos-{2}, Vel-{3} Mass-{4,3}"; /// <summary> - /// The generation that this body belongs to. + /// The backing field for the <see cref="Force"/> property. /// </summary> - public readonly uint Generation; + private Vector3d force; /// <summary> - /// The unique id for this body. + /// Backing field for the <see cref="Mass"/> property. /// </summary> - public readonly uint Id; + private double mass; /// <summary> - /// The backing field for the <see cref="Force"/> property. + /// Backing field for the <see cref="Position"/> property. /// </summary> - public Vector3d force; + private Vector3d position; /// <summary> - /// Backing field for the <see cref="Mass"/> property. + /// Backing field for the <see cref="Velocity"/> property. /// </summary> - public double mass; + private Vector3d velocity; /// <summary> - /// Backing field for the <see cref="Position"/> property. + /// The generation that this body belongs to. /// </summary> - public Vector3d position; + public readonly uint Generation; /// <summary> - /// Backing field for the <see cref="Velocity"/> property. + /// The unique id for this body. /// </summary> - public Vector3d velocity; + public readonly uint Id; /// <summary> /// Initialises a new instance of the <see cref="Body"/> class. @@ -134,6 +134,16 @@ namespace StarSimLib.Physics } /// <summary> + /// Collides this instance with the given <see cref="Body"/> instance. + /// </summary> + /// <param name="otherBody">The other instance with which to collide.</param> + public void Collide(Body otherBody) + { + mass += otherBody.Mass; + velocity += otherBody.Velocity; + } + + /// <summary> /// Finds and returns the distance between the current <see cref="Body"/> instance and the given <see cref="Body"/>. /// In other words, it finds the magnitude of the translation vector between the two <see cref="Body"/> instances. /// </summary> diff --git a/StarSim/StarSimLib/Physics/BodyGenerator.cs b/StarSim/StarSimLib/Physics/BodyGenerator.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using SFML.Graphics; + +namespace StarSimLib.Physics +{ + /// <summary> + /// Provides methods for generating <see cref="Body"/> instances. + /// </summary> + public static class BodyGenerator + { + /// <summary> + /// Caches a random number generator to use for all randomised positions and velocities. + /// </summary> + private static readonly Random Rng = new Random(); + + /// <summary> + /// The current generation of <see cref="Body"/> instances that the generator is on. + /// </summary> + public static uint CurrentGeneration { get; private set; } + + /// <summary> + /// Generates an array of <see cref="Body"/> instances, and generates <see cref="CircleShape"/> instances for + /// each generated body. Returns the generated array and dictionary as a tuple. + /// </summary> + /// <param name="bodyCount">The number of <see cref="Body"/> instances to generate.</param> + /// <param name="centralAttractor">Whether to have a central massive attractor.</param> + /// <returns>The generated <see cref="Body"/> array, and <see cref="Body"/> to <see cref="CircleShape"/> map.</returns> + public static (Body[] generatedBodies, Dictionary<Body, CircleShape> bodyCircleShapeMap) GenerateBodies(int bodyCount = 2, bool centralAttractor = false) + { + CurrentGeneration++; + + uint id = 0; + Body[] generatedBodies = new Body[bodyCount]; + Dictionary<Body, CircleShape> bodyCircleShapeMap = new Dictionary<Body, CircleShape>(); + + for (int i = 0; i < generatedBodies.Length; i++) + { + float mass = (float)(Rng.NextDouble() * Constants.SolarMass); + + Vector3d position = OrbitGenerator.RandomPosition(); + Vector3d velocity = OrbitGenerator.RandomOrbit(position); + + generatedBodies[i] = new Body(position, velocity, mass, CurrentGeneration, id); + bodyCircleShapeMap.Add(generatedBodies[i], new CircleShape(1) { FillColor = Color.White }); + + id++; + } + + if (centralAttractor && bodyCount >= 2) + { + bodyCircleShapeMap.Remove(generatedBodies[0]); + generatedBodies[0] = new Body(new Vector3d(), new Vector3d(), Constants.CentralBodyMass, CurrentGeneration, 0); + bodyCircleShapeMap.Add(generatedBodies[0], new CircleShape(4) { FillColor = Color.Red }); + } + + return (generatedBodies, bodyCircleShapeMap); + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimLib/Physics/BodyUpdater.cs b/StarSim/StarSimLib/Physics/BodyUpdater.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; +using System.Linq; + +namespace StarSimLib.Physics +{ + /// <summary> + /// Updates the given <see cref="Body"/> collections individual bodies, using the given delta time. + /// </summary> + /// <param name="bodies">The body collection.</param> + /// <param name="deltaTime">The time step.</param> + public delegate void UpdateDelegate(IEnumerable<Body> bodies, double deltaTime); + + /// <summary> + /// Provides methods for updating <see cref="Body"/> instance positions. + /// </summary> + public static class BodyUpdater + { + /// <summary> + /// Updates the positions of all the given <see cref="Body"/>s with O(n^2) time complexity, with the given time step. + /// </summary> + /// <param name="bodies">The collection of <see cref="Body"/>s whose positions to update.</param> + /// <param name="deltaTime">The time step.</param> + public static void UpdateBodiesBruteForce(IEnumerable<Body> bodies, double deltaTime) + { + IEnumerable<Body> bodyEnumerable = bodies as Body[] ?? bodies.ToArray(); + Vector3d forceVector = new Vector3d(); + + foreach (Body body in bodyEnumerable) + { + // resets the force vector to avoid another instantiation and allocation + forceVector.X = 0; + forceVector.Y = 0; + forceVector.Z = 0; + + // use LINQ expression as it is more concise; sum attraction vectors for all other bodies + forceVector = bodyEnumerable.Where(b => b != body).Aggregate(forceVector, (current, b) => current + Body.GetForceBetween(body, b)); + + body.Update(forceVector, deltaTime); + } + } + } +} +\ No newline at end of file diff --git a/StarSim/StarSimLib/Physics/OrbitGenerator.cs b/StarSim/StarSimLib/Physics/OrbitGenerator.cs @@ -3,7 +3,7 @@ namespace StarSimLib.Physics { /// <summary> - /// Initialises positions, velocities, and orbits for bodies. + /// Provides methods for initialising positions, velocities, and orbits for <see cref="Body"/> instances. /// </summary> public static class OrbitGenerator { diff --git a/StarSim/StarSimLib/StarSimLib.xml b/StarSim/StarSimLib/StarSimLib.xml @@ -108,24 +108,53 @@ Represents a drawer capable of rendering bodies to a screen. </summary> </member> - <member name="T:StarSimLib.Physics.Body"> + <member name="F:StarSimLib.Graphics.Drawer.managedBodies"> <summary> - Represents a stellar body. + Holds all the <see cref="T:StarSimLib.Physics.Body"/> instances that should be simulated. </summary> </member> - <member name="F:StarSimLib.Physics.Body.BodyFormatString"> + <member name="F:StarSimLib.Graphics.Drawer.managedBodyShapeMap"> <summary> - Describes how the <see cref="T:StarSimLib.Physics.Body"/> instance should be formatted as a <see cref="T:System.String"/>. + Maps a <see cref="T:StarSimLib.Physics.Body"/> to the <see cref="T:SFML.Graphics.CircleShape"/> that represents it, and is drawn to the + screen at the <see cref="T:StarSimLib.Physics.Body"/>s position. </summary> </member> - <member name="F:StarSimLib.Physics.Body.Generation"> + <member name="F:StarSimLib.Graphics.Drawer.originOffset"> <summary> - The generation that this body belongs to. + The offset that has to be applied to the positions of a <see cref="T:SFML.Graphics.CircleShape"/>, so that they appear + to be in the centre of the render target and not the top left corner. </summary> </member> - <member name="F:StarSimLib.Physics.Body.Id"> + <member name="F:StarSimLib.Graphics.Drawer.renderTarget"> <summary> - The unique id for this body. + The target to which the managed bodies will be drawn. + </summary> + </member> + <member name="M:StarSimLib.Graphics.Drawer.#ctor(SFML.Graphics.RenderTarget,StarSimLib.Physics.Body[]@,System.Collections.Generic.Dictionary{StarSimLib.Physics.Body,SFML.Graphics.CircleShape}@)"> + <summary> + Initialises a new instance of the <see cref="T:StarSimLib.Graphics.Drawer"/> class. + </summary> + <param name="target">The target to which the managed bodies should be rendered.</param> + <param name="bodies">The <see cref="T:StarSimLib.Physics.Body"/> instances which should be managed by this instance.</param> + <param name="bodyShapeMap"> + Maps a <see cref="T:StarSimLib.Physics.Body"/> instance to the <see cref="T:SFML.Graphics.CircleShape"/> that represents it, and is drawn to the + screen at the <see cref="T:StarSimLib.Physics.Body"/> instances position. + </param> + </member> + <member name="M:StarSimLib.Graphics.Drawer.DrawBodies"> + <summary> + Draws each <see cref="T:StarSimLib.Physics.Body"/> instance that is managed by this drawer to the <see cref="T:SFML.Graphics.RenderTarget"/> specified + in the constructor. + </summary> + </member> + <member name="T:StarSimLib.Physics.Body"> + <summary> + Represents a stellar body. + </summary> + </member> + <member name="F:StarSimLib.Physics.Body.BodyFormatString"> + <summary> + Describes how the <see cref="T:StarSimLib.Physics.Body"/> instance should be formatted as a <see cref="T:System.String"/>. </summary> </member> <member name="F:StarSimLib.Physics.Body.force"> @@ -148,6 +177,16 @@ Backing field for the <see cref="P:StarSimLib.Physics.Body.Velocity"/> property. </summary> </member> + <member name="F:StarSimLib.Physics.Body.Generation"> + <summary> + The generation that this body belongs to. + </summary> + </member> + <member name="F:StarSimLib.Physics.Body.Id"> + <summary> + The unique id for this body. + </summary> + </member> <member name="M:StarSimLib.Physics.Body.#ctor(StarSimLib.Vector3d,StarSimLib.Vector3d,System.Double,System.UInt32,System.UInt32)"> <summary> Initialises a new instance of the <see cref="T:StarSimLib.Physics.Body"/> class. @@ -193,6 +232,12 @@ </summary> <param name="otherBody">The other body to calculate the force between.</param> </member> + <member name="M:StarSimLib.Physics.Body.Collide(StarSimLib.Physics.Body)"> + <summary> + Collides this instance with the given <see cref="T:StarSimLib.Physics.Body"/> instance. + </summary> + <param name="otherBody">The other instance with which to collide.</param> + </member> <member name="M:StarSimLib.Physics.Body.DistanceTo(StarSimLib.Physics.Body,StarSimLib.Vector3d@)"> <summary> Finds and returns the distance between the current <see cref="T:StarSimLib.Physics.Body"/> instance and the given <see cref="T:StarSimLib.Physics.Body"/>. @@ -223,9 +268,52 @@ <member name="M:StarSimLib.Physics.Body.ToString"> <inheritdoc /> </member> + <member name="T:StarSimLib.Physics.BodyGenerator"> + <summary> + Provides methods for generating <see cref="T:StarSimLib.Physics.Body"/> instances. + </summary> + </member> + <member name="F:StarSimLib.Physics.BodyGenerator.Rng"> + <summary> + Caches a random number generator to use for all randomised positions and velocities. + </summary> + </member> + <member name="P:StarSimLib.Physics.BodyGenerator.CurrentGeneration"> + <summary> + The current generation of <see cref="T:StarSimLib.Physics.Body"/> instances that the generator is on. + </summary> + </member> + <member name="M:StarSimLib.Physics.BodyGenerator.GenerateBodies(System.Int32,System.Boolean)"> + <summary> + Generates an array of <see cref="T:StarSimLib.Physics.Body"/> instances, and generates <see cref="T:SFML.Graphics.CircleShape"/> instances for + each generated body. Returns the generated array and dictionary as a tuple. + </summary> + <param name="bodyCount">The number of <see cref="T:StarSimLib.Physics.Body"/> instances to generate.</param> + <param name="centralAttractor">Whether to have a central massive attractor.</param> + <returns>The generated <see cref="T:StarSimLib.Physics.Body"/> array, and <see cref="T:StarSimLib.Physics.Body"/> to <see cref="T:SFML.Graphics.CircleShape"/> map.</returns> + </member> + <member name="T:StarSimLib.Physics.UpdateDelegate"> + <summary> + Updates the given <see cref="T:StarSimLib.Physics.Body"/> collections individual bodies, using the given delta time. + </summary> + <param name="bodies">The body collection.</param> + <param name="deltaTime">The time step.</param> + </member> + <member name="T:StarSimLib.Physics.BodyUpdater"> + <summary> + Provides methods for updating <see cref="T:StarSimLib.Physics.Body"/> instance positions. + </summary> + </member> + <member name="M:StarSimLib.Physics.BodyUpdater.UpdateBodiesBruteForce(System.Collections.Generic.IEnumerable{StarSimLib.Physics.Body},System.Double)"> + <summary> + Updates the positions of all the given <see cref="T:StarSimLib.Physics.Body"/>s with O(n^2) time complexity, with the given time step. + </summary> + <param name="bodies">The collection of <see cref="T:StarSimLib.Physics.Body"/>s whose positions to update.</param> + <param name="deltaTime">The time step.</param> + </member> <member name="T:StarSimLib.Physics.OrbitGenerator"> <summary> - Initialises positions, velocities, and orbits for bodies. + Provides methods for initialising positions, velocities, and orbits for <see cref="T:StarSimLib.Physics.Body"/> instances. </summary> </member> <member name="F:StarSimLib.Physics.OrbitGenerator.Rng"> @@ -246,13 +334,6 @@ </summary> <returns>A 3D position vector.</returns> </member> - <member name="T:StarSimLib.UpdateDelegate"> - <summary> - Updates the given <see cref="T:StarSimLib.Physics.Body"/> collections individual bodies, using the given delta time. - </summary> - <param name="bodies">The body collection.</param> - <param name="deltaTime">The time step.</param> - </member> <member name="T:StarSimLib.Vector3d"> <summary> A 3D vector with <see cref="T:System.Double"/> components. diff --git a/StarSim/StarSimLib/UpdateDelegate.cs b/StarSim/StarSimLib/UpdateDelegate.cs @@ -1,12 +0,0 @@ -using System.Collections.Generic; -using StarSimLib.Physics; - -namespace StarSimLib -{ - /// <summary> - /// Updates the given <see cref="Body"/> collections individual bodies, using the given delta time. - /// </summary> - /// <param name="bodies">The body collection.</param> - /// <param name="deltaTime">The time step.</param> - public delegate void UpdateDelegate(IEnumerable<Body> bodies, double deltaTime); -} -\ No newline at end of file