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