refactor Tile16Editor: improve LoadTile8 method with asynchronous tile data loading
This commit is contained in:
@@ -1,19 +1,13 @@
|
||||
#include "tile16_editor.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <future>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "app/core/platform/renderer.h"
|
||||
#include "app/editor/editor.h"
|
||||
#include "app/editor/graphics/palette_editor.h"
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/gfx/snes_palette.h"
|
||||
#include "app/gfx/snes_tile.h"
|
||||
#include "app/gfx/tilesheet.h"
|
||||
#include "app/gui/canvas.h"
|
||||
#include "app/gui/icons.h"
|
||||
#include "app/gui/input.h"
|
||||
#include "app/gui/style.h"
|
||||
#include "app/rom.h"
|
||||
@@ -33,7 +27,6 @@ using ImGui::BeginTabItem;
|
||||
using ImGui::BeginTable;
|
||||
using ImGui::Button;
|
||||
using ImGui::Checkbox;
|
||||
using ImGui::Combo;
|
||||
using ImGui::EndChild;
|
||||
using ImGui::EndMenu;
|
||||
using ImGui::EndMenuBar;
|
||||
@@ -280,16 +273,18 @@ absl::Status Tile16Editor::DrawTileEditControls() {
|
||||
|
||||
absl::Status Tile16Editor::LoadTile8() {
|
||||
auto ow_main_pal_group = rom()->palette_group().overworld_main;
|
||||
|
||||
current_gfx_individual_.reserve(1024);
|
||||
|
||||
for (int index = 0; index < 1024; index++) {
|
||||
std::vector<uint8_t> tile_data(0x40, 0x00);
|
||||
std::vector<std::future<std::array<uint8_t, 0x40>>> futures;
|
||||
|
||||
for (int index = 0; index < 1024; index++) {
|
||||
auto task_function = [&]() {
|
||||
std::array<uint8_t, 0x40> tile_data;
|
||||
// Copy the pixel data for the current tile into the vector
|
||||
for (int ty = 0; ty < 8; ty++) {
|
||||
for (int tx = 0; tx < 8; tx++) {
|
||||
// Current Gfx Data is 16 sheets of 8x8 tiles ordered 16 wide by 4 tall
|
||||
// Current Gfx Data is 16 sheets of 8x8 tiles ordered 16 wide by 4
|
||||
// tall
|
||||
|
||||
// Calculate the position in the tile data vector
|
||||
int position = tx + (ty * 0x08);
|
||||
@@ -310,12 +305,20 @@ absl::Status Tile16Editor::LoadTile8() {
|
||||
tile_data[position] = value;
|
||||
}
|
||||
}
|
||||
return tile_data;
|
||||
};
|
||||
futures.emplace_back(std::async(std::launch::async, task_function));
|
||||
}
|
||||
|
||||
for (auto &future : futures) {
|
||||
future.wait();
|
||||
auto tile_data = future.get();
|
||||
current_gfx_individual_.emplace_back();
|
||||
current_gfx_individual_[index].Create(0x08, 0x08, 0x08, tile_data);
|
||||
RETURN_IF_ERROR(current_gfx_individual_[index].ApplyPaletteWithTransparent(
|
||||
auto &tile_bitmap = current_gfx_individual_.back();
|
||||
tile_bitmap.Create(0x08, 0x08, 0x08, tile_data);
|
||||
RETURN_IF_ERROR(tile_bitmap.ApplyPaletteWithTransparent(
|
||||
ow_main_pal_group[0], current_palette_));
|
||||
Renderer::GetInstance().RenderBitmap(¤t_gfx_individual_[index]);
|
||||
Renderer::GetInstance().RenderBitmap(&tile_bitmap);
|
||||
}
|
||||
|
||||
map_blockset_loaded_ = true;
|
||||
|
||||
@@ -48,7 +48,11 @@ class Tile16Editor : public gfx::GfxContext, public SharedRom {
|
||||
bool map_blockset_loaded_ = false;
|
||||
bool transfer_started_ = false;
|
||||
bool transfer_blockset_loaded_ = false;
|
||||
bool x_flip = false;
|
||||
bool y_flip = false;
|
||||
bool priority_tile = false;
|
||||
|
||||
int tile_size;
|
||||
int current_tile16_ = 0;
|
||||
int current_tile8_ = 0;
|
||||
uint8_t current_palette_ = 0;
|
||||
@@ -56,12 +60,6 @@ class Tile16Editor : public gfx::GfxContext, public SharedRom {
|
||||
core::NotifyValue<uint32_t> notify_tile16;
|
||||
core::NotifyValue<uint8_t> notify_palette;
|
||||
|
||||
// Various options for the Tile16 Editor
|
||||
bool x_flip;
|
||||
bool y_flip;
|
||||
bool priority_tile;
|
||||
int tile_size;
|
||||
|
||||
std::array<uint8_t, 0x200> all_tiles_types_;
|
||||
|
||||
// Tile16 blockset for selecting the tile to edit
|
||||
@@ -100,4 +98,5 @@ class Tile16Editor : public gfx::GfxContext, public SharedRom {
|
||||
|
||||
} // namespace editor
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APP_EDITOR_TILE16EDITOR_H
|
||||
|
||||
Reference in New Issue
Block a user