Пример #1
0
        public void Update()
        {
            if (scenarioState == ScenarioState.LOADING)
            {
                if (simEngine.ErrorLoadingScenario())
                {
                    SendServerStateEvent("SCENARIO_LOAD_FAILURE", "Error Loading Scenario.");
                    this.ResetServer();
                    return;
                }
                if (simEngine.IsReady())
                {
                    scenarioState = ScenarioState.PAUSED;
                    isReady       = true;
                    SendServerStateEvent("SCENARIO_LOAD_SUCCESS", "");
                }
            }
            if (replayState == ScenarioState.LOADING)
            {
                if (simEngine.ErrorLoadingScenario())
                {
                    this.StopReplay();
                    SendServerStateEvent("REPLAY_LOAD_FAILURE", "Error Loading Replay.");
                    return;
                }
                if (simEngine.IsReady())
                {
                    replayState = ScenarioState.PAUSED;
                    //SendOutAvailablePlayers();
                    isReady = true;
                    SendServerStateEvent("REPLAY_LOAD_SUCCESS", "");
                }
            }
            currentTime = (simEngine.simCore.GetSimTime() / 1000);
            List <SimulationEvent> events = eventClient.GetEvents();

            if (events.Count > 0)
            {
                foreach (SimulationEvent e in events)
                {
                    switch (e.eventType)
                    {
                    case "PauseScenarioRequest":
                        if (scenarioState == ScenarioState.RUNNING)
                        {
                            SimControlPauseScenario();
                        }
                        break;

                    case "ResumeScenarioRequest":
                        if (scenarioState == ScenarioState.PAUSED)
                        {
                            SimControlPauseScenario();
                        }
                        break;

                    case "LoadScenarioRequest":
                        if (scenarioState == ScenarioState.STOPPED)
                        {
                            SimControlLoadScenario(((StringValue)e["ScenarioPath"]).value,
                                                   ((StringValue)e["GroupName"]).value,
                                                   ((StringValue)e["OutputLogDir"]).value);
                        }
                        break;

                    case "StopScenarioRequest":
                        if (scenarioState != ScenarioState.STOPPED)
                        {
                            SimControlStopScenario(false);
                        }
                        break;

                    case "SimCoreReady":
                        SendOutAvailablePlayers();
                        break;

                    case "GameSpeedRequest":
                        double speed = 1.0;
                        try
                        {
                            speed = ((DoubleValue)e["SpeedFactor"]).value;
                        }
                        catch (Exception ex)
                        {
                            continue;
                        }
                        this.SetReplaySpeed(speed);
                        break;

                    case "ForkReplayFinished":
                        HandshakeManager.IsForkReplay = false;
                        simEngine.SetGameSpeed(1);
                        if (scenarioState == ScenarioState.RUNNING)
                        {
                            SimControlPauseScenario();
                        }
                        break;

                    case "ForkReplayStarted":
                        HandshakeManager.IsForkReplay = true;
                        simEngine.SetGameSpeed(ServerOptions.ForkReplaySpeed);
                        break;
                    }
                }
            }
        }