Enhance DungeonEditor functionality by adding room graphics loading and rendering capabilities; implement bitmap drawing for background layers and room objects in the canvas, improving visual representation of dungeon rooms.

This commit is contained in:
scawful
2025-04-27 14:00:40 -04:00
parent 5c20d867ad
commit ff74c0c92a
4 changed files with 29 additions and 15 deletions

View File

@@ -3,6 +3,7 @@
#include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_map.h"
#include "app/core/features.h" #include "app/core/features.h"
#include "app/core/platform/renderer.h" #include "app/core/platform/renderer.h"
#include "app/gfx/arena.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/gui/color.h" #include "app/gui/color.h"
@@ -60,6 +61,8 @@ absl::Status DungeonEditor::Load() {
rooms_[i].LoadRoomGraphics(); rooms_[i].LoadRoomGraphics();
} }
// rooms_[i].LoadObjects();
auto dungeon_palette_ptr = rom()->paletteset_ids[rooms_[i].palette][0]; auto dungeon_palette_ptr = rom()->paletteset_ids[rooms_[i].palette][0];
auto palette_id = rom()->ReadWord(0xDEC4B + dungeon_palette_ptr); auto palette_id = rom()->ReadWord(0xDEC4B + dungeon_palette_ptr);
if (palette_id.status() != absl::OkStatus()) { if (palette_id.status() != absl::OkStatus()) {
@@ -477,11 +480,22 @@ void DungeonEditor::DrawDungeonCanvas(int room_id) {
gui::InputHexWord("Message ID", &rooms_[room_id].message_id_); gui::InputHexWord("Message ID", &rooms_[room_id].message_id_);
SameLine(); SameLine();
if (Button("Load Room")) {
rooms_[room_id].LoadRoomGraphics();
}
ImGui::EndGroup(); ImGui::EndGroup();
canvas_.DrawBackground(ImVec2(0x200, 0x200)); canvas_.DrawBackground();
canvas_.DrawContextMenu(); canvas_.DrawContextMenu();
if (is_loaded_) { if (is_loaded_) {
canvas_.DrawBitmap(gfx::Arena::Get().bg1_bitmap(), 0, 0);
canvas_.DrawBitmap(gfx::Arena::Get().bg2_bitmap(), 0, 0);
for (const auto &object : rooms_[room_id].tile_objects_) {
canvas_.DrawOutline(object.x_, object.y_, object.width_ * 16,
object.height_ * 16);
}
canvas_.DrawBitmap(rooms_[room_id].layer1(), 0, 0); canvas_.DrawBitmap(rooms_[room_id].layer1(), 0, 0);
} }
canvas_.DrawGrid(); canvas_.DrawGrid();

View File

@@ -40,8 +40,8 @@ constexpr ImGuiTableFlags kDungeonTableFlags =
*/ */
class DungeonEditor : public Editor { class DungeonEditor : public Editor {
public: public:
explicit DungeonEditor(Rom* rom = nullptr) : rom_(rom) { explicit DungeonEditor(Rom* rom = nullptr) : rom_(rom) {
type_ = EditorType::kDungeon; type_ = EditorType::kDungeon;
} }
void Initialize() override; void Initialize() override;
@@ -57,10 +57,7 @@ class DungeonEditor : public Editor {
void add_room(int i) { active_rooms_.push_back(i); } void add_room(int i) { active_rooms_.push_back(i); }
// Set the ROM pointer
void set_rom(Rom* rom) { rom_ = rom; } void set_rom(Rom* rom) { rom_ = rom; }
// Get the ROM pointer
Rom* rom() const { return rom_; } Rom* rom() const { return rom_; }
private: private:
@@ -118,7 +115,7 @@ class DungeonEditor : public Editor {
gfx::SnesPalette full_palette_; gfx::SnesPalette full_palette_;
gfx::PaletteGroup current_palette_group_; gfx::PaletteGroup current_palette_group_;
gui::Canvas canvas_; gui::Canvas canvas_{"##DungeonCanvas", ImVec2(0x200, 0x200)};
gui::Canvas room_gfx_canvas_; gui::Canvas room_gfx_canvas_;
gui::Canvas object_canvas_; gui::Canvas object_canvas_;

View File

@@ -223,7 +223,7 @@ constexpr int kGfxBufferRoomSpriteStride = 2048;
constexpr int kGfxBufferRoomSpriteLastLineOffset = 0x88; constexpr int kGfxBufferRoomSpriteLastLineOffset = 0x88;
void Room::CopyRoomGraphicsToBuffer() { void Room::CopyRoomGraphicsToBuffer() {
auto gfx_buffer_data = rom()->graphics_buffer(); auto gfx_buffer_data = rom()->mutable_graphics_buffer();
// Copy room graphics to buffer // Copy room graphics to buffer
int sheet_pos = 0; int sheet_pos = 0;
@@ -231,7 +231,7 @@ void Room::CopyRoomGraphicsToBuffer() {
int data = 0; int data = 0;
int block_offset = blocks_[i] * kGfxBufferRoomOffset; int block_offset = blocks_[i] * kGfxBufferRoomOffset;
while (data < kGfxBufferRoomOffset) { while (data < kGfxBufferRoomOffset) {
uint8_t map_byte = gfx_buffer_data[data + block_offset]; uint8_t map_byte = (*gfx_buffer_data)[data + block_offset];
if (i < 4) { if (i < 4) {
map_byte += kGfxBufferRoomSpriteLastLineOffset; map_byte += kGfxBufferRoomSpriteLastLineOffset;
} }
@@ -249,18 +249,18 @@ void Room::CopyRoomGraphicsToBuffer() {
void Room::LoadAnimatedGraphics() { void Room::LoadAnimatedGraphics() {
int gfx_ptr = SnesToPc(rom()->version_constants().kGfxAnimatedPointer); int gfx_ptr = SnesToPc(rom()->version_constants().kGfxAnimatedPointer);
auto gfx_buffer_data = rom()->graphics_buffer(); auto gfx_buffer_data = rom()->mutable_graphics_buffer();
auto rom_data = rom()->vector(); auto rom_data = rom()->vector();
int data = 0; int data = 0;
while (data < 512) { while (data < 512) {
uint8_t map_byte = uint8_t map_byte =
gfx_buffer_data[data + (92 * 2048) + (512 * animated_frame_)]; (*gfx_buffer_data)[data + (92 * 2048) + (512 * animated_frame_)];
current_gfx16_[data + (7 * 2048)] = map_byte; current_gfx16_[data + (7 * 2048)] = map_byte;
map_byte = map_byte =
gfx_buffer_data[data + (*gfx_buffer_data)[data +
(rom_data[gfx_ptr + background_tileset_] * 2048) + (rom_data[gfx_ptr + background_tileset_] * 2048) +
(512 * animated_frame_)]; (512 * animated_frame_)];
current_gfx16_[data + (7 * 2048) - 512] = map_byte; current_gfx16_[data + (7 * 2048) - 512] = map_byte;
data++; data++;
} }

View File

@@ -79,6 +79,9 @@ constexpr int NumberOfRooms = 296;
constexpr uint16_t stairsObjects[] = {0x139, 0x138, 0x13B, 0x12E, 0x12D}; constexpr uint16_t stairsObjects[] = {0x139, 0x138, 0x13B, 0x12E, 0x12D};
constexpr int tile_address = 0x001B52;
constexpr int tile_address_floor = 0x001B5A;
struct LayerMergeType { struct LayerMergeType {
uint8_t ID; uint8_t ID;
std::string Name; std::string Name;
@@ -231,7 +234,7 @@ class Room : public SharedRom {
bool is_light_; bool is_light_;
bool is_loaded_; bool is_loaded_;
bool is_dark_; bool is_dark_;
bool is_floor_; bool is_floor_ = true;
int room_id_; int room_id_;
int animated_frame_; int animated_frame_;