Ejemplo n.º 1
0
    //  Schedule jobs using this method
    public void ScheduleNewJob <T>(T job) where T : struct, IJob
    {
        JobHandle newHandle = IJobExtensions.Schedule <T>(job, previousDependency);

        allJobDependencies = JobHandle.CombineDependencies(newHandle, allJobDependencies);
        previousDependency = newHandle;
    }
Ejemplo n.º 2
0
        public static JobHandle AsyncEnqueue(NativeQueue <T> queue, T value, JobHandle dependency)
        {
            var job = new EnqueueJob <T>()
            {
                Queue = queue,
                Value = value
            };

            return(IJobExtensions.Schedule(job, dependency));
        }
Ejemplo n.º 3
0
        public static JobHandle AsycIterate <I>(
            NativeQueue <T> queue,
            I iterator,
            JobHandle dependency
            ) where I : struct, IQueueIterator <T>
        {
            (NativeArray <T> array, OutValue <int> count) = queue.InternalGetStorage();
            iterator.Store = array;
            iterator.Count = count;

            return(IJobExtensions.Schedule(iterator, dependency));
        }
Ejemplo n.º 4
0
        protected override JobHandle OnUpdate(JobHandle inputDependencies)
        {
            if (Input.GetMouseButtonDown(0))
            {
                _lastMousePosition = GetMouseWorldPosition();
            }
            else if (Input.GetMouseButton(0))
            {
                Vector3 mousePosition = GetMouseWorldPosition();

                // Debug.DrawLine(lastMousePosition , mousePosition, Color.red, 1f, false);

                var hitList = new NativeQueue <Hit>(Allocator.TempJob);

                CaptureInputJob job = new CaptureInputJob
                {
                    hitList           = hitList.AsParallelWriter(),
                    mousePosition     = mousePosition,
                    lastMousePosition = _lastMousePosition
                };

                inputDependencies = job.Schedule(this, inputDependencies);

                ProcessInputJob processJob = new ProcessInputJob
                {
                    HitList = hitList,
                    Buffer  = _commandBufferSystem.CreateCommandBuffer()
                };



                inputDependencies = IJobExtensions.Schedule(processJob, inputDependencies);

                inputDependencies = hitList.Dispose(inputDependencies);

                _commandBufferSystem.AddJobHandleForProducer(inputDependencies);

                _lastMousePosition = mousePosition;
            }

            return(inputDependencies);
        }
Ejemplo n.º 5
0
    protected override void OnUpdate()
    {
        EntityQuery fetchGTAWQuery = GetEntityQuery(fetchGTAWQueryDec); // query the entities
        ComponentDataFromEntity <GoToAndWaitStorage> storageComponents = GetComponentDataFromEntity <GoToAndWaitStorage>();

        NativeArray <Entity> fetchGTAWEntityArray         = fetchGTAWQuery.ToEntityArray(Allocator.TempJob);//get the array of entities
        NativeArray <FetchGoToAndWaitData> fetchGTAWArray = fetchGTAWQuery.ToComponentDataArray <FetchGoToAndWaitData>(Allocator.TempJob);

        FetchGTAWJob fetchJob = new FetchGTAWJob { // creates the "fetch go to and wait" job
            entityCommandBuffer = commandBufferSystem.CreateCommandBuffer(),
            entityArray         = fetchGTAWEntityArray,
            fetchGTAWArray      = fetchGTAWArray,
            storageComponents   = storageComponents
        };
        JobHandle jobHandle = IJobExtensions.Schedule(fetchJob, this.Dependency);

        commandBufferSystem.AddJobHandleForProducer(jobHandle); // tell the system to execute the command buffer after the job has been completed

        this.Dependency = jobHandle;
    }
    protected override void OnUpdate()
    {
        EntityQuery fetchWPQuery            = GetEntityQuery(fetchWPQueryDec);  // query the entities
        BufferFromEntity <WayPoint> buffers = GetBufferFromEntity <WayPoint>(); // used to access things with waypoint buffer
        ComponentDataFromEntity <FollowWayPointsStorage> storageComponents = GetComponentDataFromEntity <FollowWayPointsStorage>();

        NativeArray <Entity>         fetchWPEntityArray = fetchWPQuery.ToEntityArray(Allocator.TempJob);//get the array of entities
        NativeArray <FetchWayPoints> fetchWPArray       = fetchWPQuery.ToComponentDataArray <FetchWayPoints>(Allocator.TempJob);

        FetchWPJob fetchJob = new FetchWPJob { // creates the "follow waypoints" job
            entityCommandBuffer = commandBufferSystem.CreateCommandBuffer(),
            entityArray         = fetchWPEntityArray,
            fetchWayPointsArray = fetchWPArray,
            wpBuffers           = buffers,
            storageComponents   = storageComponents
        };
        JobHandle jobHandle = IJobExtensions.Schedule(fetchJob, this.Dependency);

        commandBufferSystem.AddJobHandleForProducer(jobHandle); // tell the system to execute the command buffer after the job has been completed

        this.Dependency = jobHandle;
    }
Ejemplo n.º 7
0
 public JobHandle ScheduleJob(JobHandle dependsOn)
 {
     return(IJobExtensions.Schedule <PostAttemptJob>(this, dependsOn));
 }
Ejemplo n.º 8
0
    private void UpdateParticlesForIJob()
    {
        NativeArray <DynamicBone.ParticleStruct> nativeArray1;

        ((NativeArray <DynamicBone.ParticleStruct>) ref nativeArray1).\u002Ector(this.m_Particles.Count, (Allocator)2, (NativeArrayOptions)1);
        NativeArray <DynamicBone.CollisionStruct> nativeArray2;

        ((NativeArray <DynamicBone.CollisionStruct>) ref nativeArray2).\u002Ector(this.m_Colliders.Count, (Allocator)2, (NativeArrayOptions)1);
        for (int index = 0; index < this.m_Particles.Count; ++index)
        {
            DynamicBone.Particle particle = this.m_Particles[index];
            ((NativeArray <DynamicBone.ParticleStruct>) ref nativeArray1).set_Item(index, new DynamicBone.ParticleStruct()
            {
                parentIndex        = particle.m_ParentIndex,
                damping            = particle.m_Damping,
                elasticity         = particle.m_Elasticity,
                stiffness          = particle.m_Stiffness,
                inert              = particle.m_Inert,
                radius             = particle.m_Radius,
                boneLength         = particle.m_BoneLength,
                isTransform        = !Object.op_Implicit((Object)particle.m_Transform) ? 0 : 1,
                transWorldPosition = !Object.op_Implicit((Object)particle.m_Transform) ? Vector3.get_zero() : particle.m_Transform.get_position(),
                transLocalPosition = !Object.op_Implicit((Object)particle.m_Transform) ? Vector3.get_zero() : particle.m_Transform.get_localPosition(),
                position           = particle.m_Position,
                prevPosition       = particle.m_PrevPosition,
                endOffset          = particle.m_EndOffset,
                initLocalPosition  = particle.m_InitLocalPosition,
                initLocalRotation  = particle.m_InitLocalRotation,
                worldMatrix        = !Object.op_Implicit((Object)particle.m_Transform) ? Matrix4x4.get_identity() : particle.m_Transform.get_localToWorldMatrix()
            });
        }
        for (int index = 0; index < this.m_Colliders.Count; ++index)
        {
            DynamicBoneCollider collider = this.m_Colliders[index] as DynamicBoneCollider;
            if (!Object.op_Equality((Object)collider, (Object)null) && ((Behaviour)collider).get_enabled())
            {
                ((NativeArray <DynamicBone.CollisionStruct>) ref nativeArray2).set_Item(index, new DynamicBone.CollisionStruct()
                {
                    direction   = collider.m_Direction,
                    center      = collider.m_Center,
                    bound       = collider.m_Bound,
                    radius      = collider.m_Radius,
                    height      = collider.m_Height,
                    lossyScale  = ((Component)collider).get_transform().get_lossyScale(),
                    worldMatrix = ((Component)collider).get_transform().get_localToWorldMatrix()
                });
            }
        }
        JobHandle jobHandle = IJobExtensions.Schedule <DynamicBone.CalcJob>((M0) new DynamicBone.CalcJob()
        {
            calcs       = nativeArray1,
            colls       = nativeArray2,
            weight      = this.m_Weight,
            objectScale = this.m_ObjectScale
        }, (JobHandle)null);

        ((JobHandle) ref jobHandle).Complete();
        for (int index = 0; index < this.m_Particles.Count; ++index)
        {
            this.m_Particles[index].m_Position = ((NativeArray <DynamicBone.ParticleStruct>) ref nativeArray1).get_Item(index).position;
        }
        ((NativeArray <DynamicBone.ParticleStruct>) ref nativeArray1).Dispose();
        ((NativeArray <DynamicBone.CollisionStruct>) ref nativeArray2).Dispose();
    }
Ejemplo n.º 9
0
 public JobHandle Schedule(JobHandle dependsOn = default)
 {
     return(IJobExtensions.Schedule(this, dependsOn));
 }
Ejemplo n.º 10
0
 public void Run()
 {
     IJobExtensions.Run(this);
 }
Ejemplo n.º 11
0
 public JobHandle ScheduleJob(JobHandle dependsOn)
 {
     return(IJobExtensions.Schedule <CopyKMeansCentroidsJob>(this, dependsOn));
 }
Ejemplo n.º 12
0
 public JobHandle ScheduleJob(JobHandle dependsOn)
 {
     return(IJobExtensions.Schedule <TrainIterationJob>(this, dependsOn));
 }