示例#1
0
 public void ReadTestStruct(ReadStream stream, out TestStruct testStruct)
 {
     stream.Bool(out testStruct.bool_value);
     stream.Int(out testStruct.int_value, -100, 100);
     stream.Uint(out testStruct.uint_value, 100, 1000);
     stream.Bits(out testStruct.bits_value, 23);
 }
示例#2
0
    void ReadAngularVelocityDelta(ReadStream r, out int deltaX, out int deltaY, out int deltaZ)
    {
        bool isAllSmall;

        r.Bool(out isAllSmall);
        uint unsignedX;
        uint unsignedY;
        uint unsignedZ;

        if (isAllSmall)
        {
            r.Bits(out unsignedX, AngularVelocityDeltaSmallBits);
            r.Bits(out unsignedY, AngularVelocityDeltaSmallBits);
            r.Bits(out unsignedZ, AngularVelocityDeltaSmallBits);
            deltaX = UnsignedToSigned(unsignedX);
            deltaY = UnsignedToSigned(unsignedY);
            deltaZ = UnsignedToSigned(unsignedZ);
            return;
        }

        bool isSmallX;

        r.Bool(out isSmallX);

        if (isSmallX)
        {
            r.Bits(out unsignedX, AngularVelocityDeltaSmallBits);
            deltaX = UnsignedToSigned(unsignedX);
        }
        else
        {
            bool isMediumX;
            r.Bool(out isMediumX);

            if (isMediumX)
            {
                r.Bits(out unsignedX, AngularVelocityDeltaMediumBits);
                deltaX = UnsignedToSigned(unsignedX + AngularVelocityDeltaSmallThreshold);
            }
            else
            {
                r.Int(out deltaX, -AngularVelocityDeltaMax, AngularVelocityDeltaMax);
            }
        }

        bool isSmallY;

        r.Bool(out isSmallY);

        if (isSmallY)
        {
            r.Bits(out unsignedY, AngularVelocityDeltaSmallBits);
            deltaY = UnsignedToSigned(unsignedY);
        }
        else
        {
            bool isMediumY;
            r.Bool(out isMediumY);

            if (isMediumY)
            {
                r.Bits(out unsignedY, AngularVelocityDeltaMediumBits);
                deltaY = UnsignedToSigned(unsignedY + AngularVelocityDeltaSmallThreshold);
            }
            else
            {
                r.Int(out deltaY, -AngularVelocityDeltaMax, AngularVelocityDeltaMax);
            }
        }

        bool isSmallZ;

        r.Bool(out isSmallZ);

        if (isSmallZ)
        {
            r.Bits(out unsignedZ, AngularVelocityDeltaSmallBits);
            deltaZ = UnsignedToSigned(unsignedZ);
        }
        else
        {
            bool isMediumZ;
            r.Bool(out isMediumZ);

            if (isMediumZ)
            {
                r.Bits(out unsignedZ, AngularVelocityDeltaMediumBits);
                deltaZ = UnsignedToSigned(unsignedZ + AngularVelocityDeltaSmallThreshold);
            }
            else
            {
                r.Int(out deltaZ, -AngularVelocityDeltaMax, AngularVelocityDeltaMax);
            }
        }
    }
示例#3
0
    void ReadAvatar(ReadStream s, out AvatarStateQuantized a)
    {
        s.Int(out a.clientId, 0, MaxClients - 1);
        s.Int(out a.headPositionX, MinPositionXZ, MaxPositionXZ);
        s.Int(out a.headPositionY, MinPositionY, MaxPositionY);
        s.Int(out a.headPositionZ, MinPositionXZ, MaxPositionXZ);
        s.Bits(out a.headRotationLargest, 2);
        s.Bits(out a.headRotationX, RotationBits);
        s.Bits(out a.headRotationY, RotationBits);
        s.Bits(out a.headRotationZ, RotationBits);
        s.Int(out a.leftHandPositionX, MinPositionXZ, MaxPositionXZ);
        s.Int(out a.leftHandPositionY, MinPositionY, MaxPositionY);
        s.Int(out a.leftHandPositionZ, MinPositionXZ, MaxPositionXZ);
        s.Bits(out a.leftHandRotationLargest, 2);
        s.Bits(out a.leftHandRotationX, RotationBits);
        s.Bits(out a.leftHandRotationY, RotationBits);
        s.Bits(out a.leftHandRotationZ, RotationBits);
        s.Int(out a.leftHandGripTrigger, MinTrigger, MaxTrigger);
        s.Int(out a.leftHandIdTrigger, MinTrigger, MaxTrigger);
        s.Bool(out a.isLeftHandPointing);
        s.Bool(out a.areLeftHandThumbsUp);
        s.Bool(out a.isLeftHandHoldingCube);

        if (a.isLeftHandHoldingCube)
        {
            s.Int(out a.leftHandCubeId, 0, MaxCubes - 1);
            s.Bits(out a.leftHandAuthoritySequence, 16);
            s.Bits(out a.leftHandOwnershipSequence, 16);
            s.Int(out a.leftHandCubeLocalPositionX, MinLocalPosition, MaxLocalPosition);
            s.Int(out a.leftHandCubeLocalPositionY, MinLocalPosition, MaxLocalPosition);
            s.Int(out a.leftHandCubeLocalPositionZ, MinLocalPosition, MaxLocalPosition);
            s.Bits(out a.leftHandCubeLocalRotationLargest, 2);
            s.Bits(out a.leftHandCubeLocalRotationX, RotationBits);
            s.Bits(out a.leftHandCubeLocalRotationY, RotationBits);
            s.Bits(out a.leftHandCubeLocalRotationZ, RotationBits);
        }
        else
        {
            a.leftHandCubeId                   = 0;
            a.leftHandAuthoritySequence        = 0;
            a.leftHandOwnershipSequence        = 0;
            a.leftHandCubeLocalPositionX       = 0;
            a.leftHandCubeLocalPositionY       = 0;
            a.leftHandCubeLocalPositionZ       = 0;
            a.leftHandCubeLocalRotationLargest = 0;
            a.leftHandCubeLocalRotationX       = 0;
            a.leftHandCubeLocalRotationY       = 0;
            a.leftHandCubeLocalRotationZ       = 0;
        }

        s.Int(out a.rightHandPositionX, MinPositionXZ, MaxPositionXZ);
        s.Int(out a.rightHandPositionY, MinPositionY, MaxPositionY);
        s.Int(out a.rightHandPositionZ, MinPositionXZ, MaxPositionXZ);
        s.Bits(out a.rightHandRotationLargest, 2);
        s.Bits(out a.rightHandRotationX, RotationBits);
        s.Bits(out a.rightHandRotationY, RotationBits);
        s.Bits(out a.rightHandRotationZ, RotationBits);
        s.Int(out a.rightHandGripTrigger, MinTrigger, MaxTrigger);
        s.Int(out a.rightHandIndexTrigger, MinTrigger, MaxTrigger);
        s.Bool(out a.isRightHandPointing);
        s.Bool(out a.areRightHandThumbsUp);
        s.Bool(out a.isRightHandHoldingCube);

        if (a.isRightHandHoldingCube)
        {
            s.Int(out a.rightHandCubeId, 0, MaxCubes - 1);
            s.Bits(out a.rightHandAuthoritySequence, 16);
            s.Bits(out a.rightHandOwnershipSequence, 16);
            s.Int(out a.rightHandCubeLocalPositionX, MinLocalPosition, MaxLocalPosition);
            s.Int(out a.rightHandCubeLocalPositionY, MinLocalPosition, MaxLocalPosition);
            s.Int(out a.rightHandCubeLocalPositionZ, MinLocalPosition, MaxLocalPosition);
            s.Bits(out a.rightHandCubeLocalRotationLargest, 2);
            s.Bits(out a.rightHandCubeLocalRotationX, RotationBits);
            s.Bits(out a.rightHandCubeLocalRotationY, RotationBits);
            s.Bits(out a.rightHandCubeLocalRotationZ, RotationBits);
        }
        else
        {
            a.rightHandCubeId                   = 0;
            a.rightHandAuthoritySequence        = 0;
            a.rightHandOwnershipSequence        = 0;
            a.rightHandCubeLocalPositionX       = 0;
            a.rightHandCubeLocalPositionY       = 0;
            a.rightHandCubeLocalPositionZ       = 0;
            a.rightHandCubeLocalRotationLargest = 0;
            a.rightHandCubeLocalRotationX       = 0;
            a.rightHandCubeLocalRotationY       = 0;
            a.rightHandCubeLocalRotationZ       = 0;
        }
        s.Int(out a.voiceAmplitude, MinVoice, MaxVoice);
    }
示例#4
0
    public void ReadUpdatePacket(ReadStream r, out PacketHeader header, out int avatarCount, AvatarStateQuantized[] avatars, out int cubeCount, int[] cubeIds, bool[] notChanged, bool[] hasDelta, bool[] hasPerfectPrediction, bool[] hasPrediction, ushort[] baselineIds, CubeState[] cubes, CubeDelta[] deltas, CubeDelta[] predictions
                                 )
    {
        byte packetType = 0;

        r.Bits(out packetType, 8);
        Debug.Assert(packetType == (byte)StateUpdate);
        r.Bits(out header.id, 16);
        r.Bits(out header.ack, 16);
        r.Bits(out header.ackBits, 32);
        r.Bits(out header.frame, 32);
        r.Bits(out header.resetId, 16);
        r.Float(out header.timeOffset);
        r.Int(out avatarCount, 0, MaxClients);

        for (int i = 0; i < avatarCount; ++i)
        {
            ReadAvatar(r, out avatars[i]);
        }

        r.Int(out cubeCount, 0, MaxStateUpdates);

        for (int i = 0; i < cubeCount; ++i)
        {
            hasDelta[i]             = false;
            hasPerfectPrediction[i] = false;
            hasPrediction[i]        = false;
            r.Int(out cubeIds[i], 0, MaxCubes - 1);
#if DEBUG_DELTA_COMPRESSION
            read_int(stream, out cubeDelta[i].absolute_position_x, PositionMinimumXZ, PositionMaximumXZ);
            read_int(stream, out cubeDelta[i].absolute_position_y, PositionMinimumY, PositionMaximumY);
            read_int(stream, out cubeDelta[i].absolute_position_z, PositionMinimumXZ, PositionMaximumXZ);
#endif // #if DEBUG_DELTA_COMPRESSION
            r.Int(out cubes[i].authorityId, 0, MaxAuthority - 1);
            r.Bits(out cubes[i].authorityPacketId, 16);
            r.Bits(out cubes[i].ownershipId, 16);
            r.Bool(out notChanged[i]);

            if (notChanged[i])
            {
                r.Bits(out baselineIds[i], 16);
                continue;
            }

            r.Bool(out hasPerfectPrediction[i]);

            if (hasPerfectPrediction[i])
            {
                r.Bits(out baselineIds[i], 16);
                r.Bits(out cubes[i].rotationLargest, 2);
                r.Bits(out cubes[i].rotationX, RotationBits);
                r.Bits(out cubes[i].rotationY, RotationBits);
                r.Bits(out cubes[i].rotationZ, RotationBits);
                cubes[i].isActive = true;
                continue;
            }

            r.Bool(out hasPrediction[i]);

            if (hasPrediction[i])
            {
                r.Bits(out baselineIds[i], 16);
                r.Bool(out cubes[i].isActive);
                ReadLinearVelocityDelta(r, out predictions[i].linearVelocityX, out predictions[i].linearVelocityY, out predictions[i].linearVelocityZ);
                ReadAngularVelocityDelta(r, out predictions[i].angularVelocityX, out predictions[i].angularVelocityY, out predictions[i].angularVelocityZ);
                ReadPositionDelta(r, out predictions[i].positionX, out predictions[i].positionY, out predictions[i].positionZ);
                r.Bits(out cubes[i].rotationLargest, 2);
                r.Bits(out cubes[i].rotationX, RotationBits);
                r.Bits(out cubes[i].rotationY, RotationBits);
                r.Bits(out cubes[i].rotationZ, RotationBits);
                continue;
            }

            r.Bool(out hasDelta[i]);

            if (hasDelta[i])
            {
                r.Bits(out baselineIds[i], 16);
                r.Bool(out cubes[i].isActive);
                ReadLinearVelocityDelta(r, out deltas[i].linearVelocityX, out deltas[i].linearVelocityY, out deltas[i].linearVelocityZ);
                ReadAngularVelocityDelta(r, out deltas[i].angularVelocityX, out deltas[i].angularVelocityY, out deltas[i].angularVelocityZ);
                ReadPositionDelta(r, out deltas[i].positionX, out deltas[i].positionY, out deltas[i].positionZ);
                r.Bits(out cubes[i].rotationLargest, 2);
                r.Bits(out cubes[i].rotationX, RotationBits);
                r.Bits(out cubes[i].rotationY, RotationBits);
                r.Bits(out cubes[i].rotationZ, RotationBits);
                continue;
            }

            r.Bool(out cubes[i].isActive);
            r.Int(out cubes[i].positionX, MinPositionXZ, MaxPositionXZ);
            r.Int(out cubes[i].positionY, MinPositionY, MaxPositionY);
            r.Int(out cubes[i].positionZ, MinPositionXZ, MaxPositionXZ);
            r.Bits(out cubes[i].rotationLargest, 2);
            r.Bits(out cubes[i].rotationX, RotationBits);
            r.Bits(out cubes[i].rotationY, RotationBits);
            r.Bits(out cubes[i].rotationZ, RotationBits);

            if (cubes[i].isActive)
            {
                r.Int(out cubes[i].linearVelocityX, LinearVelocityMinimum, LinearVelocityMaximum);
                r.Int(out cubes[i].linearVelocityY, LinearVelocityMinimum, LinearVelocityMaximum);
                r.Int(out cubes[i].linearVelocityZ, LinearVelocityMinimum, LinearVelocityMaximum);
                r.Int(out cubes[i].angularVelocityX, AngularVelocityMinimum, AngularVelocityMaximum);
                r.Int(out cubes[i].angularVelocityY, AngularVelocityMinimum, AngularVelocityMaximum);
                r.Int(out cubes[i].angularVelocityZ, AngularVelocityMinimum, AngularVelocityMaximum);
                continue;
            }

            cubes[i].linearVelocityX  = 0;
            cubes[i].linearVelocityY  = 0;
            cubes[i].linearVelocityZ  = 0;
            cubes[i].angularVelocityX = 0;
            cubes[i].angularVelocityY = 0;
            cubes[i].angularVelocityZ = 0;
        }
    }