[SyncVar] limit increased from 32 to 64 per component

This commit is contained in:
vis2k 2018-06-07 15:50:31 +02:00
parent 903eee667c
commit a67508f624
2 changed files with 21 additions and 21 deletions

View File

@ -9,7 +9,7 @@ namespace UnityEngine.Networking
[AddComponentMenu("")]
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;
// 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 connectionToClient { get { return myView.connectionToClient; } }
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; }}
internal NetworkIdentity netIdentity { get { return myView; } }
@ -497,7 +497,7 @@ internal static string GetCmdHashListName(int cmdHash)
// ----------------------------- Helpers --------------------------------
[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)
return;
@ -532,7 +532,7 @@ protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gam
}
[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;
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
public void SetDirtyBit(uint dirtyBit)
public void SetDirtyBit(ulong dirtyBit)
{
m_SyncVarDirtyBits |= dirtyBit;
}
@ -561,14 +561,14 @@ public void SetDirtyBit(uint dirtyBit)
public void ClearAllDirtyBits()
{
m_LastSendTime = Time.time;
m_SyncVarDirtyBits = 0;
m_SyncVarDirtyBits = 0L;
}
internal int GetDirtyChannel()
{
if (Time.time - m_LastSendTime > GetNetworkSendInterval())
{
if (m_SyncVarDirtyBits != 0)
if (m_SyncVarDirtyBits != 0L)
{
return GetNetworkChannel();
}
@ -580,7 +580,7 @@ public virtual bool OnSerialize(NetworkWriter writer, bool initialState)
{
if (!initialState)
{
writer.WritePackedUInt32(0);
writer.WritePackedUInt64(0);
}
return false;
}
@ -589,7 +589,7 @@ public virtual void OnDeserialize(NetworkReader reader, bool initialState)
{
if (!initialState)
{
reader.ReadPackedUInt32();
reader.ReadPackedUInt64();
}
}

View File

@ -26,7 +26,7 @@ class NetworkBehaviourProcessor
List<MethodDefinition> m_RpcCallFuncs = 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;
TypeDefinition m_td;
@ -593,7 +593,7 @@ void GenerateSerialization()
serWorker.Append(serWorker.Create(OpCodes.Ldarg_0));
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.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_0));
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)
{
serWorker.Append(serWorker.Create(OpCodes.Ldc_I4_1));
@ -957,12 +957,12 @@ void GenerateDeSerialization()
// setup local for dirty bits
serialize.Body.InitLocals = true;
VariableDefinition dirtyBitsLocal = new VariableDefinition(Weaver.int32Type);
VariableDefinition dirtyBitsLocal = new VariableDefinition(Weaver.int64Type);
serialize.Body.Variables.Add(dirtyBitsLocal);
// get dirty bits
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));
// conditionally read each syncvar
@ -973,7 +973,7 @@ void GenerateDeSerialization()
// check if dirty bit is set
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.Brfalse, varLabel));
@ -1977,7 +1977,7 @@ static MethodDefinition ProcessSyncVarGet(FieldDefinition fd, string originalNam
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
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));
// 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;
CheckForHookFunction(fd, out hookFunctionMethod);
@ -2057,7 +2057,7 @@ MethodDefinition ProcessSyncVarSet(FieldDefinition fd, string originalName, int
return set;
}
void ProcessSyncVar(FieldDefinition fd, int dirtyBit)
void ProcessSyncVar(FieldDefinition fd, long dirtyBit)
{
string originalName = fd.Name;
@ -2139,7 +2139,7 @@ static MethodDefinition ProcessSyncListInvoke(FieldDefinition fd)
return cmd;
}
FieldDefinition ProcessSyncList(FieldDefinition fd, int dirtyBit)
FieldDefinition ProcessSyncList(FieldDefinition fd, long dirtyBit)
{
MethodDefinition syncListFunc = ProcessSyncListInvoke(fd);
m_SyncListInvocationFuncs.Add(syncListFunc);
@ -2233,7 +2233,7 @@ void ProcessSyncVars()
m_SyncVars.Add(fd);
ProcessSyncVar(fd, 1 << dirtyBitCounter);
ProcessSyncVar(fd, 1L << dirtyBitCounter);
dirtyBitCounter += 1;
numSyncVars += 1;
@ -2265,7 +2265,7 @@ void ProcessSyncVars()
m_SyncVars.Add(fd);
m_SyncLists.Add(fd);
listFields.Add(ProcessSyncList(fd, 1 << dirtyBitCounter));
listFields.Add(ProcessSyncList(fd, 1L << dirtyBitCounter));
dirtyBitCounter += 1;
numSyncVars += 1;