public IEnumerator <ITask> CompetitionTypeChangedHandler(CompetitionTypeChanged announce) { // Notify all subscribers. base.SendNotification(_submgrPort, announce); announce.ResponsePort.Post(DefaultUpdateResponseType.Instance); yield break; }
void OnServerUiMessageHandler(FromServerUiMsg msg) { switch (msg.Msg) { // 比赛类型改变事件 case FromServerUiMsg.MsgEnum.COMPETITION_ITEM_CHANGED: // 以比赛类型名称为参数初始化具体使命 InitMission(msg.Parameters[0], Convert.ToInt32(msg.Parameters[1])); // 新建比赛类型改变事件消息将比赛类型名称作为消息体 CompetitionTypeChanged announce = new CompetitionTypeChanged(); announce.Body = new CompetitionTypeChangedRequest(msg.Parameters[0], MyMission.Instance().TeamsRef.Count); // 给Server主端口发送比赛类型改变消息以启动CompetitionTypeChangedHandler向所有订阅者发送通知 _mainPort.Post(announce); //// 以比赛类型名称为参数初始化具体使命 //InitMission(msg.Parameters[0], Convert.ToInt32(msg.Parameters[1])); break; // 比赛开始事件 case FromServerUiMsg.MsgEnum.START: MyMission.Instance().ParasRef.IsRunning = true; //TaskQueue.EnqueueTimer(TimeSpan.FromMilliseconds(MyMission.Instance().ParasRef.MsPerCycle), _portSimLoop); //_receiver = Arbiter.Receive(true, TimeoutPort(MyMission.Instance().ParasRef.MsPerCycle), SimulationLoop); //_receiver = Arbiter.Receive(true, _portSimLoop, SimulationLoop); //Activate(_receiver); SimulationLoop(DateTime.Now); break; // 比赛暂停事件 case FromServerUiMsg.MsgEnum.PAUSE: //MyMission.Instance().ParasRef.IsRunning = !MyMission.Instance().ParasRef.IsRunning; MyMission.Instance().ParasRef.IsPaused = !MyMission.Instance().ParasRef.IsPaused; //if (MyMission.Instance().ParasRef.IsRunning == true) if (MyMission.Instance().ParasRef.IsPaused == false) { //TaskQueue.EnqueueTimer(TimeSpan.FromMilliseconds(MyMission.Instance().ParasRef.MsPerCycle), _portSimLoop); //_receiver = Arbiter.Receive(true, TimeoutPort(MyMission.Instance().ParasRef.MsPerCycle), SimulationLoop); //_receiver = Arbiter.Receive(true, _portSimLoop, SimulationLoop); //Activate(_receiver); SimulationLoop(DateTime.Now); // 按下“Continue”继续启动仿真循环 } else { //_receiver.Cleanup(); //_receiver = null; //Activate(Arbiter.Receive(false, TimeoutPort(MyMission.Instance().ParasRef.MsPerCycle), SimulationLoop)); } break; // 比赛回放事件 case FromServerUiMsg.MsgEnum.REPLAY: Activate(Arbiter.Receive(false, TimeoutPort(MyMission.Instance().ParasRef.MsPerCycle), Replay)); break; case FromServerUiMsg.MsgEnum.CLOSED: _mainPort.Post(new DsspDefaultDrop()); break; case FromServerUiMsg.MsgEnum.RESTART: InitMission(MyMission.Instance().ParasRef.Name, MyMission.Instance().ParasRef.TotalSeconds / 60); break; } // 开始/暂停/重启事件通知给客户端 if (msg.Msg == FromServerUiMsg.MsgEnum.START || msg.Msg == FromServerUiMsg.MsgEnum.RESTART || msg.Msg == FromServerUiMsg.MsgEnum.PAUSE) { CompetitionControlButton announceCompetitionControlButton = new CompetitionControlButton(); announceCompetitionControlButton.Body = new CompetitionControlButtonRequest(msg.Parameters[0]); _mainPort.Post(announceCompetitionControlButton); } }// end OnServerUiMessageHandler...