Пример #1
0
    public void ReadUpdatePacketHeader(ReadStream r, out PacketHeader h)
    {
        byte packetType = 0;

        r.Bits(out packetType, 8);
        Debug.Assert(packetType == (byte)StateUpdate);
        r.Bits(out h.id, 16);
        r.Bits(out h.ack, 16);
        r.Bits(out h.ackBits, 32);
        r.Bits(out h.frame, 32);
        r.Bits(out h.resetId, 16);
        r.Float(out h.timeOffset);
    }
Пример #2
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;
        }
    }