Use constants for material sort key names

This commit is contained in:
Jan 2022-07-23 13:05:37 +02:00
parent ea79e60856
commit 92d808b7a4
3 changed files with 97 additions and 66 deletions

View File

@ -880,6 +880,8 @@ namespace IW4
// water related = 19, // maybe underwater // water related = 19, // maybe underwater
// water related = 20, // maybe transparent water // water related = 20, // maybe transparent water
// ? = 21, // ? = 21,
// - = 22,
// - = 23,
SORTKEY_WINDOW_INSIDE = 24, // prob window inside SORTKEY_WINDOW_INSIDE = 24, // prob window inside
SORTKEY_WINDOW_OUTSIDE = 25, // prob window outside SORTKEY_WINDOW_OUTSIDE = 25, // prob window outside
// ? = 26, // includes motiontracker3d, impact fx, atmos // ? = 26, // includes motiontracker3d, impact fx, atmos
@ -888,18 +890,30 @@ namespace IW4
// ? = 29, // ? = 29,
// ? = 30, // ? = 30,
// ? = 31, // ? = 31,
// - = 32,
// ? = 33, // ? = 33,
// some ui/2d/fullscreen sort = 34, // some ui/2d/fullscreen sort = 34,
// - = 35,
// - = 36,
// - = 37,
// - = 38,
// - = 39,
// - = 40,
// framecolordebug = 41, // multiplicative? // framecolordebug = 41, // multiplicative?
// - = 42,
SORTKEY_DISTORTION = 43, SORTKEY_DISTORTION = 43,
// ? = 44, // ? = 44,
// ? = 45, // ? = 45,
// - = 46,
SORTKEY_BLEND_ADDITIVE = 47, // most likely blend / additive SORTKEY_BLEND_ADDITIVE = 47, // most likely blend / additive
SORTKEY_EFFECT_AUTO_SORT = 48, // most likely effect - auto sort SORTKEY_EFFECT_AUTO_SORT = 48, // most likely effect - auto sort
SORTKEY_AFTER_EFFECTS_BOTTOM = 49, SORTKEY_AFTER_EFFECTS_BOTTOM = 49,
SORTKEY_AFTER_EFFECTS_MIDDLE = 50, // prob after effects - middle SORTKEY_AFTER_EFFECTS_MIDDLE = 50, // prob after effects - middle
SORTKEY_AFTER_EFFECTS_TOP = 51, // prob after effects - top SORTKEY_AFTER_EFFECTS_TOP = 51, // prob after effects - top
// - = 52,
SORTKEY_VIEWMODEL_EFFECT = 53, // maybe viewmodel effect SORTKEY_VIEWMODEL_EFFECT = 53, // maybe viewmodel effect
SORTKEY_MAX
}; };
struct MaterialInfo struct MaterialInfo

View File

@ -361,4 +361,63 @@ namespace IW4
"Decr" "Decr"
}; };
static_assert(std::extent_v<decltype(GdtStencilOpNames)> == static_cast<size_t>(StencilOp_e::COUNT)); static_assert(std::extent_v<decltype(GdtStencilOpNames)> == static_cast<size_t>(StencilOp_e::COUNT));
inline const char* SortKeyNames[]
{
"opaque ambient", // 0
"opaque", // 1
"sky", // 2
"skybox", // 3
"?", // 4
"?", // 5
"decal - bottom 1", // 6
"decal - bottom 2", // 7
"decal - bottom 3", // 8
"decal - static decal", // 9
"decal - middle 1", // 10
"decal - middle 2", // 11
"decal - middle 3", // 12
"decal - weapon impact", // 13
"?", // 14
"?", // 15
"?", // 16
"?", // 17
"?", // 18
"?", // 19
"?", // 20
"?", // 21
"-", // 22
"-", // 23
"window inside", // 24
"window outside", // 25
"?", // 26
"?", // 27
"?", // 28
"?", // 29
"?", // 30
"?", // 31
"?", // 32
"?", // 33
"?", // 34
"?", // 35
"?", // 36
"?", // 37
"?", // 38
"?", // 39
"?", // 40
"?", // 41
"?", // 42
"distortion", // 43
"?", // 44
"?", // 45
"-", // 46
"blend / additive", // 47
"effect - auto sort", // 48
"after effects - bottom", // 49
"after effects - middle", // 50
"after effects - top", // 51
"-", // 52
"viewmodel effect", // 53
};
static_assert(std::extent_v<decltype(SortKeyNames)> == static_cast<size_t>(SORTKEY_MAX));
} }

View File

@ -8,6 +8,7 @@
#include "AssetLoading/AbstractGdtEntryReader.h" #include "AssetLoading/AbstractGdtEntryReader.h"
#include "Game/IW4/CommonIW4.h" #include "Game/IW4/CommonIW4.h"
#include "Game/IW4/IW4.h" #include "Game/IW4/IW4.h"
#include "Game/IW4/MaterialConstantsIW4.h"
#include "Game/IW4/ObjConstantsIW4.h" #include "Game/IW4/ObjConstantsIW4.h"
#include "Pool/GlobalAssetPool.h" #include "Pool/GlobalAssetPool.h"
@ -280,82 +281,39 @@ namespace IW4
if (sort.empty() || sort == "<default>") if (sort.empty() || sort == "<default>")
{ {
if (materialType == "distortion") if (materialType == "distortion")
sortKey = "distortion"; sortKey = SortKeyNames[SORTKEY_DISTORTION];
else if (polygonOffset == "Static Decal") else if (polygonOffset == "Static Decal")
sortKey = "decal - static decal"; sortKey = SortKeyNames[SORTKEY_DECAL_STATIC_DECAL];
else if (polygonOffset == "Weapon Impact") else if (polygonOffset == "Weapon Impact")
sortKey = "decal - weapon impact"; sortKey = SortKeyNames[SORTKEY_DECAL_WEAPON_IMPACT];
else if (materialType == "effect") else if (materialType == "effect")
sortKey = "effect - auto sort"; sortKey = SortKeyNames[SORTKEY_EFFECT_AUTO_SORT];
else if (materialType == "objective" || blendFunc == "Blend" || blendFunc == "Add" || blendFunc == "Screen Add") else if (materialType == "objective" || blendFunc == "Blend" || blendFunc == "Add" || blendFunc == "Screen Add")
sortKey = "blend / additive"; sortKey = SortKeyNames[SORTKEY_BLEND_ADDITIVE];
else if (blendFunc == "Multiply") // else if (blendFunc == "Multiply")
sortKey = "multiplicative"; // sortKey = SortKeyNames[SORTKEY_MULTIPLICATIVE];
else if (materialType == "sky") else if (materialType == "sky")
sortKey = "sky"; sortKey = SortKeyNames[SORTKEY_SKY];
else if (materialType == "model ambient") else if (materialType == "model ambient")
sortKey = "opaque ambient"; sortKey = SortKeyNames[SORTKEY_OPAQUE_AMBIENT];
else else
sortKey = "opaque"; sortKey = SortKeyNames[SORTKEY_OPAQUE];
} }
else else
sortKey = sort; sortKey = sort;
// if (sortKey == "opaque water") bool foundSortKey = false;
// SetSort(?); for (auto sortKeyIndex = 0u; sortKeyIndex < SORTKEY_MAX; sortKeyIndex++)
// else if (sortKey == "boat hull") {
// SetSort(?); if (sortKey == SortKeyNames[sortKeyIndex])
if (sortKey == "opaque ambient") {
SetSort(SORTKEY_OPAQUE_AMBIENT); SetSort(static_cast<unsigned char>(sortKeyIndex));
else if (sortKey == "opaque") foundSortKey = true;
SetSort(SORTKEY_OPAQUE); break;
else if (sortKey == "sky") }
SetSort(SORTKEY_SKY); }
else if (sortKey == "skybox")
SetSort(SORTKEY_SKYBOX); if (!foundSortKey)
else if (sortKey == "decal - bottom 1")
SetSort(SORTKEY_DECAL_BOTTOM_1);
else if (sortKey == "decal - bottom 2")
SetSort(SORTKEY_DECAL_BOTTOM_2);
else if (sortKey == "decal - bottom 3")
SetSort(SORTKEY_DECAL_BOTTOM_3);
else if (sortKey == "decal - static decal")
SetSort(SORTKEY_DECAL_STATIC_DECAL);
else if (sortKey == "decal - middle 1")
SetSort(SORTKEY_DECAL_MIDDLE_1);
else if (sortKey == "decal - middle 2")
SetSort(SORTKEY_DECAL_MIDDLE_2);
else if (sortKey == "decal - middle 3")
SetSort(SORTKEY_DECAL_MIDDLE_3);
else if (sortKey == "decal - weapon impact")
SetSort(SORTKEY_DECAL_WEAPON_IMPACT);
// else if (sortKey == "decal - top 1")
// SetSort(SORTKEY_DECAL_TOP_1);
// else if (sortKey == "decal - top 2")
// SetSort(SORTKEY_DECAL_TOP_2);
// else if (sortKey == "decal - top 3")
// SetSort(SORTKEY_DECAL_TOP_3);
// else if (sortKey == "multiplicative")
// SetSort(SORTKEY_MULTIPLICATIVE);
else if (sortKey == "window inside")
SetSort(SORTKEY_WINDOW_INSIDE);
else if (sortKey == "window outside")
SetSort(SORTKEY_WINDOW_OUTSIDE);
else if (sortKey == "distortion")
SetSort(SORTKEY_DISTORTION);
else if (sortKey == "blend / additive")
SetSort(SORTKEY_BLEND_ADDITIVE);
else if (sortKey == "effect - auto sort")
SetSort(SORTKEY_EFFECT_AUTO_SORT);
else if (sortKey == "after effects - bottom")
SetSort(SORTKEY_AFTER_EFFECTS_BOTTOM);
else if (sortKey == "after effects - middle")
SetSort(SORTKEY_AFTER_EFFECTS_MIDDLE);
else if (sortKey == "after effects - top")
SetSort(SORTKEY_AFTER_EFFECTS_TOP);
else if (sortKey == "viewmodel effect")
SetSort(SORTKEY_VIEWMODEL_EFFECT);
else
{ {
char* endPtr; char* endPtr;
const auto sortKeyNum = strtoul(sortKey.c_str(), &endPtr, 10); const auto sortKeyNum = strtoul(sortKey.c_str(), &endPtr, 10);
@ -422,7 +380,7 @@ namespace IW4
m_textures.push_back(textureDef); m_textures.push_back(textureDef);
} }
void SetSort(const unsigned char sort) void SetSort(const unsigned char sort) const
{ {
m_material->info.sortKey = sort; m_material->info.sortKey = sort;
} }