Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

12xx12
Copy link
Member

@12xx12 12xx12 commented Apr 8, 2023

  • Created new constant cChunkDef::LowerLimit
  • cChunkDef::Height -> cChunkDef::UpperLimit
  • replaced comparisons of absolute position and 0 with constant
  • Checks for height are now done with a function of cChunkDef constants

Name suggestions are welcome

Todo

  • Replace position comparisons with cChunkDef function

- Created new constant cChunkDef::BottomHeight
- replaced comparisons of absolute position and 0 with constant
@NiLSPACE
Copy link
Member

NiLSPACE commented Apr 9, 2023

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
CONTRIBUTING.md Outdated Show resolved Hide resolved
@12xx12
Copy link
Member Author

12xx12 commented Apr 11, 2023

I saw some other lines that need intervention

Copy link
Member Author

@12xx12 12xx12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oopsie xD

src/Blocks/BlockLeaves.h Outdated Show resolved Hide resolved
src/Entities/Entity.cpp Outdated Show resolved Hide resolved
src/Entities/Entity.cpp Outdated Show resolved Hide resolved
src/Entities/Entity.cpp Outdated Show resolved Hide resolved
src/Generating/CompoGenBiomal.cpp Show resolved Hide resolved
src/Map.cpp Outdated Show resolved Hide resolved
src/Simulator/SimulatorManager.cpp Outdated Show resolved Hide resolved
tests/Generating/BasicGeneratorTest.cpp Outdated Show resolved Hide resolved
tests/Generating/BasicGeneratorTest.cpp Outdated Show resolved Hide resolved
tests/Generating/BasicGeneratorTest.cpp Outdated Show resolved Hide resolved
@12xx12
Copy link
Member Author

12xx12 commented Apr 15, 2023

I am not sure if I got any occurence and if the change will break anything

@madmaxoft
Copy link
Member

I think the cChunkDef::IsValidHeight should be refactored:

  • Drop the Vector3i version altogether (so the usage is the same as with cChunkDef::IsValidWidth)
  • Split it into two functions, one for single block, one for range, so that the range is more explicit at the call site

My reasoning for the split is that the following doesn't provide enough context to be checked in PRs:

if (cChunkDef::IsValidHeight(BlockY, 1))

What is that 1 there? Is that 1-block-above or 1-block-below?

Compare to this:

if (cChunkDef::IsValidHeightRange(BlockY, BlockY + 1))

It's clear at first sight what this is asking.

{
Width =
{
Notes = "The width of a chunk, in number of blocks.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +178 to 186
/** 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));
}
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +488 to +489
int Lo = FloorLo[x + (cChunkDef::Width + 1) * z] / cChunkDef::VerticalBlockCount;
int Hi = FloorHi[x + (cChunkDef::Width + 1) * z] / cChunkDef::VerticalBlockCount;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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--)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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--)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))
Copy link
Member

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.

@madmaxoft
Copy link
Member

Good start, though I'm afraid it's still a long way from when we'll be able to use negative Y coords :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants