private void CheckAndAdd()
 {
     if (jobs.Count < concurrent)
     {
         int num = concurrent - jobs.Count;
         for (int i = 0; i < num; i++)
         {
             if (coroutines.Count > 0)
             {
                 IEnumerator coroutine = coroutines.Dequeue();
                 CM_Job      job       = CM_Job.Make(coroutine).NotifyOnJobComplete(notifyOnJobComplete);
                 if (isRunning)
                 {
                     job.Start();
                 }
                 jobs.Add(job);
                 if (NotifyOnJobStarted != null)
                 {
                     NotifyOnJobStarted(coroutine);
                 }
             }
             else
             {
                 break;
             }
         }
     }
 }
    /// <summary>
    /// Creates coroutine job, starts job immediately and then pauses coroutine after 4 seconds. This
    /// paused job is then stored and can be resumed/killed from any class that has a reference to that job.
    /// </summary>
    public IEnumerator JobTestWithDelayedPause()
    {
        var job = CM_Job.Make(InfiniteTest("Job test with delayed pause running")).Start();

        job.Pause(4f);

        yield return(null);
    }
 /// <summary>
 /// Creates a new job to spawn prefabs, subscribes to JobComplete event (to log a message informing user that an object has spawned),
 /// sets the job to repeat, and finally starts the job.
 /// </summary>
 void Start()
 {
     CM_Job.Make(SpawnPrefab())
     .Repeat(numToSpawn)
     .NotifyOnJobComplete((object sender, CM_JobEventArgs e) => {
         Debug.Log("Object Spawned");
     }).Start();
 }
Esempio n. 4
0
        public ConsumptionShapesClearedReason(IStateTransitioner controller,
                                              IConsumerListener consumed, FSMStateID goToState)
            : base(FSMTransistion.AllConsumableShapesConsumed, goToState, controller)
        {
            m_Consumed = consumed;

            m_MarkCompleteJob = CM_Job.Make(MarkShouldTransition()).Repeatable();
        }
    /// <summary>
    /// Creates and starts a job that will repeat for 3 seconds.
    /// The job complete event is subscribed to, this is used to display how many times the job will be repeated.
    /// </summary>
    public IEnumerator InfinitelyRepeatableJobTest()
    {
        CM_Job.Make(PrintStringAfterDelay("Infinitely repeatable Test"))
        .NotifyOnJobComplete((object sender, CM_JobEventArgs e) => {
            Debug.Log("Job repeated " + e.job.numOfTimesExecuted + " times");
        })
        .Repeat().StopRepeat(3f).Start();

        yield return(null);
    }
    void Start()
    {
        _jobsToQueue = new CM_Job[queueSize];

        for (int i = 0; i < queueSize; i++)
        {
            _jobsToQueue [i] = CM_Job.Make(SmallJobForLargeQueue(i + 1));
        }

        CM_JobQueue.Make().Enqueue(_jobsToQueue).Start();
    }
 void Start()
 {
     _text = GetComponent <Text> ();
     CM_JobManager.Global.AddJob(
         CM_Job.Make(UpdateTime())
         .NotifyOnJobPaused((object sender, CM_JobEventArgs e) => {
         Debug.Log("Job Paused");
     })
         .NotifyOnJobResumed((object sender, CM_JobEventArgs e) => {
         Debug.Log("Job Resumed");
     }).Start());
 }
    /// <summary>
    /// Creates new job, subscribes to the job start and end events and then starts job to be
    /// run immediately.
    /// </summary>
    public IEnumerator JobTestWithStartAndEndEvents()
    {
        CM_Job.Make(PrintStringAfterDelay("Job test with start and end event subscription"))
        .NotifyOnJobStarted((object sender, CM_JobEventArgs e) => {
            Debug.Log("Started: job test with event subscription");
        })
        .NotifyOnJobComplete((object sender, CM_JobEventArgs e) => {
            Debug.Log("Finished: job test with event subscription");
        }).Start();

        yield return(null);
    }
    /// <summary>
    /// Creates and starts a job that will repeat three times.
    /// The job complete event is subscribed to, this is used to display how many times the job will be repeated.
    /// </summary>
    public IEnumerator MultipleRepeatableJobTest()
    {
        int numOfTimesToRepeat = 3;

        CM_Job.Make(PrintStringAfterDelay("Multiple repeatable test"))
        .NotifyOnJobComplete((object sender, CM_JobEventArgs e) => {
            Debug.Log("Job repeated " + e.job.numOfTimesExecuted + " of " + numOfTimesToRepeat + " times");
        })
        .Repeat(numOfTimesToRepeat).Start();

        yield return(null);
    }
    /// <summary>
    /// Enqueues the specified job.
    /// </summary>
    /// <param name="job">Job.</param>
    public CM_JobQueue Enqueue(CM_Job job)
    {
        job.NotifyOnJobComplete(HandlejobComplete);

        AddJobToQueue(job);

        if (_continousRunning && _jobQueue.Count == 1)
        {
            _jobQueue.Peek().Start();
        }

        return(this);
    }
 private CM_Job GetSimpleInfiniteTestJob(string output, string id)
 {
     return(CM_Job.Make(InfiniteTest(output), id)
            .NotifyOnJobPaused((object sender, CM_JobEventArgs e) => {
         Debug.Log(e.job.id + ": paused");
     })
            .NotifyOnJobResumed((object sender, CM_JobEventArgs e) => {
         Debug.Log(e.job.id + ": resumed");
     })
            .NotifyOnJobComplete((object sender, CM_JobEventArgs e) => {
         Debug.Log(e.job.id + ": complete, killed = " + e.job.jobKilled);
     }));
 }
Esempio n. 12
0
    protected virtual CM_Job MakeJob(string id, IEnumerator routine, bool addListenerToOnComplete = true)
    {
        var job = CM_Job.Make(routine);

        job.id = (id.IsNullOrEmpty()) ? uniqueGeneratedID :  id;

        if (addListenerToOnComplete)
        {
            job.NotifyOnJobComplete(HandlejobComplete);
        }

        return(job);
    }
    /// <summary>
    /// Creates a list of jobs, adds them to a newly created local queue and starts the queue.
    /// </summary>
    public IEnumerator SimpleLocalQueueTest()
    {
        // Creates a list of jobs with three entries.
        var jobsToQueue = new List <CM_Job> ()
        {
            CM_Job.Make(PrintStringAfterDelay("Simple global queue test: job one"), "job_1"),
            CM_Job.Make(PrintStringAfterDelay("Simple global queue test: job two"), "job_2"),
            CM_Job.Make(PrintStringAfterDelay("Simple global queue test: job three"), "job_3")
        };

        CM_JobQueue.Make().Enqueue(jobsToQueue).Start();

        yield return(null);
    }
    /// <summary>
    /// Adds a repeating job to a queue.
    /// Queue will not progress if a repeating job is added until that job is manually killed
    /// or has reached its set number of times to repeat.
    /// </summary>
    public IEnumerator AddRepeatingJobToQueueTest()
    {
        var jobsToQueue = new List <CM_Job> ()
        {
            CM_Job.Make(PrintStringAfterDelay("Repeating job added to queue test, job one")),
            CM_Job.Make(PrintStringAfterDelay("Repeating job added to queue test, job two")).Repeat(5),
            CM_Job.Make(PrintStringAfterDelay("Repeating job added to queue test, , job one"))
        };

        CM_JobQueue.Make()
        .Enqueue(jobsToQueue).Start();

        yield return(null);
    }
    /// <summary>
    /// Creates and starts a job that will repeat three times. Adds a child job that will also repeat three times.
    /// The job complete event and child job complete events are subscribed to, this is used to display how many times the job will be repeated.
    /// </summary>
    public IEnumerator MutltipleRepeatableJobTestWithChild()
    {
        int numOfTimesToRepeat = 3;

        CM_Job.Make(PrintStringAfterDelay("Repeating test with child"))
        .AddChild(PrintStringAfterDelay("Repeating test (child)"))
        .NotifyOnJobComplete((object sender, CM_JobEventArgs e) => {
            Debug.Log("Parent job repeated " + e.job.numOfTimesExecuted + " of " + numOfTimesToRepeat + " times");
        })
        .NotifyOnChildJobComplete((object sender, CM_JobEventArgs e) => {
            Debug.Log("Child job repeated " + (e.job.numOfTimesExecuted + 1) + " of " + numOfTimesToRepeat + " times");
        })
        .Repeat(numOfTimesToRepeat).Start();

        yield return(null);
    }
    /// <summary>
    /// Child job test. Creates new job, adds two children (parent will not complete until children have finished processing)
    /// and starts the job.
    /// </summary>
    public IEnumerator ChildJobTest()
    {
        CM_Job.Make(PrintStringAfterDelay("Parent job test")).AddChild(PrintStringAfterDelay("Child1 job test")).AddChild(PrintStringAfterDelay("Child2 job test"))
        .NotifyOnChildJobStarted((object sender, CM_JobEventArgs e) => {
            if (e.hasChildJobs)
            {
                Debug.Log(e.childJobs.Length + " child jobs to process");
            }
        })
        .NotifyOnChildJobComplete((object sender, CM_JobEventArgs e) => {
            if (e.hasChildJobs)
            {
                Debug.Log("Finished processing " + e.childJobs.Length + " child jobs");
            }
        })
        .NotifyOnJobComplete((object sender, CM_JobEventArgs e) => {
            Debug.Log("Parent job completed");
        }).Start();

        yield return(null);
    }
Esempio n. 17
0
    /// <summary>
    /// Adds a job to the job manager.
    /// </summary>
    /// <returns>The job.</returns>
    /// <param name="job">Job.</param>
    public CM_JobManager AddJob(CM_Job job)
    {
        if (job.id.IsNullOrEmpty())
        {
            CM_Logger.instance.Log(this, "Job id is null or empty, an id will be auto generated");
            AutoGenerateJobId(job);
        }

        if (_ownedJobs.ContainsKey(job.id))
        {
            CM_Logger.instance.Log(this, "Attempted to add job with an id already present, " +
                                   "use a unique id when adding a job. Job will be created but not added to job manager.");
        }
        else
        {
            _ownedJobs.Add(job.id, job);

            OnJobAdded(new CM_JobManagerJobEditedEventArgs(_ownedJobs, job));
        }

        return(this);
    }
 /// <summary>
 /// Creates and returns a job to be cloned in tests.
 /// </summary>
 /// <returns>The job to clone.</returns>
 private CM_Job GetJobToClone()
 {
     return(CM_Job.Make(PrintStringAfterDelay("Clone job test"), "cloned_id")
            .NotifyOnJobStarted((object sender, CM_JobEventArgs e) => {
         Debug.Log("Cloned job started");
     })
            .NotifyOnJobPaused((object sender, CM_JobEventArgs e) => {
         Debug.Log("Cloned job paused");
     })
            .NotifyOnJobResumed((object sender, CM_JobEventArgs e) => {
         Debug.Log("Cloned job resumed");
     })
            .NotifyOnJobComplete((object sender, CM_JobEventArgs e) => {
         Debug.Log("Cloned job complete");
     })
            .NotifyOnChildJobStarted((object sender, CM_JobEventArgs e) => {
         Debug.Log("Cloned child jobs started");
     })
            .NotifyOnChildJobComplete((object sender, CM_JobEventArgs e) => {
         Debug.Log("Cloned child jobs completed");
     })
            .AddChild(PrintStringAfterDelay("Clone Child Test")));
 }
Esempio n. 19
0
    IEnumerator Duel_WaitInput()
    {
        DebugAdd("# 입력 대기 시작");

        m_Count = 0;
        CM_Job.Make(Duel_Counting())
        .Repeat(10)
        .NotifyOnJobComplete((object sender, CM_JobEventArgs e) => {
            DebugAdd(string.Format("input Count {0}", m_Count));
        }).Start();

        while (true)
        {
            if (m_Count == 10)
            {
                break;
            }

            yield return(null);
        }

        DebugAdd("# 입력 대기 종료");
    }
 private void RemoveJobFromQueue(CM_Job job)
 {
     job.RemoveNotifyOnJobComplete(HandlejobComplete);
     _completedJobs.Add(job);
     _jobQueue.Dequeue();
 }
Esempio n. 21
0
 public ShowShapesAction(List <ShapeControl> shapes)
 {
     m_ConsumableShapes = shapes;
     m_ShowShapesJob    = CM_Job.Make(ShowShapes()).Repeatable().Start();
 }
Esempio n. 22
0
 public ShowConsumedShapesAction(IConsumerListener consumables)
 {
     m_Consumables   = consumables;
     m_ShowShapesJob = CM_Job.Make(ShowShapes()).Repeatable();
 }
Esempio n. 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CM_JobEventArgs"/> class.
        /// </summary>
        /// <param name="job">Job.</param>
        /// <param name="childJobs">Child jobs.</param>
        public CM_JobEventArgs(CM_Job job, CM_Job[] childJobs)
        {
            this.job = job;

            this.childJobs = (childJobs != null) ? childJobs : new CM_Job[0];
        }
Esempio n. 24
0
    /// <summary>
    /// Resumes the specified coroutine if owned by this instance of job manager. Job is searched using job id.
    /// </summary>
    /// <returns>The job manager.</returns>
    /// <param name="job">Job.</param>
    public CM_JobManager ResumeCoroutine(CM_Job job)
    {
        ResumeCoroutine(job.id);

        return(this);
    }
Esempio n. 25
0
 /// <summary>
 /// Determines whether the specified job is executing.
 /// </summary>
 /// <returns><c>true</c> if the job is currently running; otherwise, <c>false</c>.</returns>
 /// <param name="job">Job.</param>
 public bool IsRunning(CM_Job job)
 {
     return(IsRunning(job.id));
 }
Esempio n. 26
0
    /// <summary>
    /// Pauses the specified coroutine if owned by this instance of job manager. Job is searched using job id.
    /// </summary>
    /// <returns>The job manager.</returns>
    /// <param name="job">Job.</param>
    public CM_JobManager PauseCoroutine(CM_Job job)
    {
        PauseCoroutine(job.id);

        return(this);
    }
Esempio n. 27
0
    /// <summary>
    /// Stops the specified coroutine if owned by this instance of job manager. Job is searched using job id.
    /// </summary>
    /// <returns>The job manager.</returns>
    /// <param name="job">Job.</param>
    public CM_JobManager StopCoroutine(CM_Job job)
    {
        StopCoroutine(job.id);

        return(this);
    }
Esempio n. 28
0
 /// <summary>
 /// Removes the job if owned by this instance of job manager.
 /// </summary>
 /// <returns>The job manager.</returns>
 /// <param name="job">Job.</param>
 public CM_JobManager RemoveJob(CM_Job job)
 {
     return(RemoveJob(job.id));
 }
Esempio n. 29
0
 void Start()
 {
     m_ButtonBounceJob = CM_Job.Make(PlayButtonBounceAnimation()).Repeatable();
 }
 private void AddJobToQueue(CM_Job job)
 {
     _jobQueue.Enqueue(job);
 }