コード例 #1
0
 public void StartPacket(MyBitStream stream)
 {
     byte[] message = new byte[stream.BufferLength() + GnetBase.HeaderSize];
     Buffer.BlockCopy(stream.GetUnderlyingArray(), 0, message, GnetBase.HeaderSize, stream.BufferLength());
     Buffer.BlockCopy(BitConverter.GetBytes(GnetBase.PROTOCOL_ID), 0, message, 0, 4);
     Buffer.BlockCopy(BitConverter.GetBytes(PacketNumber), 0, message, 4, 4);
 }
コード例 #2
0
    public byte[] Pack()
    {
        MyBitStream stream = new MyBitStream(Size);

        stream.PackBool(A);
        stream.PackBool(B);
        stream.PackBool(X);
        stream.PackBool(Y);
        stream.PackBool(Select);
        stream.PackBool(Start);
        stream.PackBool(LB);
        stream.PackBool(RB);

        stream.PackBool(Left);
        stream.PackBool(Right);
        stream.PackBool(Up);
        stream.PackBool(Down);
        stream.PackBool(LeftStick);
        stream.PackBool(RightStick);
        stream.PackBool(false);
        stream.PackBool(false);

        stream.PackFloat(LeftAxisVertical);
        stream.PackFloat(LeftAxisHorizontal);
        stream.PackFloat(RightAxisVertical);
        stream.PackFloat(RightAxisHorizontal);

        stream.PackFloat(LT);
        stream.PackFloat(RT);

        return(stream.GetUnderlyingArray());
    }
コード例 #3
0
    public IoMap(byte[] buffer)
    {
        MyBitStream stream = new MyBitStream(buffer);

        A      = stream.ReadBool();
        B      = stream.ReadBool();
        X      = stream.ReadBool();
        Y      = stream.ReadBool();
        Select = stream.ReadBool();
        Start  = stream.ReadBool();
        LB     = stream.ReadBool();
        RB     = stream.ReadBool();

        Left       = stream.ReadBool();
        Right      = stream.ReadBool();
        Up         = stream.ReadBool();
        Down       = stream.ReadBool();
        LeftStick  = stream.ReadBool();
        RightStick = stream.ReadBool();
        stream.ReadBool();
        stream.ReadBool();

        LeftAxisVertical    = stream.ReadFloat();
        LeftAxisHorizontal  = stream.ReadFloat();
        RightAxisVertical   = stream.ReadFloat();
        RightAxisHorizontal = stream.ReadFloat();

        LT = stream.ReadFloat();
        RT = stream.ReadFloat();
    }
コード例 #4
0
    public void FreshPush(MyBitStream stream)
    {
        transform.position = stream.ReadVector3();
        transform.rotation = stream.ReadQuaternion();

        _velocity = stream.ReadVector3();
        _fresh    = true;
    }
コード例 #5
0
    public void Receive(IPEndPoint endpoint, Byte[] message)
    {
        LastReceived = BitConverter.ToUInt32(message, 4);

        MyBitStream stream = new MyBitStream(message, GnetBase.HeaderSize);

        NetAggregator.Instance.UnPackAll(stream);
    }
コード例 #6
0
    public byte[] Pack()
    {
        MyBitStream stream = new MyBitStream(PackedSize);;

        stream.PackVector3(transform.position);
        stream.PackQuaternion(transform.rotation);
        stream.PackVector3(_velocity);

        return(stream.GetUnderlyingArray());
    }
コード例 #7
0
    public void UnPackAll(MyBitStream stream)
    {
        //I guess I aggregate everything?
        //Since this never changes in size, I don't have to add indexes...
        for (int i = 0; i < NetObjs.Count; i++)
        {
            NetObjs[i].FreshPush(stream);
        }

        //UnPack the number of players
        //TODO fix number of player discrepancy
        if (PlayerObjs.Count != (int)stream.ReadByte())
        {
            throw new Exception("Wow you managed to have the wrong number of players...");
        }

        for (int i = 0; i < PlayerObjs.Count; i++)
        {
            PlayerObjs[i].FreshPush(stream);
        }
    }
コード例 #8
0
    //////////////////////////////////////////////////////////////////////////////////////////////////

    public static INetworkCommand[] GetCommandsFromStream(MyBitStream stream)
    {
        int count = (int)(stream.ReadByte());

        INetworkCommand[] commands = new INetworkCommand[count];
        for (int i = 0; i < count; i++)
        {
            byte commandType = stream.ReadByte();
            switch ((CommandTypes)commandType)
            {
            case CommandTypes.disconnectRequest:
                commands[i] = new DisconnectRequestCommand();
                break;

            default:
                break;
            }
        }

        return(commands);
    }