Beispiel #1
0
 public void Copy(Bitvector other)
 {
     for (var i = 0; i < Bits.Length; i++)
     {
         Bits[i] = other.Bits[i];
     }
 }
Beispiel #2
0
 public void Subtract(Bitvector other)
 {
     for (var i = 0; i < Bits.Length; i++)
     {
         Bits[i] = Bits[i] & ~other.Bits[i];
     }
 }
Beispiel #3
0
 public void Union(Bitvector other)
 {
     for (var i = 0; i < Bits.Length; i++)
     {
         Bits[i] = Bits[i] | other.Bits[i];
     }
 }
Beispiel #4
0
 /// <summary>
 /// Checks whether a room has a particular flag set.
 /// </summary>
 /// <param name="bvect"></param>
 /// <returns></returns>
 public bool HasFlag(Bitvector bvect)
 {
     if (Macros.IsSet(CurrentRoomFlags[bvect.Group], bvect.Vector))
     {
         return(true);
     }
     return(false);
 }
Beispiel #5
0
            public Bitvector NewBitvector()
            {
                var n = (BitIndex.Count + 63) / 64;
                var b = new Bitvector {
                    Symbols = this, Bits = new ulong[n]
                };

                return(b);
            }
Beispiel #6
0
        /// <summary>
        /// Gets a bitvector's string values.
        /// </summary>
        /// <param name="bvect"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static string BitvectorString(ref Bitvector bvect, BitvectorFlagType[] flags)
        {
            int i;

            for (i = 0; flags[i].BitvectorData.Vector > 0; i++)
            {
                if (flags[i].BitvectorData.Group == bvect.Group && flags[i].BitvectorData.Vector == bvect.Vector)
                {
                    return(flags[i].Name);
                }
            }
            return(null);
        }
Beispiel #7
0
 public WearData(Bitvector wearflag, int wearloc1, int wearloc2, int wearloc3, string wearmsg1, string wearmsg2, int partneeded, int racenotallowed)
 {
     WearFlag      = wearflag;
     WearLocations = new List <int>();
     if (wearloc1 != 0)
     {
         WearLocations.Add(wearloc1);
     }
     if (wearloc2 != 0)
     {
         WearLocations.Add(wearloc2);
     }
     if (wearloc3 != 0)
     {
         WearLocations.Add(wearloc3);
     }
     WearMessageToWearer = wearmsg1;
     WearMessageToRoom   = wearmsg2;
     BodyPartNeeded      = partneeded;
     RacesNotAllowed     = racenotallowed;
 }
Beispiel #8
0
 /// <summary>
 /// Add a bitvector flag to a room.
 /// </summary>
 /// <param name="bvect"></param>
 public void AddFlag(Bitvector bvect)
 {
     Macros.SetBit(ref CurrentRoomFlags[bvect.Group], bvect.Vector);
     return;
 }
Beispiel #9
0
 /// <summary>
 /// Remove a bitvector flag from a room.
 /// </summary>
 /// <param name="bvect"></param>
 public void RemoveFlag(Bitvector bvect)
 {
     Macros.RemoveBit(ref CurrentRoomFlags[bvect.Group], bvect.Vector);
     return;
 }
Beispiel #10
0
 /// <summary>
 /// Parameterized constructor.
 /// </summary>
 /// <param name="loc"></param>
 /// <param name="bit"></param>
 public WearInfo(ObjTemplate.WearLocation loc, Bitvector bit)
 {
     WornLocation = loc;
     WearBit      = bit;
 }
Beispiel #11
0
        protected bool OnInput(NetworkMessage msg)
        {
            var inputMsg = msg as InputMessage;

            Log($"[OnInput] Processing sequence {msg.SequenceNumber}");

            // If a disconnect is requested, go ahead and disconnect now.
            bool disconnectRequested = inputMsg.DisconnectRequested;

            if (disconnectRequested)
            {
                if (currentState != State.Disconnected && !disconnectEventSent)
                {
                    Log("Disconnecting endpoint on remote request.");
                    QueueEvent(new UdpProtocolEvent(UdpProtocolEvent.Type.Disconnected));
                    disconnectEventSent = true;
                }
            }
            else
            {
                // Update the peer connection status if this peer is still considered to be part
                // of the network.
                NetworkConnectStatus[] remoteStatus = inputMsg.PeerConnectStatus;
                for (int i = 0; i < peerConnectStatus.Length; i++)
                {
                    if (remoteStatus[i] != null && peerConnectStatus[i] != null)
                    {
                        Debug.Assert(remoteStatus[i].LastFrame >= peerConnectStatus[i].LastFrame);
                        peerConnectStatus[i].Disconnected = peerConnectStatus[i].Disconnected || remoteStatus[i].Disconnected;
                        peerConnectStatus[i].LastFrame    = Math.Max(peerConnectStatus[i].LastFrame, remoteStatus[i].LastFrame);
                    }
                }
            }

            // Decompress the input.
            int lastReceivedFrameNumber = lastReceivedInput.frame;

            if (inputMsg.NumBits > 0)
            {
                int  offset       = 0;
                uint currentFrame = inputMsg.StartFrame;

                lastReceivedInput.size = inputMsg.InputSize;
                if (lastReceivedInput.frame < 0)
                {
                    lastReceivedInput.frame = (int)(inputMsg.StartFrame - 1);
                }

                while (offset < inputMsg.NumBits)
                {
                    // Keep walking through the frames (parsing bits) until we reach
                    // the inputs for the frame right after the one we're on.
                    Debug.Assert(currentFrame <= lastReceivedInput.frame + 1,
                                 $"currentFrame is {currentFrame} and lastRecievedInput.frame is {lastReceivedInput.frame} from sequence {inputMsg.SequenceNumber}");
                    bool useInputs = currentFrame == (lastReceivedInput.frame + 1);

                    while (Bitvector.ReadBit(inputMsg.Bits, ref offset) > 0)
                    {
                        bool on     = Bitvector.ReadBit(inputMsg.Bits, ref offset) > 0;
                        int  button = Bitvector.ReadNibblet(inputMsg.Bits, ref offset);

                        if (useInputs)
                        {
                            if (on)
                            {
                                lastReceivedInput.Set(button);
                            }
                            else
                            {
                                lastReceivedInput.Clear(button);
                            }
                        }
                    }
                    Debug.Assert(offset <= inputMsg.NumBits);

                    // Now if we want to use these inputs, go ahead and send them to
                    // the emulator.
                    if (useInputs)
                    {
                        // Move forward 1 frame in the stream.
                        Debug.Assert(currentFrame == lastReceivedInput.frame + 1,
                                     $"currentFrame is {currentFrame} and lastRecievedInput.frame is {lastReceivedInput.frame} from sequence {inputMsg.SequenceNumber}");
                        lastReceivedInput.frame = (int)currentFrame;

                        // Send the event to the emulator
                        var evt = new InputEvent
                        {
                            Input = lastReceivedInput,
                        };

                        runningState.lastInputPacketReceiveTime = Utility.GetCurrentTime();
                        Log($"Sending frame {lastReceivedInput.frame} to emu queue {queue} ({lastReceivedInput.ToString()}).");
                        QueueEvent(evt);
                    }
                    else
                    {
                        Log($"Skipping past frame:({currentFrame}) current is {lastReceivedInput.frame}.");
                    }

                    // Move forward 1 frame in the input stream.
                    currentFrame++;
                }
            }

            Debug.Assert(lastReceivedInput.frame >= lastReceivedFrameNumber);

            // Get rid of our buffered input
            while (!pendingOutput.IsEmpty && pendingOutput.Front().frame < inputMsg.AckFrame)
            {
                Log($"Throwing away pending output frame {pendingOutput.Front().frame}");
                lastAckedInput = pendingOutput.Front();
                pendingOutput.Pop();
            }

            Log($"[OnInput] Completed sequence {msg.SequenceNumber}");
            return(true);
        }
Beispiel #12
0
        protected void SendPendingOutput()
        {
            var       msg    = new InputMessage();
            int       offset = 0;
            GameInput last   = lastAckedInput;

            if (!pendingOutput.IsEmpty)
            {
                msg.StartFrame = (uint)pendingOutput.Front().frame;
                msg.InputSize  = (byte)pendingOutput.Front().size;

                Debug.Assert(last.frame == -1 || last.frame + 1 == msg.StartFrame);

                for (int j = 0; j < pendingOutput.Size; j++)
                {
                    GameInput current = pendingOutput[j];
                    if (!current.Equal(last, true))
                    {
                        Debug.Assert((GameInput.MaxBytes * GameInput.MaxPlayers * 8) < (1 << Bitvector.NibbleSize));

                        for (int i = 0; i < current.size * 8; i++)
                        {
                            Debug.Assert(i < (1 << Bitvector.NibbleSize));
                            if (current[i] != last[i])
                            {
                                // Add a true bit here to signal that there's more input to parse
                                Bitvector.SetBit(msg.Bits, ref offset);

                                if (current[i])
                                {
                                    Bitvector.SetBit(msg.Bits, ref offset);
                                }
                                else
                                {
                                    Bitvector.ClearBit(msg.Bits, ref offset);
                                }
                                Bitvector.WriteNibblet(msg.Bits, i, ref offset);
                            }
                        }
                    }

                    // Add a stop bit to signal the end of the inpu set
                    Bitvector.ClearBit(msg.Bits, ref offset);
                    last = lastSentInput = current;
                }
            }
            else
            {
                msg.StartFrame = 0;
                msg.InputSize  = 0;
            }

            msg.AckFrame = lastReceivedInput.frame;
            msg.NumBits  = (ushort)offset;

            msg.DisconnectRequested = currentState == State.Disconnected;
            if (localConnectStatus != null)
            {
                for (int i = 0; i < Constants.MaxPlayers; i++)
                {
                    msg.PeerConnectStatus[i]?.Copy(localConnectStatus[i]);
                }
            }
            else
            {
                for (int i = 0; i < Constants.MaxPlayers; i++)
                {
                    msg.PeerConnectStatus[i]?.Reset();
                }
            }

            Debug.Assert(offset < Constants.MaxCompressedBits);

            SendMessage(msg);
        }