当前位置: 首页>>代码示例>>C#>>正文


C# IMyReplicable.GetType方法代码示例

本文整理汇总了C#中IMyReplicable.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IMyReplicable.GetType方法的具体用法?C# IMyReplicable.GetType怎么用?C# IMyReplicable.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMyReplicable的用法示例。


在下文中一共展示了IMyReplicable.GetType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Destroy

        public void Destroy(IMyReplicable obj)
        {
            Debug.Assert(obj != null);
            if (!IsTypeReplicated(obj.GetType()))
            {
                return;
            }

            var id = GetNetworkIdByObject(obj);
            if (id.IsInvalid)
            {
                Debug.Fail("Destroying object which is not present");
                return;
            }

            // Remove from client states, remove from client replicables, send destroy
            foreach (var client in m_clientStates)
            {
                // TODO: Postpone removing for client (we don't want to peak network when a lot of objects get removed)
                if (client.Value.Replicables.ContainsKey(obj))
                {
                    RemoveForClient(obj, client.Key, client.Value, true);
                }
            }

            RemoveStateGroups(obj);
            var netId = RemoveNetworkedObject(obj);
            m_replicables.Remove(netId);
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:29,代码来源:MyReplicationServer.cs

示例2: SendReplicationCreate

        void SendReplicationCreate(IMyReplicable obj, EndpointId clientEndpoint)
        {
            var typeId = GetTypeIdByType(obj.GetType());
            var networkId = GetNetworkIdByObject(obj);

            var groups = m_replicableGroups[obj];
            Debug.Assert(groups.Count <= 255, "Unexpectedly high number of groups");

            m_sendStream.ResetWrite();
            m_sendStream.WriteTypeId(typeId);
            m_sendStream.WriteNetworkId(networkId);
            m_sendStream.WriteByte((byte)groups.Count);
            for (int i = 0; i < groups.Count; i++)
            {
                m_sendStream.WriteNetworkId(GetNetworkIdByObject(groups[i]));
            }
            obj.OnSave(m_sendStream);

            m_callback.SendReplicationCreate(m_sendStream, clientEndpoint);
            //Server.SendMessage(m_sendStream, clientId, PacketReliabilityEnum.RELIABLE, PacketPriorityEnum.LOW_PRIORITY, MyChannelEnum.Replication);
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:21,代码来源:MyReplicationServer.cs

示例3: Replicate

        public void Replicate(IMyReplicable obj)
        {
            if (!IsTypeReplicated(obj.GetType()))
            {
                Debug.Fail(String.Format("Type '{0}' not replicated, this should be checked before calling Replicate", obj.GetType().Name));
                return;
            }

            NetworkId networkId = AddNetworkObjectServer(obj);
            m_replicables.Add(networkId, obj);

            AddStateGroups(obj);

            // HACK: test serialization
            //m_sendStream.ResetWrite(MessageIDEnum.REPLICATION_CREATE);
            //stateData.Replicate(m_sendStream);
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:17,代码来源:MyReplicationServer.cs

示例4: PrepareForceReplicable

        bool PrepareForceReplicable(IMyReplicable obj)
        {
            Debug.Assert(obj != null);
            if (!IsTypeReplicated(obj.GetType()))
            {
                Debug.Fail(String.Format("Cannot replicate {0}, type is not replicated", obj));
                return false;
            }

            NetworkId id;
            if (!TryGetNetworkIdByObject(obj, out id))
            {
                Replicate(obj);
            }
            return true;
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:16,代码来源:MyReplicationServer.cs

示例5: SendReplicationCreate

        void SendReplicationCreate(IMyReplicable obj, ClientData clientData, EndpointId clientEndpoint)
        {
            
            if (m_replicationPaused)
            {
                clientData.PausedReplicables.Add(obj);
                return;
            }

            ProfilerShort.Begin("PrepareSave");
            var typeId = GetTypeIdByType(obj.GetType());
            var networkId = GetNetworkIdByObject(obj);

            var groups = m_replicableGroups[obj];
            Debug.Assert(groups.Count <= 255, "Unexpectedly high number of groups");

            m_sendStream.ResetWrite();
            m_sendStream.WriteTypeId(typeId);
            m_sendStream.WriteNetworkId(networkId);


            var streamable = obj as IMyStreamableReplicable;

            bool sendStreamed = streamable != null && streamable.NeedsToBeStreamed;
            if (streamable != null && streamable.NeedsToBeStreamed == false)
            {
                m_sendStream.WriteByte((byte)(groups.Count - 1));
            }
            else
            {
                m_sendStream.WriteByte((byte)groups.Count);
            }


            for (int i = 0; i < groups.Count; i++)
            {
                if (sendStreamed == false && groups[i].GroupType == StateGroupEnum.Streamining)
                {
                    continue;
                }
                m_sendStream.WriteNetworkId(GetNetworkIdByObject(groups[i]));
            }

            ProfilerShort.End();

            ProfilerShort.Begin("SaveReplicable");

            if (sendStreamed)
            {
                clientData.Replicables[obj].IsStreaming = true;
                m_callback.SendReplicationCreateStreamed(m_sendStream, clientEndpoint);
            }
            else
            {
                obj.OnSave(m_sendStream);
                ProfilerShort.Begin("Send");
                m_callback.SendReplicationCreate(m_sendStream, clientEndpoint);
                ProfilerShort.End();
            }
            ProfilerShort.End();
       
            //Server.SendMessage(m_sendStream, clientId, PacketReliabilityEnum.RELIABLE, PacketPriorityEnum.LOW_PRIORITY, MyChannelEnum.Replication);
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:63,代码来源:MyReplicationServer.cs

示例6: RefreshReplicable

        private void RefreshReplicable(IMyReplicable replicable)
        {
            ProfilerShort.Begin("m_timeFunc");
            MyTimeSpan now = m_timeFunc();
            ProfilerShort.End();

            foreach (var client in m_clientStates)
            {
                ProfilerShort.Begin("RefreshReplicablePerClient");

                ProfilerShort.Begin("TryGetValue Replicables");
                MyReplicableClientData replicableInfo;
                bool hasObj = client.Value.Replicables.TryGetValue(replicable, out replicableInfo);
                ProfilerShort.End();

                ProfilerShort.Begin("GetPriority");
                ProfilerShort.Begin(replicable.GetType().Name);
                float priority = replicable.GetPriority(new MyClientInfo(client.Value));

                if (hasObj)
                {
                    replicableInfo.Priority = priority;
                }

                bool isRelevant = priority > 0;
                ProfilerShort.End();
                ProfilerShort.End();

                if (isRelevant && !hasObj)
                {
                    ProfilerShort.Begin("CheckReady");
                    var dependency = replicable.GetDependency();
                    isRelevant = dependency == null || client.Value.IsReplicableReady(dependency);
                    ProfilerShort.End();

                    if (isRelevant)
                    {
                        ProfilerShort.Begin("AddForClient");
                        AddForClient(replicable, client.Key, client.Value, priority, false);
                        ProfilerShort.End();
                    }
                }
                else if (hasObj)
                {
                    ProfilerShort.Begin("UpdateSleepAndRemove");
                    // Hysteresis
                    replicableInfo.UpdateSleep(isRelevant, now);
                    if (replicableInfo.ShouldRemove(now, MaxSleepTime))
                        RemoveForClient(replicable, client.Key, client.Value, true);
                    ProfilerShort.End();
                }

                ProfilerShort.End();
            }
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:55,代码来源:MyReplicationServer.cs

示例7: Destroy

        public void Destroy(IMyReplicable obj)
        {
            Debug.Assert(obj != null);
            if (!IsTypeReplicated(obj.GetType()))
            {
                return;
            }

            var id = GetNetworkIdByObject(obj);
            if (id.IsInvalid)
            {
                Debug.Fail("Destroying object which is not present");
                return;
            }

            m_priorityUpdates.Remove(obj);
            bool isAnyClientPending = false;

            // Remove from client states, remove from client replicables, send destroy
            foreach (var client in m_clientStates)
            {
                // Damn, this id is blocked, i cannot remove it yet!
                if (client.Value.BlockedReplicables.ContainsKey(obj))
                {
                    // Mark for remove after replication ready.
                    client.Value.BlockedReplicables[obj].Remove = true;
                    if(!obj.IsChild && !m_priorityUpdates.Contains(obj))
                    {
                        m_priorityUpdates.Add(obj);
                    }
                    isAnyClientPending = true;
                    continue;
                }

                // TODO: Postpone removing for client (we don't want to peak network when a lot of objects get removed)
                if (client.Value.Replicables.ContainsKey(obj))
                {
                    RemoveForClient(obj, client.Key, client.Value, true);
                }
            }

            // if noone pending than remove replicable.
            if (!isAnyClientPending)
            {
                RemoveStateGroups(obj);
                var netId = RemoveNetworkedObject(obj);
                m_replicables.RemoveHierarchy(obj);
            }
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:49,代码来源:MyReplicationServer.cs

示例8: PrepareForceReplicable

        bool PrepareForceReplicable(IMyReplicable obj)
        {
            Debug.Assert(obj != null);
            if (obj == null || !IsTypeReplicated(obj.GetType()))
            {
                Debug.Fail(String.Format("Cannot replicate {0}, type is not replicated", obj));
                return false;
            }

            NetworkId id;
            if (!TryGetNetworkIdByObject(obj, out id))
            {
                Debug.Fail("Force replicable dependency not replicated yet!");
                //Replicate(obj); // This would cause crashes
                return false;
            }
            return true;
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:18,代码来源:MyReplicationServer.cs

示例9: Replicate

        public void Replicate(IMyReplicable obj)
        {
            if (!IsTypeReplicated(obj.GetType()))
            {
                Debug.Fail(String.Format("Type '{0}' not replicated, this should be checked before calling Replicate", obj.GetType().Name));
                return;
            }

            IMyReplicable parent;

            NetworkId networkId = AddNetworkObjectServer(obj);
            m_replicables.Add(obj, out parent);
            AddStateGroups(obj);

            if (parent != null)
            {
                // Replicate to all clients which has parent
                foreach (var client in m_clientStates)
                {
                    MyReplicableClientData parentInfo;
                    if (client.Value.Replicables.TryGetValue(parent, out parentInfo))
                    {
                        AddForClient(obj, client.Key, client.Value, parentInfo.Priority,false);
                    }
                }
            }
            else
            {
                m_priorityUpdates.Add(obj);
            }

            // HACK: uncomment this to test serialization
            //m_sendStream.ResetWrite(MessageIDEnum.REPLICATION_CREATE);
            //stateData.Replicate(m_sendStream);
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:35,代码来源:MyReplicationServer.cs


注:本文中的IMyReplicable.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。