Beispiel #1
0
 public void Serialize(INetBuffer writer)
 {
     writer.Put(Tick);
     writer.Put(PlayerStates.Length);
     foreach (var playerState in PlayerStates)
     {
         playerState.Serialize(writer);
     }
 }
Beispiel #2
0
    public static void Put(this INetBuffer writer, Vector3 value, bool delta = false)
    {
        if (GameConfig.deltaZeroCompression && delta)
        {
            if (Vector3.SqrMagnitude(value) < 0.0001)
            {
                writer.Put(false);
                return;
            }
            writer.Put(true);
        }

        if (GameConfig.deltaZeroDeep && delta)
        {
            writer.Put(value.x, true);
            writer.Put(value.y, true);
            writer.Put(value.z, true);
        }
        else
        {
            writer.Put(value.x);
            writer.Put(value.y);
            writer.Put(value.z);
        }
    }
Beispiel #3
0
    public static void Put(this INetBuffer writer, Quaternion value, bool delta = false)
    {
        if (GameConfig.deltaZeroCompression && delta)
        {
            if (value == Quaternion.identity)
            {
                writer.Put(false);
                return;
            }
            writer.Put(true);
        }

        bool deltaZero = GameConfig.deltaZeroDeep && delta;

        if (GameConfig.smallestThree)
        {
            SmallestThree.EncodeQuaternion(writer, value, delta);
        }
        else
        {
            writer.Put(value.x, deltaZero);
            writer.Put(value.y, deltaZero);
            writer.Put(value.z, deltaZero);
            writer.Put(value.w, deltaZero);
        }
    }
Beispiel #4
0
 public void Serialize(INetBuffer writer)
 {
     writer.Put(PlayerId);
     writer.Put(Position, true);
     writer.Put(Rotation, true);
 }
Beispiel #5
0
    public static void EncodeQuaternion(INetBuffer writer, Quaternion quaternion, bool delta = false)
    {
        byte  maxIndex     = 0;
        float maxValue     = float.MinValue;
        float maxValueSign = 1;

        // Find the largest value in the quaternion and save its index.
        for (byte i = 0; i < 4; i++)
        {
            var value    = quaternion[i];
            var absValue = Mathf.Abs(value);
            if (absValue > maxValue)
            {
                maxIndex = i;
                maxValue = absValue;

                // Note the sign of the maxValue for later.
                maxValueSign = Mathf.Sign(value);
            }
        }

        // Encode the smallest three components.
        short a, b, c;

        switch (maxIndex)
        {
        case 0:
            a = (short)(quaternion.y * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            b = (short)(quaternion.z * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            c = (short)(quaternion.w * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            break;

        case 1:
            a = (short)(quaternion.x * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            b = (short)(quaternion.z * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            c = (short)(quaternion.w * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            break;

        case 2:
            a = (short)(quaternion.x * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            b = (short)(quaternion.y * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            c = (short)(quaternion.w * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            break;

        case 3:
            a = (short)(quaternion.x * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            b = (short)(quaternion.y * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            c = (short)(quaternion.z * maxValueSign * QUAT_FLOAT_PRECISION_MULT);
            break;

        default:
            throw new InvalidProgramException("Unexpected quaternion index.");
        }

        bool deltaZero = GameConfig.deltaZeroDeep && delta;

        writer.Put(maxIndex);
        writer.Put(a, deltaZero);
        writer.Put(b, deltaZero);
        writer.Put(c, deltaZero);
    }