protected override void OnUpdate() { EntityQuery entityQuery = GetEntityQuery(typeof(Translation), typeof(QuadrantEntity)); quadrantMap.Clear(); if (entityQuery.CalculateEntityCount() > quadrantMap.Capacity) { quadrantMap.Capacity = entityQuery.CalculateEntityCount(); } // Create Job SetQuadrantDataHashMapJob job = new SetQuadrantDataHashMapJob { hashMap = quadrantMap.AsParallelWriter() }; // Schedule and complete Job JobHandle jobHandle = JobForEachExtensions.Schedule(job, entityQuery); jobHandle.Complete(); DebugDrawQuadrant(UtilsClass.GetMouseWorldPosition()); int quadrantKey = GetKeyFromPosition(UtilsClass.GetMouseWorldPosition()); int entityCount = GetEntityCountInQuadrant(quadrantKey); Debug.Log("There are " + entityCount + " in Quadrant " + quadrantKey); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var settings = GetSingleton <SettingsComponent>(); if (_positionsQuery.CalculateEntityCount() == settings.Width * settings.Height) { return(inputDeps); } var helper = new ArrayHelper(settings.Width, settings.Height); var cachedEntities = new NativeArray <Entity>(settings.Width * settings.Height, Allocator.TempJob); var cacheJob = new CacheJob { CachedEntities = cachedEntities, Entities = _positionsQuery.ToEntityArray(Allocator.TempJob), Positions = _positionsQuery.ToComponentDataArray <PositionComponent>(Allocator.TempJob), Helper = helper }; var jobHandle = cacheJob.Schedule(_positionsQuery.CalculateEntityCount(), 32, inputDeps); var moveJob = new MoveJob { CachedEntities = cachedEntities, Position = GetComponentDataFromEntity <PositionComponent>(), Helper = helper }; jobHandle = moveJob.Schedule(jobHandle); return(jobHandle); }
protected override void OnUpdate() { EntityQuery entityQuery = GetEntityQuery(typeof(Translation), typeof(QuadrantEntity)); quadrantMultiHashMap.Clear(); if (entityQuery.CalculateEntityCount() > quadrantMultiHashMap.Capacity) { quadrantMultiHashMap.Capacity = entityQuery.CalculateEntityCount(); } NativeMultiHashMap <int, QuadrantData> .ParallelWriter quadrantMultiHashMap2 = quadrantMultiHashMap.AsParallelWriter(); //TODO smells Entities.ForEach((Entity entity, Translation t, ref QuadrantEntity qe, in InfectionComponent ic) => { if (ic.infected) { int hashMapKey = GetPositionHashMapKey(t.Value); //Debug.Log(hashMapKey); quadrantMultiHashMap2.Add(hashMapKey, new QuadrantData { entity = entity, position = t.Value, quadrantEntity = qe }); } }).ScheduleParallel(); }
protected override void OnUpdate() { VehiclesSegmentsHashMap.Clear(); EntityQuery entityQuery = GetEntityQuery(typeof(VehiclePositionComponent)); if (entityQuery.CalculateEntityCount() > VehiclesSegmentsHashMap.Capacity) { VehiclesSegmentsHashMap.Capacity = entityQuery.CalculateEntityCount(); } NativeMultiHashMap <Entity, VehicleSegmentData> .ParallelWriter multiHashMap = VehiclesSegmentsHashMap.AsParallelWriter(); Dependency = Entities.ForEach((Entity entity, int entityInQueryIndex, in VehicleSegmentInfoComponent vehicleSegmentInfoComponent, in VehiclePositionComponent vehiclePositionComponent, in VehicleConfigComponent vehicleConfigComponent) => { Entity segmentEntity = vehicleSegmentInfoComponent.IsBackInPreviousSegment ? vehicleSegmentInfoComponent.PreviousSegment : vehicleSegmentInfoComponent.HeadSegment; multiHashMap.Add(segmentEntity, new VehicleSegmentData { Entity = entity, BackSegPosition = vehiclePositionComponent.BackSegPos, VehicleSize = vehicleConfigComponent.Length }); }).ScheduleParallel(Dependency);
void Generate(Entity mapEntity, float2 resize) { var mapData = EntityManager.GetComponentData <MapData>(mapEntity); var commandBuffer = _barrierSystem.CreateCommandBuffer(); int monsterCount = _monstersQuery.CalculateEntityCount(); Job.WithCode(() => { var genData = GenerateMap.Default; genData.monsterCount = monsterCount; commandBuffer.AddComponent(mapEntity, genData); mapData.width += (int)resize.x; mapData.height += (int)resize.y; mapData.width = math.max(15, mapData.width); mapData.height = math.max(15, mapData.height); commandBuffer.SetComponent(mapEntity, mapData); }).Schedule(); _barrierSystem.AddJobHandleForProducer(Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var settings = GetSingleton <GameBoardSettingsComponent>(); if (_positionsQuery.CalculateEntityCount() != settings.Width * settings.Height) { return(inputDeps); } var cachedEntities = new NativeArray <Entity>(settings.Width * settings.Height, Allocator.TempJob); var helper = new ArrayToCoordinatesConverter(settings.Width, settings.Height); var cacheJob = new CacheJob { CachedEntities = cachedEntities, Entities = _positionsQuery.ToEntityArray(Allocator.TempJob), Positions = _positionsQuery.ToComponentDataArray <CellPositionComponent>(Allocator.TempJob), Helper = helper }; var splitJob = new SplitJob { CachedEntities = cachedEntities, CellType = GetComponentDataFromEntity <CellTypeComponent>(true), Helper = helper }; var jobHandle = cacheJob.Schedule(_positionsQuery.CalculateEntityCount(), 32, inputDeps); jobHandle = splitJob.Schedule(jobHandle); return(jobHandle); }
protected override void OnUpdate() { if (m_UpdateMeshAndCommandBufferGroup.CalculateEntityCount() < 1 && m_UpdateVerticesOnlyGroup.CalculateEntityCount() < 1) { return; } if (m_UpdateMeshAndCommandBufferGroup.CalculateEntityCount() > 0) { RebuildMeshAndCommandBuffers(); // Now sort layers: NativeArray <CanvasLayer> layerEntity; var canvasLayerIdFromEntity = GetComponentDataFromEntity <CanvasSortLayer>(true); using (var roots = m_AnyTarget.ToEntityArray(Allocator.TempJob)) { layerEntity = new NativeArray <CanvasLayer>(roots.Length, Allocator.TempJob); for (int i = 0; i < layerEntity.Length; i++) { layerEntity[i] = new CanvasLayer() { CanvasEntity = roots[i], SortId = canvasLayerIdFromEntity[roots[i]].Value } } ; layerEntity.Sort(); } NativeMultiHashMap <int, int> cameraIdToLayerIdx = new NativeMultiHashMap <int, int>(layerEntity.Length, Allocator.Temp); for (int i = 0; i < layerEntity.Length; i++) { if (EntityManager.HasComponent(layerEntity[i].CanvasEntity, typeof(CanvasTargetCamera))) { var camera = EntityManager.GetSharedComponentData <CanvasTargetCamera>(layerEntity[i].CanvasEntity); camera.Target.InjectedCommandBuffers.Clear(); cameraIdToLayerIdx.Add(camera.Target.GetInstanceID(), i); } } for (int i = 0; i < layerEntity.Length; i++) { var entity = layerEntity[i].CanvasEntity; if (EntityManager.HasComponent(entity, typeof(CanvasTargetCamera))) { var camera = EntityManager.GetSharedComponentData <CanvasTargetCamera>(entity); camera.Target.InjectedCommandBuffers.Add(EntityManager.GetSharedComponentData <CanvasCommandBufferContainer>(entity).Value); } else if (EntityManager.HasComponent(entity, typeof(CanvasTargetRenderTexture))) { } } layerEntity.Dispose(); } if (m_UpdateVerticesOnlyGroup.CalculateEntityCount() > 0) { UpdateVerticesOnly(); } }
protected override void OnUpdate() { EntityQuery eq = GetEntityQuery(typeof(Translation), typeof(CollisionComponent)); Debug.Log("Entity count = " + eq.CalculateEntityCount()); quadTreeMap.Clear(); if (eq.CalculateEntityCount() > quadTreeMap.Capacity) { quadTreeMap.Capacity = eq.CalculateEntityCount(); } SetQuadrantHashMapJob sqj = new SetQuadrantHashMapJob { quadTreeMap = quadTreeMap.AsParallelWriter(), }; JobHandle job = JobForEachExtensions.Schedule(sqj, eq); job.Complete(); //Debug.Log("Total number of entities = " + quadTreeMap.Length); DrawQuadrant(Camera.main.ScreenToWorldPoint(Input.mousePosition)); //Debug.Log("Entities in Quadrant " + GetPositionHashMapKey(Camera.main.ScreenToWorldPoint(Input.mousePosition)) + " = " + GetEntityCount(quadTreeMap, GetPositionHashMapKey(Camera.main.WorldToScreenPoint(Input.mousePosition)))); }
private void CreateNewGhosts(NativeList <uint> blockedId) { if (m_InvalidGhostQuery.CalculateEntityCount() > 0) { using (var ghostArray = m_InvalidGhostQuery.ToComponentDataArray <GhostIdentifier>(Allocator.TempJob)) { foreach (var id in ghostArray) { m_GhostIdQueue.Enqueue(id.Value); } } EntityManager.RemoveComponent <GhostIdentifier>(m_InvalidGhostQuery); } if (m_GhostWithoutIdentifierQuery.CalculateEntityCount() == 0) { return; } var addArray = new NativeArray <GhostIdentifier>(m_GhostWithoutIdentifierQuery.CalculateEntityCount(), Allocator.TempJob); for (int i = 0, length = addArray.Length; i < length; i++) { addArray[i] = new GhostIdentifier { Value = FindGhostId(blockedId) } } ; EntityManager.AddComponentData(m_GhostWithoutIdentifierQuery, addArray); addArray.Dispose(); }
protected override void OnUpdate() { //calculate the number of entities we have to store (entities with translation component and QuadrantEntity component) EntityQuery entityQuery = GetEntityQuery(quadrantQueryDesc); NativeArray <Entity> entityArray = entityQuery.ToEntityArray(Allocator.TempJob); // create the entity array NativeArray <Translation> transArray = entityQuery.ToComponentDataArray <Translation>(Allocator.TempJob); NativeArray <MovingQuadrantEntity> movingQuadEntArray = entityQuery.ToComponentDataArray <MovingQuadrantEntity>(Allocator.TempJob); // create the stationary quadrant entities array NativeArray <PreviousMovement> prevMoveArray = entityQuery.ToComponentDataArray <PreviousMovement>(Allocator.TempJob); //the length is calculated from above //NativeMultiHashMap<int, QuadrantData> quadrantMultiHashMap = new NativeMultiHashMap<int, QuadrantData>(entityQuery.CalculateLength(),Allocator.TempJob); quadrantMultiHashMap.Clear(); // clear the hashmap // if the amount of stuff to add to the hashmap is larger than the capacity of the hashmap if (entityQuery.CalculateEntityCount() > quadrantMultiHashMap.Capacity) { quadrantMultiHashMap.Capacity = entityQuery.CalculateEntityCount(); //Increase the hashmap to hold everything } //using jobs //Cycle through all entities and get their positions //selects all entities with a translation component and adds them to the hashmap SetQuadrantDataHashMapJob setQuadrantDataHashMapJob = new SetQuadrantDataHashMapJob { quadrantMultiHashMap = quadrantMultiHashMap.AsParallelWriter(), //ToConcurrent used to allow for concurrent writing entities = entityArray, translations = transArray, quadEntTypes = movingQuadEntArray, prevMovements = prevMoveArray }; JobHandle jobHandle = IJobParallelForExtensions.Schedule(setQuadrantDataHashMapJob, entityArray.Length, 32, this.Dependency); //JobForEachExtensions.Schedule(setQuadrantDataHashMapJob, entityQuery); jobHandle.Complete(); //Cycle through all entities and get their positions //selects all entities with a translation component //without jobs /*Entities.ForEach((Entity entity, ref Translation translation) =>{ * int hashMapKey = GetPositionHashMapKey(translation.Value); * quadrantMultiHashMap.Add(hashMapKey, entity); * });*/ //Debug.Log(GetPositionHashMapKey(MousePosition.GetMouseWorldPositionOnPlane(50)) + " Mouse position: " + MousePosition.GetMouseWorldPositionOnPlane(50)); //DebugDrawQuadrant(MousePosition.GetMouseWorldPositionOnPlane(50)); //Debug.Log(GetEntityCountInHashMap(quadrantMultiHashMap,GetPositionHashMapKey(MousePosition.GetMouseWorldPositionOnPlane(50)))); //quadrantMultiHashMap.Dispose(); }
protected override void OnUpdate() { if (!HasSingleton <CanvasRoot>()) { TextUtility.CreateCanvas(EntityManager); SetSingleton(default(CanvasRoot)); } m_vertexCounter.Value = 0; m_vertexIndexCounter.Value = 0; m_subMeshCounter.Value = 0; var changedVerticesCount = m_vertexDataQuery.CalculateEntityCount(); if (changedVerticesCount == 0) { return; } m_vertexDataQuery.ResetFilter(); var length = m_vertexDataQuery.CalculateEntityCount(); var canvasRootEntity = GetSingletonEntity <CanvasRoot>(); var sortedEntities = EntityManager.GetAllSortedEntities(this, Allocator.TempJob); Dependency = m_vertexDataQuery.ToEntityIndexMap(EntityManager, ref m_entityIndexMap, Dependency); Dependency = JobHandle.CombineDependencies( m_offsets.Resize(length, Dependency), m_sharedFontIndices.Resize(length, Dependency)); Dependency = new GatherSharedComponentIndices <FontMaterial> { ChunkSharedComponentType = GetArchetypeChunkSharedComponentType <FontMaterial>(), Indices = m_sharedFontIndices.AsDeferredJobArray() }.Schedule(m_vertexDataQuery, Dependency); CreateOffsets( m_entityIndexMap, sortedEntities, m_sharedFontIndices.AsDeferredJobArray(), m_offsets.AsDeferredJobArray(), m_vertexCounter, m_vertexIndexCounter, m_subMeshCounter); Dependency = JobHandle.CombineDependencies( m_canvasdRootQuery.ResizeBufferDeferred <Vertex>(this, m_vertexCounter, Dependency), m_canvasdRootQuery.ResizeBufferDeferred <VertexIndex>(this, m_vertexIndexCounter, Dependency), m_canvasdRootQuery.ResizeBufferDeferred <SubMeshInfo>(this, m_subMeshCounter, Dependency)); MergeBatching(canvasRootEntity, m_offsets.AsDeferredJobArray()); Dependency = sortedEntities.Dispose(Dependency); m_vertexDataQuery.SetChangedVersionFilter(m_filterChanged); }
protected override JobHandle OnUpdate(JobHandle inputDependencies) { var paddleEntity = GetSingletonEntity <PaddleTag>(); var paddleJob = new CollideBallsWithPaddleJob { PaddleEntity = paddleEntity, PaddleTranslation = GetComponentDataFromEntity <Position2D>(true), PaddleBounds = GetComponentDataFromEntity <RectangleBounds>(true) }; var paddleHandle = paddleJob.Schedule(this, inputDependencies); var collideBrickHandle = paddleHandle; var brickCount = m_BrickQuery.CalculateEntityCount(); if (brickCount > 0) { var hashGrid = GetSingleton <BrickHashGrid>(); var brickJob = new CollideBallsWithBricksJob_Accelerated { Ecb = m_EndSimECBSystem.CreateCommandBuffer().ToConcurrent(), BrickGrid = hashGrid, BrickTranslationRO = GetComponentDataFromEntity <Position2D>(true), BrickRectangleBoundsRO = GetComponentDataFromEntity <RectangleBounds>(true) }; collideBrickHandle = brickJob.Schedule(this, paddleHandle); m_EndSimECBSystem.AddJobHandleForProducer(collideBrickHandle); } return(collideBrickHandle); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (_moveQuery.CalculateEntityCount() == 0) { return(inputDeps); } var mapEntity = _mapQuery.GetSingletonEntity(); var map = EntityManager.GetBuffer <MapTiles>(mapEntity); var mapData = EntityManager.GetComponentData <MapData>(mapEntity); inputDeps = Entities .WithReadOnly(map) .ForEach((ref Position p, ref Movement move) => { int2 dest = p.value + move.value; int index = dest.y * mapData.width + dest.x; move = int2.zero; if (index < 0 || index >= map.Length) { return; } if (map[index] != TileType.Wall) { p = dest; } }).Schedule(inputDeps); return(inputDeps); }
protected override void OnUpdate() { Count = _query.CalculateEntityCount(); Entities .ForEach( (in ValueTestData testData) => { }
protected override void OnUpdate() { if (m_vertexDataQuery.CalculateEntityCount() > 0) { RebuildMesh(); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { EntityQuery unitQuery = GetEntityQuery(typeof(FluidComponent)); NativeArray <float3> directionsArray = new NativeArray <float3>(unitQuery.CalculateEntityCount(), Allocator.TempJob); FindCollisionCubeSystemJob findTargetQuadrantSystemJob = new FindCollisionCubeSystemJob { quadrantMultiHashMap = CubeSystem.cubeMultiHashMap, finalDirectionsArray = directionsArray, Bounds = GameData.Bounds }; JobHandle jobHandle = findTargetQuadrantSystemJob.Schedule(this, inputDeps); // Add HasTarget Component to Entities that have a Closest Target //AddComponentJob addComponentJob = new AddComponentJob //{ // offsetsArray = directionsArray, // entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(), //}; //jobHandle = addComponentJob.Schedule(this, jobHandle); endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); return(jobHandle); }
public void CountTanks() { EntityManager entityManager = world.GetExistingSystem <MoveSystem>().EntityManager; EntityQuery entityQuery = entityManager.CreateEntityQuery(ComponentType.ReadOnly <TankData>()); UpdateTankCount(entityQuery.CalculateEntityCount()); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { //test if we have any requests if (pokemonMoveDataQuery.CalculateEntityCount() == 0 && pokemonMoveFinishEntities.CalculateEntityCount() == 0) { return(inputDeps); } NativeArray <EntityParent> entityParents = pokemonMoveDataQuery.ToComponentDataArray <EntityParent>(Allocator.TempJob); NativeArray <GroupIndexInfo> parentInfos = new NativeArray <GroupIndexInfo>(entityParents.Length, Allocator.TempJob); for (int i = 0; i < entityParents.Length; i++) { parentInfos[i] = EntityManager.GetComponentData <GroupIndexInfo>(entityParents[i].entity); } //preform the job JobHandle jh = new RemovePokemonData { pokemonMoveDataEntities = pokemonMoveDataQuery.ToEntityArray(Allocator.TempJob), ecb = ecbs.CreateCommandBuffer(), pokemonMoveDatas = pokemonMoveDataQuery.ToComponentDataArray <PokemonMoveDataEntity>(Allocator.TempJob), parents = entityParents, parentInfos = parentInfos, pokemonMoveEntityEntities = pokemonMoveFinishEntities.ToEntityArray(Allocator.TempJob), hasParticleRemoveRequest = GetComponentDataFromEntity <ParticleSystemRemoveRequest>(), pokemonMoveRemoveDatas = pokemonMoveFinishEntities.ToComponentDataArray <PokemonMoveDataEntity>(Allocator.TempJob) }.Schedule(inputDeps); jh.Complete(); return(jh); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (m_RootGroup.CalculateEntityCount() < 1) { return(inputDeps); } inputDeps = UpdateBatchIndices(inputDeps); var childFromEntity = GetBufferFromEntity <Child>(true); var verticesFromEntity = GetBufferFromEntity <ControlVertexData>(true); var trianglesFromEntity = GetBufferFromEntity <ControlVertexIndex>(true); using (new ProfilerSample("RenderSystem.BuildingChunks")) { MeshBatching chunkJob = new MeshBatching() { EntityType = GetArchetypeChunkEntityType(), ChildFromEntity = childFromEntity, SubMeshList = GetArchetypeChunkBufferType <SubMeshInfo>(), EntityToMaterial = m_EntityToMaterialID, VerticesFromEntity = verticesFromEntity, TrianglesFromEntity = trianglesFromEntity, VertexPointerFromEntity = GetComponentDataFromEntity <ElementVertexPointerInMesh>(), DisabledFromEntity = GetComponentDataFromEntity <Disabled>(true), VertexType = GetArchetypeChunkBufferType <MeshVertex>(), VertexIndexType = GetArchetypeChunkBufferType <MeshVertexIndex>(), }; inputDeps = chunkJob.Schedule(m_RootGroup, inputDeps); } return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { int massCount = massQuery.CalculateEntityCount(); int springCount = springQuery.CalculateEntityCount(); if (massCount == 0 || springCount == 0) { return(inputDeps); } NativeMultiHashMap <Entity, float3> hashMap = new NativeMultiHashMap <Entity, float3>(massCount * 4, Allocator.TempJob); HashSpringForceJob hashMassSpringJob = new HashSpringForceJob { _hashMap = hashMap.AsParallelWriter() }; JobHandle hashMassSPringHandle = hashMassSpringJob.Schedule(this, inputDeps); MassSpringForceJob massSpringForceJob = new MassSpringForceJob { _massSpringHashMap = hashMap }; JobHandle massSpringForceHandle = massSpringForceJob.Schedule(this, hashMassSPringHandle); massSpringForceHandle.Complete(); hashMap.Dispose(); return(massSpringForceHandle); }
protected override void OnCreate() { RequireSingletonForUpdate <MapRenderTerminal>(); RequireSingletonForUpdate <Map>(); _renderableActors = GetEntityQuery( ComponentType.ReadOnly <Position>(), ComponentType.ReadOnly <Renderable>(), ComponentType.ReadOnly <Actor>()); _renderableItems = GetEntityQuery( ComponentType.ReadOnly <Position>(), ComponentType.ReadOnly <Renderable>(), ComponentType.ReadOnly <Item>()); _actorsMovedQuery = GetEntityQuery( ComponentType.ReadOnly <Position>() ); _actorsMovedQuery.AddChangedVersionFilter(ComponentType.ReadOnly <Position>()); _gameStateChanged = GetEntityQuery( ComponentType.ReadOnly <GameState>()); _gameStateChanged.AddChangedVersionFilter(typeof(GameState)); _terminalChangedQuery = GetEntityQuery( ComponentType.ReadOnly <MapRenderTerminal>(), ComponentType.ReadOnly <TerminalTilesBuffer>()); _terminalChangedQuery.AddChangedVersionFilter(typeof(TerminalTilesBuffer)); _terminalDirtyQuery = GetEntityQuery(ComponentType.ReadOnly <MapRenderTerminal>(), ComponentType.ReadOnly <Terminal>()); _terminalDirtyQuery.AddChangedVersionFilter(typeof(Terminal)); _lastRenderableCount = _renderableActors.CalculateEntityCount(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var buffer = _barrier.CreateCommandBuffer().ToConcurrent(); int actingAICount = _actingAI.CalculateEntityCount(); NativeArray <int2> directions = new NativeArray <int2>(actingAICount, Allocator.TempJob); // Generate random directions for (int i = 0; i < actingAICount; ++i) { directions[i] = GetRandomDirection(); } inputDeps = Entities .WithStoreEntityQueryInField(ref _actingAI) .WithAll <Enemy>() // Only act when we have a turn .WithAll <TurnAction>() .ForEach((int entityInQueryIndex, Entity e) => { buffer.AddComponent <TryMove>(entityInQueryIndex, e, directions[entityInQueryIndex]); }).Schedule(inputDeps); _barrier.CreateCommandBuffer().RemoveComponent <TurnAction>(_actingAI); _barrier.AddJobHandleForProducer(inputDeps); directions.Dispose(inputDeps); return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var glyphMap = new NativeHashMap <int, Entity>(glyphQuery.CalculateEntityCount(), Allocator.TempJob); var glyphMapDeps = new BuildGlyphMapJob { GlyphMap = glyphMap.AsParallelWriter() }.Schedule(glyphQuery, inputDeps); var textMeshDeps = new BuildTextMeshJob { GlyphMap = glyphMap, GlyphData = GetBufferFromEntity <GlyphElement>(true), FontFaces = GetComponentDataFromEntity <FontFaceInfo>(true), EntityType = GetArchetypeChunkEntityType(), CharBufferType = GetArchetypeChunkBufferType <CharElement>(true), TextOptionType = GetArchetypeChunkComponentType <TextOptions>(true), TxtFontIDType = GetArchetypeChunkComponentType <TextFontID>(true), ColorType = GetArchetypeChunkComponentType <AppliedColor>(true), LTWType = GetArchetypeChunkComponentType <LocalToWorld>(true), DimensionType = GetArchetypeChunkComponentType <Dimensions>(true), MeshVertexDataType = GetArchetypeChunkBufferType <MeshVertexData>(), TriangleIndexType = GetArchetypeChunkBufferType <TriangleIndexElement>(), CmdBuffer = cmdBufferSystem.CreateCommandBuffer().ToConcurrent() }.Schedule(textQuery, glyphMapDeps); var finalDeps = glyphMap.Dispose(textMeshDeps); cmdBufferSystem.AddJobHandleForProducer(finalDeps); return(finalDeps); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var settings = GetSingleton <SettingsComponent>(); var cachedEntities = new NativeArray <Entity>(settings.Width * settings.Height, Allocator.TempJob); var helper = new ArrayHelper(settings.Width, settings.Height); var cacheJob = new CacheJob { CachedEntities = cachedEntities, Entities = _positionsQuery.ToEntityArray(Allocator.TempJob), Positions = _positionsQuery.ToComponentDataArray <PositionComponent>(Allocator.TempJob), Helper = helper }; var destroyJob = new DestroyJob { CachedEntities = cachedEntities, CommandBuffer = _commandBuffer.CreateCommandBuffer(), ClickedComponents = _clickedQuery.ToComponentDataArray <ClickedComponent>(Allocator.TempJob), InGroup = GetComponentDataFromEntity <InGroupComponent>(true), Helper = helper, MinGroupSize = settings.MinGroupSize }; var jobHandle = cacheJob.Schedule(_positionsQuery.CalculateEntityCount(), 32, inputDeps); jobHandle = destroyJob.Schedule(jobHandle); _commandBuffer.AddJobHandleForProducer(jobHandle); return(jobHandle); }
protected override void OnUpdate() { return; var flockSetting = _flockSetting; var flockEntitiesCount = _flockEntityQuery.CalculateEntityCount(); var cohesionArray = new NativeArray<float2>(flockEntitiesCount, Allocator.TempJob); var alignmentArray = new NativeArray<float2>(flockEntitiesCount, Allocator.TempJob); var separationArray = new NativeArray<float2>(flockEntitiesCount, Allocator.TempJob); //var steerArray = new NativeArray<float2>(flockEntitiesCount, Allocator.TempJob); //flock var flockJobHandle = Entities.WithName("CohesionJob").WithAll<FlockEntityData>().ForEach( (int entityInQueryIndex, in NeighborsData flockNeighborsData, in TransformData transformData, in SteerData flockNavigationData) => { if (flockNeighborsData.NeighborCount > 0) { cohesionArray[entityInQueryIndex] = math.normalizesafe(flockNeighborsData.MeanPosition - transformData.Position); alignmentArray[entityInQueryIndex] = math.normalizesafe(flockNeighborsData.MeanVelocity); } separationArray[entityInQueryIndex] = flockNeighborsData.SeparationVector; //steerArray[entityInQueryIndex] = math.normalizesafe(flockNavigationData.Goal - localToWorld.Position.xz); })
/// <summary> /// Schedules an attribute job /// </summary> /// <param name="inputDependencies">JobHandle</param> /// <param name="query">The EntityQuery used for filtering group</param> /// <param name="AttributeHash">Attribute MultiHashMap mapping entity to attribute value</param> /// <param name="job">Returned job handle</param> /// <typeparam name="TOper">The type of operator for this attribute job</typeparam> private void ScheduleAttributeJob <TOper>(ref JobHandle inputDependencies, ref EntityQuery query, ref NativeMultiHashMap <Entity, float> AttributeHash, out JobHandle job) where TOper : struct, IAttributeOperator, IComponentData { var nEntities = query.CalculateEntityCount(); var hashCapacity = AttributeHash.Capacity; AttributeHash.Clear(); if (nEntities == 0) { job = inputDependencies; return; } ; if (hashCapacity < nEntities) // We need to increase hash capacity { AttributeHash.Capacity = (int)(nEntities * 1.1); } else if (hashCapacity > nEntities * 4) // We need to reduce hash capacity { AttributeHash.Dispose(); AttributeHash = new NativeMultiHashMap <Entity, float>(nEntities, Allocator.Persistent); } // // AttributeHash = new NativeMultiHashMap<Entity, float>(query.CalculateEntityCount(), Allocator.TempJob); inputDependencies = new GetAttributeValuesJob_Sum <TOper, TAttributeTag> { owners = GetArchetypeChunkComponentType <AttributesOwnerComponent>(false), attributeModifiers = GetArchetypeChunkComponentType <AttributeModifier <TOper, TAttributeTag> >(false), AttributeModifierValues = AttributeHash.AsParallelWriter() }.Schedule(query, inputDependencies); job = inputDependencies; }
/*public void setOnCrowdRepelStep(){ * Debug.Log("Started Counting"); * onCrowdRepelStep = true; * }*/ public int checkCrowdNumber() { EntityQuery query = GetEntityQuery(ComponentType.ReadOnly <Crowd>()); //Debug.Log("CrowdCount" + query.CalculateEntityCount()); return(query.CalculateEntityCount()); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (m_Query.CalculateEntityCount() <= 0) { return(inputDeps); } var generator = m_GeneratorQuery.GetSingleton <LbBoardGenerator>(); var board = m_BoardQuery.GetSingleton <LbBoard>(); var boardEntity = m_BoardQuery.GetSingletonEntity(); var bufferLookup = GetBufferFromEntity <LbDirectionMap>(); var buffer = bufferLookup[boardEntity]; var bufferArray = buffer.AsNativeArray(); var spawnerHandle = new BoardSpawnerJob() { Generator = generator, Seed = m_Random.NextUInt(), DirectionBuffer = bufferLookup[boardEntity].AsNativeArray(), CommandBuffer = m_Barrier.CreateCommandBuffer() }.Schedule(inputDeps); var cleanUpHandle = new BoardSpawnerCleanJob() { CommandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent(), }.Schedule(this, spawnerHandle); m_Barrier.AddJobHandleForProducer(cleanUpHandle); return(cleanUpHandle); }
protected override void OnUpdate() { if (flyingQuery.CalculateEntityCount() > 0) { //跟随主角扔出的道具 Entities .WithAll <Flying>() .WithStructuralChanges() .ForEach((Entity entity, in OwnerPredictedState ownerState, in LocalToWorld localToWorld) => { // FSLog.Info($"Flying Camera,entity:{entity}"); if (ownerState.PreOwner == Entity.Null) { return; } if (!HasComponent <LocalCharacter>(ownerState.PreOwner)) { return; } MoveCamera(localToWorld); }).Run();
protected override void OnUpdate() { // Assign values to local variables captured in your job here, so that it has // everything it needs to do its work when it runs later. // For example, // float deltaTime = Time.DeltaTime; // This declares a new kind of job, which is a unit of work to do. // The job is declared as an Entities.ForEach with the target components as parameters, // meaning it will process all entities in the world that have both // Translation and Rotation components. Change it to process the component // types you want. int entitiesInQuery = query.CalculateEntityCount(); //Create a native array to hold the intermediate sums //(one element per entity) NativeArray <int> intermediateSums = new NativeArray <int>(entitiesInQuery, Allocator.TempJob); Entities.WithStoreEntityQueryInField(ref query) .ForEach((int entityInQueryIndex, in DynamicBuffer <CIntBufferData> buffer) => { for (int i = 0; i < buffer.Length; i++) { intermediateSums[entityInQueryIndex] += buffer[i].Value; } }).WithName("IntermediateSums")