Merge pull request #154 from lioncash/constexpr

CSamusDoll: Minor changes
This commit is contained in:
Luke S 2020-02-24 03:00:11 -05:00 committed by GitHub
commit c8291ee3dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 56 deletions

View File

@ -8,6 +8,7 @@
#include "Runtime/World/CMorphBall.hpp"
#include <algorithm>
#include <array>
#include <cfloat>
#include <cmath>
#include <memory>
@ -16,46 +17,81 @@
#include <zeus/CEulerAngles.hpp>
namespace urde::MP1 {
namespace {
constexpr std::array<std::pair<const char*, u32>, 8> SpiderBallGlassModels{{
{"SamusSpiderBallGlassCMDL", 0},
{"SamusSpiderBallGlassCMDL", 0},
{"SamusSpiderBallGlassCMDL", 1},
{"SamusPhazonBallGlassCMDL", 0},
{"SamusSpiderBallGlassCMDL", 0},
{"SamusSpiderBallGlassCMDL", 0},
{"SamusSpiderBallGlassCMDL", 1},
{"SamusPhazonBallGlassCMDL", 0},
}};
const zeus::CVector3f CSamusDoll::skInitialOffset = {0.f, 0.f, 0.8f};
constexpr std::array<std::pair<const char*, u32>, 8> SpiderBallCharacters{{
{"SamusSpiderBallANCS", 0},
{"SamusSpiderBallANCS", 0},
{"SamusSpiderBallANCS", 1},
{"SamusPhazonBallANCS", 0},
{"SamusFusionBallANCS", 0},
{"SamusFusionBallANCS", 2},
{"SamusFusionBallANCS", 1},
{"SamusFusionBallANCS", 3},
}};
static const std::pair<const char*, u32> SpiderBallGlassModels[] = {
{"SamusSpiderBallGlassCMDL", 0}, {"SamusSpiderBallGlassCMDL", 0}, {"SamusSpiderBallGlassCMDL", 1},
{"SamusPhazonBallGlassCMDL", 0}, {"SamusSpiderBallGlassCMDL", 0}, {"SamusSpiderBallGlassCMDL", 0},
{"SamusSpiderBallGlassCMDL", 1}, {"SamusPhazonBallGlassCMDL", 0},
constexpr std::array<std::pair<const char*, u32>, 8> BallCharacters{{
{"SamusBallANCS", 0},
{"SamusBallANCS", 0},
{"SamusBallANCS", 1},
{"SamusBallANCS", 0},
{"SamusFusionBallANCS", 0},
{"SamusFusionBallANCS", 2},
{"SamusFusionBallANCS", 1},
{"SamusFusionBallANCS", 3},
}};
constexpr std::array<u32, 8> SpiderBallGlowColorIdxs{
3, 3, 2, 4, 5, 7, 6, 8,
};
static const std::pair<const char*, u32> SpiderBallCharacters[] = {
{"SamusSpiderBallANCS", 0}, {"SamusSpiderBallANCS", 0}, {"SamusSpiderBallANCS", 1}, {"SamusPhazonBallANCS", 0},
{"SamusFusionBallANCS", 0}, {"SamusFusionBallANCS", 2}, {"SamusFusionBallANCS", 1}, {"SamusFusionBallANCS", 3},
constexpr std::array<u32, 8> BallGlowColorIdxs{
0, 0, 1, 0, 5, 7, 6, 8,
};
static const std::pair<const char*, u32> BallCharacters[] = {
{"SamusBallANCS", 0}, {"SamusBallANCS", 0}, {"SamusBallANCS", 1}, {"SamusBallANCS", 0},
{"SamusFusionBallANCS", 0}, {"SamusFusionBallANCS", 2}, {"SamusFusionBallANCS", 1}, {"SamusFusionBallANCS", 3},
constexpr std::array BeamModels{
"CMDL_InvPowerBeam", "CMDL_InvIceBeam", "CMDL_InvWaveBeam", "CMDL_InvPlasmaBeam", "CMDL_InvPowerBeam",
};
static const u32 SpiderBallGlowColorIdxs[] = {3, 3, 2, 4, 5, 7, 6, 8};
constexpr std::array VisorModels{
"CMDL_InvVisor", "CMDL_InvGravityVisor", "CMDL_InvVisor", "CMDL_InvPhazonVisor",
"CMDL_InvFusionVisor", "CMDL_InvFusionVisor", "CMDL_InvFusionVisor", "CMDL_InvFusionVisor",
};
static const u32 BallGlowColorIdxs[] = {0, 0, 1, 0, 5, 7, 6, 8};
constexpr std::array FinModels{
"CMDL_InvPowerFins", "CMDL_InvPowerFins", "CMDL_InvPowerFins", "CMDL_InvPowerFins",
"CMDL_InvPowerFins", "CMDL_InvVariaFins", "CMDL_InvGravityFins", "CMDL_InvPhazonFins",
};
static const char* BeamModels[] = {"CMDL_InvPowerBeam", "CMDL_InvIceBeam", "CMDL_InvWaveBeam", "CMDL_InvPlasmaBeam",
"CMDL_InvPowerBeam"};
constexpr std::array<u32, 8> Character1Idxs{
0, 6, 2, 10, 16, 24, 20, 28,
};
static const char* VisorModels[] = {"CMDL_InvVisor", "CMDL_InvGravityVisor", "CMDL_InvVisor",
"CMDL_InvPhazonVisor", "CMDL_InvFusionVisor", "CMDL_InvFusionVisor",
"CMDL_InvFusionVisor", "CMDL_InvFusionVisor"};
constexpr std::array<u32, 8> CharacterBootsIdxs{
1, 7, 3, 11, 17, 25, 21, 29,
};
static const char* FinModels[] = {"CMDL_InvPowerFins", "CMDL_InvPowerFins", "CMDL_InvPowerFins",
"CMDL_InvPowerFins", "CMDL_InvPowerFins", "CMDL_InvVariaFins",
"CMDL_InvGravityFins", "CMDL_InvPhazonFins"};
static const u32 Character1Idxs[8] = {0, 6, 2, 10, 16, 24, 20, 28};
static const u32 CharacterBootsIdxs[8] = {1, 7, 3, 11, 17, 25, 21, 29};
static const u32 Character2and3Idxs[8][2] = {{14, 15}, {8, 9}, {4, 5}, {12, 13},
{18, 19}, {26, 27}, {22, 23}, {30, 31}};
constexpr std::array<std::array<u32, 2>, 8> Character2and3Idxs{{
{14, 15},
{8, 9},
{4, 5},
{12, 13},
{18, 19},
{26, 27},
{22, 23},
{30, 31},
}};
} // Anonymous namespace
CSamusDoll::CSamusDoll(const CDependencyGroup& suitDgrp, const CDependencyGroup& ballDgrp,
CPlayerState::EPlayerSuit suit, CPlayerState::EBeamId beam, bool hasSpiderBall,
@ -65,15 +101,15 @@ CSamusDoll::CSamusDoll(const CDependencyGroup& suitDgrp, const CDependencyGroup&
, x48_beam(beam) {
x70_fixedRot.rotateZ(M_PIF);
x90_userInterpRot = xb0_userRot = x70_fixedRot;
x1d4_spiderBallGlass = g_SimplePool->GetObj(SpiderBallGlassModels[int(suit)].first);
x1e0_ballMatIdx = hasSpiderBall ? SpiderBallCharacters[int(suit)].second : BallCharacters[int(suit)].second;
x1e4_glassMatIdx = SpiderBallGlassModels[int(suit)].second;
x1e8_ballGlowColorIdx = hasSpiderBall ? SpiderBallGlowColorIdxs[int(suit)] : BallGlowColorIdxs[int(suit)];
x1d4_spiderBallGlass = g_SimplePool->GetObj(SpiderBallGlassModels[size_t(suit)].first);
x1e0_ballMatIdx = hasSpiderBall ? SpiderBallCharacters[size_t(suit)].second : BallCharacters[size_t(suit)].second;
x1e4_glassMatIdx = SpiderBallGlassModels[size_t(suit)].second;
x1e8_ballGlowColorIdx = hasSpiderBall ? SpiderBallGlowColorIdxs[size_t(suit)] : BallGlowColorIdxs[size_t(suit)];
x1ec_itemScreenSamus = g_SimplePool->GetObj("ANCS_ItemScreenSamus");
x1f4_invBeam = g_SimplePool->GetObj(BeamModels[int(beam)]);
x200_invVisor = g_SimplePool->GetObj(VisorModels[int(suit)]);
x1f4_invBeam = g_SimplePool->GetObj(BeamModels[size_t(beam)]);
x200_invVisor = g_SimplePool->GetObj(VisorModels[size_t(suit)]);
x20c_invGrappleBeam = g_SimplePool->GetObj("CMDL_InvGrappleBeam");
x218_invFins = g_SimplePool->GetObj(FinModels[int(suit)]);
x218_invFins = g_SimplePool->GetObj(FinModels[size_t(suit)]);
x224_ballInnerGlow = g_SimplePool->GetObj("BallInnerGlow");
x22c_ballInnerGlowGen = std::make_unique<CElementGen>(x224_ballInnerGlow);
x230_ballTransitionFlash = g_SimplePool->GetObj("MorphBallTransitionFlash");
@ -112,7 +148,7 @@ bool CSamusDoll::IsLoaded() const {
}
CModelData CSamusDoll::BuildSuitModelData1(CPlayerState::EPlayerSuit suit) {
CModelData ret(CAnimRes(g_ResFactory->GetResourceIdByName("ANCS_ItemScreenSamus")->id, Character1Idxs[int(suit)],
CModelData ret(CAnimRes(g_ResFactory->GetResourceIdByName("ANCS_ItemScreenSamus")->id, Character1Idxs[size_t(suit)],
zeus::skOne3f, 2, true));
CAnimPlaybackParms parms(2, -1, 1.f, true);
ret.GetAnimationData()->SetAnimation(parms, false);
@ -120,8 +156,8 @@ CModelData CSamusDoll::BuildSuitModelData1(CPlayerState::EPlayerSuit suit) {
}
CModelData CSamusDoll::BuildSuitModelDataBoots(CPlayerState::EPlayerSuit suit) {
CModelData ret(CAnimRes(g_ResFactory->GetResourceIdByName("ANCS_ItemScreenSamus")->id, CharacterBootsIdxs[int(suit)],
zeus::skOne3f, 2, true));
CModelData ret(CAnimRes(g_ResFactory->GetResourceIdByName("ANCS_ItemScreenSamus")->id,
CharacterBootsIdxs[size_t(suit)], zeus::skOne3f, 2, true));
CAnimPlaybackParms parms(2, -1, 1.f, true);
ret.GetAnimationData()->SetAnimation(parms, false);
return ret;
@ -137,7 +173,7 @@ bool CSamusDoll::CheckLoadComplete() {
xc8_suitModel0.emplace(BuildSuitModelData1(x44_suit));
for (int i = 0; i < 2; ++i) {
CAnimRes res(g_ResFactory->GetResourceIdByName("ANCS_ItemScreenSamus")->id, Character2and3Idxs[int(x44_suit)][i],
CAnimRes res(g_ResFactory->GetResourceIdByName("ANCS_ItemScreenSamus")->id, Character2and3Idxs[size_t(x44_suit)][i],
zeus::skOne3f, 2, true);
CModelData mData(res);
x118_suitModel1and2.push_back(mData.GetAnimationData()->GetModelData());
@ -146,13 +182,13 @@ bool CSamusDoll::CheckLoadComplete() {
x134_suitModelBoots.emplace(BuildSuitModelDataBoots(x44_suit));
CAnimRes res(g_ResFactory
->GetResourceIdByName(x270_24_hasSpiderBall ? SpiderBallCharacters[int(x44_suit)].first
: BallCharacters[int(x44_suit)].first)
->GetResourceIdByName(x270_24_hasSpiderBall ? SpiderBallCharacters[size_t(x44_suit)].first
: BallCharacters[size_t(x44_suit)].first)
->id,
0, zeus::skOne3f, 0, true);
x184_ballModelData.emplace(res);
x1e0_ballMatIdx =
x270_24_hasSpiderBall ? SpiderBallCharacters[int(x44_suit)].second : BallCharacters[int(x44_suit)].second;
x270_24_hasSpiderBall ? SpiderBallCharacters[size_t(x44_suit)].second : BallCharacters[size_t(x44_suit)].second;
x270_31_loaded = true;
return true;
}
@ -512,23 +548,23 @@ void CSamusDoll::Draw(const CStateManager& mgr, float alpha) {
if (x270_24_hasSpiderBall) {
CGraphics::SetModelMatrix(x10_ballXf);
CModelFlags flags = {};
flags.x1_matSetIdx = x1e4_glassMatIdx;
CModelFlags spiderBallGlassFlags = {};
spiderBallGlassFlags.x1_matSetIdx = x1e4_glassMatIdx;
x1d4_spiderBallGlass->GetInstance().ActivateLights(x23c_lights);
flags.m_extendedShader = EExtendedShader::SolidColorBackfaceCullLEqualAlphaOnly;
flags.x4_color = zeus::skWhite;
x1d4_spiderBallGlass->Draw(flags);
spiderBallGlassFlags.m_extendedShader = EExtendedShader::SolidColorBackfaceCullLEqualAlphaOnly;
spiderBallGlassFlags.x4_color = zeus::skWhite;
x1d4_spiderBallGlass->Draw(spiderBallGlassFlags);
flags.m_extendedShader = EExtendedShader::ForcedAlpha;
flags.x4_color = zeus::skWhite;
flags.x4_color.a() = alpha;
x1d4_spiderBallGlass->Draw(flags);
spiderBallGlassFlags.m_extendedShader = EExtendedShader::ForcedAlpha;
spiderBallGlassFlags.x4_color = zeus::skWhite;
spiderBallGlassFlags.x4_color.a() = alpha;
x1d4_spiderBallGlass->Draw(spiderBallGlassFlags);
flags.m_extendedShader = EExtendedShader::ForcedAdditive;
flags.x4_color = zeus::skWhite;
flags.x4_color.a() = x6c_ballPulseFactor * alpha * itemPulse;
x1d4_spiderBallGlass->Draw(flags);
spiderBallGlassFlags.m_extendedShader = EExtendedShader::ForcedAdditive;
spiderBallGlassFlags.x4_color = zeus::skWhite;
spiderBallGlassFlags.x4_color.a() = x6c_ballPulseFactor * alpha * itemPulse;
x1d4_spiderBallGlass->Draw(spiderBallGlassFlags);
}
}

View File

@ -85,7 +85,7 @@ class CSamusDoll {
u32 _dummy = 0;
};
static const zeus::CVector3f skInitialOffset;
static constexpr zeus::CVector3f skInitialOffset{0.0f, 0.0f, 0.8f};
static CModelData BuildSuitModelData1(CPlayerState::EPlayerSuit suit);
static CModelData BuildSuitModelDataBoots(CPlayerState::EPlayerSuit suit);
void SetupLights();