コード例 #1
0
    public void WriteStateUpdatePacket(Network.WriteStream stream, State cubeState)
    {
#if DEBUG_DELTA_COMPRESSION
        write_int(stream, cubeDelta.absolute_position_x, Constants.PositionMinimumXZ, Constants.PositionMaximumXZ);
        write_int(stream, cubeDelta.absolute_position_y, Constants.PositionMinimumY, Constants.PositionMaximumY);
        write_int(stream, cubeDelta.absolute_position_z, Constants.PositionMinimumXZ, Constants.PositionMaximumXZ);
#endif // #if DEBUG_DELTA_COMPRESSION

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


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

        /*
         * if (cubeState.active)
         * {
         *  write_int(stream, cubeState.linear_velocity_x, Constants.LinearVelocityMinimum, Constants.LinearVelocityMaximum);
         *  write_int(stream, cubeState.linear_velocity_y, Constants.LinearVelocityMinimum, Constants.LinearVelocityMaximum);
         *  write_int(stream, cubeState.linear_velocity_z, Constants.LinearVelocityMinimum, Constants.LinearVelocityMaximum);
         *
         *  write_int(stream, cubeState.angular_velocity_x, Constants.AngularVelocityMinimum, Constants.AngularVelocityMaximum);
         *  write_int(stream, cubeState.angular_velocity_y, Constants.AngularVelocityMinimum, Constants.AngularVelocityMaximum);
         *  write_int(stream, cubeState.angular_velocity_z, Constants.AngularVelocityMinimum, Constants.AngularVelocityMaximum);
         * }
         */
    }
コード例 #2
0
 public void WriteTestStruct(Network.WriteStream stream, ref TestStruct testStruct)
 {
     write_bool(stream, testStruct.bool_value);
     write_int(stream, testStruct.int_value, -100, +100);
     write_uint(stream, testStruct.uint_value, 100, 1000);
     write_bits(stream, testStruct.bits_value, 23);
 }
コード例 #3
0
    public void WriteHeader(Network.WriteStream stream, byte isAvatar, int obj, bool shotLight, int potionNum, bool hasParent, State cubeState)
    {
        write_bits(stream, 00000000, 8);
        //write_bool(stream, false);
        write_int(stream, obj, 0, 3);
        write_bool(stream, shotLight);
        write_int(stream, potionNum, 0, 127);
        write_bool(stream, hasParent);

        WriteStateUpdatePacket(stream, cubeState);
    }
コード例 #4
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);
    }
コード例 #5
0
 public void write_float(WriteStream stream, float value)
 {
     stream.SerializeFloat(value);
 }
コード例 #6
0
 public void write_string(WriteStream stream, string value)
 {
     stream.SerializeString(value);
 }
コード例 #7
0
 public void write_bits(WriteStream stream, ulong value, int bits)
 {
     stream.SerializeBits(value, bits);
 }
コード例 #8
0
 public void write_uint(WriteStream stream, uint value, uint min, uint max)
 {
     stream.SerializeUnsignedInteger(value, min, max);
 }
コード例 #9
0
 public void write_int(WriteStream stream, int value, int min, int max)
 {
     stream.SerializeSignedInteger(value, min, max);
 }
コード例 #10
0
        // write

        public void write_bool(WriteStream stream, bool value)
        {
            uint unsigned_value = (value == true) ? 1U : 0U;

            stream.SerializeBits(unsigned_value, 1);
        }