Exemple #1
0
        private int ComputeExpectedSize(NetworkSyncableVarsDirtyData dirtyData)
        {
            NetworkSyncableGameobjectInfos infos = _gameObjectSyncInfos[dirtyData.GameObject];
            int totalSize = 9;

            for (int i = 0; i < _syncableVariablesEnumValues.Length; i++)
            {
                SyncableVariable var = (SyncableVariable)_syncableVariablesEnumValues.GetValue(i);
                if (dirtyData.IsDirty(var))
                {
                    totalSize += infos.GetSyncVarByteSize(var);
                }
            }

            return(totalSize);
        }
Exemple #2
0
        private void PerformSync(bool[] syncFreqs)
        {
            for (int c = 0; c < CHANNEL_COUNT; c++)
            {
                List <NetworkSyncableVarsDirtyData> dirtyDatas = new List <NetworkSyncableVarsDirtyData>();
                SyncableVariable channelMask = _channelMasks[c];
                for (int f = 0; f < syncFreqs.Length; f++)
                {
                    if (syncFreqs[f] == false)
                    {
                        continue;
                    }

                    foreach (GameObject go in _gameObjectSyncInfos.Keys)
                    {
                        bool hasAuthority = go.GetComponent <NetworkIdentity>().hasAuthority;

                        NetworkSyncableVarsDirtyData currentDirtyData = null;
                        bool             goRequireSync = false;
                        SyncableVariable frequencyMask = _gameObjectSyncInfos[go].FrequenciesMasks[f];
                        for (int v = 0; v < _syncableVariablesEnumValues.Length; v++)
                        {
                            SyncableVariable var = (SyncableVariable)_syncableVariablesEnumValues.GetValue(v);
                            if ((var & channelMask & frequencyMask) > 0)
                            {
                                if (_gameObjectSyncInfos[go].IgnoreAuthority(var) == false && hasAuthority == false)
                                {
                                    continue;
                                }
                                if (_gameObjectSyncInfos[go].IsDirty(var))
                                {
                                    if (goRequireSync == false)
                                    {
                                        goRequireSync    = true;
                                        currentDirtyData = new NetworkSyncableVarsDirtyData(go);
                                        dirtyDatas.Add(currentDirtyData);
                                    }

                                    currentDirtyData.AddDirty(var);
                                    _gameObjectSyncInfos[go].ClearDirty(var);
                                }
                            }
                        }
                    }
                }
                if (dirtyDatas.Count > 0)
                {
                    List <NetworkSyncableVarsDirtyDataChunk> dirtyDataChunks = ComputeDirtyDataChunks(dirtyDatas);
                    for (int i = 0; i < dirtyDataChunks.Count; i++)
                    {
                        if (isServer == true)
                        {
                            PerformTargetSync(c, dirtyDataChunks[i]);
                        }
                        else
                        {
                            GetCmdPerformSyncMethod(c).Invoke(dirtyDataChunks[i]);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public static void WriteNetworkSyncableVarsDirtyData(this NetworkWriter writer, NetworkSyncableVarsDirtyData data)
        {
            writer.WriteGameObject(data.GameObject);
            writer.WriteInt64((long)data.DirtyVars);

            PinouNetworkManager.MainBehaviour.InvokeRegisterMethods(data.GameObject, data.DirtyVars, writer);
        }