コード例 #1
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);
        }
コード例 #2
0
        /** The scheduled method will be called every 'interval' seconds.
         * If paused is YES, then it won't be called until it is resumed.
         * If 'interval' is 0, it will be called every frame, but if so, it recommended to use 'scheduleUpdateForTarget:' instead.
         * If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
         * repeat lets the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously
         * delay is the amount of time the action will wait before it'll start
         *
         * @since v0.99.3, repeat and delay added in v1.1
         */
        public void schedule(TICK_IMP selector, System.Object target, float interval, uint repeat, bool paused, float delay = 0)
        {
            NSUtils.Assert(selector != null, "Argument selector must be non-nil");
            NSUtils.Assert(target != null, "Argument target must be non-nil");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element == null)
            {
                element        = new tHashTimerEntry();
                element.target = target;
                hashForTimers.HASH_ADD_INT(target.GetHashCode(), element);

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = paused;
            }
            else
            {
                NSUtils.Assert(element.paused == paused, "CCScheduler. Trying to schedule a selector with a pause value different than the target");
            }


            if (element.timers == null)
            {
                element.timers = new List <CCTimer> (10);
            }
            else
            {
                var enumerator = element.timers.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    CCTimer timer = enumerator.Current;
                    if (timer is CCTimerTargetSelector && selector == ((CCTimerTargetSelector)timer).selector)
                    {
                        CCDebug.Log("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: {0:0.0000} to {1:0.0000}", timer.interval, interval);
                        timer.interval = interval;
                        return;
                    }
                }
            }
            CCTimerTargetSelector timerSelector = new CCTimerTargetSelector(target, selector, interval, repeat, delay);

            element.timers.Add(timerSelector);
        }
コード例 #3
0
//		-(NSSet *) pauseAllRunningActions
//		{
//			NSMutableSet* idsWithActions = [NSMutableSet setWithCapacity:50];
//
//			for(tHashElement *element=targets; element != NULL; element=element->hh.next) {
//				if( !element->paused ) {
//					element->paused = YES;
//					[idsWithActions addObject:element->target];
//				}
//			}
//			return idsWithActions;
//		}
//
//		-(void) resumeTargets:(NSSet *)targetsToResume
//		{
//			for(id target in targetsToResume) {
//				[self resumeTarget:target];
//			}
//		}

        #endregion



        #region ActionManager - run
        public void addAction(CCAction action, System.Object target, bool paused)
        {
            NSUtils.Assert(action != null, "Argument action must be non-nil");
            NSUtils.Assert(target != null, "Argument target must be non-nil");

            tHashElement element = _targets.HASH_FIND_INT(target.GetHashCode());

            if (element == null)
            {
                element        = new tHashElement();
                element.paused = paused;
                element.target = target;
                _targets.HASH_ADD_INT(target.GetHashCode(), element);
            }
            actionAllocWithHashElement(element);

            NSUtils.Assert(!element.actions.Contains(action), "runAction: Action already running");
            element.actions.Add(action);

            action.startWithTarget(target);
        }