Skip to content

Commit 90ca0d7

Browse files
briaguya-aiKiritoDv
andcommitted
f3dex split fixes
All credit to @KiritoDv Co-authored-by: Lywx <[email protected]>
1 parent c2555d1 commit 90ca0d7

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

src/graphic/Fast3D/f3dex.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ constexpr int8_t F3DEX_G_MTX_PUSH = 0x04;
7272
*
7373
*/
7474

75-
constexpr int32_t F3DEX_G_CLIPPING = 0x00800000;
76-
constexpr int32_t F3DEX_G_TEXTURE_ENABLE = 0x00000002;
77-
constexpr int32_t F3DEX_G_SHADING_SMOOTH = 0x00000200;
78-
constexpr int32_t F3DEX_G_CULL_FRONT = 0x00001000;
79-
constexpr int32_t F3DEX_G_CULL_BACK = 0x00002000;
80-
constexpr int32_t F3DEX_G_CULL_BOTH = 0x00003000;
75+
constexpr uint32_t F3DEX_G_CLIPPING = 0x00800000;
76+
constexpr uint32_t F3DEX_G_TEXTURE_ENABLE = 0x00000002;
77+
constexpr uint32_t F3DEX_G_SHADING_SMOOTH = 0x00000200;
78+
constexpr uint32_t F3DEX_G_CULL_FRONT = 0x00001000;
79+
constexpr uint32_t F3DEX_G_CULL_BACK = 0x00002000;
80+
constexpr uint32_t F3DEX_G_CULL_BOTH = 0x00003000;
8181

8282
/*
8383
* MOVEMEM indices

src/graphic/Fast3D/f3dex2.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ constexpr int8_t F3DEX2_G_MTX_PUSH = 0x01;
6464
* See the man page for gSP1Triangle().
6565
*
6666
*/
67-
constexpr int32_t F3DEX2_G_CLIPPING = 0x00800000;
68-
constexpr int32_t F3DEX2_G_TEXTURE_ENABLE = 0x00000000;
69-
constexpr int32_t F3DEX2_G_SHADING_SMOOTH = 0x00200000;
70-
constexpr int32_t F3DEX2_G_CULL_FRONT = 0x00000200;
71-
constexpr int32_t F3DEX2_G_CULL_BACK = 0x00000400;
72-
constexpr int32_t F3DEX2_G_CULL_BOTH = 0x00000600;
67+
constexpr uint32_t F3DEX2_G_CLIPPING = 0x00800000;
68+
constexpr uint32_t F3DEX2_G_TEXTURE_ENABLE = 0x00000000;
69+
constexpr uint32_t F3DEX2_G_SHADING_SMOOTH = 0x00200000;
70+
constexpr uint32_t F3DEX2_G_CULL_FRONT = 0x00000200;
71+
constexpr uint32_t F3DEX2_G_CULL_BACK = 0x00000400;
72+
constexpr uint32_t F3DEX2_G_CULL_BOTH = 0x00000600;
7373

7474
/*
7575
* MOVEMEM indices

src/graphic/Fast3D/gfx_pc.cpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <assert.h>
99
#include <stdio.h>
1010

11+
#include <any>
1112
#include <map>
1213
#include <set>
1314
#include <unordered_map>
@@ -149,24 +150,27 @@ static map<string, MaskedTextureEntry> masked_textures;
149150

150151
static UcodeHandlers ucode_handler_index = ucode_f3dex2;
151152

152-
const static std::unordered_map<Attribute, int8_t> f3dex2AttrHandler = {
153+
const static std::unordered_map<Attribute, std::any> f3dex2AttrHandler = {
153154
{ MTX_PROJECTION, F3DEX2_G_MTX_PROJECTION }, { MTX_LOAD, F3DEX2_G_MTX_LOAD }, { MTX_PUSH, F3DEX2_G_MTX_PUSH },
154155
{ 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 },
156157
};
157158

158-
const static std::unordered_map<Attribute, int8_t> f3dexAttrHandler = {
159+
const static std::unordered_map<Attribute, std::any> f3dexAttrHandler = {
159160
{ MTX_PROJECTION, F3DEX_G_MTX_PROJECTION }, { MTX_LOAD, F3DEX_G_MTX_LOAD }, { MTX_PUSH, F3DEX_G_MTX_PUSH },
160161
{ 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 }
162163
};
163164

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,
166167
};
167168

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));
170174
}
171175

172176
static std::string GetPathWithoutFileName(char* filePath) {
@@ -1088,9 +1092,9 @@ static void gfx_sp_matrix(uint8_t parameters, const int32_t* addr) {
10881092
#endif
10891093
}
10901094

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);
10941098

10951099
if (parameters & mtx_projection) {
10961100
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
13651369
return;
13661370
}
13671371

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);
13711375

13721376
if ((g_rsp.geometry_mode & cull_both) != 0) {
13731377
float dx1 = v1->x / (v1->w) - v2->x / (v2->w);

0 commit comments

Comments
 (0)