You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.6 KiB
C#
92 lines
2.6 KiB
C#
3 weeks ago
|
using System.Runtime.CompilerServices;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace Fusion.Addons.SimpleKCC
|
||
|
{
|
||
|
internal static class KCCNetworkUtility
|
||
|
{
|
||
|
public const int WORD_COUNT_BOOL = 1;
|
||
|
|
||
|
public const int WORD_COUNT_INT = 1;
|
||
|
|
||
|
public const int WORD_COUNT_FLOAT = 1;
|
||
|
|
||
|
public const int WORD_COUNT_VECTOR3 = 3;
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static bool ReadBool(int* ptr)
|
||
|
{
|
||
|
if (*ptr == 0)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static void WriteBool(int* ptr, bool value)
|
||
|
{
|
||
|
*ptr = (value ? 1 : 0);
|
||
|
}
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static int ReadInt(int* ptr)
|
||
|
{
|
||
|
return *ptr;
|
||
|
}
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static void WriteInt(int* ptr, int value)
|
||
|
{
|
||
|
*ptr = value;
|
||
|
}
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static float ReadFloat(int* ptr)
|
||
|
{
|
||
|
return *(float*)ptr;
|
||
|
}
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static void WriteFloat(int* ptr, float value)
|
||
|
{
|
||
|
*(float*)ptr = value;
|
||
|
}
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static Vector3 ReadVector3(int* ptr)
|
||
|
{
|
||
|
Vector3 result = default(Vector3);
|
||
|
result.x = *(float*)ptr;
|
||
|
result.y = *(float*)(ptr + 1);
|
||
|
result.z = *(float*)(ptr + 2);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static void WriteVector3(int* ptr, Vector3 value)
|
||
|
{
|
||
|
*(float*)ptr = value.x;
|
||
|
*(float*)(ptr + 1) = value.y;
|
||
|
*(float*)(ptr + 2) = value.z;
|
||
|
}
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static KCCNetworkID ReadNetworkID(int* ptr)
|
||
|
{
|
||
|
KCCNetworkID result = default(KCCNetworkID);
|
||
|
result.Value0 = (uint)(*ptr);
|
||
|
result.Value1 = (uint)ptr[1];
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||
|
public unsafe static void WriteNetworkID(int* ptr, KCCNetworkID networkID)
|
||
|
{
|
||
|
*ptr = (int)networkID.Value0;
|
||
|
ptr[1] = (int)networkID.Value1;
|
||
|
}
|
||
|
}
|
||
|
}
|