public SimulationTabContent(Stream statsOut, string entityDefinitionPath, SimulationSettings settings) { InitializeComponent(); var definitionDatabase = LocalStorage.GetDefinitionDatabase(entityDefinitionPath); var newSim = new Simulation(settings, definitionDatabase); if (!(statsOut is null)) { // Set up statistics gathering StatisticsGatherer gatherer = new StatisticsGatherer(); newSim.WeaponSystem.OnAttack += gatherer.HandleInfo; newSim.ReproductionSystem.BirthEvent += gatherer.HandleInfo; newSim.HealthDeathSystem.OnDeath += gatherer.HandleInfo; newSim.OldAgeDeathSystem.OnDeath += gatherer.HandleInfo; newSim.EnergyDeathSystem.OnDeath += gatherer.HandleInfo; newSim.CritterPositionReporter.OnReport += gatherer.HandleInfo; newSim.FoodPositionReporter.OnReport += gatherer.HandleInfo; newSim.VisibleColourInfoReporter.OnReport += gatherer.HandleInfo; // Set a stats logger to run until closed. FileStatLogger logger = new FileStatLogger(gatherer, statsOut); _statLoggingThread = new Thread(() => logger.LogStats()); _statLoggingThread.Start(); } // Subscribe to the events for the UI. //newSim.WeaponSystem.OnAttack += postSimulationEvent; newSim.ReproductionSystem.BirthEvent += postSimulationEvent; newSim.HealthDeathSystem.OnDeath += postSimulationEvent; newSim.EnergyDeathSystem.OnDeath += postSimulationEvent; newSim.OldAgeDeathSystem.OnDeath += postSimulationEvent; soupGraphicsControl.CurrentSimulation = newSim; soupGraphicsControl.GraphicsInitialized += () => { soupGraphicsControl.CurrentSimulation.InitGraphics(soupGraphicsControl.GraphicsDevice, soupGraphicsControl.Editor.Content); soupGraphicsControl.CurrentSimulation.SetUp(); }; eventView.View = View.Details; eventView.GridLines = true; }
public FileStatLogger(StatisticsGatherer gatherer, Stream outputStream) { _gatherer = gatherer; _outputStream = outputStream; }