chore: Refactor room object loading and drawing methods
This commit is contained in:
@@ -366,29 +366,28 @@ void Room::LoadObjects() {
|
||||
sizeXY = 0;
|
||||
}
|
||||
|
||||
RoomObject r =
|
||||
AddObject(oid, posX, posY, sizeXY, static_cast<uint8_t>(layer));
|
||||
|
||||
/**
|
||||
if (r != nullptr) {
|
||||
tilesObjects.push_back(r);
|
||||
}
|
||||
|
||||
RoomObject r(oid, posX, posY, sizeXY, static_cast<uint8_t>(layer));
|
||||
tile_objects_.push_back(r);
|
||||
|
||||
for (short stair : stairsObjects) {
|
||||
if (stair == oid) {
|
||||
if (nbr_of_staircase < 4) {
|
||||
tilesObjects.back().options |= ObjectOption::Stairs;
|
||||
staircaseRooms.push_back(StaircaseRoom(
|
||||
posX, posY, "To " + staircase_rooms_[nbr_of_staircase]));
|
||||
tile_objects_.back().set_options(ObjectOption::Stairs |
|
||||
tile_objects_.back().options());
|
||||
staircase_rooms_vec_.push_back(StaircaseRooms(
|
||||
posX, posY,
|
||||
absl::StrCat("To ", staircase_rooms_[nbr_of_staircase])
|
||||
.data()));
|
||||
nbr_of_staircase++;
|
||||
} else {
|
||||
tilesObjects.back().options |= ObjectOption::Stairs;
|
||||
staircaseRooms.push_back(StaircaseRoom(posX, posY, "To ???"));
|
||||
tile_objects_.back().set_options(ObjectOption::Stairs |
|
||||
tile_objects_.back().options());
|
||||
staircase_rooms_vec_.push_back(
|
||||
StaircaseRooms(posX, posY, "To ???"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
if (oid == 0xF99) {
|
||||
if (chests_in_room.size() > 0) {
|
||||
tilesObjects.back().options |= ObjectOption::Chest;
|
||||
@@ -408,7 +407,6 @@ void Room::LoadObjects() {
|
||||
tilesObjects.push_back(object_door(static_cast<short>((b2 << 8) + b1), 0,
|
||||
0, 0, static_cast<uint8_t>(layer)));
|
||||
}
|
||||
|
||||
**/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,15 @@ struct ChestData {
|
||||
bool size_;
|
||||
};
|
||||
|
||||
struct StaircaseRooms {};
|
||||
struct StaircaseRooms {
|
||||
StaircaseRooms() = default;
|
||||
StaircaseRooms(uchar i, uchar r, const char* label)
|
||||
: id_(i), room_(r), label_(label){};
|
||||
|
||||
uchar id_;
|
||||
uchar room_;
|
||||
const char* label_;
|
||||
};
|
||||
|
||||
class Room : public SharedRom {
|
||||
public:
|
||||
|
||||
@@ -5,6 +5,25 @@ namespace app {
|
||||
namespace zelda3 {
|
||||
namespace dungeon {
|
||||
|
||||
ObjectOption operator|(ObjectOption lhs, ObjectOption rhs) {
|
||||
return static_cast<ObjectOption>(static_cast<int>(lhs) |
|
||||
static_cast<int>(rhs));
|
||||
}
|
||||
|
||||
ObjectOption operator&(ObjectOption lhs, ObjectOption rhs) {
|
||||
return static_cast<ObjectOption>(static_cast<int>(lhs) &
|
||||
static_cast<int>(rhs));
|
||||
}
|
||||
|
||||
ObjectOption operator^(ObjectOption lhs, ObjectOption rhs) {
|
||||
return static_cast<ObjectOption>(static_cast<int>(lhs) ^
|
||||
static_cast<int>(rhs));
|
||||
}
|
||||
|
||||
ObjectOption operator~(ObjectOption option) {
|
||||
return static_cast<ObjectOption>(~static_cast<int>(option));
|
||||
}
|
||||
|
||||
SubtypeInfo FetchSubtypeInfo(uint16_t object_id) {
|
||||
SubtypeInfo info;
|
||||
|
||||
@@ -31,7 +50,7 @@ SubtypeInfo FetchSubtypeInfo(uint16_t object_id) {
|
||||
return info;
|
||||
}
|
||||
|
||||
void RoomObject::DrawTile(Tile t, int xx, int yy,
|
||||
void RoomObject::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,
|
||||
|
||||
@@ -28,8 +28,6 @@ struct SubtypeInfo {
|
||||
|
||||
SubtypeInfo FetchSubtypeInfo(uint16_t object_id);
|
||||
|
||||
struct Tile {};
|
||||
|
||||
enum class SpecialObjectType { Chest, BigChest, InterroomStairs };
|
||||
|
||||
enum Background2 {
|
||||
@@ -55,7 +53,7 @@ enum Sorting {
|
||||
SortStairs = 64
|
||||
};
|
||||
|
||||
enum ObjectOption {
|
||||
enum class ObjectOption {
|
||||
Nothing = 0,
|
||||
Door = 1,
|
||||
Chest = 2,
|
||||
@@ -65,6 +63,11 @@ enum ObjectOption {
|
||||
Stairs = 32
|
||||
};
|
||||
|
||||
ObjectOption operator|(ObjectOption lhs, ObjectOption rhs);
|
||||
ObjectOption operator&(ObjectOption lhs, ObjectOption rhs);
|
||||
ObjectOption operator^(ObjectOption lhs, ObjectOption rhs);
|
||||
ObjectOption operator~(ObjectOption option);
|
||||
|
||||
constexpr int kRoomObjectSubtype1 = 0x8000; // JP = Same
|
||||
constexpr int kRoomObjectSubtype2 = 0x83F0; // JP = Same
|
||||
constexpr int kRoomObjectSubtype3 = 0x84F0; // JP = Same
|
||||
@@ -123,11 +126,15 @@ class RoomObject : public SharedRom {
|
||||
}
|
||||
}
|
||||
|
||||
void DrawTile(Tile t, int xx, int yy, std::vector<uint8_t>& current_gfx16,
|
||||
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);
|
||||
|
||||
auto options() const { return options_; }
|
||||
void set_options(ObjectOption options) { options_ = options; }
|
||||
|
||||
protected:
|
||||
bool all_bgs_ = false;
|
||||
bool lit_ = false;
|
||||
@@ -161,19 +168,19 @@ class RoomObject : public SharedRom {
|
||||
|
||||
std::string name_;
|
||||
|
||||
std::vector<uint8_t> preview_object_data_;
|
||||
std::vector<gfx::Tile16> tiles_;
|
||||
|
||||
LayerType layer_;
|
||||
ObjectOption options_ = ObjectOption::Nothing;
|
||||
std::vector<gfx::Tile16> tiles_;
|
||||
std::vector<uint8_t> preview_object_data_;
|
||||
};
|
||||
|
||||
class Subtype1 : public RoomObject {
|
||||
public:
|
||||
std::vector<Tile> tiles;
|
||||
std::string name;
|
||||
bool allBgs;
|
||||
Sorting sort;
|
||||
int tile_count_;
|
||||
std::string name;
|
||||
Sorting sort;
|
||||
|
||||
Subtype1(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer,
|
||||
int tileCount)
|
||||
@@ -187,10 +194,13 @@ class Subtype1 : public RoomObject {
|
||||
sort = (Sorting)(Sorting::Horizontal | Sorting::Wall);
|
||||
}
|
||||
|
||||
void Draw() {
|
||||
void Draw(std::vector<uint8_t>& current_gfx16,
|
||||
std::vector<uint8_t>& tiles_bg1_buffer,
|
||||
std::vector<uint8_t>& tiles_bg2_buffer) {
|
||||
for (int s = 0; s < size_ + (tile_count_ == 8 ? 1 : 0); s++) {
|
||||
for (int i = 0; i < tile_count_; i++) {
|
||||
// DrawTile(tiles[i], ((s * 2)) * 8, (i / 2) * 8);
|
||||
DrawTile(tiles_[i], ((s * 2)) * 8, (i / 2) * 8, current_gfx16,
|
||||
tiles_bg1_buffer, tiles_bg2_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,7 +208,6 @@ class Subtype1 : public RoomObject {
|
||||
|
||||
class Subtype2 : public RoomObject {
|
||||
public:
|
||||
std::vector<Tile> tiles;
|
||||
std::string name;
|
||||
bool allBgs;
|
||||
Sorting sort;
|
||||
@@ -214,18 +223,20 @@ class Subtype2 : public RoomObject {
|
||||
sort = (Sorting)(Sorting::Horizontal | Sorting::Wall);
|
||||
}
|
||||
|
||||
void Draw() {
|
||||
void Draw(std::vector<uint8_t>& current_gfx16,
|
||||
std::vector<uint8_t>& tiles_bg1_buffer,
|
||||
std::vector<uint8_t>& tiles_bg2_buffer) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// DrawTile(tiles[i], x_ * 8, (y_ + i) * 8);
|
||||
DrawTile(tiles_[i], x_ * 8, (y_ + i) * 8, current_gfx16, tiles_bg1_buffer,
|
||||
tiles_bg2_buffer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Subtype3 : public RoomObject {
|
||||
public:
|
||||
std::vector<Tile> tiles;
|
||||
std::string name;
|
||||
bool allBgs;
|
||||
std::string name;
|
||||
Sorting sort;
|
||||
|
||||
Subtype3(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer)
|
||||
@@ -239,9 +250,12 @@ class Subtype3 : public RoomObject {
|
||||
sort = (Sorting)(Sorting::Horizontal | Sorting::Wall);
|
||||
}
|
||||
|
||||
void Draw() {
|
||||
void Draw(std::vector<uint8_t>& current_gfx16,
|
||||
std::vector<uint8_t>& tiles_bg1_buffer,
|
||||
std::vector<uint8_t>& tiles_bg2_buffer) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// DrawTile(tiles[i], x_ * 8, (y_ + i) * 8);
|
||||
DrawTile(tiles_[i], x_ * 8, (y_ + i) * 8, current_gfx16, tiles_bg1_buffer,
|
||||
tiles_bg2_buffer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user