chore: Refactor room object loading and drawing methods

This commit is contained in:
scawful
2024-08-21 00:09:57 -04:00
parent 4baa302f40
commit 3b5e4cd791
4 changed files with 74 additions and 35 deletions

View File

@@ -366,29 +366,28 @@ void Room::LoadObjects() {
sizeXY = 0; sizeXY = 0;
} }
RoomObject r = RoomObject r(oid, posX, posY, sizeXY, static_cast<uint8_t>(layer));
AddObject(oid, posX, posY, sizeXY, static_cast<uint8_t>(layer)); tile_objects_.push_back(r);
/**
if (r != nullptr) {
tilesObjects.push_back(r);
}
for (short stair : stairsObjects) { for (short stair : stairsObjects) {
if (stair == oid) { if (stair == oid) {
if (nbr_of_staircase < 4) { if (nbr_of_staircase < 4) {
tilesObjects.back().options |= ObjectOption::Stairs; tile_objects_.back().set_options(ObjectOption::Stairs |
staircaseRooms.push_back(StaircaseRoom( tile_objects_.back().options());
posX, posY, "To " + staircase_rooms_[nbr_of_staircase])); staircase_rooms_vec_.push_back(StaircaseRooms(
posX, posY,
absl::StrCat("To ", staircase_rooms_[nbr_of_staircase])
.data()));
nbr_of_staircase++; nbr_of_staircase++;
} else { } else {
tilesObjects.back().options |= ObjectOption::Stairs; tile_objects_.back().set_options(ObjectOption::Stairs |
staircaseRooms.push_back(StaircaseRoom(posX, posY, "To ???")); tile_objects_.back().options());
staircase_rooms_vec_.push_back(
StaircaseRooms(posX, posY, "To ???"));
} }
} }
} }
/**
if (oid == 0xF99) { if (oid == 0xF99) {
if (chests_in_room.size() > 0) { if (chests_in_room.size() > 0) {
tilesObjects.back().options |= ObjectOption::Chest; tilesObjects.back().options |= ObjectOption::Chest;
@@ -408,7 +407,6 @@ void Room::LoadObjects() {
tilesObjects.push_back(object_door(static_cast<short>((b2 << 8) + b1), 0, tilesObjects.push_back(object_door(static_cast<short>((b2 << 8) + b1), 0,
0, 0, static_cast<uint8_t>(layer))); 0, 0, static_cast<uint8_t>(layer)));
} }
**/ **/
} }
} }

View File

@@ -117,7 +117,15 @@ struct ChestData {
bool size_; 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 { class Room : public SharedRom {
public: public:

View File

@@ -5,6 +5,25 @@ namespace app {
namespace zelda3 { namespace zelda3 {
namespace dungeon { 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 FetchSubtypeInfo(uint16_t object_id) {
SubtypeInfo info; SubtypeInfo info;
@@ -31,7 +50,7 @@ SubtypeInfo FetchSubtypeInfo(uint16_t object_id) {
return info; 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>& current_gfx16,
std::vector<uint8_t>& tiles_bg1_buffer, std::vector<uint8_t>& tiles_bg1_buffer,
std::vector<uint8_t>& tiles_bg2_buffer, std::vector<uint8_t>& tiles_bg2_buffer,

View File

@@ -28,8 +28,6 @@ struct SubtypeInfo {
SubtypeInfo FetchSubtypeInfo(uint16_t object_id); SubtypeInfo FetchSubtypeInfo(uint16_t object_id);
struct Tile {};
enum class SpecialObjectType { Chest, BigChest, InterroomStairs }; enum class SpecialObjectType { Chest, BigChest, InterroomStairs };
enum Background2 { enum Background2 {
@@ -55,7 +53,7 @@ enum Sorting {
SortStairs = 64 SortStairs = 64
}; };
enum ObjectOption { enum class ObjectOption {
Nothing = 0, Nothing = 0,
Door = 1, Door = 1,
Chest = 2, Chest = 2,
@@ -65,6 +63,11 @@ enum ObjectOption {
Stairs = 32 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 kRoomObjectSubtype1 = 0x8000; // JP = Same
constexpr int kRoomObjectSubtype2 = 0x83F0; // JP = Same constexpr int kRoomObjectSubtype2 = 0x83F0; // JP = Same
constexpr int kRoomObjectSubtype3 = 0x84F0; // 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_bg1_buffer,
std::vector<uint8_t>& tiles_bg2_buffer, std::vector<uint8_t>& tiles_bg2_buffer,
ushort tile_under = 0xFFFF); ushort tile_under = 0xFFFF);
auto options() const { return options_; }
void set_options(ObjectOption options) { options_ = options; }
protected: protected:
bool all_bgs_ = false; bool all_bgs_ = false;
bool lit_ = false; bool lit_ = false;
@@ -161,19 +168,19 @@ class RoomObject : public SharedRom {
std::string name_; std::string name_;
std::vector<uint8_t> preview_object_data_;
std::vector<gfx::Tile16> tiles_;
LayerType layer_; LayerType layer_;
ObjectOption options_ = ObjectOption::Nothing; ObjectOption options_ = ObjectOption::Nothing;
std::vector<gfx::Tile16> tiles_;
std::vector<uint8_t> preview_object_data_;
}; };
class Subtype1 : public RoomObject { class Subtype1 : public RoomObject {
public: public:
std::vector<Tile> tiles;
std::string name;
bool allBgs; bool allBgs;
Sorting sort;
int tile_count_; int tile_count_;
std::string name;
Sorting sort;
Subtype1(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer, Subtype1(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer,
int tileCount) int tileCount)
@@ -187,10 +194,13 @@ class Subtype1 : public RoomObject {
sort = (Sorting)(Sorting::Horizontal | Sorting::Wall); 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 s = 0; s < size_ + (tile_count_ == 8 ? 1 : 0); s++) {
for (int i = 0; i < tile_count_; i++) { 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 { class Subtype2 : public RoomObject {
public: public:
std::vector<Tile> tiles;
std::string name; std::string name;
bool allBgs; bool allBgs;
Sorting sort; Sorting sort;
@@ -214,18 +223,20 @@ class Subtype2 : public RoomObject {
sort = (Sorting)(Sorting::Horizontal | Sorting::Wall); 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++) { 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 { class Subtype3 : public RoomObject {
public: public:
std::vector<Tile> tiles;
std::string name;
bool allBgs; bool allBgs;
std::string name;
Sorting sort; Sorting sort;
Subtype3(int16_t id, uint8_t x, uint8_t y, uint8_t size, uint8_t layer) 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); 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++) { 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);
} }
} }
}; };