Пример #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);
        }
Пример #2
0
        protected override JobHandle OnUpdate(JobHandle deps)
        {
            _position    = _vehicleGroup.GetComponentDataArray <Position>();
            _rotation    = _vehicleGroup.GetComponentDataArray <Rotation>();
            _vehicleData = _vehicleGroup.GetComponentDataArray <VehicleData>();
            _hitResult   = _vehicleGroup.GetComponentDataArray <HitResult>();

            //RoadGraph.Instance.VehicleData = _vehicleData;

            var commands = new NativeArray <RaycastCommand>(Capacity, Allocator.TempJob);
            var hits     = new NativeArray <RaycastHit>(Capacity, Allocator.TempJob);

            // 1: Setup Raycast for environment sensing
            var setupRaycastJob = new SetupRaycastJob
            {
                Commands    = commands,
                VehicleData = _vehicleData,
            };

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

            // 2: Raycast jobs
            deps = RaycastCommand.ScheduleBatch(commands, hits, 64, deps);

            // 3: Transfer raycast result to vehicledata
            var transferJob = new TransferRaycastResultJob
            {
                Commands    = commands,
                RaycastHits = hits,
                HitResult   = _hitResult
            };

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

            // 4: move vehicle
            var vehicleMoveJob = new VehicleMoveJob()
            {
                Positions    = _position,
                Rotations    = _rotation,
                VehicleData  = _vehicleData,
                RoadNodes    = _roadNodes,
                RoadSegments = _roadSegments,
                RandSeed     = _randSeed,
                HitResult    = _hitResult
            };

            vehicleMoveJob.FrameSeed = (uint)Time.frameCount;
            vehicleMoveJob.DeltaTime = Time.deltaTime;
            deps = vehicleMoveJob.Schedule(Capacity, 64, deps);

            return(deps);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }