Beispiel #1
0
    public static NBTChunk LoadChunk(int chunkX, int chunkZ)
    {
        UnityEngine.Profiling.Profiler.BeginSample("ChunkChecker.Update");

        key.Set(chunkX, chunkZ);
        if (!chunkDict.ContainsKey(key))
        {
            TagNodeCompound Chunk = GetChunkNode(chunkX, chunkZ);
            if (Chunk != null)
            {
                TagNodeCompound Level = Chunk["Level"] as TagNodeCompound;

                TagNodeList Sections = Level["Sections"] as TagNodeList;
                NBTChunk    chunk    = ChunkPool.GetChunk();
                chunk.SetData(chunkX, chunkZ, Sections);
                chunkDict.Add(key, chunk);
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();

        if (chunkDict.ContainsKey(key))
        {
            return(chunkDict[key]);
        }
        return(null);
    }
Beispiel #2
0
 void InitChunks()
 {
     for (int i = 0; i < CountChunksAtStart; i++)
     {
         CurrentChunks.Add(ChunkPool.GetChunk());
     }
 }
Beispiel #3
0
    public static void LoadChunk(CSChunk csChunk)
    {
        //Debug.Log("loadChunk,x=" + csChunk.Position.x + ",z=" + csChunk.Position.y);
        Chunk chunk = ChunkPool.GetChunk();

        chunk.SetData(csChunk.Position.x, csChunk.Position.y, csChunk.BlocksInBytes);
        AddToChunkDict(chunk);
        ChunkRefresher.Add(chunk);
    }
Beispiel #4
0
        private Chunk GenerateChunk(ChunkSpacePosition position)
        {
            int arrayX = (position.x - worldViewPositionX) + Configuration.CHUNK_VIEW_DISTANCE;
            int arrayZ = (position.z - worldViewPositionZ) + Configuration.CHUNK_VIEW_DISTANCE;

            Chunk newChunk = chunkPool.GetChunk(position);

            ChunkRepository.Add(newChunk);
            ChunkRepository.SetChunkAtPosition(position, newChunk);
            loadedChunksCheckArray[arrayX, position.y, arrayZ] = true;
            newChunk.LoadOrGenerate();
            return(newChunk);
        }
Beispiel #5
0
    void CheckLast()
    {
        if (CurrentChunks.Count <= 1)
        {
            return;
        }
        CurrentDistance.x = Mathf.Abs(Block.transform.position.x - Rocket.transform.position.x);
        CurrentDistance.y = Mathf.Abs(Block.transform.position.y - Rocket.transform.position.y);
        if (CurrentDistance.x > Distance || CurrentDistance.y > Distance)
        {
            var chunk = CurrentChunks[0];


            Block.position = chunk.transform.position;
            CurrentChunks.Remove(chunk);
            chunk.ChunkDisable();
            CurrentChunks.Add(ChunkPool.GetChunk());
            if (!lockSpeed)
            {
                ChangeSpeed();
            }
        }
    }
Beispiel #6
0
    public static async Task <NBTChunk> LoadChunkAsync(int chunkX, int chunkZ)
    {
        Vector2Int key = new Vector2Int(chunkX, chunkZ);

        if (!chunkDict.ContainsKey(key))
        {
            TagNodeCompound Chunk = await GetChunkNodeAsync(chunkX, chunkZ);

            if (Chunk != null)
            {
                TagNodeCompound Level = Chunk["Level"] as TagNodeCompound;
                NBTChunk        chunk = ChunkPool.GetChunk();
                chunk.SetData(chunkX, chunkZ, Level);
                chunkDict.Add(key, chunk);
            }
        }

        if (chunkDict.ContainsKey(key))
        {
            return(chunkDict[key]);
        }
        return(null);
    }