Exemplo n.º 1
0
 private void SendMyPaddlePosition()
 {
     while (this.shouldSyncData)
     {
         MailBox.Send(new MessageEnvelope(this.followerPaddlePosition, this.enemyPlayerId));
         Thread.Sleep(MessageSendFrequency);
     }
 }
Exemplo n.º 2
0
 private void SyncGameState()
 {
     while (this.shouldSyncData)
     {
         this.state.CurrentTime = GetUnixTimestamp();
         MailBox.Send(new MessageEnvelope(this.state, this.enemyPlayerId));
         Thread.Sleep(MessageSendFrequency);
     }
 }
        void CreateThreadToCheckData()
        {
            int sum = 0;

            async void Receive()
            {
                while (data.Live)
                {
                    if (await mailBox.DOReceive())
                    {
                        //switch (data.messagetype)
                        //{
                        //    case Messagetype.carinfomessage: ChangeCarMessage(); break;
                        //    case Messagetype.volumepackage: ChangeCarMessage(); break;
                        //    case Messagetype.package: ChangeCarMessage(); break;
                        //}
                    }
                    else
                    {
                        Thread.Sleep(100); sum++;
                    }
                }
            }

            Receive();
            while (data.Live)
            {
                if (!data.Live)
                {
                    centerManager.iplist[DeviceID].ID = null;
                }

                if (sum == 100)
                {
                    mailBox.Send(CenterNet.CreateOrderString("monitor")); sum = 0;
                }
                if (order.TryDequeue(out Order))
                {
                    Send(Order);
                }
            }
        }
Exemplo n.º 4
0
        private void SyncGameState()
        {
            while (this.shouldSyncData)
            {
                this.state.CurrentTime = GetTimestamp();

                if (this.state.CurrentTime - this.lastSentMessageTimestamp > MessageSendFrequency)
                {
                    this.state.All = false;
                    MailBox.Send(new MessageEnvelope(this.state, this.enemyPlayerId));
                    this.state.All = true;
                    this.lastSentMessageTimestamp = this.state.CurrentTime;
                }
            }
        }
Exemplo n.º 5
0
 private void Challenge(long player)
 {
     if (this.multiplayerConnectionState.CouldTransitionTo(MultiplayerConnectionState.AwaitingChallengeRequestReponse))
     {
         ModEntry.Instance.Monitor.Log("SENT CHALLENGE", LogLevel.Error);
         this.currentChallengeRequestRecipient = player;
         MailBox.Send(new MessageEnvelope(new ChallengeRequestMessage(), player));
         this.multiplayerConnectionState.TransitionTo(MultiplayerConnectionState.AwaitingChallengeRequestReponse);
     }
     else if (this.multiplayerConnectionState.State == MultiplayerConnectionState.ReceivedChallengeRequest &&
              player == this.currentChallengeRequestRecipient)
     {
         this.SendChallengeResponse(player, true);
         this.MoveToGame(player);
     }
     //TODO: remove else if block after modals
 }
Exemplo n.º 6
0
 private void ForceSyncGameState()
 {
     this.state.CurrentTime = GetTimestamp();
     MailBox.Send(new MessageEnvelope(this.state, this.enemyPlayerId));
     this.lastSentMessageTimestamp = this.state.CurrentTime;
 }
Exemplo n.º 7
0
 private void SendChallengeResponse(long player, bool accepted, string reason = null)
 {
     MailBox.Send(new MessageEnvelope(new ChallengeRequestResponseMessage(accepted, reason), player));
 }
Exemplo n.º 8
0
    public void run()
    {
        int agentID = agentState.agentID;

        MailBox <PerceptRequest> perceptRequests = simulationState.perceptRequests; //To send percept requests to unity
        MailBox <Percept>        percepts        = agentState.percepts;             //To receive percepts from unity

        MailBox <Action>       actions = agentState.actions;                        //To send action request to unity
        MailBox <ActionResult> results = agentState.results;                        //To receive action result from unit

        Percept      percept;
        Action       action;
        ActionResult result;

        while (!quit)
        {
            Thread.Sleep(0);
            try {
                //Receive request: for perception or action.
                receiveRequest(out action);

                if (action == null)                     //Percept request received

                {
                    perceptRequests.Send(new PerceptRequest(agentID, percepts));        // send a percept request to unity

                    //simulationState.stdout.Send(String.Format("AC {0}: sending percept request.\n", name));

                    percepts.Recv(out percept);                                         // block until I receive percept from unity

                    //simulationState.stdout.Send(String.Format("AC {0}: percept ready, sending...\n", name));

                    sendPercept(percept);       // send percept to agent
                }
                else                            //Action request received
                //simulationState.stdout.Send(String.Format("AC {0}: action received.\n", name));

                {
                    if (action.type == ActionType.goodbye)                              // if the action is say goodbye, close the connection
                    {
                        sendResult(ActionResult.success);
                        quit = true;
                    }
                    else
                    {
                        //simulationState.stdout.Send(String.Format("AC {0}: sending action to handler...\n", name));
                        actions.Send(action);                                       // send action to handler
                        if (results.Recv(out result))                               // get action result from handler
                        //simulationState.stdout.Send(String.Format("AC {0}: action result received.\n", name));
                        //Thread.Sleep(action.duration);                          // sleep for the duration of the action.
                        //simulationState.stdout.Send(String.Format("AC {0}: sending action result to agent.\n", name));
                        {
                            sendResult(result);                                         // send action result to agent
                        }
                    }
                    //sendResult(ActionResult.success); //PETOR

                    //simulationState.stdout.Send(String.Format("AC {0}: perceive-act loop iteration complete.\n", name));
                }
            }
            catch (System.ObjectDisposedException) {
                quit = true;
            }
            catch (System.IO.IOException) {
                quit = true;
            }
        }
        //simulationState.stdout.Send(String.Format("AC {0}: quitting...\n", name));
        try {
            tcpClient.Close();

            //simulationState.stdout.Send(String.Format("AC {0}: Connection closed.\n", name));
        }
        catch (System.ObjectDisposedException) {
            //simulationState.stdout.Send(String.Format("AC {0}: Error while closing connection.\n", name));
        }
    }