yaze 0.2.0
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 "app/emu/cpu/cpu.h"
10#include "app/emu/video/ppu.h"
12#include "app/gfx/snes_tile.h"
13#include "app/rom.h"
16
17namespace yaze {
18namespace app {
19namespace zelda3 {
20namespace dungeon {
21
23 uint32_t subtype_ptr;
24 uint32_t routine_ptr;
25};
26
27SubtypeInfo FetchSubtypeInfo(uint16_t object_id);
28
30
31enum Sorting {
32 All = 0,
33 Wall = 1,
38 Floors = 32,
39 SortStairs = 64
40};
41
42enum class ObjectOption {
43 Nothing = 0,
44 Door = 1,
45 Chest = 2,
46 Block = 4,
47 Torch = 8,
48 Bgr = 16,
49 Stairs = 32
50};
51
56
57constexpr int kRoomObjectSubtype1 = 0x8000; // JP = Same
58constexpr int kRoomObjectSubtype2 = 0x83F0; // JP = Same
59constexpr int kRoomObjectSubtype3 = 0x84F0; // JP = Same
60constexpr int kRoomObjectTileAddress = 0x1B52; // JP = Same
61constexpr int kRoomObjectTileAddressFloor = 0x1B5A; // JP = Same
62
63class RoomObject : public SharedRom {
64 public:
65 enum LayerType { BG1 = 0, BG2 = 1, BG3 = 2 };
66
67 RoomObject(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer = 0)
68 : id_(id),
69 x_(x),
70 y_(y),
71 size_(size),
72 layer_(static_cast<LayerType>(layer)),
73 nx_(x),
74 ny_(y),
75 ox_(x),
76 oy_(y),
77 width_(16),
78 height_(16) {}
79
80 void AddTiles(int nbr, int pos) {
81 for (int i = 0; i < nbr; i++) {
82 ASSIGN_OR_LOG_ERROR(auto tile, rom()->ReadTile16(pos + (i * 2)));
83 tiles_.push_back(tile);
84 }
85 }
86
87 void DrawTile(gfx::Tile16 t, int xx, int yy,
88 std::vector<uint8_t>& current_gfx16,
89 std::vector<uint8_t>& tiles_bg1_buffer,
90 std::vector<uint8_t>& tiles_bg2_buffer,
91 ushort tile_under = 0xFFFF);
92
93 auto options() const { return options_; }
95
96 protected:
97 bool all_bgs_ = false;
98 bool lit_ = false;
99
100 int16_t id_;
101 uint8_t x_;
102 uint8_t y_;
103 uint8_t size_;
104 uint8_t nx_;
105 uint8_t ny_;
106 uint8_t ox_;
107 uint8_t oy_;
108 uint8_t z_ = 0;
109 uint8_t previous_size_ = 0;
110
113 int offset_x_ = 0;
114 int offset_y_ = 0;
115
116 std::string name_;
117
118 std::vector<uint8_t> preview_object_data_;
119 std::vector<gfx::Tile16> tiles_;
120
123};
124
125class Subtype1 : public RoomObject {
126 public:
129 std::string name;
131
132 Subtype1(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer,
133 int tile_count)
134 : RoomObject(id, x, y, size, layer), tile_count_(tile_count) {
135 auto rom_data = rom()->data();
136 int pos = kRoomObjectTileAddress +
137 static_cast<int16_t>(
138 (rom_data[kRoomObjectSubtype1 + ((id & 0xFF) * 2) + 1] << 8) +
139 rom_data[kRoomObjectSubtype1 + ((id & 0xFF) * 2)]);
140 AddTiles(tile_count_, pos);
142 }
143
144 void Draw(std::vector<uint8_t>& current_gfx16,
145 std::vector<uint8_t>& tiles_bg1_buffer,
146 std::vector<uint8_t>& tiles_bg2_buffer) {
147 for (int s = 0; s < size_ + (tile_count_ == 8 ? 1 : 0); s++) {
148 for (int i = 0; i < tile_count_; i++) {
149 DrawTile(tiles_[i], ((s * 2)) * 8, (i / 2) * 8, current_gfx16,
150 tiles_bg1_buffer, tiles_bg2_buffer);
151 }
152 }
153 }
154};
155
156class Subtype2 : public RoomObject {
157 public:
158 std::string name;
161
162 Subtype2(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer)
163 : RoomObject(id, x, y, size, layer) {
164 auto rom_data = rom()->data();
165 int pos = kRoomObjectTileAddress +
166 static_cast<int16_t>(
167 (rom_data[kRoomObjectSubtype2 + ((id & 0x7F) * 2) + 1] << 8) +
168 rom_data[kRoomObjectSubtype2 + ((id & 0x7F) * 2)]);
169 AddTiles(8, pos);
171 }
172
173 void Draw(std::vector<uint8_t>& current_gfx16,
174 std::vector<uint8_t>& tiles_bg1_buffer,
175 std::vector<uint8_t>& tiles_bg2_buffer) {
176 for (int i = 0; i < 8; i++) {
177 DrawTile(tiles_[i], x_ * 8, (y_ + i) * 8, current_gfx16, tiles_bg1_buffer,
178 tiles_bg2_buffer);
179 }
180 }
181};
182
183class Subtype3 : public RoomObject {
184 public:
186 std::string name;
188
189 Subtype3(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer)
190 : RoomObject(id, x, y, size, layer) {
191 auto rom_data = rom()->data();
192 int pos = kRoomObjectTileAddress +
193 static_cast<int16_t>(
194 (rom_data[kRoomObjectSubtype3 + ((id & 0xFF) * 2) + 1] << 8) +
195 rom_data[kRoomObjectSubtype3 + ((id & 0xFF) * 2)]);
196 AddTiles(8, pos);
198 }
199
200 void Draw(std::vector<uint8_t>& current_gfx16,
201 std::vector<uint8_t>& tiles_bg1_buffer,
202 std::vector<uint8_t>& tiles_bg2_buffer) {
203 for (int i = 0; i < 8; i++) {
204 DrawTile(tiles_[i], x_ * 8, (y_ + i) * 8, current_gfx16, tiles_bg1_buffer,
205 tiles_bg2_buffer);
206 }
207 }
208};
209
210} // namespace dungeon
211} // namespace zelda3
212} // namespace app
213} // namespace yaze
214
215#endif // YAZE_APP_ZELDA3_DUNGEON_ROOM_OBJECT_H
A class to hold a shared pointer to a Rom object.
Definition rom.h:576
Tile composition of four 8x8 tiles.
Definition snes_tile.h:130
void set_options(ObjectOption options)
Definition room_object.h:94
void DrawTile(gfx::Tile16 t, int xx, int yy, std::vector< uint8_t > &current_gfx16, std::vector< uint8_t > &tiles_bg1_buffer, std::vector< uint8_t > &tiles_bg2_buffer, ushort tile_under=0xFFFF)
RoomObject(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer=0)
Definition room_object.h:67
std::vector< gfx::Tile16 > tiles_
std::vector< uint8_t > preview_object_data_
Subtype1(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer, int tile_count)
void Draw(std::vector< uint8_t > &current_gfx16, std::vector< uint8_t > &tiles_bg1_buffer, std::vector< uint8_t > &tiles_bg2_buffer)
Subtype2(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer)
void Draw(std::vector< uint8_t > &current_gfx16, std::vector< uint8_t > &tiles_bg1_buffer, std::vector< uint8_t > &tiles_bg2_buffer)
Subtype3(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer)
void Draw(std::vector< uint8_t > &current_gfx16, std::vector< uint8_t > &tiles_bg1_buffer, std::vector< uint8_t > &tiles_bg2_buffer)
#define ASSIGN_OR_LOG_ERROR(type_variable_name, expression)
Definition constants.h:81
unsigned short ushort
Definition constants.h:112
ObjectOption operator&(ObjectOption lhs, ObjectOption rhs)
constexpr int kRoomObjectTileAddressFloor
Definition room_object.h:61
constexpr int kRoomObjectSubtype1
Definition room_object.h:57
ObjectOption operator|(ObjectOption lhs, ObjectOption rhs)
Definition room_object.cc:8
constexpr int kRoomObjectSubtype3
Definition room_object.h:59
ObjectOption operator~(ObjectOption option)
constexpr int kRoomObjectSubtype2
Definition room_object.h:58
ObjectOption operator^(ObjectOption lhs, ObjectOption rhs)
constexpr int kRoomObjectTileAddress
Definition room_object.h:60
SubtypeInfo FetchSubtypeInfo(uint16_t object_id)
Definition common.cc:22