示例#1
0
 /// <summary>
 /// Internal step-Method to calculate the next step
 /// </summary>
 private void step()
 {
     lastHostState = new SimulatorHostState();
     try
     {
         environment.Step(lastSimulationState);
         lastSimulationState.TotalRounds = (ushort)configuration.RoundCount;
     }
     catch (Exception ex)
     {
         exception = ex;
     }
 }
示例#2
0
        /// <summary>
        /// Executes one single step in simulation and returns hostState.
        /// </summary>
        /// <param name="simulationState">The prefilled simulationState to put the currrent simulation-Snapshot in.</param>
        /// <returns>Summery of the executed simulationStep.</returns>
        public SimulatorHostState Step(ref SimulationState simulationState)
        {
            // check, of proxy is still usable
            if (host == null)
            {
                throw new InvalidOperationException(Resource.SimulationCoreProxyUnloaded);
            }

            // execute step inside the appdomain via host
            SimulatorHostState state = host.Step(ref simulationState);

            // in case of an exception
            if (state == null)
            {
                throw host.Exception;
            }

            // return success
            return(state);
        }
示例#3
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;
        }