yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
room_object.cc
Go to the documentation of this file.
1#include "room_object.h"
2
3namespace yaze {
4namespace app {
5namespace zelda3 {
6namespace dungeon {
7
9 return static_cast<ObjectOption>(static_cast<int>(lhs) |
10 static_cast<int>(rhs));
11}
12
14 return static_cast<ObjectOption>(static_cast<int>(lhs) &
15 static_cast<int>(rhs));
16}
17
19 return static_cast<ObjectOption>(static_cast<int>(lhs) ^
20 static_cast<int>(rhs));
21}
22
24 return static_cast<ObjectOption>(~static_cast<int>(option));
25}
26
27SubtypeInfo FetchSubtypeInfo(uint16_t object_id) {
28 SubtypeInfo info;
29
30 // TODO: Determine the subtype based on object_id
31 uint8_t subtype = 1;
32
33 switch (subtype) {
34 case 1: // Subtype 1
35 info.subtype_ptr = kRoomObjectSubtype1 + (object_id & 0xFF) * 2;
36 info.routine_ptr = kRoomObjectSubtype1 + 0x200 + (object_id & 0xFF) * 2;
37 break;
38 case 2: // Subtype 2
39 info.subtype_ptr = kRoomObjectSubtype2 + (object_id & 0x7F) * 2;
40 info.routine_ptr = kRoomObjectSubtype2 + 0x80 + (object_id & 0x7F) * 2;
41 break;
42 case 3: // Subtype 3
43 info.subtype_ptr = kRoomObjectSubtype3 + (object_id & 0xFF) * 2;
44 info.routine_ptr = kRoomObjectSubtype3 + 0x100 + (object_id & 0xFF) * 2;
45 break;
46 default:
47 throw std::runtime_error("Invalid object subtype");
48 }
49
50 return info;
51}
52
53void RoomObject::DrawTile(gfx::Tile16 t, int xx, int yy,
54 std::vector<uint8_t>& current_gfx16,
55 std::vector<uint8_t>& tiles_bg1_buffer,
56 std::vector<uint8_t>& tiles_bg2_buffer,
57 ushort tileUnder) {
58 bool preview = false;
59 if (width_ < xx + 8) {
60 width_ = xx + 8;
61 }
62 if (height_ < yy + 8) {
63 height_ = yy + 8;
64 }
65 if (preview) {
66 if (xx < 0x39 && yy < 0x39 && xx >= 0 && yy >= 0) {
67 gfx::TileInfo ti; // t.GetTileInfo();
68 for (auto yl = 0; yl < 8; yl++) {
69 for (auto xl = 0; xl < 4; xl++) {
70 int mx = xl;
71 int my = yl;
72 uint8_t r = 0;
73
74 if (ti.horizontal_mirror_) {
75 mx = 3 - xl;
76 r = 1;
77 }
78 if (ti.vertical_mirror_) {
79 my = 7 - yl;
80 }
81
82 // Formula information to get tile index position in the array.
83 //((ID / nbrofXtiles) * (imgwidth/2) + (ID - ((ID/16)*16) ))
84 int tx = ((ti.id_ / 0x10) * 0x200) +
85 ((ti.id_ - ((ti.id_ / 0x10) * 0x10)) * 4);
86 auto pixel = current_gfx16[tx + (yl * 0x40) + xl];
87 // nx,ny = object position, xx,yy = tile position, xl,yl = pixel
88 // position
89
90 int index =
91 ((xx / 8) * 8) + ((yy / 8) * 0x200) + ((mx * 2) + (my * 0x40));
92 preview_object_data_[index + r ^ 1] =
93 (uint8_t)((pixel & 0x0F) + ti.palette_ * 0x10);
94 preview_object_data_[index + r] =
95 (uint8_t)(((pixel >> 4) & 0x0F) + ti.palette_ * 0x10);
96 }
97 }
98 }
99 } else {
100 if (((xx / 8) + nx_ + offset_x_) + ((ny_ + offset_y_ + (yy / 8)) * 0x40) <
101 0x1000 &&
102 ((xx / 8) + nx_ + offset_x_) + ((ny_ + offset_y_ + (yy / 8)) * 0x40) >=
103 0) {
104 ushort td = 0; // gfx::GetTilesInfo();
105
106 // collisionPoint.Add(
107 // new Point(xx + ((nx + offsetX) * 8), yy + ((ny + +offsetY) * 8)));
108
109 if (layer_ == 0 || (uint8_t)layer_ == 2 || all_bgs_) {
110 if (tileUnder ==
111 tiles_bg1_buffer[((xx / 8) + offset_x_ + nx_) +
112 ((ny_ + offset_y_ + (yy / 8)) * 0x40)]) {
113 return;
114 }
115
116 tiles_bg1_buffer[((xx / 8) + offset_x_ + nx_) +
117 ((ny_ + offset_y_ + (yy / 8)) * 0x40)] = td;
118 }
119
120 if ((uint8_t)layer_ == 1 || all_bgs_) {
121 if (tileUnder ==
122 tiles_bg2_buffer[((xx / 8) + nx_ + offset_x_) +
123 ((ny_ + offset_y_ + (yy / 8)) * 0x40)]) {
124 return;
125 }
126
127 tiles_bg2_buffer[((xx / 8) + nx_ + offset_x_) +
128 ((ny_ + offset_y_ + (yy / 8)) * 0x40)] = td;
129 }
130 }
131 }
132}
133
134} // namespace dungeon
135} // namespace zelda3
136} // namespace app
137} // namespace yaze
Tile composition of four 8x8 tiles.
Definition snes_tile.h:130
SNES 16-bit tile metadata container.
Definition snes_tile.h:50
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)
std::vector< uint8_t > preview_object_data_
unsigned short ushort
Definition constants.h:112
ObjectOption operator&(ObjectOption lhs, ObjectOption rhs)
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)
SubtypeInfo FetchSubtypeInfo(uint16_t object_id)
Definition common.cc:22