New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created constant for lower bound of chunk #5488
base: master
Are you sure you want to change the base?
Conversation
- Created new constant cChunkDef::BottomHeight - replaced comparisons of absolute position and 0 with constant
It might be useful to export some of these constants to the Lua api as well. Especially since the max and min chunk height was changed in 1.17. If plugins can use those constants now they wouldn't break when we increase/decrease the chunk limits. |
- Created lua constants - renamed to upper and lower limit
I saw some other lines that need intervention |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oopsie xD
I am not sure if I got any occurence and if the change will break anything |
I think the
My reasoning for the split is that the following doesn't provide enough context to be checked in PRs:
What is that Compare to this:
It's clear at first sight what this is asking. |
{ | ||
Width = | ||
{ | ||
Notes = "The width of a chunk, in number of blocks.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes = "The width of a chunk, in number of blocks.", | |
Notes = "The X or Z size of a chunk, in number of blocks.", |
}, | ||
LowerLimit = | ||
{ | ||
Notes = "The lower limit of the chunk coordinate vertical range.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes = "The lower limit of the chunk coordinate vertical range.", | |
Notes = "The lower limit of the chunk coordinate vertical (Y) range.", |
}, | ||
UpperLimit = | ||
{ | ||
Notes = "The upper limit of the chunk coordinate vertical range.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notes = "The upper limit of the chunk coordinate vertical range.", | |
Notes = "The upper limit of the chunk coordinate vertical (Y) range.", |
@@ -1011,7 +1011,7 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) | |||
Vector3d NextPos = Vector3d(GetPosX(), GetPosY(), GetPosZ()); | |||
Vector3d NextSpeed = Vector3d(GetSpeedX(), GetSpeedY(), GetSpeedZ()); | |||
|
|||
if ((BlockY >= cChunkDef::Height) || (BlockY < 0)) | |||
if ((BlockY >= cChunkDef::UpperLimit) || (BlockY < cChunkDef::LowerLimit)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ((BlockY >= cChunkDef::UpperLimit) || (BlockY < cChunkDef::LowerLimit)) | |
if (!cChunkDef::IsValidHeight(BlockY)) |
The off-by-one change introduced here doesn't matter much here I believe.
/** DEPRECATED!!! Validates a height-coordinate. Returns false if height-coordinate is out of height bounds. | ||
Might be enclosed by a_SpaceBelow and a_SpaceAbove. [LowerLimit + a_SpaceBelow, UpperLimit - a_SpaceAbove) is valid. | ||
@deprecated */ | ||
inline static bool IsValidHeight(int a_Height, int a_SpaceAbove = 0, int a_SpaceBelow = 0) | ||
{ | ||
return ((a_BlockPosition.y >= 0) && (a_BlockPosition.y < Height)); | ||
ASSERT(a_SpaceBelow >= 0); | ||
ASSERT(a_SpaceAbove >= 0); | ||
return ((a_Height >= LowerLimit + a_SpaceBelow) && (a_Height < UpperLimit - a_SpaceAbove)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the deprecation? I think this is a perfectly fine usage of Y-coord only. After all, it's the same usage as IsValidWidth
{ | ||
FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] = ( | ||
m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) * | ||
m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256 | ||
m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / cChunkDef::VerticalBlockCount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / cChunkDef::VerticalBlockCount | |
m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256 |
int Lo = FloorLo[x + (cChunkDef::Width + 1) * z] / cChunkDef::VerticalBlockCount; | ||
int Hi = FloorHi[x + (cChunkDef::Width + 1) * z] / cChunkDef::VerticalBlockCount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int Lo = FloorLo[x + (cChunkDef::Width + 1) * z] / cChunkDef::VerticalBlockCount; | |
int Hi = FloorHi[x + (cChunkDef::Width + 1) * z] / cChunkDef::VerticalBlockCount; | |
int Lo = FloorLo[x + (cChunkDef::Width + 1) * z] / 256; | |
int Hi = FloorHi[x + (cChunkDef::Width + 1) * z] / 256; |
@@ -261,7 +261,7 @@ void cLightingThread::LightChunk(cLightingChunkStay & a_Item) | |||
{ | |||
for (int z = 0; z < cChunkDef::Width * 3; z++) | |||
{ | |||
for (int y = cChunkDef::Height / 2; y >= 0; y--) | |||
for (int y = cChunkDef::UpperLimit / 2; y >= cChunkDef::LowerLimit; y--) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (int y = cChunkDef::UpperLimit / 2; y >= cChunkDef::LowerLimit; y--) | |
for (int y = cChunkDef::VerticalBlockCount / 2; y >= 0; y--) |
@@ -292,7 +292,7 @@ void cLightingThread::LightChunk(cLightingChunkStay & a_Item) | |||
{ | |||
for (int z = 0; z < cChunkDef::Width * 3; z++) | |||
{ | |||
for (int y = cChunkDef::Height / 2; y >= 0; y--) | |||
for (int y = cChunkDef::UpperLimit / 2; y >= 0; y--) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (int y = cChunkDef::UpperLimit / 2; y >= 0; y--) | |
for (int y = cChunkDef::VerticalBlockCount / 2; y >= 0; y--) |
@@ -357,7 +357,7 @@ void cLightingThread::PrepareSkyLight(void) | |||
m_NumSeeds = 0; | |||
|
|||
// Fill the top of the chunk with all-light: | |||
if (m_MaxHeight < cChunkDef::Height - 1) | |||
if (cChunkDef::IsValidHeight(m_MaxHeight, 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗ This needs rework, m_MaxHeight
is used as an index into the internal array, so must be always 0-based, unlike an Y-coord.
Good start, though I'm afraid it's still a long way from when we'll be able to use negative Y coords :) |
cChunkDef::LowerLimit
cChunkDef::Height
->cChunkDef::UpperLimit
cChunkDef
constantsName suggestions are welcome
Todo