/// <summary> /// Initialises a new instance of the <see cref="SimulationScreen"/> class. /// </summary> /// <param name="renderWindow">The render window to which to display this instance.</param> /// <param name="inputHandler">The input handler for this instance.</param> /// <param name="bodies">The bodies managed by this instance.</param> /// <param name="bodyShapeMap">The shapes for the bodies managed by this instance.</param> /// <param name="bodyPositionUpdater">The body position update delegate for this instance.</param> public SimulationScreen(RenderWindow renderWindow, IInputHandler inputHandler, ref Body[] bodies, ref Dictionary <Body, CircleShape> bodyShapeMap, UpdateDelegate bodyPositionUpdater) : base(renderWindow, inputHandler) { this.bodies = bodies; this.bodyShapeMap = bodyShapeMap; this.bodyPositionUpdater = bodyPositionUpdater; simulationDrawer = new SimulationDrawer(renderWindow, ref this.bodies, ref this.bodyShapeMap); simulationInputHandler = (SimulationInputHandler)inputHandler; simulationInputHandler.SetSimulationDrawer(simulationDrawer); // constructs a new timer and attaches a timer event handler that updates the fps and window title every interval miscTimer = new Timer(TimerRefreshIntervalMs) { AutoReset = true, Enabled = true }; miscTimer.Elapsed += (sender, args) => { fps = framesElapsed / (TimerRefreshIntervalMs / 1000); framesElapsed = 0; renderWindow.SetTitle($"N-Body Simulator: FPS {fps}"); }; fileWriter = CreateFileWriter(); }
/// <summary> /// Sets the simulation drawer. /// </summary> /// <param name="drawer"></param> public void SetSimulationDrawer(SimulationDrawer drawer) { simulationDrawer = drawer; }