Enhance Dungeon Editor with Object Rendering and Layout Management

- Introduced new object rendering features in DungeonEditor, allowing for improved visualization of dungeon objects with options to show outlines, render objects, and display object information.
- Implemented a caching mechanism for rendered objects to optimize performance.
- Added functionality to load and manage room layouts, including walls, floors, and other structural elements, enhancing the overall editing experience.
- Refactored object handling in Room and RoomObject classes to support new rendering logic and ensure compatibility with the updated layout system.
- Introduced ObjectParser for efficient parsing of object data directly from ROM, improving reliability and performance in object rendering.
This commit is contained in:
scawful
2025-09-23 22:00:54 -04:00
parent 8da8014170
commit edaf6427c8
12 changed files with 1537 additions and 176 deletions

View File

@@ -8,6 +8,7 @@
#include "app/gui/canvas.h"
#include "app/rom.h"
#include "imgui/imgui.h"
#include "zelda3/dungeon/object_renderer.h"
#include "zelda3/dungeon/room.h"
#include "zelda3/dungeon/room_entrance.h"
#include "zelda3/dungeon/room_object.h"
@@ -40,7 +41,8 @@ constexpr ImGuiTableFlags kDungeonTableFlags =
*/
class DungeonEditor : public Editor {
public:
explicit DungeonEditor(Rom* rom = nullptr) : rom_(rom) {
explicit DungeonEditor(Rom* rom = nullptr)
: rom_(rom), object_renderer_(rom) {
type_ = EditorType::kDungeon;
}
@@ -78,6 +80,26 @@ class DungeonEditor : public Editor {
void DrawTileSelector();
void DrawObjectRenderer();
// Object rendering methods
void RenderObjectInCanvas(const zelda3::RoomObject& object,
const gfx::SnesPalette& palette);
void DisplayObjectInfo(const zelda3::RoomObject& object, int canvas_x,
int canvas_y);
void RenderLayoutObjects(const zelda3::RoomLayout& layout,
const gfx::SnesPalette& palette);
// Object rendering cache to avoid re-rendering the same objects
struct ObjectRenderCache {
int object_id;
int object_x, object_y, object_size;
uint64_t palette_hash;
gfx::Bitmap rendered_bitmap;
bool is_valid;
};
std::vector<ObjectRenderCache> object_render_cache_;
uint64_t last_palette_hash_ = 0;
void CalculateUsageStats();
void DrawUsageStats();
void DrawUsageGrid();
@@ -123,7 +145,7 @@ class DungeonEditor : public Editor {
std::array<zelda3::Room, 0x128> rooms_ = {};
std::array<zelda3::RoomEntrance, 0x8C> entrances_ = {};
// zelda3::DungeonObjectRenderer object_renderer_;
zelda3::ObjectRenderer object_renderer_;
absl::flat_hash_map<uint16_t, int> spriteset_usage_;
absl::flat_hash_map<uint16_t, int> blockset_usage_;