2019-10-26 18:57:17 +00:00
|
|
|
#include "Runtime/MP1/CArtifactDoll.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2019-10-21 23:23:41 +00:00
|
|
|
#include <array>
|
2019-10-26 18:57:17 +00:00
|
|
|
#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>
|
2017-05-13 04:57:24 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce::MP1 {
|
2019-10-21 22:59:51 +00:00
|
|
|
namespace {
|
2019-10-21 23:23:41 +00:00
|
|
|
constexpr std::array ArtifactPieceModels{
|
2018-12-08 05:30:43 +00:00
|
|
|
"CMDL_Piece1", // Truth
|
|
|
|
"CMDL_Piece2", // Strength
|
|
|
|
"CMDL_Piece3", // Elder
|
|
|
|
"CMDL_Piece4", // Wild
|
|
|
|
"CMDL_Piece5", // Lifegiver
|
|
|
|
"CMDL_Piece6", // Warrior
|
|
|
|
"CMDL_Piece7", // Chozo
|
|
|
|
"CMDL_Piece8", // Nature
|
|
|
|
"CMDL_Piece9", // Sun
|
2017-05-13 04:57:24 +00:00
|
|
|
"CMDL_Piece10", // World
|
|
|
|
"CMDL_Piece11", // Spirit
|
2018-12-08 05:30:43 +00:00
|
|
|
"CMDL_Piece12" // Newborn
|
2017-05-13 04:57:24 +00:00
|
|
|
};
|
|
|
|
|
2019-10-21 23:23:41 +00:00
|
|
|
constexpr std::array<CAssetId, 12> ArtifactHeadScans{
|
2022-02-19 13:04:45 +00:00
|
|
|
0x32C9DDCEu, // Truth
|
|
|
|
0xB45DAF60u, // Strength
|
|
|
|
0x7F017CC5u, // Elder
|
|
|
|
0x62044C7Du, // Wild
|
|
|
|
0xA9589FD8u, // Lifegiver
|
|
|
|
0x2FCCED76u, // Warrior
|
|
|
|
0xE4903ED3u, // Chozo
|
|
|
|
0x15C68C06u, // Nature
|
|
|
|
0xDE9A5FA3u, // Sun
|
|
|
|
0xFBBE9D9Au, // World
|
|
|
|
0x30E24E3Fu, // Spirit
|
|
|
|
0xB6763C91u // Newborn
|
2017-05-13 04:57:24 +00:00
|
|
|
};
|
|
|
|
|
2019-10-21 22:59:51 +00:00
|
|
|
constexpr zeus::CColor ArtifactPreColor{0.4f, 0.68f, 0.88f, 0.8f};
|
|
|
|
constexpr zeus::CColor ArtifactPostColor{1.f, 0.63f, 0.02f, 1.f};
|
|
|
|
} // Anonymous namespace
|
2017-05-13 04:57:24 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CArtifactDoll::CArtifactDoll() {
|
2019-02-24 07:15:54 +00:00
|
|
|
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);
|
2019-10-21 23:23:41 +00:00
|
|
|
x0_models.reserve(ArtifactPieceModels.size());
|
|
|
|
for (const char* const model : ArtifactPieceModels) {
|
|
|
|
x0_models.emplace_back(g_SimplePool->GetObj(model));
|
|
|
|
}
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int CArtifactDoll::GetArtifactHeadScanIndex(CAssetId scanId) {
|
2019-10-21 23:23:41 +00:00
|
|
|
for (size_t i = 0; i < ArtifactHeadScans.size(); ++i) {
|
|
|
|
if (ArtifactHeadScans[i] == scanId) {
|
|
|
|
return int(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return -1;
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CAssetId CArtifactDoll::GetArtifactHeadScanFromItemType(CPlayerState::EItemType item) {
|
2019-10-21 23:23:41 +00:00
|
|
|
if (item < CPlayerState::EItemType::Truth || item > CPlayerState::EItemType::Newborn) {
|
2022-02-19 13:04:45 +00:00
|
|
|
return {};
|
2019-10-21 23:23:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ArtifactHeadScans[size_t(item) - 29];
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CArtifactDoll::UpdateArtifactHeadScan(const CStateManager& mgr, float delta) {
|
|
|
|
CPlayerState& playerState = *mgr.GetPlayerState();
|
2019-10-21 23:23:41 +00:00
|
|
|
for (size_t i = 0; i < ArtifactHeadScans.size(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType(i + 29))) {
|
2019-10-21 23:23:41 +00:00
|
|
|
const CAssetId id = ArtifactHeadScans[i];
|
2019-10-01 07:38:03 +00:00
|
|
|
playerState.SetScanTime(id, std::min(playerState.GetScanTime(id) + delta, 1.f));
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CArtifactDoll::CompleteArtifactHeadScan(const CStateManager& mgr) { UpdateArtifactHeadScan(mgr, 1.f); }
|
|
|
|
|
|
|
|
void CArtifactDoll::Draw(float alpha, const CStateManager& mgr, bool inArtifactCategory, int selectedArtifact) {
|
|
|
|
if (!IsLoaded())
|
|
|
|
return;
|
2019-07-21 08:42:52 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CArtifactDoll::Draw", zeus::skPurple);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
alpha *= x24_fader;
|
|
|
|
g_Renderer->SetPerspective(55.f, g_Viewport.x8_width, g_Viewport.xc_height, 0.2f, 4096.f);
|
|
|
|
CGraphics::SetViewPointMatrix(zeus::CTransform::Translate(0.f, -10.f, 0.f));
|
|
|
|
|
|
|
|
float angle = CGraphics::GetSecondsMod900() * 2.f * M_PIF * 0.25f;
|
|
|
|
CGraphics::SetModelMatrix(zeus::CTransform::RotateX(zeus::degToRad(std::sin(angle) * 8.f)) *
|
|
|
|
zeus::CTransform::RotateZ(zeus::degToRad(std::cos(angle) * 8.f)) *
|
|
|
|
zeus::CTransform::RotateX(M_PIF / 2.f) * zeus::CTransform::Scale(0.2f));
|
|
|
|
|
|
|
|
CPlayerState& playerState = *mgr.GetPlayerState();
|
2019-06-12 02:05:17 +00:00
|
|
|
for (size_t i = 0; i < x0_models.size(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
TLockedToken<CModel>& model = x0_models[i];
|
|
|
|
zeus::CColor color = ArtifactPreColor;
|
|
|
|
if (playerState.HasPowerUp(CPlayerState::EItemType(i + 29))) {
|
|
|
|
if (ArtifactHeadScans[i].IsValid()) {
|
2019-10-01 07:38:03 +00:00
|
|
|
float interp = (playerState.GetScanTime(ArtifactHeadScans[i]) - 0.5f) * 2.f;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (interp < 0.5f)
|
2019-02-24 07:15:54 +00:00
|
|
|
color = zeus::CColor::lerp(ArtifactPreColor, zeus::skWhite, 2.f * interp);
|
2018-12-08 05:30:43 +00:00
|
|
|
else
|
2019-02-24 07:15:54 +00:00
|
|
|
color = zeus::CColor::lerp(zeus::skWhite, ArtifactPostColor, 2.f * (interp - 0.5f));
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
color = ArtifactPostColor;
|
|
|
|
}
|
|
|
|
}
|
2017-05-13 04:57:24 +00:00
|
|
|
|
2019-10-21 23:23:41 +00:00
|
|
|
if (inArtifactCategory && i == size_t(selectedArtifact)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
float interp = (std::sin(CGraphics::GetSecondsMod900() * 2.f * M_PIF) + 1.f) * 0.5f;
|
2019-02-24 07:15:54 +00:00
|
|
|
color = zeus::CColor::lerp(zeus::skWhite, color, interp);
|
2018-12-08 05:30:43 +00:00
|
|
|
color.a() *= zeus::clamp(0.f, 1.25f - interp, 1.f);
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
CModelFlags flags(7, 0, 3, zeus::CColor(1.f, 0.f));
|
|
|
|
flags.m_extendedShader = EExtendedShader::SolidColorFrontfaceCullLEqualAlphaOnly;
|
|
|
|
x20_actorLights->ActivateLights(model->GetInstance());
|
|
|
|
model->Draw(flags);
|
|
|
|
|
|
|
|
flags.x4_color = color;
|
|
|
|
flags.x4_color.a() *= alpha;
|
|
|
|
flags.m_extendedShader = EExtendedShader::ForcedAdditive;
|
|
|
|
model->Draw(flags);
|
|
|
|
}
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CArtifactDoll::UpdateActorLights() {
|
2021-06-07 19:29:18 +00:00
|
|
|
x10_lights[0] = CLight::BuildDirectional((zeus::skForward + 0.25f * zeus::skRight + 0.1f * zeus::skDown).normalized(),
|
|
|
|
zeus::skWhite);
|
2019-02-24 07:15:54 +00:00
|
|
|
x10_lights[1] = CLight::BuildDirectional(-zeus::skForward, zeus::skBlack);
|
2018-12-08 05:30:43 +00:00
|
|
|
x20_actorLights->BuildFakeLightList(x10_lights, zeus::CColor(0.25f, 1.f));
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CArtifactDoll::Update(float dt, const CStateManager& mgr) {
|
|
|
|
if (!CheckLoadComplete())
|
|
|
|
return;
|
2017-05-13 04:57:24 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x24_fader = std::min(x24_fader + 2.f * dt, 1.f);
|
|
|
|
if (std::fabs(x24_fader - 1.f) < 0.00001f)
|
|
|
|
UpdateArtifactHeadScan(mgr, 0.5f * dt * 0.5f);
|
|
|
|
UpdateActorLights();
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CArtifactDoll::Touch() {
|
|
|
|
if (!CheckLoadComplete())
|
|
|
|
return;
|
2017-05-13 04:57:24 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (TLockedToken<CModel>& model : x0_models)
|
|
|
|
model->Touch(0);
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CArtifactDoll::CheckLoadComplete() {
|
2019-10-21 23:40:22 +00:00
|
|
|
if (IsLoaded()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2019-10-21 23:40:22 +00:00
|
|
|
}
|
2017-05-13 04:57:24 +00:00
|
|
|
|
2019-10-21 23:40:22 +00:00
|
|
|
const bool allLoaded =
|
|
|
|
std::all_of(x0_models.cbegin(), x0_models.cend(), [](const auto& model) { return model.IsLoaded(); });
|
|
|
|
if (!allLoaded) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-13 04:57:24 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x28_24_loaded = true;
|
|
|
|
return true;
|
2017-05-13 04:57:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce::MP1
|