From 310c1076a7acce6e4dd4c2611527b65fe86fe351 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Fri, 14 Dec 2012 22:38:30 +0000 Subject: cChunk now tracks its neighbors as direct pointers; used in UnboundedRelGetBlock et al. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1073 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/ChunkMap.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'source/ChunkMap.h') diff --git a/source/ChunkMap.h b/source/ChunkMap.h index 38d16d0c4..5dd4778ce 100644 --- a/source/ChunkMap.h +++ b/source/ChunkMap.h @@ -264,6 +264,9 @@ private: /// Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check cChunkPtr GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ ); + /// Returns the specified chunk, or NULL if not created yet + cChunk * FindChunk(int a_ChunkX, int a_ChunkZ); + int GetX(void) const {return m_LayerX; } int GetZ(void) const {return m_LayerZ; } @@ -288,12 +291,20 @@ private: }; typedef std::list cChunkLayerList; - // TODO: Use smart pointers for cChunkLayerList as well, so that ticking and saving needn't lock the entire layerlist - // This however means that cChunkLayer needs to interlock its m_Chunks[] - cChunkLayer * GetLayerForChunk( int a_ChunkX, int a_ChunkZ ); // Creates the layer if it doesn't already exist - cChunkLayer * GetLayer( int a_LayerX, int a_LayerZ ); // Creates the layer if it doesn't already exist - void RemoveLayer( cChunkLayer* a_Layer ); + /// Finds the cChunkLayer object responsible for the specified chunk; returns NULL if not found. Assumes m_CSLayers is locked. + cChunkLayer * FindLayerForChunk(int a_ChunkX, int a_ChunkZ); + + /// Returns the specified cChunkLayer object; returns NULL if not found. Assumes m_CSLayers is locked. + cChunkLayer * FindLayer(int a_LayerX, int a_LayerZ); + + /// Returns the cChunkLayer object responsible for the specified chunk; creates it if not found. + cChunkLayer * GetLayerForChunk (int a_ChunkX, int a_ChunkZ); + + /// Returns the specified cChunkLayer object; creates it if not found. + cChunkLayer * GetLayer(int a_LayerX, int a_LayerZ); + + void RemoveLayer(cChunkLayer * a_Layer); cCriticalSection m_CSLayers; cChunkLayerList m_Layers; @@ -313,6 +324,9 @@ private: /// Fast-sets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) bool LockedFastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + + /// Locates a chunk ptr in the chunkmap; doesn't create it when not found; assumes m_CSLayers is locked. To be called only from cChunkMap. + cChunk * FindChunk(int a_ChunkX, int a_ChunkZ); }; -- cgit v1.2.3