2012-02-08 07:36:54 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
// cChunkMap.h
|
|
|
|
|
|
|
|
// Interfaces to the cChunkMap class representing the chunk storage for a single world
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#pragma once
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
#include "cChunk.h"
|
|
|
|
|
2012-02-08 07:36:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-30 20:52:20 -04:00
|
|
|
class cWorld;
|
2011-10-03 14:41:19 -04:00
|
|
|
class cEntity;
|
2012-02-08 07:36:54 -05:00
|
|
|
class MTRand;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
class cChunkMap
|
|
|
|
{
|
|
|
|
public:
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
static const int LAYER_SIZE = 32;
|
|
|
|
|
2012-01-29 16:40:21 -05:00
|
|
|
cChunkMap(cWorld* a_World );
|
2011-10-03 14:41:19 -04:00
|
|
|
~cChunkMap();
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cChunkPtr GetChunk ( int a_X, int a_Y, int a_Z ); // Also queues the chunk for loading / generating if not valid
|
|
|
|
cChunkPtr GetChunkNoGen( int a_X, int a_Y, int a_Z ); // Also queues the chunk for loading if not valid; doesn't generate
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-08 07:36:54 -05:00
|
|
|
void Tick( float a_Dt, MTRand & a_TickRand );
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
void UnloadUnusedChunks();
|
|
|
|
void SaveAllChunks();
|
2011-12-24 18:34:30 -05:00
|
|
|
|
|
|
|
cWorld* GetWorld() { return m_World; }
|
2012-01-01 11:20:52 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
int GetNumChunks(void);
|
2012-02-08 07:36:54 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
private:
|
2012-02-08 07:36:54 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
class cChunkLayer
|
|
|
|
{
|
|
|
|
public:
|
2012-02-13 16:47:03 -05:00
|
|
|
cChunkLayer(int a_LayerX, int a_LayerZ, cChunkMap * a_Parent);
|
|
|
|
|
|
|
|
/// Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check
|
|
|
|
cChunkPtr GetChunk( int a_ChunkX, int a_ChunkZ );
|
|
|
|
|
|
|
|
int GetX(void) const {return m_LayerX; }
|
|
|
|
int GetZ(void) const {return m_LayerZ; }
|
|
|
|
int GetNumChunksLoaded(void) const {return m_NumChunksLoaded; }
|
2012-01-30 08:54:39 -05:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
void Save(void);
|
|
|
|
void UnloadUnusedChunks(void);
|
|
|
|
|
|
|
|
void Tick( float a_Dt, MTRand & a_TickRand );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
cChunkPtr m_Chunks[LAYER_SIZE * LAYER_SIZE];
|
|
|
|
int m_LayerX;
|
|
|
|
int m_LayerZ;
|
|
|
|
cChunkMap * m_Parent;
|
2011-10-03 14:41:19 -04:00
|
|
|
int m_NumChunksLoaded;
|
|
|
|
};
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
typedef std::list<cChunkLayer *> 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[]
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
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 );
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cCriticalSection m_CSLayers;
|
|
|
|
cChunkLayerList m_Layers;
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
cWorld * m_World;
|
2011-10-29 17:19:06 -04:00
|
|
|
};
|
2012-02-08 07:36:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|