Ejemplo n.º 1
0
 /// <summary>
 /// Unloads simulator.
 /// </summary>
 public void Unload()
 {
     if (proxy != null)
     {
         proxy.Unload();
         proxy = null;
         GC.Collect();
     }
     state = SimulatorState.Finished;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates the next step and deliver through parameter.
        /// </summary>
        /// <param name="simulationState">empty <see cref="SimulationState"/></param>
        public void Step(ref SimulationState simulationState)
        {
            lastSimulationState = simulationState;
            switch (state)
            {
            case SimulatorState.Ready:
            case SimulatorState.Simulating:

                // Create proxy
                if (proxy == null)
                {
                    proxy = new SimulatorProxy();
                    proxy.Init(configuration);
                    currentLoop++;
                    currentRound = 0;
                    loopTime     = 0;
                    for (int i = 0; i < configuration.Teams.Count; i++)
                    {
                        for (int j = 0; j < configuration.Teams[i].Player.Count; j++)
                        {
                            totalPlayerTime[configuration.Teams[i].Player[j].Guid] = 0;
                        }
                    }
                    state = SimulatorState.Simulating;
                }

                // Calculate step
                currentRound++;
                lastHostState   = proxy.Step(ref lastSimulationState);
                simulationState = lastSimulationState;

                // Calculate times
                roundTime  = lastHostState.ElapsedRoundTime;
                loopTime  += lastHostState.ElapsedRoundTime;
                totalTime += lastHostState.ElapsedRoundTime;
                for (int i = 0; i < configuration.Teams.Count; i++)
                {
                    for (int j = 0; j < configuration.Teams[i].Player.Count; j++)
                    {
                        // TODO: Fix Dictionary-Problem with time-list
                        Guid guid = configuration.Teams[i].Player[j].Guid;
                        totalPlayerTime[guid] += lastHostState.ElapsedPlayerTimes[guid];
                    }
                }

                // After one loop, unload appdomain
                if (currentRound >= configuration.RoundCount)
                {
                    proxy.Unload();
                    proxy = null;
                    GC.Collect();
                }

                // Mark Simulator as finished after all loops
                if (currentRound >= configuration.RoundCount &&
                    currentLoop >= configuration.LoopCount)
                {
                    state = SimulatorState.Finished;
                }
                break;

            case SimulatorState.Finished:

                // Throw exception, if step was called on a finished simulator
                throw new InvalidOperationException(
                          Resource.SimulationCoreSimulatorRestartFailed);
            }
            lastSimulationState = null;
        }