Skip to content

RFC: Fix straight-view draw order (walls bucket at their visible face) - #5068

Merged
Loobinex merged 2 commits into
dkfans:masterfrom
RupixTalahone:review/frontview-depth-doctrine
Jul 29, 2026
Merged

RFC: Fix straight-view draw order (walls bucket at their visible face)#5068
Loobinex merged 2 commits into
dkfans:masterfrom
RupixTalahone:review/frontview-depth-doctrine

Conversation

@RupixTalahone

@RupixTalahone RupixTalahone commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Draft on purpose: this fixes the reported bug in our testing, but it changes 29-year-old draw-order behavior, so we want the reasoning reviewed before it counts as ready. Tear it apart.

The bug

Community report: creatures visible through the tops of walls they are standing behind in the straight view (reproduces on alpha 1.4.0.5252). Same family as #5060 / #5062 / #5066: draw-order assumptions sized for 320x200 breaking at modern zoom.

Root cause

The straight view buckets by screen pixels. draw_element buckets the entire column at the tile's NORTH edge, but the visible wall face is the tile's SOUTHERN boundary plane, one tile later in draw order. Any thing bias toward the camera (the #5062 size bias, or even the legacy -3 for a thing standing in the southern strip of its tile) can out-bucket the wall directly south of it, and once the feet cross that line the whole sprite draws over the wall top. Separately, the +64 bucket margin was sized for the legacy -3 bias; at the bottom rows of the screen modern biases overspend it, everything clamps into bucket 0, and ordering collapses there.

The fix (one file, +45/-8)

  • Wall-class columns (tall AND blocking) bucket their faces and caps at the south edge. Walkable columns of any height (dungeon heart pedestal, room floors, lair padding) are floors and keep the early bucket, under their occupants.
  • A wall whose screen-south neighbor is also wall-class shows no face at all, so its top draws over everything nearby. This also cuts wide sprites brushing a wall strip sideways instead of letting them spill over the tops.
  • The dig/place markers lift three rows so they stay visible on tagged wall strips.
  • The shared bucket margin grows 64 -> 1024 in both formulas; it cancels between things and columns, and BUCKETS_COUNT (4098) has headroom at any real window height.

Testing

4K, straight view, on two builds: this branch applied to current master, and the truecolor fork where it soaked first. Creatures behind walls are buried at every position including pressed against the wall; creatures in front keep their heads; lair rooms full of nests show no tile-boundary cuts; the heart is fully visible on its pedestal; markers stay visible on tagged strips; bottom-edge ordering holds. The max-zoom sprite vanish still present on this branch is #5066, not this change.

Known residual (pre-existing)

A wide sprite whose feet are south of a wall's EXPOSED end face can still overlap that face. The bucket list sorts on one axis and this case needs the second one; the honest fix for it is per-pixel depth, and it exists in current master too.

Review questions

  1. Wall-class is SlbAtFlg_Blocking plus get_column_floor_filled_subtiles >= 3. Is there map content this misclassifies (walkable 3+ columns, blocking 2-cube ledges)?
  2. Hidden-face tops draw 2 rows late and markers lift 3 rows. Tuned constants, not derived ones; sturdier ideas welcome.
  3. The 1024 margin assumes engine windows under roughly 3000px tall.

🤖 Generated with Claude Code


Update: volume box depth bias retuned (addresses the boundbox report below)

The build-room volume box carries a hand-tuned depth bias that ducks its lines under wall faces. It was calibrated against the original north-edge wall bucketing; with walls bucketing at their visible face, the branch's earlier 3.5-subtile compensation overshot and the box's bottom line showed through walls where unrevealed terrain lies beyond. The committed 2.75 subtiles was measured against a test matrix at 4K: box over walls, against walls with dark beyond, over open and unrevealed ground, both box render modes, across zoom levels.

Two things reviewers should know:

  1. This interaction has been through two tuning iterations already, and this is as good as it gets from our side short of per-pixel depth, i.e. a renderer rewrite. The remaining artifact is a one-pixel slimming of horizontal lines where covering geometry meets them: the painter's list quantizes the boundary row, and it goes to the occluder.
  2. The volume box renders broken at 4K on every official build we tested, including stable 1.4.0 and alpha 5249, because the 1997-sized bucket margin collapses at 4K window heights. The margin raise in this branch is what makes the box tunable at 4K at all. At lower resolutions the old margin may hold. This is unconfirmed since lower resolutions don't work well with my screen.

@RupixTalahone
RupixTalahone force-pushed the review/frontview-depth-doctrine branch from 7f66893 to 0fa4342 Compare July 27, 2026 17:17
@rainlizard

Copy link
Copy Markdown
Contributor

Works well with this test (before & after):
Untitled2
Untitled1

The code can possibly be made a few lines slimmer but is otherwise good.

Community report: creatures show through the tops of walls they stand
behind. Root cause: draw_element buckets a whole column at the tile's
NORTH edge, but the visible wall face is the SOUTHERN boundary plane -
one tile later in draw order. Any thing bias toward the camera (the
size bias from dkfans#5062, or the legacy -3 for a thing in the southern
strip of its tile) could out-bucket the wall directly south and paint
the whole sprite over the wall top.

- Wall-class columns (tall AND blocking) bucket faces and caps at the
  south edge. Walkable columns of any height (dungeon heart pedestal,
  room floors) are floors and keep the early bucket.
- A wall whose screen-south neighbor is also wall-class shows no face
  at all, so its top draws over everything nearby - this also cuts
  wide sprites brushing a wall strip sideways.
- The dig/place markers lift three rows to stay above those tops.
- The shared bucket margin grows 64 -> 1024: bottom-screen rows spent
  the 1997-sized margin, clamped into bucket 0 and lost all ordering.

Known residual: a wide sprite south of an EXPOSED end face can still
overlap it; that case needs per-pixel depth and also exists today.

RFC with full reasoning and test matrix accompanies this branch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@RupixTalahone
RupixTalahone force-pushed the review/frontview-depth-doctrine branch from 0fa4342 to e4b7c46 Compare July 28, 2026 10:43
@RupixTalahone
RupixTalahone marked this pull request as ready for review July 28, 2026 10:57
@Loobinex

Loobinex commented Jul 28, 2026

Copy link
Copy Markdown
Member

@RupixTalahone I tested it, and with this PR I can see the green boundbox through walls. (you get that when building rooms).

In Alpha 5249 this goes correct, as does the seeing imps through walls bug.

The frontview build-room volume box carries a depth bias that ducks
its lines under wall faces. It was tuned against the old north-edge
wall bucketing; with walls bucketing at their visible face the old
3.5-subtile compensation overshoots and the box bottom line shows
through walls where unrevealed terrain lies beyond. The committed
2.75 subtiles was measured against a test matrix at 4K: box over
walls, against walls with dark beyond, over open and unrevealed
ground, both box render modes, across zoom.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

3 participants