コード例 #1
0
        public static void SendAction(GameAction action)
        {
            byte[] buffer = action.ToBytes();
            NetworkTransport.Send(hostId, connectionId, channelActionId, buffer, buffer.Length, out error);

            if (error != (byte)NetworkError.Ok) {
                Debug.LogError("[ERROR] NetworkAPI :: SendAction :: Send : " + error);
            }
        }
コード例 #2
0
 // TODO check if the last action is of the same type,
 // if true, override the previous with it, else, enqueue it
 void OnDemand(GameAction ga)
 {
     actionQueue.Enqueue(ga);
 }
コード例 #3
0
        void Start()
        {
            enabled = false;

            accumulatedTime = 0;
            gameFrame = 0;
            lockstepTurn = 0;

            actionQueue = new Queue<GameAction>();

            actions = new GameAction[3][];
            for (int i = 0; i < actions.Length; ++i) {
                actions[i] = new GameAction[numberOfPlayers]; // allready set to null
            }

            numberOfPlayerWhoSendAction = new uint[3]; // allready set to 0

            playerHaveConfirmedMyAction = new bool[3][];
            for (int i = 0; i < playerHaveConfirmedMyAction.Length; ++i) {
                playerHaveConfirmedMyAction[i] = new bool[numberOfPlayers]; // allready set to false
            }

            numberOfPlayerWhoConfirmedMyAction = new uint[3]; // allready set to 0

            wait = new uint[3][];
            for (int i = 0; i < wait.Length; ++i) {
                wait[i] = new uint[numberOfPlayers]; // allready set to false
            }
        }
コード例 #4
0
        void OnAction(int playerID, GameAction action)
        {
            if (action.LockstepTurn > lockstepTurn) {
                uint turn = action.LockstepTurn - lockstepTurn;

                NetworkUI.Log("Receive action from player " + playerID + " for turn " + turn);

                if (turn <= 2 && actions[turn][playerID] == null) {
                    actions[turn][playerID] = action;
                    ++numberOfPlayerWhoSendAction[turn];
                }
            }

            // Send wait message for stop overloaded network
            bool wait = action.LockstepTurn > lockstepTurn + 2;

            NetworkAPI.SendConfirmation(new GameConfirmation(action.LockstepTurn, wait));
        }