From 92d808b7a4d03676de9ea14a8ce3aee435917cd1 Mon Sep 17 00:00:00 2001 From: Jan Date: Sat, 23 Jul 2022 13:05:37 +0200 Subject: [PATCH] Use constants for material sort key names --- src/Common/Game/IW4/IW4_Assets.h | 14 +++ src/ObjCommon/Game/IW4/MaterialConstantsIW4.h | 59 ++++++++++++ .../IW4/AssetLoaders/AssetLoaderMaterial.cpp | 90 +++++-------------- 3 files changed, 97 insertions(+), 66 deletions(-) diff --git a/src/Common/Game/IW4/IW4_Assets.h b/src/Common/Game/IW4/IW4_Assets.h index d42951d8..2e54ae8d 100644 --- a/src/Common/Game/IW4/IW4_Assets.h +++ b/src/Common/Game/IW4/IW4_Assets.h @@ -880,6 +880,8 @@ namespace IW4 // water related = 19, // maybe underwater // water related = 20, // maybe transparent water // ? = 21, + // - = 22, + // - = 23, SORTKEY_WINDOW_INSIDE = 24, // prob window inside SORTKEY_WINDOW_OUTSIDE = 25, // prob window outside // ? = 26, // includes motiontracker3d, impact fx, atmos @@ -888,18 +890,30 @@ namespace IW4 // ? = 29, // ? = 30, // ? = 31, + // - = 32, // ? = 33, // some ui/2d/fullscreen sort = 34, + // - = 35, + // - = 36, + // - = 37, + // - = 38, + // - = 39, + // - = 40, // framecolordebug = 41, // multiplicative? + // - = 42, SORTKEY_DISTORTION = 43, // ? = 44, // ? = 45, + // - = 46, SORTKEY_BLEND_ADDITIVE = 47, // most likely blend / additive SORTKEY_EFFECT_AUTO_SORT = 48, // most likely effect - auto sort SORTKEY_AFTER_EFFECTS_BOTTOM = 49, SORTKEY_AFTER_EFFECTS_MIDDLE = 50, // prob after effects - middle SORTKEY_AFTER_EFFECTS_TOP = 51, // prob after effects - top + // - = 52, SORTKEY_VIEWMODEL_EFFECT = 53, // maybe viewmodel effect + + SORTKEY_MAX }; struct MaterialInfo diff --git a/src/ObjCommon/Game/IW4/MaterialConstantsIW4.h b/src/ObjCommon/Game/IW4/MaterialConstantsIW4.h index 748b60f3..237380b5 100644 --- a/src/ObjCommon/Game/IW4/MaterialConstantsIW4.h +++ b/src/ObjCommon/Game/IW4/MaterialConstantsIW4.h @@ -361,4 +361,63 @@ namespace IW4 "Decr" }; static_assert(std::extent_v == static_cast(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 == static_cast(SORTKEY_MAX)); } diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp index 3235d1f9..a3876390 100644 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp +++ b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderMaterial.cpp @@ -8,6 +8,7 @@ #include "AssetLoading/AbstractGdtEntryReader.h" #include "Game/IW4/CommonIW4.h" #include "Game/IW4/IW4.h" +#include "Game/IW4/MaterialConstantsIW4.h" #include "Game/IW4/ObjConstantsIW4.h" #include "Pool/GlobalAssetPool.h" @@ -280,82 +281,39 @@ namespace IW4 if (sort.empty() || sort == "") { if (materialType == "distortion") - sortKey = "distortion"; + sortKey = SortKeyNames[SORTKEY_DISTORTION]; else if (polygonOffset == "Static Decal") - sortKey = "decal - static decal"; + sortKey = SortKeyNames[SORTKEY_DECAL_STATIC_DECAL]; else if (polygonOffset == "Weapon Impact") - sortKey = "decal - weapon impact"; + sortKey = SortKeyNames[SORTKEY_DECAL_WEAPON_IMPACT]; 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") - sortKey = "blend / additive"; - else if (blendFunc == "Multiply") - sortKey = "multiplicative"; + sortKey = SortKeyNames[SORTKEY_BLEND_ADDITIVE]; + // else if (blendFunc == "Multiply") + // sortKey = SortKeyNames[SORTKEY_MULTIPLICATIVE]; else if (materialType == "sky") - sortKey = "sky"; + sortKey = SortKeyNames[SORTKEY_SKY]; else if (materialType == "model ambient") - sortKey = "opaque ambient"; + sortKey = SortKeyNames[SORTKEY_OPAQUE_AMBIENT]; else - sortKey = "opaque"; + sortKey = SortKeyNames[SORTKEY_OPAQUE]; } else sortKey = sort; - // if (sortKey == "opaque water") - // SetSort(?); - // else if (sortKey == "boat hull") - // SetSort(?); - if (sortKey == "opaque ambient") - SetSort(SORTKEY_OPAQUE_AMBIENT); - else if (sortKey == "opaque") - SetSort(SORTKEY_OPAQUE); - else if (sortKey == "sky") - SetSort(SORTKEY_SKY); - else if (sortKey == "skybox") - SetSort(SORTKEY_SKYBOX); - 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 + bool foundSortKey = false; + for (auto sortKeyIndex = 0u; sortKeyIndex < SORTKEY_MAX; sortKeyIndex++) + { + if (sortKey == SortKeyNames[sortKeyIndex]) + { + SetSort(static_cast(sortKeyIndex)); + foundSortKey = true; + break; + } + } + + if (!foundSortKey) { char* endPtr; const auto sortKeyNum = strtoul(sortKey.c_str(), &endPtr, 10); @@ -422,7 +380,7 @@ namespace IW4 m_textures.push_back(textureDef); } - void SetSort(const unsigned char sort) + void SetSort(const unsigned char sort) const { m_material->info.sortKey = sort; }