Refactor NetworkMessage and NetworkStream to handle errors gracefully, including in Release builds
This commit is contained in:
@@ -11,7 +11,7 @@ namespace FlaxEngine.Networking
|
||||
/// Writes raw bytes into the message.
|
||||
/// </summary>
|
||||
/// <param name="bytes">The bytes that will be written.</param>
|
||||
/// <param name="length">The amount of bytes to write from the bytes pointer.</param>
|
||||
/// <param name="length">The amount of bytes to write from the pointer.</param>
|
||||
public void WriteBytes(byte* bytes, int length)
|
||||
{
|
||||
WriteData(new IntPtr(bytes), length);
|
||||
@@ -20,8 +20,7 @@ namespace FlaxEngine.Networking
|
||||
/// <summary>
|
||||
/// Reads raw bytes from the message into the given byte array.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The buffer pointer that will be used to store the bytes. Should be of the same length as length or longer.
|
||||
/// </param>
|
||||
/// <param name="buffer">The buffer pointer that will be used to store the bytes. Should be of the same length as length or longer.</param>
|
||||
/// <param name="length">The minimal amount of bytes that the buffer contains.</param>
|
||||
public void ReadBytes(byte* buffer, int length)
|
||||
{
|
||||
@@ -285,8 +284,12 @@ namespace FlaxEngine.Networking
|
||||
/// </summary>
|
||||
public void WriteVector2(Vector2 value)
|
||||
{
|
||||
WriteSingle((float)value.X);
|
||||
WriteSingle((float)value.Y);
|
||||
#if USE_LARGE_WORLDS
|
||||
var tmp = new Float2(value);
|
||||
WriteBytes((byte*)&tmp, sizeof(Float2));
|
||||
#else
|
||||
WriteBytes((byte*)&value, sizeof(Float2));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -302,9 +305,12 @@ namespace FlaxEngine.Networking
|
||||
/// </summary>
|
||||
public void WriteVector3(Vector3 value)
|
||||
{
|
||||
WriteSingle((float)value.X);
|
||||
WriteSingle((float)value.Y);
|
||||
WriteSingle((float)value.Z);
|
||||
#if USE_LARGE_WORLDS
|
||||
var tmp = new Vector3(value);
|
||||
WriteBytes((byte*)&tmp, sizeof(Vector3));
|
||||
#else
|
||||
WriteBytes((byte*)&value, sizeof(Vector3));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -320,10 +326,12 @@ namespace FlaxEngine.Networking
|
||||
/// </summary>
|
||||
public void WriteVector4(Vector4 value)
|
||||
{
|
||||
WriteSingle((float)value.X);
|
||||
WriteSingle((float)value.Y);
|
||||
WriteSingle((float)value.Z);
|
||||
WriteSingle((float)value.W);
|
||||
#if USE_LARGE_WORLDS
|
||||
var tmp = new Vector4(value);
|
||||
WriteBytes((byte*)&tmp, sizeof(Vector4));
|
||||
#else
|
||||
WriteBytes((byte*)&value, sizeof(Vector4));
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -339,8 +347,7 @@ namespace FlaxEngine.Networking
|
||||
/// </summary>
|
||||
public void WriteFloat2(Float2 value)
|
||||
{
|
||||
WriteSingle(value.X);
|
||||
WriteSingle(value.Y);
|
||||
WriteBytes((byte*)&value, sizeof(Float2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -356,9 +363,7 @@ namespace FlaxEngine.Networking
|
||||
/// </summary>
|
||||
public void WriteFloat3(Float3 value)
|
||||
{
|
||||
WriteSingle(value.X);
|
||||
WriteSingle(value.Y);
|
||||
WriteSingle(value.Z);
|
||||
WriteBytes((byte*)&value, sizeof(Float3));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -374,10 +379,7 @@ namespace FlaxEngine.Networking
|
||||
/// </summary>
|
||||
public void WriteFloat4(Float4 value)
|
||||
{
|
||||
WriteSingle(value.X);
|
||||
WriteSingle(value.Y);
|
||||
WriteSingle(value.Z);
|
||||
WriteSingle(value.W);
|
||||
WriteBytes((byte*)&value, sizeof(Float4));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -393,10 +395,8 @@ namespace FlaxEngine.Networking
|
||||
/// </summary>
|
||||
public void WriteQuaternion(Quaternion value)
|
||||
{
|
||||
WriteSingle(value.X);
|
||||
WriteSingle(value.Y);
|
||||
WriteSingle(value.Z);
|
||||
WriteSingle(value.W);
|
||||
// TODO: use NetworkQuaternion to match C++
|
||||
WriteBytes((byte*)&value, sizeof(Quaternion));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -404,7 +404,10 @@ namespace FlaxEngine.Networking
|
||||
/// </summary>
|
||||
public Quaternion ReadQuaternion()
|
||||
{
|
||||
return new Quaternion(ReadSingle(), ReadSingle(), ReadSingle(), ReadSingle());
|
||||
// TODO: use NetworkQuaternion to match C++
|
||||
Quaternion result = Quaternion.Identity;
|
||||
ReadBytes((byte*)&result, sizeof(Quaternion));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user