3#include "absl/strings/str_format.h"
13 return absl::FailedPreconditionError(
"ROM not loaded");
17 layout_id >=
static_cast<int>(kRoomLayoutPointers.size())) {
18 return absl::InvalidArgumentError(
19 absl::StrFormat(
"Invalid layout id %d", layout_id));
22 uint32_t snes_addr = kRoomLayoutPointers[layout_id];
23 int pc_addr =
SnesToPc(
static_cast<int>(snes_addr));
24 if (pc_addr < 0 || pc_addr >=
static_cast<int>(
rom_->
size())) {
25 return absl::OutOfRangeError(
26 absl::StrFormat(
"Layout pointer %d out of range", layout_id));
35 if (!addr_result.ok()) {
36 return addr_result.status();
39 int pos = addr_result.value();
43 LOG_DEBUG(
"RoomLayout",
"Loading layout %d from PC address 0x%05X", layout_id,
47 while (pos + 2 <
static_cast<int>(
rom_->
size())) {
48 uint8_t b1 = rom_data[pos];
49 uint8_t b2 = rom_data[pos + 1];
51 if (b1 == 0xFF && b2 == 0xFF) {
54 "Layout %d terminated at pos=0x%05X after %d objects",
55 layout_id, pos, obj_index);
59 if (pos + 2 >=
static_cast<int>(
rom_->
size())) {
63 uint8_t b3 = rom_data[pos + 2];
67 b1, b2, b3,
static_cast<uint8_t
>(layer));
74 "Layout %d obj[%d]: bytes=[%02X,%02X,%02X] -> id=0x%03X x=%d "
75 "y=%d size=%d tiles=%zu",
76 layout_id, obj_index, b1, b2, b3, obj.
id_, obj.
x_, obj.
y_,
81 LOG_DEBUG(
"RoomLayout",
"Layout %d loaded with %zu objects", layout_id,
84 return absl::OkStatus();
92 uint8_t floor2_graphics)
const {
94 return absl::FailedPreconditionError(
"ROM not loaded");
98 return absl::OkStatus();
105 std::vector<RoomObject> render_objects =
objects_;
106 for (
auto& obj : render_objects) {
113 return drawer.
DrawObjectList(render_objects, bg1, bg2, palette_group, state);
Interface for accessing dungeon game state.
Draws dungeon objects to background buffers using game patterns.
void SetRoomFloorGraphics(uint8_t floor1, uint8_t floor2)
void SetBG1RevealMaskSource(gfx::BG1RevealMaskSource source)
absl::Status DrawObjectList(const std::vector< RoomObject > &objects, gfx::BackgroundBuffer &bg1, gfx::BackgroundBuffer &bg2, const gfx::PaletteGroup &palette_group, const DungeonState *state=nullptr, gfx::BackgroundBuffer *layout_bg1=nullptr, bool reset_room_event_indices=true, gfx::BackgroundBuffer *layout_bg2=nullptr)
Draw all objects in a room.
std::vector< RoomObject > objects_
absl::Status Draw(int room_id, const uint8_t *gfx_data, gfx::BackgroundBuffer &bg1, gfx::BackgroundBuffer &bg2, const gfx::PaletteGroup &palette_group, DungeonState *state, uint8_t floor1_graphics, uint8_t floor2_graphics) const
absl::StatusOr< int > GetLayoutAddress(int layout_id) const
absl::Status LoadLayout(int layout_id)
static RoomObject DecodeObjectFromBytes(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t layer)
const std::vector< gfx::TileInfo > & tiles() const
#define LOG_DEBUG(category, format,...)
Zelda 3 specific classes and functions.
uint32_t SnesToPc(uint32_t addr) noexcept
Represents a group of palettes.