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); * } */ }
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); }
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); }
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); }
public void write_float(WriteStream stream, float value) { stream.SerializeFloat(value); }
public void write_string(WriteStream stream, string value) { stream.SerializeString(value); }
public void write_bits(WriteStream stream, ulong value, int bits) { stream.SerializeBits(value, bits); }
public void write_uint(WriteStream stream, uint value, uint min, uint max) { stream.SerializeUnsignedInteger(value, min, max); }
public void write_int(WriteStream stream, int value, int min, int max) { stream.SerializeSignedInteger(value, min, max); }
// write public void write_bool(WriteStream stream, bool value) { uint unsigned_value = (value == true) ? 1U : 0U; stream.SerializeBits(unsigned_value, 1); }