|
1 | 1 | #include "resource/factory/DisplayListFactory.h"
|
2 | 2 | #include "resource/type/DisplayList.h"
|
| 3 | +#include "resource/readerbox/BinaryReaderBox.h" |
| 4 | +#include "resource/readerbox/XMLReaderBox.h" |
3 | 5 | #include "spdlog/spdlog.h"
|
4 | 6 |
|
5 | 7 | #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
|
6 | 8 |
|
7 | 9 | namespace LUS {
|
8 |
| -std::shared_ptr<IResource> DisplayListFactory::ReadResource(std::shared_ptr<ResourceInitData> initData, |
9 |
| - std::shared_ptr<BinaryReader> reader) { |
10 |
| - auto resource = std::make_shared<DisplayList>(initData); |
11 |
| - std::shared_ptr<ResourceVersionFactory> factory = nullptr; |
12 |
| - |
13 |
| - switch (resource->GetInitData()->ResourceVersion) { |
14 |
| - case 0: |
15 |
| - factory = std::make_shared<DisplayListFactoryV0>(); |
16 |
| - break; |
17 |
| - } |
18 |
| - |
19 |
| - if (factory == nullptr) { |
20 |
| - SPDLOG_ERROR("Failed to load DisplayList with version {}", resource->GetInitData()->ResourceVersion); |
| 10 | +std::shared_ptr<IResource> ResourceFactoryBinaryDisplayListV0::ReadResource(std::shared_ptr<ResourceInitData> initData, |
| 11 | + std::shared_ptr<ReaderBox> readerBox) { |
| 12 | + auto binaryReaderBox = std::dynamic_pointer_cast<BinaryReaderBox>(readerBox); |
| 13 | + if (binaryReaderBox == nullptr) { |
| 14 | + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); |
21 | 15 | return nullptr;
|
22 | 16 | }
|
23 | 17 |
|
24 |
| - factory->ParseFileBinary(reader, resource); |
25 |
| - |
26 |
| - return resource; |
27 |
| -} |
28 |
| - |
29 |
| -std::shared_ptr<IResource> DisplayListFactory::ReadResourceXML(std::shared_ptr<ResourceInitData> initData, |
30 |
| - tinyxml2::XMLElement* reader) { |
31 |
| - auto resource = std::make_shared<DisplayList>(initData); |
32 |
| - std::shared_ptr<ResourceVersionFactory> factory = nullptr; |
33 |
| - |
34 |
| - switch (resource->GetInitData()->ResourceVersion) { |
35 |
| - case 0: |
36 |
| - factory = std::make_shared<DisplayListFactoryV0>(); |
37 |
| - break; |
38 |
| - } |
39 |
| - |
40 |
| - if (factory == nullptr) { |
41 |
| - SPDLOG_ERROR("Failed to load DisplayList with version {}", resource->GetInitData()->ResourceVersion); |
| 18 | + auto reader = binaryReaderBox->GetReader(); |
| 19 | + if (reader == nullptr) { |
| 20 | + SPDLOG_ERROR("null reader in box."); |
42 | 21 | return nullptr;
|
43 | 22 | }
|
44 | 23 |
|
45 |
| - factory->ParseFileXML(reader, resource); |
46 |
| - |
47 |
| - return resource; |
48 |
| -} |
49 |
| - |
50 |
| -void DisplayListFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) { |
51 |
| - std::shared_ptr<DisplayList> displayList = std::static_pointer_cast<DisplayList>(resource); |
52 |
| - ResourceVersionFactory::ParseFileBinary(reader, displayList); |
| 24 | + auto displayList = std::make_shared<DisplayList>(initData); |
53 | 25 |
|
54 | 26 | while (reader->GetBaseAddress() % 8 != 0) {
|
55 | 27 | reader->ReadInt8();
|
@@ -77,60 +49,25 @@ void DisplayListFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader,
|
77 | 49 | break;
|
78 | 50 | }
|
79 | 51 | }
|
80 |
| -} |
81 |
| - |
82 |
| -std::unordered_map<std::string, uint32_t> renderModes = { { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, |
83 |
| - { "G_RM_AA_ZB_OPA_SURF", G_RM_AA_ZB_OPA_SURF }, |
84 |
| - { "G_RM_AA_ZB_OPA_DECAL", G_RM_AA_ZB_OPA_DECAL }, |
85 |
| - { "G_RM_AA_ZB_OPA_INTER", G_RM_AA_ZB_OPA_INTER }, |
86 |
| - { "G_RM_AA_ZB_TEX_EDGE", G_RM_AA_ZB_TEX_EDGE }, |
87 |
| - { "G_RM_AA_ZB_XLU_SURF", G_RM_AA_ZB_XLU_SURF }, |
88 |
| - { "G_RM_AA_ZB_XLU_DECAL", G_RM_AA_ZB_XLU_DECAL }, |
89 |
| - { "G_RM_AA_ZB_XLU_INTER", G_RM_AA_ZB_XLU_INTER }, |
90 |
| - { "G_RM_FOG_SHADE_A", G_RM_FOG_SHADE_A }, |
91 |
| - { "G_RM_FOG_PRIM_A", G_RM_FOG_PRIM_A }, |
92 |
| - { "G_RM_PASS", G_RM_PASS }, |
93 |
| - { "G_RM_ADD", G_RM_ADD }, |
94 |
| - { "G_RM_NOOP", G_RM_NOOP }, |
95 |
| - { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, |
96 |
| - { "G_RM_ZB_OPA_DECAL", G_RM_ZB_OPA_DECAL }, |
97 |
| - { "G_RM_ZB_XLU_SURF", G_RM_ZB_XLU_SURF }, |
98 |
| - { "G_RM_ZB_XLU_DECAL", G_RM_ZB_XLU_DECAL }, |
99 |
| - { "G_RM_OPA_SURF", G_RM_OPA_SURF }, |
100 |
| - { "G_RM_ZB_CLD_SURF", G_RM_ZB_CLD_SURF }, |
101 |
| - { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, |
102 |
| - { "G_RM_AA_ZB_OPA_SURF2", G_RM_AA_ZB_OPA_SURF2 }, |
103 |
| - { "G_RM_AA_ZB_OPA_DECAL2", G_RM_AA_ZB_OPA_DECAL2 }, |
104 |
| - { "G_RM_AA_ZB_OPA_INTER2", G_RM_AA_ZB_OPA_INTER2 }, |
105 |
| - { "G_RM_AA_ZB_TEX_EDGE2", G_RM_AA_ZB_TEX_EDGE2 }, |
106 |
| - { "G_RM_AA_ZB_XLU_SURF2", G_RM_AA_ZB_XLU_SURF2 }, |
107 |
| - { "G_RM_AA_ZB_XLU_DECAL2", G_RM_AA_ZB_XLU_DECAL2 }, |
108 |
| - { "G_RM_AA_ZB_XLU_INTER2", G_RM_AA_ZB_XLU_INTER2 }, |
109 |
| - { "G_RM_ADD2", G_RM_ADD2 }, |
110 |
| - { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, |
111 |
| - { "G_RM_ZB_OPA_DECAL2", G_RM_ZB_OPA_DECAL2 }, |
112 |
| - { "G_RM_ZB_XLU_SURF2", G_RM_ZB_XLU_SURF2 }, |
113 |
| - { "G_RM_ZB_XLU_DECAL2", G_RM_ZB_XLU_DECAL2 }, |
114 |
| - { "G_RM_ZB_CLD_SURF2", G_RM_ZB_CLD_SURF2 } }; |
115 |
| - |
116 |
| -static Gfx GsSpVertexOtR2P1(char* filePathPtr) { |
117 |
| - Gfx g; |
118 |
| - g.words.w0 = G_VTX_OTR_FILEPATH << 24; |
119 |
| - g.words.w1 = (uintptr_t)filePathPtr; |
120 | 52 |
|
121 |
| - return g; |
| 53 | + return displayList; |
122 | 54 | }
|
123 | 55 |
|
124 |
| -static Gfx GsSpVertexOtR2P2(int vtxCnt, int vtxBufOffset, int vtxDataOffset) { |
125 |
| - Gfx g; |
126 |
| - g.words.w0 = (uintptr_t)vtxCnt; |
127 |
| - g.words.w1 = (uintptr_t)((vtxBufOffset << 16) | vtxDataOffset); |
| 56 | +std::shared_ptr<IResource> ResourceFactoryXMLDisplayListV0::ReadResource(std::shared_ptr<ResourceInitData> initData, |
| 57 | + std::shared_ptr<ReaderBox> readerBox) { |
| 58 | + auto xmlReaderBox = std::dynamic_pointer_cast<XMLReaderBox>(readerBox); |
| 59 | + if (xmlReaderBox == nullptr) { |
| 60 | + SPDLOG_ERROR("ReaderBox must be an XMLReaderBox."); |
| 61 | + return nullptr; |
| 62 | + } |
128 | 63 |
|
129 |
| - return g; |
130 |
| -} |
| 64 | + auto reader = xmlReaderBox->GetReader(); |
| 65 | + if (reader == nullptr) { |
| 66 | + SPDLOG_ERROR("null reader in box."); |
| 67 | + return nullptr; |
| 68 | + } |
131 | 69 |
|
132 |
| -void DisplayListFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::shared_ptr<IResource> resource) { |
133 |
| - std::shared_ptr<DisplayList> dl = std::static_pointer_cast<DisplayList>(resource); |
| 70 | + auto dl = std::make_shared<DisplayList>(initData); |
134 | 71 |
|
135 | 72 | auto child = reader->FirstChildElement();
|
136 | 73 |
|
@@ -1031,9 +968,61 @@ void DisplayListFactoryV0::ParseFileXML(tinyxml2::XMLElement* reader, std::share
|
1031 | 968 |
|
1032 | 969 | child = child->NextSiblingElement();
|
1033 | 970 | }
|
| 971 | + |
| 972 | + return displayList; |
| 973 | +} |
| 974 | + |
| 975 | +std::unordered_map<std::string, uint32_t> renderModes = { { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, |
| 976 | + { "G_RM_AA_ZB_OPA_SURF", G_RM_AA_ZB_OPA_SURF }, |
| 977 | + { "G_RM_AA_ZB_OPA_DECAL", G_RM_AA_ZB_OPA_DECAL }, |
| 978 | + { "G_RM_AA_ZB_OPA_INTER", G_RM_AA_ZB_OPA_INTER }, |
| 979 | + { "G_RM_AA_ZB_TEX_EDGE", G_RM_AA_ZB_TEX_EDGE }, |
| 980 | + { "G_RM_AA_ZB_XLU_SURF", G_RM_AA_ZB_XLU_SURF }, |
| 981 | + { "G_RM_AA_ZB_XLU_DECAL", G_RM_AA_ZB_XLU_DECAL }, |
| 982 | + { "G_RM_AA_ZB_XLU_INTER", G_RM_AA_ZB_XLU_INTER }, |
| 983 | + { "G_RM_FOG_SHADE_A", G_RM_FOG_SHADE_A }, |
| 984 | + { "G_RM_FOG_PRIM_A", G_RM_FOG_PRIM_A }, |
| 985 | + { "G_RM_PASS", G_RM_PASS }, |
| 986 | + { "G_RM_ADD", G_RM_ADD }, |
| 987 | + { "G_RM_NOOP", G_RM_NOOP }, |
| 988 | + { "G_RM_ZB_OPA_SURF", G_RM_ZB_OPA_SURF }, |
| 989 | + { "G_RM_ZB_OPA_DECAL", G_RM_ZB_OPA_DECAL }, |
| 990 | + { "G_RM_ZB_XLU_SURF", G_RM_ZB_XLU_SURF }, |
| 991 | + { "G_RM_ZB_XLU_DECAL", G_RM_ZB_XLU_DECAL }, |
| 992 | + { "G_RM_OPA_SURF", G_RM_OPA_SURF }, |
| 993 | + { "G_RM_ZB_CLD_SURF", G_RM_ZB_CLD_SURF }, |
| 994 | + { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, |
| 995 | + { "G_RM_AA_ZB_OPA_SURF2", G_RM_AA_ZB_OPA_SURF2 }, |
| 996 | + { "G_RM_AA_ZB_OPA_DECAL2", G_RM_AA_ZB_OPA_DECAL2 }, |
| 997 | + { "G_RM_AA_ZB_OPA_INTER2", G_RM_AA_ZB_OPA_INTER2 }, |
| 998 | + { "G_RM_AA_ZB_TEX_EDGE2", G_RM_AA_ZB_TEX_EDGE2 }, |
| 999 | + { "G_RM_AA_ZB_XLU_SURF2", G_RM_AA_ZB_XLU_SURF2 }, |
| 1000 | + { "G_RM_AA_ZB_XLU_DECAL2", G_RM_AA_ZB_XLU_DECAL2 }, |
| 1001 | + { "G_RM_AA_ZB_XLU_INTER2", G_RM_AA_ZB_XLU_INTER2 }, |
| 1002 | + { "G_RM_ADD2", G_RM_ADD2 }, |
| 1003 | + { "G_RM_ZB_OPA_SURF2", G_RM_ZB_OPA_SURF2 }, |
| 1004 | + { "G_RM_ZB_OPA_DECAL2", G_RM_ZB_OPA_DECAL2 }, |
| 1005 | + { "G_RM_ZB_XLU_SURF2", G_RM_ZB_XLU_SURF2 }, |
| 1006 | + { "G_RM_ZB_XLU_DECAL2", G_RM_ZB_XLU_DECAL2 }, |
| 1007 | + { "G_RM_ZB_CLD_SURF2", G_RM_ZB_CLD_SURF2 } }; |
| 1008 | + |
| 1009 | +static Gfx GsSpVertexOtR2P1(char* filePathPtr) { |
| 1010 | + Gfx g; |
| 1011 | + g.words.w0 = G_VTX_OTR_FILEPATH << 24; |
| 1012 | + g.words.w1 = (uintptr_t)filePathPtr; |
| 1013 | + |
| 1014 | + return g; |
| 1015 | +} |
| 1016 | + |
| 1017 | +static Gfx GsSpVertexOtR2P2(int vtxCnt, int vtxBufOffset, int vtxDataOffset) { |
| 1018 | + Gfx g; |
| 1019 | + g.words.w0 = (uintptr_t)vtxCnt; |
| 1020 | + g.words.w1 = (uintptr_t)((vtxBufOffset << 16) | vtxDataOffset); |
| 1021 | + |
| 1022 | + return g; |
1034 | 1023 | }
|
1035 | 1024 |
|
1036 |
| -uint32_t DisplayListFactoryV0::GetCombineLERPValue(std::string valStr) { |
| 1025 | +uint32_t ResourceFactoryDisplayList::GetCombineLERPValue(std::string valStr) { |
1037 | 1026 | std::string strings[] = { "G_CCMUX_COMBINED",
|
1038 | 1027 | "G_CCMUX_TEXEL0",
|
1039 | 1028 | "G_CCMUX_TEXEL1",
|
|
0 commit comments