protected override JobHandle OnUpdate(JobHandle inputDeps) { var neighbors = new NeighborsDetectionJob { prodThresh = math.cos(math.radians(Bootstrap.Param.neighborFov)), distThresh = Bootstrap.Param.neighborDistance, neighborsFromEntity = GetBufferFromEntity <NeighborsEntityBuffer>(false), positionFromEntity = GetComponentDataFromEntity <Position>(true), entities = group.GetEntityArray(), }; var wall = new WallJob { scale = Bootstrap.Param.wallScale * 0.5f, thresh = Bootstrap.Param.wallDistance, weight = Bootstrap.Param.wallWeight, }; var separation = new SeparationJob { separationWeight = Bootstrap.Param.separationWeight, neighborsFromEntity = GetBufferFromEntity <NeighborsEntityBuffer>(true), positionFromEntity = GetComponentDataFromEntity <Position>(true), }; var alignment = new AlignmentJob { alignmentWeight = Bootstrap.Param.alignmentWeight, neighborsFromEntity = GetBufferFromEntity <NeighborsEntityBuffer>(true), velocityFromEntity = GetComponentDataFromEntity <Velocity>(true), }; var cohesion = new CohesionJob { cohesionWeight = Bootstrap.Param.cohesionWeight, neighborsFromEntity = GetBufferFromEntity <NeighborsEntityBuffer>(true), positionFromEntity = GetComponentDataFromEntity <Position>(true), }; var move = new MoveJob { dt = Time.deltaTime, minSpeed = Bootstrap.Param.minSpeed, maxSpeed = Bootstrap.Param.maxSpeed, }; inputDeps = neighbors.Schedule(this, inputDeps); inputDeps = wall.Schedule(this, inputDeps); inputDeps = separation.Schedule(this, inputDeps); inputDeps = alignment.Schedule(this, inputDeps); inputDeps = cohesion.Schedule(this, inputDeps); inputDeps = move.Schedule(this, inputDeps); return(inputDeps); }
void IEcsRunSystem.Run() { if (_filter.EntitiesCount == 0) { return; } if (FullBackground) { if (!CanRead) { jobHandle.Complete(); CanRead = true; } } var neighbors = new NeighborsDetectionJob { prodThresh = NeighborFov, distThresh = NeighborDistance, velocities = BoidEntityData.velocities, positions = BoidEntityData.positions, neighborsFromEntity = BoidEntityData.neighbors, entitiesCount = EntitiesCount }; var wall = new WallJob { scale = WallScale, thresh = WallDistance, weight = WallWeight, positions = BoidEntityData.positions, accelerations = BoidEntityData.accelerations, _right = new Float3(1, 0, 0), _up = new Float3(0, 1, 0), _fwd = new Float3(0, 0, 1), _left = new Float3(-1, 0, 0), _down = new Float3(0, -1, 0), _back = new Float3(0, 0, -1) }; var separation = new SeparationJob { separationWeight = SeparationWeight, entitiesCount = EntitiesCount, neighborsFromEntity = BoidEntityData.neighbors, positions = BoidEntityData.positions, accelerations = BoidEntityData.accelerations }; var alignment = new AlignmentJob { alignmentWeight = AlignmentWeight, entitiesCount = EntitiesCount, neighborsFromEntity = BoidEntityData.neighbors, velocities = BoidEntityData.velocities, accelerations = BoidEntityData.accelerations }; var cohesion = new CohesionJob { cohesionWeight = CohesionWeight, entitiesCount = EntitiesCount, neighborsFromEntity = BoidEntityData.neighbors, positions = BoidEntityData.positions, accelerations = BoidEntityData.accelerations }; var move = new MoveJob { dt = _timeSystem.DeltaTime, minSpeed = MinSpeed, maxSpeed = MaxSpeed, scale = BoidScale, positions = BoidEntityData.positions, velocities = BoidEntityData.velocities, accelerations = BoidEntityData.accelerations, matrices = BoidsVisualisationSystem._nativeMatrices }; jobHandle = neighbors.Schedule(EntitiesCount, NumBoidsPerJob); jobHandle = wall.Schedule(EntitiesCount, NumBoidsPerJob, jobHandle); jobHandle = separation.Schedule(EntitiesCount, NumBoidsPerJob, jobHandle); jobHandle = alignment.Schedule(EntitiesCount, NumBoidsPerJob, jobHandle); jobHandle = cohesion.Schedule(EntitiesCount, NumBoidsPerJob, jobHandle); jobHandle = move.Schedule(EntitiesCount, NumBoidsPerJob, jobHandle); JobHandle.ScheduleBatchedJobs(); if (FullBackground) { CanRead = false; } else { jobHandle.Complete(); CanRead = true; } }