private void Start() { _camera = Camera.main; _steer = new Steer(_direction_number); _interesets = new List <Transform>(); _dangers = new List <Transform>(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var positions = allPlanets.GetComponentDataArray <Position>(); var headings = allPlanets.GetComponentDataArray <Heading>(); var speeds = allPlanets.GetComponentDataArray <MoveSpeed>(); var sunPos = suns.GetComponentDataArray <Position>(); sunPositions = new NativeArray <Position>(sunPos.Length, Allocator.Persistent); for (int i = 0; i < sunPos.Length; i++) { sunPositions[i] = sunPos[i]; } var steerJob = new Steer { headings = headings, planetPositions = positions, speeds = speeds, sunPositions = sunPositions }; var steerJobHandle = steerJob.Schedule(allPlanets.CalculateLength(), 64); steerJobHandle.Complete(); sunPositions.Dispose(); inputDeps = steerJobHandle; return(inputDeps); }
protected override void OnExit() { if (_isLast && _steer != null) { _steer.Reset(); } _steer = null; RpxPool <Runtime> .Release(this); }
// Use this for initialization void Start() { acceleration = Vector3.zero; velocity = transform.forward; //get component references characterController = gameObject.GetComponent<CharacterController> (); steer = gameObject.GetComponent<Steer> (); //gets reference to the steer GameObject main = GameObject.Find("MainGO"); attr = main.GetComponent<SteeringAttributes> (); }
// Use this for initialization void Start() { acceleration = Vector3.zero; velocity = transform.forward; //get component references characterController = gameObject.GetComponent <CharacterController> (); steer = gameObject.GetComponent <Steer> (); //gets reference to the steer GameObject main = GameObject.Find("MainGO"); attr = main.GetComponent <SteeringAttributes> (); }
void Start() { acceleration = Vector3.zero; velocity = transform.forward; obstacles = GameObject.FindGameObjectsWithTag("Obstacle"); //get component references characterController = gameObject.GetComponent <CharacterController> (); steer = gameObject.GetComponent <Steer> (); steeringAtt = GameObject.Find("MainGO").GetComponent <SteeringAttributes> (); gm = GameObject.Find("MainGO").GetComponent <GameManager>(); }
protected override void OnEnter() { _arrive = false; long now = SystemTime.GetTime(); long extra = (long)(cpx.duration * 1000); _duetime = now + extra; model.SetAnimator(AnimatorType.IS_RUNNING, AnimatorControllerParameterType.Bool, 1); _steer = model.GetAttach <Steer>() ?? model.Attach(new Steer()); _start = model.position; _calcPos = _start; _position = _start; LuaTable tb = machine.GetRuntimeData <LuaTable>(CpxState.TEMP_DATA); Vector3 dest, pos; if (!tb.TryGet("position", out pos)) { GlobalLogger.LogError(string.Format("{0} require position", this)); _status = CompStatus.COMPLETE; return; } if (!tb.TryGet("forcast", out dest)) { GlobalLogger.LogError(string.Format("{0} require forcast", this)); _status = CompStatus.COMPLETE; return; } _isLast = (bool)tb["isLast"]; if (now - _steer.prevTime > extra) { _steer.prevTime = now; } _prevTime = _steer.prevTime; if (_isLast) { _destiny = pos; } else { Vector3 dir = dest - pos; VectorMath.Truncate(ref dir, model.speed * 0.1f); _destiny = dir + pos; } _status = CompStatus.RUNING; }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var positions = allPlanets.GetComponentDataArray <Position>(); var headings = allPlanets.GetComponentDataArray <Heading>(); var speeds = allPlanets.GetComponentDataArray <MoveSpeed>(); var steerJob = new Steer { headings = headings, planetPositions = positions, speeds = speeds, sunPosition = sun.transform.position }; var steerJobHandle = steerJob.Schedule(allPlanets.CalculateLength(), 64); steerJobHandle.Complete(); inputDeps = steerJobHandle; return(inputDeps); }
public static Pose NextPose(Pose current, Steer steer, Gear gear, float speed, float dt, float turnRadius, out float length) { length = speed * dt; float x, y, phi; if (steer == Steer.Straight) { x = length; y = 0; phi = 0; } else { phi = length / turnRadius; float phiover2 = phi / 2; float sinPhi = (float)Math.Sin(phiover2); float L = 2 * sinPhi * turnRadius; x = L * (float)Math.Cos(phiover2); y = L * sinPhi; } if (steer == Steer.Right) { y = -y; phi = -phi; } if (gear == Gear.Backward) { x = -x; phi = -phi; } Vector2 pos = new Vector2(x, y); pos = Vector2.Transform(pos, Matrix.CreateRotationZ(current.Orientation)); return(new Pose(current.Position + pos, current.Orientation + phi)); }
public static Pose NextPose(Pose current, Steer steer, Gear gear, float speed, float dt, float turnRadius, out float length) { length = speed * dt; float x, y, phi; if (steer == Steer.Straight) { x = length; y = 0; phi = 0; } else { phi = length / turnRadius; float phiover2 = phi / 2; float sinPhi = (float)Math.Sin(phiover2); float L = 2 * sinPhi * turnRadius; x = L * (float)Math.Cos(phiover2); y = L * sinPhi; } if (steer == Steer.Right) { y = -y; phi = -phi; } if (gear == Gear.Backward) { x = -x; phi = -phi; } Vector2 pos = new Vector2(x, y); pos = Vector2.Transform(pos, Matrix.CreateRotationZ(current.Orientation)); return new Pose(current.Position + pos, current.Orientation + phi); }
void Update() { foreach (BoidUtil _boid in BoidList) { foreach (SteerBehaviour Steer in SteerBehaviours) { _boid.velocity += Steer.GetForce(BoidList, _boid, _boid.maxSpeed, FoodList, MenaceList, ActualWaypoint) * Steer.weight * Time.deltaTime; _boid.velocity = _boid.VelocityLimiter(_boid.velocity, _boid.maxSpeed); float distace = Vector3.Distance(_boid.transform.position, ActualWaypoint); if (distace < 1f) { WaypointIndex++; WaypointIndex = WaypointIndex >= WaypointsList.Count ? 0 : WaypointIndex; ActualWaypoint = WaypointsList.ToArray()[WaypointIndex]; } } _boid.transform.position += _boid.velocity * Time.deltaTime; } if (Input.GetKeyDown(KeyCode.S)) { Spawn(); } }
public SortNode(Steer s, Rank r) { m_s = s; m_r = r; }
public Admin(CommandManager c) { c.AddTab(GameRuleComplete, "gamerule"); c.AddAdminCommand(MassPardon, "masspardon"); c.AddAdminCommand(KillJava, "killjava"); c.AddAdminCommand(NickCommand, "nick"); c.AddAdminCommand(Say, "say"); c.AddAdminCommand(Say2, "say2"); c.AddAdminCommand(Kick, "kick"); c.AddAdminCommand(Ban, "ban"); c.AddAdminCommand(BanIP, "ban-ip", "banip"); c.AddAdminCommand(CleanBannedRegions, "cleanregionsbanned"); c.AddAdminCommand(VanillaCommands, "give"); c.AddAdminCommand(VanillaCommands, "enchant"); c.AddAdminCommand(VanillaCommands, "difficulty"); c.AddAdminCommand(VanillaCommands, "gamerule"); c.AddAdminCommand(VanillaCommands, "spawnpoint"); c.AddAdminCommand(VanillaCommands, "clear"); c.AddAdminCommand(VanillaCommands, "gamemode"); c.AddAdminCommand(VanillaCommands, "effect"); c.AddAdminCommand(VanillaCommands, "scoreboard"); c.AddAdminCommand(VanillaCommands, "weather"); c.AddAdminCommand(VanillaCommands, "toggledownfall"); c.AddAdminCommand(VanillaCommands, "setidletimeout"); c.AddAdminCommand(VanillaCommands, "op", "deop"); c.AddAdminCommand(VanillaCommands, "achievement"); c.AddAdminCommand(VanillaCommands, "blockdata"); c.AddAdminCommand(VanillaCommands, "clone"); c.AddAdminCommand(VanillaCommands, "defaultgamemode"); c.AddAdminCommand(VanillaCommands, "execute"); c.AddAdminCommand(VanillaCommands, "fill"); c.AddAdminCommand(VanillaCommands, "particle"); c.AddAdminCommand(VanillaCommands, "playsound"); c.AddAdminCommand(VanillaCommands, "setblock"); c.AddAdminCommand(VanillaCommands, "summon"); c.AddAdminCommand(VanillaCommands, "title"); c.AddAdminCommand(VanillaLoad, "vanillaload"); c.AddAdminCommand(VanillaUnload, "vanillaunload"); c.AddAdminCommand(VanillaStop, "vanillarestart"); c.AddAdminCommand(AllBack, "allback"); c.AddAdminCommand(OldRestart, null, "restart", "shutdown", "stop"); c.AddAdminCommand(ProxyStop, "proxystop"); c.AddAdminCommand((player, cmd, iarg) => { Threads.DebugThreads(); }, "debugthreads"); c.AddAdminCommand((player, cmd, iarg) => { player.TellSystem(Chat.Pink, "New Usage: /ban 30 username Reason for ban"); }, null, "ban30"); c.AddAdminCommand(VanillaSuspend, "vanillastop"); c.AddAdminCommand(VanillaResume, "vanillastart"); c.AddAdminCommand(Possess, "possess", "poss"); c.AddAdminCommand(Slots, "slots"); c.AddAdminCommand(Flush, "flush"); c.AddAdminCommand(Mode, "mode", "gm", "m"); c.AddAdminCommand(Teleport, "tp", "go"); c.AddAdminCommand(Crash, "crash"); c.AddAdminCommand((player, cmd, offset) => { if (cmd.Length != 4) { throw new UsageException("/ee effectID amplification duration"); } var ee = new EntityEffect(player.EntityID, (PlayerEffects)int.Parse(cmd [1]), int.Parse(cmd [2]), int.Parse(cmd [3])); player.Queue.Queue(ee); player.TellSystem(Chat.Purple, ee.ToString()); }, "ee"); #if DEBUG c.AddCommand((player, cmd, offset) => { var steer = new Steer(); steer.Action = Steer.Actions.Unmount; player.FromClient(steer); }, "steer"); #endif }
public ReedsSheppAction(Steer steer, Gear gear, float length) { Steer = steer; Gear = gear; Length = length; }
public void AddAction(Steer steer, Gear gear, float length) { Actions.Add(new ReedsSheppAction(steer, gear, length)); Length += Math.Abs(length); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityManager.GetAllUniqueSharedComponentData(m_UniqueTypes); var obstacleCount = m_ObstacleQuery.CalculateEntityCount(); var targetCount = m_TargetQuery.CalculateEntityCount(); // Cannot call [DeallocateOnJobCompletion] on Hashmaps yet, so doing own cleanup here // of the hashes created in the previous iteration. for (int i = 0; i < m_PrevFrameHashmaps.Count; ++i) { m_PrevFrameHashmaps[i].Dispose(); } m_PrevFrameHashmaps.Clear(); // Each variant of the Boid represents a different value of the SharedComponentData and is self-contained, // meaning Boids of the same variant only interact with one another. Thus, this loop processes each // variant type individually. for (int boidVariantIndex = 0; boidVariantIndex < m_UniqueTypes.Count; boidVariantIndex++) { var settings = m_UniqueTypes[boidVariantIndex]; m_BoidQuery.SetFilter(settings); var boidCount = m_BoidQuery.CalculateEntityCount(); if (boidCount == 0) { // Early out. If the given variant includes no Boids, move on to the next loop. // For example, variant 0 will always exit early bc it's it represents a default, uninitialized // Boid struct, which does not appear in this sample. continue; } // The following calculates spatial cells of neighboring Boids // note: working with a sparse grid and not a dense bounded grid so there // are no predefined borders of the space. var hashMap = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob); var cellIndices = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellObstaclePositionIndex = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellTargetPositionIndex = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellCount = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellObstacleDistance = new NativeArray <float>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellAlignment = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellSeparation = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var copyTargetPositions = new NativeArray <float3>(targetCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var copyObstaclePositions = new NativeArray <float3>(obstacleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); // The following jobs all run in parallel because the same JobHandle is passed for their // input dependencies when the jobs are scheduled; thus, they can run in any order (or concurrently). // The concurrency is property of how they're scheduled, not of the job structs themselves. var initialCellAlignmentJob = new CopyHeadings { headings = cellAlignment }; var initialCellAlignmentJobHandle = initialCellAlignmentJob.Schedule(m_BoidQuery, inputDeps); var initialCellSeparationJob = new CopyPositions { positions = cellSeparation }; var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(m_BoidQuery, inputDeps); var copyTargetPositionsJob = new CopyPositions { positions = copyTargetPositions }; var copyTargetPositionsJobHandle = copyTargetPositionsJob.Schedule(m_TargetQuery, inputDeps); var copyObstaclePositionsJob = new CopyPositions { positions = copyObstaclePositions }; var copyObstaclePositionsJobHandle = copyObstaclePositionsJob.Schedule(m_ObstacleQuery, inputDeps); // Cannot call [DeallocateOnJobCompletion] on Hashmaps yet, so adding resolved hashes to the list // so that theyre usable in the upcoming cell jobs and also have a straight forward cleanup. m_PrevFrameHashmaps.Add(hashMap); // setting up the jobs for position and cell count var hashPositionsJob = new HashPositions { hashMap = hashMap.AsParallelWriter(), cellRadius = settings.CellRadius }; var hashPositionsJobHandle = hashPositionsJob.Schedule(m_BoidQuery, inputDeps); var initialCellCountJob = new MemsetNativeArray <int> { Source = cellCount, Value = 1 }; var initialCellCountJobHandle = initialCellCountJob.Schedule(boidCount, 64, inputDeps); var initialCellBarrierJobHandle = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, initialCellCountJobHandle); var copyTargetObstacleBarrierJobHandle = JobHandle.CombineDependencies(copyTargetPositionsJobHandle, copyObstaclePositionsJobHandle); var mergeCellsBarrierJobHandle = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, copyTargetObstacleBarrierJobHandle); var mergeCellsJob = new MergeCells { cellIndices = cellIndices, cellAlignment = cellAlignment, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellObstaclePositionIndex = cellObstaclePositionIndex, cellTargetPositionIndex = cellTargetPositionIndex, cellCount = cellCount, targetPositions = copyTargetPositions, obstaclePositions = copyObstaclePositions }; var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle); var steerJob = new Steer { cellIndices = cellIndices, settings = settings, cellAlignment = cellAlignment, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellObstaclePositionIndex = cellObstaclePositionIndex, cellTargetPositionIndex = cellTargetPositionIndex, cellCount = cellCount, targetPositions = copyTargetPositions, obstaclePositions = copyObstaclePositions, dt = Time.deltaTime, }; var steerJobHandle = steerJob.Schedule(m_BoidQuery, mergeCellsJobHandle); inputDeps = steerJobHandle; m_BoidQuery.AddDependency(inputDeps); } m_UniqueTypes.Clear(); return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDependencies) { EntityManager.GetAllUniqueSharedComponentData(uniqueTypes); var obstacleCount = obstacleQuery.CalculateEntityCount(); var targetCount = targetQuery.CalculateEntityCount(); for (int i = 0; i < prevFrameHashmaps.Count; i++) { prevFrameHashmaps[i].Dispose(); } prevFrameHashmaps.Clear(); for (int hordeVariantIndex = 0; hordeVariantIndex < uniqueTypes.Count; hordeVariantIndex++) { var settings = uniqueTypes[hordeVariantIndex]; hordeQuery.SetFilter(settings); var hordeCount = hordeQuery.CalculateEntityCount(); if (hordeCount == 0) { continue; } //Debug.Log(hordeCount); #region Initial vars var hashMap = new NativeMultiHashMap <int, int>(hordeCount, Allocator.TempJob); var cellIndices = new NativeArray <int>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellObstaclePositionIndex = new NativeArray <int>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellTargetPositionIndex = new NativeArray <int>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellCount = new NativeArray <int>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellObstacleDistance = new NativeArray <float>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellAlignment = new NativeArray <float3>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellSeparation = new NativeArray <float3>(hordeCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var copyTargetPositions = new NativeArray <float3>(targetCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var copyObstaclePositions = new NativeArray <float3>(obstacleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); #endregion #region Initial jobs var initialCellAlignmentJob = new CopyHeadings { headings = cellAlignment }; var initialCellAlignmentJobHandle = initialCellAlignmentJob.Schedule(hordeQuery, inputDependencies); var initialCellSeparationJob = new CopyPositions { positions = cellSeparation }; var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(hordeQuery, inputDependencies); var copyTargetPositionsJob = new CopyPositions { positions = copyTargetPositions }; var copyTargetPositionsJobHandle = copyTargetPositionsJob.Schedule(targetQuery, inputDependencies); var copyObstaclePositionsJob = new CopyPositions { positions = copyObstaclePositions }; var copyObstaclePositionsJobHandle = copyObstaclePositionsJob.Schedule(obstacleQuery, inputDependencies); prevFrameHashmaps.Add(hashMap); var hashPositionsJob = new HashPositions { hashMap = hashMap.AsParallelWriter(), cellRadius = settings.CellRadius }; var hashPositionsJobHandle = hashPositionsJob.Schedule(hordeQuery, inputDependencies); var initialCellCountJob = new MemsetNativeArray <int> { Source = cellCount, Value = 1 }; var initialCellCountJobHandle = initialCellCountJob.Schedule(hordeCount, 64, inputDependencies); #endregion var initialCellBarrierJobHandle = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, initialCellCountJobHandle); var copyTargetObstacleBarrierJobHandle = JobHandle.CombineDependencies(copyTargetPositionsJobHandle, copyObstaclePositionsJobHandle); var mergeCellsBarrierJobHandle = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, copyTargetObstacleBarrierJobHandle); var mergeCellsJob = new MergeCells { cellIndices = cellIndices, cellAlignment = cellAlignment, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellObstaclePositionIndex = cellObstaclePositionIndex, cellTargetPositionIndex = cellTargetPositionIndex, cellCount = cellCount, targetPositions = copyTargetPositions, obstaclePositions = copyObstaclePositions }; var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle); var steerJob = new Steer { cellIndices = cellIndices, settings = settings, cellAlignment = cellAlignment, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellObstaclePositionIndex = cellObstaclePositionIndex, cellTargetPositionIndex = cellTargetPositionIndex, cellCount = cellCount, targetPositions = copyTargetPositions, obstaclePositions = copyObstaclePositions, dt = Time.deltaTime, }; var steerJobHandle = steerJob.Schedule(hordeQuery, mergeCellsJobHandle); inputDependencies = steerJobHandle; hordeQuery.AddDependency(inputDependencies); } uniqueTypes.Clear(); return(inputDependencies); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { BoidActionSort boidActionsSort = new BoidActionSort(); NonBoidActionSort nonBoidActionSort = new NonBoidActionSort(); EntityManager.GetAllUniqueSharedComponentData(m_UniqueTypes); int obstacleCount = m_ObstacleGroup.CalculateLength(); int targetCount = m_TargetGroup.CalculateLength(); // Ingore typeIndex 0, can't use the default for anything meaningful. for (int typeIndex = 1; typeIndex < m_UniqueTypes.Count; typeIndex++) { MainBoid uniqueBoidConfig = m_UniqueTypes[typeIndex]; m_BoidGroup.SetFilter(uniqueBoidConfig); int boidCount = m_BoidGroup.CalculateLength(); //some of this can be cached from last time to reduce component data calls. int cacheIndex = typeIndex - 1; //this was causing an undisposed allocation error //NativeArray<JobHandle> initializationJobHandles = new NativeArray<JobHandle>(5, Allocator.Temp); NativeArray <Heading> boidHeadings = m_BoidGroup.ToComponentDataArray <Heading>(Allocator.TempJob, out JobHandle initialCellAlignmentJobHandle); //TODO: make this into a 2d array so that the 2d positions doesnt have to be calculated all the time. NativeArray <Translation> boidPositions = m_BoidGroup.ToComponentDataArray <Translation>(Allocator.TempJob, out JobHandle initialCellSeparationJobHandle); NativeArray <Translation> copyTargetPositions = m_TargetGroup.ToComponentDataArray <Translation>(Allocator.TempJob, out JobHandle copyTargetPositionsJobHandle); NativeArray <Translation> copyObstaclePositions = m_ObstacleGroup.ToComponentDataArray <Translation>(Allocator.TempJob, out JobHandle copyObstaclePositionsJobHandle); // initializationJobHandles[0] = initialCellAlignmentJobHandle; // initializationJobHandles[1] = initialCellSeparationJobHandle; // initializationJobHandles[2] = copyTargetPositionsJobHandle; // initializationJobHandles[3] = copyObstaclePositionsJobHandle; NativeArray <BoidAction> orderedBoidActions = new NativeArray <BoidAction>(uniqueBoidConfig.boidActions.Length, Allocator.TempJob); orderedBoidActions.CopyFrom(uniqueBoidConfig.boidActions); NativeArray <NonBoidAction> orderedNonBoidActions = new NativeArray <NonBoidAction>(uniqueBoidConfig.boidActions.Length, Allocator.TempJob); orderedBoidActions.CopyFrom(uniqueBoidConfig.boidActions); orderedNonBoidActions.Sort(nonBoidActionSort); orderedBoidActions.Sort(boidActionsSort); var hashMap = new NativeHashMap <float3, int>(boidCount, Allocator.TempJob); var hashPositionsJob = new HashPositions { hashMap = hashMap.ToConcurrent() }; var hashPositionsJobHandle = hashPositionsJob.Schedule(m_BoidGroup, inputDeps); // initializationJobHandles[4] = hashPositionsJobHandle; var nextCells = new PrevCells { hashMap = hashMap, boidHeadings = boidHeadings, boidPositions = boidPositions, copyObstaclePositions = copyObstaclePositions, copyTargetPositions = copyTargetPositions, orderedBoidActions = orderedBoidActions, orderedNonBoidActions = orderedNonBoidActions, }; if (cacheIndex > (m_PrevCells.Count - 1)) { m_PrevCells.Add(nextCells); } else { m_PrevCells[cacheIndex].hashMap.Dispose(); m_PrevCells[cacheIndex].copyTargetPositions.Dispose(); m_PrevCells[cacheIndex].copyObstaclePositions.Dispose(); m_PrevCells[cacheIndex].boidHeadings.Dispose(); m_PrevCells[cacheIndex].boidPositions.Dispose(); m_PrevCells[cacheIndex].orderedBoidActions.Dispose(); m_PrevCells[cacheIndex].orderedNonBoidActions.Dispose(); } m_PrevCells[cacheIndex] = nextCells; JobHandle initialCellBarrierJobHandle = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, copyTargetPositionsJobHandle); JobHandle copyTargetObstacleBarrierJobHandle = JobHandle.CombineDependencies(initialCellBarrierJobHandle, copyObstaclePositionsJobHandle, hashPositionsJobHandle); Steer steerJob = new Steer { // boidActionFunctions = boidActionFunctions, //boidConfig = uniqueBoidConfig, boidIndexs = hashMap, boidHeadings = boidHeadings, boidPositions = boidPositions, orderedBoidActions = orderedBoidActions, orderedNonBoidActions = orderedNonBoidActions, targetPositions = copyTargetPositions, obstaclePositions = copyObstaclePositions, dt = Time.deltaTime }; JobHandle steerJobHandle = steerJob.Schedule(m_BoidGroup, copyTargetObstacleBarrierJobHandle); inputDeps = steerJobHandle; m_BoidGroup.AddDependency(inputDeps); } m_UniqueTypes.Clear(); return(inputDeps); }
void Start() { acceleration = Vector3.zero; velocity = transform.forward; obstacles = GameObject.FindGameObjectsWithTag ("Obstacle"); //get component references characterController = gameObject.GetComponent<CharacterController> (); steer = gameObject.GetComponent<Steer> (); steeringAtt = GameObject.Find("MainGO").GetComponent<SteeringAttributes> (); gm = GameObject.Find("MainGO").GetComponent<GameManager>(); }
protected override JobHandle OnUpdate(JobHandle inputDependencies) { Settings settings; settings.CellRadius = 16; settings.SeparationWeight = 1; settings.AlignmentWeight = 1; settings.TargetWeight = 2; settings.MaxTargetDistance = 10000; //settings.ObstacleAversionDistance = 35; settings.MoveSpeed = 25; settings.boidRadius = 0.5f; EntityManager.GetAllUniqueSharedComponentData(uniqueFactions); int healthCount = healthQuery.CalculateEntityCount(); for (int i = 0; i < prevFrameHashmaps.Count; i++) { prevFrameHashmaps[i].Dispose(); } prevFrameHashmaps.Clear(); for (int index = 0; index < uniqueFactions.Count; index++) { boidQuery.SetFilter(uniqueFactions[index]); int boidCount = boidQuery.CalculateEntityCount(); if (boidCount == 0) { continue; } var cellIndices = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var hashMap = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob); var cellObstacleDistance = new NativeArray <float>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellCount = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var killTrigger = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellAlignment = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellSeparation = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var boidsData = new NativeArray <Boid>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellTargetPositions = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellObstaclePositions = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var bulletSpawns = new NativeArray <BulletSpawn>(boidCount, Allocator.TempJob, NativeArrayOptions.ClearMemory); var damageDict = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob); var initialCellAlignmentJob = new CopyHeadings { headings = cellAlignment }; var initialCellAlignmentJobHandle = initialCellAlignmentJob.Schedule(boidQuery, inputDependencies); var initialCellSeparationJob = new CopyPositions { positions = cellSeparation }; var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(boidQuery, inputDependencies); var initialBoidData = new CopyBoids { boids = boidsData }; var initialBoidDataJobHandle = initialBoidData.Schedule(boidQuery, inputDependencies); // Cannot call [DeallocateOnJobCompletion] on Hashmaps yet prevFrameHashmaps.Add(hashMap); var hashPositionsJob = new HashPositions { hashMap = hashMap.AsParallelWriter(), cellRadius = settings.CellRadius }; var hashPositionsJobHandle = hashPositionsJob.Schedule(boidQuery, inputDependencies); var initialCellCountJob = new MemsetNativeArray <int> { Source = cellCount, Value = 1 }; var initialCellCountJobHandle = initialCellCountJob.Schedule(boidCount, 64, inputDependencies); var killTriggerJob = new MemsetNativeArray <int> { Source = killTrigger, Value = 0 }; var killTriggerJobHandle = killTriggerJob.Schedule(boidCount, 64, inputDependencies); var initialCellBarrierJobHandle = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, initialCellCountJobHandle); var initialBoidBarrierJobHandle = JobHandle.CombineDependencies(initialBoidDataJobHandle, killTriggerJobHandle); var mergeCellsBarrierJobHandle = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, initialBoidBarrierJobHandle); ref PhysicsWorld physicsWorld = ref Unity.Entities.World.Active.GetExistingSystem <BuildPhysicsWorld>().PhysicsWorld; var commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent(); prevFrameHashmaps.Add(damageDict); var mergeCellsJob = new MergeCells { cellIndices = cellIndices, cellObstaclePositions = cellObstaclePositions, cellTargetPositions = cellTargetPositions, cellAlignment = cellAlignment, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellCount = cellCount, boidsData = boidsData, killTrigger = killTrigger, physicsWorld = physicsWorld, damageDict = damageDict.AsParallelWriter(), bulletSpawns = bulletSpawns, commandBuffer = commandBuffer, bulletPrefab = BulletPrefabAuthoring.Prefab, //enemyEntityLook = Setup.enemyEntityLook, groupIndex = math.select(4u, 8u, uniqueFactions[index].Value == 0), time = Time.time, settings = settings, }; var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle); m_Barrier.AddJobHandleForProducer(mergeCellsJobHandle); var applyBulletSpawnDataJob = new ApplyBulletSpawnData { bulletSpawns = bulletSpawns, destroyAtTime = Time.time + 5, commandBuffer = commandBuffer, bulletPrefab = BulletPrefabAuthoring.Prefab }; var applyBulletSpawnDataJobHandle = applyBulletSpawnDataJob.Schedule(boidCount, 64, mergeCellsJobHandle); m_Barrier.AddJobHandleForProducer(applyBulletSpawnDataJobHandle); var updateBoidData = new UpdateBoidData { boidsData = boidsData }; var updateBoidDataJobHandle = updateBoidData.Schedule(boidQuery, applyBulletSpawnDataJobHandle); var steerJob = new Steer { cellIndices = cellIndices, settings = settings, cellAlignment = cellAlignment, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellCount = cellCount, targetPositions = cellTargetPositions, obstaclePositions = cellObstaclePositions, boidsData = boidsData, dt = Time.deltaTime, }; var steerJobHandle = steerJob.Schedule(boidQuery, updateBoidDataJobHandle); var killJob = new Kill { killTrigger = killTrigger, commandBuffer = commandBuffer, }; var killJobHandle = killJob.Schedule(boidQuery, steerJobHandle); m_Barrier.AddJobHandleForProducer(killJobHandle); var applyDamageJob = new ApplyDamage { damageDict = damageDict }; var applyDamageJobHandle = applyDamageJob.Schedule(healthQuery, mergeCellsJobHandle); inputDependencies = JobHandle.CombineDependencies(killJobHandle, applyDamageJobHandle, applyBulletSpawnDataJobHandle); boidQuery.AddDependency(inputDependencies); }
private void Awake() { _steer = new Steer(_directions_count); _walker = GetComponent <Walker>(); _looker = GetComponent <Looker>(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var boidCount = m_Boids.boidTag.Length; var cellIndices = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var hashMap = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob); var copyTargetPositions = new NativeArray <Position>(m_Boids.boidTarget.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var copyObstaclePositions = new NativeArray <Position>(m_Obstacles.obstaclePositions.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellSeparation = new NativeArray <Position>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellObstacleDistance = new NativeArray <float>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellObstaclePositionIndex = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellCount = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var hashPositionsJob = new HashPositions { positions = m_Boids.boidPositions, hashMap = hashMap, cellRadius = ECSBootstrapper.boidSettings.cellRadius }; var hashPositionsJobHandle = hashPositionsJob.Schedule(boidCount, 64, inputDeps); var initialCellSeparationJob = new CopyComponentData <Position> { Source = m_Boids.boidPositions, Results = cellSeparation }; var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(boidCount, 64, inputDeps); var initialCellCountJob = new MemsetNativeArray <int> { Source = cellCount, Value = 1 }; var initialCellCountJobHandle = initialCellCountJob.Schedule(boidCount, 64, inputDeps); var initialCellBarrierJobHandle = JobHandle.CombineDependencies(initialCellSeparationJobHandle, initialCellCountJobHandle); var copyTargetPositionJob = new CopyTargetPositions { Source = m_Boids.boidTarget, Results = copyTargetPositions }; var copyTargetPositionsJobHandle = copyTargetPositionJob.Schedule(m_Boids.boidTarget.Length, 2, inputDeps); var copyObstaclePositionsJob = new CopyComponentData <Position> { Source = m_Obstacles.obstaclePositions, Results = copyObstaclePositions }; var copyObstaclePositionsJobHandle = copyObstaclePositionsJob.Schedule(m_Obstacles.obstaclePositions.Length, 2, inputDeps); var copyTargetObstacleBarrierJobHandle = JobHandle.CombineDependencies(copyTargetPositionsJobHandle, copyObstaclePositionsJobHandle); var mergeCellsBarrierJobHandle = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, copyTargetObstacleBarrierJobHandle); var mergeCellsJob = new MergeCells { cellIndices = cellIndices, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellObstaclePositionIndex = cellObstaclePositionIndex, cellCount = cellCount, obstaclePositions = copyObstaclePositions }; var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle); var steerJob = new Steer { cellIndices = cellIndices, //D settings = ECSBootstrapper.boidSettings, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellObstaclePositionIndex = cellObstaclePositionIndex, cellCount = cellCount, targetPositions = copyTargetPositions, obstaclePositions = copyObstaclePositions, dt = Time.deltaTime, positions = m_Boids.boidPositions, headings = m_Boids.boidHeadings, }; var steerJobHandle = steerJob.Schedule(boidCount, 64, mergeCellsJobHandle); steerJobHandle.Complete(); cellIndices.Dispose(); hashMap.Dispose(); copyTargetPositions.Dispose(); copyObstaclePositions.Dispose(); cellSeparation.Dispose(); cellObstacleDistance.Dispose(); cellObstaclePositionIndex.Dispose(); cellCount.Dispose(); return(inputDeps); }
public static Pose NextPose(Pose current, Steer steer, Gear gear, float dt, out float length) { return(NextPose(current, steer, gear, SlowVelocity, dt, TurnRadius, out length)); }
private void LoadMetadata(SpecDB db) { if (TableName.StartsWith("CAR_NAME_")) { string locale = TableName.Split('_')[2]; if (locale.Equals("ALPHABET") || locale.Equals("JAPAN")) { locale = "UnistrDB.sdb"; } else { locale += "_StrDB.sdb"; } TableMetadata = new CarName(db.SpecDBFolderType, locale); } else if (TableName.StartsWith("CAR_VARIATION_")) { string locale = TableName.Split('_')[2]; if (locale.Equals("ALPHABET") || locale.Equals("JAPAN")) { locale = "UnistrDB.sdb"; } else { locale += "_StrDB.sdb"; } TableMetadata = new CarVariation(db.SpecDBFolderType, locale); } else if (TableName.StartsWith("COURSE_NAME_")) { string locale = TableName.Split('_')[2]; if (locale.Equals("ALPHABET") || locale.Equals("JAPAN")) { locale = "UnistrDB.sdb"; } else { locale += "_StrDB.sdb"; } TableMetadata = new CourseName(db.SpecDBFolderType, locale); } else if (TableName.StartsWith("VARIATION")) { string locale = "UnistrDB.sdb"; if (TableName.Length > 9) { locale = TableName.Substring(9); if (!locale.Equals("ALPHABET") && !locale.Equals("JAPAN")) { locale += "_StrDB.sdb"; } } TableMetadata = new Variation(db.SpecDBFolderType, locale); } else if (TableName.StartsWith("RIDER_EQUIPMENT")) { string locale = "UnistrDB.sdb"; if (TableName.Length > 15) { locale = TableName.Substring(15); if (!locale.Equals("ALPHABET") && !locale.Equals("JAPAN")) { locale += "_StrDB.sdb"; } } TableMetadata = new RiderEquipment(db.SpecDBFolderType, locale); } else { switch (TableName) { case "AIR_CLEANER": TableMetadata = new AirCleaner(db.SpecDBFolderType); break; case "ALLOW_ENTRY": TableMetadata = new AllowEntry(db.SpecDBFolderType); break; case "ARCADEINFO_NORMAL": case "ARCADEINFO_TUNED": TableMetadata = new ArcadeInfoNormal(db.SpecDBFolderType); break; case "ASCC": TableMetadata = new ASCC(db.SpecDBFolderType); break; case "BRAKE": TableMetadata = new Brake(db.SpecDBFolderType); break; case "BRAKECONTROLLER": TableMetadata = new BrakeController(db.SpecDBFolderType); break; case "CATALYST": TableMetadata = new Catalyst(db.SpecDBFolderType); break; case "CLUTCH": TableMetadata = new Clutch(db.SpecDBFolderType); break; case "COMPUTER": TableMetadata = new Computer(db.SpecDBFolderType); break; case "COURSE": TableMetadata = new Course(db.SpecDBFolderType); break; case "CAR_CUSTOM_INFO": TableMetadata = new CarCustomInfo(db.SpecDBFolderType); break; case "DEFAULT_PARAM": TableMetadata = new DefaultParam(db.SpecDBFolderType); break; case "DEFAULT_PARTS": TableMetadata = new DefaultParts(db.SpecDBFolderType); break; case "DISPLACEMENT": TableMetadata = new Displacement(db.SpecDBFolderType); break; case "DRIVETRAIN": TableMetadata = new Drivetrain(db.SpecDBFolderType); break; case "ENGINE": TableMetadata = new Engine(db.SpecDBFolderType); break; case "EXHAUST_MANIFOLD": TableMetadata = new ExhaustManifold(db.SpecDBFolderType); break; case "FLYWHEEL": TableMetadata = new Flywheel(db.SpecDBFolderType); break; case "GEAR": TableMetadata = new Gear(db.SpecDBFolderType); break; case "MAKER": TableMetadata = new Maker(db.SpecDBFolderType); break; case "MODEL_INFO": TableMetadata = new ModelInfo(db.SpecDBFolderType); break; case "PAINT_COLOR_INFO": TableMetadata = new PaintColorInfo(db.SpecDBFolderType); break; case "GENERIC_CAR": TableMetadata = new GenericCar(db.SpecDBFolderType); break; case "FRONTTIRE": TableMetadata = new FrontTire(db.SpecDBFolderType); break; case "REARTIRE": TableMetadata = new RearTire(db.SpecDBFolderType); break; case "RACINGMODIFY": TableMetadata = new RacingModify(db.SpecDBFolderType); break; case "CHASSIS": TableMetadata = new Chassis(db.SpecDBFolderType); break; case "INTAKE_MANIFOLD": TableMetadata = new IntakeManifold(db.SpecDBFolderType); break; case "LIGHTWEIGHT": TableMetadata = new Lightweight(db.SpecDBFolderType); break; case "LSD": TableMetadata = new Lsd(db.SpecDBFolderType); break; case "MUFFLER": TableMetadata = new Muffler(db.SpecDBFolderType); break; case "NATUNE": TableMetadata = new Natune(db.SpecDBFolderType); break; case "NOS": TableMetadata = new NOS(db.SpecDBFolderType); break; case "PROPELLERSHAFT": TableMetadata = new PropellerShaft(db.SpecDBFolderType); break; case "RACE": TableMetadata = new Race(db.SpecDBFolderType); break; case "STEER": TableMetadata = new Steer(db.SpecDBFolderType); break; case "SUPERCHARGER": TableMetadata = new Supercharger(db.SpecDBFolderType); break; case "SUSPENSION": TableMetadata = new Suspension(db.SpecDBFolderType); break; case "TIRECOMPOUND": TableMetadata = new TireCompound(db.SpecDBFolderType); break; case "TURBINEKIT": TableMetadata = new TurbineKit(db.SpecDBFolderType); break; case "GENERIC_ITEMS": TableMetadata = new GenericItems(db.SpecDBFolderType); break; case "TUNED_CARS": TableMetadata = new TunedCars(db.SpecDBFolderType); break; case "TUNER": TableMetadata = new Tuner(db.SpecDBFolderType); break; case "WHEEL": TableMetadata = new Wheel(db.SpecDBFolderType); break; // Unmapped, but havent seen having rows case "TCSC": TableMetadata = new TCSC(db.SpecDBFolderType); break; case "TIREFORCEVOL": TableMetadata = new TireForceVol(db.SpecDBFolderType); break; case "GENERIC_CAR_INFO": TableMetadata = new GenericCarInfo(db.SpecDBFolderType); break; case "INDEP_THROTTLE": TableMetadata = new IndepThrottle(db.SpecDBFolderType); break; case "INTERCOOLER": TableMetadata = new Intercooler(db.SpecDBFolderType); break; case "PORTPOLISH": TableMetadata = new PortPolish(db.SpecDBFolderType); break; case "WING": TableMetadata = new Wing(db.SpecDBFolderType); break; case "TUNER_LIST": TableMetadata = new TunerList(db.SpecDBFolderType); break; case "TIRESIZE": TableMetadata = new TireSize(db.SpecDBFolderType); break; case "ENEMY_CARS": TableMetadata = new EnemyCars(db.SpecDBFolderType); break; case "ENGINEBALANCE": TableMetadata = new EngineBalance(db.SpecDBFolderType); break; case "RIDER_SET_ASSIGN": TableMetadata = new RiderSetAssign(db.SpecDBFolderType); break; case "RIDER_SET": TableMetadata = new RiderSet(db.SpecDBFolderType); break; default: throw new NotSupportedException($"This table ({TableName}) is not yet mapped."); } for (int i = 0; i < TableMetadata.Columns.Count; i++) { TableMetadata.Columns[i].ColumnIndex = i; } } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityManager.GetAllUniqueSharedComponentData(m_UniqueTypes); var obstacleCount = m_ObstacleGroup.CalculateLength(); var targetCount = m_TargetGroup.CalculateLength(); // Ignore typeIndex 0, can't use the default for anything meaningful. for (int typeIndex = 1; typeIndex < m_UniqueTypes.Count; typeIndex++) { var settings = m_UniqueTypes[typeIndex]; m_BoidGroup.SetFilter(settings); var boidCount = m_BoidGroup.CalculateLength(); var cacheIndex = typeIndex - 1; var cellIndices = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var hashMap = new NativeMultiHashMap <int, int>(boidCount, Allocator.TempJob); var cellObstacleDistance = new NativeArray <float>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellObstaclePositionIndex = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellTargetPositionIndex = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellCount = new NativeArray <int>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellAlignment = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellSeparation = new NativeArray <float3>(boidCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var copyTargetPositions = new NativeArray <float3>(targetCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var copyObstaclePositions = new NativeArray <float3>(obstacleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var initialCellAlignmentJob = new CopyHeadings { headings = cellAlignment }; var initialCellAlignmentJobHandle = initialCellAlignmentJob.Schedule(m_BoidGroup, inputDeps); var initialCellSeparationJob = new CopyPositions { positions = cellSeparation }; var initialCellSeparationJobHandle = initialCellSeparationJob.Schedule(m_BoidGroup, inputDeps); var copyTargetPositionsJob = new CopyPositions { positions = copyTargetPositions }; var copyTargetPositionsJobHandle = copyTargetPositionsJob.Schedule(m_TargetGroup, inputDeps); var copyObstaclePositionsJob = new CopyPositions { positions = copyObstaclePositions }; var copyObstaclePositionsJobHandle = copyObstaclePositionsJob.Schedule(m_ObstacleGroup, inputDeps); var nextCells = new PrevCells { cellIndices = cellIndices, hashMap = hashMap, copyObstaclePositions = copyObstaclePositions, copyTargetPositions = copyTargetPositions, cellAlignment = cellAlignment, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellObstaclePositionIndex = cellObstaclePositionIndex, cellTargetPositionIndex = cellTargetPositionIndex, cellCount = cellCount }; if (cacheIndex > (m_PrevCells.Count - 1)) { m_PrevCells.Add(nextCells); } else { m_PrevCells[cacheIndex].hashMap.Dispose(); m_PrevCells[cacheIndex].cellIndices.Dispose(); m_PrevCells[cacheIndex].cellObstaclePositionIndex.Dispose(); m_PrevCells[cacheIndex].cellTargetPositionIndex.Dispose(); m_PrevCells[cacheIndex].copyTargetPositions.Dispose(); m_PrevCells[cacheIndex].copyObstaclePositions.Dispose(); m_PrevCells[cacheIndex].cellAlignment.Dispose(); m_PrevCells[cacheIndex].cellSeparation.Dispose(); m_PrevCells[cacheIndex].cellObstacleDistance.Dispose(); m_PrevCells[cacheIndex].cellCount.Dispose(); } m_PrevCells[cacheIndex] = nextCells; var hashPositionsJob = new HashPositions { hashMap = hashMap.ToConcurrent(), cellRadius = settings.CellRadius }; var hashPositionsJobHandle = hashPositionsJob.Schedule(m_BoidGroup, inputDeps); var initialCellCountJob = new MemsetNativeArray <int> { Source = cellCount, Value = 1 }; var initialCellCountJobHandle = initialCellCountJob.Schedule(boidCount, 64, inputDeps); var initialCellBarrierJobHandle = JobHandle.CombineDependencies(initialCellAlignmentJobHandle, initialCellSeparationJobHandle, initialCellCountJobHandle); var copyTargetObstacleBarrierJobHandle = JobHandle.CombineDependencies(copyTargetPositionsJobHandle, copyObstaclePositionsJobHandle); var mergeCellsBarrierJobHandle = JobHandle.CombineDependencies(hashPositionsJobHandle, initialCellBarrierJobHandle, copyTargetObstacleBarrierJobHandle); var mergeCellsJob = new MergeCells { cellIndices = cellIndices, cellAlignment = cellAlignment, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellObstaclePositionIndex = cellObstaclePositionIndex, cellTargetPositionIndex = cellTargetPositionIndex, cellCount = cellCount, targetPositions = copyTargetPositions, obstaclePositions = copyObstaclePositions }; var mergeCellsJobHandle = mergeCellsJob.Schedule(hashMap, 64, mergeCellsBarrierJobHandle); var steerJob = new Steer { cellIndices = nextCells.cellIndices, settings = settings, cellAlignment = cellAlignment, cellSeparation = cellSeparation, cellObstacleDistance = cellObstacleDistance, cellObstaclePositionIndex = cellObstaclePositionIndex, cellTargetPositionIndex = cellTargetPositionIndex, cellCount = cellCount, targetPositions = copyTargetPositions, obstaclePositions = copyObstaclePositions, dt = Time.deltaTime, }; var steerJobHandle = steerJob.Schedule(m_BoidGroup, mergeCellsJobHandle); inputDeps = steerJobHandle; m_BoidGroup.AddDependency(inputDeps); } m_UniqueTypes.Clear(); return(inputDeps); }
//----------------------------------------------------------------------------- protected override JobHandle OnUpdate(JobHandle inputDeps) { var settings = m_Agents.GridSettings[0]; var agentCount = m_Agents.Positions.Length; // process the previous frame if (m_PreviousJobData.IsValid && m_PreviousJobData.JobHandle.IsCompleted) { m_PreviousJobData.JobHandle.Complete(); // copy data back to the components var copyPrevJobHandle = new CopyPreviousResultsToAgentsJob { Positions = m_PreviousJobData.Positions, Rotations = m_PreviousJobData.Rotations, Velocities = m_PreviousJobData.Velocities, TargetReached = m_PreviousJobData.TargetReached, OutputPositions = m_Agents.Positions, OutputRotations = m_Agents.Rotations, OutputVelocities = m_Agents.Velocities, OutputTargetReached = m_Agents.TargetReached, }.Schedule(m_PreviousJobData.Length, 64, inputDeps); copyPrevJobHandle.Complete(); m_PreviousJobData.Goals.Dispose(); m_PreviousJobData.NeighborHashMap.Dispose(); } else if (m_PreviousJobData.IsValid && !m_PreviousJobData.JobHandle.IsCompleted) { return(inputDeps); } var positions = new NativeArray <Position>(agentCount, Allocator.TempJob); var copyPositions = new CopyComponentData <Position> { Source = m_Agents.Positions, Results = positions }.Schedule(agentCount, 64, inputDeps); var rotations = new NativeArray <Rotation>(agentCount, Allocator.TempJob); var copyRotation = new CopyComponentData <Rotation> { Source = m_Agents.Rotations, Results = rotations }.Schedule(agentCount, 64, inputDeps); var velocities = new NativeArray <Velocity>(agentCount, Allocator.TempJob); var copyVelocities = new CopyComponentData <Velocity> { Source = m_Agents.Velocities, Results = velocities }.Schedule(agentCount, 64, inputDeps); var goals = new NativeArray <Goal>(agentCount, Allocator.TempJob); var copyGoals = new CopyComponentData <Goal> { Source = m_Agents.Goals, Results = goals }.Schedule(agentCount, 64, inputDeps); var targetReached = new NativeArray <TargetReached>(agentCount, Allocator.TempJob); var copyTargetReached = new CopyComponentData <TargetReached> { Source = m_Agents.TargetReached, Results = targetReached }.Schedule(agentCount, 64, inputDeps); var copyJobs = JobHandle.CombineDependencies(JobHandle.CombineDependencies(copyPositions, copyRotation, copyVelocities), copyGoals, copyTargetReached); CopyFlowField(); var neighborHashMap = new NativeMultiHashMap <int, int>(agentCount, Allocator.TempJob); var vecFromNearestNeighbor = new NativeArray <float3>(agentCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var cellNeighborIndices = new NativeArray <int>(agentCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var neighborHashes = new NativeArray <int>(agentCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var avgNeighborPositions = new NativeArray <float3>(agentCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var avgNeighborVelocities = new NativeArray <float3>(agentCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); var steerParams = Main.ActiveSteeringParams; var neighborCellSize = steerParams.NeighbourHashCellSize; var hashNeighborPositionsJob = new HashPositionsWidthSavedHash { Positions = positions, HashMap = neighborHashMap, CellRadius = neighborCellSize, HashedPositions = neighborHashes }; var hashNeighborPositionsJobHandle = hashNeighborPositionsJob.Schedule(agentCount, 64, copyJobs); var mergeNeighborCellsJob = new MergeNeighborCells { cellIndices = cellNeighborIndices, }; var mergeNeighborCellsJobHandle = mergeNeighborCellsJob.Schedule(neighborHashMap, 64, hashNeighborPositionsJobHandle); var closestNeighborJob = new FindClosestNeighbor { CellHash = neighborHashMap, CellHashes = cellNeighborIndices, Positions = positions, ClosestNeighbor = vecFromNearestNeighbor, CellRadius = neighborCellSize, Hashes = neighborHashes, SteerParams = steerParams, AvgNeighborPositions = avgNeighborPositions, AvgNeighborVelocities = avgNeighborVelocities, Velocities = velocities }; var closestNeighborJobHandle = closestNeighborJob.Schedule(agentCount, 64, mergeNeighborCellsJobHandle); var steerJob = new Steer { Settings = settings, AvgVelocities = avgNeighborVelocities, AvgPositions = avgNeighborPositions, DeltaTime = Time.deltaTime, VecFromNearestNeighbor = vecFromNearestNeighbor, Positions = positions, Velocities = velocities, TerrainFlowfield = Main.TerrainFlow, Goals = goals, TargetReached = targetReached, FlowFields = m_AllFlowFields, FlowFieldLength = m_AllFlowFields.Length / TileSystem.k_MaxNumFlowFields, SteerParams = steerParams }; var speedJob = new PositionRotationJob { Velocity = velocities, Positions = positions, Rotations = rotations, TimeDelta = Time.deltaTime, SteerParams = steerParams, GridSettings = settings, Heights = Main.TerrainHeight, Normals = Main.TerrainNormals }; var steerJobHandle = steerJob.Schedule(agentCount, 64, closestNeighborJobHandle); var speedJobHandel = speedJob.Schedule(agentCount, 64, steerJobHandle); m_PreviousJobData = new PreviousJobData { JobHandle = speedJobHandel, IsValid = true, Positions = positions, Rotations = rotations, Velocities = velocities, Goals = goals, TargetReached = targetReached, NeighborHashMap = neighborHashMap, Length = agentCount, }; return(copyJobs); }
void OnSteer(InputValue value) { Steer?.Invoke(value.Get <float>()); horizantalInput = value.Get <float>(); }
public static Pose NextPose(Pose current, Steer steer, Gear gear, float dt, out float length) { return NextPose(current, steer, gear, SlowVelocity, dt, TurnRadius, out length); }