Beispiel #1
0
        // Returns true if it was successful in returning it to the pool
        public bool AttemptToUnload()
        {
            if (unload)
            {
                if (GetLoadState() == ChunkLoadState.LoadingFromDisk)
                {
                    return(false);
                }

                if (GetLoadState() == ChunkLoadState.BlocksGenerating ||
                    GetLoadState() == ChunkLoadState.MeshCalculating)
                {
                    bool workRevoked = AsyncService.GetCPUMediator().CancelProcessingRequest(this);
                    if (!workRevoked)
                    {
                        return(false);
                    }
                }

                if (GetLoadState() != ChunkLoadState.WaitingToGenerateBlocks)
                {
                    Save();
                }

                GeneratorService.ReturnChunk(this);
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        void OnApplicationQuit()
        {
            AsyncService.GetCPUMediator().Shutdown();

            UnityEngine.Debug.Log("Saving all loaded chunks...");
            ChunkRepository.SaveAllLoadedChunks();
            FileRepository.Shutdown();
            UnityEngine.Debug.Log("Done.");
        }
Beispiel #3
0
 public void Generate(Chunk northChunk, Chunk southChunk,
                      Chunk westChunk, Chunk eastChunk,
                      Chunk aboveChunk, Chunk belowChunk)
 {
     this.northChunk = northChunk;
     this.southChunk = southChunk;
     this.westChunk  = westChunk;
     this.eastChunk  = eastChunk;
     this.aboveChunk = aboveChunk;
     this.belowChunk = belowChunk;
     AsyncService.GetCPUMediator().EnqueueBatchForProcessing(generateMeshWorkFunction, (object)this,
                                                             CPUMediator.HIGH_PRIORITY, transform.position);
 }
Beispiel #4
0
        public void GenerateBlocks(float seed)
        {
            if (WaitingToGenerateBlocks())
            {
                SetLoadState(ChunkLoadState.BlocksGenerating);

                Vector3 position;
                position.x = worldPosition.x * SIZE;
                position.y = worldPosition.y * SIZE;
                position.z = worldPosition.z * SIZE;
                AsyncService.GetCPUMediator().EnqueueBatchForProcessing(generateBlocksWorkFunction,
                                                                        (object)this, CPUMediator.LOW_PRIORITY, position);
            }
        }