Add BitmapCanvasPipeline, more CgxViewer updates

This commit is contained in:
Justin Scofield
2023-08-02 12:53:05 -04:00
parent d51bb7b3d0
commit 7b2e017bb3
17 changed files with 237 additions and 206 deletions

View File

@@ -9,11 +9,47 @@
#include <optional>
#include "absl/strings/string_view.h"
#include "app/core/common.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gui/canvas.h"
#include "app/rom.h"
namespace yaze {
namespace app {
namespace core {
void ButtonPipe(absl::string_view button_text, std::function<void()> callback) {
if (ImGui::Button(button_text.data())) {
callback();
}
}
void BitmapCanvasPipeline(int width, int height, int tile_size, int canvas_id,
bool is_loaded, gfx::Bitmap& bitmap) {
gui::Canvas canvas;
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)canvas_id);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
canvas.DrawBackground(ImVec2(width + 1, height + 1));
canvas.DrawContextMenu();
canvas.DrawBitmap(bitmap, 2, is_loaded);
canvas.DrawTileSelector(tile_size);
canvas.DrawGrid(tile_size);
canvas.DrawOverlay();
}
ImGui::EndChild();
}
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,
absl::string_view file_extensions,
std::optional<absl::string_view> button_text,

View File

@@ -10,11 +10,24 @@
#include <optional>
#include "absl/strings/string_view.h"
#include "app/core/constants.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/rom.h"
namespace yaze {
namespace app {
namespace core {
void ButtonPipe(absl::string_view button_text, std::function<void()> callback);
void BitmapCanvasPipeline(int width, int height, int tile_size, int canvas_id,
bool is_loaded, gfx::Bitmap& bitmap);
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,
absl::string_view file_extensions,
std::optional<absl::string_view> button_text,

View File

@@ -30,9 +30,10 @@ absl::Status GraphicsEditor::Update() {
ImGui::End();
}
BEGIN_TABLE("#gfxEditTable", 3, kGfxEditFlags)
BEGIN_TABLE("#gfxEditTable", 4, kGfxEditFlags)
SETUP_COLUMN("Graphics (BIN, CGX, SCR)")
SETUP_COLUMN("Palette (COL)")
SETUP_COLUMN("Maps and Animations (SCR, PNL)")
SETUP_COLUMN("Preview")
TABLE_HEADERS()
NEXT_COLUMN()
@@ -44,13 +45,16 @@ absl::Status GraphicsEditor::Update() {
NEXT_COLUMN()
status_ = DrawPaletteControls();
NEXT_COLUMN()
core::BitmapCanvasPipeline(0x200, 0x200, 0x20, 6, scr_loaded_, cgx_bitmap_);
NEXT_COLUMN()
if (super_donkey_) {
status_ = DrawGraphicsBin();
} else if (cgx_loaded_ && col_file_) {
status_ = DrawCgxViewer();
core::BitmapCanvasPipeline(0x100, 16384, 0x20, 5, cgx_loaded_, cgx_bitmap_);
} else {
status_ = DrawDecompressedData();
core::BitmapCanvasPipeline(0x100, 16384, 0x20, 2, gfx_loaded_, bitmap_);
}
END_TABLE()
@@ -66,7 +70,11 @@ absl::Status GraphicsEditor::DrawToolset() {
ImGui::TableNextColumn();
if (ImGui::Button(ICON_MD_MEMORY)) {
open_memory_editor_ = true;
if (!open_memory_editor_) {
open_memory_editor_ = true;
} else {
open_memory_editor_ = false;
}
}
TEXT_COLUMN("Open Memory Editor") // Separator
@@ -81,21 +89,31 @@ absl::Status GraphicsEditor::DrawCgxImport() {
ImGui::InputText("##CGXFile", cgx_file_name_, sizeof(cgx_file_name_));
ImGui::SameLine();
core::FileDialogPipeline("ImportCgxKey", ".CGX,.cgx\0", "Open CGX", [&]() {
strncpy(cgx_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(cgx_file_path_));
strncpy(cgx_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(cgx_file_name_));
RETURN_IF_ERROR(temp_rom_.LoadFromFile(cgx_file_path_, /*z3_load=*/false))
cgx_viewer_.LoadCgx(temp_rom_);
auto all_tiles_data = cgx_viewer_.GetCgxData();
cgx_bitmap_.Create(core::kTilesheetWidth, 8192, core::kTilesheetDepth,
all_tiles_data.data(), all_tiles_data.size());
is_open_ = true;
cgx_loaded_ = true;
});
core::FileDialogPipeline(
"ImportCgxKey", ".CGX,.cgx\0", "Open CGX", [&]() -> auto {
strncpy(cgx_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(cgx_file_path_));
strncpy(cgx_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(cgx_file_name_));
status_ = temp_rom_.LoadFromFile(cgx_file_path_, /*z3_load=*/false);
cgx_viewer_.LoadCgx(temp_rom_);
auto all_tiles_data = cgx_viewer_.GetCgxData();
cgx_bitmap_.Create(core::kTilesheetWidth, 8192, core::kTilesheetDepth,
all_tiles_data.data(), all_tiles_data.size());
if (col_file_) {
cgx_bitmap_.ApplyPalette(col_file_palette_);
rom_.RenderBitmap(&cgx_bitmap_);
}
is_open_ = true;
cgx_loaded_ = true;
});
core::ButtonPipe("Copy File Path",
[&]() -> auto { ImGui::SetClipboardText(cgx_file_path_); });
CLEAR_AND_RETURN_STATUS(status_)
return absl::OkStatus();
}
@@ -109,26 +127,18 @@ absl::Status GraphicsEditor::DrawFileImport() {
ImGui::InputText("##ROMFile", file_path_, sizeof(file_path_));
ImGui::SameLine();
// Open the file dialog when the user clicks the "Browse" button
if (ImGui::Button("Open BIN")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportDlgKey", "Choose File",
".bin,.hex\0", ".");
}
// Draw the file dialog
if (ImGuiFileDialog::Instance()->Display("ImportDlgKey")) {
// If the user made a selection, copy the filename to the file_path_ buffer
if (ImGuiFileDialog::Instance()->IsOk()) {
strncpy(file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(file_path_));
RETURN_IF_ERROR(temp_rom_.LoadFromFile(file_path_))
is_open_ = true;
}
core::FileDialogPipeline(
"ImportDlgKey", ".bin,.hex\0", "Open BIN", [&]() -> auto {
strncpy(file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(file_path_));
status_ = temp_rom_.LoadFromFile(file_path_);
is_open_ = true;
});
// Close the modal
ImGuiFileDialog::Instance()->Close();
}
core::ButtonPipe("Copy File Path",
[&]() -> auto { ImGui::SetClipboardText(file_path_); });
gui::InputHex("Offset", &current_offset_);
gui::InputHex("Size ", &size);
@@ -150,32 +160,23 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
ImGui::InputText("##ColFile", col_file_name_, sizeof(col_file_name_));
ImGui::SameLine();
if (ImGui::Button("Open COL")) {
ImGuiFileDialog::Instance()->OpenDialog("ImportColKey", "Choose File",
".COL,.col", ".");
}
core::FileDialogPipeline(
"ImportColKey", ".COL,.col,.BAK,.bak\0", "Open COL", [&]() -> auto {
strncpy(col_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(col_file_path_));
strncpy(col_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(col_file_name_));
status_ = temp_rom_.LoadFromFile(col_file_path_, /*z3_load=*/false);
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
col_file_palette_ = gfx::SNESPalette(col_data_);
col_file_ = true;
is_open_ = true;
});
if (ImGuiFileDialog::Instance()->Display("ImportColKey")) {
if (ImGuiFileDialog::Instance()->IsOk()) {
strncpy(col_file_path_,
ImGuiFileDialog::Instance()->GetFilePathName().c_str(),
sizeof(col_file_path_));
strncpy(col_file_name_,
ImGuiFileDialog::Instance()->GetCurrentFileName().c_str(),
sizeof(col_file_name_));
RETURN_IF_ERROR(temp_rom_.LoadFromFile(col_file_path_, /*z3_load=*/false))
auto col_data_ = gfx::GetColFileData(temp_rom_.data());
col_file_palette_ = gfx::SNESPalette(col_data_);
col_file_ = true;
is_open_ = true;
if (cgx_loaded_) {
cgx_bitmap_.ApplyPalette(col_file_palette_);
rom_.RenderBitmap(&cgx_bitmap_);
}
}
ImGuiFileDialog::Instance()->Close();
}
core::ButtonPipe("Copy File Path",
[&]() -> auto { ImGui::SetClipboardText(col_file_path_); });
if (rom_.isLoaded()) {
gui::TextWithSeparators("ROM Palette");
@@ -185,7 +186,6 @@ absl::Status GraphicsEditor::DrawPaletteControls() {
}
if (col_file_palette_.size() != 0) {
ImGuiFileDialog::Instance()->prDrawFileListView(ImVec2(0, 200));
palette_editor_.DrawPortablePalette(col_file_palette_);
}
@@ -231,36 +231,6 @@ absl::Status GraphicsEditor::DrawMemoryEditor() {
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawCgxViewer() {
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)5);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
import_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
import_canvas_.DrawContextMenu();
import_canvas_.DrawBitmap(cgx_bitmap_, 2, cgx_loaded_);
import_canvas_.DrawTileSelector(32);
import_canvas_.DrawGrid(32.0f);
import_canvas_.DrawOverlay();
}
ImGui::EndChild();
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawDecompressedData() {
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)2);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
import_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
import_canvas_.DrawContextMenu();
import_canvas_.DrawBitmap(bitmap_, 2, gfx_loaded_);
import_canvas_.DrawTileSelector(32);
import_canvas_.DrawGrid(32.0f);
import_canvas_.DrawOverlay();
}
ImGui::EndChild();
return absl::OkStatus();
}
absl::Status GraphicsEditor::DrawGraphicsBin() {
if (ImGuiID child_id = ImGui::GetID((void*)(intptr_t)3);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
@@ -276,7 +246,7 @@ absl::Status GraphicsEditor::DrawGraphicsBin() {
top_left_y = super_donkey_canvas_.GetZeroPoint().y + 0x40 * key;
}
super_donkey_canvas_.GetDrawList()->AddImage(
(void*)value.GetTexture(),
(void*)value.texture(),
ImVec2(super_donkey_canvas_.GetZeroPoint().x + 2, top_left_y),
ImVec2(super_donkey_canvas_.GetZeroPoint().x + 0x100,
super_donkey_canvas_.GetZeroPoint().y + offset));

View File

@@ -8,6 +8,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/core/pipeline.h"
#include "app/editor/palette_editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_tile.h"
@@ -70,8 +71,6 @@ class GraphicsEditor {
absl::Status DrawClipboardImport();
absl::Status DrawExperimentalFeatures();
absl::Status DrawMemoryEditor();
absl::Status DrawCgxViewer();
absl::Status DrawDecompressedData();
absl::Status DrawGraphicsBin();
absl::Status DecompressImportData(int size);
@@ -89,6 +88,7 @@ class GraphicsEditor {
bool super_donkey_ = false;
bool col_file_ = false;
bool cgx_loaded_ = false;
bool scr_loaded_ = false;
char file_path_[256] = "";
char col_file_path_[256] = "";

View File

@@ -9,6 +9,7 @@
#include "absl/status/status.h"
#include "app/core/constants.h"
#include "app/core/pipeline.h"
#include "app/editor/assembly_editor.h"
#include "app/editor/dungeon_editor.h"
#include "app/editor/graphics_editor.h"

View File

@@ -9,6 +9,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"
#include "app/core/pipeline.h"
#include "app/editor/palette_editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
@@ -210,7 +211,7 @@ void OverworldEditor::DrawOverworldCanvas() {
if (overworld_.isLoaded()) {
DrawOverworldMaps();
DrawOverworldEntrances();
DrawOverworldSprites();
// DrawOverworldSprites();
// User has selected a tile they want to draw from the blockset.
if (!blockset_canvas_.Points().empty()) {
int x = blockset_canvas_.Points().front().x / 32;
@@ -232,19 +233,6 @@ void OverworldEditor::DrawOverworldCanvas() {
// ----------------------------------------------------------------------------
// Tile 16 Selector
// Displays all the tiles in the game.
void OverworldEditor::DrawTile16Selector() {
blockset_canvas_.DrawBackground(ImVec2(0x100 + 1, (8192 * 2) + 1));
blockset_canvas_.DrawContextMenu();
blockset_canvas_.DrawBitmap(tile16_blockset_bmp_, 2, map_blockset_loaded_);
blockset_canvas_.DrawTileSelector(32);
blockset_canvas_.DrawGrid(32.0f);
blockset_canvas_.DrawOverlay();
}
// ----------------------------------------------------------------------------
// Tile 8 Selector
// Displays all the individual tiles that make up a tile16.
void OverworldEditor::DrawTile8Selector() {
@@ -259,7 +247,7 @@ void OverworldEditor::DrawTile8Selector() {
top_left_y = graphics_bin_canvas_.GetZeroPoint().y + 0x40 * key;
}
graphics_bin_canvas_.GetDrawList()->AddImage(
(void *)value.GetTexture(),
(void *)value.texture(),
ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 2, top_left_y),
ImVec2(graphics_bin_canvas_.GetZeroPoint().x + 0x100,
graphics_bin_canvas_.GetZeroPoint().y + offset));
@@ -271,29 +259,12 @@ void OverworldEditor::DrawTile8Selector() {
// ----------------------------------------------------------------------------
// Displays the graphics tilesheets that are available on the current selected
// overworld map.
void OverworldEditor::DrawAreaGraphics() {
current_gfx_canvas_.DrawBackground(ImVec2(256 + 1, 0x10 * 0x40 + 1));
current_gfx_canvas_.DrawContextMenu();
current_gfx_canvas_.DrawTileSelector(32);
current_gfx_canvas_.DrawBitmap(current_gfx_bmp_, 2, overworld_.isLoaded());
current_gfx_canvas_.DrawGrid(32.0f);
current_gfx_canvas_.DrawOverlay();
}
// ----------------------------------------------------------------------------
void OverworldEditor::DrawTileSelector() {
if (ImGui::BeginTabBar(kTileSelectorTab.data(),
ImGuiTabBarFlags_FittingPolicyScroll)) {
if (ImGui::BeginTabItem("Tile16")) {
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)2);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
DrawTile16Selector();
}
ImGui::EndChild();
core::BitmapCanvasPipeline(0x100, (8192 * 2), 0x20, 1,
map_blockset_loaded_, tile16_blockset_bmp_);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Tile8")) {
@@ -306,12 +277,8 @@ void OverworldEditor::DrawTileSelector() {
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Area Graphics")) {
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)3);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
DrawAreaGraphics();
}
ImGui::EndChild();
core::BitmapCanvasPipeline(256, 0x10 * 0x40, 0x20, 3,
overworld_.isLoaded(), current_gfx_bmp_);
ImGui::EndTabItem();
}
ImGui::EndTabBar();
@@ -328,14 +295,16 @@ absl::Status OverworldEditor::LoadGraphics() {
// Load the Link to the Past overworld.
RETURN_IF_ERROR(overworld_.Load(rom_))
palette_ = overworld_.AreaPalette();
current_gfx_bmp_.Create(0x80, 0x200, 0x40, overworld_.AreaGraphics());
current_gfx_bmp_.ApplyPalette(palette_);
rom_.RenderBitmap(&current_gfx_bmp_);
// Create the area graphics image
core::BuildAndRenderBitmapPipeline(0x80, 0x200, 0x40,
overworld_.AreaGraphics(), rom_,
current_gfx_bmp_, palette_);
// Create the tile16 blockset image
tile16_blockset_bmp_.Create(0x80, 0x2000, 0x80, overworld_.Tile16Blockset());
tile16_blockset_bmp_.ApplyPalette(palette_);
rom_.RenderBitmap(&tile16_blockset_bmp_);
core::BuildAndRenderBitmapPipeline(0x80, 0x2000, 0x80,
overworld_.Tile16Blockset(), rom_,
tile16_blockset_bmp_, palette_);
map_blockset_loaded_ = true;
// Copy the tile16 data into individual tiles.
@@ -363,19 +332,18 @@ absl::Status OverworldEditor::LoadGraphics() {
// Render the bitmaps of each tile.
for (int id = 0; id < 4096; id++) {
tile16_individual_.emplace_back();
tile16_individual_[id].Create(0x10, 0x10, 0x80,
tile16_individual_data_[id]);
tile16_individual_[id].ApplyPalette(palette_);
rom_.RenderBitmap(&tile16_individual_[id]);
core::BuildAndRenderBitmapPipeline(0x10, 0x10, 0x80,
tile16_individual_data_[id], rom_,
tile16_individual_[id], palette_);
}
// Render the overworld maps loaded from the ROM.
for (int i = 0; i < core::kNumOverworldMaps; ++i) {
overworld_.SetCurrentMap(i);
auto palette = overworld_.AreaPalette();
maps_bmp_[i].Create(0x200, 0x200, 0x200, overworld_.BitmapData());
maps_bmp_[i].ApplyPalette(palette);
rom_.RenderBitmap(&(maps_bmp_[i]));
core::BuildAndRenderBitmapPipeline(0x200, 0x200, 0x200,
overworld_.BitmapData(), rom_,
maps_bmp_[i], palette);
}
return absl::OkStatus();

View File

@@ -10,6 +10,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"
#include "app/core/pipeline.h"
#include "app/editor/palette_editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
@@ -75,9 +76,7 @@ class OverworldEditor : public SharedROM {
void DrawOverworldEdits() const;
void DrawOverworldCanvas();
void DrawTile16Selector();
void DrawTile8Selector();
void DrawAreaGraphics();
void DrawTileSelector();
absl::Status LoadGraphics();
absl::Status LoadSpriteGraphics();

View File

@@ -38,13 +38,12 @@ class Bitmap {
this->pixel_data_[position] = value;
}
int GetWidth() const { return width_; }
int GetHeight() const { return height_; }
auto GetSize() const { return data_size_; }
auto GetData() const { return pixel_data_; }
auto GetByte(int i) const { return pixel_data_[i]; }
auto GetTexture() const { return texture_.get(); }
auto GetSurface() const { return surface_.get(); }
int width() const { return width_; }
int height() const { return height_; }
auto size() const { return data_size_; }
auto data() const { return pixel_data_; }
auto at(int i) const { return pixel_data_[i]; }
auto texture() const { return texture_.get(); }
auto IsActive() const { return active_; }
private:

View File

@@ -153,6 +153,23 @@ Bytes BPP8SNESToIndexed(Bytes data, uint64_t bpp) {
return buffer;
}
ushort TileInfoToShort(TileInfo tile_info) {
ushort result = 0;
// Copy the id_ value
result |= tile_info.id_ & 0x3FF; // ids are 10 bits
// Set the vertical_mirror_, horizontal_mirror_, and over_ flags
result |= (tile_info.vertical_mirror_ ? 1 : 0) << 10;
result |= (tile_info.horizontal_mirror_ ? 1 : 0) << 11;
result |= (tile_info.over_ ? 1 : 0) << 12;
// Set the palette_
result |= (tile_info.palette_ & 0x07) << 13; // palettes are 3 bits
return result;
}
TileInfo GetTilesInfo(ushort tile) {
// vhopppcc cccccccc
bool o = false;

View File

@@ -40,25 +40,10 @@ class TileInfo {
vertical_mirror_(v),
horizontal_mirror_(h),
palette_(palette) {}
ushort ToShort() const {
ushort result = 0;
// Copy the id_ value
result |= id_ & 0x3FF; // ids are 10 bits
// Set the vertical_mirror_, horizontal_mirror_, and over_ flags
result |= (vertical_mirror_ ? 1 : 0) << 10;
result |= (horizontal_mirror_ ? 1 : 0) << 11;
result |= (over_ ? 1 : 0) << 12;
// Set the palette_
result |= (palette_ & 0x07) << 13; // palettes are 3 bits
return result;
}
};
ushort TileInfoToShort(TileInfo tile_info);
TileInfo GetTilesInfo(ushort tile);
class Tile32 {

View File

@@ -96,11 +96,11 @@ bool Canvas::DrawTilePainter(const Bitmap &bitmap, int size) {
if (bitmap.IsActive()) {
draw_list_->AddImage(
(void *)bitmap.GetTexture(),
(void *)bitmap.texture(),
ImVec2(origin.x + draw_tile_outline_pos.x,
origin.y + draw_tile_outline_pos.y),
ImVec2(origin.x + draw_tile_outline_pos.x + bitmap.GetWidth(),
origin.y + draw_tile_outline_pos.y + bitmap.GetHeight()));
ImVec2(origin.x + draw_tile_outline_pos.x + bitmap.width(),
origin.y + draw_tile_outline_pos.y + bitmap.height()));
}
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
@@ -147,20 +147,20 @@ void Canvas::DrawTileSelector(int size) {
void Canvas::DrawBitmap(const Bitmap &bitmap, int border_offset, bool ready) {
if (ready) {
draw_list_->AddImage(
(void *)bitmap.GetTexture(),
(void *)bitmap.texture(),
ImVec2(canvas_p0_.x + border_offset, canvas_p0_.y + border_offset),
ImVec2(canvas_p0_.x + (bitmap.GetWidth() * 2),
canvas_p0_.y + (bitmap.GetHeight() * 2)));
ImVec2(canvas_p0_.x + (bitmap.width() * 2),
canvas_p0_.y + (bitmap.height() * 2)));
}
}
void Canvas::DrawBitmap(const Bitmap &bitmap, int x_offset, int y_offset) {
draw_list_->AddImage(
(void *)bitmap.GetTexture(),
(void *)bitmap.texture(),
ImVec2(canvas_p0_.x + x_offset + scrolling_.x,
canvas_p0_.y + y_offset + scrolling_.y),
ImVec2(canvas_p0_.x + x_offset + scrolling_.x + (bitmap.GetWidth()),
canvas_p0_.y + y_offset + scrolling_.y + (bitmap.GetHeight())));
ImVec2(canvas_p0_.x + x_offset + scrolling_.x + (bitmap.width()),
canvas_p0_.y + y_offset + scrolling_.y + (bitmap.height())));
}
// TODO: Add parameters for sizing and positioning
@@ -171,7 +171,7 @@ void Canvas::DrawBitmapTable(const BitmapTable &gfx_bin) {
if (key >= 1) {
top_left_y = canvas_p0_.y + 0x40 * key;
}
draw_list_->AddImage((void *)value.GetTexture(),
draw_list_->AddImage((void *)value.texture(),
ImVec2(canvas_p0_.x + 2, top_left_y),
ImVec2(canvas_p0_.x + 0x100, canvas_p0_.y + offset));
}

View File

@@ -284,11 +284,11 @@ absl::Status ROM::LoadAllGraphicsData() {
core::kTilesheetDepth, converted_sheet.data(), 0x1000);
graphics_bin_.at(i).CreateTexture(renderer_);
for (int j = 0; j < graphics_bin_.at(i).GetSize(); ++j) {
graphics_buffer_.push_back(graphics_bin_.at(i).GetByte(j));
for (int j = 0; j < graphics_bin_.at(i).size(); ++j) {
graphics_buffer_.push_back(graphics_bin_.at(i).at(j));
}
} else {
for (int j = 0; j < graphics_bin_.at(0).GetSize(); ++j) {
for (int j = 0; j < graphics_bin_.at(0).size(); ++j) {
graphics_buffer_.push_back(0xFF);
}
}
@@ -315,11 +315,10 @@ absl::Status ROM::LoadFromFile(const absl::string_view& filename,
rom_data_[i] = byte_to_read;
}
// copy ROM title
memcpy(title_, rom_data_.data() + kTitleStringOffset, kTitleStringLength);
file.close();
if (z3_load) {
// copy ROM title
memcpy(title_, rom_data_.data() + kTitleStringOffset, kTitleStringLength);
LoadAllPalettes();
}
is_loaded_ = true;

View File

@@ -138,14 +138,16 @@ class ROM {
uchar& operator[](int i) {
if (i > size_) {
std::cout << "ROM: Index out of bounds" << std::endl;
std::cout << "ROM: Index " << i << " out of bounds, size: " << size_
<< std::endl;
return rom_data_[0];
}
return rom_data_[i];
}
uchar& operator+(int i) {
if (i > size_) {
std::cout << "ROM: Index out of bounds" << std::endl;
std::cout << "ROM: Index " << i << " out of bounds, size: " << size_
<< std::endl;
return rom_data_[0];
}
return rom_data_[i];

View File

@@ -4,6 +4,7 @@
#include <iostream>
#include <vector>
#include "app/core/pipeline.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
@@ -12,14 +13,8 @@ namespace yaze {
namespace app {
namespace viewer {
void CgxViewer::Update() {
static int current_bpp = 1;
// ImGui::Combo("BPP", current_bpp, "0\0 1\0 2\0 3\0", 4, 4);
LoadGfx(current_bpp);
LoadScr();
}
void CgxViewer::LoadCgx(ROM& cgx_rom) {
void CgxViewer::LoadCgx(ROM &cgx_rom) {
std::cout << "Loading CGX" << std::endl;
raw_data_.malloc(0x40000);
all_tiles_data_.malloc(0x40000);
@@ -50,6 +45,43 @@ void CgxViewer::LoadCgx(ROM& cgx_rom) {
LoadGfx(current_selection_);
}
void CgxViewer::DrawBG1(int p, int bpp) {
auto *ptr = (uchar *)screen_bitmap_.data();
// for each tile on the tile buffer
for (int i = 0; i < 0x400; i++) {
if (room_bg1_bitmap_.data()[i + p] != 0xFFFF) {
gfx::TileInfo t = gfx::GetTilesInfo(room_bg1_bitmap_.data()[i + p]);
for (uint16_t yl = 0; yl < 8; yl++) {
for (uint16_t xl = 0; xl < 8; xl++) {
int mx = xl * (1 - t.horizontal_mirror_) +
(7 - xl) * (t.horizontal_mirror_);
int my =
yl * (1 - t.vertical_mirror_) + (7 - yl) * (t.vertical_mirror_);
int ty = (t.id_ / 16) * 1024;
int tx = (t.id_ % 16) * 8;
uchar pixel = all_tiles_data_[(tx + ty) + (yl * 128) + xl];
int index =
(((i % 32) * 8) + ((i / 32) * 2048) + ((mx) + (my * 256)));
if (bpp != 8) {
ptr[index] = (uchar)((((pixel)&0xFF) + t.palette_ * 16));
} else {
ptr[index] = (uchar)((((pixel)&0xFF)));
}
}
}
}
}
// Apply data to Bitmap
}
void CgxViewer::DrawBG2() {}
void CgxViewer::DrawOAM(int bpp, int drawmode, gfx::OAMTile data, int frame) {}
void CgxViewer::LoadGfx(int combo_bpp) {
if (combo_bpp == 0) {
bpp_ = 4;

View File

@@ -4,6 +4,7 @@
#include <iostream>
#include <vector>
#include "app/core/pipeline.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
@@ -15,9 +16,12 @@ namespace viewer {
class CgxViewer {
public:
void Update();
auto GetCgxData() const { return all_tiles_data_; }
void LoadCgx(ROM&);
auto GetCgxData() const { return all_tiles_data_; }
void DrawBG1(int p, int bpp);
void DrawBG2();
void DrawOAM(int bpp, int drawmode, gfx::OAMTile data, int frame);
private:
void LoadGfx(int comboBpp);
@@ -25,10 +29,16 @@ class CgxViewer {
void RefreshPalettes();
gfx::Bitmap screen_bitmap_;
gfx::Bitmap room_bg1_bitmap_;
gfx::Bitmap room_bg2_bitmap_;
gfx::Bitmap indexed_bitmap_;
std::string label1_text;
int bpp_;
int current_selection_;
ROM all_tiles_data_;
ROM raw_data_;
};

View File

@@ -129,7 +129,7 @@ void Room::LoadRoomGraphics(uchar entrance_blockset) {
auto newPdata = rom_.GetGraphicsBuffer();
uchar* sheetsData = current_graphics_.GetData();
uchar* sheetsData = current_graphics_.data();
// Into "room gfx16" 16 of them
int sheetPos = 0;
@@ -159,7 +159,7 @@ void Room::LoadAnimatedGraphics() {
auto newPdata = rom_.GetGraphicsBuffer();
uchar* sheetsData = current_graphics_.GetData();
uchar* sheetsData = current_graphics_.data();
int data = 0;
while (data < 512) {
uchar mapByte = newPdata[data + (92 * 2048) + (512 * animated_frame)];

View File

@@ -42,7 +42,7 @@ void TitleScreen::BuildTileset() {
staticgfx[15] = 112;
// Loaded gfx for the current screen (empty at this point)
uchar* currentmapgfx8Data = tiles8Bitmap.GetData();
uchar* currentmapgfx8Data = tiles8Bitmap.data();
// All gfx of the game pack of 2048 bytes (4bpp)
uchar* allgfxData = nullptr; // rom_.GetMasterGraphicsBin();