2012-02-16 08:42:35 -05:00
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
#ifndef __C_CHUNK_INL_H__
|
|
|
|
#define __C_CHUNK_INL_H__
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
# define MAX(a,b) (((a)>(b))?(a):(b))
|
|
|
|
#endif
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
__C_CHUNK_INLINE__
|
2012-03-05 11:41:57 -05:00
|
|
|
char cChunk::GetNibble(char* a_Buffer, int a_BlockIdx)
|
2011-12-31 16:08:23 -05:00
|
|
|
{
|
|
|
|
if( a_BlockIdx > -1 && a_BlockIdx < c_NumBlocks )
|
|
|
|
{
|
|
|
|
const int cindex = (a_BlockIdx/2);
|
|
|
|
if( (a_BlockIdx & 1) == 0 )
|
|
|
|
{ // First half byte
|
|
|
|
return (a_Buffer[cindex] & 0x0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ((a_Buffer[cindex] & 0xf0) >> 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
__C_CHUNK_INLINE__
|
2012-03-05 11:41:57 -05:00
|
|
|
char cChunk::GetNibble(char* a_Buffer, int x, int y, int z)
|
2011-12-31 16:08:23 -05:00
|
|
|
{
|
2012-03-03 15:55:16 -05:00
|
|
|
if( x < c_ChunkWidth && x > -1 && y < c_ChunkHeight && y > -1 && z < c_ChunkWidth && z > -1 )
|
2011-12-31 16:08:23 -05:00
|
|
|
{
|
2012-03-09 19:25:05 -05:00
|
|
|
const int cindex = MakeIndexNoCheck(x, y, z)/2;
|
2012-03-09 21:39:36 -05:00
|
|
|
#if AXIS_ORDER == AXIS_ORDER_XZY
|
|
|
|
if( (x & 1) == 0 )
|
2012-03-10 08:49:40 -05:00
|
|
|
#elif AXIS_ORDER == AXIS_ORDER_YZX
|
2011-12-31 16:08:23 -05:00
|
|
|
if( (y & 1) == 0 )
|
2012-03-09 21:39:36 -05:00
|
|
|
#endif
|
2011-12-31 16:08:23 -05:00
|
|
|
{ // First half byte
|
|
|
|
return (a_Buffer[cindex] & 0x0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ((a_Buffer[cindex] & 0xf0) >> 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
__C_CHUNK_INLINE__
|
2012-03-05 11:41:57 -05:00
|
|
|
void cChunk::SetNibble(char* a_Buffer, int a_BlockIdx, char a_Light)
|
2011-12-31 16:08:23 -05:00
|
|
|
{
|
|
|
|
if( a_BlockIdx > -1 && a_BlockIdx < c_NumBlocks )
|
|
|
|
{
|
|
|
|
const int cindex = (a_BlockIdx/2);
|
|
|
|
if( (a_BlockIdx & 1) == 0 )
|
|
|
|
{ // First half byte
|
|
|
|
a_Buffer[cindex] &= 0xf0; // Set first half to 0
|
|
|
|
a_Buffer[cindex] |= (a_Light) & 0x0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_Buffer[cindex] &= 0x0f; // Set second half to 0
|
|
|
|
a_Buffer[cindex] |= (a_Light << 4) & 0xf0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
__C_CHUNK_INLINE__
|
2012-03-05 11:41:57 -05:00
|
|
|
void cChunk::SetNibble(char* a_Buffer, int x, int y, int z, char light)
|
2011-12-31 16:08:23 -05:00
|
|
|
{
|
2012-03-03 15:55:16 -05:00
|
|
|
if( x < c_ChunkWidth && x > -1 && y < c_ChunkHeight && y > -1 && z < c_ChunkWidth && z > -1 )
|
2011-12-31 16:08:23 -05:00
|
|
|
{
|
2012-03-09 19:25:05 -05:00
|
|
|
int cindex = MakeIndexNoCheck(x, y, z)/2;
|
2012-03-09 21:39:36 -05:00
|
|
|
#if AXIS_ORDER == AXIS_ORDER_XZY
|
|
|
|
if( (x & 1) == 0 )
|
2012-03-10 08:49:40 -05:00
|
|
|
#elif AXIS_ORDER == AXIS_ORDER_YZX
|
2011-12-31 16:08:23 -05:00
|
|
|
if( (y & 1) == 0 )
|
2012-03-09 21:39:36 -05:00
|
|
|
#endif
|
2011-12-31 16:08:23 -05:00
|
|
|
{ // First half byte
|
|
|
|
a_Buffer[cindex] &= 0xf0; // Set first half to 0
|
|
|
|
a_Buffer[cindex] |= (light) & 0x0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_Buffer[cindex] &= 0x0f; // Set second half to 0
|
|
|
|
a_Buffer[cindex] |= (light << 4) & 0xf0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
__C_CHUNK_INLINE__
|
|
|
|
void cChunk::SpreadLightOfBlock(char* a_LightBuffer, int a_X, int a_Y, int a_Z, char a_Falloff)
|
|
|
|
{
|
2012-03-05 11:41:57 -05:00
|
|
|
unsigned char CurrentLight = GetNibble( a_LightBuffer, a_X, a_Y, a_Z );
|
|
|
|
SetNibble( a_LightBuffer, a_X-1, a_Y, a_Z, MAX(GetNibble( a_LightBuffer, a_X-1, a_Y, a_Z ), MAX(0,CurrentLight-a_Falloff) ) );
|
|
|
|
SetNibble( a_LightBuffer, a_X+1, a_Y, a_Z, MAX(GetNibble( a_LightBuffer, a_X+1, a_Y, a_Z ), MAX(0,CurrentLight-a_Falloff) ) );
|
|
|
|
SetNibble( a_LightBuffer, a_X, a_Y-1, a_Z, MAX(GetNibble( a_LightBuffer, a_X, a_Y-1, a_Z ), MAX(0,CurrentLight-a_Falloff) ) );
|
|
|
|
SetNibble( a_LightBuffer, a_X, a_Y+1, a_Z, MAX(GetNibble( a_LightBuffer, a_X, a_Y+1, a_Z ), MAX(0,CurrentLight-a_Falloff) ) );
|
|
|
|
SetNibble( a_LightBuffer, a_X, a_Y, a_Z-1, MAX(GetNibble( a_LightBuffer, a_X, a_Y, a_Z-1 ), MAX(0,CurrentLight-a_Falloff) ) );
|
|
|
|
SetNibble( a_LightBuffer, a_X, a_Y, a_Z+1, MAX(GetNibble( a_LightBuffer, a_X, a_Y, a_Z+1 ), MAX(0,CurrentLight-a_Falloff) ) );
|
|
|
|
MarkDirty();
|
2011-12-31 16:08:23 -05:00
|
|
|
}
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
__C_CHUNK_INLINE__
|
|
|
|
void cChunk::SpreadLightOfBlockX(char* a_LightBuffer, int a_X, int a_Y, int a_Z)
|
|
|
|
{
|
2012-03-05 11:41:57 -05:00
|
|
|
unsigned char CurrentLight = GetNibble( a_LightBuffer, a_X, a_Y, a_Z );
|
|
|
|
SetNibble( a_LightBuffer, a_X-1, a_Y, a_Z, MAX(GetNibble( a_LightBuffer, a_X-1, a_Y, a_Z ), CurrentLight-1) );
|
|
|
|
SetNibble( a_LightBuffer, a_X+1, a_Y, a_Z, MAX(GetNibble( a_LightBuffer, a_X+1, a_Y, a_Z ), CurrentLight-1) );
|
|
|
|
MarkDirty();
|
2011-12-31 16:08:23 -05:00
|
|
|
}
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
__C_CHUNK_INLINE__
|
|
|
|
void cChunk::SpreadLightOfBlockY(char* a_LightBuffer, int a_X, int a_Y, int a_Z)
|
|
|
|
{
|
2012-03-05 11:41:57 -05:00
|
|
|
unsigned char CurrentLight = GetNibble( a_LightBuffer, a_X, a_Y, a_Z );
|
|
|
|
SetNibble( a_LightBuffer, a_X, a_Y-1, a_Z, MAX(GetNibble( a_LightBuffer, a_X, a_Y-1, a_Z ), CurrentLight-1) );
|
|
|
|
SetNibble( a_LightBuffer, a_X, a_Y+1, a_Z, MAX(GetNibble( a_LightBuffer, a_X, a_Y+1, a_Z ), CurrentLight-1) );
|
|
|
|
MarkDirty();
|
2011-12-31 16:08:23 -05:00
|
|
|
}
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
__C_CHUNK_INLINE__
|
|
|
|
void cChunk::SpreadLightOfBlockZ(char* a_LightBuffer, int a_X, int a_Y, int a_Z)
|
|
|
|
{
|
2012-03-05 11:41:57 -05:00
|
|
|
unsigned char CurrentLight = GetNibble( a_LightBuffer, a_X, a_Y, a_Z );
|
|
|
|
SetNibble( a_LightBuffer, a_X, a_Y, a_Z-1, MAX(GetNibble( a_LightBuffer, a_X, a_Y, a_Z-1 ), CurrentLight-1) );
|
|
|
|
SetNibble( a_LightBuffer, a_X, a_Y, a_Z+1, MAX(GetNibble( a_LightBuffer, a_X, a_Y, a_Z+1 ), CurrentLight-1) );
|
|
|
|
MarkDirty();
|
2011-12-31 16:08:23 -05:00
|
|
|
}
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-31 16:08:23 -05:00
|
|
|
#endif
|