Refactor OverworldEntity to use uint16_t for map_id and improve code organization
This commit is contained in:
@@ -132,7 +132,7 @@ bool DrawOverworldEntrancePopup(
|
|||||||
}
|
}
|
||||||
if (ImGui::BeginPopupModal("Entrance editor", NULL,
|
if (ImGui::BeginPopupModal("Entrance editor", NULL,
|
||||||
ImGuiWindowFlags_AlwaysAutoResize)) {
|
ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||||
gui::InputHex("Map ID", &entrance.map_id_);
|
gui::InputHexWord("Map ID", &entrance.map_id_);
|
||||||
gui::InputHexByte("Entrance ID", &entrance.entrance_id_,
|
gui::InputHexByte("Entrance ID", &entrance.entrance_id_,
|
||||||
kInputFieldSize + 20);
|
kInputFieldSize + 20);
|
||||||
gui::InputHex("X", &entrance.x_);
|
gui::InputHex("X", &entrance.x_);
|
||||||
@@ -209,7 +209,7 @@ bool DrawExitEditorPopup(zelda3::overworld::OverworldExit &exit) {
|
|||||||
gui::InputHexWord("Room", &exit.room_id_);
|
gui::InputHexWord("Room", &exit.room_id_);
|
||||||
SameLine();
|
SameLine();
|
||||||
gui::InputHex("Entity ID", &exit.entity_id_, 4);
|
gui::InputHex("Entity ID", &exit.entity_id_, 4);
|
||||||
gui::InputHex("Map", &exit.map_id_);
|
gui::InputHexWord("Map", &exit.map_id_);
|
||||||
SameLine();
|
SameLine();
|
||||||
Checkbox("Automatic", &exit.is_automatic_);
|
Checkbox("Automatic", &exit.is_automatic_);
|
||||||
|
|
||||||
@@ -350,8 +350,8 @@ bool DrawItemEditorPopup(zelda3::overworld::OverworldItem &item) {
|
|||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
for (int i = 0; i < zelda3::overworld::kSecretItemNames.size(); i++) {
|
for (int i = 0; i < zelda3::overworld::kSecretItemNames.size(); i++) {
|
||||||
if (Selectable(zelda3::overworld::kSecretItemNames[i].c_str(),
|
if (Selectable(zelda3::overworld::kSecretItemNames[i].c_str(),
|
||||||
item.id == i)) {
|
item.id_ == i)) {
|
||||||
item.id = i;
|
item.id_ = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
|
|||||||
@@ -843,8 +843,8 @@ void OverworldEditor::DrawOverworldItems() {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto &item : *overworld_.mutable_all_items()) {
|
for (auto &item : *overworld_.mutable_all_items()) {
|
||||||
// Get the item's bitmap and real X and Y positions
|
// Get the item's bitmap and real X and Y positions
|
||||||
if (item.room_map_id < 0x40 + (current_world_ * 0x40) &&
|
if (item.room_map_id_ < 0x40 + (current_world_ * 0x40) &&
|
||||||
item.room_map_id >= (current_world_ * 0x40) && !item.deleted) {
|
item.room_map_id_ >= (current_world_ * 0x40) && !item.deleted) {
|
||||||
ow_map_canvas_.DrawRect(item.x_, item.y_, 16, 16, ImVec4(255, 0, 0, 150));
|
ow_map_canvas_.DrawRect(item.x_, item.y_, 16, 16, ImVec4(255, 0, 0, 150));
|
||||||
|
|
||||||
if (current_mode == EditingMode::ITEMS) {
|
if (current_mode == EditingMode::ITEMS) {
|
||||||
@@ -862,10 +862,10 @@ void OverworldEditor::DrawOverworldItems() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string item_name = "";
|
std::string item_name = "";
|
||||||
if (item.id < zelda3::overworld::kSecretItemNames.size()) {
|
if (item.id_ < zelda3::overworld::kSecretItemNames.size()) {
|
||||||
item_name = zelda3::overworld::kSecretItemNames[item.id];
|
item_name = zelda3::overworld::kSecretItemNames[item.id_];
|
||||||
} else {
|
} else {
|
||||||
item_name = absl::StrFormat("0x%02X", item.id);
|
item_name = absl::StrFormat("0x%02X", item.id_);
|
||||||
}
|
}
|
||||||
ow_map_canvas_.DrawText(item_name, item.x_, item.y_);
|
ow_map_canvas_.DrawText(item_name, item.x_, item.y_);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,14 +45,14 @@ class OverworldEntity {
|
|||||||
int game_x_;
|
int game_x_;
|
||||||
int game_y_;
|
int game_y_;
|
||||||
int entity_id_;
|
int entity_id_;
|
||||||
int map_id_;
|
uint16_t map_id_;
|
||||||
|
|
||||||
auto set_x(int x) { x_ = x; }
|
auto set_x(int x) { x_ = x; }
|
||||||
auto set_y(int y) { y_ = y; }
|
auto set_y(int y) { y_ = y; }
|
||||||
|
|
||||||
OverworldEntity() = default;
|
OverworldEntity() = default;
|
||||||
|
|
||||||
virtual void UpdateMapProperties(short map_id) = 0;
|
virtual void UpdateMapProperties(uint16_t map_id) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::string TileTypeNames[] = {
|
static const std::string TileTypeNames[] = {
|
||||||
|
|||||||
@@ -468,8 +468,8 @@ absl::Status Overworld::LoadItems() {
|
|||||||
(y * 16) + (sy * 512), false);
|
(y * 16) + (sy * 512), false);
|
||||||
auto size = all_items_.size();
|
auto size = all_items_.size();
|
||||||
|
|
||||||
all_items_[size - 1].game_x = (uint8_t)x;
|
all_items_[size - 1].game_x_ = (uint8_t)x;
|
||||||
all_items_[size - 1].game_y = (uint8_t)y;
|
all_items_[size - 1].game_y_ = (uint8_t)y;
|
||||||
addr += 3;
|
addr += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1335,7 +1335,7 @@ bool compareItemsArrays(std::vector<OverworldItem> itemArray1,
|
|||||||
// Check all sprite in 2nd array if one match
|
// Check all sprite in 2nd array if one match
|
||||||
if (itemArray1[i].x_ == itemArray2[j].x_ &&
|
if (itemArray1[i].x_ == itemArray2[j].x_ &&
|
||||||
itemArray1[i].y_ == itemArray2[j].y_ &&
|
itemArray1[i].y_ == itemArray2[j].y_ &&
|
||||||
itemArray1[i].id == itemArray2[j].id) {
|
itemArray1[i].id_ == itemArray2[j].id_) {
|
||||||
match = true;
|
match = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1357,11 +1357,11 @@ absl::Status Overworld::SaveItems() {
|
|||||||
for (int i = 0; i < 128; i++) {
|
for (int i = 0; i < 128; i++) {
|
||||||
room_items[i] = std::vector<OverworldItem>();
|
room_items[i] = std::vector<OverworldItem>();
|
||||||
for (const OverworldItem &item : all_items_) {
|
for (const OverworldItem &item : all_items_) {
|
||||||
if (item.room_map_id == i) {
|
if (item.room_map_id_ == i) {
|
||||||
room_items[i].emplace_back(item);
|
room_items[i].emplace_back(item);
|
||||||
if (item.id == 0x86) {
|
if (item.id_ == 0x86) {
|
||||||
RETURN_IF_ERROR(rom()->WriteWord(
|
RETURN_IF_ERROR(rom()->WriteWord(
|
||||||
0x16DC5 + (i * 2), (item.game_x + (item.game_y * 64)) * 2));
|
0x16DC5 + (i * 2), (item.game_x_ + (item.game_y_ * 64)) * 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1398,11 +1398,11 @@ absl::Status Overworld::SaveItems() {
|
|||||||
item_pointers[i] = data_pos;
|
item_pointers[i] = data_pos;
|
||||||
for (const OverworldItem &item : room_items[i]) {
|
for (const OverworldItem &item : room_items[i]) {
|
||||||
short map_pos =
|
short map_pos =
|
||||||
static_cast<short>(((item.game_y << 6) + item.game_x) << 1);
|
static_cast<short>(((item.game_y_ << 6) + item.game_x_) << 1);
|
||||||
|
|
||||||
uint32_t data = static_cast<uint8_t>(map_pos & 0xFF) |
|
uint32_t data = static_cast<uint8_t>(map_pos & 0xFF) |
|
||||||
static_cast<uint8_t>(map_pos >> 8) |
|
static_cast<uint8_t>(map_pos >> 8) |
|
||||||
static_cast<uint8_t>(item.id);
|
static_cast<uint8_t>(item.id_);
|
||||||
RETURN_IF_ERROR(rom()->WriteLong(data_pos, data));
|
RETURN_IF_ERROR(rom()->WriteLong(data_pos, data));
|
||||||
data_pos += 3;
|
data_pos += 3;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,21 +79,21 @@ constexpr int overworldItemsEndData = 0xDC89C; // 0DC89E
|
|||||||
|
|
||||||
class OverworldItem : public OverworldEntity {
|
class OverworldItem : public OverworldEntity {
|
||||||
public:
|
public:
|
||||||
bool bg2 = false;
|
bool bg2_ = false;
|
||||||
uint8_t game_x;
|
uint8_t id_;
|
||||||
uint8_t game_y;
|
uint8_t game_x_;
|
||||||
uint8_t id;
|
uint8_t game_y_;
|
||||||
uint16_t room_map_id;
|
uint16_t room_map_id_;
|
||||||
int unique_id = 0;
|
int unique_id = 0;
|
||||||
bool deleted = false;
|
bool deleted = false;
|
||||||
OverworldItem() = default;
|
OverworldItem() = default;
|
||||||
|
|
||||||
OverworldItem(uint8_t id, uint16_t room_map_id, int x, int y, bool bg2) {
|
OverworldItem(uint8_t id, uint16_t room_map_id, int x, int y, bool bg2) {
|
||||||
this->id = id;
|
this->id_ = id;
|
||||||
this->x_ = x;
|
this->x_ = x;
|
||||||
this->y_ = y;
|
this->y_ = y;
|
||||||
this->bg2 = bg2;
|
this->bg2_ = bg2;
|
||||||
this->room_map_id = room_map_id;
|
this->room_map_id_ = room_map_id;
|
||||||
this->map_id_ = room_map_id;
|
this->map_id_ = room_map_id;
|
||||||
this->entity_id_ = id;
|
this->entity_id_ = id;
|
||||||
this->type_ = kItem;
|
this->type_ = kItem;
|
||||||
@@ -101,32 +101,28 @@ class OverworldItem : public OverworldEntity {
|
|||||||
int map_x = room_map_id - ((room_map_id / 8) * 8);
|
int map_x = room_map_id - ((room_map_id / 8) * 8);
|
||||||
int map_y = room_map_id / 8;
|
int map_y = room_map_id / 8;
|
||||||
|
|
||||||
this->game_x = static_cast<uint8_t>(std::abs(x - (map_x * 512)) / 16);
|
game_x_ = static_cast<uint8_t>(std::abs(x - (map_x * 512)) / 16);
|
||||||
this->game_y = static_cast<uint8_t>(std::abs(y - (map_y * 512)) / 16);
|
game_y_ = static_cast<uint8_t>(std::abs(y - (map_y * 512)) / 16);
|
||||||
// this->unique_id = ROM.unique_item_id++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateMapProperties(int16_t room_map_id) override {
|
void UpdateMapProperties(uint16_t room_map_id) override {
|
||||||
this->room_map_id = static_cast<uint16_t>(room_map_id);
|
room_map_id_ = room_map_id;
|
||||||
|
|
||||||
if (room_map_id >= 64) {
|
if (room_map_id_ >= 64) {
|
||||||
room_map_id -= 64;
|
room_map_id_ -= 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
int map_x = room_map_id - ((room_map_id / 8) * 8);
|
int map_x = room_map_id_ - ((room_map_id_ / 8) * 8);
|
||||||
int map_y = room_map_id / 8;
|
int map_y = room_map_id_ / 8;
|
||||||
|
|
||||||
this->game_x =
|
game_x_ = static_cast<uint8_t>(std::abs(x_ - (map_x * 512)) / 16);
|
||||||
static_cast<uint8_t>(std::abs(this->x_ - (map_x * 512)) / 16);
|
game_y_ = static_cast<uint8_t>(std::abs(y_ - (map_y * 512)) / 16);
|
||||||
this->game_y =
|
|
||||||
static_cast<uint8_t>(std::abs(this->y_ - (map_y * 512)) / 16);
|
|
||||||
|
|
||||||
std::cout << "Item: " << std::hex << std::setw(2) << std::setfill('0')
|
std::cout << "Item: " << std::hex << std::setw(2) << std::setfill('0')
|
||||||
<< static_cast<int>(this->id) << " MapId: " << std::hex
|
<< static_cast<int>(id_) << " MapId: " << std::hex << std::setw(2)
|
||||||
<< std::setw(2) << std::setfill('0')
|
<< std::setfill('0') << static_cast<int>(room_map_id_)
|
||||||
<< static_cast<int>(this->room_map_id)
|
<< " X: " << static_cast<int>(game_x_)
|
||||||
<< " X: " << static_cast<int>(this->game_x)
|
<< " Y: " << static_cast<int>(game_y_) << std::endl;
|
||||||
<< " Y: " << static_cast<int>(this->game_y) << std::endl;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -191,7 +187,6 @@ class OverworldExit : public OverworldEntity {
|
|||||||
entrance_id_(0),
|
entrance_id_(0),
|
||||||
area_x_(0),
|
area_x_(0),
|
||||||
area_y_(0),
|
area_y_(0),
|
||||||
is_hole_(false),
|
|
||||||
room_id_(room_id),
|
room_id_(room_id),
|
||||||
y_scroll_(y_scroll),
|
y_scroll_(y_scroll),
|
||||||
x_scroll_(x_scroll),
|
x_scroll_(x_scroll),
|
||||||
@@ -203,12 +198,13 @@ class OverworldExit : public OverworldEntity {
|
|||||||
scroll_mod_x_(scroll_mod_x),
|
scroll_mod_x_(scroll_mod_x),
|
||||||
door_type_1_(door_type_1),
|
door_type_1_(door_type_1),
|
||||||
door_type_2_(door_type_2),
|
door_type_2_(door_type_2),
|
||||||
|
is_hole_(false),
|
||||||
deleted_(deleted) {
|
deleted_(deleted) {
|
||||||
// Initialize entity variables
|
// Initialize entity variables
|
||||||
this->x_ = player_x;
|
x_ = player_x;
|
||||||
this->y_ = player_y;
|
y_ = player_y;
|
||||||
this->map_id_ = map_id;
|
map_id_ = map_id;
|
||||||
this->type_ = kExit;
|
type_ = kExit;
|
||||||
|
|
||||||
int mapX = (map_id_ - ((map_id_ / 8) * 8));
|
int mapX = (map_id_ - ((map_id_ / 8) * 8));
|
||||||
int mapY = (map_id_ / 8);
|
int mapY = (map_id_ / 8);
|
||||||
@@ -242,7 +238,7 @@ class OverworldExit : public OverworldEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Overworld overworld
|
// Overworld overworld
|
||||||
void UpdateMapProperties(short map_id) override {
|
void UpdateMapProperties(uint16_t map_id) override {
|
||||||
map_id_ = map_id;
|
map_id_ = map_id;
|
||||||
|
|
||||||
int large = 256;
|
int large = 256;
|
||||||
@@ -365,7 +361,7 @@ class OverworldEntrance : public OverworldEntity {
|
|||||||
is_hole_);
|
is_hole_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateMapProperties(short map_id) override {
|
void UpdateMapProperties(uint16_t map_id) override {
|
||||||
map_id_ = map_id;
|
map_id_ = map_id;
|
||||||
|
|
||||||
if (map_id_ >= 64) {
|
if (map_id_ >= 64) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace yaze {
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace zelda3 {
|
namespace zelda3 {
|
||||||
|
|
||||||
void Sprite::UpdateMapProperties(short map_id) {
|
void Sprite::UpdateMapProperties(uint16_t map_id) {
|
||||||
map_x_ = x_;
|
map_x_ = x_;
|
||||||
map_y_ = y_;
|
map_y_ = y_;
|
||||||
name_ = kSpriteDefaultNames[id_];
|
name_ = kSpriteDefaultNames[id_];
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ class Sprite : public OverworldEntity {
|
|||||||
bool mirror_x = false, bool mirror_y = false,
|
bool mirror_x = false, bool mirror_y = false,
|
||||||
int sizex = 2, int sizey = 2);
|
int sizex = 2, int sizey = 2);
|
||||||
|
|
||||||
void UpdateMapProperties(short map_id) override;
|
void UpdateMapProperties(uint16_t map_id) override;
|
||||||
|
|
||||||
// New methods
|
// New methods
|
||||||
void UpdateCoordinates(int map_x, int map_y);
|
void UpdateCoordinates(int map_x, int map_y);
|
||||||
|
|||||||
Reference in New Issue
Block a user