Implemented suggestions
This commit is contained in:
parent
01546020fc
commit
ffce8d6907
@ -378,16 +378,14 @@ void cChunk::SetLight(
|
|||||||
// TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation.
|
// TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation.
|
||||||
// Postponing until we see how bad it is :)
|
// Postponing until we see how bad it is :)
|
||||||
|
|
||||||
{ // Compress blocklight
|
|
||||||
bool FoundNonEmpty = false;
|
|
||||||
int IdxWhereNonEmptyStarts = 0;
|
int IdxWhereNonEmptyStarts = 0;
|
||||||
|
{ // Compress blocklight
|
||||||
m_BlockLight.clear();
|
m_BlockLight.clear();
|
||||||
|
|
||||||
for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--)
|
for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--)
|
||||||
{
|
{
|
||||||
if (a_BlockLight[Idx] != 0)
|
if (a_BlockLight[Idx] != 0)
|
||||||
{
|
{
|
||||||
FoundNonEmpty = true;
|
|
||||||
IdxWhereNonEmptyStarts = Idx;
|
IdxWhereNonEmptyStarts = Idx;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -396,19 +394,7 @@ void cChunk::SetLight(
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ // Compress skylight
|
{ // Compress skylight
|
||||||
bool FoundNonEmpty = false;
|
|
||||||
int IdxWhereNonEmptyStarts = 0;
|
|
||||||
m_BlockSkyLight.clear();
|
m_BlockSkyLight.clear();
|
||||||
|
|
||||||
for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--)
|
|
||||||
{
|
|
||||||
if (a_SkyLight[Idx] != 0xff)
|
|
||||||
{
|
|
||||||
FoundNonEmpty = true;
|
|
||||||
IdxWhereNonEmptyStarts = Idx;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]);
|
m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,10 +407,8 @@ void cChunk::SetLight(
|
|||||||
|
|
||||||
void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes)
|
void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes)
|
||||||
{
|
{
|
||||||
std::vector<BLOCKTYPE> Blocks = m_BlockTypes;
|
std::copy(m_BlockTypes.begin(), m_BlockTypes.end(), a_BlockTypes);
|
||||||
Blocks.resize(NumBlocks);
|
std::fill_n(&a_BlockTypes[m_BlockTypes.size()], NumBlocks - m_BlockTypes.size(), E_BLOCK_AIR);
|
||||||
|
|
||||||
memcpy(a_BlockTypes, &Blocks[0], NumBlocks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -832,7 +816,7 @@ void cChunk::BroadcastPendingBlockChanges(void)
|
|||||||
|
|
||||||
void cChunk::CheckBlocks()
|
void cChunk::CheckBlocks()
|
||||||
{
|
{
|
||||||
if (m_ToTickBlocks.size() == 0)
|
if (m_ToTickBlocks.empty())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1605,7 +1589,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT
|
|||||||
|
|
||||||
MarkDirty();
|
MarkDirty();
|
||||||
|
|
||||||
if (m_BlockTypes.empty() || ((size_t)index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */)
|
if (m_BlockTypes.empty() || ((size_t)index >= m_BlockTypes.size()))
|
||||||
{
|
{
|
||||||
m_BlockTypes.resize(index + 1);
|
m_BlockTypes.resize(index + 1);
|
||||||
}
|
}
|
||||||
@ -2550,7 +2534,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_BlockTypes.empty() || ((size_t)a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */)
|
if (m_BlockTypes.empty() || ((size_t)a_BlockIdx >= m_BlockTypes.size()))
|
||||||
{
|
{
|
||||||
return E_BLOCK_AIR;
|
return E_BLOCK_AIR;
|
||||||
}
|
}
|
||||||
|
@ -221,22 +221,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int a_BlockIdx)
|
|
||||||
{
|
|
||||||
if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks))
|
|
||||||
{
|
|
||||||
return (a_Buffer[a_BlockIdx / 2] >> ((a_BlockIdx & 1) * 4)) & 0x0f;
|
|
||||||
}
|
|
||||||
ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static NIBBLETYPE GetNibble(const std::vector<NIBBLETYPE> & a_Buffer, int a_BlockIdx, bool a_IsSkyLightNibble = false)
|
static NIBBLETYPE GetNibble(const std::vector<NIBBLETYPE> & a_Buffer, int a_BlockIdx, bool a_IsSkyLightNibble = false)
|
||||||
{
|
{
|
||||||
if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks))
|
if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks))
|
||||||
{
|
{
|
||||||
if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) > a_Buffer.size() - 1))
|
if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) >= a_Buffer.size()))
|
||||||
{
|
{
|
||||||
return (a_IsSkyLightNibble ? 0xff : 0);
|
return (a_IsSkyLightNibble ? 0xff : 0);
|
||||||
}
|
}
|
||||||
@ -247,6 +236,22 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static NIBBLETYPE GetNibble(const std::vector<NIBBLETYPE> & a_Buffer, int x, int y, int z, bool a_IsSkyLightNibble = false)
|
||||||
|
{
|
||||||
|
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
|
||||||
|
{
|
||||||
|
int Index = MakeIndexNoCheck(x, y, z);
|
||||||
|
if (a_Buffer.empty() || ((size_t)(Index / 2) >= a_Buffer.size()))
|
||||||
|
{
|
||||||
|
return (a_IsSkyLightNibble ? 0xff : 0);
|
||||||
|
}
|
||||||
|
return (a_Buffer[(size_t)(Index / 2)] >> ((Index & 1) * 4)) & 0x0f;
|
||||||
|
}
|
||||||
|
ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int x, int y, int z)
|
static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int x, int y, int z)
|
||||||
{
|
{
|
||||||
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
|
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
|
||||||
@ -259,36 +264,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static NIBBLETYPE GetNibble(const std::vector<NIBBLETYPE> & a_Buffer, int x, int y, int z, bool a_IsSkyLightNibble = false)
|
|
||||||
{
|
|
||||||
if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
|
|
||||||
{
|
|
||||||
int Index = MakeIndexNoCheck(x, y, z);
|
|
||||||
if (a_Buffer.empty() || ((size_t)(Index / 2) > a_Buffer.size() - 1))
|
|
||||||
{
|
|
||||||
return (a_IsSkyLightNibble ? 0xff : 0);
|
|
||||||
}
|
|
||||||
return (a_Buffer[(size_t)(Index / 2)] >> ((Index & 1) * 4)) & 0x0f;
|
|
||||||
}
|
|
||||||
ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void SetNibble(NIBBLETYPE * a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble)
|
|
||||||
{
|
|
||||||
if ((a_BlockIdx < 0) || (a_BlockIdx >= NumBlocks))
|
|
||||||
{
|
|
||||||
ASSERT(!"cChunkDef::SetNibble(): index out of range!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
a_Buffer[a_BlockIdx / 2] = static_cast<NIBBLETYPE>(
|
|
||||||
(a_Buffer[a_BlockIdx / 2] & (0xf0 >> ((a_BlockIdx & 1) * 4))) | // The untouched nibble
|
|
||||||
((a_Nibble & 0x0f) << ((a_BlockIdx & 1) * 4)) // The nibble being set
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void SetNibble(std::vector<NIBBLETYPE> & a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble)
|
static void SetNibble(std::vector<NIBBLETYPE> & a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble)
|
||||||
{
|
{
|
||||||
if ((a_BlockIdx < 0) || (a_BlockIdx >= NumBlocks))
|
if ((a_BlockIdx < 0) || (a_BlockIdx >= NumBlocks))
|
||||||
@ -296,7 +271,7 @@ public:
|
|||||||
ASSERT(!"cChunkDef::SetNibble(): index out of range!");
|
ASSERT(!"cChunkDef::SetNibble(): index out of range!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) > a_Buffer.size() - 1))
|
if (a_Buffer.empty() || ((size_t)(a_BlockIdx / 2) >= a_Buffer.size()))
|
||||||
{
|
{
|
||||||
a_Buffer.resize((size_t)((a_BlockIdx / 2) + 1));
|
a_Buffer.resize((size_t)((a_BlockIdx / 2) + 1));
|
||||||
}
|
}
|
||||||
@ -307,26 +282,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void SetNibble(NIBBLETYPE * a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble)
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
(x >= Width) || (x < 0) ||
|
|
||||||
(y >= Height) || (y < 0) ||
|
|
||||||
(z >= Width) || (z < 0)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
ASSERT(!"cChunkDef::SetNibble(): index out of range!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Index = MakeIndexNoCheck(x, y, z);
|
|
||||||
a_Buffer[Index / 2] = static_cast<NIBBLETYPE>(
|
|
||||||
(a_Buffer[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble
|
|
||||||
((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void SetNibble(std::vector<NIBBLETYPE> & a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble)
|
static void SetNibble(std::vector<NIBBLETYPE> & a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
@ -340,7 +295,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Index = MakeIndexNoCheck(x, y, z);
|
int Index = MakeIndexNoCheck(x, y, z);
|
||||||
if (a_Buffer.empty() || ((size_t)(Index / 2) > a_Buffer.size() - 1))
|
if (a_Buffer.empty() || ((size_t)(Index / 2) >= a_Buffer.size()))
|
||||||
{
|
{
|
||||||
a_Buffer.resize((size_t)((Index / 2) + 1));
|
a_Buffer.resize((size_t)((Index / 2) + 1));
|
||||||
}
|
}
|
||||||
@ -350,18 +305,6 @@ public:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos)
|
|
||||||
{
|
|
||||||
return GetNibble(a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline static void SetNibble(NIBBLETYPE * a_Buffer, const Vector3i & a_BlockPos, NIBBLETYPE a_Value)
|
|
||||||
{
|
|
||||||
SetNibble( a_Buffer, a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_Value );
|
|
||||||
}
|
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user