Refactor Room and RoomObject classes to remove inheritance from SharedRom, enhancing code clarity and maintainability. Introduce ROM pointer management in both classes for improved functionality. Update LoadRoomFromRom to accommodate new constructor signature.
This commit is contained in:
@@ -75,7 +75,7 @@ RoomSize CalculateRoomSize(Rom *rom, int room_id) {
|
||||
}
|
||||
|
||||
Room LoadRoomFromRom(Rom *rom, int room_id) {
|
||||
Room room(room_id);
|
||||
Room room(room_id, rom);
|
||||
|
||||
int header_pointer = (rom->data()[kRoomHeaderPointer + 2] << 16) +
|
||||
(rom->data()[kRoomHeaderPointer + 1] << 8) +
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/rom.h"
|
||||
#include "app/zelda3/dungeon/room_object.h"
|
||||
#include "app/zelda3/sprite/sprite.h"
|
||||
@@ -198,23 +197,24 @@ enum TagKey {
|
||||
Kill_boss_Again
|
||||
};
|
||||
|
||||
class Room : public SharedRom {
|
||||
class Room {
|
||||
public:
|
||||
Room(int room_id) : room_id_(room_id) {}
|
||||
Room() = default;
|
||||
Room(int room_id, Rom *rom) : room_id_(room_id), rom_(rom) {}
|
||||
|
||||
void LoadRoomGraphics(uint8_t entrance_blockset = 0xFF);
|
||||
void CopyRoomGraphicsToBuffer();
|
||||
void LoadAnimatedGraphics();
|
||||
|
||||
void LoadObjects();
|
||||
void LoadSprites();
|
||||
void LoadChests();
|
||||
|
||||
auto blocks() const { return blocks_; }
|
||||
auto &mutable_blocks() { return blocks_; }
|
||||
auto &layer1() { return background_bmps_[0]; }
|
||||
auto &layer2() { return background_bmps_[1]; }
|
||||
auto &layer3() { return background_bmps_[2]; }
|
||||
auto rom() { return rom_; }
|
||||
auto mutable_rom() { return rom_; }
|
||||
|
||||
Rom *rom_;
|
||||
|
||||
uint8_t blockset = 0;
|
||||
uint8_t spriteset = 0;
|
||||
@@ -223,13 +223,9 @@ class Room : public SharedRom {
|
||||
uint8_t holewarp = 0;
|
||||
uint8_t floor1 = 0;
|
||||
uint8_t floor2 = 0;
|
||||
|
||||
uint16_t message_id_ = 0;
|
||||
|
||||
gfx::Bitmap current_graphics_;
|
||||
std::vector<uint8_t> bg1_buffer_;
|
||||
std::vector<uint8_t> bg2_buffer_;
|
||||
std::vector<uint8_t> current_gfx16_;
|
||||
std::array<uint8_t, 0x4000> current_gfx16_;
|
||||
|
||||
bool is_light_;
|
||||
bool is_loaded_;
|
||||
@@ -253,7 +249,6 @@ class Room : public SharedRom {
|
||||
std::array<uint8_t, 16> blocks_;
|
||||
std::array<chest, 16> chest_list_;
|
||||
|
||||
std::array<gfx::Bitmap, 3> background_bmps_;
|
||||
std::vector<RoomObject> tile_objects_;
|
||||
std::vector<zelda3::Sprite> sprites_;
|
||||
std::vector<staircase> z3_staircases_;
|
||||
|
||||
@@ -54,7 +54,7 @@ constexpr int kRoomObjectSubtype3 = 0x84F0; // JP = Same
|
||||
constexpr int kRoomObjectTileAddress = 0x1B52; // JP = Same
|
||||
constexpr int kRoomObjectTileAddressFloor = 0x1B5A; // JP = Same
|
||||
|
||||
class RoomObject : public SharedRom {
|
||||
class RoomObject {
|
||||
public:
|
||||
enum LayerType { BG1 = 0, BG2 = 1, BG3 = 2 };
|
||||
|
||||
@@ -71,6 +71,10 @@ class RoomObject : public SharedRom {
|
||||
width_(16),
|
||||
height_(16) {}
|
||||
|
||||
void set_rom(Rom* rom) { rom_ = rom; }
|
||||
auto rom() { return rom_; }
|
||||
auto mutable_rom() { return rom_; }
|
||||
|
||||
void AddTiles(int nbr, int pos) {
|
||||
for (int i = 0; i < nbr; i++) {
|
||||
ASSIGN_OR_LOG_ERROR(auto tile, rom()->ReadTile16(pos + (i * 2)));
|
||||
@@ -87,7 +91,6 @@ class RoomObject : public SharedRom {
|
||||
auto options() const { return options_; }
|
||||
void set_options(ObjectOption options) { options_ = options; }
|
||||
|
||||
protected:
|
||||
bool all_bgs_ = false;
|
||||
bool lit_ = false;
|
||||
|
||||
@@ -114,6 +117,8 @@ class RoomObject : public SharedRom {
|
||||
|
||||
LayerType layer_;
|
||||
ObjectOption options_ = ObjectOption::Nothing;
|
||||
|
||||
Rom* rom_;
|
||||
};
|
||||
|
||||
class Subtype1 : public RoomObject {
|
||||
|
||||
Reference in New Issue
Block a user