Exemplo n.º 1
0
        InputAssignment AssignInput()
        {
            InputAssignment next = assignedInputs.GetNextAssignment();

            Debug.Assert(next != 0);
            assignedInputs |= next;
            return(next);
        }
Exemplo n.º 2
0
        InputAssignment AssignInput()
        {
            InputAssignment next = assignedInputs.GetNextAssignment();

            if (next == 0)
            {
                Log.Error("没有下一个InputAssign");
            }
            assignedInputs |= next;
            return(next);
        }
Exemplo n.º 3
0
        // TODO: To add support for multiple players per network peer, remove this (find-all-references to fix up the places it gets used)
        /// <returns>The first player assigned in a given assignment, or -1 if no players are assigned</returns>
        public static int GetFirstAssignedPlayerIndex(this InputAssignment ia)
        {
            for (var i = 0; i < MaxPlayerInputAssignments; i++)
            {
                if (((int)ia & (1 << i)) != 0)
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemplo n.º 4
0
        // There a bunch of bit-twiddling that could be done here, for some fun over-optimisation.

        public static InputAssignment GetNextAssignment(this InputAssignment ia)
        {
            for (var i = 0; i < MaxPlayerInputAssignments; i++)
            {
                if (((int)ia & (1 << i)) == 0)
                {
                    return((InputAssignment)(1 << i));
                }
            }

            return(0);
        }
Exemplo n.º 5
0
        /// <summary>Construct for host migration only!</summary>
        internal P2PServer(P2PNetwork owner, bool hostMigrationValidatedByServer, int maxConnectionId)
        {
            this.owner = owner;
            owner.Log("Becoming P2P Server (host migration)");


            hostMigrationTime    = NetTime.Now;
            clientDisconnections = new ClientDisconnections();

            if (hostMigrationValidatedByServer)
            {
                ValidateHostMigration();
            }


            owner.LocalPeerInfo.IsServer = true;


            // Recover information from application-connected peer list:
            var leavingPeers = new List <RemotePeer>();

            foreach (var remotePeer in owner.RemotePeers)
            {
                Debug.Assert(remotePeer.PeerInfo.IsApplicationConnected);
                Debug.Assert(remotePeer.PeerInfo.ConnectionId <= maxConnectionId);

                Debug.Assert(remotePeer.PeerInfo.InputAssignment != 0);
                Debug.Assert((assignedInputs & remotePeer.PeerInfo.InputAssignment) == 0);
                assignedInputs |= remotePeer.PeerInfo.InputAssignment;

                Debug.Assert(!(remotePeer.PeerInfo.IsServer &&
                               remotePeer.IsConnected));                 // old server should not still be connected

                if (remotePeer.IsConnected)
                {
                    locallyConnected.Add(remotePeer.Connection);
                }
                // Anyone not connected will get removed from the game in CompleteHostMigration

                remotePeer.PeerInfo.IsServer = false;                 // Un-server-ify the original server
            }

            // And also from ourself:
            Debug.Assert(owner.LocalPeerInfo.IsApplicationConnected);
            Debug.Assert(owner.LocalPeerInfo.ConnectionId <= maxConnectionId);
            Debug.Assert(owner.LocalPeerInfo.InputAssignment != 0);
            Debug.Assert((assignedInputs & owner.LocalPeerInfo.InputAssignment) == 0);
            assignedInputs |= owner.LocalPeerInfo.InputAssignment;


            // This should be safe, as host migration should remove all traces peers beyond this point (including in the app layer) and is atomic
            nextConnectionId = maxConnectionId + 1;
        }
Exemplo n.º 6
0
 void ReleaseInputAssignment(InputAssignment assignment)
 {
     assignedInputs &= ~assignment;
 }
Exemplo n.º 7
0
 public static void Write(this NetOutgoingMessage message, InputAssignment ia)
 {
     message.Write((uint)ia, MaxPlayerInputAssignments);
 }
Exemplo n.º 8
0
 public static void Write(InputAssignment ia)
 {
     //TODO SendMsg
 }