Replace BuildAndRenderBitmap with Rom::CreateAndRenderBitmap

This commit is contained in:
scawful
2024-04-14 15:02:56 -05:00
parent 5953e58bd4
commit 81e5659c1f
7 changed files with 46 additions and 48 deletions

View File

@@ -353,9 +353,9 @@ absl::Status Tile16Editor::UpdateTransferTileCanvas() {
palette_ = transfer_overworld_.AreaPalette(); palette_ = transfer_overworld_.AreaPalette();
// Create the tile16 blockset image // Create the tile16 blockset image
gui::BuildAndRenderBitmapPipeline(0x80, 0x2000, 0x80, RETURN_IF_ERROR(rom()->CreateAndRenderBitmap(0x80, 0x2000, 0x80,
transfer_overworld_.Tile16Blockset(), transfer_overworld_.Tile16Blockset(),
*rom(), transfer_blockset_bmp_, palette_); transfer_blockset_bmp_, palette_));
transfer_blockset_loaded_ = true; transfer_blockset_loaded_ = true;
} }

View File

@@ -790,15 +790,14 @@ void OverworldEditor::DrawTile8Selector() {
graphics_bin_canvas_.DrawOverlay(); graphics_bin_canvas_.DrawOverlay();
} }
void OverworldEditor::DrawAreaGraphics() { absl::Status OverworldEditor::DrawAreaGraphics() {
if (overworld_.is_loaded()) { if (overworld_.is_loaded()) {
if (current_graphics_set_.count(current_map_) == 0) { if (current_graphics_set_.count(current_map_) == 0) {
overworld_.set_current_map(current_map_); overworld_.set_current_map(current_map_);
palette_ = overworld_.AreaPalette(); palette_ = overworld_.AreaPalette();
gfx::Bitmap bmp; gfx::Bitmap bmp;
gui::BuildAndRenderBitmapPipeline(0x80, 0x200, 0x08, RETURN_IF_ERROR(rom()->CreateAndRenderBitmap(
overworld_.current_graphics(), *rom(), 0x80, 0x200, 0x08, overworld_.current_graphics(), bmp, palette_));
bmp, palette_);
current_graphics_set_[current_map_] = bmp; current_graphics_set_[current_map_] = bmp;
} }
} }
@@ -818,6 +817,7 @@ void OverworldEditor::DrawAreaGraphics() {
} }
ImGui::EndChild(); ImGui::EndChild();
ImGui::EndGroup(); ImGui::EndGroup();
return absl::OkStatus();
} }
absl::Status OverworldEditor::DrawTileSelector() { absl::Status OverworldEditor::DrawTileSelector() {
@@ -863,9 +863,8 @@ bool IsMouseHoveringOverEntity(const zelda3::OverworldEntity &entity,
return false; return false;
} }
void MoveEntityOnGrid(zelda3::OverworldEntity *entity, void MoveEntityOnGrid(zelda3::OverworldEntity *entity, ImVec2 canvas_p0,
ImVec2 canvas_p0, ImVec2 scrolling, ImVec2 scrolling, bool free_movement = false) {
bool free_movement = false) {
// Get the mouse position relative to the canvas // Get the mouse position relative to the canvas
const ImGuiIO &io = ImGui::GetIO(); const ImGuiIO &io = ImGui::GetIO();
const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y); const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y);
@@ -884,9 +883,8 @@ void MoveEntityOnGrid(zelda3::OverworldEntity *entity,
entity->set_y(new_y); entity->set_y(new_y);
} }
void HandleEntityDragging(zelda3::OverworldEntity *entity, void HandleEntityDragging(zelda3::OverworldEntity *entity, ImVec2 canvas_p0,
ImVec2 canvas_p0, ImVec2 scrolling, ImVec2 scrolling, bool &is_dragging_entity,
bool &is_dragging_entity,
zelda3::OverworldEntity *&dragged_entity, zelda3::OverworldEntity *&dragged_entity,
zelda3::OverworldEntity *&current_entity, zelda3::OverworldEntity *&current_entity,
bool free_movement = false) { bool free_movement = false) {
@@ -1609,14 +1607,12 @@ absl::Status OverworldEditor::LoadGraphics() {
palette_ = overworld_.AreaPalette(); palette_ = overworld_.AreaPalette();
// Create the area graphics image // Create the area graphics image
gui::BuildAndRenderBitmapPipeline(0x80, 0x200, 0x40, rom()->CreateAndRenderBitmap(0x80, 0x200, 0x40, overworld_.current_graphics(),
overworld_.current_graphics(), *rom(), current_gfx_bmp_, palette_);
current_gfx_bmp_, palette_);
// Create the tile16 blockset image // Create the tile16 blockset image
gui::BuildAndRenderBitmapPipeline(0x80, 0x2000, 0x08, rom()->CreateAndRenderBitmap(0x80, 0x2000, 0x08, overworld_.Tile16Blockset(),
overworld_.Tile16Blockset(), *rom(), tile16_blockset_bmp_, palette_);
tile16_blockset_bmp_, palette_);
map_blockset_loaded_ = true; map_blockset_loaded_ = true;
// Copy the tile16 data into individual tiles. // Copy the tile16 data into individual tiles.
@@ -1644,18 +1640,17 @@ absl::Status OverworldEditor::LoadGraphics() {
// Render the bitmaps of each tile. // Render the bitmaps of each tile.
for (int id = 0; id < 4096; id++) { for (int id = 0; id < 4096; id++) {
tile16_individual_.emplace_back(); tile16_individual_.emplace_back();
gui::BuildAndRenderBitmapPipeline(0x10, 0x10, 0x80, RETURN_IF_ERROR(rom()->CreateAndRenderBitmap(
tile16_individual_data_[id], *rom(), 0x10, 0x10, 0x80, tile16_individual_data_[id], tile16_individual_[id],
tile16_individual_[id], palette_); palette_));
} }
// Render the overworld maps loaded from the ROM. // Render the overworld maps loaded from the ROM.
for (int i = 0; i < zelda3::overworld::kNumOverworldMaps; ++i) { for (int i = 0; i < zelda3::overworld::kNumOverworldMaps; ++i) {
overworld_.set_current_map(i); overworld_.set_current_map(i);
auto palette = overworld_.AreaPalette(); auto palette = overworld_.AreaPalette();
gui::BuildAndRenderBitmapPipeline(0x200, 0x200, 0x200, RETURN_IF_ERROR(rom()->CreateAndRenderBitmap(
overworld_.BitmapData(), *rom(), 0x200, 0x200, 0x200, overworld_.BitmapData(), maps_bmp_[i], palette));
maps_bmp_[i], palette);
} }
if (flags()->overworld.kDrawOverworldSprites) { if (flags()->overworld.kDrawOverworldSprites) {
@@ -1675,9 +1670,9 @@ absl::Status OverworldEditor::RefreshTile16Blockset() {
overworld_.set_current_map(current_map_); overworld_.set_current_map(current_map_);
palette_ = overworld_.AreaPalette(); palette_ = overworld_.AreaPalette();
// Create the tile16 blockset image // Create the tile16 blockset image
gui::BuildAndRenderBitmapPipeline(0x80, 0x2000, 0x08, RETURN_IF_ERROR(rom()->CreateAndRenderBitmap(0x80, 0x2000, 0x08,
overworld_.Tile16Blockset(), *rom(), overworld_.Tile16Blockset(),
tile16_blockset_bmp_, palette_); tile16_blockset_bmp_, palette_));
// Copy the tile16 data into individual tiles. // Copy the tile16 data into individual tiles.
auto tile16_data = overworld_.Tile16Blockset(); auto tile16_data = overworld_.Tile16Blockset();
@@ -1925,9 +1920,9 @@ absl::Status OverworldEditor::LoadAnimatedMaps() {
} }
RETURN_IF_ERROR(map.BuildBitmap(blockset)); RETURN_IF_ERROR(map.BuildBitmap(blockset));
gui::BuildAndRenderBitmapPipeline(0x200, 0x200, 0x200, map.bitmap_data(), RETURN_IF_ERROR(rom()->CreateAndRenderBitmap(
*rom(), animated_maps_[world_index], 0x200, 0x200, 0x200, map.bitmap_data(), animated_maps_[world_index],
*map.mutable_current_palette()); *map.mutable_current_palette()));
animated_built[world_index] = true; animated_built[world_index] = true;
} }

View File

@@ -162,7 +162,7 @@ class OverworldEditor : public Editor,
absl::Status DrawTile16Selector(); absl::Status DrawTile16Selector();
void DrawTile8Selector(); void DrawTile8Selector();
void DrawAreaGraphics(); absl::Status DrawAreaGraphics();
absl::Status DrawTileSelector(); absl::Status DrawTileSelector();
absl::Status LoadSpriteGraphics(); absl::Status LoadSpriteGraphics();

View File

@@ -22,8 +22,6 @@ namespace app {
*/ */
namespace gfx { namespace gfx {
/** /**
* @brief Convert SDL_Surface to PNG image data. * @brief Convert SDL_Surface to PNG image data.
*/ */
@@ -52,6 +50,16 @@ class Bitmap {
: width_(width), height_(height), depth_(depth), data_(data) { : width_(width), height_(height), depth_(depth), data_(data) {
InitializeFromData(width, height, depth, data); InitializeFromData(width, height, depth, data);
} }
Bitmap(int width, int height, int depth, const Bytes &data,
const SnesPalette &palette)
: width_(width),
height_(height),
depth_(depth),
data_(data),
palette_(palette) {
InitializeFromData(width, height, depth, data);
ApplyPalette(palette);
}
/** /**
* @brief Creates a bitmap object and reserves space for graphical data. * @brief Creates a bitmap object and reserves space for graphical data.

View File

@@ -15,7 +15,6 @@
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/gui/color.h" #include "app/gui/color.h"
#include "app/gui/input.h" #include "app/gui/input.h"
#include "app/rom.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -158,14 +157,6 @@ void BitmapCanvasPipeline(gui::Canvas& canvas, const gfx::Bitmap& bitmap,
} }
} }
void BuildAndRenderBitmapPipeline(int width, int height, int depth, Bytes data,
Rom& z3_rom, gfx::Bitmap& bitmap,
gfx::SnesPalette& palette) {
bitmap.Create(width, height, depth, data);
bitmap.ApplyPalette(palette);
z3_rom.RenderBitmap(&bitmap);
}
void FileDialogPipeline(absl::string_view display_key, void FileDialogPipeline(absl::string_view display_key,
absl::string_view file_extensions, absl::string_view file_extensions,
std::optional<absl::string_view> button_text, std::optional<absl::string_view> button_text,

View File

@@ -14,7 +14,6 @@
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/rom.h"
namespace yaze { namespace yaze {
namespace app { namespace app {
@@ -38,10 +37,6 @@ void GraphicsManagerCanvasPipeline(int width, int height, int tile_size,
bool is_loaded, bool is_loaded,
const gfx::BitmapManager& graphics_manager); const gfx::BitmapManager& graphics_manager);
void BuildAndRenderBitmapPipeline(int width, int height, int depth, Bytes data,
Rom& z3_rom, gfx::Bitmap& bitmap,
gfx::SnesPalette& palette);
void FileDialogPipeline(absl::string_view display_key, void FileDialogPipeline(absl::string_view display_key,
absl::string_view file_extensions, absl::string_view file_extensions,
std::optional<absl::string_view> button_text, std::optional<absl::string_view> button_text,

View File

@@ -507,6 +507,15 @@ class Rom : public core::ExperimentFlags {
renderer_ = renderer; renderer_ = renderer;
} }
absl::Status CreateAndRenderBitmap(int width, int height, int depth,
const Bytes& data, gfx::Bitmap& bitmap,
gfx::SnesPalette& palette) {
bitmap.Create(width, height, depth, data);
RETURN_IF_ERROR(bitmap.ApplyPalette(palette));
RenderBitmap(&bitmap);
return absl::OkStatus();
}
/** /**
* @brief Used to render a bitmap to the screen. * @brief Used to render a bitmap to the screen.
*/ */