private void RefreshReplicable(IMyReplicable replicable)
        {
            MyTimeSpan now = m_timeFunc();

            foreach (var client in m_clientStates)
            {
                MyReplicableClientData replicableInfo;
                bool hasObj     = client.Value.Replicables.TryGetValue(replicable, out replicableInfo);
                bool isRelevant = replicable.GetPriority(client.Value.State) > 0;
                if (isRelevant)
                {
                    var dependency = replicable.GetDependency();
                    isRelevant = dependency == null || client.Value.IsReplicableReady(dependency);
                }

                if (!hasObj && isRelevant)
                {
                    AddForClient(replicable, client.Key, client.Value);
                }
                else if (hasObj)
                {
                    // Hysteresis
                    replicableInfo.UpdateSleep(isRelevant, now);
                    if (replicableInfo.ShouldRemove(now, MaxSleepTime))
                    {
                        RemoveForClient(replicable, client.Key, client.Value, true);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Takes into account:
        /// Static body (zero priority for static),
        /// ResponsibilityForUpdate by client (zero priority for not responsible),
        /// otherwise returns OwnerReplicable priority.
        /// </summary>
        protected float GetBasicPhysicsPriority(MyClientStateBase client)
        {
            // Called only on server
            if (Entity.Physics.IsStatic)
            {
                return(0);
            }

            // TODO: Rewrite and move 'ResponsibleForUpdate' to this class (when on trunk)
            var sync = (MySyncEntity)Entity.SyncObject;

            if (sync.ResponsibleForUpdate(client.GetClient()))
            {
                return(0);
            }

            return(OwnerReplicable.GetPriority(client));
        }
        private void RefreshReplicable(IMyReplicable replicable)
        {
            MyTimeSpan now = m_timeFunc();

            foreach (var client in m_clientStates)
            {
                MyReplicableClientData replicableInfo;
                bool hasObj = client.Value.Replicables.TryGetValue(replicable, out replicableInfo);
                bool isRelevant = replicable.GetPriority(client.Value.State) > 0;
                if(isRelevant)
                {
                    var dependency = replicable.GetDependency();
                    isRelevant = dependency == null || client.Value.IsReplicableReady(dependency);
                }                

                if (!hasObj && isRelevant)
                {
                    AddForClient(replicable, client.Key, client.Value);
                }
                else if (hasObj)
                {
                    // Hysteresis
                    replicableInfo.UpdateSleep(isRelevant, now);
                    if (replicableInfo.ShouldRemove(now, MaxSleepTime))
                        RemoveForClient(replicable, client.Key, client.Value, true);
                }
            }
        }
        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();
            }
        }
Beispiel #5
0
 public static bool IsRelevant(this IMyReplicable obj, MyClientStateBase state, out float priority)
 {
     priority = obj.GetPriority(state);
     return(priority > 0);
 }
Beispiel #6
0
 public static bool IsRelevant(this IMyReplicable obj, MyClientStateBase state)
 {
     return(obj.GetPriority(state) > 0);
 }