yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
object_dimensions.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_DUNGEON_OBJECT_DIMENSIONS_H
2#define YAZE_ZELDA3_DUNGEON_OBJECT_DIMENSIONS_H
3
4#include <cstdint>
5#include <tuple>
6#include <unordered_map>
7#include <utility>
8
9#include "absl/status/status.h"
10#include "rom/rom.h"
11
12namespace yaze {
13namespace zelda3 {
14
15struct RoomObject;
16
30 public:
31 static ObjectDimensionTable& Get();
32
34 int offset_x = 0; // Offset from object x in tiles
35 int offset_y = 0; // Offset from object y in tiles
36 int width = 1; // Width in tiles
37 int height = 1; // Height in tiles
38 };
39
40 // Load dimension data from ROM
41 absl::Status LoadFromRom(Rom* rom);
42
43 // Get base dimensions for an object (without size extension)
44 std::pair<int, int> GetBaseDimensions(int object_id) const;
45
46 // Get full dimensions accounting for size parameter
47 std::pair<int, int> GetDimensions(int object_id, int size) const;
48
49 // Get dimensions for selection bounds (without size=0 inflation)
50 // This version caps the size and doesn't use 32-when-zero for display
51 std::pair<int, int> GetSelectionDimensions(int object_id, int size) const;
52
53 // Get selection bounds with offsets in tile coordinates
54 SelectionBounds GetSelectionBounds(int object_id, int size) const;
55
56 // Get hit-test bounds in tile coordinates (x, y, width, height)
57 std::tuple<int, int, int, int> GetHitTestBounds(const RoomObject& obj) const;
58
59 // Check if loaded
60 bool IsLoaded() const { return loaded_; }
61
62 // Reset state (for testing)
63 void Reset() {
64 dimensions_.clear();
65 loaded_ = false;
66 }
67
68 private:
70
71 // Dimension entry: base width/height and extension direction
73 int base_width = 1; // Base width in tiles
74 int base_height = 1; // Base height in tiles
75 // SuperSquare: Uses both size nibbles independently
76 // width = (size_x + 1) * multiplier, height = (size_y + 1) * multiplier
78 int extend_multiplier = 1; // Tiles added per size unit
79 bool use_32_when_zero = false; // ASM: GetSize_1to15or32 uses 32 when size=0
80 int zero_size_override = -1; // Optional override (e.g., 26) when size=0
81 };
82
83 // Object ID -> dimension entry
84 std::unordered_map<int, DimensionEntry> dimensions_;
85 bool loaded_ = false;
86
87 int ResolveEffectiveSize(const DimensionEntry& entry, int size) const;
88
89 // Initialize default dimensions based on draw routine patterns
90 void InitializeDefaults();
91
92 // Parse ROM tables for more accurate dimensions
93 void ParseSubtype1Tables(Rom* rom);
94 void ParseSubtype2Tables(Rom* rom);
95 void ParseSubtype3Tables(Rom* rom);
96};
97
98} // namespace zelda3
99} // namespace yaze
100
101#endif // YAZE_ZELDA3_DUNGEON_OBJECT_DIMENSIONS_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
ROM-based object dimension lookup table.
std::pair< int, int > GetBaseDimensions(int object_id) const
std::tuple< int, int, int, int > GetHitTestBounds(const RoomObject &obj) const
std::pair< int, int > GetDimensions(int object_id, int size) const
std::unordered_map< int, DimensionEntry > dimensions_
SelectionBounds GetSelectionBounds(int object_id, int size) const
int ResolveEffectiveSize(const DimensionEntry &entry, int size) const
static ObjectDimensionTable & Get()
std::pair< int, int > GetSelectionDimensions(int object_id, int size) const
enum yaze::zelda3::ObjectDimensionTable::DimensionEntry::ExtendDir extend_dir