Merge pull request #113 from lioncash/artifact

CArtifactDoll: Minor changes
This commit is contained in:
Phillip Stephens 2019-10-26 17:51:30 -07:00 committed by GitHub
commit 5865552d7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 25 deletions

View File

@ -1,12 +1,21 @@
#include "CArtifactDoll.hpp" #include "Runtime/MP1/CArtifactDoll.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp" #include <algorithm>
#include "CStateManager.hpp" #include <array>
#include "Graphics/CBooRenderer.hpp" #include <cmath>
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CBooRenderer.hpp"
#include "Runtime/Graphics/CGraphics.hpp"
#include <zeus/CColor.hpp>
#include <zeus/CTransform.hpp>
namespace urde::MP1 { namespace urde::MP1 {
namespace {
static const char* ArtifactPieceModels[] = { constexpr std::array ArtifactPieceModels{
"CMDL_Piece1", // Truth "CMDL_Piece1", // Truth
"CMDL_Piece2", // Strength "CMDL_Piece2", // Strength
"CMDL_Piece3", // Elder "CMDL_Piece3", // Elder
@ -21,7 +30,7 @@ static const char* ArtifactPieceModels[] = {
"CMDL_Piece12" // Newborn "CMDL_Piece12" // Newborn
}; };
static const CAssetId ArtifactHeadScans[] = { constexpr std::array<CAssetId, 12> ArtifactHeadScans{
0x32C9DDCE, // Truth 0x32C9DDCE, // Truth
0xB45DAF60, // Strength 0xB45DAF60, // Strength
0x7F017CC5, // Elder 0x7F017CC5, // Elder
@ -36,36 +45,43 @@ static const CAssetId ArtifactHeadScans[] = {
0xB6763C91 // Newborn 0xB6763C91 // Newborn
}; };
static const zeus::CColor ArtifactPreColor = {0.4f, 0.68f, 0.88f, 0.8f}; constexpr zeus::CColor ArtifactPreColor{0.4f, 0.68f, 0.88f, 0.8f};
static const zeus::CColor ArtifactPostColor = {1.f, 0.63f, 0.02f, 1.f}; constexpr zeus::CColor ArtifactPostColor{1.f, 0.63f, 0.02f, 1.f};
} // Anonymous namespace
CArtifactDoll::CArtifactDoll() { CArtifactDoll::CArtifactDoll() {
x10_lights.resize(2, CLight::BuildDirectional(zeus::skForward, zeus::skWhite)); x10_lights.resize(2, CLight::BuildDirectional(zeus::skForward, zeus::skWhite));
x20_actorLights = std::make_unique<CActorLights>(8, zeus::skZero3f, 4, 4, false, false, false, 0.1f); x20_actorLights = std::make_unique<CActorLights>(8, zeus::skZero3f, 4, 4, false, false, false, 0.1f);
x28_24_loaded = false; x28_24_loaded = false;
x0_models.reserve(12); x0_models.reserve(ArtifactPieceModels.size());
for (int i = 0; i < 12; ++i) for (const char* const model : ArtifactPieceModels) {
x0_models.push_back(g_SimplePool->GetObj(ArtifactPieceModels[i])); x0_models.emplace_back(g_SimplePool->GetObj(model));
}
} }
int CArtifactDoll::GetArtifactHeadScanIndex(CAssetId scanId) { int CArtifactDoll::GetArtifactHeadScanIndex(CAssetId scanId) {
for (int i = 0; i < 12; ++i) for (size_t i = 0; i < ArtifactHeadScans.size(); ++i) {
if (ArtifactHeadScans[i] == scanId) if (ArtifactHeadScans[i] == scanId) {
return i; return int(i);
}
}
return -1; return -1;
} }
CAssetId CArtifactDoll::GetArtifactHeadScanFromItemType(CPlayerState::EItemType item) { CAssetId CArtifactDoll::GetArtifactHeadScanFromItemType(CPlayerState::EItemType item) {
if (item < CPlayerState::EItemType::Truth || item > CPlayerState::EItemType::Newborn) if (item < CPlayerState::EItemType::Truth || item > CPlayerState::EItemType::Newborn) {
return -1; return -1;
return ArtifactHeadScans[int(item) - 29]; }
return ArtifactHeadScans[size_t(item) - 29];
} }
void CArtifactDoll::UpdateArtifactHeadScan(const CStateManager& mgr, float delta) { void CArtifactDoll::UpdateArtifactHeadScan(const CStateManager& mgr, float delta) {
CPlayerState& playerState = *mgr.GetPlayerState(); CPlayerState& playerState = *mgr.GetPlayerState();
for (int i = 0; i < 12; ++i) { for (size_t i = 0; i < ArtifactHeadScans.size(); ++i) {
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType(i + 29))) { if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType(i + 29))) {
CAssetId id = ArtifactHeadScans[i]; const CAssetId id = ArtifactHeadScans[i];
playerState.SetScanTime(id, std::min(playerState.GetScanTime(id) + delta, 1.f)); playerState.SetScanTime(id, std::min(playerState.GetScanTime(id) + delta, 1.f));
} }
} }
@ -103,7 +119,7 @@ void CArtifactDoll::Draw(float alpha, const CStateManager& mgr, bool inArtifactC
} }
} }
if (inArtifactCategory && i == selectedArtifact) { if (inArtifactCategory && i == size_t(selectedArtifact)) {
float interp = (std::sin(CGraphics::GetSecondsMod900() * 2.f * M_PIF) + 1.f) * 0.5f; float interp = (std::sin(CGraphics::GetSecondsMod900() * 2.f * M_PIF) + 1.f) * 0.5f;
color = zeus::CColor::lerp(zeus::skWhite, color, interp); color = zeus::CColor::lerp(zeus::skWhite, color, interp);
color.a() *= zeus::clamp(0.f, 1.25f - interp, 1.f); color.a() *= zeus::clamp(0.f, 1.25f - interp, 1.f);
@ -148,12 +164,15 @@ void CArtifactDoll::Touch() {
} }
bool CArtifactDoll::CheckLoadComplete() { bool CArtifactDoll::CheckLoadComplete() {
if (IsLoaded()) if (IsLoaded()) {
return true; return true;
}
for (TLockedToken<CModel>& model : x0_models) const bool allLoaded =
if (!model.IsLoaded()) std::all_of(x0_models.cbegin(), x0_models.cend(), [](const auto& model) { return model.IsLoaded(); });
if (!allLoaded) {
return false; return false;
}
x28_24_loaded = true; x28_24_loaded = true;
return true; return true;