コード例 #1
0
 public void Add(Simulation simulation)
 {
     Simulations.Add(simulation);
     simulation.OnCollision += simulation_OnCollision;
     simulation.OnCompleted += simulation_OnCompleted;
 }
コード例 #2
0
        private void generateDialog_Closed(object sender, EventArgs e)
        {
            var d = sender as GenerateSimulationDialog;

            if (d != null)
            {
                if (d.DialogResult.GetValueOrDefault())
                {
                    switch (d.RunIn)
                    {
                    case GenerateSimulationDialog.RunInEnum.Screen:
                        _simulation = RealtimeSimulation.GenerateSimulation(
                            d.StopWhenCompleted, d.TotalCycle,
                            drawingSurface.ActualWidth, drawingSurface.ActualHeight,
                            d.DummyCellCount, d.MaxVX, d.MaxVY, d.MaxRadius, d.MinRadius,
                            d.SmartCellCount, d.SMaxVX, d.SMaxVY, d.SMaxRadius, d.SMinRadius
                            );
                        _simulation.OnCollision   += _simulation_OnCollision;
                        _simulation.OnObjectAdded += _simulation_OnObjectAdded;
                        fillUniverseProperties(_simulation);
                        fillCellsProperties(_simulation);
                        break;

                    case GenerateSimulationDialog.RunInEnum.Memory:
                        var rSimulation = RealtimeSimulation.GenerateSimulation(
                            d.StopWhenCompleted, d.TotalCycle,
                            drawingSurface.ActualWidth, drawingSurface.ActualHeight,
                            d.DummyCellCount, d.MaxVX, d.MaxVY, d.MaxRadius, d.MinRadius,
                            d.SmartCellCount, d.SMaxVX, d.SMaxVY, d.SMaxRadius, d.SMinRadius
                            );
                        _memorySimulation              = new Simulation(rSimulation);
                        _memorySimulation.OnNextCycle += _memorySimulation_OnNextCycle;
                        _memorySimulation.OnCompleted += _memorySimulation_OnCompleted;
                        _memorySimulation.StartAsync();
                        enableButtons(false);
                        break;

                    case GenerateSimulationDialog.RunInEnum.MemoryBatch:
                        var simulationBatch = new SimulationBatch();
                        for (int i = 0; i < d.TotalBatch; i++)
                        {
                            var rSim = RealtimeSimulation.GenerateSimulation(
                                d.StopWhenCompleted, d.TotalCycle,
                                drawingSurface.ActualWidth, drawingSurface.ActualHeight,
                                d.DummyCellCount, d.MaxVX, d.MaxVY, d.MaxRadius, d.MinRadius,
                                d.SmartCellCount, d.SMaxVX, d.SMaxVY, d.SMaxRadius, d.SMinRadius
                                );
                            var sim = new Simulation(rSim);
                            simulationBatch.Add(sim);
                        }
                        var batchPlayer = new SimulationBatchPlayer(simulationBatch);
                        batchPlayer.Closed += batchPlayer_Closed;
                        batchPlayer.Show();
                        _simulationBatchPlayer = batchPlayer;
                        break;

                    case GenerateSimulationDialog.RunInEnum.Server:
                        break;

                    default:
                        break;
                    }
                }
            }
        }