Files
yaze/docs/dungeon_canvas_fix_summary.md
scawful 5c863b1445 Refactor graphics optimizations documentation and add ImGui widget testing guide
- Updated the gfx_optimizations_complete.md to streamline the overview and implementation details of graphics optimizations, removing completed status indicators and enhancing clarity on future recommendations.
- Introduced imgui_widget_testing_guide.md, detailing the usage of YAZE's ImGui testing infrastructure for automated GUI testing, including architecture, integration steps, and best practices.
- Created ollama_integration_status.md to document the current status of Ollama integration, highlighting completed tasks, ongoing issues, and next steps for improvement.
- Revised developer_guide.md to reflect the latest updates in AI provider configuration and input methods for the z3ed agent, ensuring clarity on command-line flags and supported providers.
2025-10-04 03:24:42 -04:00

3.2 KiB

Dungeon Canvas Blank Screen - Fix Summary

Issue

The dungeon editor canvas was displaying only UI elements but the room graphics were blank, despite the rendering pipeline appearing to be set up correctly.

Root Cause

The background buffers (bg1 and bg2) were never being populated with tile indices from room objects before calling DrawBackground().

The Missing Step

  1. Room::RenderRoomGraphics() would:

    • Copy graphics data to current_gfx16_
    • Draw floor pattern via DrawFloor()
    • Call DrawBackground() to render tiles to pixels
  2. Problem: DrawBackground() expects the buffer to contain tile indices, but only the floor pattern was in the buffer. Room objects were loaded but never converted to tile indices in the buffer!

How ZScream Does It

  • ZScream's Room.loadLayoutObjects() and object drawing methods populate tilesBg1Buffer/tilesBg2Buffer with tile indices
  • GraphicsManager.DrawBackground() then converts those buffer indices to pixels
  • Result: Complete room with floors, walls, and objects

Solution Implemented

Changes Made

File: src/app/zelda3/dungeon/room.cc

  1. Enhanced RenderRoomGraphics() (line 286-315)

    • Added call to RenderObjectsToBackground() after DrawFloor() but before DrawBackground()
  2. Implemented RenderObjectsToBackground() (line 317-383)

    • Iterates through all tile_objects_
    • Ensures each object has tiles loaded via EnsureTilesLoaded()
    • For each object:
      • Determines correct layer (BG1 vs BG2)
      • Converts each Tile16 to 4 TileInfo sub-tiles
      • Converts each TileInfo to word format using TileInfoToWord()
      • Places tiles in background buffer using SetTileAt()

Technical Details

Tile Structure:

  • Tile16 = 16x16 pixel tile made of 4 TileInfo (8x8) tiles
  • Arranged as: [tile0_][tile1_] (top row), [tile2_][tile3_] (bottom row)

Word Format (per SNES specs):

Bit 15: Vertical flip
Bit 14: Horizontal flip  
Bit 13: Priority/over
Bits 10-12: Palette (3 bits)
Bits 0-9: Tile ID (10 bits)

Buffer Layout:

  • 64x64 tiles (512x512 pixels)
  • Buffer index = y * 64 + x
  • Each entry is a uint16_t word

Testing

To verify the fix:

  1. Build yaze with: cmake --build build --target yaze
  2. Run yaze and open the dungeon editor
  3. Select any room
  4. Canvas should now display:
    • Floor pattern
    • Wall structures
    • Room objects
    • Correct layer separation

Future Enhancements

  • Add layout object rendering (walls from room layout data)
  • Optimize tile placement algorithm for different object types
  • Add support for animated tiles
  • Implement object-specific draw routines (similar to ZScream's DungeonObjectDraw.cs)
  • Implementation: src/app/zelda3/dungeon/room.cc
  • Header: src/app/zelda3/dungeon/room.h
  • Buffer: src/app/gfx/background_buffer.cc
  • Tiles: src/app/gfx/snes_tile.h
  • Reference: ZeldaFullEditor/GraphicsManager.cs (ZScream)
  • Reference: ZeldaFullEditor/Data/Types/DungeonObjectDraw.cs (ZScream)

Build Status

Compilation: Success (0 errors) ⚠️ Warnings: 21 warnings (pre-existing, unrelated to this fix)