Side-car geometry engine that replays draw routines against an off-screen buffer to calculate real extents. More...
#include <object_geometry.h>
Classes | |
| struct | CacheKey |
| struct | CacheKeyHash |
Public Member Functions | |
| const DrawRoutineInfo * | LookupRoutine (int routine_id) const |
| absl::StatusOr< GeometryBounds > | MeasureByRoutineId (int routine_id, const RoomObject &object) const |
| absl::StatusOr< GeometryBounds > | MeasureByObjectId (const RoomObject &object) const |
| absl::StatusOr< GeometryBounds > | MeasureByObjectIdForState (const RoomObject &object, const DungeonState *state) const |
| void | ClearCache () |
| absl::StatusOr< GeometryBounds > | MeasureRoutine (const DrawRoutineInfo &routine, const RoomObject &object) const |
| absl::StatusOr< GeometryBounds > | MeasureRoutineForState (const DrawRoutineInfo &routine, const RoomObject &object, const DungeonState *state) const |
| std::pair< int, int > | ResolveAnchor (int16_t object_id, uint8_t size_byte) const |
| Resolve the canvas anchor (x, y) for a given object's draw routine. | |
| absl::StatusOr< GeometryBounds > | MeasureForLayerCompositing (int routine_id, const RoomObject &object) const |
| Measure bounds for a BG2 overlay object and mark it for masking. | |
Static Public Member Functions | |
| static ObjectGeometry & | Get () |
| static bool | IsLayerOneRoutine (int routine_id) |
| Get list of routine IDs that draw to BG2 layer. | |
| static bool | IsDiagonalCeilingRoutine (int routine_id) |
| Check if a routine ID corresponds to a diagonal ceiling. | |
| static GeometryBounds | ApplySelectionBounds (GeometryBounds render_bounds, int routine_id) |
| Compute tighter selection bounds for diagonal shapes. | |
Private Member Functions | |
| ObjectGeometry () | |
| void | BuildRegistry () |
Private Attributes | |
| std::vector< DrawRoutineInfo > | routines_ |
| std::unordered_map< int, DrawRoutineInfo > | routine_map_ |
| std::unordered_map< CacheKey, GeometryBounds, CacheKeyHash > | cache_ |
Side-car geometry engine that replays draw routines against an off-screen buffer to calculate real extents.
This is intentionally self-contained (no ROM or editor coupling) so it can be tested in isolation and later dropped into ObjectDrawer/editor hit-testing paths.
Definition at line 121 of file object_geometry.h.
|
private |
Definition at line 130 of file object_geometry.cc.
References BuildRegistry().

|
static |
Definition at line 125 of file object_geometry.cc.
Referenced by yaze::editor::TileObjectHandler::CalculateGhostPreviewGeometry(), yaze::zelda3::ObjectTileEditor::CaptureObjectLayout(), yaze::zelda3::DimensionService::GetDimensions(), yaze::zelda3::DimensionService::GetHitTestBounds(), yaze::zelda3::DimensionService::GetSelectionBoundsPixels(), and yaze::cli::anonymous_namespace{dungeon_object_validate_commands.cc}::ResolveExpectedBounds().
| const DrawRoutineInfo * yaze::zelda3::ObjectGeometry::LookupRoutine | ( | int | routine_id | ) | const |
Definition at line 148 of file object_geometry.cc.
References routine_map_.
Referenced by MeasureByObjectIdForState(), MeasureByRoutineId(), and ResolveAnchor().
| absl::StatusOr< GeometryBounds > yaze::zelda3::ObjectGeometry::MeasureByRoutineId | ( | int | routine_id, |
| const RoomObject & | object ) const |
Definition at line 156 of file object_geometry.cc.
References ApplySelectionBounds(), LookupRoutine(), and MeasureRoutine().
Referenced by MeasureByObjectId(), and MeasureForLayerCompositing().

| absl::StatusOr< GeometryBounds > yaze::zelda3::ObjectGeometry::MeasureByObjectId | ( | const RoomObject & | object | ) | const |
Definition at line 266 of file object_geometry.cc.
References cache_, yaze::zelda3::DrawRoutineRegistry::Get(), yaze::zelda3::DrawRoutineRegistry::GetRoutineIdForObject(), and MeasureByRoutineId().
Referenced by yaze::zelda3::DimensionService::GetDimensions(), yaze::zelda3::DimensionService::GetHitTestBounds(), and yaze::zelda3::DimensionService::GetSelectionBoundsPixels().

| absl::StatusOr< GeometryBounds > yaze::zelda3::ObjectGeometry::MeasureByObjectIdForState | ( | const RoomObject & | object, |
| const DungeonState * | state ) const |
Definition at line 289 of file object_geometry.cc.
References ApplySelectionBounds(), yaze::zelda3::DrawRoutineRegistry::Get(), yaze::zelda3::DrawRoutineRegistry::GetRoutineIdForObject(), LookupRoutine(), and MeasureRoutineForState().
Referenced by yaze::cli::anonymous_namespace{dungeon_object_validate_commands.cc}::ResolveExpectedBounds().
| void yaze::zelda3::ObjectGeometry::ClearCache | ( | ) |
Definition at line 311 of file object_geometry.cc.
References cache_.
| absl::StatusOr< GeometryBounds > yaze::zelda3::ObjectGeometry::MeasureRoutine | ( | const DrawRoutineInfo & | routine, |
| const RoomObject & | object ) const |
Definition at line 186 of file object_geometry.cc.
References MeasureRoutineForState().
Referenced by MeasureByRoutineId().

| absl::StatusOr< GeometryBounds > yaze::zelda3::ObjectGeometry::MeasureRoutineForState | ( | const DrawRoutineInfo & | routine, |
| const RoomObject & | object, | ||
| const DungeonState * | state ) const |
Definition at line 192 of file object_geometry.cc.
References yaze::zelda3::DrawRoutineInfo::function, yaze::gfx::BackgroundBuffer::GetTileAt(), yaze::zelda3::GeometryBounds::height_tiles, yaze::zelda3::DrawRoutineInfo::id, yaze::zelda3::GeometryBounds::is_bg2_overlay, yaze::zelda3::DrawRoutineIds::kChest, yaze::zelda3::DrawContext::kMaxTilesX, yaze::zelda3::DrawContext::kMaxTilesY, yaze::zelda3::DrawRoutineInfo::min_tiles, yaze::zelda3::GeometryBounds::min_x_tiles, yaze::zelda3::GeometryBounds::min_y_tiles, yaze::zelda3::DrawContext::target_bg, yaze::zelda3::RoomObject::tiles(), yaze::zelda3::GeometryBounds::width_tiles, yaze::zelda3::RoomObject::x_, and yaze::zelda3::RoomObject::y_.
Referenced by MeasureByObjectIdForState(), and MeasureRoutine().

| std::pair< int, int > yaze::zelda3::ObjectGeometry::ResolveAnchor | ( | int16_t | object_id, |
| uint8_t | size_byte ) const |
Resolve the canvas anchor (x, y) for a given object's draw routine.
Replay-style preview/editor pipelines that call ObjectDrawer::DrawObject with hardcoded coordinates clip routines that draw upward or leftward (acute diagonals 0x09-0x14 / 0x15-0x20, diagonal ceilings 0xA0-0xAC, and moving wall west 0xCD). This returns the same anchor that ObjectGeometry uses internally for MeasureRoutine, so callers can position their RoomObject at coordinates that keep the full extent within the trace canvas.
Returns (0, 0) for unknown routines, or for routines whose draw direction does not require headroom.
Definition at line 170 of file object_geometry.cc.
References yaze::zelda3::DrawRoutineRegistry::Get(), yaze::zelda3::DrawRoutineRegistry::GetRoutineIdForObject(), and LookupRoutine().
Referenced by yaze::editor::TileObjectHandler::CalculateGhostPreviewGeometry(), and yaze::zelda3::ObjectTileEditor::CaptureObjectLayout().

| absl::StatusOr< GeometryBounds > yaze::zelda3::ObjectGeometry::MeasureForLayerCompositing | ( | int | routine_id, |
| const RoomObject & | object ) const |
Measure bounds for a BG2 overlay object and mark it for masking.
This is a convenience method that measures the object and sets the is_bg2_overlay flag if the object's layer indicates it draws to BG2. Used by the dungeon editor to determine BG1 mask regions.
| routine_id | Draw routine ID |
| object | Object with layer information |
Definition at line 315 of file object_geometry.cc.
References yaze::zelda3::RoomObject::BG2, yaze::zelda3::GeometryBounds::is_bg2_overlay, and MeasureByRoutineId().

|
static |
Get list of routine IDs that draw to BG2 layer.
These routines write to the lower tilemap (BG2) and require corresponding BG1 transparency for proper compositing.
Definition at line 331 of file object_geometry.cc.
|
static |
Check if a routine ID corresponds to a diagonal ceiling.
Diagonal ceilings (routines 75-78 for objects 0xA0-0xA3) have triangular fill patterns that require tighter selection bounds than their bounding box.
Definition at line 348 of file object_geometry.cc.
Referenced by ApplySelectionBounds().
|
static |
Compute tighter selection bounds for diagonal shapes.
For triangular diagonal ceilings, this computes a selection rectangle that's roughly 70% of the bounding box, centered on the visual content.
| render_bounds | Full render bounds from MeasureRoutine |
| routine_id | The routine ID to check for diagonal shapes |
Definition at line 357 of file object_geometry.cc.
References yaze::zelda3::SelectionRect::height_tiles, yaze::zelda3::GeometryBounds::height_tiles, IsDiagonalCeilingRoutine(), yaze::zelda3::GeometryBounds::min_x_tiles, yaze::zelda3::GeometryBounds::min_y_tiles, yaze::zelda3::GeometryBounds::selection_bounds, yaze::zelda3::SelectionRect::width_tiles, yaze::zelda3::GeometryBounds::width_tiles, yaze::zelda3::SelectionRect::x_tiles, and yaze::zelda3::SelectionRect::y_tiles.
Referenced by MeasureByObjectIdForState(), and MeasureByRoutineId().

|
private |
Definition at line 134 of file object_geometry.cc.
References yaze::zelda3::DrawRoutineRegistry::Get(), routine_map_, and routines_.
Referenced by ObjectGeometry().

|
private |
Definition at line 240 of file object_geometry.h.
Referenced by BuildRegistry().
|
private |
Definition at line 241 of file object_geometry.h.
Referenced by BuildRegistry(), and LookupRoutine().
|
mutableprivate |
Definition at line 242 of file object_geometry.h.
Referenced by ClearCache(), and MeasureByObjectId().