1
0
Fork 0

Merge pull request #3090 from LogicParrot/outOfWorld

Out of world
This commit is contained in:
LogicParrot 2016-04-23 10:22:25 +03:00
commit 611cb8cb4e
4 changed files with 33 additions and 63 deletions

View File

@ -2594,16 +2594,6 @@ bool cChunk::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_
BLOCKTYPE cChunk::GetBlock(int a_RelX, int a_RelY, int a_RelZ) const BLOCKTYPE cChunk::GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
{ {
if (
(a_RelX < 0) || (a_RelX >= Width) ||
(a_RelY < 0) || (a_RelY >= Height) ||
(a_RelZ < 0) || (a_RelZ >= Width)
)
{
ASSERT(!"GetBlock(x, y, z) out of bounds!");
return 0; // Clip
}
return m_ChunkData.GetBlock(a_RelX, a_RelY, a_RelZ); return m_ChunkData.GetBlock(a_RelX, a_RelY, a_RelZ);
} }

View File

@ -150,9 +150,14 @@ cChunkData::~cChunkData()
BLOCKTYPE cChunkData::GetBlock(int a_X, int a_Y, int a_Z) const BLOCKTYPE cChunkData::GetBlock(int a_X, int a_Y, int a_Z) const
{ {
ASSERT((a_X >= 0) && (a_X < cChunkDef::Width)); if (
ASSERT((a_Y >= 0) && (a_Y < cChunkDef::Height)); (a_X < 0) || (a_X >= cChunkDef::Width) ||
ASSERT((a_Z >= 0) && (a_Z < cChunkDef::Width)); (a_Y < 0) || (a_Y >= cChunkDef::Height) ||
(a_Z < 0) || (a_Z >= cChunkDef::Width)
)
{
return E_BLOCK_AIR; // Coordinates are outside outside the world, so this must be an air block
}
int Section = a_Y / SectionHeight; int Section = a_Y / SectionHeight;
if (m_Sections[Section] != nullptr) if (m_Sections[Section] != nullptr)
{ {
@ -222,7 +227,7 @@ NIBBLETYPE cChunkData::GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
return 0; return 0;
} }
} }
ASSERT(!"cChunkData::GetMeta(): coords out of chunk range!"); // Coordinates are outside outside the world, so it must be an air block with a blank meta
return 0; return 0;
} }

View File

@ -250,7 +250,7 @@ bool cPath::StepOnce()
{ {
if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, y, 1), CurrentCell, NORMAL_G_COST)) if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, y, 1), CurrentCell, NORMAL_G_COST))
{ {
DoneWest = true; DoneSouth = true;
if (y == 0) if (y == 0)
{ {
WalkableSouth = true; WalkableSouth = true;

View File

@ -13,7 +13,7 @@ int main(int argc, char** argv)
{ {
return new cChunkData::sChunkSection(); return new cChunkData::sChunkSection();
} }
virtual void Free(cChunkData::sChunkSection * a_Ptr) virtual void Free(cChunkData::sChunkSection * a_Ptr)
{ {
delete a_Ptr; delete a_Ptr;
@ -36,7 +36,7 @@ int main(int argc, char** argv)
testassert(buffer.GetBlock(0, 32, 0) == 0x0); testassert(buffer.GetBlock(0, 32, 0) == 0x0);
testassert(buffer.GetMeta(0, 48, 0) == 0x0); testassert(buffer.GetMeta(0, 48, 0) == 0x0);
// Out of Range // Out of range SetBlock
CheckAsserts( CheckAsserts(
buffer.SetBlock(-1, 0, 0, 0); buffer.SetBlock(-1, 0, 0, 0);
); );
@ -55,28 +55,7 @@ int main(int argc, char** argv)
CheckAsserts( CheckAsserts(
buffer.SetBlock(0, 0, 256, 0); buffer.SetBlock(0, 0, 256, 0);
); );
// Out of range SetMeta
// Out of Range
CheckAsserts(
buffer.GetBlock(-1, 0, 0);
);
CheckAsserts(
buffer.GetBlock(0, -1, 0);
);
CheckAsserts(
buffer.GetBlock(0, 0, -1);
);
CheckAsserts(
buffer.GetBlock(256, 0, 0);
);
CheckAsserts(
buffer.GetBlock(0, 256, 0);
);
CheckAsserts(
buffer.GetBlock(0, 0, 256);
);
// Out of Range
CheckAsserts( CheckAsserts(
buffer.SetMeta(-1, 0, 0, 0); buffer.SetMeta(-1, 0, 0, 0);
); );
@ -96,30 +75,26 @@ int main(int argc, char** argv)
buffer.SetMeta(0, 0, 256, 0); buffer.SetMeta(0, 0, 256, 0);
); );
// Out of Range // Reading out of range blocks should return air
CheckAsserts( testassert(buffer.GetBlock(-1, 0, 0) == 0);
buffer.GetMeta(-1, 0, 0); testassert(buffer.GetBlock(0, -1, 0) == 0);
); testassert(buffer.GetBlock(0, 0, -1) == 0);
CheckAsserts( testassert(buffer.GetBlock(256, 0, 0) == 0);
buffer.GetMeta(0, -1, 0); testassert(buffer.GetBlock(0, 256, 0) == 0);
); testassert(buffer.GetBlock(0, 0, 256) == 0);
CheckAsserts(
buffer.GetMeta(0, 0, -1); // Reading out of range metas should return 0
); testassert(buffer.GetMeta(-1, 0, 0) == 0);
CheckAsserts( testassert(buffer.GetMeta(0, -1, 0) == 0);
buffer.GetMeta(256, 0, 0); testassert(buffer.GetMeta(0, 0, -1) == 0);
); testassert(buffer.GetMeta(256, 0, 0) == 0);
CheckAsserts( testassert(buffer.GetMeta(0, 256, 0) == 0);
buffer.GetMeta(0, 256, 0); testassert(buffer.GetMeta(0, 0, 256) == 0);
);
CheckAsserts(
buffer.GetMeta(0, 0, 256);
);
} }
{ {
cChunkData buffer(Pool); cChunkData buffer(Pool);
// Zero's // Zero's
buffer.SetBlock(0, 0, 0, 0x0); buffer.SetBlock(0, 0, 0, 0x0);
buffer.SetBlock(0, 0, 1, 0xab); buffer.SetBlock(0, 0, 1, 0xab);
@ -131,8 +106,8 @@ int main(int argc, char** argv)
testassert(buffer.GetMeta(0, 16, 0) == 0x0); testassert(buffer.GetMeta(0, 16, 0) == 0x0);
testassert(buffer.GetMeta(0, 16, 1) == 0xc); testassert(buffer.GetMeta(0, 16, 1) == 0xc);
} }
{ {
// Operator = // Operator =
cChunkData buffer(Pool); cChunkData buffer(Pool);
@ -141,6 +116,6 @@ int main(int argc, char** argv)
copy = std::move(buffer); copy = std::move(buffer);
testassert(copy.GetBlock(0, 0, 0) == 0x42); testassert(copy.GetBlock(0, 0, 0) == 0x42);
} }
return 0; return 0;
} }