コード例 #1
0
 public void read_string(ReadStream stream, out string value)
 {
     if (!stream.SerializeString(out value))
     {
         throw new SerializeException();
     }
 }
コード例 #2
0
 public void read_float(ReadStream stream, out float value)
 {
     if (!stream.SerializeFloat(out value))
     {
         throw new SerializeException();
     }
 }
コード例 #3
0
 public void read_uint(ReadStream stream, out uint value, uint min, uint max)
 {
     if (!stream.SerializeUnsignedInteger(out value, min, max))
     {
         throw new SerializeException();
     }
 }
コード例 #4
0
 public void read_bits(ReadStream stream, out ulong value, int bits)
 {
     if (!stream.SerializeBits(out value, bits))
     {
         throw new SerializeException();
     }
 }
コード例 #5
0
 public void ReadTestStruct(Network.ReadStream stream, out TestStruct testStruct)
 {
     read_bool(stream, out testStruct.bool_value);
     read_int(stream, out testStruct.int_value, -100, +100);
     read_uint(stream, out testStruct.uint_value, 100, 1000);
     read_bits(stream, out testStruct.bits_value, 23);
 }
コード例 #6
0
        // read

        public void read_bool(ReadStream stream, out bool value)
        {
            uint unsigned_value;

            if (!stream.SerializeBits(out unsigned_value, 1))
            {
                throw new SerializeException();
            }
            value = (unsigned_value == 1) ? true : false;
        }
コード例 #7
0
    public void ReadStateUpdatePacket(Network.ReadStream stream, ref State cubeState)
    {
        //hasDelta = false;
        //perfectPrediction = false;
        //hasPredictionDelta = false;

#if DEBUG_DELTA_COMPRESSION
        read_int(stream, out cubeDelta.absolute_position_x, Constants.PositionMinimumXZ, Constants.PositionMaximumXZ);
        read_int(stream, out cubeDelta.absolute_position_y, Constants.PositionMinimumY, Constants.PositionMaximumY);
        read_int(stream, out cubeDelta.absolute_position_z, Constants.PositionMinimumXZ, Constants.PositionMaximumXZ);
#endif // #if DEBUG_DELTA_COMPRESSION

        /*
         * read_bool(stream, out isAvatar);
         * read_int(stream, out objNum, 0, 3);
         * read_bool(stream, out shotLight);
         * read_int(stream, out potionNum, 0, 15);
         */


        read_int(stream, out cubeState.position_x, Constants.PositionMinimumXZ, Constants.PositionMaximumXZ);
        read_int(stream, out cubeState.position_y, Constants.PositionMinimumY, Constants.PositionMaximumY);
        read_int(stream, out cubeState.position_z, Constants.PositionMinimumXZ, Constants.PositionMaximumXZ);

        read_bits(stream, out cubeState.rotation_largest, 2);
        read_bits(stream, out cubeState.rotation_a, Constants.RotationBits);
        read_bits(stream, out cubeState.rotation_b, Constants.RotationBits);
        read_bits(stream, out cubeState.rotation_c, Constants.RotationBits);

        /*
         * if (cubeState.active)
         * {
         *  read_int(stream, out cubeState.linear_velocity_x, Constants.LinearVelocityMinimum, Constants.LinearVelocityMaximum);
         *  read_int(stream, out cubeState.linear_velocity_y, Constants.LinearVelocityMinimum, Constants.LinearVelocityMaximum);
         *  read_int(stream, out cubeState.linear_velocity_z, Constants.LinearVelocityMinimum, Constants.LinearVelocityMaximum);
         *
         *  read_int(stream, out cubeState.angular_velocity_x, Constants.AngularVelocityMinimum, Constants.AngularVelocityMaximum);
         *  read_int(stream, out cubeState.angular_velocity_y, Constants.AngularVelocityMinimum, Constants.AngularVelocityMaximum);
         *  read_int(stream, out cubeState.angular_velocity_z, Constants.AngularVelocityMinimum, Constants.AngularVelocityMaximum);
         * }
         * else
         * {
         *  cubeState.linear_velocity_x = 0;
         *  cubeState.linear_velocity_y = 0;
         *  cubeState.linear_velocity_z = 0;
         *
         *  cubeState.angular_velocity_x = 0;
         *  cubeState.angular_velocity_y = 0;
         *  cubeState.angular_velocity_z = 0;
         * }
         */
    }
コード例 #8
0
    public void ReadHeader(Network.ReadStream stream, ref byte isAvatar, ref int objNum, ref bool shotLight, ref int potionNum, ref bool hasParent, ref State cubeState)
    {
        read_bits(stream, out isAvatar, 8);
        //read_bool(stream, out isAvatar);
        if (isAvatar != 00000001)
        {
            read_int(stream, out objNum, 0, 3);
            read_bool(stream, out shotLight);
            read_int(stream, out potionNum, 0, 127);
            read_bool(stream, out hasParent);

            ReadStateUpdatePacket(stream, ref cubeState);
        }
    }
コード例 #9
0
    static void test_serialization()
    {
        Debug.Log("test_serialization");

        const int MaxPacketSize = 1024;

        var serializer = new TestSerializer();

        var buffer = new uint[MaxPacketSize / 4];

        var writeStream = new Network.WriteStream();

        writeStream.Start(buffer);

        TestStruct input;

        input.bool_value = true;
        input.int_value  = -5;
        input.uint_value = 215;
        input.bits_value = 12345;

        serializer.WriteTestStruct(writeStream, ref input);

        writeStream.Finish();

        byte[] packet = writeStream.GetData();

        var readStream = new Network.ReadStream();

        readStream.Start(packet);

        TestStruct output;

        serializer.ReadTestStruct(readStream, out output);

        readStream.Finish();

        Assert.AreEqual(input.bool_value, output.bool_value);
        Assert.AreEqual(input.int_value, output.int_value);
        Assert.AreEqual(input.uint_value, output.uint_value);
        Assert.AreEqual(input.bits_value, output.bits_value);
    }