From 9ec8b987c773cea84f3c8fee0010bb6ec9dde026 Mon Sep 17 00:00:00 2001 From: Lywx Date: Tue, 22 Oct 2024 15:31:29 -0600 Subject: [PATCH] [Breaking Change] Make the display lists ucode aware (#693) * [Breaking Change] Make the display lists ucode aware * Fixed tidy * Added more ucodes and implemented ucode into resource * Fixed compilation * Fixed missing cases on f3d and handled end in a better way * Fixed tidy --- src/graphic/Fast3D/gfx_pc.cpp | 20 +++++++++++------- src/public/bridge/gfxbridge.h | 2 ++ src/resource/factory/DisplayListFactory.cpp | 23 ++++++++++++++++++++- src/resource/type/DisplayList.h | 3 ++- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/graphic/Fast3D/gfx_pc.cpp b/src/graphic/Fast3D/gfx_pc.cpp index 88fa2444e..18a47c3f9 100644 --- a/src/graphic/Fast3D/gfx_pc.cpp +++ b/src/graphic/Fast3D/gfx_pc.cpp @@ -166,10 +166,12 @@ const static std::unordered_map f3dexAttrHandler = { { MTX_ { CULL_BOTH, F3DEX_G_CULL_BOTH } }; static constexpr std::array ucode_attr_handlers = { - &f3dexAttrHandler, - &f3dexAttrHandler, - &f3dex2AttrHandler, - &f3dex2AttrHandler, + &f3dexAttrHandler, // ucode_f3db + &f3dexAttrHandler, // ucode_f3d + &f3dexAttrHandler, // ucode_f3dex + &f3dexAttrHandler, // ucode_f3exb + &f3dex2AttrHandler, // ucode_f3ex2 + &f3dex2AttrHandler, // ucode_s2dex }; template static constexpr T get_attr(Attribute attr) { @@ -3947,10 +3949,12 @@ static constexpr UcodeHandler s2dexHandlers = { }; static constexpr std::array ucode_handlers = { - &f3dHandlers, - &f3dexHandlers, - &f3dex2Handlers, - &s2dexHandlers, + &f3dHandlers, // ucode_f3db + &f3dHandlers, // ucode_f3d + &f3dexHandlers, // ucode_f3dex + &f3dexHandlers, // ucode_f3dexb + &f3dex2Handlers, // ucode_f3dex2 + &s2dexHandlers, // ucode_s2dex }; const char* GfxGetOpcodeName(int8_t opcode) { diff --git a/src/public/bridge/gfxbridge.h b/src/public/bridge/gfxbridge.h index e2a833a4c..64eab3727 100644 --- a/src/public/bridge/gfxbridge.h +++ b/src/public/bridge/gfxbridge.h @@ -4,8 +4,10 @@ #include "stdint.h" typedef enum UcodeHandlers { + ucode_f3db, ucode_f3d, ucode_f3dex, + ucode_f3dexb, ucode_f3dex2, ucode_s2dex, ucode_max, diff --git a/src/resource/factory/DisplayListFactory.cpp b/src/resource/factory/DisplayListFactory.cpp index 8d11e2771..14d80992a 100644 --- a/src/resource/factory/DisplayListFactory.cpp +++ b/src/resource/factory/DisplayListFactory.cpp @@ -2,6 +2,7 @@ #include "resource/type/DisplayList.h" #include "spdlog/spdlog.h" #include "libultraship/libultra/gbi.h" +#include "graphic/Fast3D/lus_gbi.h" namespace LUS { std::unordered_map renderModes = { @@ -133,6 +134,23 @@ uint32_t ResourceFactoryDisplayList::GetCombineLERPValue(const char* valStr) { return G_CCMUX_1; } +int8_t GetEndOpcodeByUCode(UcodeHandlers ucode) { + switch (ucode) { + case ucode_f3d: + case ucode_f3db: + case ucode_f3dex: + case ucode_f3dexb: + return F3DEX_G_ENDDL; + case ucode_f3dex2: + case ucode_s2dex: { + return F3DEX2_G_ENDDL; + } + case ucode_max: + break; + } + return -1; +} + std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResource(std::shared_ptr file) { if (!FileHasValidFormatAndReader(file)) { return nullptr; @@ -140,6 +158,9 @@ std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResourc auto displayList = std::make_shared(file->InitData); auto reader = std::get>(file->Reader); + auto ucode = (UcodeHandlers)reader->ReadInt8(); + + displayList->UCode = ucode; while (reader->GetBaseAddress() % 8 != 0) { reader->ReadInt8(); @@ -163,7 +184,7 @@ std::shared_ptr ResourceFactoryBinaryDisplayListV0::ReadResourc displayList->Instructions.push_back(command); } - if (opcode == (int8_t)G_ENDDL) { + if (opcode == GetEndOpcodeByUCode(ucode)) { break; } } diff --git a/src/resource/type/DisplayList.h b/src/resource/type/DisplayList.h index 4ab0a14f9..9ec95959d 100644 --- a/src/resource/type/DisplayList.h +++ b/src/resource/type/DisplayList.h @@ -2,7 +2,7 @@ #include #include "resource/Resource.h" - +#include "public/bridge/gfxbridge.h" #include namespace LUS { @@ -16,6 +16,7 @@ class DisplayList : public Ship::Resource { Gfx* GetPointer() override; size_t GetPointerSize() override; + UcodeHandlers UCode; std::vector Instructions; std::vector Strings; };