|
8 | 8 | #include <assert.h>
|
9 | 9 | #include <stdio.h>
|
10 | 10 |
|
| 11 | +#include <any> |
11 | 12 | #include <map>
|
12 | 13 | #include <set>
|
13 | 14 | #include <unordered_map>
|
@@ -149,24 +150,31 @@ static map<string, MaskedTextureEntry> masked_textures;
|
149 | 150 |
|
150 | 151 | static UcodeHandlers ucode_handler_index = ucode_f3dex2;
|
151 | 152 |
|
152 |
| -const static std::unordered_map<Attribute, int8_t> f3dex2AttrHandler = { |
| 153 | +const static std::unordered_map<Attribute, std::any> f3dex2AttrHandler = { |
153 | 154 | { MTX_PROJECTION, F3DEX2_G_MTX_PROJECTION }, { MTX_LOAD, F3DEX2_G_MTX_LOAD }, { MTX_PUSH, F3DEX2_G_MTX_PUSH },
|
154 | 155 | { MTX_NOPUSH, F3DEX_G_MTX_NOPUSH }, { CULL_FRONT, F3DEX2_G_CULL_FRONT }, { CULL_BACK, F3DEX2_G_CULL_BACK },
|
155 |
| - { CULL_BOTH, F3DEX2_G_CULL_BOTH }, { MV_VIEWPORT, F3DEX2_G_MOVEMEM }, { MV_LIGHT, F3DEX2_G_MOVEMEM } |
| 156 | + { CULL_BOTH, F3DEX2_G_CULL_BOTH }, |
156 | 157 | };
|
157 | 158 |
|
158 |
| -const static std::unordered_map<Attribute, int8_t> f3dexAttrHandler = { |
159 |
| - { MTX_PROJECTION, F3DEX_G_MTX_PROJECTION }, { MTX_LOAD, F3DEX_G_MTX_LOAD }, { MTX_PUSH, F3DEX_G_MTX_PUSH }, |
160 |
| - { MTX_NOPUSH, F3DEX_G_MTX_NOPUSH }, { CULL_FRONT, F3DEX_G_CULL_FRONT }, { CULL_BACK, F3DEX_G_CULL_BACK }, |
161 |
| - { CULL_BOTH, F3DEX_G_CULL_BOTH }, { MV_VIEWPORT, F3DEX_G_MOVEMEM }, { MV_LIGHT, F3DEX_G_MOVEMEM } |
| 159 | +const static std::unordered_map<Attribute, std::any> f3dexAttrHandler = { { MTX_PROJECTION, F3DEX_G_MTX_PROJECTION }, |
| 160 | + { MTX_LOAD, F3DEX_G_MTX_LOAD }, |
| 161 | + { MTX_PUSH, F3DEX_G_MTX_PUSH }, |
| 162 | + { MTX_NOPUSH, F3DEX_G_MTX_NOPUSH }, |
| 163 | + { CULL_FRONT, F3DEX_G_CULL_FRONT }, |
| 164 | + { CULL_BACK, F3DEX_G_CULL_BACK }, |
| 165 | + { CULL_BOTH, F3DEX_G_CULL_BOTH } }; |
| 166 | + |
| 167 | +static constexpr std::array ucode_attr_handlers = { |
| 168 | + &f3dexAttrHandler, |
| 169 | + &f3dexAttrHandler, |
| 170 | + &f3dex2AttrHandler, |
| 171 | + &f3dex2AttrHandler, |
162 | 172 | };
|
163 | 173 |
|
164 |
| -static constexpr std::array<const std::unordered_map<Attribute, int8_t>*, ucode_max> ucode_attr_handlers = { |
165 |
| - &f3dexAttrHandler, &f3dexAttrHandler, &f3dex2AttrHandler |
166 |
| -}; |
167 |
| - |
168 |
| -static int8_t get_attr(Attribute attr) { |
169 |
| - return ucode_attr_handlers[ucode_handler_index]->at(attr); |
| 174 | +template <typename T> static constexpr T get_attr(Attribute attr) { |
| 175 | + const auto ucode_map = ucode_attr_handlers[ucode_handler_index]; |
| 176 | + assert(ucode_map->contains(attr) && "Attribute not found in the current ucode handler"); |
| 177 | + return std::any_cast<T>(ucode_map->at(attr)); |
170 | 178 | }
|
171 | 179 |
|
172 | 180 | static std::string GetPathWithoutFileName(char* filePath) {
|
@@ -1088,9 +1096,9 @@ static void gfx_sp_matrix(uint8_t parameters, const int32_t* addr) {
|
1088 | 1096 | #endif
|
1089 | 1097 | }
|
1090 | 1098 |
|
1091 |
| - const int8_t mtx_projection = get_attr(MTX_PROJECTION); |
1092 |
| - const int8_t mtx_load = get_attr(MTX_LOAD); |
1093 |
| - const int8_t mtx_push = get_attr(MTX_PUSH); |
| 1099 | + const auto mtx_projection = get_attr<int8_t>(MTX_PROJECTION); |
| 1100 | + const auto mtx_load = get_attr<int8_t>(MTX_LOAD); |
| 1101 | + const auto mtx_push = get_attr<int8_t>(MTX_PUSH); |
1094 | 1102 |
|
1095 | 1103 | if (parameters & mtx_projection) {
|
1096 | 1104 | if (parameters & mtx_load) {
|
@@ -1365,9 +1373,9 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
|
1365 | 1373 | return;
|
1366 | 1374 | }
|
1367 | 1375 |
|
1368 |
| - const int32_t cull_both = get_attr(CULL_BOTH); |
1369 |
| - const int32_t cull_front = get_attr(CULL_FRONT); |
1370 |
| - const int32_t cull_back = get_attr(CULL_BACK); |
| 1376 | + const auto cull_both = get_attr<uint32_t>(CULL_BOTH); |
| 1377 | + const auto cull_front = get_attr<uint32_t>(CULL_FRONT); |
| 1378 | + const auto cull_back = get_attr<uint32_t>(CULL_BACK); |
1371 | 1379 |
|
1372 | 1380 | if ((g_rsp.geometry_mode & cull_both) != 0) {
|
1373 | 1381 | float dx1 = v1->x / (v1->w) - v2->x / (v2->w);
|
|
0 commit comments