VMan  1.0
Library for voxel managment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Chunk Class Reference

#include <Chunk.h>

+ Collaboration diagram for Chunk:

Public Member Functions

 Chunk (Volume *volume, int chunkX, int chunkY, int chunkZ)
 
 ~Chunk ()
 
int getChunkX () const
 
int getChunkY () const
 
int getChunkZ () const
 
ChunkId getId () const
 
std::string toString () const
 
void * getLayer (int index)
 
const void * getConstLayer (int index) const
 
bool loadFromFile ()
 
bool saveToFile ()
 
void addReference ()
 
void releaseReference ()
 
bool isUnused () const
 
bool isModified () const
 
time_t getModificationTime () const
 
void setModified ()
 
tthread::mutex * getMutex ()
 
 Chunk (const Chunk &chunk)
 
Chunkoperator= (const Chunk &chunk)
 
void initializeLayer (int index)
 
void clearLayers (bool silent=false)
 
void unsetModified ()
 

Static Public Member Functions

static ChunkId GenerateChunkId (int chunkX, int chunkY, int chunkZ)
 
static std::string ChunkCoordsToString (int chunkX, int chunkY, int chunkZ)
 
static std::string ChunkIdToString (ChunkId chunkId)
 
static void UnpackChunkId (ChunkId chunkId, int *outX, int *outY, int *outZ)
 

Public Attributes

Volumem_Volume
 
const int m_ChunkX
 
const int m_ChunkY
 
const int m_ChunkZ
 
std::vector< char * > m_Layers
 
bool m_Modified
 
time_t m_ModificationTime
 
tthread::atomic_int m_References
 
tthread::mutex m_Mutex
 

Detailed Description

Definition at line 18 of file Chunk.h.

Constructor & Destructor Documentation

Chunk ( Volume volume,
int  chunkX,
int  chunkY,
int  chunkZ 
)

Definition at line 58 of file Chunk.cpp.

~Chunk ( )

Definition at line 68 of file Chunk.cpp.

+ Here is the call graph for this function:

Chunk ( const Chunk chunk)

Forbidden Stuff.

Definition at line 426 of file Chunk.cpp.

Member Function Documentation

ChunkId GenerateChunkId ( int  chunkX,
int  chunkY,
int  chunkZ 
)
static

Definition at line 21 of file Chunk.cpp.

+ Here is the caller graph for this function:

static std::string ChunkCoordsToString ( int  chunkX,
int  chunkY,
int  chunkZ 
)
static
std::string ChunkIdToString ( ChunkId  chunkId)
static

Definition at line 51 of file Chunk.cpp.

+ Here is the call graph for this function:

int getChunkX ( ) const

Definition at line 76 of file Chunk.cpp.

int getChunkY ( ) const

Definition at line 81 of file Chunk.cpp.

int getChunkZ ( ) const

Definition at line 86 of file Chunk.cpp.

ChunkId getId ( ) const

Definition at line 91 of file Chunk.cpp.

+ Here is the call graph for this function:

std::string toString ( ) const

Definition at line 96 of file Chunk.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void * getLayer ( int  index)

Will create a layer if it doesn't exists already.

Data is initialized to 0. Use the chunk edge length to compute the array size.

Returns
Data of the given layer.
See Also
Volume::getChunkEdgeLength

Definition at line 129 of file Chunk.cpp.

+ Here is the call graph for this function:

const void * getConstLayer ( int  index) const

Const pointer version of getLayer.

Returns
NULL if a layer doesn't exists.
See Also
getLayer

Definition at line 139 of file Chunk.cpp.

bool loadFromFile ( )

Clears chunk on failure!

Returns
false if the file is not readable.

Definition at line 187 of file Chunk.cpp.

+ Here is the call graph for this function:

bool saveToFile ( )

Will unset m_Modified on success.

Returns
true on success.

Definition at line 290 of file Chunk.cpp.

+ Here is the call graph for this function:

void addReference ( )

Increments the internal reference counter.

Chunks with reference won't be unloaded. Is thread safe.

See Also
releaseReference

Definition at line 371 of file Chunk.cpp.

+ Here is the caller graph for this function:

void releaseReference ( )

Decrements the internal reference counter.

Is thread safe.

See Also
addReference

Definition at line 377 of file Chunk.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool isUnused ( ) const

Is thread safe.

Whether the chunk may be unloaded.

Definition at line 387 of file Chunk.cpp.

bool isModified ( ) const

Definition at line 392 of file Chunk.cpp.

+ Here is the caller graph for this function:

time_t getModificationTime ( ) const

Timestamp of the first modification since last save event.

Definition at line 397 of file Chunk.cpp.

void setModified ( )

If it wasn't modified before: Sets the modification flag, updates the modification time and adds the chunk to the modified list.

Definition at line 402 of file Chunk.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

tthread::mutex * getMutex ( )

Use this to lock the object while using methods that aren't thread safe.

Definition at line 417 of file Chunk.cpp.

+ Here is the caller graph for this function:

void UnpackChunkId ( ChunkId  chunkId,
int *  outX,
int *  outY,
int *  outZ 
)
static

Definition at line 36 of file Chunk.cpp.

+ Here is the caller graph for this function:

Chunk & operator= ( const Chunk chunk)

Definition at line 434 of file Chunk.cpp.

void initializeLayer ( int  index)

Definition at line 101 of file Chunk.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void clearLayers ( bool  silent = false)

Deletes all layers and resets them to NULL.

If at least one layer was deleted m_Modified will be set.

Definition at line 115 of file Chunk.cpp.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void unsetModified ( )

Resets the modified flag.

Definition at line 412 of file Chunk.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

Volume* m_Volume

Definition at line 125 of file Chunk.h.

const int m_ChunkX

Definition at line 127 of file Chunk.h.

const int m_ChunkY

Definition at line 128 of file Chunk.h.

const int m_ChunkZ

Definition at line 129 of file Chunk.h.

std::vector<char*> m_Layers

Holds voxel arrays for all layers registered in the volume.

A pointer is NULL if the layer is not used in this chunk, in that case the layers default voxel value shuld be used. Voxels have to be initialized with 0!

Definition at line 137 of file Chunk.h.

bool m_Modified

Which layers are compressed.

True when the chunk has been modified and needs to be written to disk.

Definition at line 148 of file Chunk.h.

time_t m_ModificationTime

Timestamp of the first modification since last save event.

Is updated each time, when m_Modified changes from false to true.

Definition at line 155 of file Chunk.h.

tthread::atomic_int m_References

Reference count on this chunk.

Definition at line 167 of file Chunk.h.

tthread::mutex m_Mutex
mutable

Definition at line 169 of file Chunk.h.


The documentation for this class was generated from the following files: