コード例 #1
0
ファイル: CustomJob.cs プロジェクト: takaaptech/Voxelis
        public virtual void Depends(CustomJob dependency)
        {
            if (dependency == null)
            {
                return;
            }                                  // Probably we depends on an "AlreadyFinished" job.

            // TODO: dependency.followingTasks is a LinkedList; dependencies may overlap due to chunk locking. currently this was not cared and dependencies are let to be duplicated.
            dependency.followingTasks.AddLast(this);
            dependenciesCount += 1;
        }
コード例 #2
0
ファイル: CustomJob.cs プロジェクト: takaaptech/Voxelis
        // Try to add a job to current queue. If the job is already presented, the existing job will be returned; If the job is already finished, null will be returned; otherwise the job itself will be returned.
        public static CustomJob TryAddJob(CustomJob job, OnFinishCallback finishCallback = null)
        {
#if PROFILE
            UnityEngine.Profiling.Profiler.BeginSample("CustomJob.TryAddJob");
#endif
            if (job.isUnique)
            {
                if (queuedUniqueJobs.ContainsKey(job))
                {
                    //Debug.Log($"{job.ToString()} has already been queued.");
                    queuedUniqueJobs[job].finishCallback += finishCallback;
#if PROFILE
                    Profiler.EndSample();
#endif
                    return(queuedUniqueJobs[job]);
                }

                // Check if job is already finished
                job.finishCallback = finishCallback;
                if (job.AlreadyFinished())
                {
                    job.OnFinish();
#if PROFILE
                    Profiler.EndSample();
#endif
                    return(null);
                }

                job.InitJob();
                queuedUniqueJobs.Add(job, job);
                Count += 1;
                job.Schedule();
            }
            else
            {
                job.InitJob();
                Count += 1;
                job.Schedule();
            }

#if PROFILE
            Profiler.EndSample();
#endif

            return(job);
        }