Beispiel #1
0
        public void StopObservingPrimitive(MyHighLevelPrimitive primitive, IMyHighLevelPrimitiveObserver observer)
        {
            Debug.Assert(primitive.Parent == this);
            if (primitive.Parent != this)
            {
                return;
            }

            List <IMyHighLevelPrimitiveObserver> observers = null;
            int index = primitive.Index;

            // This primitive is being removed currently, so all observers will be removed from it anyway.
            if (index == m_removingPrimitive)
            {
                return;
            }

            if (m_primitiveObservers.TryGetValue(index, out observers))
            {
                observers.Remove(observer);
                if (observers.Count == 0)
                {
                    m_primitiveObservers.Remove(index);
                }
            }
            else
            {
                Debug.Assert(false, "The path is not observing this primitive anymore!");
            }
        }
Beispiel #2
0
 public void ObservePrimitive(MyHighLevelPrimitive primitive, IMyHighLevelPrimitiveObserver observer)
 {
     if (ReferenceEquals(primitive.Parent, this))
     {
         List <IMyHighLevelPrimitiveObserver> list = null;
         int index = primitive.Index;
         if (!this.m_primitiveObservers.TryGetValue(index, out list))
         {
             list = new List <IMyHighLevelPrimitiveObserver>(4);
             this.m_primitiveObservers.Add(index, list);
         }
         list.Add(observer);
     }
 }
Beispiel #3
0
 public void StopObservingPrimitive(MyHighLevelPrimitive primitive, IMyHighLevelPrimitiveObserver observer)
 {
     if (ReferenceEquals(primitive.Parent, this))
     {
         List <IMyHighLevelPrimitiveObserver> list = null;
         int index = primitive.Index;
         if ((index != this.m_removingPrimitive) && this.m_primitiveObservers.TryGetValue(index, out list))
         {
             list.Remove(observer);
             if (list.Count == 0)
             {
                 this.m_primitiveObservers.Remove(index);
             }
         }
     }
 }
Beispiel #4
0
        public void ObservePrimitive(MyHighLevelPrimitive primitive, IMyHighLevelPrimitiveObserver observer)
        {
            Debug.Assert(primitive.Parent == this);
            if (primitive.Parent != this)
            {
                return;
            }

            List <IMyHighLevelPrimitiveObserver> observers = null;
            int index = primitive.Index;

            if (!m_primitiveObservers.TryGetValue(index, out observers))
            {
                observers = new List <IMyHighLevelPrimitiveObserver>(4);
                m_primitiveObservers.Add(index, observers);
            }

            Debug.Assert(!observers.Contains(observer), "The given path is already observing the primitive!");
            observers.Add(observer);
        }