Beispiel #1
0
        void appendIn(utList <tListEntry> list, System.Object target, bool paused)
        {
            tListEntry listEntry = new tListEntry();

            listEntry.target            = target;
            listEntry.paused            = paused;
            listEntry.markedForDeletion = false;
            MethodInfo method = target.GetType().GetMethod(updateSelector);

            listEntry.impMethod = (TICK_IMP)Delegate.CreateDelegate(typeof(TICK_IMP), target, method);

            utNode <tListEntry> listElement = new utNode <tListEntry> ();

            listElement.next = listElement.prev = null;
            listElement.obj  = listEntry;

            list.DL_APPEND(listElement);

            tHashUpdateEntry hashElement = new tHashUpdateEntry();

            hashElement.target = target;
            hashElement.list   = list;
            hashElement.entry  = listElement;
            hashForUpdates.HASH_ADD_INT(target.GetHashCode(), hashElement);
        }
 public void DL_DELETE(utNode <T> del)
 {
     NSUtils.Assert((del).prev != null, "utList#DL_DELETE: del.prev should not be null.");
     if ((del).prev == (del))
     {
         (_head) = null;
     }
     else if ((del) == (_head))
     {
         if (del.next != null)
         {
             (del).next.prev = (del).prev;
         }
         (_head) = (del).next;
     }
     else
     {
         (del).prev.next = (del).next;
         if ((del).next != null)
         {
             (del).next.prev = (del).prev;
         }
         else
         {
             (_head).prev = (del).prev;
         }
     }
 }
 public void DL_REPLACE_ELEM(utNode <T> el, utNode <T> add)
 {
     NSUtils.Assert(head != null, "utList#DL_REPLACE_ELEM: head should not be null");
     NSUtils.Assert(el != null, "utList#DL_REPLACE_ELEM: el should not be null");
     NSUtils.Assert(add != null, "utList#DL_REPLACE_ELEM: add should not be null");
     if ((_head) == (el))
     {
         _head      = add;
         (add).next = (el).next;
         if ((el).next == null)
         {
             (add).prev = (add);
         }
         else
         {
             (add).prev      = (el).prev;
             (add).next.prev = (add);
         }
     }
     else
     {
         (add).next      = (el).next;
         (add).prev      = (el).prev;
         (add).prev.next = (add);
         if ((el).next == null)
         {
             (head).prev = (add);
         }
         else
         {
             (add).next.prev = (add);
         }
     }
 }
        public void DL_PREPEND(T t)
        {
            utNode <T> listElement = new utNode <T> ();

            listElement.next = listElement.prev = null;
            listElement.obj  = t;
            DL_PREPEND(listElement);
        }
Beispiel #5
0
        void priorityIn(utList <tListEntry> list, System.Object target, int priority, bool paused)
        {
            tListEntry listEntry = new tListEntry();

            listEntry.target   = target;
            listEntry.priority = priority;
            listEntry.paused   = paused;
            MethodInfo method = target.GetType().GetMethod(updateSelector);

            listEntry.impMethod         = (TICK_IMP)Delegate.CreateDelegate(typeof(TICK_IMP), target, method);
            listEntry.markedForDeletion = false;

            utNode <tListEntry> listElement = new utNode <tListEntry> ();

            listElement.next = listElement.prev = null;
            listElement.obj  = listEntry;


            if (list.head == null)
            {
                list.DL_APPEND(listElement);
            }
            else
            {
                bool added = false;
                for (utNode <tListEntry> elem = list.head; elem != null; elem = elem.next)
                {
                    if (priority < elem.obj.priority)
                    {
                        if (elem == list.head)
                        {
                            list.DL_PREPEND(listElement);
                        }
                        else
                        {
                            listElement.next = elem;
                            listElement.prev = elem.prev;

                            elem.prev.next = listElement;
                            elem.prev      = listElement;
                        }
                        added = true;
                        break;
                    }
                }

                if (!added)
                {
                    list.DL_APPEND(listElement);
                }
            }
            tHashUpdateEntry hashElement = new tHashUpdateEntry();

            hashElement.target = target;
            hashElement.list   = list;
            hashElement.entry  = listElement;
            hashForUpdates.HASH_ADD_INT(target.GetHashCode(), hashElement);
        }
        public int DL_COUNT()
        {
            int count = 0;

            for (utNode <T> ent = this.head; ent != null; ent = ent.next)
            {
                count++;
            }
            return(count);
        }
 public void DL_DELETE(T t)
 {
     for (utNode <T> tmp = this.head; tmp != null; tmp = tmp.next)
     {
         utNode <T> entry = tmp;
         if (entry.obj.Equals(t))
         {
             DL_DELETE(entry);
         }
     }
 }
 public bool DL_CONTAINS(T t)
 {
     for (utNode <T> tmp = this.head; tmp != null; tmp = tmp.next)
     {
         utNode <T> entry = tmp;
         if (entry.obj.Equals(t))
         {
             return(true);
         }
     }
     return(false);
 }
 public void DL_PREPEND(utNode <T> add)
 {
     (add).next = _head;
     if (_head != null)
     {
         (add).prev   = (_head).prev;
         (_head).prev = (add);
     }
     else
     {
         (add).prev = (add);
     }
     (_head) = (add);
 }
Beispiel #10
0
        /** Pause all selectors and blocks from all targets with a minimum priority.
         * You should only call this with kCCPriorityNonSystemMin or higher.
         * @since v2.0.0
         */
        public HashSet <System.Object> pauseAllTargetsWithMinPriority(int minPriority)
        {
            HashSet <System.Object> idsWithSelectors = new HashSet <System.Object>();

            // Custom Selectors
            {
                var enumerator = hashForTimers.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    KeyValuePair <int, tHashTimerEntry> kv = enumerator.Current;
                    tHashTimerEntry element = kv.Value;
                    element.paused = true;
                    idsWithSelectors.Add(element.target);
                }
            }
            // Updates selectors
            if (minPriority < 0)
            {
                for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next)
                {
                    utNode <tListEntry> entry = tmp;
                    if (entry.obj.priority >= minPriority)
                    {
                        entry.obj.paused = true;
                        idsWithSelectors.Add(entry.obj.target);
                    }
                }
            }
            if (minPriority <= 0)
            {
                for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next)
                {
                    utNode <tListEntry> entry = tmp;
                    entry.obj.paused = true;
                    idsWithSelectors.Add(entry.obj.target);
                }
            }
            {
                for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next)
                {
                    utNode <tListEntry> entry = tmp;
                    if (entry.obj.priority >= minPriority)
                    {
                        entry.obj.paused = true;
                        idsWithSelectors.Add(entry.obj.target);
                    }
                }
            }
            return(idsWithSelectors);
        }
Beispiel #11
0
        void removeUpdatesFromHash(utNode <tListEntry> entry)
        {
            tHashUpdateEntry element = hashForUpdates.HASH_FIND_INT(entry.obj.target.GetHashCode());

            if (element != null)
            {
                // list entry
                element.list.DL_DELETE(element.entry);
                element.entry = null;

                // hash entry
                System.Object target = element.target;
                hashForUpdates.HASH_DEL(target.GetHashCode());
            }
        }
 public void DL_APPEND(utNode <T> add)
 {
     if (_head != null)
     {
         add.prev        = _head.prev;
         _head.prev.next = add;
         _head.prev      = add;
         add.next        = null;
     }
     else
     {
         _head      = add;
         _head.prev = _head;
         _head.next = null;
     }
 }
		public void addLaterDelegate(System.Object aDelegate, int priority, utList<tListEntry> list)
		{
			// XXX: Since, "remove" is "executed" after "add", it is not needed to check if the delegate was already added for removal.
			// In fact, if you remove it now, it could be a bug, since EventDispatcher doesn't support updated priority.
			// And the only way to update the priority is by deleting, re-adding the delegate with a new priority
			tListAddedEntry listEntry = new tListAddedEntry();
			
			listEntry.aDelegate = aDelegate;
			listEntry.priority = priority;
			listEntry.listToBeAdded = list;

			utNode<tListAddedEntry> listElement = new utNode<tListAddedEntry> ();
			listElement.next = listElement.prev = null;
			listElement.obj = listEntry;

			_delegatesToBeAdded.DL_APPEND(listElement);
		}
        public void DL_REPLACE_ELEM(T elT, T addT)
        {
            utNode <T> el = null;

            for (utNode <T> tmp = this.head; tmp != null; tmp = tmp.next)
            {
                utNode <T> entry = tmp;
                if (entry.obj.Equals(elT))
                {
                    el = entry;
                }
            }
            utNode <T> add = new utNode <T> ();

            add.next = add.prev = null;
            add.obj  = addT;
            DL_REPLACE_ELEM(el, add);
        }
		public void removeLaterDelegate(System.Object aDelegate, utList<tListEntry> list)
		{
			// Only add it if it was not already added for deletion
			if( ! removeDelegate<tListAddedEntry>(aDelegate, _delegatesToBeAdded)) {
				
				tListDeletedEntry listEntry = new tListDeletedEntry();
				
				listEntry.aDelegate = aDelegate;
				listEntry.listToBeDeleted = list;

				
				utNode<tListDeletedEntry> listElement = new utNode<tListDeletedEntry> ();
				listElement.next = listElement.prev = null;
				listElement.obj = listEntry;
				
				_delegatesToBeRemoved.DL_APPEND(listElement );
			}
		}
        public void DL_CONTACT(utList <T> list2)
        {
            var head1 = _head;
            var head2 = list2.head;

            if (head2 != null)
            {
                if (head1 != null)
                {
                    var tmp = head2.prev;
                    head2.prev      = head1.prev;
                    head1.prev.next = head2;
                    head1.prev      = tmp;
                }
                else
                {
                    _head = head2;
                }
            }
        }
Beispiel #17
0
 /** Unschedules all selectors and blocks from all targets with a minimum priority.
  * You should only call this with kCCPriorityNonSystemMin or higher.
  * @since v2.0.0
  */
 public void unscheduleAllWithMinPriority(int minPriority)
 {
     // Custom Selectors
     for (int i = hashForTimers.Count - 1; i >= 0; i--)
     {
         KeyValuePair <int, tHashTimerEntry> keyValue = hashForTimers.ElementAt(i);
         System.Object target = keyValue.Value.target;
         unscheduleAllForTarget(target);
     }
     // Updates selectors
     if (minPriority < 0)
     {
         for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next)
         {
             utNode <tListEntry> entry = tmp;
             if (entry.obj.priority >= minPriority)
             {
                 unscheduleUpdateForTarget(entry.obj.target);
             }
         }
     }
     if (minPriority <= 0)
     {
         for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next)
         {
             utNode <tListEntry> entry = tmp;
             unscheduleUpdateForTarget(entry.obj.target);
         }
     }
     for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next)
     {
         utNode <tListEntry> entry = tmp;
         if (entry.obj.priority >= minPriority)
         {
             unscheduleUpdateForTarget(entry.obj.target);
         }
     }
 }
		public void addDelegate(System.Object aDelegate, int priority, utList<tListEntry> list)
		{
			tListEntry listEntry = new tListEntry();
			
			listEntry.aDelegate = aDelegate;
			listEntry.priority = priority;

			utNode<tListEntry> listElement = new utNode<tListEntry> ();
			listElement.next = listElement.prev = null;
			listElement.obj = listEntry;

			bool added = false;
			
			for( utNode<tListEntry> elem = list.head; elem != null ; elem = elem.next ) {
				if( priority <= elem.obj.priority ) {
					
					if( elem == list.head )
						list.DL_PREPEND(listElement);
					else {
						listElement.next = elem;
						listElement.prev = elem.prev;
						
						elem.prev.next = listElement;
						elem.prev = listElement;
					}
					
					added = true;
					break;
				}
			}
			
			// Not added? priority has the higher value. Append it.
			if( !added )
				list.DL_APPEND(listElement);

		}
 public void DL_CLEAR()
 {
     _head = null;
 }
Beispiel #20
0
        //-------------update------------

        /** 'update' the scheduler.
         * You should NEVER call this method, unless you know what you are doing.
         */
        public void update(float dt)
        {
            if (_paused)
            {
                return;
            }
            updateHashLocked = true;
            if (!FloatUtils.EQ(_timeScale, 1.0f))
            {
                dt *= _timeScale;
            }

            // Iterate all over the Updates selectors
            // updates with priority < 0
            {
                for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next)
                {
                    utNode <tListEntry> entry = tmp;
                    if (!entry.obj.paused && !entry.obj.markedForDeletion)
                    {
                        entry.obj.impMethod.Invoke(dt);
                    }
                }
            }
            // updates with priority == 0
            {
                for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next)
                {
                    utNode <tListEntry> entry = tmp;
                    if (!entry.obj.paused && !entry.obj.markedForDeletion)
                    {
                        entry.obj.impMethod.Invoke(dt);
                    }
                }
            }
            // updates with priority > 0
            {
                for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next)
                {
                    utNode <tListEntry> entry = tmp;
                    if (!entry.obj.paused && !entry.obj.markedForDeletion)
                    {
                        entry.obj.impMethod.Invoke(dt);
                    }
                }
            }

//			 Iterate all over the custom selectors (CCTimers)
            if (hashForTimers.Any())
            {
                var enumerator = new Dictionary <int, tHashTimerEntry>(hashForTimers).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    var elt = enumerator.Current.Value;
                    currentTarget         = elt;
                    currentTargetSalvaged = false;
                    if (!currentTarget.paused)
                    {
                        for (elt.timerIndex = 0; elt.timerIndex < elt.timers.Count; elt.timerIndex++)
                        {
                            elt.currentTimer         = elt.timers[elt.timerIndex];
                            elt.currentTimerSalvaged = false;
                            elt.currentTimer.update(dt);
                            elt.currentTimer = null;
                        }
                    }
                    if (currentTargetSalvaged && currentTarget.timers.Count == 0)
                    {
                        removeHashElement(currentTarget);
                    }
                }
            }


            for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next)
            {
                utNode <tListEntry> entry = tmp;
                if (entry.obj.markedForDeletion)
                {
                    removeUpdatesFromHash(entry);
                }
            }

            for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next)
            {
                utNode <tListEntry> entry = tmp;
                if (entry.obj.markedForDeletion)
                {
                    removeUpdatesFromHash(entry);
                }
            }


            for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next)
            {
                utNode <tListEntry> entry = tmp;
                if (entry.obj.markedForDeletion)
                {
                    removeUpdatesFromHash(entry);
                }
            }
            updateHashLocked = false;
            currentTarget    = null;
        }