unload rom assets on file -> close

This commit is contained in:
scawful
2024-02-01 01:05:57 -05:00
parent 8d2cd60b5f
commit 427b7f6f41
5 changed files with 43 additions and 39 deletions

View File

@@ -343,7 +343,10 @@ void MasterEditor::DrawFileMenu() {
if (rom()->is_loaded()) { if (rom()->is_loaded()) {
MENU_ITEM("Reload") { status_ = rom()->Reload(); } MENU_ITEM("Reload") { status_ = rom()->Reload(); }
MENU_ITEM("Close") { status_ = rom()->Close(); } MENU_ITEM("Close") {
status_ = rom()->Close();
rom_assets_loaded_ = false;
}
} }
ImGui::Separator(); ImGui::Separator();

View File

@@ -293,8 +293,6 @@ absl::Status Tile16Editor::UpdateTransferTileCanvas() {
return absl::OkStatus(); return absl::OkStatus();
} }
using core::TaskManager;
absl::Status Tile16Editor::InitBlockset( absl::Status Tile16Editor::InitBlockset(
const gfx::Bitmap& tile16_blockset_bmp, gfx::Bitmap current_gfx_bmp, const gfx::Bitmap& tile16_blockset_bmp, gfx::Bitmap current_gfx_bmp,
const std::vector<gfx::Bitmap>& tile16_individual, const std::vector<gfx::Bitmap>& tile16_individual,
@@ -310,7 +308,6 @@ absl::Status Tile16Editor::InitBlockset(
absl::Status Tile16Editor::LoadTile8() { absl::Status Tile16Editor::LoadTile8() {
current_gfx_individual_.reserve(1024); current_gfx_individual_.reserve(1024);
// std::function<void(int)> taskFunc = [&](int index) {
for (int index = 0; index < 1024; index++) { for (int index = 0; index < 1024; index++) {
std::vector<uint8_t> tile_data(0x40, 0x00); std::vector<uint8_t> tile_data(0x40, 0x00);
@@ -346,20 +343,8 @@ absl::Status Tile16Editor::LoadTile8() {
rom()->palette_group("ow_main")[0], current_palette_); rom()->palette_group("ow_main")[0], current_palette_);
rom()->RenderBitmap(&current_gfx_individual_[index]); rom()->RenderBitmap(&current_gfx_individual_[index]);
} }
// };
// // Create the task manager
// static bool started = false;
// if (!started) {
// task_manager_ = TaskManager<std::function<void(int)>>(1024, 60);
// started = true;
// }
// task_manager_.ExecuteTasks(taskFunc);
// if (task_manager_.IsTaskComplete()) {
// // All tasks are complete
map_blockset_loaded_ = true; map_blockset_loaded_ = true;
// }
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -52,6 +52,7 @@ absl::Status OverworldEditor::Update() {
} else if (!rom()->is_loaded() && all_gfx_loaded_) { } else if (!rom()->is_loaded() && all_gfx_loaded_) {
// TODO: Destroy the overworld graphics canvas. // TODO: Destroy the overworld graphics canvas.
Shutdown(); Shutdown();
overworld_.Destroy();
all_gfx_loaded_ = false; all_gfx_loaded_ = false;
map_blockset_loaded_ = false; map_blockset_loaded_ = false;
} }
@@ -177,43 +178,37 @@ absl::Status OverworldEditor::DrawToolset() {
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Selectable(ICON_MD_DOOR_FRONT, if (ImGui::Selectable(ICON_MD_DOOR_FRONT,
current_mode == EditingMode::ENTRANCES)) { current_mode == EditingMode::ENTRANCES))
current_mode = EditingMode::ENTRANCES; current_mode = EditingMode::ENTRANCES;
}
HOVER_HINT("Entrances") HOVER_HINT("Entrances")
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Selectable(ICON_MD_DOOR_BACK, if (ImGui::Selectable(ICON_MD_DOOR_BACK,
current_mode == EditingMode::EXITS)) { current_mode == EditingMode::EXITS))
current_mode = EditingMode::EXITS; current_mode = EditingMode::EXITS;
}
HOVER_HINT("Exits") HOVER_HINT("Exits")
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Selectable(ICON_MD_GRASS, current_mode == EditingMode::ITEMS)) { if (ImGui::Selectable(ICON_MD_GRASS, current_mode == EditingMode::ITEMS))
current_mode = EditingMode::ITEMS; current_mode = EditingMode::ITEMS;
}
HOVER_HINT("Items") HOVER_HINT("Items")
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Selectable(ICON_MD_PEST_CONTROL_RODENT, if (ImGui::Selectable(ICON_MD_PEST_CONTROL_RODENT,
current_mode == EditingMode::SPRITES)) { current_mode == EditingMode::SPRITES))
current_mode = EditingMode::SPRITES; current_mode = EditingMode::SPRITES;
}
HOVER_HINT("Sprites") HOVER_HINT("Sprites")
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Selectable(ICON_MD_ADD_LOCATION, if (ImGui::Selectable(ICON_MD_ADD_LOCATION,
current_mode == EditingMode::TRANSPORTS)) { current_mode == EditingMode::TRANSPORTS))
current_mode = EditingMode::TRANSPORTS; current_mode = EditingMode::TRANSPORTS;
}
HOVER_HINT("Transports") HOVER_HINT("Transports")
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Selectable(ICON_MD_MUSIC_NOTE, if (ImGui::Selectable(ICON_MD_MUSIC_NOTE,
current_mode == EditingMode::MUSIC)) { current_mode == EditingMode::MUSIC))
current_mode = EditingMode::MUSIC; current_mode = EditingMode::MUSIC;
}
HOVER_HINT("Music") HOVER_HINT("Music")
TableNextColumn(); TableNextColumn();
@@ -786,7 +781,7 @@ void OverworldEditor::DrawAreaGraphics() {
palette_ = overworld_.AreaPalette(); palette_ = overworld_.AreaPalette();
gfx::Bitmap bmp; gfx::Bitmap bmp;
gui::BuildAndRenderBitmapPipeline( gui::BuildAndRenderBitmapPipeline(
0x80, 0x200, 0x08, overworld_.AreaGraphics(), *rom(), bmp, palette_); 0x80, 0x200, 0x08, overworld_.current_graphics(), *rom(), bmp, palette_);
current_graphics_set_[current_map_] = bmp; current_graphics_set_[current_map_] = bmp;
} }
} }
@@ -970,7 +965,7 @@ bool DrawOverworldEntrancePopup(zelda3::OverworldEntrance &entrance) {
void OverworldEditor::DrawOverworldEntrances(ImVec2 canvas_p0, ImVec2 scrolling, void OverworldEditor::DrawOverworldEntrances(ImVec2 canvas_p0, ImVec2 scrolling,
bool holes) { bool holes) {
int i = 0; int i = 0;
for (auto &each : overworld_.Entrances()) { for (auto &each : overworld_.entrances()) {
if (each.map_id_ < 0x40 + (current_world_ * 0x40) && if (each.map_id_ < 0x40 + (current_world_ * 0x40) &&
each.map_id_ >= (current_world_ * 0x40) && !each.deleted) { each.map_id_ >= (current_world_ * 0x40) && !each.deleted) {
// Make this yellow // Make this yellow
@@ -1017,8 +1012,8 @@ void OverworldEditor::DrawOverworldEntrances(ImVec2 canvas_p0, ImVec2 scrolling,
ImGui::OpenPopup("Entrance Inserter"); ImGui::OpenPopup("Entrance Inserter");
} else { } else {
if (entrance_internal::DrawOverworldEntrancePopup( if (entrance_internal::DrawOverworldEntrancePopup(
overworld_.Entrances()[current_entrance_id_])) { overworld_.entrances()[current_entrance_id_])) {
overworld_.Entrances()[current_entrance_id_] = current_entrance_; overworld_.entrances()[current_entrance_id_] = current_entrance_;
} }
} }
} }
@@ -1567,7 +1562,7 @@ absl::Status OverworldEditor::LoadGraphics() {
// Create the area graphics image // Create the area graphics image
gui::BuildAndRenderBitmapPipeline(0x80, 0x200, 0x40, gui::BuildAndRenderBitmapPipeline(0x80, 0x200, 0x40,
overworld_.AreaGraphics(), *rom(), overworld_.current_graphics(), *rom(),
current_gfx_bmp_, palette_); current_gfx_bmp_, palette_);
// Create the tile16 blockset image // Create the tile16 blockset image
@@ -1784,11 +1779,11 @@ absl::Status OverworldEditor::UpdateUsageStats() {
for (int i = 0; i < 0x81; i++) { for (int i = 0; i < 0x81; i++) {
std::string str = absl::StrFormat("%#x", i); std::string str = absl::StrFormat("%#x", i);
if (ImGui::Selectable(str.c_str(), selected_entrance_ == i, if (ImGui::Selectable(str.c_str(), selected_entrance_ == i,
overworld_.Entrances().at(i).deleted overworld_.entrances().at(i).deleted
? ImGuiSelectableFlags_Disabled ? ImGuiSelectableFlags_Disabled
: 0)) { : 0)) {
selected_entrance_ = i; selected_entrance_ = i;
selected_usage_map_ = overworld_.Entrances().at(i).map_id_; selected_usage_map_ = overworld_.entrances().at(i).map_id_;
properties_canvas_.set_highlight_tile_id(selected_usage_map_); properties_canvas_.set_highlight_tile_id(selected_usage_map_);
} }
} }
@@ -1805,7 +1800,7 @@ absl::Status OverworldEditor::UpdateUsageStats() {
void OverworldEditor::CalculateUsageStats() { void OverworldEditor::CalculateUsageStats() {
absl::flat_hash_map<uint16_t, int> entrance_usage; absl::flat_hash_map<uint16_t, int> entrance_usage;
for (auto each_entrance : overworld_.Entrances()) { for (auto each_entrance : overworld_.entrances()) {
if (each_entrance.map_id_ < 0x40 + (current_world_ * 0x40) && if (each_entrance.map_id_ < 0x40 + (current_world_ * 0x40) &&
each_entrance.map_id_ >= (current_world_ * 0x40)) { each_entrance.map_id_ >= (current_world_ * 0x40)) {
entrance_usage[each_entrance.entrance_id_]++; entrance_usage[each_entrance.entrance_id_]++;

View File

@@ -496,6 +496,18 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
absl::Status SaveMapProperties(); absl::Status SaveMapProperties();
absl::Status LoadPrototype(ROM &rom_, const std::string &tilemap_filename); absl::Status LoadPrototype(ROM &rom_, const std::string &tilemap_filename);
void Destroy() {
for (auto &map : overworld_maps_) {
map.Destroy();
}
overworld_maps_.clear();
all_entrances_.clear();
all_exits_.clear();
all_items_.clear();
all_sprites_.clear();
is_loaded_ = false;
}
int current_world_ = 0; int current_world_ = 0;
int GetTileFromPosition(ImVec2 position) const { int GetTileFromPosition(ImVec2 position) const {
if (current_world_ == 0) { if (current_world_ == 0) {
@@ -516,10 +528,10 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
auto Sprites(int state) const { return all_sprites_[state]; } auto Sprites(int state) const { return all_sprites_[state]; }
auto mutable_sprites(int state) { return &all_sprites_[state]; } auto mutable_sprites(int state) { return &all_sprites_[state]; }
auto AreaGraphics() const { auto current_graphics() const {
return overworld_maps_[current_map_].current_graphics(); return overworld_maps_[current_map_].current_graphics();
} }
auto &Entrances() { return all_entrances_; } auto &entrances() { return all_entrances_; }
auto mutable_entrances() { return &all_entrances_; } auto mutable_entrances() { return &all_entrances_; }
auto &holes() { return all_holes_; } auto &holes() { return all_holes_; }
auto mutable_holes() { return &all_holes_; } auto mutable_holes() { return &all_holes_; }
@@ -529,7 +541,9 @@ class Overworld : public SharedROM, public core::ExperimentFlags {
auto AreaPaletteById(int id) const { auto AreaPaletteById(int id) const {
return overworld_maps_[id].current_palette(); return overworld_maps_[id].current_palette();
} }
auto BitmapData() const { return overworld_maps_[current_map_].bitmap_data(); } auto BitmapData() const {
return overworld_maps_[current_map_].bitmap_data();
}
auto Tile16Blockset() const { auto Tile16Blockset() const {
return overworld_maps_[current_map_].current_tile16_blockset(); return overworld_maps_[current_map_].current_tile16_blockset();
} }

View File

@@ -91,6 +91,13 @@ class OverworldMap : public GfxContext {
large_map_ = false; large_map_ = false;
} }
void Destroy() {
current_blockset_.clear();
current_gfx_.clear();
bitmap_data_.clear();
tiles16_.clear();
}
private: private:
void LoadAreaInfo(); void LoadAreaInfo();