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