protected override JobHandle OnUpdate(JobHandle inputDeps) { var sumNoTag = CreateJob(_noTagEntities, _allocatedArrays[0]); var noTagHandler = sumNoTag.ScheduleBatch(_noTagEntities.CalculateLength(), sumNoTag.EntitiesInButch); var sumFirstTag = CreateJob(_firstTagEntities, _allocatedArrays[1]); var firstTagHandler = sumFirstTag.ScheduleBatch(_firstTagEntities.CalculateLength(), sumFirstTag.EntitiesInButch); var sumSecodTag = CreateJob(_secondTagEntities, _allocatedArrays[2]); var secondTagHandler = sumSecodTag.ScheduleBatch(_secondTagEntities.CalculateLength(), sumSecodTag.EntitiesInButch); var sumAll = CreateJob(_allRandomEntities, _allocatedArrays[3]); var handlerAll = sumAll.ScheduleBatch(_allRandomEntities.CalculateLength(), sumAll.EntitiesInButch); _jobHandler[0] = handlerAll; _jobHandler[1] = noTagHandler; _jobHandler[2] = firstTagHandler; _jobHandler[3] = secondTagHandler; JobHandle.CompleteAll(_jobHandler); double noTagsSum = CalcSum(sumNoTag.Sums); double firstTagSum = CalcSum(sumFirstTag.Sums); double secondTagSum = CalcSum(sumSecodTag.Sums); double totalSum = CalcSum(sumAll.Sums); InitializeChunkIterationWorld.LogSumResults(this, noTagsSum, firstTagSum, secondTagSum, totalSum); return(base.OnUpdate(inputDeps)); }
protected override void OnUpdate() { double noTagsSum = 0; double firstTagSum = 0; double secondTagSum = 0; double totalSum = 0; var randomValues = _group.GetComponentDataArray <RandomValue>(); var entities = _group.GetEntityArray(); for (int i = 0; i < randomValues.Length; i++) { var randomValue = randomValues[i].Value; var entity = entities[i]; bool hasFirst = _entitiesWithFirstTag.Exists(entity); bool hasSecond = _entitiesWithSecondTag.Exists(entity); totalSum += randomValue; if (hasFirst) { firstTagSum += randomValue; } if (hasSecond) { secondTagSum += randomValue; } else if (!hasFirst) { noTagsSum += randomValue; } } InitializeChunkIterationWorld.LogSumResults(this, noTagsSum, firstTagSum, secondTagSum, totalSum); }
protected override void OnUpdate() { _firstType = GetArchetypeChunkComponentType <FirstTag>(true); _secondType = GetArchetypeChunkComponentType <SecondTag>(true); _randomType = GetArchetypeChunkComponentType <RandomValue>(true); var chunks = EntityManager.CreateArchetypeChunkArray(_query, Allocator.TempJob); double noTagsSum = 0; double firstTagSum = 0; double secondTagSum = 0; double totalSum = 0; for (int i = 0; i < chunks.Length; i++) { var chunk = chunks[i]; var firstTag = chunk.Has(_firstType); var secondTag = chunk.Has(_secondType); var array = chunk.GetNativeArray(_randomType); totalSum += CalcSumValues(array); if (firstTag) { firstTagSum += CalcSumValues(array); } if (secondTag) { secondTagSum += CalcSumValues(array); } else if (!firstTag) { noTagsSum += CalcSumValues(array); } } chunks.Dispose(); InitializeChunkIterationWorld.LogSumResults(this, noTagsSum, firstTagSum, secondTagSum, totalSum); }
protected override void OnUpdate() { _randomType = GetArchetypeChunkComponentType <RandomValue>(true); double noTagsSum = CalcSumFromChanks(_noTagQuery); double firstTagSum = CalcSumFromChanks(_firstTagQuery); double secondTagSum = CalcSumFromChanks(_secondTagQuery); double totalSum = CalcSumFromChanks(_allRandomQuery); InitializeChunkIterationWorld.LogSumResults(this, noTagsSum, firstTagSum, secondTagSum, totalSum); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (!_totalSum.IsCreated) { var chunks = EntityManager.CreateArchetypeChunkArray(new EntityArchetypeQuery { Any = new ComponentType[0], All = new[] { ComponentType.Create <RandomValue>() }, None = new ComponentType[0] }, Allocator.Persistent); int chunksCount = chunks.Length; chunks.Dispose(); _totalSum = new NativeArray <double>(chunksCount, Allocator.Persistent); _noTagSum = new NativeArray <double>(chunksCount, Allocator.Persistent); _firstTagSum = new NativeArray <double>(chunksCount, Allocator.Persistent); _secondTagSum = new NativeArray <double>(chunksCount, Allocator.Persistent); } var job = new SumChunkJob { TotalResults = _totalSum, FirstTagResults = _firstTagSum, SecondTagResults = _secondTagSum, NoTagResults = _noTagSum, RandomType = GetArchetypeChunkComponentType <RandomValue>(true), FirstTagType = GetArchetypeChunkComponentType <FirstTag>(true), SecondTagType = GetArchetypeChunkComponentType <SecondTag>(true) }.Schedule(_randomGroup, inputDeps); job.Complete(); double noTagsSum = 0; double firstTagSum = 0; double secondTagSum = 0; double totalSum = 0; for (int i = 0; i < _totalSum.Length; i++) { totalSum += _totalSum[i]; noTagsSum += _noTagSum[i]; firstTagSum += _firstTagSum[i]; secondTagSum += _secondTagSum[i]; } InitializeChunkIterationWorld.LogSumResults(this, noTagsSum, firstTagSum, secondTagSum, totalSum); return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var chunks = EntityManager.CreateArchetypeChunkArray(_query, Allocator.TempJob); InitializeChunkIterationWorld.LogChunksCount(this, chunks.Length); if (!_totalSum.IsCreated) { _totalSum = new NativeArray <double>(chunks.Length, Allocator.Persistent); _noTagSum = new NativeArray <double>(chunks.Length, Allocator.Persistent); _firstTagSum = new NativeArray <double>(chunks.Length, Allocator.Persistent); _secondTagSum = new NativeArray <double>(chunks.Length, Allocator.Persistent); } var job = new ChunkSum { Chunks = chunks, RandomType = GetArchetypeChunkComponentType <RandomValue>(true), FirstTagType = GetArchetypeChunkComponentType <FirstTag>(true), SecondTagType = GetArchetypeChunkComponentType <SecondTag>(true), TotalResults = _totalSum, NoTagResults = _noTagSum, FirstTagResults = _firstTagSum, SecondTagResults = _secondTagSum }.Schedule(chunks.Length, 64); job.Complete(); double noTagsSum = 0; double firstTagSum = 0; double secondTagSum = 0; double totalSum = 0; for (int i = 0; i < _totalSum.Length; i++) { totalSum += _totalSum[i]; noTagsSum += _noTagSum[i]; firstTagSum += _firstTagSum[i]; secondTagSum += _secondTagSum[i]; } InitializeChunkIterationWorld.LogSumResults(this, noTagsSum, firstTagSum, secondTagSum, totalSum); chunks.Dispose(); return(base.OnUpdate(inputDeps)); }
protected override void OnUpdate() { double noTagsSum = 0; double firstTagSum = 0; double secondTagSum = 0; double totalSum = 0; if (_noTagEntities.CalculateLength() != 0) { var randArray = _noTagEntities.GetComponentDataArray <RandomValue>(); for (int i = 0; i < randArray.Length; i++) { var value = randArray[i].Value; noTagsSum += value; } } if (_firstTagEntities.CalculateLength() != 0) { var randArray = _firstTagEntities.GetComponentDataArray <RandomValue>(); for (int i = 0; i < randArray.Length; i++) { var value = randArray[i].Value; firstTagSum += value; } } if (_secondTagEntities.CalculateLength() != 0) { var randArray = _secondTagEntities.GetComponentDataArray <RandomValue>(); for (int i = 0; i < randArray.Length; i++) { var value = randArray[i].Value; secondTagSum += value; } } var allRandArray = _allRandomEntities.GetComponentDataArray <RandomValue>(); for (int i = 0; i < allRandArray.Length; i++) { var value = allRandArray[i].Value; totalSum += value; } InitializeChunkIterationWorld.LogSumResults(this, noTagsSum, firstTagSum, secondTagSum, totalSum); }
private void Start() { World.DisposeAllWorlds(); _instance = this; _world = new World("ChunksIteration"); ////_world.CreateManager<SingleGroupIterationSystem>(); //extremely slow //_world.CreateManager<MultyGroupsIterationSystem>(); ////approximately equal //_world.CreateManager<SingleQueryChunkIterationSystem>(); //_world.CreateManager<MultyQueryChunkIterationsSystem>(); //_world.CreateManager<GroupsIterationBathingJobSystem>(); _world.CreateManager <ChunkParallelIterationJobSystem>(); _world.CreateManager <ChunkIterationBatchingJobSystem>(); _world.CreateManager <ChunkIterationJobSystem>(); //_world.CreateManager<GroupsIterationSingleJobSystem>(); var em = _world.GetOrCreateManager <EntityManager>(); int elementsForType = ChunksCount / 4; var start = DateTime.Now; var startInitMsg = $"Begin initializing {ChunksCount}x{EntitiesInChunk} entities " + start; Debug.Log(startInitMsg); if (DebugText != null) { DebugText.text += startInitMsg + "\n"; } InitEntities(em, elementsForType, ComponentType.Create <FirstTag>()); InitEntities(em, elementsForType, ComponentType.Create <SecondTag>()); InitEntities(em, elementsForType, ComponentType.Create <FirstTag>(), ComponentType.Create <SecondTag>()); InitEntities(em, ChunksCount - 3 * elementsForType); ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.AllWorlds.ToArray()); var msg = $"Initialize {ChunksCount * EntitiesInChunk} entities with random components total sum = {_totalSym:F2} for {DateTime.Now.Subtract(start).TotalSeconds:F2}s"; Debug.Log(msg); if (DebugText != null) { DebugText.text += msg; } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var sumNoTag = CreateJob(_noTagEntities, _allocatedArrays[0]); var sumFirstTag = CreateJob(_firstTagEntities, _allocatedArrays[1]); var sumSecodTag = CreateJob(_secondTagEntities, _allocatedArrays[2]); var sumAll = CreateJob(_allRandomEntities, _allocatedArrays[3]); _jobHandler[0] = sumAll.Schedule(); _jobHandler[1] = sumNoTag.Schedule(); _jobHandler[2] = sumFirstTag.Schedule(); _jobHandler[3] = sumSecodTag.Schedule(); JobHandle.CompleteAll(_jobHandler); double noTagsSum = sumNoTag.Sums[0]; double firstTagSum = sumFirstTag.Sums[0]; double secondTagSum = sumSecodTag.Sums[0]; double totalSum = sumAll.Sums[0]; InitializeChunkIterationWorld.LogSumResults(this, noTagsSum, firstTagSum, secondTagSum, totalSum); return(base.OnUpdate(inputDeps)); }