Moved a couple of folders and wrote some code
This commit is contained in:
153
Assets/Packages/FishNet/Runtime/Object/Helping/Hashing.cs
Normal file
153
Assets/Packages/FishNet/Runtime/Object/Helping/Hashing.cs
Normal file
@ -0,0 +1,153 @@
|
||||
namespace FishNet.Object.Helping
|
||||
{
|
||||
|
||||
public static class Hashing
|
||||
{
|
||||
|
||||
private const uint FNV_offset_basis32 = 2166136261;
|
||||
private const uint FNV_prime32 = 16777619;
|
||||
private const ulong FNV_offset_basis64 = 14695981039346656037;
|
||||
private const ulong FNV_prime64 = 1099511628211;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// non cryptographic stable hash code,
|
||||
/// it will always return the same hash for the same
|
||||
/// string.
|
||||
///
|
||||
/// This is simply an implementation of FNV-1 32 bit xor folded to 16 bit
|
||||
/// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
/// </summary>
|
||||
/// <returns>The stable hash32.</returns>
|
||||
/// <param name="txt">Text.</param>
|
||||
internal static ushort GetStableHash16(this string txt)
|
||||
{
|
||||
uint hash32 = txt.GetStableHash32();
|
||||
|
||||
return (ushort)((hash32 >> 16) ^ hash32);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// non cryptographic stable hash code,
|
||||
/// it will always return the same hash for the same
|
||||
/// string.
|
||||
///
|
||||
/// This is simply an implementation of FNV-1 32 bit
|
||||
/// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
/// </summary>
|
||||
/// <returns>The stable hash32.</returns>
|
||||
/// <param name="txt">Text.</param>
|
||||
public static uint GetStableHash32(this string txt)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
uint hash = FNV_offset_basis32;
|
||||
for (int i = 0; i < txt.Length; i++)
|
||||
{
|
||||
uint ch = txt[i];
|
||||
hash = hash * FNV_prime32;
|
||||
hash = hash ^ ch;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// non cryptographic stable hash code,
|
||||
/// it will always return the same hash for the same
|
||||
/// string.
|
||||
///
|
||||
/// This is simply an implementation of FNV-1 64 bit
|
||||
/// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
/// </summary>
|
||||
/// <returns>The stable hash32.</returns>
|
||||
/// <param name="txt">Text.</param>
|
||||
internal static ulong GetStableHash64(this string txt)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
ulong hash = FNV_offset_basis64;
|
||||
for (int i = 0; i < txt.Length; i++)
|
||||
{
|
||||
ulong ch = txt[i];
|
||||
hash = hash * FNV_prime64;
|
||||
hash = hash ^ ch;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// non cryptographic stable hash code,
|
||||
///// it will always return the same hash for the same
|
||||
///// string.
|
||||
/////
|
||||
///// This is simply an implementation of FNV-1 32 bit xor folded to 16 bit
|
||||
///// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
///// </summary>
|
||||
///// <returns>The stable hash32.</returns>
|
||||
///// <param name="bytes">Text.</param>
|
||||
//internal static ushort GetStableHash16(this byte[] bytes)
|
||||
//{
|
||||
// uint hash32 = bytes.GetStableHash32();
|
||||
|
||||
// return (ushort)((hash32 >> 16) ^ hash32);
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// non cryptographic stable hash code,
|
||||
///// it will always return the same hash for the same
|
||||
///// string.
|
||||
/////
|
||||
///// This is simply an implementation of FNV-1 32 bit
|
||||
///// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
///// </summary>
|
||||
///// <returns>The stable hash32.</returns>
|
||||
///// <param name="bytes">Text.</param>
|
||||
//internal static uint GetStableHash32(this byte[] bytes)
|
||||
//{
|
||||
// unchecked
|
||||
// {
|
||||
// uint hash = FNV_offset_basis32;
|
||||
// for (int i = 0; i < bytes.Length; i++)
|
||||
// {
|
||||
// uint bt = bytes[i];
|
||||
// hash = hash * FNV_prime32;
|
||||
// hash = hash ^ bt;
|
||||
// }
|
||||
// return hash;
|
||||
// }
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// non cryptographic stable hash code,
|
||||
///// it will always return the same hash for the same
|
||||
///// string.
|
||||
/////
|
||||
///// This is simply an implementation of FNV-1 64 bit
|
||||
///// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
///// </summary>
|
||||
///// <returns>The stable hash32.</returns>
|
||||
///// <param name="bytes">Text.</param>
|
||||
//internal static ulong GetStableHash64(this byte[] bytes)
|
||||
//{
|
||||
// unchecked
|
||||
// {
|
||||
// ulong hash = FNV_offset_basis64;
|
||||
// for (int i = 0; i < bytes.Length; i++)
|
||||
// {
|
||||
// ulong bt = bytes[i];
|
||||
// hash = hash * FNV_prime64;
|
||||
// hash = hash ^ bt;
|
||||
// }
|
||||
// return hash;
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c55dc5a22646764aa5dbfab2062669e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Packages/FishNet/Runtime/Object/Helping/RpcLink.cs
Normal file
39
Assets/Packages/FishNet/Runtime/Object/Helping/RpcLink.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using FishNet.Object.Helping;
|
||||
|
||||
namespace FishNet.Object
|
||||
{
|
||||
|
||||
#region Types.
|
||||
/// <summary>
|
||||
/// Lookup data for a RPC Link.
|
||||
/// </summary>
|
||||
internal struct RpcLink
|
||||
{
|
||||
/// <summary>
|
||||
/// ObjectId for link.
|
||||
/// </summary>
|
||||
public int ObjectId;
|
||||
/// <summary>
|
||||
/// NetworkBehaviour component index on ObjectId.
|
||||
/// </summary>
|
||||
public byte ComponentIndex;
|
||||
/// <summary>
|
||||
/// RpcHash for link.
|
||||
/// </summary>
|
||||
public uint RpcHash;
|
||||
/// <summary>
|
||||
/// Type of Rpc link is for.
|
||||
/// </summary>
|
||||
public RpcType RpcType;
|
||||
|
||||
public RpcLink(int objectId, byte componentIndex, uint rpcHash, RpcType rpcType)
|
||||
{
|
||||
ObjectId = objectId;
|
||||
ComponentIndex = componentIndex;
|
||||
RpcHash = rpcHash;
|
||||
RpcType = rpcType;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05a91745dd829d043aadf391ac7b233e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
13
Assets/Packages/FishNet/Runtime/Object/Helping/RpcType.cs
Normal file
13
Assets/Packages/FishNet/Runtime/Object/Helping/RpcType.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace FishNet.Object.Helping
|
||||
{
|
||||
public enum RpcType : int
|
||||
{
|
||||
None = 0,
|
||||
Server = 1,
|
||||
Observers = 2,
|
||||
Target = 4,
|
||||
Replicate = 8,
|
||||
Reconcile = 16
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09f9e7236f988c64fad54645f4cc7f8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,49 @@
|
||||
|
||||
namespace FishNet.Object.Helping
|
||||
{
|
||||
|
||||
public static class CodegenHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns if a NetworkObject is deinitializing.
|
||||
/// </summary>
|
||||
/// <param name="nb"></param>
|
||||
/// <returns></returns>
|
||||
public static bool NetworkObject_Deinitializing(NetworkBehaviour nb)
|
||||
{
|
||||
if (nb == null)
|
||||
return true;
|
||||
|
||||
return nb.IsDeinitializing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if running as server.
|
||||
/// </summary>
|
||||
/// <param name="nb"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsServer(NetworkBehaviour nb)
|
||||
{
|
||||
if (nb == null)
|
||||
return false;
|
||||
|
||||
return nb.IsServer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if running as client.
|
||||
/// </summary>
|
||||
/// <param name="nb"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsClient(NetworkBehaviour nb)
|
||||
{
|
||||
if (nb == null)
|
||||
return false;
|
||||
|
||||
return nb.IsClient;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 149cde0042627604d810c2c7fc0f9176
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user