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