Skip to content

Commit d7ff859

Browse files
f3dex split fixes (Kenix3#567)
* f3dex split fixes All credit to @KiritoDv Co-authored-by: Lywx <[email protected]> * clang format --------- Co-authored-by: Lywx <[email protected]>
1 parent 6dc4bd1 commit d7ff859

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
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

+26-18
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,31 @@ 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-
{ 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,
162172
};
163173

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));
170178
}
171179

172180
static std::string GetPathWithoutFileName(char* filePath) {
@@ -1088,9 +1096,9 @@ static void gfx_sp_matrix(uint8_t parameters, const int32_t* addr) {
10881096
#endif
10891097
}
10901098

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

10951103
if (parameters & mtx_projection) {
10961104
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
13651373
return;
13661374
}
13671375

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

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

0 commit comments

Comments
 (0)