My Project
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
ParaEngine::BlockChunk Class Reference

Chunk is a 16*16*16 inside a region. More...

#include <BlockChunk.h>

Public Member Functions

 BlockChunk (uint16_t nPackedChunkId, BlockRegion *pRegion)
 
void ReserveBlocks (int nCount)
 
int GetTotalBytes ()
 get total number of memory bytes that this chunk occupies. More...
 
bool CanBlockSeeTheSkyWS (uint16 x, uint16 y, uint16 z)
 blocks higher than the highest solid block in the height map can sky. More...
 
uint32 GetBlockCount ()
 
bool IsDirty () const
 
void SetDirty (bool val)
 set dirty by block changes in this chunk
 
void SetDirtyByNeighbor ()
 set dirty by neighbor block change. More...
 
void SetLightDirty ()
 
bool IsDirtyByNeighbor ()
 whether this chunk is made dirty by neighbor other than content change. More...
 
bool IsDirtyByLight ()
 whether this chunk is made dirty by light than content change. More...
 
bool IsDirtyByBlockChange ()
 whether this chunk is made dirty by actual block changes. More...
 
void SetLightingInitialized (bool bInitialized)
 
bool IsLightingInitialized ()
 
void Reset ()
 
BlockGetBlockByIndex (uint16_t nBlockIndex)
 the caller should ensure that nBlockIndex is valid. More...
 
BlockGetBlock (uint16_t nBlockIndex)
 get block More...
 
int LoadBlocks (const std::vector< uint16_t > &blockIndices, BlockTemplate *pTemplate)
 load one or more blocks of a given block type. More...
 
Uint16x3 GetBlockPosRs (uint16 nBlockIndex)
 
void UpdateHeightMapAtLoadTime (uint16_t nBlockIndex, bool isTransparent)
 
void LoadBlock (uint16_t nBlockIndex, BlockTemplate *pTemplate)
 
void SetBlockTemplate (uint16_t nBlockIndex, BlockTemplate *pTemplate)
 
BlockTemplateGetBlockTemplate (uint16_t nBlockIndex)
 
void SetBlockData (uint16_t nBlockIndex, uint32 nData)
 
void SetBlock (uint16_t nBlockIndex, BlockTemplate *pTemplate, uint32 nData)
 set block template and data
 
CBlockWorldGetBlockWorld ()
 get container block world
 
bool SetBlockToAir (Uint16x3 &blockId_r)
 set block to empty More...
 
bool RemoveLight (Uint16x3 &blockId_r)
 remove light More...
 
void AddLight (Uint16x3 &blockId_r)
 add light
 
void AddLight (uint16 nPackedBlockID)
 
LightDataGetLightData (uint16_t nIndex)
 get the light data. More...
 
bool IsInfluenceBySunLight ()
 is any block influenced by sun light. More...
 
bool IsVisibleBlock (int32_t index, Block *pBlock=NULL)
 
void QueryNeighborBlockData (const Uint16x3 &blockId_cs, Block **pBlockData, int nFrom=0, int nTo=26)
 
bool IsNearbyChunksLoaded ()
 return true if the nearby 4 chunk columns have been generated (and loaded)
 
std::vector< Uint16x3refreshBlockVisible (uint16_t blockTemplateId)
 return the blocks need to re notification
 
void ClearAllLight ()
 

Static Public Member Functions

static int GetTotalChunksInMemory ()
 

Public Attributes

std::vector< int16_t > m_blockIndices
 
std::set< uint16_t > m_lightBlockIndices
 
std::vector< LightDatam_lightmapArray
 16*16*16 of light data (fixed sized at initialization)
 
Uint16x3 m_minBlockId_ws
 
Uint16x3 m_minBlockId_rs
 
Uint16x3 m_chunkId_rs
 

Static Public Attributes

static int s_total_chunks = 0
 total number of chunks
 

Protected Member Functions

bool IsBoundaryChunk () const
 
void SetBoundaryChunk (bool val)
 
int16 FindBlock (BlockTemplate *pTemplate)
 find block in the m_blocks pool by template. More...
 
int16 FindBlock (BlockTemplate *pTemplate, uint32 nData)
 
void SetBlockEmpty (uint16_t nBlockIndex, Block &block)
 
bool RecycleBlock (uint16 nIndex, Block &block)
 
BlockCreateBlock (uint16_t nBlockIndex)
 

Protected Attributes

std::vector< Blockm_blocks
 
uint32 m_nDirty
 
uint16 m_isBoundaryChunk
 
uint16 m_emptyBlockSlotIndex
 
BlockRegionm_ownerBlockRegion
 
int16_t m_packedChunkID
 

Detailed Description

Chunk is a 16*16*16 inside a region.

Member Function Documentation

§ CanBlockSeeTheSkyWS()

bool ParaEngine::BlockChunk::CanBlockSeeTheSkyWS ( uint16  x,
uint16  y,
uint16  z 
)

blocks higher than the highest solid block in the height map can sky.

Note, the top most opaque block can not see the sky.

Parameters
x,y,zin world space

§ FindBlock()

int16 ParaEngine::BlockChunk::FindBlock ( BlockTemplate pTemplate)
protected

find block in the m_blocks pool by template.

return -1 if not found.

§ GetBlock()

Block * ParaEngine::BlockChunk::GetBlock ( uint16_t  nBlockIndex)

get block

Parameters
nBlockIndex[0,4096)

§ GetBlockByIndex()

Block & ParaEngine::BlockChunk::GetBlockByIndex ( uint16_t  nBlockIndex)

the caller should ensure that nBlockIndex is valid.

§ GetLightData()

LightData * ParaEngine::BlockChunk::GetLightData ( uint16_t  nIndex)

get the light data.

may return NULL.

Parameters
nIndexparameters

§ GetTotalBytes()

int ParaEngine::BlockChunk::GetTotalBytes ( )

get total number of memory bytes that this chunk occupies.

for memory algorithm or stats.

§ IsDirtyByBlockChange()

bool ParaEngine::BlockChunk::IsDirtyByBlockChange ( )

whether this chunk is made dirty by actual block changes.

§ IsDirtyByLight()

bool ParaEngine::BlockChunk::IsDirtyByLight ( )

whether this chunk is made dirty by light than content change.

§ IsDirtyByNeighbor()

bool ParaEngine::BlockChunk::IsDirtyByNeighbor ( )

whether this chunk is made dirty by neighbor other than content change.

§ IsInfluenceBySunLight()

bool ParaEngine::BlockChunk::IsInfluenceBySunLight ( )

is any block influenced by sun light.

§ LoadBlocks()

int ParaEngine::BlockChunk::LoadBlocks ( const std::vector< uint16_t > &  blockIndices,
BlockTemplate pTemplate 
)

load one or more blocks of a given block type.

usually called when chunk is loaded from file return the number of blocks created.

§ QueryNeighborBlockData()

void ParaEngine::BlockChunk::QueryNeighborBlockData ( const Uint16x3 blockId_cs,
Block **  pBlockData,
int  nFrom = 0,
int  nTo = 26 
)
Parameters
pBlockDataBlock* neighborBlocks[27] depending on nFrom, nTo;
nFrom,nTodefault to query all 27 neighbor. Other frequently used ones are 1,6 (for six adjacent ones)

§ RemoveLight()

bool ParaEngine::BlockChunk::RemoveLight ( Uint16x3 blockId_r)

remove light

Parameters
blockId_rregion space

§ SetBlockToAir()

bool ParaEngine::BlockChunk::SetBlockToAir ( Uint16x3 blockId_r)

set block to empty

Parameters
blockId_rregion space

§ SetDirtyByNeighbor()

void ParaEngine::BlockChunk::SetDirtyByNeighbor ( )

set dirty by neighbor block change.


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