yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dimension_service.cc
Go to the documentation of this file.
2
3#include <algorithm>
4
7
8namespace yaze {
9namespace zelda3 {
10
12 static DimensionService instance;
13 return instance;
14}
15
17 const RoomObject& obj) const {
18 // Try ObjectGeometry first (exact buffer-replay).
19 auto geo_result = ObjectGeometry::Get().MeasureByObjectId(obj);
20 if (geo_result.ok()) {
21 const auto& bounds = *geo_result;
22 return DimensionResult{
23 .offset_x_tiles = bounds.min_x_tiles,
24 .offset_y_tiles = bounds.min_y_tiles,
25 .width_tiles = std::max(1, bounds.width_tiles),
26 .height_tiles = std::max(1, bounds.height_tiles),
27 };
28 }
29
30 // Fall back to ObjectDimensionTable.
31 auto& dim_table = ObjectDimensionTable::Get();
32 if (dim_table.IsLoaded()) {
33 auto sel = dim_table.GetSelectionBounds(obj.id_, obj.size_);
34 return DimensionResult{
35 .offset_x_tiles = sel.offset_x,
36 .offset_y_tiles = sel.offset_y,
37 .width_tiles = std::max(1, sel.width),
38 .height_tiles = std::max(1, sel.height),
39 };
40 }
41
42 // Last resort: naive estimate.
43 int size = obj.size_ & 0x0F;
44 return DimensionResult{
45 .offset_x_tiles = 0,
46 .offset_y_tiles = 0,
47 .width_tiles = std::max(1, 2 + size * 2),
48 .height_tiles = 2,
49 };
50}
51
53 const RoomObject& obj) const {
54 auto result = GetDimensions(obj);
55 return {result.width_pixels(), result.height_pixels()};
56}
57
58std::tuple<int, int, int, int> DimensionService::GetHitTestBounds(
59 const RoomObject& obj) const {
60 auto result = GetDimensions(obj);
61 return {obj.x_ + result.offset_x_tiles, obj.y_ + result.offset_y_tiles,
62 result.width_tiles, result.height_tiles};
63}
64
65std::tuple<int, int, int, int> DimensionService::GetSelectionBoundsPixels(
66 const RoomObject& obj) const {
67 auto result = GetDimensions(obj);
68 int x_px = (obj.x_ + result.offset_x_tiles) * 8;
69 int y_px = (obj.y_ + result.offset_y_tiles) * 8;
70 return {x_px, y_px, result.width_pixels(), result.height_pixels()};
71}
72
73} // namespace zelda3
74} // namespace yaze
Unified dimension lookup for dungeon room objects.
static DimensionService & Get()
std::tuple< int, int, int, int > GetSelectionBoundsPixels(const RoomObject &obj) const
DimensionResult GetDimensions(const RoomObject &obj) const
std::tuple< int, int, int, int > GetHitTestBounds(const RoomObject &obj) const
std::pair< int, int > GetPixelDimensions(const RoomObject &obj) const
static ObjectDimensionTable & Get()
absl::StatusOr< GeometryBounds > MeasureByObjectId(const RoomObject &object) const
static ObjectGeometry & Get()