|
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,27 @@ 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 | +const static std::unordered_map<Attribute, std::any> f3dexAttrHandler = { |
159 | 160 | { MTX_PROJECTION, F3DEX_G_MTX_PROJECTION }, { MTX_LOAD, F3DEX_G_MTX_LOAD }, { MTX_PUSH, F3DEX_G_MTX_PUSH },
|
160 | 161 | { 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 } |
| 162 | + { CULL_BOTH, F3DEX_G_CULL_BOTH } |
162 | 163 | };
|
163 | 164 |
|
164 |
| -static constexpr std::array<const std::unordered_map<Attribute, int8_t>*, ucode_max> ucode_attr_handlers = { |
165 |
| - &f3dexAttrHandler, &f3dexAttrHandler, &f3dex2AttrHandler |
| 165 | +static constexpr std::array ucode_attr_handlers = { |
| 166 | + &f3dexAttrHandler, &f3dexAttrHandler, &f3dex2AttrHandler, &f3dex2AttrHandler, |
166 | 167 | };
|
167 | 168 |
|
168 |
| -static int8_t get_attr(Attribute attr) { |
169 |
| - return ucode_attr_handlers[ucode_handler_index]->at(attr); |
| 169 | +template <typename T> |
| 170 | +static constexpr T get_attr(Attribute attr) { |
| 171 | + const auto ucode_map = ucode_attr_handlers[ucode_handler_index]; |
| 172 | + assert(ucode_map->contains(attr) && "Attribute not found in the current ucode handler"); |
| 173 | + return std::any_cast<T>(ucode_map->at(attr)); |
170 | 174 | }
|
171 | 175 |
|
172 | 176 | static std::string GetPathWithoutFileName(char* filePath) {
|
@@ -1088,9 +1092,9 @@ static void gfx_sp_matrix(uint8_t parameters, const int32_t* addr) {
|
1088 | 1092 | #endif
|
1089 | 1093 | }
|
1090 | 1094 |
|
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); |
| 1095 | + const auto mtx_projection = get_attr<int8_t>(MTX_PROJECTION); |
| 1096 | + const auto mtx_load = get_attr<int8_t>(MTX_LOAD); |
| 1097 | + const auto mtx_push = get_attr<int8_t>(MTX_PUSH); |
1094 | 1098 |
|
1095 | 1099 | if (parameters & mtx_projection) {
|
1096 | 1100 | if (parameters & mtx_load) {
|
@@ -1365,9 +1369,9 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
|
1365 | 1369 | return;
|
1366 | 1370 | }
|
1367 | 1371 |
|
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); |
| 1372 | + const auto cull_both = get_attr<uint32_t>(CULL_BOTH); |
| 1373 | + const auto cull_front = get_attr<uint32_t>(CULL_FRONT); |
| 1374 | + const auto cull_back = get_attr<uint32_t>(CULL_BACK); |
1371 | 1375 |
|
1372 | 1376 | if ((g_rsp.geometry_mode & cull_both) != 0) {
|
1373 | 1377 | float dx1 = v1->x / (v1->w) - v2->x / (v2->w);
|
|
0 commit comments