Skip to content

Document pass on WaterBox code#2695

Open
mzxrules wants to merge 1 commit into
zeldaret:mainfrom
mzxrules:waterbox_bug
Open

Document pass on WaterBox code#2695
mzxrules wants to merge 1 commit into
zeldaret:mainfrom
mzxrules:waterbox_bug

Conversation

@mzxrules
Copy link
Copy Markdown
Contributor

@mzxrules mzxrules commented Feb 17, 2026

As I was attempting to document the newly found waterbox bug, I found a few mistakes and improvements to make in my old documentation.

I've implemented a similar pr in MM, and would like there to be a consensus reached between both games before merging.

The sister PR can be found here:

zeldaret/mm#1860

@mzxrules
Copy link
Copy Markdown
Contributor Author

mzxrules commented Mar 9, 2026

Contributions past, current, and future made to this repository are licensed under CC0. I couldn't find the thread, i'm in a rush.

Comment thread include/bgcheck.h
#define COLPOLY_VTX(vtxId, flags) ((((flags) & 7) << 13) | ((vtxId) & 0x1FFF))

// flags for flags_vIA
// flags for variable flags_vIA
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

did you mean "struct member" or just "member" instead of "variable" (I think it was fine as is in main)

Comment thread include/bgcheck.h
Comment on lines +99 to +101
/* The true purpose of the flag is unknown. The state is never enabled on any waterbox, and functions that
* pass on flag enabled are never called, so there is no direct usecase context. */
#define WATERBOX_IS_DISABLED (1 << 19) // Disables waterbox collision
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

where does the name come from then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So in functions BgCheck_GetWaterSurface and BgCheck_FindWaterBox, the search routines will skip over a WaterBox with the flag set, and since these are the only two functions in use that process WaterBoxes, the flag basically "disables" them. WATERBOX_IS_DISABLED makes sense here.

However, my concern is that WATERBOX_IS_DISABLED could potentially be incorrect based on the context in which it's used in func_800425B0.

func_800425B0 has the same arguments as BgCheck_GetWaterSurface and performs the same search, except the one difference is that it now only selects WaterBoxes with the flag set. To me it's a really odd design and makes me believe that there was some other purpose for this flag. Like, one potential possibility that I have zero evidence of would be to have a flag turning water into lava, as those two things would be something that could share the same basic properties (e.g. flat, you'd want to know the surface height) but you would want to exclude from one another.

So in short, I opted to choose a name that make sense within the scope of what we know now, but added a comment to highlight that the assumption could potentially be incorrect, because again, never used.

Copy link
Copy Markdown
Collaborator

@Dragorn421 Dragorn421 Apr 11, 2026

Choose a reason for hiding this comment

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

I see. The comment game me the wrong impression that the flag was entirely unused outside of unused code

Maybe:

Suggested change
/* The true purpose of the flag is unknown. The state is never enabled on any waterbox, and functions that
* pass on flag enabled are never called, so there is no direct usecase context. */
#define WATERBOX_IS_DISABLED (1 << 19) // Disables waterbox collision
/* The original intended purpose of this flag may not be disabling a waterbox. See func_800425B0 (unused) which by contrast only considers waterboxes with this flag set. */
#define WATERBOX_IS_DISABLED (1 << 19) // Disables waterbox collision

+ formatting

Comment thread src/code/z_bgcheck.c
* `outWaterBox` returns a pointer to the WaterBox
*
* This performs a special case check on a custom waterbox in Zora's Domain that has a finite depth
* Otherwise, the search performed assumes waterboxes cannot overlap, as water has effectively infinite depth
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't understand the relation between not overlapping and having infinite depth

Comment thread src/code/z_bgcheck.c
Comment on lines +4319 to +4320
//! @bug: WaterBox bounds check issue.
if (waterBox->xMin < x && x < waterBox->xMin + waterBox->xLength) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

did you forget to add details here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, I only added it in MM woops.

@Dragorn421 Dragorn421 added the Waiting for author There are requested changes that have not been addressed label Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Waiting for author There are requested changes that have not been addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants