refactor Tile16Editor: improve LoadTile8 method with asynchronous tile data loading
This commit is contained in:
@@ -1,19 +1,13 @@
|
|||||||
#include "tile16_editor.h"
|
#include "tile16_editor.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <future>
|
||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "absl/status/statusor.h"
|
|
||||||
#include "app/core/platform/file_dialog.h"
|
#include "app/core/platform/file_dialog.h"
|
||||||
#include "app/core/platform/renderer.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/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.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/canvas.h"
|
||||||
#include "app/gui/icons.h"
|
|
||||||
#include "app/gui/input.h"
|
#include "app/gui/input.h"
|
||||||
#include "app/gui/style.h"
|
#include "app/gui/style.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
@@ -33,7 +27,6 @@ using ImGui::BeginTabItem;
|
|||||||
using ImGui::BeginTable;
|
using ImGui::BeginTable;
|
||||||
using ImGui::Button;
|
using ImGui::Button;
|
||||||
using ImGui::Checkbox;
|
using ImGui::Checkbox;
|
||||||
using ImGui::Combo;
|
|
||||||
using ImGui::EndChild;
|
using ImGui::EndChild;
|
||||||
using ImGui::EndMenu;
|
using ImGui::EndMenu;
|
||||||
using ImGui::EndMenuBar;
|
using ImGui::EndMenuBar;
|
||||||
@@ -49,9 +42,9 @@ using ImGui::TableSetupColumn;
|
|||||||
using ImGui::Text;
|
using ImGui::Text;
|
||||||
|
|
||||||
absl::Status Tile16Editor::InitBlockset(
|
absl::Status Tile16Editor::InitBlockset(
|
||||||
const gfx::Bitmap& tile16_blockset_bmp, const gfx::Bitmap& current_gfx_bmp,
|
const gfx::Bitmap &tile16_blockset_bmp, const gfx::Bitmap ¤t_gfx_bmp,
|
||||||
const std::vector<gfx::Bitmap>& tile16_individual,
|
const std::vector<gfx::Bitmap> &tile16_individual,
|
||||||
std::array<uint8_t, 0x200>& all_tiles_types) {
|
std::array<uint8_t, 0x200> &all_tiles_types) {
|
||||||
all_tiles_types_ = all_tiles_types;
|
all_tiles_types_ = all_tiles_types;
|
||||||
tile16_blockset_bmp_ = tile16_blockset_bmp;
|
tile16_blockset_bmp_ = tile16_blockset_bmp;
|
||||||
tile16_individual_ = tile16_individual;
|
tile16_individual_ = tile16_individual;
|
||||||
@@ -280,42 +273,52 @@ absl::Status Tile16Editor::DrawTileEditControls() {
|
|||||||
|
|
||||||
absl::Status Tile16Editor::LoadTile8() {
|
absl::Status Tile16Editor::LoadTile8() {
|
||||||
auto ow_main_pal_group = rom()->palette_group().overworld_main;
|
auto ow_main_pal_group = rom()->palette_group().overworld_main;
|
||||||
|
|
||||||
current_gfx_individual_.reserve(1024);
|
current_gfx_individual_.reserve(1024);
|
||||||
|
|
||||||
|
std::vector<std::future<std::array<uint8_t, 0x40>>> futures;
|
||||||
|
|
||||||
for (int index = 0; index < 1024; index++) {
|
for (int index = 0; index < 1024; index++) {
|
||||||
std::vector<uint8_t> tile_data(0x40, 0x00);
|
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
|
||||||
|
|
||||||
// Copy the pixel data for the current tile into the vector
|
// Calculate the position in the tile data vector
|
||||||
for (int ty = 0; ty < 8; ty++) {
|
int position = tx + (ty * 0x08);
|
||||||
for (int tx = 0; tx < 8; tx++) {
|
|
||||||
// Current Gfx Data is 16 sheets of 8x8 tiles ordered 16 wide by 4 tall
|
|
||||||
|
|
||||||
// Calculate the position in the tile data vector
|
// Calculate the position in the current gfx data
|
||||||
int position = tx + (ty * 0x08);
|
int num_columns = current_gfx_bmp_.width() / 8;
|
||||||
|
int x = (index % num_columns) * 8 + tx;
|
||||||
|
int y = (index / num_columns) * 8 + ty;
|
||||||
|
int gfx_position = x + (y * 0x100);
|
||||||
|
|
||||||
// Calculate the position in the current gfx data
|
// Get the pixel value from the current gfx data
|
||||||
int num_columns = current_gfx_bmp_.width() / 8;
|
uint8_t value = current_gfx_bmp_.data()[gfx_position];
|
||||||
int x = (index % num_columns) * 8 + tx;
|
|
||||||
int y = (index / num_columns) * 8 + ty;
|
|
||||||
int gfx_position = x + (y * 0x100);
|
|
||||||
|
|
||||||
// Get the pixel value from the current gfx data
|
if (value & 0x80) {
|
||||||
uint8_t value = current_gfx_bmp_.data()[gfx_position];
|
value -= 0x88;
|
||||||
|
}
|
||||||
|
|
||||||
if (value & 0x80) {
|
tile_data[position] = value;
|
||||||
value -= 0x88;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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_.emplace_back();
|
||||||
current_gfx_individual_[index].Create(0x08, 0x08, 0x08, tile_data);
|
auto &tile_bitmap = current_gfx_individual_.back();
|
||||||
RETURN_IF_ERROR(current_gfx_individual_[index].ApplyPaletteWithTransparent(
|
tile_bitmap.Create(0x08, 0x08, 0x08, tile_data);
|
||||||
|
RETURN_IF_ERROR(tile_bitmap.ApplyPaletteWithTransparent(
|
||||||
ow_main_pal_group[0], current_palette_));
|
ow_main_pal_group[0], current_palette_));
|
||||||
Renderer::GetInstance().RenderBitmap(¤t_gfx_individual_[index]);
|
Renderer::GetInstance().RenderBitmap(&tile_bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
map_blockset_loaded_ = true;
|
map_blockset_loaded_ = true;
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ namespace editor {
|
|||||||
*/
|
*/
|
||||||
class Tile16Editor : public gfx::GfxContext, public SharedRom {
|
class Tile16Editor : public gfx::GfxContext, public SharedRom {
|
||||||
public:
|
public:
|
||||||
absl::Status InitBlockset(const gfx::Bitmap& tile16_blockset_bmp,
|
absl::Status InitBlockset(const gfx::Bitmap &tile16_blockset_bmp,
|
||||||
const gfx::Bitmap& current_gfx_bmp,
|
const gfx::Bitmap ¤t_gfx_bmp,
|
||||||
const std::vector<gfx::Bitmap>& tile16_individual,
|
const std::vector<gfx::Bitmap> &tile16_individual,
|
||||||
std::array<uint8_t, 0x200>& all_tiles_types);
|
std::array<uint8_t, 0x200> &all_tiles_types);
|
||||||
|
|
||||||
absl::Status Update();
|
absl::Status Update();
|
||||||
absl::Status DrawMenu();
|
absl::Status DrawMenu();
|
||||||
@@ -48,7 +48,11 @@ class Tile16Editor : public gfx::GfxContext, public SharedRom {
|
|||||||
bool map_blockset_loaded_ = false;
|
bool map_blockset_loaded_ = false;
|
||||||
bool transfer_started_ = false;
|
bool transfer_started_ = false;
|
||||||
bool transfer_blockset_loaded_ = 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_tile16_ = 0;
|
||||||
int current_tile8_ = 0;
|
int current_tile8_ = 0;
|
||||||
uint8_t current_palette_ = 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<uint32_t> notify_tile16;
|
||||||
core::NotifyValue<uint8_t> notify_palette;
|
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_;
|
std::array<uint8_t, 0x200> all_tiles_types_;
|
||||||
|
|
||||||
// Tile16 blockset for selecting the tile to edit
|
// Tile16 blockset for selecting the tile to edit
|
||||||
@@ -100,4 +98,5 @@ class Tile16Editor : public gfx::GfxContext, public SharedRom {
|
|||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|
||||||
#endif // YAZE_APP_EDITOR_TILE16EDITOR_H
|
#endif // YAZE_APP_EDITOR_TILE16EDITOR_H
|
||||||
|
|||||||
Reference in New Issue
Block a user