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 <array>
5#include <cstdint>
6#include <stdexcept>
7#include <string>
8#include <vector>
9
10#include "app/emu/cpu/cpu.h"
12#include "app/emu/video/ppu.h"
14#include "app/gfx/snes_tile.h"
15#include "app/rom.h"
18
19namespace yaze {
20namespace app {
21namespace zelda3 {
22namespace dungeon {
23
25 uint32_t subtype_ptr;
26 uint32_t routine_ptr;
27};
28
29SubtypeInfo FetchSubtypeInfo(uint16_t object_id);
30
32
44
45enum Sorting {
46 All = 0,
47 Wall = 1,
52 Floors = 32,
53 SortStairs = 64
54};
55
56enum class ObjectOption {
57 Nothing = 0,
58 Door = 1,
59 Chest = 2,
60 Block = 4,
61 Torch = 8,
62 Bgr = 16,
63 Stairs = 32
64};
65
70
71constexpr int kRoomObjectSubtype1 = 0x8000; // JP = Same
72constexpr int kRoomObjectSubtype2 = 0x83F0; // JP = Same
73constexpr int kRoomObjectSubtype3 = 0x84F0; // JP = Same
74constexpr int kRoomObjectTileAddress = 0x1B52; // JP = Same
75constexpr int kRoomObjectTileAddressFloor = 0x1B5A; // JP = Same
76
77class RoomObject : public SharedRom {
78 public:
79 enum LayerType { BG1 = 0, BG2 = 1, BG3 = 2 };
80
81 RoomObject(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer = 0)
82 : id_(id),
83 x_(x),
84 y_(y),
85 size_(size),
86 layer_(static_cast<LayerType>(layer)),
87 nx_(x),
88 ny_(y),
89 ox_(x),
90 oy_(y),
91 width_(16),
92 height_(16),
93 unique_id_(0) {}
94
97 size_ = 1;
99 UpdateSize();
100 size_ = 2;
101 GetSizeSized();
102 UpdateSize();
104 }
105
106 void GetBaseSize() {
109 }
110
115
116 void UpdateSize() {
117 width_ = 8;
118 height_ = 8;
119 }
120
121 void AddTiles(int nbr, int pos) {
122 for (int i = 0; i < nbr; i++) {
123 ASSIGN_OR_LOG_ERROR(auto tile, rom()->ReadTile16(pos + (i * 2)));
124 tiles_.push_back(tile);
125 }
126 }
127
128 void DrawTile(gfx::Tile16 t, int xx, int yy,
129 std::vector<uint8_t>& current_gfx16,
130 std::vector<uint8_t>& tiles_bg1_buffer,
131 std::vector<uint8_t>& tiles_bg2_buffer,
132 ushort tile_under = 0xFFFF);
133
134 auto options() const { return options_; }
136
137 protected:
138 bool all_bgs_ = false;
139 bool lit_ = false;
140 bool deleted_ = false;
141 bool show_rectangle_ = false;
142 bool diagonal_fix_ = false;
143 bool selected_ = false;
144
145 int16_t id_;
146 uint8_t x_;
147 uint8_t y_;
148 uint8_t size_;
149 uint8_t nx_;
150 uint8_t ny_;
151 uint8_t ox_;
152 uint8_t oy_;
153 uint8_t z_ = 0;
154 uint8_t previous_size_ = 0;
155
162 int tile_index_ = 0;
163 int offset_x_ = 0;
164 int offset_y_ = 0;
165 int preview_id_ = 0;
166 int unique_id_ = 0;
167
168 std::string name_;
169
170 std::vector<uint8_t> preview_object_data_;
171 std::vector<gfx::Tile16> tiles_;
172
175};
176
177class Subtype1 : public RoomObject {
178 public:
179 bool allBgs;
181 std::string name;
183
184 Subtype1(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer,
185 int tileCount)
186 : RoomObject(id, x, y, size, layer), tile_count_(tileCount) {
187 auto rom_data = rom()->data();
188 int pos = kRoomObjectTileAddress +
189 static_cast<int16_t>(
190 (rom_data[kRoomObjectSubtype1 + ((id & 0xFF) * 2) + 1] << 8) +
191 rom_data[kRoomObjectSubtype1 + ((id & 0xFF) * 2)]);
192 AddTiles(tile_count_, pos);
194 }
195
196 void Draw(std::vector<uint8_t>& current_gfx16,
197 std::vector<uint8_t>& tiles_bg1_buffer,
198 std::vector<uint8_t>& tiles_bg2_buffer) {
199 for (int s = 0; s < size_ + (tile_count_ == 8 ? 1 : 0); s++) {
200 for (int i = 0; i < tile_count_; i++) {
201 DrawTile(tiles_[i], ((s * 2)) * 8, (i / 2) * 8, current_gfx16,
202 tiles_bg1_buffer, tiles_bg2_buffer);
203 }
204 }
205 }
206};
207
208class Subtype2 : public RoomObject {
209 public:
210 std::string name;
211 bool allBgs;
213
214 Subtype2(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer)
215 : RoomObject(id, x, y, size, layer) {
216 auto rom_data = rom()->data();
217 int pos = kRoomObjectTileAddress +
218 static_cast<int16_t>(
219 (rom_data[kRoomObjectSubtype2 + ((id & 0x7F) * 2) + 1] << 8) +
220 rom_data[kRoomObjectSubtype2 + ((id & 0x7F) * 2)]);
221 AddTiles(8, pos);
223 }
224
225 void Draw(std::vector<uint8_t>& current_gfx16,
226 std::vector<uint8_t>& tiles_bg1_buffer,
227 std::vector<uint8_t>& tiles_bg2_buffer) {
228 for (int i = 0; i < 8; i++) {
229 DrawTile(tiles_[i], x_ * 8, (y_ + i) * 8, current_gfx16, tiles_bg1_buffer,
230 tiles_bg2_buffer);
231 }
232 }
233};
234
235class Subtype3 : public RoomObject {
236 public:
237 bool allBgs;
238 std::string name;
240
241 Subtype3(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer)
242 : RoomObject(id, x, y, size, layer) {
243 auto rom_data = rom()->data();
244 int pos = kRoomObjectTileAddress +
245 static_cast<int16_t>(
246 (rom_data[kRoomObjectSubtype3 + ((id & 0xFF) * 2) + 1] << 8) +
247 rom_data[kRoomObjectSubtype3 + ((id & 0xFF) * 2)]);
248 AddTiles(8, pos);
250 }
251
252 void Draw(std::vector<uint8_t>& current_gfx16,
253 std::vector<uint8_t>& tiles_bg1_buffer,
254 std::vector<uint8_t>& tiles_bg2_buffer) {
255 for (int i = 0; i < 8; i++) {
256 DrawTile(tiles_[i], x_ * 8, (y_ + i) * 8, current_gfx16, tiles_bg1_buffer,
257 tiles_bg2_buffer);
258 }
259 }
260};
261
262} // namespace dungeon
263} // namespace zelda3
264} // namespace app
265} // namespace yaze
266
267#endif // YAZE_APP_ZELDA3_DUNGEON_ROOM_OBJECT_H
A class to hold a shared pointer to a Rom object.
Definition rom.h:585
Tile composition of four 8x8 tiles.
Definition snes_tile.h:133
void set_options(ObjectOption options)
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:81
std::vector< gfx::Tile16 > tiles_
std::vector< uint8_t > preview_object_data_
void Draw(std::vector< uint8_t > &current_gfx16, std::vector< uint8_t > &tiles_bg1_buffer, std::vector< uint8_t > &tiles_bg2_buffer)
Subtype1(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer, int tileCount)
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:88
unsigned short ushort
Definition constants.h:119
ObjectOption operator&(ObjectOption lhs, ObjectOption rhs)
constexpr int kRoomObjectTileAddressFloor
Definition room_object.h:75
constexpr int kRoomObjectSubtype1
Definition room_object.h:71
ObjectOption operator|(ObjectOption lhs, ObjectOption rhs)
Definition room_object.cc:8
constexpr int kRoomObjectSubtype3
Definition room_object.h:73
ObjectOption operator~(ObjectOption option)
constexpr int kRoomObjectSubtype2
Definition room_object.h:72
ObjectOption operator^(ObjectOption lhs, ObjectOption rhs)
constexpr int kRoomObjectTileAddress
Definition room_object.h:74
SubtypeInfo FetchSubtypeInfo(uint16_t object_id)
Definition common.cc:21