public CoroutineState(IEnumerator enumerator, RecurranceParameters rp = null)
        {
            if (enumerator == null) throw new ArgumentNullException("enumerator");
            this.Enumerator = enumerator;

            RecurranceParameters = rp;
        }
Пример #2
0
        //private Coroutine(RecurranceParameters recurranceParameters = null)
        //{
        //    this.RecurranceParameters = recurranceParameters;
        //}

        public static Coroutine Start(IEnumerator coroutine, object owner = null, RecurranceParameters recurranceParameters = null)
        {
            var host = GetCoroutineHost(owner);

            var c = new Coroutine();
            c.State = host.EnqueueCoroutine(coroutine, recurranceParameters);
            return c;
        }
Пример #3
0
        /// <summary>
        /// Run coroutine once immediately.  Returns null if the coroutine finished.
        /// </summary>
        /// <param name="owner">owner must provide a CoroutineHost by implementing IHasCoroutineHost.CoroutineHost, or the static Coroutine.DefaultCoroutineHost must be set</param>
        /// <param name="coroutine"></param>
        /// <param name="recurranceParameters"></param>
        /// <returns></returns>
        public static Coroutine StartImmediately(IEnumerator coroutine, object owner = null, RecurranceParameters recurranceParameters = null)
        {
            var host = GetCoroutineHost(owner);

            var state = host.RunCoroutine(coroutine, recurranceParameters);
            if (state == null) return null; // Finished right away

            var c = new Coroutine();
            c.State = state;
            return c;
        }
Пример #4
0
 public ScorePoller(IPolledScorer polled, RecurranceParameters recurranceParameters = null)
 {
     if (recurranceParameters == null)
     {
         var hasRP = polled as IHasScorerRecurranceParameters;
         if (hasRP != null)
         {
             recurranceParameters = hasRP.ScorerRecurranceParameters;
         }
     }
     SetPolledAndRP(polled, recurranceParameters);
 }
 public StatusPoller(IPolledStatus polled, RecurranceParameters recurranceParameters = null
     //, object context = null
     ) 
 {
     if (recurranceParameters == null)
     {
         var hasRP = polled as IHasStatusRecurranceParameters;
         if (hasRP != null)
         {
             recurranceParameters = hasRP.RecurranceParameters;
         }
     }
     SetPolledAndRP(polled, recurranceParameters); 
 }
Пример #6
0
        protected void SetPolledAndRP(object polled, RecurranceParameters recurranceParameters)
        {
            this.PollTarget = polled; // Also sets context

            if (recurranceParameters != null)
            {
                RecurranceParameters = recurranceParameters;
            }
            else
            {
                IHasRecurranceParameters hasRP = polled as IHasRecurranceParameters;
                if (hasRP != null)
                {
                    RecurranceParameters = hasRP.RecurranceParameters;
                }
            }
        }
Пример #7
0
        protected override BehaviorStatus OnStart()
        {
            coroutineRecurranceParameters = new RecurranceParameters() // TODO - clone
            {
                Interval = this.RecurranceParameters.Interval,
                StartImmediately = this.RecurranceParameters.StartImmediately,
            };
            
            if (behaviorCoroutine == null)
            {
                behaviorCoroutine = new BehaviorCoroutine(this, CheckTime, coroutineRecurranceParameters);
            }
            // else bc will respond to start

            //Coroutine.Start(CheckTime, this.Context, this.RecurranceParameters);
            return base.OnStart();
        }
        public BehaviorCoroutine(IBehavior behavior, IEnumerator enumerator, RecurranceParameters recurranceParameters = null)
        {
            if (behavior == null) throw new ArgumentNullException("behavior");
            if (enumerator == null) throw new ArgumentNullException("enumerator");
            this.behavior = behavior;
            this.enumerator = enumerator;
            this.recurranceParameters = recurranceParameters;

            #region this.coroutineHost = ...
            // OLD
            //public static CoroutineHost DefaultCoroutineHost;
            //this.coroutineHost = coroutineHost;

            //if (coroutineHost == null)
            //{
            //    IHasCoroutineHost hasCH = behavior.Context as IHasCoroutineHost;
            //    if (hasCH != null) coroutineHost = hasCH.CoroutineHost;
            //}

            //if (coroutineHost == null)
            //{
            //    coroutineHost = DefaultCoroutineHost;
            //}

            //if (coroutineHost == null)
            //{
            //    throw new ArgumentNullException("CoroutineHost must be set by behavior.Context (which implements IHasCoroutineHost), or in BehaviorCoroutine.DefaultCoroutineHost.");
            //}

            #endregion
            
            behavior.StatusChangedForFromTo += OnBehaviorStatusChanged;

            if (behavior.IsRunning)
            {
                StartCoroutine();
            }
        }
Пример #9
0
        int backlog = 0; // TODO: Attach to child status and when it finishes, decrement backlog and launch another

        #endregion

        #region Construction

        public OldPollingRepeater(IBehavior behavior, RecurranceParameters recurranceParameters = null)
        {
            l.Warn("TODO: Obsolete OldPollingRepeater - get interval support in new Repeater");
            behavior.Parent = this; // TODO - how to automatically set Parents 
            //this.behavior = behavior;

            //if (recurranceParameters == null)
            //{
            //    var hasRP = behavior as IHasStartRecurranceParameters;
            //    if (hasRP != null)
            //    {
            //        recurranceParameters = hasRP.StartRecurranceParameters;
            //    }
            //}
            SetPolledAndRP(behavior, recurranceParameters);
        }
Пример #10
0
 public IntervalRepeater(IBehavior behavior, RecurranceParameters recurranceParameters = null)
     : base(behavior)
 {
     this.RecurranceParameters = recurranceParameters;
 }