mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
[SyncVar] limit increased from 32 to 64 per component
This commit is contained in:
parent
903eee667c
commit
a67508f624
@ -9,7 +9,7 @@ namespace UnityEngine.Networking
|
|||||||
[AddComponentMenu("")]
|
[AddComponentMenu("")]
|
||||||
public class NetworkBehaviour : MonoBehaviour
|
public class NetworkBehaviour : MonoBehaviour
|
||||||
{
|
{
|
||||||
uint m_SyncVarDirtyBits;
|
ulong m_SyncVarDirtyBits; // ulong instead of uint for 64 instead of 32 SyncVar limit per component
|
||||||
float m_LastSendTime;
|
float m_LastSendTime;
|
||||||
|
|
||||||
// this prevents recursion when SyncVar hook functions are called.
|
// this prevents recursion when SyncVar hook functions are called.
|
||||||
@ -24,7 +24,7 @@ public class NetworkBehaviour : MonoBehaviour
|
|||||||
public NetworkConnection connectionToServer { get { return myView.connectionToServer; } }
|
public NetworkConnection connectionToServer { get { return myView.connectionToServer; } }
|
||||||
public NetworkConnection connectionToClient { get { return myView.connectionToClient; } }
|
public NetworkConnection connectionToClient { get { return myView.connectionToClient; } }
|
||||||
public short playerControllerId { get { return myView.playerControllerId; } }
|
public short playerControllerId { get { return myView.playerControllerId; } }
|
||||||
protected uint syncVarDirtyBits { get { return m_SyncVarDirtyBits; } }
|
protected ulong syncVarDirtyBits { get { return m_SyncVarDirtyBits; } }
|
||||||
protected bool syncVarHookGuard { get { return m_SyncVarGuard; } set { m_SyncVarGuard = value; }}
|
protected bool syncVarHookGuard { get { return m_SyncVarGuard; } set { m_SyncVarGuard = value; }}
|
||||||
|
|
||||||
internal NetworkIdentity netIdentity { get { return myView; } }
|
internal NetworkIdentity netIdentity { get { return myView; } }
|
||||||
@ -497,7 +497,7 @@ internal static string GetCmdHashListName(int cmdHash)
|
|||||||
// ----------------------------- Helpers --------------------------------
|
// ----------------------------- Helpers --------------------------------
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, uint dirtyBit, ref NetworkInstanceId netIdField)
|
protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, ulong dirtyBit, ref NetworkInstanceId netIdField)
|
||||||
{
|
{
|
||||||
if (m_SyncVarGuard)
|
if (m_SyncVarGuard)
|
||||||
return;
|
return;
|
||||||
@ -532,7 +532,7 @@ protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gam
|
|||||||
}
|
}
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
protected void SetSyncVar<T>(T value, ref T fieldValue, uint dirtyBit)
|
protected void SetSyncVar<T>(T value, ref T fieldValue, ulong dirtyBit)
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
if (value == null)
|
if (value == null)
|
||||||
@ -553,7 +553,7 @@ protected void SetSyncVar<T>(T value, ref T fieldValue, uint dirtyBit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// these are masks, not bit numbers, ie. 0x004 not 2
|
// these are masks, not bit numbers, ie. 0x004 not 2
|
||||||
public void SetDirtyBit(uint dirtyBit)
|
public void SetDirtyBit(ulong dirtyBit)
|
||||||
{
|
{
|
||||||
m_SyncVarDirtyBits |= dirtyBit;
|
m_SyncVarDirtyBits |= dirtyBit;
|
||||||
}
|
}
|
||||||
@ -561,14 +561,14 @@ public void SetDirtyBit(uint dirtyBit)
|
|||||||
public void ClearAllDirtyBits()
|
public void ClearAllDirtyBits()
|
||||||
{
|
{
|
||||||
m_LastSendTime = Time.time;
|
m_LastSendTime = Time.time;
|
||||||
m_SyncVarDirtyBits = 0;
|
m_SyncVarDirtyBits = 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal int GetDirtyChannel()
|
internal int GetDirtyChannel()
|
||||||
{
|
{
|
||||||
if (Time.time - m_LastSendTime > GetNetworkSendInterval())
|
if (Time.time - m_LastSendTime > GetNetworkSendInterval())
|
||||||
{
|
{
|
||||||
if (m_SyncVarDirtyBits != 0)
|
if (m_SyncVarDirtyBits != 0L)
|
||||||
{
|
{
|
||||||
return GetNetworkChannel();
|
return GetNetworkChannel();
|
||||||
}
|
}
|
||||||
@ -580,7 +580,7 @@ public virtual bool OnSerialize(NetworkWriter writer, bool initialState)
|
|||||||
{
|
{
|
||||||
if (!initialState)
|
if (!initialState)
|
||||||
{
|
{
|
||||||
writer.WritePackedUInt32(0);
|
writer.WritePackedUInt64(0);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -589,7 +589,7 @@ public virtual void OnDeserialize(NetworkReader reader, bool initialState)
|
|||||||
{
|
{
|
||||||
if (!initialState)
|
if (!initialState)
|
||||||
{
|
{
|
||||||
reader.ReadPackedUInt32();
|
reader.ReadPackedUInt64();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class NetworkBehaviourProcessor
|
|||||||
List<MethodDefinition> m_RpcCallFuncs = new List<MethodDefinition>();
|
List<MethodDefinition> m_RpcCallFuncs = new List<MethodDefinition>();
|
||||||
List<MethodDefinition> m_TargetRpcCallFuncs = new List<MethodDefinition>();
|
List<MethodDefinition> m_TargetRpcCallFuncs = new List<MethodDefinition>();
|
||||||
|
|
||||||
const int k_SyncVarLimit = 32;
|
const int k_SyncVarLimit = 64; // ulong = 64 bytes
|
||||||
int m_QosChannel;
|
int m_QosChannel;
|
||||||
|
|
||||||
TypeDefinition m_td;
|
TypeDefinition m_td;
|
||||||
@ -593,7 +593,7 @@ void GenerateSerialization()
|
|||||||
|
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0));
|
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Call, Weaver.NetworkBehaviourDirtyBitsReference));
|
serWorker.Append(serWorker.Create(OpCodes.Call, Weaver.NetworkBehaviourDirtyBitsReference));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldc_I4, 1 << dirtyBit));
|
serWorker.Append(serWorker.Create(OpCodes.Ldc_I8, 1L << dirtyBit)); // 8 bytes = long
|
||||||
serWorker.Append(serWorker.Create(OpCodes.And));
|
serWorker.Append(serWorker.Create(OpCodes.And));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Brfalse, varLabel));
|
serWorker.Append(serWorker.Create(OpCodes.Brfalse, varLabel));
|
||||||
|
|
||||||
@ -654,7 +654,7 @@ static void WriteDirtyCheck(ILProcessor serWorker, bool reset)
|
|||||||
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1));
|
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0));
|
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Call, Weaver.NetworkBehaviourDirtyBitsReference));
|
serWorker.Append(serWorker.Create(OpCodes.Call, Weaver.NetworkBehaviourDirtyBitsReference));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Callvirt, Weaver.NetworkWriterWritePacked32));
|
serWorker.Append(serWorker.Create(OpCodes.Callvirt, Weaver.NetworkWriterWritePacked64));
|
||||||
if (reset)
|
if (reset)
|
||||||
{
|
{
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldc_I4_1));
|
serWorker.Append(serWorker.Create(OpCodes.Ldc_I4_1));
|
||||||
@ -957,12 +957,12 @@ void GenerateDeSerialization()
|
|||||||
|
|
||||||
// setup local for dirty bits
|
// setup local for dirty bits
|
||||||
serialize.Body.InitLocals = true;
|
serialize.Body.InitLocals = true;
|
||||||
VariableDefinition dirtyBitsLocal = new VariableDefinition(Weaver.int32Type);
|
VariableDefinition dirtyBitsLocal = new VariableDefinition(Weaver.int64Type);
|
||||||
serialize.Body.Variables.Add(dirtyBitsLocal);
|
serialize.Body.Variables.Add(dirtyBitsLocal);
|
||||||
|
|
||||||
// get dirty bits
|
// get dirty bits
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1));
|
serWorker.Append(serWorker.Create(OpCodes.Ldarg_1));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Callvirt, Weaver.NetworkReaderReadPacked32));
|
serWorker.Append(serWorker.Create(OpCodes.Callvirt, Weaver.NetworkReaderReadPacked64));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Stloc_0));
|
serWorker.Append(serWorker.Create(OpCodes.Stloc_0));
|
||||||
|
|
||||||
// conditionally read each syncvar
|
// conditionally read each syncvar
|
||||||
@ -973,7 +973,7 @@ void GenerateDeSerialization()
|
|||||||
|
|
||||||
// check if dirty bit is set
|
// check if dirty bit is set
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldloc_0));
|
serWorker.Append(serWorker.Create(OpCodes.Ldloc_0));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Ldc_I4, 1 << dirtyBit));
|
serWorker.Append(serWorker.Create(OpCodes.Ldc_I8, 1L << dirtyBit));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.And));
|
serWorker.Append(serWorker.Create(OpCodes.And));
|
||||||
serWorker.Append(serWorker.Create(OpCodes.Brfalse, varLabel));
|
serWorker.Append(serWorker.Create(OpCodes.Brfalse, varLabel));
|
||||||
|
|
||||||
@ -1977,7 +1977,7 @@ static MethodDefinition ProcessSyncVarGet(FieldDefinition fd, string originalNam
|
|||||||
return get;
|
return get;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodDefinition ProcessSyncVarSet(FieldDefinition fd, string originalName, int dirtyBit, FieldDefinition netFieldId)
|
MethodDefinition ProcessSyncVarSet(FieldDefinition fd, string originalName, long dirtyBit, FieldDefinition netFieldId)
|
||||||
{
|
{
|
||||||
//Create the set method
|
//Create the set method
|
||||||
MethodDefinition set = new MethodDefinition("set_Network" + originalName, MethodAttributes.Public |
|
MethodDefinition set = new MethodDefinition("set_Network" + originalName, MethodAttributes.Public |
|
||||||
@ -1998,7 +1998,7 @@ MethodDefinition ProcessSyncVarSet(FieldDefinition fd, string originalName, int
|
|||||||
setWorker.Append(setWorker.Create(OpCodes.Ldflda, fd));
|
setWorker.Append(setWorker.Create(OpCodes.Ldflda, fd));
|
||||||
|
|
||||||
// dirty bit
|
// dirty bit
|
||||||
setWorker.Append(setWorker.Create(OpCodes.Ldc_I4, dirtyBit));
|
setWorker.Append(setWorker.Create(OpCodes.Ldc_I8, dirtyBit)); // 8 byte integer aka long
|
||||||
|
|
||||||
MethodDefinition hookFunctionMethod;
|
MethodDefinition hookFunctionMethod;
|
||||||
CheckForHookFunction(fd, out hookFunctionMethod);
|
CheckForHookFunction(fd, out hookFunctionMethod);
|
||||||
@ -2057,7 +2057,7 @@ MethodDefinition ProcessSyncVarSet(FieldDefinition fd, string originalName, int
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessSyncVar(FieldDefinition fd, int dirtyBit)
|
void ProcessSyncVar(FieldDefinition fd, long dirtyBit)
|
||||||
{
|
{
|
||||||
string originalName = fd.Name;
|
string originalName = fd.Name;
|
||||||
|
|
||||||
@ -2139,7 +2139,7 @@ static MethodDefinition ProcessSyncListInvoke(FieldDefinition fd)
|
|||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldDefinition ProcessSyncList(FieldDefinition fd, int dirtyBit)
|
FieldDefinition ProcessSyncList(FieldDefinition fd, long dirtyBit)
|
||||||
{
|
{
|
||||||
MethodDefinition syncListFunc = ProcessSyncListInvoke(fd);
|
MethodDefinition syncListFunc = ProcessSyncListInvoke(fd);
|
||||||
m_SyncListInvocationFuncs.Add(syncListFunc);
|
m_SyncListInvocationFuncs.Add(syncListFunc);
|
||||||
@ -2233,7 +2233,7 @@ void ProcessSyncVars()
|
|||||||
|
|
||||||
m_SyncVars.Add(fd);
|
m_SyncVars.Add(fd);
|
||||||
|
|
||||||
ProcessSyncVar(fd, 1 << dirtyBitCounter);
|
ProcessSyncVar(fd, 1L << dirtyBitCounter);
|
||||||
dirtyBitCounter += 1;
|
dirtyBitCounter += 1;
|
||||||
numSyncVars += 1;
|
numSyncVars += 1;
|
||||||
|
|
||||||
@ -2265,7 +2265,7 @@ void ProcessSyncVars()
|
|||||||
|
|
||||||
m_SyncVars.Add(fd);
|
m_SyncVars.Add(fd);
|
||||||
m_SyncLists.Add(fd);
|
m_SyncLists.Add(fd);
|
||||||
listFields.Add(ProcessSyncList(fd, 1 << dirtyBitCounter));
|
listFields.Add(ProcessSyncList(fd, 1L << dirtyBitCounter));
|
||||||
dirtyBitCounter += 1;
|
dirtyBitCounter += 1;
|
||||||
numSyncVars += 1;
|
numSyncVars += 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user