コード例 #1
0
    public bool IsJobInQueue(Vector3 chunkLocation)
    {
        GenerateChunkJob check = new GenerateChunkJob();

        check.chunkLocationToGenerate = chunkLocation;

        if (check.Equals(activeGenerationJob))
        {
            return(true);
        }
        else if (generationQueue.Contains(check))
        {
            return(true);
        }
        else if (check.Equals(activeMeshJob))
        {
            return(true);
        }
        else if (meshGenerationQueue.Contains(check.ToMeshJob()))
        {
            return(true);
        }

        return(false);
    }
コード例 #2
0
 public void RemoveGenerationJob(GenerateChunkJob jobToRemove)
 {
     if (jobToRemove.Equals(activeGenerationJob))
     {
         activeGenerationJob.Abort();
         activeGenerationJob    = null;
         hasActiveGenerationJob = false;
     }
     else if (!generationQueue.Contains(jobToRemove))
     {
         if (jobToRemove.Equals(activeMeshJob))
         {
             activeMeshJob.Abort();
             activeMeshJob    = null;
             hasActiveMeshJob = false;
         }
         else
         {
             meshGenerationQueue.Remove(jobToRemove.ToMeshJob());
         }
     }
     else
     {
         generationQueue.Remove(jobToRemove);
     }
 }
コード例 #3
0
    void RemoveChunkJob(Vector3 targetRemovalPositon)
    {
        GenerateChunkJob removalJob = new GenerateChunkJob();

        removalJob.chunkLocationToGenerate = targetRemovalPositon;

        generationJobManager.RemoveGenerationJob(removalJob);
    }
コード例 #4
0
    public bool Equals(GenerateChunkJob check)
    {
        if (check == null)
        {
            return(false);
        }

        if (chunkLocationToGenerate == check.chunkLocationToGenerate)
        {
            return(true);
        }

        return(false);
    }
コード例 #5
0
 private void LoadNewChunksNearPlayer(Vector3 playerChunkLocation)
 {
     for (int i = -chunksAroundPlayer; i < chunksAroundPlayer + 1; i++)
     {
         for (int k = -chunksAroundPlayer; k < chunksAroundPlayer + 1; k++)
         {
             if (!chunkMap.IsChunkLoaded(new Vector3(playerChunkLocation.x + i, 0, playerChunkLocation.z + k)))
             {
                 GenerateChunkJob chunkToGenerate = new GenerateChunkJob();
                 chunkToGenerate.chunkLocationToGenerate = new Vector3(playerChunkLocation.x + i, 0, playerChunkLocation.z + k);
                 generationJobManager.AddGenerationJob(chunkToGenerate);
                 chunkMap.AddLoadedChunk(new Vector3(playerChunkLocation.x + i, 0, playerChunkLocation.z + k));
             }
         }
     }
 }
コード例 #6
0
    private void CheckActiveGenerationJob()
    {
        if (activeGenerationJob != null)
        {
            if (activeGenerationJob.Update())
            {
                hasActiveGenerationJob = false;

                GenerateMeshFromChunkJob meshJob = new GenerateMeshFromChunkJob();
                meshJob.chunkCoordinates = activeGenerationJob.chunkLocationToGenerate;
                meshJob.chunkVoxelArray  = activeGenerationJob.chunkVoxelArray;
                AddMeshJob(meshJob);

                activeGenerationJob = null;
            }
        }
    }
コード例 #7
0
    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        var generateBURSTJob = new GenerateChunkBURSTJob
        {
            ChunkSize = ChunkMarkGenerateJS.ChunkSize,
            cbd       = GetBufferFromEntity <ChunkBufferData>()
        };
        var handle = generateBURSTJob.Schedule(this, inputDeps);

        var generateJob = new GenerateChunkJob
        {
            commandBuffer = ecbSystem.CreateCommandBuffer().ToConcurrent(),
        };

        handle = generateJob.Schedule(this, handle);
        ecbSystem.AddJobHandleForProducer(handle);
        return(handle);
    }
コード例 #8
0
    public void GenerateAllNewChunks(int chunkWidth, int chunkHeight)
    {
        if (newChunks.Count > 0)
        {
            NativeList <JobHandle> jobHandleList = new NativeList <JobHandle>(Allocator.Temp);
            foreach (TerrainChunk c in newChunks.Values)
            {
                //NativeHashMap<float2, bool> stateMap = new NativeHashMap<float2, bool>(chunkWidth * chunkHeight, Allocator.TempJob);
                NativeList <bool> stateList = new NativeList <bool>(chunkWidth * chunkHeight, Allocator.TempJob);
                GenerateChunkJob  chunkJob  = new GenerateChunkJob
                {
                    width       = chunkWidth,
                    height      = chunkHeight,
                    position    = c.position,
                    seed        = planetSettings.planetSeed,
                    featureSize = planetSettings.planetFeatureSize,
                    tileStates  = stateList
                };
                chunkBoolMap.Add(stateList);
                jobHandleList.Add(chunkJob.Schedule());
            }
            JobHandle.CompleteAll(jobHandleList);

            int index = 0;

            foreach (TerrainChunk c in newChunks.Values)
            {
                c.SetTileStatesFromNativeList(chunkBoolMap[index]);


                c.GenerateChunk();

                chunkBoolMap[index].Dispose();
                index++;
            }
            //CombineMeshes();

            jobHandleList.Dispose();

            chunkBoolMap.Clear();
            newChunks.Clear();
        }
    }
コード例 #9
0
 public void AddGenerationJob(GenerateChunkJob jobToAdd)
 {
     generationQueue.Enqueue(jobToAdd);
 }
コード例 #10
0
 private void StartNextGenerationJob()
 {
     activeGenerationJob    = generationQueue.Dequeue();
     hasActiveGenerationJob = true;
     activeGenerationJob.Start();
 }