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>
        /// Gets priority of different replicable.
        /// E.g. can be used to get priority of grid when calling GetPriority on cube block.
        /// </summary>
        public float GetPriority(IMyReplicable replicable)
        {
            while (replicable.IsChild)
            {
                var parent = replicable.GetDependency();
                if (parent == null)
                {
                    break;
                }
                else
                {
                    replicable = parent;
                }
            }

            MyReplicableClientData data;

            return(m_clientData.Replicables.TryGetValue(replicable, out data) ? data.Priority : 0);
        }
Beispiel #3
0
 bool TryGetDependency(IMyReplicable replicable, out IMyReplicable parent)
 {
     parent = replicable.GetDependency();
     return(parent != null);
 }
        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 #5
0
 bool TryGetDependency(IMyReplicable replicable, out IMyReplicable parent)
 {
     parent = replicable.GetDependency();
     return parent != null;
 }
        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();
            }
        }