big cleanup, replace Bytes alias with std::vector<uint8_t> to reduce ambiguity

This commit is contained in:
scawful
2024-08-20 12:02:47 -04:00
parent 2443336f9d
commit 49611d4944
33 changed files with 141 additions and 281 deletions

View File

@@ -60,7 +60,7 @@ class GfxGroupEditor : public SharedRom {
gfx::PaletteGroup palette_group_;
gfx::Bitmap* tile16_blockset_bmp_;
std::vector<Bytes> tile16_individual_data_;
std::vector<std::vector<uint8_t>> tile16_individual_data_;
std::vector<gfx::Bitmap> tile16_individual_;
gui::BitmapViewer gfx_group_viewer_;

View File

@@ -712,7 +712,7 @@ absl::Status GraphicsEditor::DrawClipboardImport() {
if (Button("Paste From Clipboard")) {
const char* text = ImGui::GetClipboardText();
if (text) {
const auto clipboard_data = Bytes(text, text + strlen(text));
const auto clipboard_data = std::vector<uint8_t>(text, text + strlen(text));
ImGui::MemFree((void*)text);
status_ = temp_rom_.LoadFromBytes(clipboard_data);
is_open_ = true;

View File

@@ -166,8 +166,8 @@ class GraphicsEditor : public SharedRom, public Editor {
MemoryEditor cgx_memory_editor_;
MemoryEditor col_memory_editor_;
PaletteEditor palette_editor_;
Bytes import_data_;
Bytes graphics_buffer_;
std::vector<uint8_t> import_data_;
std::vector<uint8_t> graphics_buffer_;
std::vector<uint8_t> decoded_cgx_;
std::vector<uint8_t> cgx_data_;
std::vector<uint8_t> extra_cgx_data_;

View File

@@ -85,7 +85,7 @@ class ScreenEditor : public SharedRom, public Editor {
bool copy_button_pressed = false;
bool paste_button_pressed = false;
Bytes all_gfx_;
std::vector<uint8_t> all_gfx_;
zelda3::screen::Inventory inventory_;
gfx::SnesPalette palette_;
gui::Canvas screen_canvas_;

View File

@@ -91,7 +91,7 @@ class Tile16Editor : public context::GfxContext, public SharedRom {
gui::Canvas transfer_canvas_;
gfx::Bitmap transfer_blockset_bmp_;
std::vector<Bytes> tile16_individual_data_;
std::vector<std::vector<uint8_t>> tile16_individual_data_;
std::vector<gfx::Bitmap> tile16_individual_;
std::vector<gfx::Bitmap> current_gfx_individual_;

View File

@@ -706,30 +706,6 @@ std::string MessageEditor::DisplayTextOverflowError(int pos, bool bank) {
return message;
}
// push_backs a command to the text field when the push_back command button is
// pressed or the command is double clicked in the list.
void MessageEditor::InsertCommandButton_Click_1() {
// InsertSelectedText(
// TextCommands[TextCommandList.SelectedIndex].GetParameterizedToken(
// (uint8_t)ParamsBox.HexValue));
}
// push_backs a special character to the text field when the push_back command
// button is pressed or the character is double clicked in the list.
void MessageEditor::InsertSpecialButton_Click() {
// InsertSelectedText(
// SpecialChars[SpecialsList.SelectedIndex].GetParameterizedToken());
}
void MessageEditor::InsertSelectedText(std::string str) {
int textboxPos = message_text_box_.selection_start;
from_form = true;
// message_text_box_.Text = message_text_box_.Text.Insert(textboxPos, str);
from_form = false;
message_text_box_.selection_start = textboxPos + str.size();
message_text_box_.Focus();
}
void MessageEditor::Delete() {
// Determine if any text is selected in the TextBox control.
if (message_text_box_.selection_length == 0) {

View File

@@ -109,10 +109,6 @@ class MessageEditor : public Editor, public SharedRom {
void DrawMessagePreview();
std::string DisplayTextOverflowError(int pos, bool bank);
void InsertCommandButton_Click_1();
void InsertSpecialButton_Click();
void InsertSelectedText(std::string str);
private:
bool skip_next = false;
bool from_form = false;
@@ -133,8 +129,8 @@ class MessageEditor : public Editor, public SharedRom {
MessageData current_message_;
Bytes font_gfx16_data_;
Bytes current_font_gfx16_data_;
std::vector<uint8_t> font_gfx16_data_;
std::vector<uint8_t> current_font_gfx16_data_;
gfx::Bitmap font_gfx_bitmap_;
gfx::Bitmap current_font_gfx16_bitmap_;

View File

@@ -132,7 +132,7 @@ absl::Status OverworldEditor::DrawToolset() {
static bool show_gfx_group = false;
static bool show_properties = false;
if (BeginTable("OWToolset", 23, kToolsetTableFlags, ImVec2(0, 0))) {
if (BeginTable("OWToolset", 22, kToolsetTableFlags, ImVec2(0, 0))) {
for (const auto &name : kToolsetColumnNames)
ImGui::TableSetupColumn(name.data());
@@ -243,19 +243,12 @@ absl::Status OverworldEditor::DrawToolset() {
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
TableNextColumn(); // Experimental
Checkbox("Experimental", &show_experimental);
TableNextColumn();
Checkbox("Properties", &show_properties);
ImGui::EndTable();
}
if (show_experimental) {
RETURN_IF_ERROR(DrawExperimentalModal())
}
if (show_tile16_editor_) {
// Create a table in ImGui for the Tile16 Editor
ImGui::Begin("Tile16 Editor", &show_tile16_editor_,
@@ -428,7 +421,7 @@ void OverworldEditor::DrawOverworldEdits() {
}
void OverworldEditor::RenderUpdatedMapBitmap(const ImVec2 &click_position,
const Bytes &tile_data) {
const std::vector<uint8_t> &tile_data) {
// Calculate the tile position relative to the current active map
constexpr int tile_size = 16; // Tile size is 16x16 pixels
@@ -987,8 +980,6 @@ void OverworldEditor::DrawOverworldSprites() {
}
}
// ----------------------------------------------------------------------------
absl::Status OverworldEditor::LoadGraphics() {
// Load the Link to the Past overworld.
RETURN_IF_ERROR(overworld_.Load(*rom()))
@@ -1011,7 +1002,7 @@ absl::Status OverworldEditor::LoadGraphics() {
// Loop through the tiles and copy their pixel data into separate vectors
for (int i = 0; i < 4096; i++) {
// Create a new vector for the pixel data of the current tile
Bytes tile_data(16 * 16, 0x00); // More efficient initialization
std::vector<uint8_t> tile_data(16 * 16, 0x00); // More efficient initialization
// Copy the pixel data for the current tile into the vector
for (int ty = 0; ty < 16; ty++) {
@@ -1127,55 +1118,6 @@ void OverworldEditor::DrawOverworldProperties() {
}
}
absl::Status OverworldEditor::DrawExperimentalModal() {
ImGui::Begin("Experimental", &show_experimental);
DrawDebugWindow();
gui::TextWithSeparators("PROTOTYPE OVERWORLD TILEMAP LOADER");
Text("Please provide two files:");
Text("One based on MAPn.DAT, which represents the overworld tilemap");
Text("One based on MAPDATn.DAT, which is the tile32 configurations.");
Text("Currently, loading CGX for this component is NOT supported. ");
Text("Please load a US ROM of LTTP (JP ROM support coming soon).");
Text(
"Once you've loaded the files, you can click the button below to load "
"the tilemap into the editor");
ImGui::InputText("##TilemapFile", &ow_tilemap_filename_);
SameLine();
gui::FileDialogPipeline(
"ImportTilemapsKey", ".DAT,.dat\0", "Tilemap Hex File", [this]() {
ow_tilemap_filename_ = ImGuiFileDialog::Instance()->GetFilePathName();
});
ImGui::InputText("##Tile32ConfigurationFile",
&tile32_configuration_filename_);
SameLine();
gui::FileDialogPipeline("ImportTile32Key", ".DAT,.dat\0", "Tile32 Hex File",
[this]() {
tile32_configuration_filename_ =
ImGuiFileDialog::Instance()->GetFilePathName();
});
if (Button("Load Prototype Overworld with ROM graphics")) {
RETURN_IF_ERROR(LoadGraphics())
all_gfx_loaded_ = true;
}
gui::TextWithSeparators("Configuration");
gui::InputHexShort("Tilemap File Offset (High)", &tilemap_file_offset_high_);
gui::InputHexShort("Tilemap File Offset (Low)", &tilemap_file_offset_low_);
gui::InputHexShort("LW Maps to Load", &light_maps_to_load_);
gui::InputHexShort("DW Maps to Load", &dark_maps_to_load_);
gui::InputHexShort("SP Maps to Load", &sp_maps_to_load_);
ImGui::End();
return absl::OkStatus();
}
absl::Status OverworldEditor::UpdateUsageStats() {
if (BeginTable("UsageStatsTable", 3, kOWEditFlags, ImVec2(0, 0))) {
TableSetupColumn("Entrances");
@@ -1226,16 +1168,6 @@ absl::Status OverworldEditor::UpdateUsageStats() {
return absl::OkStatus();
}
void OverworldEditor::CalculateUsageStats() {
absl::flat_hash_map<uint16_t, int> entrance_usage;
for (auto each_entrance : overworld_.entrances()) {
if (each_entrance.map_id_ < 0x40 + (current_world_ * 0x40) &&
each_entrance.map_id_ >= (current_world_ * 0x40)) {
entrance_usage[each_entrance.entrance_id_]++;
}
}
}
void OverworldEditor::DrawUsageGrid() {
// Create a grid of 8x8 squares
int totalSquares = 128;
@@ -1284,37 +1216,6 @@ void OverworldEditor::DrawUsageGrid() {
}
}
absl::Status OverworldEditor::LoadAnimatedMaps() {
int world_index = 0;
static std::vector<bool> animated_built(0x40, false);
if (!animated_built[world_index]) {
animated_maps_[world_index] = maps_bmp_[world_index];
auto &map = *overworld_.mutable_overworld_map(world_index);
map.DrawAnimatedTiles();
RETURN_IF_ERROR(map.BuildTileset());
RETURN_IF_ERROR(map.BuildTiles16Gfx(overworld_.tiles16().size()));
zelda3::OWBlockset blockset;
if (current_world_ == 0) {
blockset = overworld_.map_tiles().light_world;
} else if (current_world_ == 1) {
blockset = overworld_.map_tiles().dark_world;
} else {
blockset = overworld_.map_tiles().special_world;
}
RETURN_IF_ERROR(map.BuildBitmap(blockset));
RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap(
kOverworldMapSize, kOverworldMapSize, 0x200, map.bitmap_data(),
animated_maps_[world_index], *map.mutable_current_palette()));
animated_built[world_index] = true;
}
return absl::OkStatus();
}
// ----------------------------------------------------------------------------
void OverworldEditor::DrawDebugWindow() {
Text("Current Map: %d", current_map_);
Text("Current Tile16: %d", current_tile16_);

View File

@@ -37,11 +37,11 @@ static constexpr uint kTile8DisplayHeight = 64;
static constexpr float kInputFieldSize = 30.f;
static constexpr absl::string_view kToolsetColumnNames[] = {
"#undoTool", "#redoTool", "#separator2", "#zoomOutTool",
"#zoomInTool", "#separator", "#drawTool", "#history",
"#entranceTool", "#exitTool", "#itemTool", "#spriteTool",
"#transportTool", "#musicTool", "#separator3", "#tilemapTool",
"propertiesTool"};
"#undoTool", "#redoTool", "#separator2", "#zoomOutTool",
"#zoomInTool", "#separator", "#drawTool", "#history",
"#entranceTool", "#exitTool", "#itemTool", "#spriteTool",
"#transportTool", "#musicTool", "#separator3", "#tilemapTool",
"propertiesTool", "#separator4", "#experimentalTool"};
constexpr ImGuiTableFlags kOWMapFlags =
ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable;
@@ -156,7 +156,7 @@ class OverworldEditor : public Editor,
void DrawOverworldMaps();
void DrawOverworldEdits();
void RenderUpdatedMapBitmap(const ImVec2& click_position,
const Bytes& tile_data);
const std::vector<uint8_t>& tile_data);
void CheckForOverworldEdits();
void CheckForSelectRectangle();
absl::Status CheckForCurrentMap();
@@ -176,13 +176,9 @@ class OverworldEditor : public Editor,
void DrawOverworldProperties();
absl::Status DrawExperimentalModal();
absl::Status UpdateUsageStats();
void DrawUsageGrid();
void CalculateUsageStats();
absl::Status LoadAnimatedMaps();
void DrawDebugWindow();
auto gfx_group_editor() const { return gfx_group_editor_; }
@@ -204,12 +200,14 @@ class OverworldEditor : public Editor,
int current_world_ = 0;
int current_map_ = 0;
int current_parent_ = 0;
int current_entrance_id_ = 0;
int current_exit_id_ = 0;
int current_item_id_ = 0;
int current_sprite_id_ = 0;
int game_state_ = 1;
int current_tile16_ = 0;
int selected_tile_ = 0;
int current_blockset_ = 0;
int selected_entrance_ = 0;
int selected_usage_map_ = 0xFFFF;
@@ -220,12 +218,6 @@ class OverworldEditor : public Editor,
char message_id_[5] = "";
char staticgfx[16];
uint32_t tilemap_file_offset_high_ = 0;
uint32_t tilemap_file_offset_low_ = 0;
uint32_t light_maps_to_load_ = 0x51;
uint32_t dark_maps_to_load_ = 0x2A;
uint32_t sp_maps_to_load_ = 0x07;
bool opt_enable_grid = true;
bool all_gfx_loaded_ = false;
bool map_blockset_loaded_ = false;
@@ -236,29 +228,20 @@ class OverworldEditor : public Editor,
bool show_gfx_group_editor_ = false;
bool overworld_canvas_fullscreen_ = false;
bool middle_mouse_dragging_ = false;
bool is_dragging_entity_ = false;
zelda3::OverworldEntity* dragged_entity_;
zelda3::OverworldEntity* current_entity_;
int current_entrance_id_ = 0;
zelda3::overworld::OverworldEntrance current_entrance_;
int current_exit_id_ = 0;
zelda3::overworld::OverworldExit current_exit_;
int current_item_id_ = 0;
zelda3::overworld::OverworldItem current_item_;
int current_sprite_id_ = 0;
zelda3::Sprite current_sprite_;
bool show_experimental = false;
std::string ow_tilemap_filename_ = "";
std::string tile32_configuration_filename_ = "";
Bytes selected_tile_data_;
std::vector<Bytes> tile16_individual_data_;
std::vector<uint8_t> selected_tile_data_;
std::vector<std::vector<uint8_t>> tile16_individual_data_;
std::vector<gfx::Bitmap> tile16_individual_;
std::vector<Bytes> tile8_individual_data_;
std::vector<std::vector<uint8_t>> tile8_individual_data_;
std::vector<gfx::Bitmap> tile8_individual_;
Tile16Editor tile16_editor_;
@@ -287,7 +270,6 @@ class OverworldEditor : public Editor,
gfx::BitmapTable maps_bmp_;
gfx::BitmapTable current_graphics_set_;
gfx::BitmapTable sprite_previews_;
gfx::BitmapTable animated_maps_;
zelda3::OWBlockset refresh_blockset_;

View File

@@ -122,7 +122,7 @@ absl::Status OverworldEditor::RefreshTile16Blockset() {
std::launch::async,
[&](int index) {
// Create a new vector for the pixel data of the current tile
Bytes tile_data(16 * 16, 0x00); // More efficient initialization
std::vector<uint8_t> tile_data(16 * 16, 0x00); // More efficient initialization
// Copy the pixel data for the current tile into the vector
for (int ty = 0; ty < 16; ty++) {