void ScheduleMeshDataJobs()
    {
        var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
        var chunks        = meshDataGroup.CreateArchetypeChunkArray(Allocator.TempJob);

        var entityType     = GetArchetypeChunkEntityType();
        var matrixType     = GetArchetypeChunkComponentType <CellSystem.MatrixComponent>(true);
        var sectorTypeType = GetArchetypeChunkComponentType <SectorSystem.TypeComponent>(true);
        var masterCellType = GetArchetypeChunkComponentType <SectorSystem.MasterCell>(true);

        var worleyType   = GetArchetypeChunkBufferType <WorleyNoise.PointData>(true);
        var topologyType = GetArchetypeChunkBufferType <TopologySystem.Height>(true);

        for (int c = 0; c < chunks.Length; c++)
        {
            var chunk = chunks[c];

            var entities    = chunk.GetNativeArray(entityType);
            var matrices    = chunk.GetNativeArray(matrixType);
            var sectorTypes = chunk.GetNativeArray(sectorTypeType);
            var masterCells = chunk.GetNativeArray(masterCellType);

            var worleyArrays   = chunk.GetBufferAccessor(worleyType);
            var topologyArrays = chunk.GetBufferAccessor(topologyType);

            for (int e = 0; e < entities.Length; e++)
            {
                var worley = new NativeArray <WorleyNoise.PointData>(worleyArrays[e].AsNativeArray(), Allocator.TempJob);
                var height = new NativeArray <TopologySystem.Height>(topologyArrays[e].AsNativeArray(), Allocator.TempJob);

                TerrainMeshDataJob job = new TerrainMeshDataJob {
                    commandBuffer      = jobManager.commandBuffer,
                    sectorEntity       = entities[e],
                    sectorType         = sectorTypes[e].Value,
                    matrix             = matrices[e],
                    masterCell         = masterCells[e].Value,
                    worley             = worley,
                    terrainHeightArray = height,
                    topologyUtil       = topologyUtil
                };

                jobManager.ScheduleNewJob(job);
            }
        }

        commandBuffer.Playback(entityManager);
        commandBuffer.Dispose();
        chunks.Dispose();
    }
Beispiel #2
0
    protected override void OnUpdate()
    {
        bool newGame          = false;
        bool newRound         = false;
        var  tankPlayerChunks = tankPlayerQuery.CreateArchetypeChunkArray(Allocator.TempJob);

        if (tankPlayerChunks.Length == 1)
        {
            if (tankPlayerChunks[0].Count == 1)
            {
                // Exactly one tank left alive. Its owner wins this round.
                var chunkPlayers  = tankPlayerChunks[0].GetNativeArray(tankPlayerComponentType);
                var winningPlayer = chunkPlayers[0];
                winningPlayer.Score += 1;

                var gameSettings = GetSingleton <GameSettings>();
                if (winningPlayer.Score == gameSettings.ScoreToWin)
                {
                    // game over, this player wins
                    newGame = true;
                }
                else
                {
                    // round over
                    newRound = true;
                }
            }
        }
        else if (tankPlayerChunks.Length == 0)
        {
            // No tanks left alive. This round is a tie.
            newRound = true;
        }
        tankPlayerChunks.Dispose();

        if (newRound)
        {
            var gameProgress = GetSingleton <GameProgress>();
            gameProgress.CurrentRound += 1;
            SetSingleton(gameProgress);
            // TODO: reactivate tanks
        }
        else if (newGame)
        {
            var gameProgress = GetSingleton <GameProgress>();
            gameProgress.CurrentRound = 1;
            SetSingleton(gameProgress);
        }
    }
            protected override void OnUpdate()
            {
                var chunks          = m_Group.CreateArchetypeChunkArray(Allocator.TempJob);
                var ecsIntElements  = GetArchetypeChunkBufferType <EcsIntElement>();
                var updateChunksJob = new UpdateChunks
                {
                    Chunks         = chunks,
                    EcsIntElements = ecsIntElements
                };
                var updateChunksJobHandle = updateChunksJob.Schedule(chunks.Length, 32);

                updateChunksJobHandle.Complete();

                chunks.Dispose();
            }
        void UpdateDynamicRenderBatches()
        {
            m_InstancedRenderMeshBatchGroup.RemoveTag(new FrozenRenderSceneTag());

            Profiler.BeginSample("CreateArchetypeChunkArray");
            var chunks = m_DynamicGroup.CreateArchetypeChunkArray(Allocator.TempJob);

            Profiler.EndSample();

            if (chunks.Length > 0)
            {
                CacheMeshBatchRendererGroup(new FrozenRenderSceneTag(), chunks, chunks.Length);
            }
            chunks.Dispose();
        }
Beispiel #5
0
        JobHandle RenderPass(JobHandle dependencies = default)
        {
            var chunkArray             = _renderQuery.CreateArchetypeChunkArray(Allocator.TempJob);
            var versionType            = GetArchetypeChunkComponentType <ChunkCullingSystemVersion>();
            var blockCulledVersionType = GetArchetypeChunkComponentType <BlockCulledFacesComponent.Version>();

            var blockActiveVersionType = GetArchetypeChunkComponentType <BlockActiveComponent.Version>(true);

            var VoxelChunkEntityArchetype = GetArchetypeChunkEntityType();

            Profiler.BeginSample("Process ECS Chunk");
            foreach (var ecsChunk in chunkArray)
            {
                var systemVersions        = ecsChunk.GetNativeArray(versionType);
                var activeVersions        = ecsChunk.GetNativeArray(blockActiveVersionType);
                var blockCulledVersions   = ecsChunk.GetNativeArray(blockCulledVersionType);
                var voxelChunkEntityArray = ecsChunk.GetNativeArray(VoxelChunkEntityArchetype);

                var i = 0;
                foreach (var voxelChunkEntity in voxelChunkEntityArray)
                {
                    var version        = systemVersions[i];
                    var currentVersion = new ChunkCullingSystemVersion()
                    {
                        ActiveVersion = activeVersions[i]
                    };

                    if (currentVersion.DidChange(version))
                    {
                        Profiler.BeginSample("Update Chunk");
                        var job = UpdateVoxelChunkV2(voxelChunkEntity, dependencies);
                        job.Complete();
                        Profiler.EndSample();
                        systemVersions[i]      = currentVersion;
                        blockCulledVersions[i] = blockCulledVersions[i].GetDirty();
                    }

                    i++;
                }
            }


            Profiler.EndSample();

            chunkArray.Dispose();
//            return merged;
            return(dependencies);
        }
        protected override unsafe JobHandle OnUpdate(JobHandle handle)
        {
            _batchMatrices.Clear();

            var chunkArray = _query.CreateArchetypeChunkArray(Allocator.TempJob);
            var job        = new MyJob {
                Time           = UTJ.Time.GetCurrent(),
                DistortionType = GetArchetypeChunkComponentType <DistortionComponent>(),
                ChunkArray     = chunkArray,
                Matrices       = _batchMatrices,
            };

            handle = job.Schedule(handle);
            _renderDistortionSystem.AddJobHandleForProducer(handle);
            return(handle);
        }
        private void RenderPass(EntityQuery query)
        {
            var chunkRenderMeshType = GetArchetypeChunkComponentType <ChunkRenderMesh>(true);
            var matrixType          = GetArchetypeChunkComponentType <LocalToWorld>(true);

            using (var chunks = query.CreateArchetypeChunkArray(Allocator.TempJob))
            {
                foreach (var chunk in chunks)
                {
                    var chunkRenderMeshes = chunk.GetNativeArray(chunkRenderMeshType);
                    var matrixes          = chunk.GetNativeArray(matrixType);

                    RenderChunk(chunkRenderMeshes, matrixes);
                }
            }
        }
        protected override void OnUpdate()
        {
            var entityType = GetArchetypeChunkEntityType();
            var chunkArray = initializerGroup.CreateArchetypeChunkArray(Allocator.TempJob);

            foreach (var chunk in chunkArray)
            {
                var entities = chunk.GetNativeArray(entityType);
                for (int i = 0; i < entities.Length; i++)
                {
                    PostUpdateCommands.AddComponent(entities[i], new HeartbeatData());
                }
            }

            chunkArray.Dispose();
        }
Beispiel #9
0
        protected override unsafe void OnUpdate()
        {
            var typeMoveCommand     = GetArchetypeChunkComponentType <MoveCommand>(true);
            var typeDestroyable     = GetArchetypeChunkComponentType <DestroyableComponentData>();
            var typeTicks           = GetArchetypeChunkComponentType <DateTimeTicksToProcess>(true);
            var typeTeamTag         = GetArchetypeChunkComponentType <TeamTag>(true);
            var typePhysicsVelocity = GetArchetypeChunkComponentType <PhysicsVelocity>();
            var currentTicks        = DateTime.Now.Ticks;

            using (var moveCommandChunks = _queryMoveCommand.CreateArchetypeChunkArray(Allocator.TempJob))
                using (var velocitiesChunks = _query.CreateArchetypeChunkArray(Allocator.TempJob))
                {
                    foreach (var moveCommandChunk in moveCommandChunks)
                    {
                        var moveCommands = moveCommandChunk.GetNativeArray(typeMoveCommand);
                        var destroys     = moveCommandChunk.GetNativeArray(typeDestroyable);
                        var ticks        = moveCommandChunk.GetNativeArray(typeTicks);
                        for (var i = 0; i < ticks.Length; i++)
                        {
                            if (ticks[i].Value < currentTicks || destroys[i].ShouldDestroy)
                            {
                                continue;
                            }
                            destroys[i] = new DestroyableComponentData()
                            {
                                ShouldDestroy = true
                            };
                            foreach (var velocitiesChunk in velocitiesChunks)
                            {
                                var teamTags          = velocitiesChunk.GetNativeArray(typeTeamTag);
                                var physicsVelocities = velocitiesChunk.GetNativeArray(typePhysicsVelocity);
                                for (var j = 0; j < teamTags.Length; j++)
                                {
                                    if (teamTags[j].Id != moveCommands[i].Id)
                                    {
                                        continue;
                                    }
                                    UnsafeUtilityEx
                                    .ArrayElementAsRef <PhysicsVelocity>(NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(physicsVelocities), j)
                                    .Linear += moveCommands[i].DeltaVelocity;
                                }
                            }
                        }
                    }
                }
        }
 protected override void OnUpdate()
 {
     using (var chunkArray = m_UpdateSizeGroup.CreateArchetypeChunkArray(Allocator.TempJob))
     {
         var cameraType = GetArchetypeChunkSharedComponentType <CanvasTargetCamera>();
         var sizeType   = GetArchetypeChunkComponentType <CanvasScreenSize>();
         foreach (var chunk in chunkArray)
         {
             var camera     = chunk.GetSharedComponentData(cameraType, EntityManager);
             var canvasSize = new CanvasScreenSize()
             {
                 Value = new float2(camera.Target.UnityCamera.pixelWidth, camera.Target.UnityCamera.pixelHeight)
             };
             chunk.SetChunkComponentData(sizeType, canvasSize);
         }
     }
 }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //Migrate material on LineStyle to RenderMesh by chunks
            using (var aca = newRegisterQuery.CreateArchetypeChunkArray(Allocator.TempJob))
            {
                if (aca.Length > 0)
                {
                    EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp);

                    var lineStyleType = GetArchetypeChunkSharedComponentType <LineStyle>();

                    //TODO : This shouldn't be needed, but somehow the mesh became `null` in editor world??
                    CreateMeshIfNotYet();

                    for (int i = 0; i < aca.Length; i++)
                    {
                        ArchetypeChunk ac        = aca[i];
                        var            lineStyle = ac.GetSharedComponentData <LineStyle>(lineStyleType, EntityManager);

                        //Filter to narrow down chunk operation.
                        newRegisterQuery.SetSharedComponentFilter(lineStyle);
                        ecb.AddSharedComponent(newRegisterQuery,
                                               new RenderMesh {
                            mesh = lineMesh, material = lineStyle.material
                        });
                    }

                    ecb.Playback(EntityManager);
                    newRegisterQuery.ResetFilter();
                }
            }

            //Use EQ operation to prepare other components where they don't need initialization value.
            EntityManager.AddComponent(newRegisterQuery, ComponentType.ReadOnly <Translation>());
            EntityManager.AddComponent(newRegisterQuery, ComponentType.ReadOnly <Rotation>());
            EntityManager.AddComponent(newRegisterQuery, ComponentType.ReadOnly <NonUniformScale>());
            //Unity stopped adding LTW for us without GO conversion.
            EntityManager.AddComponent(newRegisterQuery, ComponentType.ReadOnly <LocalToWorld>());

            //This make them not registered again.
            EntityManager.AddComponent(newRegisterQuery, ComponentType.ReadOnly <RegisteredState>());

            //This is for clean up of system state component in the case the entity was destroyed.
            EntityManager.RemoveComponent(cleanUpQuery, ComponentType.ReadOnly <RegisteredState>());

            return(default);
Beispiel #12
0
            protected override void OnUpdate()
            {
                if (m_handle.IsCompleted)
                {
                    m_handle.Complete();

                    m_entityCommandBuffer.Playback(EntityManager);
                    m_entityCommandBuffer.Dispose();
                }
                else
                {
                    return;
                }

                m_entityCommandBuffer = new EntityCommandBuffer(Allocator.TempJob);

                var entityType     = GetArchetypeChunkEntityType();
                var chunkIndexType = GetArchetypeChunkComponentType <ChunkIndex>();
                var voxelType      = GetArchetypeChunkBufferType <Voxel>();

                var chunks = m_query.CreateArchetypeChunkArray(Allocator.TempJob);

                int jobCount = Mathf.Min(CONCURRENT_JOB_COUNT, chunks.Length);

                NativeArray <JobHandle> handlesToCombine = new NativeArray <JobHandle>(jobCount, Allocator.TempJob);

                for (int i = 0; i < jobCount; i++)
                {
                    int chunkIndex = i;

                    var job = new Job
                    {
                        ChunkIndex     = chunkIndex,
                        EntityType     = entityType,
                        ChunkIndexType = chunkIndexType,
                        VoxelType      = voxelType,
                        Chunks         = chunks
                    };

                    var handle = job.Schedule();
                    handlesToCombine[i] = handle;
                }

                m_handle = JobHandle.CombineDependencies(handlesToCombine);
            }
Beispiel #13
0
        protected override void OnUpdate()
        {
            var typeTicks       = GetArchetypeChunkComponentType <DateTimeTicksToProcess>(true);
            var typeTranslation = GetArchetypeChunkComponentType <Translation>(true);
            var typePoint       = GetArchetypeChunkComponentType <Point>(true);
            var typeEntities    = GetArchetypeChunkEntityType();
            var current         = DateTime.Now.Ticks;

            using (var entityList = new NativeList <Entity>(Allocator.Temp))
                using (var translationList = new NativeList <Translation>(Allocator.Temp))
                    using (var pointList = new NativeList <Point>(Allocator.Temp))
                    {
                        using (var chunks = _query.CreateArchetypeChunkArray(Allocator.TempJob))
                        {
                            for (var chunkIndex = 0; chunkIndex < chunks.Length; chunkIndex++)
                            {
                                var chunk        = chunks[chunkIndex];
                                var ticks        = chunk.GetNativeArray(typeTicks);
                                var translations = chunk.GetNativeArray(typeTranslation);
                                var points       = chunk.GetNativeArray(typePoint);
                                var entities     = chunk.GetNativeArray(typeEntities);
                                for (var index = 0; index < ticks.Length; index++)
                                {
                                    if (current < ticks[index].Value)
                                    {
                                        continue;
                                    }
                                    entityList.Add(entities[index]);
                                    translationList.Add(translations[index]);
                                    pointList.Add(points[index]);
                                }
                            }
                        }
                        var entityArray      = (NativeArray <Entity>)entityList;
                        var translationArray = (NativeArray <Translation>)translationList;
                        var pointArray       = (NativeArray <Point>)pointList;
                        EntityManager.DestroyEntity(entityArray);
                        EntityManager.Instantiate(CurrentPointPrefab, entityArray);
                        for (var i = 0; i < entityArray.Length; i++)
                        {
                            EntityManager.SetComponentData(entityArray[i], translationArray[i]);
                            EntityManager.SetComponentData(entityArray[i], pointArray[i]);
                        }
                    }
        }
Beispiel #14
0
        protected override void OnUpdate()
        {
            var typeMoveCommand     = GetArchetypeChunkComponentType <MoveCommandMoreComplex>(true);
            var typeDestroyable     = GetArchetypeChunkComponentType <DestroyableComponentData>();
            var typeTicks           = GetArchetypeChunkComponentType <DateTimeTicksToProcess>(true);
            var typeTeamTag         = GetArchetypeChunkComponentType <TeamTag>(true);
            var typePhysicsVelocity = GetArchetypeChunkComponentType <PhysicsVelocity>();
            var currentTicks        = DateTime.Now.Ticks;

            using (var moveCommandChunks = _queryMoveCommand.CreateArchetypeChunkArray(Allocator.TempJob))
                using (var velocitiesChunks = _query.CreateArchetypeChunkArray(Allocator.TempJob))
                {
                    foreach (var moveCommandChunk in moveCommandChunks)
                    {
                        var moveCommands    = moveCommandChunk.GetNativeArray(typeMoveCommand);
                        var destroys        = moveCommandChunk.GetNativeArray(typeDestroyable);
                        var commandTeamTags = moveCommandChunk.GetNativeArray(typeTeamTag);
                        var ticks           = moveCommandChunk.GetNativeArray(typeTicks);
                        for (var i = 0; i < ticks.Length; i++)
                        {
                            if (ticks[i].Value < currentTicks || destroys[i].ShouldDestroy)
                            {
                                continue;
                            }
                            destroys[i] = new DestroyableComponentData()
                            {
                                ShouldDestroy = true
                            };
                            foreach (var velocitiesChunk in velocitiesChunks)
                            {
                                var teamTags          = velocitiesChunk.GetNativeArray(typeTeamTag);
                                var physicsVelocities = velocitiesChunk.GetNativeArray(typePhysicsVelocity);
                                for (var j = 0; j < teamTags.Length; j++)
                                {
                                    if (teamTags[j].Id != commandTeamTags[i].Id)
                                    {
                                        continue;
                                    }
                                    physicsVelocities[j] = moveCommands[i].Value;
                                }
                            }
                        }
                    }
                }
        }
    void ScheduleMeshDataJobs()
    {
        var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
        var chunks        = meshDataGroup.CreateArchetypeChunkArray(Allocator.TempJob);

        var entityType           = GetArchetypeChunkEntityType();
        var matrixType           = GetArchetypeChunkComponentType <CellSystem.MatrixComponent>(true);
        var sectorMasterCellType = GetArchetypeChunkComponentType <SectorSystem.MasterCell>(true);
        var worleyType           = GetArchetypeChunkBufferType <WorleyNoise.PointData>(true);

        for (int c = 0; c < chunks.Length; c++)
        {
            var chunk = chunks[c];

            var entities          = chunk.GetNativeArray(entityType);
            var matrices          = chunk.GetNativeArray(matrixType);
            var sectorMasterCells = chunk.GetNativeArray(sectorMasterCellType);
            var worleyArrays      = chunk.GetBufferAccessor(worleyType);

            for (int e = 0; e < entities.Length; e++)
            {
                CellSystem.MatrixComponent matrix     = matrices[e];
                WorleyNoise.CellData       masterCell = sectorMasterCells[e].Value;

                var worley = new NativeArray <WorleyNoise.PointData>(worleyArrays[e].AsNativeArray(), Allocator.Persistent);

                WaterMeshDataJob waterJob = new WaterMeshDataJob {
                    commandBuffer        = jobManager.commandBuffer,
                    waterEntityArchetype = waterArchetype,
                    matrix       = matrix,
                    masterCell   = masterCell,
                    worley       = worley,
                    topologyUtil = topologyUtil
                };

                jobManager.ScheduleNewJob(waterJob);

                commandBuffer.RemoveComponent <Tags.CreateWaterEntity>(entities[e]);
            }
        }

        commandBuffer.Playback(entityManager);
        commandBuffer.Dispose();
        chunks.Dispose();
    }
        protected override JobHandle OnUpdate(JobHandle handle)
        {
            _batchMatrices.Clear();

            var chunkArray = _query.CreateArchetypeChunkArray(Allocator.TempJob);
            var job        = new Job {
                TranslationType      = GetArchetypeChunkComponentType <Translation>(),
                CachedBeamMatrixType = GetArchetypeChunkComponentType <CachedBeamMatrix>(),
                BeamType             = GetArchetypeChunkComponentType <BeamComponent>(),
                ChunkArray           = chunkArray,
                Matrices             = _batchMatrices,
            };

            handle = job.Schedule(handle);
            _renderBeamSystem.AddJobHandleForProducer(handle);

            return(handle);
        }
Beispiel #17
0
        override protected JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (shipGroup.IsEmptyIgnoreFilter)
            {
                return(inputDeps);
            }
            var       trackJob = new ChunkTrackJob();
            JobHandle gatherJob, levelHandle;

            trackJob.shipChunks   = shipGroup.CreateArchetypeChunkArray(Allocator.TempJob, out gatherJob);
            trackJob.positionType = GetArchetypeChunkComponentType <Translation>(true);
            trackJob.stateType    = GetArchetypeChunkComponentType <ShipStateComponentData>(true);
            trackJob.screenWidth  = Screen.width;
            trackJob.screenHeight = Screen.height;
            trackJob.level        = m_LevelGroup.ToComponentDataArray <LevelComponent>(Allocator.TempJob, out levelHandle);
            trackJob.teleport     = teleport;
            return(trackJob.ScheduleSingle(this, JobHandle.CombineDependencies(inputDeps, gatherJob, levelHandle)));
        }
    protected override void OnUpdate()
    {
        //已经过时
        //var rotationType = GetArchetypeChunkComponentType<RotationQuaternion>();
        //var rotationSpeedType = GetArchetypeChunkComponentType<RotationSpeed>(true);

        var chunks = m_Query.CreateArchetypeChunkArray(Allocator.TempJob);

        var rotationsSpeedJob = new SRotationSpeedSystem2_Job
        {
            Chunks               = chunks,
            DeltaTime            = Time.DeltaTime,
            CRotationData84_Type = GetComponentTypeHandle <CRotationData84>(false),
            CSpeedData_Type      = GetComponentTypeHandle <CSpeedData84>(true)
        };

        this.Dependency = rotationsSpeedJob.Schedule(chunks.Length, 32, this.Dependency);
    }
Beispiel #19
0
    void AddNewSectorsToMatrix()
    {
        var commandBuffer = new EntityCommandBuffer(Allocator.TempJob);
        var chunks        = sectorSortQuery.CreateArchetypeChunkArray(Allocator.TempJob);

        var entityType            = GetArchetypeChunkEntityType();
        var cellArrayType         = GetArchetypeChunkBufferType <SectorCell>(true);
        var adjacentCellArrayType = GetArchetypeChunkBufferType <AdjacentCell>(true);

        for (int c = 0; c < chunks.Length; c++)
        {
            var chunk = chunks[c];

            var entities           = chunk.GetNativeArray(entityType);
            var cellArrays         = chunk.GetBufferAccessor(cellArrayType);
            var adjacentCellArrays = chunk.GetBufferAccessor(adjacentCellArrayType);

            for (int e = 0; e < entities.Length; e++)
            {
                Entity sectorEntity = entities[e];
                DynamicBuffer <SectorCell>   cells         = cellArrays[e];
                DynamicBuffer <AdjacentCell> adjacentCells = adjacentCellArrays[e];

                for (int i = 0; i < cells.Length; i++)
                {
                    TryAddCell(cells[i].index);

                    TryAddSector(sectorEntity, cells[i].index);
                }

                for (int i = 0; i < adjacentCells.Length; i++)
                {
                    TryAddCell(adjacentCells[i].index);
                }

                commandBuffer.AddComponent <Tags.TerrainEntity>(sectorEntity, new Tags.TerrainEntity());
            }
        }

        commandBuffer.Playback(entityManager);
        commandBuffer.Dispose();

        chunks.Dispose();
    }
        public void RefreshData()
        {
            if (world == null)
            {
                return;
            }

            using (refreshDataMarker.Auto())
            {
                fullData.Clear();
                var spatialOSComponentType = world.EntityManager.GetArchetypeChunkComponentType <SpatialEntityId>(true);
                var metadataComponentType  =
                    world.EntityManager.GetArchetypeChunkComponentType <Metadata.Component>(true);
                var ecsEntityType = world.EntityManager.GetArchetypeChunkEntityType();

                using (var chunks = query.CreateArchetypeChunkArray(Allocator.TempJob))
                {
                    foreach (var chunk in chunks)
                    {
                        NativeArray <Metadata.Component>?metadataArray = null;

                        if (chunk.Has(metadataComponentType))
                        {
                            metadataArray = chunk.GetNativeArray(metadataComponentType);
                        }

                        var entityIdArray = chunk.GetNativeArray(spatialOSComponentType);
                        var entities      = chunk.GetNativeArray(ecsEntityType);

                        for (var i = 0; i < entities.Length; i++)
                        {
                            var data = new EntityData(entities[i], entityIdArray[i].EntityId, metadataArray?[i].EntityType);
                            fullData.Add(data);
                        }
                    }
                }

                fullData.Sort();
            }

            ApplySearch(searchParameters);
        }
Beispiel #21
0
        private void UpdateChangeParents()
        {
            using (new ProfilerSample("UpdateChangeParents"))
            {
                if (m_ExistingParentsGroup.CalculateLength() < 1)
                {
                    return;
                }

                var changeParentsChunks = m_ExistingParentsGroup.CreateArchetypeChunkArray(Allocator.TempJob);
                if (changeParentsChunks.Length > 0)
                {
                    var parentType         = GetArchetypeChunkComponentType <UIParent>(true);
                    var previousParentType = GetArchetypeChunkComponentType <UIPreviousParent>(true);
                    var entityType         = GetArchetypeChunkEntityType();
                    var changedParents     = new NativeList <ChangedParent>(Allocator.TempJob);

                    var filterChangedParentsJob = new FilterChangedParents
                    {
                        Chunks             = changeParentsChunks,
                        ChangedParents     = changedParents,
                        ParentType         = parentType,
                        PreviousParentType = previousParentType,
                        EntityType         = entityType
                    };
                    var filterChangedParentsJobHandle = filterChangedParentsJob.Schedule();
                    filterChangedParentsJobHandle.Complete();

                    for (int i = 0; i < changedParents.Length; i++)
                    {
                        var childEntity          = changedParents[i].ChildEntity;
                        var previousParentEntity = changedParents[i].PreviousParentEntity;
                        var parentEntity         = changedParents[i].ParentEntity;

                        RemoveChildFromParent(childEntity, previousParentEntity);
                        AddChildToParent(childEntity, parentEntity);
                    }
                    changedParents.Dispose();
                }
                changeParentsChunks.Dispose();
            }
        }
Beispiel #22
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var chunks = m_Group.CreateArchetypeChunkArray(Allocator.TempJob);
            NativeList <SleepingNode> WakeNodes = new NativeList <SleepingNode>(Allocator.TempJob);
            var job = new WakeJob()
            {
                sleepTypes      = _sleepTypes,
                EntityType      = GetArchetypeChunkEntityType(),
                ArchetypeChunks = chunks,
                sleepNodes      = _sleepNodes,
            };

            var job_B = new WakeJob_B()
            {
                sleepTypes = _sleepTypes,
                sleepNodes = _sleepNodes,
                EntityType = GetArchetypeChunkEntityType(),
                WakeNodes  = WakeNodes
            };

            var handle   = job.Schedule(inputDeps);
            var handle_B = job_B.Schedule(handle);

            handle_B.Complete();

            for (int i = 0; i < WakeNodes.Length; i++)
            {
                var nodeInfo = WakeNodes[i];
                var runState = EntityManager.GetComponentData <ActionRunState>(nodeInfo.Entity);
                var Index    = new ActionStateIndex()
                {
                    ChunkIndex = runState.ChunkIndex,
                    NodeIndex  = nodeInfo.NodeIndex
                };
                ActionStateMapToAsset.Instance.GetContainer(runState.InstanceID).SetNodeCycle(Index, NodeCycle.Waking);
            }

            chunks.Dispose();
            WakeNodes.Dispose();
            return(inputDeps);
        }
Beispiel #23
0
        protected override void OnUpdate()
        {
            int newWidth  = Screen.width;
            int newHeight = Screen.height;

            if (m_OldWidth != newWidth || m_OldHeight != newHeight)
            {
                using (var chunkArray = m_UpdateSizeGroup.CreateArchetypeChunkArray(Allocator.TempJob))
                {
                    var sizeType   = GetArchetypeChunkComponentType <CanvasScreenSize>();
                    var entityType = GetArchetypeChunkEntityType();
                    NativeQueue <Entity> commandBuffer = new NativeQueue <Entity>(Allocator.Temp);
                    foreach (var chunk in chunkArray)
                    {
                        var canvasSize = new CanvasScreenSize()
                        {
                            Value = new int2(newWidth, newHeight)
                        };

                        var sizeArray   = chunk.GetNativeArray(sizeType);
                        var entityArray = chunk.GetNativeArray(entityType);
                        for (int i = 0; i < sizeArray.Length; i++)
                        {
                            if (!sizeArray[i].Value.Equals(canvasSize.Value))
                            {
                                commandBuffer.Enqueue(entityArray[i]);
                                sizeArray[i] = canvasSize;
                            }
                        }
                    }
                    while (commandBuffer.TryDequeue(out var entity))
                    {
                        EntityManager.AddComponent <RebuildCanvasHierarchyFlag>(entity);
                    }
                }

                m_OldWidth  = newWidth;
                m_OldHeight = newHeight;
            }
        }
Beispiel #24
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (m_connectionGroup.IsEmptyIgnoreFilter)
            {
                // No connected players, just destroy all asteroids to save CPU
                inputDeps.Complete();
                World.EntityManager.DestroyEntity(asteroidGroup);
                return(default(JobHandle));
            }
            var settings     = GetSingleton <ServerSettings>();
            var maxAsteroids = settings.numAsteroids;

            JobHandle gatherJob;
            var       countJob = new CountJob
            {
                chunks     = asteroidGroup.CreateArchetypeChunkArray(Allocator.TempJob, out gatherJob),
                count      = count,
                entityType = GetArchetypeChunkEntityType()
            };

            inputDeps = countJob.Schedule(JobHandle.CombineDependencies(inputDeps, gatherJob));

            JobHandle levelHandle;
            var       spawnJob = new SpawnJob
            {
                commandBuffer     = barrier.CreateCommandBuffer(),
                count             = count,
                targetCount       = maxAsteroids,
                asteroidArchetype = settings.asteroidArchetype,
                asteroidRadius    = settings.asteroidRadius,
                asteroidVelocity  = settings.asteroidVelocity,
                level             = m_LevelGroup.ToComponentDataArray <LevelComponent>(Allocator.TempJob, out levelHandle),
                rand = new Unity.Mathematics.Random((uint)Stopwatch.GetTimestamp())
            };
            var handle = spawnJob.Schedule(JobHandle.CombineDependencies(inputDeps, levelHandle));

            barrier.AddJobHandleForProducer(handle);
            return(handle);
        }
Beispiel #25
0
    protected override void OnUpdate()
    {
        var chunkComponentType = GetArchetypeChunkComponentType <Health>(true);

        using (var chunks = _query.CreateArchetypeChunkArray(Allocator.TempJob))
        {
            foreach (var chunk in chunks)
            {
                var healthVersion = chunk.GetComponentVersion(chunkComponentType);

                if (ChangeVersionUtility.DidChange(healthVersion, LastSystemVersion))
                {
                    Debug.Log("[CHUNK] Chunk contains entities with modified health.");
                    var healthItems = chunk.GetNativeArray(chunkComponentType);
                    foreach (var healthItem in healthItems)
                    {
                        Debug.Log($"[CHUNK] New health: {healthItem.Value}");
                    }
                }
            }
        }
    }
Beispiel #26
0
        protected override void OnUpdate()
        {
            var chunks = m_MissingRenderBounds.CreateArchetypeChunkArray(Allocator.TempJob);
            var archetypeChunkRenderMeshType = GetArchetypeChunkSharedComponentType <RenderMesh>();

            for (int i = 0; i < chunks.Length; ++i)
            {
                var chunk           = chunks[i];
                var sharedComponent = chunk.GetSharedComponentData(archetypeChunkRenderMeshType, EntityManager);
                if (sharedComponent.mesh != null)
                {
                    var entities = chunk.GetNativeArray(GetArchetypeChunkEntityType());
                    for (int j = 0; j < chunk.Count; ++j)
                    {
                        PostUpdateCommands.AddComponent(entities[j], new RenderBounds {
                            Value = sharedComponent.mesh.bounds.ToAABB()
                        });
                    }
                }
            }
            chunks.Dispose();
        }
Beispiel #27
0
        protected override void OnUpdate()
        {
            // Check for game-over condition (1+ entities with the NewGameTag component)
            var newGameChunks = _newGameQuery.CreateArchetypeChunkArray(Allocator.TempJob);

            if (newGameChunks.Length > 0)
            {
                if (_options == null)
                {
                    _options = GameObject.Find("Options").GetComponent <Options>();
                }

                Debug.Log("New game started!");

                // Destroy all existing entities between games
                var entityManager = World.EntityManager;
                var allEntities   = entityManager.GetAllEntities();
                entityManager.DestroyEntity(allEntities);
                allEntities.Dispose();
                // If the bootstrap object still exists, it can be disposed of as well.
                Object.Destroy(GameObject.Find("Bootstrapper"));

                // Create cannonball prefab entity
                _tankFireSystem.CreateCannonballPrefab();

                // Reset the terrain -- this destroys any existing cached terrain data, forcing it to be regenerated
                // the next time the system is updated.
                var terrain = World.GetOrCreateSystem <TerrainSystem>();
                terrain.Reset();

                // Reset the timer text to zero
                if (_timerText == null)
                {
                    _timerText = GameObject.Find("TimerText").GetComponent <TimerText>();
                }
                _timerText.ResetToZero();
            }
            newGameChunks.Dispose();
        }
Beispiel #28
0
        void ProcessQuery()
        {
            var universe = GameManager.Universe;
//            var entityType = GetArchetypeChunkEntityType();
            var eventityType = GetArchetypeChunkComponentType <CreateChunkEventity>(true);

            using (var ecsChunks = _eventQuery.CreateArchetypeChunkArray(Allocator.TempJob))
            {
                foreach (var ecsEventityChunk in ecsChunks)
                {
//                    using (var ecsEventityArray = ecsEventityChunk.GetNativeArray(entityType))
//                    {
                    var eventityArray = ecsEventityChunk.GetNativeArray(eventityType);
//                        var i = 0;
                    for (var i = 0; i < eventityArray.Length; i++)
                    {
                        var chunkPos = eventityArray[i].ChunkPosition;
                        var entity   = EntityManager.CreateEntity(_blockChunkArchetype);
                        EntityManager.SetComponentData(entity,
                                                       new ChunkIdComponent()
                        {
                            Value = chunkPos
                        });

                        EnforceChunkSize(entity);
                        InitializeBuffer(entity);
//                        i++;

                        universe[chunkPos.WorldId].Register(chunkPos.ChunkId, entity);
                    }


//                    }
                }
            }

            EntityManager.DestroyEntity(_eventQuery);
        }
    protected override void OnUpdate()
    {
        var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
        var chunks        = applyMeshGroup.CreateArchetypeChunkArray(Allocator.TempJob);

        var entityType = GetArchetypeChunkEntityType();
        var vertType   = GetArchetypeChunkBufferType <Vertex>(true);
        var triType    = GetArchetypeChunkBufferType <Triangle>(true);
        var colorType  = GetArchetypeChunkBufferType <VertColor>(true);

        for (int c = 0; c < chunks.Length; c++)
        {
            var chunk = chunks[c];

            var entities    = chunk.GetNativeArray(entityType);
            var vertArrays  = chunk.GetBufferAccessor <Vertex>(vertType);
            var triArrays   = chunk.GetBufferAccessor <Triangle>(triType);
            var colorArrays = chunk.GetBufferAccessor <VertColor>(colorType);

            for (int e = 0; e < entities.Length; e++)
            {
                Entity entity = entities[e];

                Mesh mesh = MakeMesh(vertArrays[e], triArrays[e], colorArrays[e]);
                SetMeshComponent(mesh, entity, commandBuffer);

                commandBuffer.RemoveComponent(entity, typeof(Vertex));
                commandBuffer.RemoveComponent(entity, typeof(Triangle));
                commandBuffer.RemoveComponent(entity, typeof(VertColor));
                commandBuffer.RemoveComponent(entity, typeof(WorleyNoise.PointData));
            }
        }

        commandBuffer.Playback(entityManager);
        commandBuffer.Dispose();

        chunks.Dispose();
    }
Beispiel #30
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            ArchetypeChunkSharedComponentType <SpriteAsset> assetType      = GetArchetypeChunkSharedComponentType <SpriteAsset>();
            ArchetypeChunkComponentType <SpriteVertexData>  spriteDataType = GetArchetypeChunkComponentType <SpriteVertexData>();

            using (var chunkArray = m_SpriteAssetGroup.CreateArchetypeChunkArray(Unity.Collections.Allocator.TempJob))
            {
                foreach (var chunk in chunkArray)
                {
                    var spriteDataArray = chunk.GetNativeArray(spriteDataType);
                    var asset           = chunk.GetSharedComponentData(assetType, EntityManager);
                    var spriteData      = SpriteUtility.GetSpriteVertexData(asset.Value);
                    spriteData.NativeMaterialId = chunk.GetSharedComponentIndex(assetType);
                    for (int i = 0; i < chunk.Count; i++)
                    {
                        spriteDataArray[i] = spriteData;
                    }
                    //chunk.SetChunkComponentData(spriteDataType, spriteData);
                }
            }
            EntityManager.AddComponent(m_SpriteAssetGroup, typeof(SpriteAssetInitialized));
            return(inputDeps);
        }