Update DungeonObjectRenderer experiment
This commit is contained in:
@@ -15,7 +15,7 @@ namespace app {
|
||||
namespace editor {
|
||||
|
||||
void DungeonEditor::Update() {
|
||||
if (!is_loaded_) {
|
||||
if (!is_loaded_ && rom()->isLoaded()) {
|
||||
for (int i = 0; i < 0x100; i++) {
|
||||
rooms_.emplace_back(zelda3::dungeon::Room(i));
|
||||
rooms_[i].LoadHeader();
|
||||
@@ -56,9 +56,6 @@ void DungeonEditor::Update() {
|
||||
ImGui::TableNextColumn();
|
||||
DrawDungeonTabView();
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Button("dungeon object renderer")) {
|
||||
object_renderer_.RenderObjectsAsBitmaps();
|
||||
}
|
||||
DrawTileSelector();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
@@ -158,7 +155,7 @@ void DungeonEditor::DrawDungeonCanvas(int room_id) {
|
||||
}
|
||||
|
||||
void DungeonEditor::DrawToolset() {
|
||||
if (ImGui::BeginTable("DWToolset", 9, ImGuiTableFlags_SizingFixedFit,
|
||||
if (ImGui::BeginTable("DWToolset", 10, ImGuiTableFlags_SizingFixedFit,
|
||||
ImVec2(0, 0))) {
|
||||
ImGui::TableSetupColumn("#undoTool");
|
||||
ImGui::TableSetupColumn("#redoTool");
|
||||
@@ -196,6 +193,12 @@ void DungeonEditor::DrawToolset() {
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Button(ICON_MD_PEST_CONTROL_RODENT);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Button("Load Dungeon Objects")) {
|
||||
// object_renderer_.CreateVramFromRoomBlockset();
|
||||
object_renderer_.RenderObjectsAsBitmaps(*rom());
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ class Room : public SharedROM {
|
||||
uint8_t layout = 0;
|
||||
|
||||
uint16_t message_id_ = 0;
|
||||
|
||||
|
||||
gfx::Bitmap current_graphics_;
|
||||
|
||||
private:
|
||||
|
||||
@@ -19,53 +19,76 @@ namespace app {
|
||||
namespace zelda3 {
|
||||
namespace dungeon {
|
||||
|
||||
class DungeonObjectRenderer : public SharedROM {
|
||||
class DungeonObjectRenderer {
|
||||
public:
|
||||
|
||||
struct PseudoVram {
|
||||
std::vector<gfx::Bitmap> sheets;
|
||||
};
|
||||
|
||||
void CreateVramFromRoomBlockset() {
|
||||
auto bitmap_manager = rom()->BitmapManager();
|
||||
uint16_t room_id = 0;
|
||||
auto room_blockset = rom()->room_blockset_ids[room_id];
|
||||
|
||||
for (const auto blockset_id : room_blockset) {
|
||||
auto blockset = bitmap_manager[(uint16_t)blockset_id];
|
||||
vram_.sheets.push_back(*blockset.get());
|
||||
}
|
||||
// auto bitmap_manager = rom()->BitmapManager();
|
||||
// uint16_t room_id = 0;
|
||||
// auto room_blockset = rom()->room_blockset_ids[room_id];
|
||||
|
||||
// for (const auto blockset_id : room_blockset) {
|
||||
// auto blockset = bitmap_manager[(uint16_t)blockset_id];
|
||||
// vram_.sheets.push_back(*blockset.get());
|
||||
// }
|
||||
}
|
||||
|
||||
void RenderObjectsAsBitmaps() {
|
||||
void RenderObjectsAsBitmaps(ROM& rom) {
|
||||
memory_.Initialize(rom.vector());
|
||||
cpu.Init();
|
||||
|
||||
auto subtype1_ptr = core::subtype1_tiles;
|
||||
auto subtype1_routine_ptr =
|
||||
core::subtype1_tiles + 0x200; // Where the draw routines start
|
||||
auto subtype1_routine_ptr = core::subtype1_tiles + 0x200;
|
||||
std::array<uint16_t, 256> routine_ptrs;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
uint16_t actual_ptr = rom.toint16(subtype1_routine_ptr + (i * 2));
|
||||
routine_ptrs[i] = actual_ptr;
|
||||
std::cout << std::hex << routine_ptrs[i] << std::endl;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (const auto routine_ptr : routine_ptrs) {
|
||||
cpu.PC = routine_ptr - 2;
|
||||
cpu.PB = 0x00;
|
||||
|
||||
auto cycles_to_run = clock_.GetCycleCount();
|
||||
|
||||
while (true) {
|
||||
auto opcode = cpu.FetchByte();
|
||||
// Fetch and execute an instruction
|
||||
cpu.ExecuteInstruction(opcode);
|
||||
|
||||
// Handle any interrupts, if necessary
|
||||
cpu.HandleInterrupts();
|
||||
|
||||
// Check if the instruction is RTS
|
||||
if (opcode == 0x60) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
if (i > 50) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto subtype2_ptr = core::subtype2_tiles;
|
||||
auto subtype2_routine_ptr =
|
||||
core::subtype2_tiles + 0x80; // Where the draw routines start
|
||||
std::array<uint16_t, 128> subtype2_routine_ptrs;
|
||||
for (int i = 0; i < 128; i++) {
|
||||
subtype2_routine_ptrs[i] = subtype2_routine_ptr + i * 2;
|
||||
}
|
||||
|
||||
auto subtype3_ptr = core::subtype3_tiles;
|
||||
auto subtype3_routine_ptr =
|
||||
core::subtype3_tiles + 0x100; // Where the draw routines start
|
||||
|
||||
auto data = (*rom()).vector();
|
||||
// Construct a copy of the rooms VRAM
|
||||
// Jump to the routine that draws the object based on the ID
|
||||
// Run the routine and get the VRAM data using the CPU and PPU
|
||||
// Render the VRAM data to a bitmap
|
||||
|
||||
memory_.Initialize(data);
|
||||
cpu.PC = subtype1_routine_ptr;
|
||||
cpu.JMP(cpu.FetchWord());
|
||||
auto dest = cpu.PC + 0x10;
|
||||
while (cpu.PC < dest) {
|
||||
cpu.ExecuteInstruction(cpu.FetchByte());
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint8_t> rom_data_;
|
||||
emu::MemoryImpl memory_;
|
||||
emu::ClockImpl clock_;
|
||||
emu::CPU cpu{memory_, clock_};
|
||||
|
||||
Reference in New Issue
Block a user