yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
room_object.h
Go to the documentation of this file.
1#ifndef YAZE_APP_ZELDA3_DUNGEON_ROOM_OBJECT_H
2#define YAZE_APP_ZELDA3_DUNGEON_ROOM_OBJECT_H
3
4#include <cstdint>
5#include <string>
6#include <vector>
7
8#include "absl/strings/str_format.h"
10#include "rom/rom.h"
12
13namespace yaze {
14namespace zelda3 {
15
17
18enum Sorting {
19 All = 0,
20 Wall = 1,
25 Floors = 32,
26 SortStairs = 64
27};
28
29enum class ObjectOption {
30 Nothing = 0,
31 Door = 1,
32 Chest = 2,
33 Block = 4,
34 Torch = 8,
35 Bgr = 16,
36 Stairs = 32
37};
38
43
44constexpr int kRoomObjectSubtype1 = 0x8000; // JP = Same
45constexpr int kRoomObjectSubtype2 = 0x83F0; // JP = Same
46constexpr int kRoomObjectSubtype3 = 0x84F0; // JP = Same
47constexpr int kRoomObjectTileAddress = 0x1B52; // JP = Same
48constexpr int kRoomObjectTileAddressFloor = 0x1B5A; // JP = Same
49
51 public:
52 enum LayerType { BG1 = 0, BG2 = 1, BG3 = 2 };
53
54 // ROM room object stream index (0=primary, 1=BG2 overlay, 2=BG1 overlay).
55 // Same numeric values as LayerType for encode buckets; use only when the
56 // object came from the room object stream (see `layer_` comment below).
57 enum ListIndex : uint8_t {
61 };
62
63 RoomObject(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer = 0)
64 : id_(id),
65 x_(x),
66 y_(y),
67 size_(size),
68 layer_(static_cast<LayerType>(layer)),
69 nx_(x),
70 ny_(y),
71 ox_(x),
72 oy_(y),
73 width_(16),
74 height_(16),
75 rom_(nullptr) {
77 }
78
79 void SetRom(Rom* rom) { rom_ = rom; }
80 Rom* rom() const { return rom_; }
81 auto mutable_rom() { return rom_; }
82
83 // Position setters and getters
84 void set_id(int16_t id);
85 void set_x(uint8_t x) { x_ = x; }
86 void set_y(uint8_t y) { y_ = y; }
87 void set_size(uint8_t size) { size_ = size; }
88 uint8_t x() const { return x_; }
89 uint8_t y() const { return y_; }
90 uint8_t size() const { return size_; }
91
92 // Ensures tiles_ is populated with a basic set based on ROM tables so we can
93 // preview/draw objects without needing full emulator execution.
94 void EnsureTilesLoaded();
95
96 // Load tiles using the new ObjectParser
97 absl::Status LoadTilesWithParser();
98
99 // Getter for tiles
100 const std::vector<gfx::TileInfo>& tiles() const { return tiles_; }
101 std::vector<gfx::TileInfo>& mutable_tiles() { return tiles_; }
102
103 // Get tile data through Arena system - returns references, not copies
104 absl::StatusOr<std::span<const gfx::TileInfo>> GetTiles() const;
105
106 // Get individual tile by index - uses Arena lookup
107 absl::StatusOr<const gfx::TileInfo*> GetTile(int index) const;
108
109 // Get tile count without loading all tiles
110 int GetTileCount() const;
111
112 // ============================================================================
113 // Object Encoding/Decoding (Phase 1, Task 1.1)
114 // ============================================================================
115
116 // 3-byte object encoding structure
117 struct ObjectBytes {
118 uint8_t b1;
119 uint8_t b2;
120 uint8_t b3;
121 };
122
123 // Decode object from 3-byte ROM format
124 // Type1: xxxxxxss yyyyyyss iiiiiiii (ID 0x00-0xFF)
125 // Type2: 111111xx xxxxyyyy yyiiiiii (ID 0x100-0x1FF)
126 // Type3: xxxxxxii yyyyyyii 11111iii (ID 0xF00-0xFFF)
127 static RoomObject DecodeObjectFromBytes(uint8_t b1, uint8_t b2, uint8_t b3,
128 uint8_t layer);
129
130 // Encode object to 3-byte ROM format
132
133 // Determine object type from bytes (1, 2, or 3)
134 static int DetermineObjectType(uint8_t b1, uint8_t b3);
135
136 // Get layer from LayerType enum
137 uint8_t GetLayerValue() const { return static_cast<uint8_t>(layer_); }
138
139 // ============================================================================
140
141 // NOTE: Legacy ZScream methods removed. Modern rendering uses:
142 // - ObjectParser for loading tiles from ROM
143 // - ObjectDrawer for rendering tiles to BackgroundBuffer
144
145 auto options() const { return options_; }
147
148 // For `ObjectOption::Block` objects only. Holds the current committed
149 // 0-based index of the corresponding 4-byte global pushable-block entry.
150 // LoadBlocks initializes it from ROM; a successful structural save rebases
151 // it after deleted entries are compacted. This preserves vanilla's
152 // interleaved authoring order on later no-op saves. User-added blocks use
153 // kBlockLoadOrderNew until their first successful save assigns a committed
154 // tail slot. Ignored for non-block objects.
155 int block_load_order() const { return block_load_order_; }
156 void set_block_load_order(int order) { block_load_order_ = order; }
157
158 // Pushable-block bit 14 is independent of `layer_`: `layer_` stores the
159 // bit-13 draw target, while this selector is retained for runtime pit and
160 // collision behavior. It is preserved by edits and copies unless changed
161 // explicitly by a future dedicated behavior control.
162 uint8_t block_behavior_layer() const { return block_behavior_layer_; }
163 void set_block_behavior_layer(uint8_t layer) {
164 block_behavior_layer_ = layer & 0x01;
165 }
166
167 // Lightable-torch bit 14 is reserved by the runtime table. Keep it separate
168 // from `layer_`, which stores the bit-13 BG1/BG2 draw target, so ordinary
169 // edits and copies do not discard authoring data that yaze does not expose.
170 uint8_t torch_reserved_bit() const { return torch_reserved_bit_; }
171 void set_torch_reserved_bit(uint8_t reserved) {
172 torch_reserved_bit_ = reserved & 0x01;
173 }
174
175 // Copying an editor entity must not claim the source block's ROM table slot.
176 // Ordinary C++ copies intentionally preserve load order for move validation,
177 // undo snapshots, and rendering; creation paths call this method explicitly.
179 RoomObject copy = *this;
181 return copy;
182 }
183
184 bool all_bgs_ = false;
185 bool lit_ = false;
186
187 int16_t id_;
188 uint8_t x_;
189 uint8_t y_;
190 uint8_t size_;
191 uint8_t nx_;
192 uint8_t ny_;
193 uint8_t ox_;
194 uint8_t oy_;
195 uint8_t z_ = 0;
196 uint8_t previous_size_ = 0;
197 // Size nibble bits captured from object encoding (0..3 each) for heuristic
198 // orientation and sizing decisions.
199 uint8_t size_x_bits_ = 0;
200 uint8_t size_y_bits_ = 0;
201
204 int offset_x_ = 0;
205 int offset_y_ = 0;
206
207 std::string name_;
208
209 std::vector<uint8_t> preview_object_data_;
210
211 // Tile data storage - using Arena system for efficient memory management
212 // Instead of copying Tile16 vectors, we store references to Arena-managed
213 // data
214 mutable std::vector<gfx::TileInfo> tiles_; // Individual tiles like ZScream
215 mutable bool tiles_loaded_ = false;
216 mutable int tile_count_ = 0;
217 mutable int tile_data_ptr_ = -1; // Pointer to tile data in ROM
218
219 // For room-stream objects this is the object *list* index (0=primary, 1=BG2
220 // overlay, 2=BG1 overlay), matching `Room::EncodeObjects` buckets; map it
221 // through MapRoomObjectListIndexToDrawLayer() before drawing. For torches and
222 // pushable blocks, values 0/1 are the special-table draw target. Pushable
223 // block behavior and the torch reserved bit use independent fields.
226
227 // Sentinel for blocks that were not loaded from ROM (user-added in the
228 // editor). `SaveAllBlocks` keeps these at the tail of the encoded
229 // buffer in creation order so they don't get sorted in front of the
230 // vanilla entries.
231 static constexpr int kBlockLoadOrderNew = -1;
235
237
238 private:
240 void InvalidateTileCache();
241};
242
243// USDASM (LoadAndBuildRoom): three room-object lists separated by $FFFF after the
244// floor/layout header. `RoomObject::layer_` stores that list index (0, 1, 2) for
245// encode round-trip — not the same as “which SNES buffer”. After
246// `RoomDraw_DrawFloors`, the layout pass and the primary room-object list both
247// still target the upper/BG1 tilemap pointers; only the post-$FFFF overlay pass
248// explicitly swaps to lower/BG2, and the final pass swaps back to upper/BG1.
249// Use this when building draw lists.
251 uint8_t list_index) {
252 if (list_index > 2) {
253 list_index = 2;
254 }
255 if (list_index == 1) {
257 }
258 return list_index == 0 ? RoomObject::LayerType::BG1
260}
261
262// NOTE: Legacy Subtype1, Subtype2, Subtype3 classes removed.
263// These were ported from ZScream but are no longer used.
264// Modern code uses: ObjectParser + ObjectDrawer + ObjectRenderer
265
266constexpr static inline const char* Type1RoomObjectNames[] = {
267 "Ceiling ↔",
268 "Wall (top, north) ↔",
269 "Wall (top, south) ↔",
270 "Wall (bottom, north) ↔",
271 "Wall (bottom, south) ↔",
272 "Wall columns (north) ↔",
273 "Wall columns (south) ↔",
274 "Deep wall (north) ↔",
275 "Deep wall (south) ↔",
276 "Diagonal wall A ◤ (top) ↔",
277 "Diagonal wall A ◣ (top) ↔",
278 "Diagonal wall A ◥ (top) ↔",
279 "Diagonal wall A ◢ (top) ↔",
280 "Diagonal wall B ◤ (top) ↔",
281 "Diagonal wall B ◣ (top) ↔",
282 "Diagonal wall B ◥ (top) ↔",
283 "Diagonal wall B ◢ (top) ↔",
284 "Diagonal wall C ◤ (top) ↔",
285 "Diagonal wall C ◣ (top) ↔",
286 "Diagonal wall C ◥ (top) ↔",
287 "Diagonal wall C ◢ (top) ↔",
288 "Diagonal wall A ◤ (bottom) ↔",
289 "Diagonal wall A ◣ (bottom) ↔",
290 "Diagonal wall A ◥ (bottom) ↔",
291 "Diagonal wall A ◢ (bottom) ↔",
292 "Diagonal wall B ◤ (bottom) ↔",
293 "Diagonal wall B ◣ (bottom) ↔",
294 "Diagonal wall B ◥ (bottom) ↔",
295 "Diagonal wall B ◢ (bottom) ↔",
296 "Diagonal wall C ◤ (bottom) ↔",
297 "Diagonal wall C ◣ (bottom) ↔",
298 "Diagonal wall C ◥ (bottom) ↔",
299 "Diagonal wall C ◢ (bottom) ↔",
300 "Platform stairs ↔",
301 "Rail ↔",
302 "Pit edge ┏━┓ A (north) ↔",
303 "Pit edge ┏━┓ B (north) ↔",
304 "Pit edge ┏━┓ C (north) ↔",
305 "Pit edge ┏━┓ D (north) ↔",
306 "Pit edge ┏━┓ E (north) ↔",
307 "Pit edge ┗━┛ (south) ↔",
308 "Pit edge ━━━ (south) ↔",
309 "Pit edge ━━━ (north) ↔",
310 "Pit edge ━━┛ (south) ↔",
311 "Pit edge ┗━━ (south) ↔",
312 "Pit edge ━━┓ (north) ↔",
313 "Pit edge ┏━━ (north) ↔",
314 "Rail wall (north) ↔",
315 "Rail wall (south) ↔",
316 "Nothing",
317 "Nothing",
318 "Carpet ↔",
319 "Carpet trim ↔",
320 "Hole in wall", // Generic opening or doorway
321 "Drapes (north) ↔",
322 "Drapes (west, odd) ↔",
323 "Statues ↔",
324 "Columns ↔",
325 "Wall decors (north) ↔",
326 "Wall decors (south) ↔",
327 "Chairs in pairs ↔",
328 "Tall torches ↔",
329 "Supports (north) ↔",
330 "Water edge ┏━┓ (concave) ↔",
331 "Water edge ┗━┛ (concave) ↔",
332 "Water edge ┏━┓ (convex) ↔",
333 "Water edge ┗━┛ (convex) ↔",
334 "Water edge ┏━┛ (concave) ↔",
335 "Water edge ┗━┓ (concave) ↔",
336 "Water edge ┗━┓ (convex) ↔",
337 "Water edge ┏━┛ (convex) ↔",
338 "Waterfall A ↔",
339 "Waterfall B ↔",
340 "Floor tiles 4x2 A ↔",
341 "Floor tiles 4x2 B ↔",
342 "Supports (south) ↔",
343 "Bar ↔",
344 "Shelf A ↔",
345 "Shelf B ↔",
346 "Shelf C ↔",
347 "Somaria path ↔",
348 "Cannon hole A (north) ↔",
349 "Cannon hole A (south) ↔",
350 "Pipe path ↔",
351 "Nothing",
352 "Wall torches (north) ↔",
353 "Wall torches (south) ↔",
354 "Nothing",
355 "Nothing",
356 "Nothing",
357 "Nothing",
358 "Cannon hole B (north) ↔",
359 "Cannon hole B (south) ↔",
360 "Thick rail ↔",
361 "Blocks ↔",
362 "Long rail ↔",
363 "Ceiling ↕",
364 "Wall (top, west) ↕",
365 "Wall (top, east) ↕",
366 "Wall (bottom, west) ↕",
367 "Wall (bottom, east) ↕",
368 "Wall columns (west) ↕",
369 "Wall columns (east) ↕",
370 "Deep wall (west) ↕",
371 "Deep wall (east) ↕",
372 "Rail ↕",
373 "Pit edge (west) ↕",
374 "Pit edge (east) ↕",
375 "Rail wall (west) ↕",
376 "Rail wall (east) ↕",
377 "Nothing",
378 "Nothing",
379 "Carpet ↕",
380 "Carpet trim ↕",
381 "Nothing",
382 "Drapes (west) ↕",
383 "Drapes (east) ↕",
384 "Columns ↕",
385 "Wall decors (west) ↕",
386 "Wall decors (east) ↕",
387 "Supports (west) ↕",
388 "Water edge (west) ↕",
389 "Water edge (east) ↕",
390 "Supports (east) ↕",
391 "Somaria path ↕",
392 "Pipe path ↕",
393 "Nothing",
394 "Wall torches (west) ↕",
395 "Wall torches (east) ↕",
396 "Wall decors tight A (west) ↕",
397 "Wall decors tight A (east) ↕",
398 "Wall decors tight B (west) ↕",
399 "Wall decors tight B (east) ↕",
400 "Cannon hole (west) ↕",
401 "Cannon hole (east) ↕",
402 "Tall torches ↕",
403 "Thick rail ↕",
404 "Blocks ↕",
405 "Long rail ↕",
406 "Jump ledge (west) ↕",
407 "Jump ledge (east) ↕",
408 "Rug trim (west) ↕",
409 "Rug trim (east) ↕",
410 "Bar ↕",
411 "Wall flair (west) ↕",
412 "Wall flair (east) ↕",
413 "Blue pegs ↕",
414 "Orange pegs ↕",
415 "Invisible floor ↕",
416 "Fake pots ↕",
417 "Hammer pegs ↕",
418 "Nothing",
419 "Nothing",
420 "Nothing",
421 "Nothing",
422 "Nothing",
423 "Nothing",
424 "Nothing",
425 "Nothing",
426 "Nothing",
427 "Diagonal ceiling A ◤",
428 "Diagonal ceiling A ◣",
429 "Diagonal ceiling A ◥",
430 "Diagonal ceiling A ◢",
431 "Pit ⇲",
432 "Diagonal layer 2 mask A ◤",
433 "Diagonal layer 2 mask A ◣",
434 "Diagonal layer 2 mask A ◥",
435 "Diagonal layer 2 mask A ◢",
436 "Diagonal layer 2 mask B ◤", // TODO: VERIFY
437 "Diagonal layer 2 mask B ◣", // TODO: VERIFY
438 "Diagonal layer 2 mask B ◥", // TODO: VERIFY
439 "Diagonal layer 2 mask B ◢", // TODO: VERIFY
440 "Nothing",
441 "Nothing",
442 "Nothing",
443 "Jump ledge (north) ↔",
444 "Jump ledge (south) ↔",
445 "Rug ↔",
446 "Rug trim (north) ↔",
447 "Rug trim (south) ↔",
448 "Archery game curtains ↔",
449 "Wall flair (north) ↔",
450 "Wall flair (south) ↔",
451 "Blue pegs ↔",
452 "Orange pegs ↔",
453 "Invisible floor ↔",
454 "Fake pressure plates ↔",
455 "Fake pots ↔",
456 "Hammer pegs ↔",
457 "Nothing",
458 "Nothing",
459 "Ceiling (large) ⇲",
460 "Chest platform (tall) ⇲",
461 "Layer 2 pit mask (large) ⇲",
462 "Layer 2 pit mask (medium) ⇲",
463 "Floor 1 ⇲",
464 "Floor 3 ⇲",
465 "Layer 2 mask (large) ⇲",
466 "Floor 4 ⇲",
467 "Water floor ⇲ ",
468 "Flood water (medium) ⇲ ",
469 "Conveyor floor ⇲ ",
470 "Nothing",
471 "Nothing",
472 "Moving wall (west) ⇲",
473 "Moving wall (east) ⇲",
474 "Nothing",
475 "Nothing",
476 "Icy floor A ⇲",
477 "Icy floor B ⇲",
478 "Wall moved check A (logic)",
479 "Wall moved check B (logic)",
480 "Wall moved check C (logic)",
481 "Wall moved check D (logic)",
482 "Layer 2 mask (medium) ⇲",
483 "Flood water (large) ⇲",
484 "Layer 2 swim mask ⇲",
485 "Flood water B (large) ⇲",
486 "Floor 2 ⇲",
487 "Chest platform (short) ⇲",
488 "Table / rock ⇲",
489 "Spike blocks ⇲",
490 "Spiked floor ⇲",
491 "Floor 7 ⇲",
492 "Tiled floor ⇲",
493 "Rupee floor ⇲",
494 "Conveyor upwards ⇲",
495 "Conveyor downwards ⇲",
496 "Conveyor leftwards ⇲",
497 "Conveyor rightwards ⇲",
498 "Heavy current water ⇲",
499 "Floor 10 ⇲",
500 "Nothing",
501 "Nothing",
502 "Nothing",
503 "Nothing",
504 "Nothing",
505 "Nothing",
506 "Nothing",
507 "Nothing",
508 "Nothing",
509 "Nothing",
510 "Nothing",
511 "Nothing",
512 "Nothing",
513 "Nothing",
514 "Nothing",
515};
516
517constexpr static inline const char* Type2RoomObjectNames[] = {
518 "Corner (top, concave) ▛",
519 "Corner (top, concave) ▙",
520 "Corner (top, concave) ▜",
521 "Corner (top, concave) ▟",
522 "Corner (top, convex) ▟",
523 "Corner (top, convex) ▜",
524 "Corner (top, convex) ▙",
525 "Corner (top, convex) ▛",
526 "Corner (bottom, concave) ▛",
527 "Corner (bottom, concave) ▙",
528 "Corner (bottom, concave) ▜",
529 "Corner (bottom, concave) ▟",
530 "Corner (bottom, convex) ▟",
531 "Corner (bottom, convex) ▜",
532 "Corner (bottom, convex) ▙",
533 "Corner (bottom, convex) ▛",
534 "Kinked corner north (bottom) ▜",
535 "Kinked corner south (bottom) ▟",
536 "Kinked corner north (bottom) ▛",
537 "Kinked corner south (bottom) ▙",
538 "Kinked corner west (bottom) ▙",
539 "Kinked corner west (bottom) ▛",
540 "Kinked corner east (bottom) ▟",
541 "Kinked corner east (bottom) ▜",
542 "Deep corner (concave) ▛",
543 "Deep corner (concave) ▙",
544 "Deep corner (concave) ▜",
545 "Deep corner (concave) ▟",
546 "Large brazier",
547 "Statue",
548 "Star tile (disabled)",
549 "Star tile (enabled)",
550 "Small torch (lit)",
551 "Barrel",
552 "Statue (back)",
553 "Table",
554 "Fairy statue",
555 "Potted plant",
556 "Stool",
557 "Chair",
558 "Bed",
559 "Fireplace",
560 "Mario portrait",
561 "Rightwards 2x2 decor",
562 "Rightwards 6x3 decor",
563 "Interroom stairs (up)",
564 "Interroom stairs (down)",
565 "Interroom stairs B (down)",
566 "Intraroom stairs north B", // TODO: VERIFY LAYER HANDLING
567 "Intraroom stairs north (separate layers)",
568 "Intraroom stairs north (merged layers)",
569 "Intraroom stairs north (swim layer)",
570 "Block",
571 "Water-hop stairs A",
572 "Water-hop stairs B",
573 "Dam floodgate",
574 "Interroom spiral stairs up (top)",
575 "Interroom spiral stairs down (top)",
576 "Interroom spiral stairs up (bottom)",
577 "Interroom spiral stairs down (bottom)",
578 "Sanctuary wall (north)",
579 "Sanctuary pew (right end)",
580 "Pew",
581 "Magic bat altar",
582};
583
584constexpr static inline const char* Type3RoomObjectNames[] = {
585 "Waterfall face (empty)",
586 "Waterfall face (short)",
587 "Waterfall face (long)",
588 "Somaria path endpoint",
589 "Somaria path intersection ╋",
590 "Somaria path corner ┏",
591 "Somaria path corner ┗",
592 "Somaria path corner ┓",
593 "Somaria path corner ┛",
594 "Somaria path intersection ┳",
595 "Somaria path intersection ┻",
596 "Somaria path intersection ┣",
597 "Somaria path intersection ┫",
598 "Prison cell bars (alt)",
599 "Somaria path 2-way endpoint",
600 "Somaria path crossover",
601 "Babasu hole (north)",
602 "Babasu hole (south)",
603 "9 blue rupees",
604 "Telepathy tile",
605 "Unused / Warp door",
606 "Kholdstare's shell",
607 "Hammer peg",
608 "Prison cell",
609 "Big key lock",
610 "Chest",
611 "Chest (open)",
612 "Intraroom stairs south", // TODO: VERIFY LAYER HANDLING
613 "Intraroom stairs south (separate layers)",
614 "Intraroom stairs south (merged layers)",
615 "Interroom straight stairs up (north, top)",
616 "Interroom straight stairs down (north, top)",
617 "Interroom straight stairs up (south, top)",
618 "Interroom straight stairs down (south, top)",
619 "Deep corner (convex) ▟",
620 "Deep corner (convex) ▜",
621 "Deep corner (convex) ▙",
622 "Deep corner (convex) ▛",
623 "Interroom straight stairs up (north, bottom)",
624 "Interroom straight stairs down (north, bottom)",
625 "Interroom straight stairs up (south, bottom)",
626 "Interroom straight stairs down (south, bottom)",
627 "Lamp cones",
628 "Single 2x2 decor A",
629 "Liftable large block",
630 "Agahnim's altar",
631 "Agahnim's boss room",
632 "Pot",
633 "Single 2x2 decor B",
634 "Big chest",
635 "Big chest (open)",
636 "Intraroom stairs south (swim layer)",
637 "Intraroom stairs south (long)",
638 "Ladder (north)",
639 "Ladder (south)",
640 "4x4 decor A ↔",
641 "4x4 decor B ↔",
642 "4x4 decor C ↔",
643 "Pipe end (south)",
644 "Pipe end (north)",
645 "Pipe end (east)",
646 "Pipe end (west)",
647 "Pipe corner ▛",
648 "Pipe corner ▙",
649 "Pipe corner ▜",
650 "Pipe corner ▟",
651 "Pipe-rock intersection ⯊",
652 "Pipe-rock intersection ⯋",
653 "Pipe-rock intersection ◖",
654 "Pipe-rock intersection ◗",
655 "Pipe crossover",
656 "Bombable floor",
657 "Fake bombable floor",
658 "Single 2x2 decor C",
659 "Warp tile",
660 "Tool rack",
661 "Furnace",
662 "Tub (wide)",
663 "Anvil",
664 "Warp tile (disabled)",
665 "Pressure plate",
666 "Single 2x2 decor D",
667 "Blue peg",
668 "Orange peg",
669 "Fortune teller room",
670 "Utility 3x5 decor",
671 "Bar corner ▛",
672 "Bar corner ▙",
673 "Bar corner ▜",
674 "Bar corner ▟",
675 "Decorative bowl",
676 "Tub (tall)",
677 "Bookcase",
678 "Range",
679 "Suitcase",
680 "Bar bottles",
681 "Arrow game hole (west)",
682 "Arrow game hole (east)",
683 "Vitreous goo gfx",
684 "Fake pressure plate",
685 "Medusa head",
686 "4-way shooter block",
687 "Pit",
688 "Wall crack (north)",
689 "Wall crack (south)",
690 "Wall crack (west)",
691 "Wall crack (east)",
692 "Large decor",
693 "Water grate (north)",
694 "Water grate (south)",
695 "Water grate (west)",
696 "Water grate (east)",
697 "Window sunlight",
698 "Floor sunlight",
699 "Trinexx's shell",
700 "Layer 2 mask (full)",
701 "Boss entrance",
702 "Minigame chest",
703 "Ganon door",
704 "Triforce wall ornament",
705 "Triforce floor tiles",
706 "Freezor hole",
707 "Pile of bones",
708 "Vitreous goo damage",
709 "Arrow tile ↑",
710 "Arrow tile ↓",
711 "Arrow tile →",
712 "Nothing",
713};
714
715// Helper function to get object name from ID
716// Works across all three object subtypes
717inline std::string GetObjectName(int object_id) {
718 if (object_id < 0x100) {
719 // Type 1: Subtype 1 objects (0x00-0xFF)
720 constexpr size_t kType1Count =
721 sizeof(Type1RoomObjectNames) / sizeof(Type1RoomObjectNames[0]);
722 if (object_id >= 0 && object_id < static_cast<int>(kType1Count)) {
723 return Type1RoomObjectNames[object_id];
724 }
725 return absl::StrFormat("Unknown Type1 (0x%02X)", object_id);
726 } else if (object_id >= 0x100 && object_id < 0x200) {
727 // Type 2: Subtype 2 objects (0x100-0x1FF)
728 int idx = object_id - 0x100;
729 constexpr size_t kType2Count =
730 sizeof(Type2RoomObjectNames) / sizeof(Type2RoomObjectNames[0]);
731 if (idx >= 0 && idx < static_cast<int>(kType2Count)) {
732 return Type2RoomObjectNames[idx];
733 }
734 return absl::StrFormat("Unknown Type2 (0x%03X)", object_id);
735 } else if (object_id >= 0xF80) {
736 // Type 3: Special objects (0xF80-0xFFF, decoded from ASM 0x200-0x27F)
737 int idx = object_id - 0xF80;
738 constexpr size_t kType3Count =
739 sizeof(Type3RoomObjectNames) / sizeof(Type3RoomObjectNames[0]);
740 if (idx >= 0 && idx < static_cast<int>(kType3Count)) {
741 return Type3RoomObjectNames[idx];
742 }
743 return absl::StrFormat("Unknown Type3 (0x%03X)", object_id);
744 }
745 return absl::StrFormat("Unknown (0x%03X)", object_id);
746}
747
748// Helper to get object type/subtype from ID
749inline int GetObjectSubtype(int object_id) {
750 if (object_id < 0x100)
751 return 1;
752 if (object_id < 0x200)
753 return 2;
754 if (object_id >= 0xF80)
755 return 3;
756 return 0; // Unknown
757}
758
759} // namespace zelda3
760} // namespace yaze
761
762#endif // YAZE_APP_ZELDA3_DUNGEON_ROOM_OBJECT_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
absl::StatusOr< const gfx::TileInfo * > GetTile(int index) const
static RoomObject DecodeObjectFromBytes(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t layer)
std::vector< uint8_t > preview_object_data_
std::vector< gfx::TileInfo > tiles_
void set_size(uint8_t size)
Definition room_object.h:87
std::vector< gfx::TileInfo > & mutable_tiles()
ObjectBytes EncodeObjectToBytes() const
const std::vector< gfx::TileInfo > & tiles() const
void set_x(uint8_t x)
Definition room_object.h:85
void set_id(int16_t id)
static int DetermineObjectType(uint8_t b1, uint8_t b3)
absl::Status LoadTilesWithParser()
void set_block_behavior_layer(uint8_t layer)
void SetRom(Rom *rom)
Definition room_object.h:79
uint8_t size() const
Definition room_object.h:90
static constexpr int kBlockLoadOrderNew
void set_torch_reserved_bit(uint8_t reserved)
absl::StatusOr< std::span< const gfx::TileInfo > > GetTiles() const
uint8_t block_behavior_layer() const
RoomObject(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer=0)
Definition room_object.h:63
uint8_t GetLayerValue() const
void set_block_load_order(int order)
uint8_t torch_reserved_bit() const
RoomObject CopyForNewPlacement() const
void set_y(uint8_t y)
Definition room_object.h:86
void set_options(ObjectOption options)
constexpr int kRoomObjectSubtype3
Definition room_object.h:46
RoomObject::LayerType MapRoomObjectListIndexToDrawLayer(uint8_t list_index)
ObjectOption operator|(ObjectOption lhs, ObjectOption rhs)
int GetObjectSubtype(int object_id)
ObjectOption operator^(ObjectOption lhs, ObjectOption rhs)
constexpr int kRoomObjectSubtype1
Definition room_object.h:44
constexpr int kRoomObjectSubtype2
Definition room_object.h:45
constexpr int kRoomObjectTileAddress
Definition room_object.h:47
ObjectOption operator~(ObjectOption option)
std::string GetObjectName(int object_id)
ObjectOption operator&(ObjectOption lhs, ObjectOption rhs)
constexpr int kRoomObjectTileAddressFloor
Definition room_object.h:48