Exemple #1
0
        protected override JobHandle OnUpdate(JobHandle deps)
        {
            deps = _BVH.Calculate(deps, _vehicleGroup.AABB);

            var senseJob = new SenseEnvironmentJob()
            {
                VehicleData        = _vehicleGroup.VehicleData,
                BVHArray           = _BVH.BVHArray,
                HitResult          = _vehicleGroup.HitResult,
                HalfBVHArrayLength = _BVH.BVHArray.Length / 2,
            };

            deps = senseJob.Schedule(Capacity, 64, deps);

            var vehicleMoveJob = new VehicleMoveJob()
            {
                Positions    = _vehicleGroup.Position,
                Rotations    = _vehicleGroup.Rotation,
                VehicleData  = _vehicleGroup.VehicleData,
                RoadNodes    = _roadNodes,
                RoadSegments = _roadSegments,
                RandSeed     = _randSeed,
                HitResult    = _vehicleGroup.HitResult,
                AABB         = _vehicleGroup.AABB,
                FrameSeed    = (uint)Time.frameCount,
                DeltaTime    = Time.deltaTime
            };

            deps = vehicleMoveJob.Schedule(Capacity, 64, deps);

            return(deps);
        }
        protected override JobHandle OnUpdate(JobHandle deps)
        {
            //temp container, deallocated in jobs
            var vehicleAABB          = _vehicleGroup.ToComponentDataArray <BVHAABB>(Allocator.TempJob);
            var vehicleData          = _vehicleGroup.ToComponentDataArray <VehicleData>(Allocator.TempJob);
            var vehicleHitresultTemp = _vehicleGroup.ToComponentDataArray <HitResult>(Allocator.TempJob);

            deps = _BVH.Calculate(deps, vehicleAABB);

            //Sense surrounding vehicles, write to vehicleHitResultTemp, the writing limit exceed chunk, so write to a temp first.
            deps = new SenseEnvironmentJob()
            {
                VehicleData        = vehicleData,
                BVHArray           = _BVH.BVHArray,
                HitResult          = vehicleHitresultTemp,
                HalfBVHArrayLength = _BVH.BVHArray.Length / 2,
            }.Schedule(_capacity, 64, deps);

            var hitResults = GetArchetypeChunkComponentType <HitResult>(false);

            //need to access entity id and write with id, dispatch a chunkjob
            deps = new WriteSenseResultJob()
            {
                HitResultTemp = vehicleHitresultTemp,
                HitResult     = hitResults
            }.Schedule(_vehicleGroup, deps);

            //move according to sense result
            deps = new VehicleMoveJob()
            {
                RoadNodes    = _roadNodeGroup.ToComponentDataArray <RoadNode>(Allocator.TempJob),
                RoadSegments = _roadSegmentGroup.ToComponentDataArray <RoadSegment>(Allocator.TempJob),
                FrameSeed    = (uint)UnityEngine.Time.frameCount,
                DeltaTime    = Time.DeltaTime,
                BoundingBox  = _bound,
                RdGens       = _rdGens
            }.Schedule(_vehicleGroup, deps);


            return(deps);
        }
        protected override JobHandle OnUpdate(JobHandle deps)
        {
            var vehicleAABB      = _vehicleGroup.GetComponentDataArray <BVHAABB>();
            var vehicleData      = _vehicleGroup.GetComponentDataArray <VehicleData>();
            var vehicleHitresult = _vehicleGroup.GetComponentDataArray <HitResult>();

            deps = _BVH.Calculate(deps, vehicleAABB);

            var senseJob = new SenseEnvironmentJob()
            {
                VehicleData        = vehicleData,
                BVHArray           = _BVH.BVHArray,
                HitResult          = vehicleHitresult,
                HalfBVHArrayLength = _BVH.BVHArray.Length / 2,
            };

            deps = senseJob.Schedule(Capacity, 64, deps);

            var vehicleMoveJob = new VehicleMoveJob()
            {
                Positions    = _vehicleGroup.GetComponentDataArray <Position>(),
                Rotations    = _vehicleGroup.GetComponentDataArray <Rotation>(),
                VehicleData  = vehicleData,
                RoadNodes    = _roadNodeGroup.GetComponentDataArray <RoadNode>(),
                RoadSegments = _roadSegmentGroup.GetComponentDataArray <RoadSegment>(),
                HitResult    = vehicleHitresult,
                AABB         = vehicleAABB,
                FrameSeed    = (uint)Time.frameCount,
                DeltaTime    = Time.deltaTime,
                BoundingBox  = _bound,
                rdGen        = new Unity.Mathematics.Random(_randSeed[Time.frameCount % _randSeed.Length])
            };

            deps = vehicleMoveJob.Schedule(Capacity, 64, deps);

            return(deps);
        }