yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
object_geometry.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_DUNGEON_GEOMETRY_OBJECT_GEOMETRY_H
2#define YAZE_ZELDA3_DUNGEON_GEOMETRY_OBJECT_GEOMETRY_H
3
4#include <optional>
5#include <tuple>
6#include <unordered_map>
7#include <vector>
8
9#include "absl/status/statusor.h"
12
13namespace yaze {
14namespace zelda3 {
15
20 int x_tiles = 0;
21 int y_tiles = 0;
22 int width_tiles = 0;
23 int height_tiles = 0;
24
25 int width_pixels() const { return width_tiles * 8; }
26 int height_pixels() const { return height_tiles * 8; }
27};
28
43 // Full rendered area (bounding box of all drawn tiles)
44 int min_x_tiles = 0;
45 int min_y_tiles = 0;
46 int width_tiles = 0;
47 int height_tiles = 0;
48
49 // Layer information for BG2 masking
50 bool is_bg2_overlay = false; // True if this object draws to BG2 (Layer 1)
51
52 // Optional tighter selection hitbox for non-rectangular shapes
53 // If not set, selection uses the full render bounds
54 std::optional<SelectionRect> selection_bounds;
55
56 int max_x_tiles() const { return min_x_tiles + width_tiles; }
57 int max_y_tiles() const { return min_y_tiles + height_tiles; }
58 int width_pixels() const { return width_tiles * 8; }
59 int height_pixels() const { return height_tiles * 8; }
60
61 // Pixel-based accessors for the mask rectangle
62 int min_x_pixels() const { return min_x_tiles * 8; }
63 int min_y_pixels() const { return min_y_tiles * 8; }
64
72 bool RequiresBG1Mask() const { return is_bg2_overlay && width_tiles > 0; }
73
80 bool HasTighterSelectionBounds() const { return selection_bounds.has_value(); }
81
93
101 std::tuple<int, int, int, int> GetBG1MaskRect(int obj_x, int obj_y) const {
102 int start_x = (obj_x + min_x_tiles) * 8;
103 int start_y = (obj_y + min_y_tiles) * 8;
104 return {start_x, start_y, width_pixels(), height_pixels()};
105 }
106};
107
117 public:
118 static ObjectGeometry& Get();
119
120 // Look up routine metadata by routine ID. Returns nullptr on unknown IDs.
121 const DrawRoutineInfo* LookupRoutine(int routine_id) const;
122
123 // Measure bounds by routine id using the object's size/id bits.
124 absl::StatusOr<GeometryBounds> MeasureByRoutineId(
125 int routine_id, const RoomObject& object) const;
126
127 // Measure bounds for a specific routine metadata entry.
128 absl::StatusOr<GeometryBounds> MeasureRoutine(
129 const DrawRoutineInfo& routine, const RoomObject& object) const;
130
142 absl::StatusOr<GeometryBounds> MeasureForLayerCompositing(
143 int routine_id, const RoomObject& object) const;
144
151 static bool IsLayerOneRoutine(int routine_id);
152
159 static bool IsDiagonalCeilingRoutine(int routine_id);
160
172 int routine_id);
173
174 private:
176 void BuildRegistry();
177
178 std::vector<DrawRoutineInfo> routines_;
179 std::unordered_map<int, DrawRoutineInfo> routine_map_;
180};
181
182} // namespace zelda3
183} // namespace yaze
184
185#endif // YAZE_ZELDA3_DUNGEON_GEOMETRY_OBJECT_GEOMETRY_H
Side-car geometry engine that replays draw routines against an off-screen buffer to calculate real ex...
static bool IsDiagonalCeilingRoutine(int routine_id)
Check if a routine ID corresponds to a diagonal ceiling.
std::vector< DrawRoutineInfo > routines_
absl::StatusOr< GeometryBounds > MeasureForLayerCompositing(int routine_id, const RoomObject &object) const
Measure bounds for a BG2 overlay object and mark it for masking.
absl::StatusOr< GeometryBounds > MeasureRoutine(const DrawRoutineInfo &routine, const RoomObject &object) const
std::unordered_map< int, DrawRoutineInfo > routine_map_
const DrawRoutineInfo * LookupRoutine(int routine_id) const
absl::StatusOr< GeometryBounds > MeasureByRoutineId(int routine_id, const RoomObject &object) const
static GeometryBounds ApplySelectionBounds(GeometryBounds render_bounds, int routine_id)
Compute tighter selection bounds for diagonal shapes.
static ObjectGeometry & Get()
static bool IsLayerOneRoutine(int routine_id)
Get list of routine IDs that draw to BG2 layer.
Metadata about a draw routine.
Bounding box result for a draw routine execution.
std::tuple< int, int, int, int > GetBG1MaskRect(int obj_x, int obj_y) const
Get the BG1 mask rectangle in pixel coordinates.
std::optional< SelectionRect > selection_bounds
SelectionRect GetSelectionBounds() const
Get the selection bounds for hit testing.
bool RequiresBG1Mask() const
Check if this object requires BG1 masking.
bool HasTighterSelectionBounds() const
Check if this object has a tighter selection hitbox.
Simple rectangle for selection bounds.