metaforce/Runtime/MP1/CArtifactDoll.cpp

163 lines
5.4 KiB
C++
Raw Normal View History

2017-05-13 04:57:24 +00:00
#include "CArtifactDoll.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
#include "CStateManager.hpp"
#include "Graphics/CBooRenderer.hpp"
2018-12-08 05:30:43 +00:00
namespace urde::MP1 {
static const char* ArtifactPieceModels[] = {
"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
};
2018-12-08 05:30:43 +00:00
static const CAssetId ArtifactHeadScans[] = {
2017-05-13 04:57:24 +00:00
0x32C9DDCE, // Truth
0xB45DAF60, // Strength
0x7F017CC5, // Elder
0x62044C7D, // Wild
0xA9589FD8, // Lifegiver
0x2FCCED76, // Warrior
0xE4903ED3, // Chozo
0x15C68C06, // Nature
0xDE9A5FA3, // Sun
0xFBBE9D9A, // World
0x30E24E3F, // Spirit
2018-12-08 05:30:43 +00:00
0xB6763C91 // Newborn
2017-05-13 04:57:24 +00:00
};
static const zeus::CColor ArtifactPreColor = {0.4f, 0.68f, 0.88f, 0.8f};
static const zeus::CColor ArtifactPostColor = {1.f, 0.63f, 0.02f, 1.f};
2018-12-08 05:30:43 +00:00
CArtifactDoll::CArtifactDoll() {
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);
2018-12-08 05:30:43 +00:00
x28_24_loaded = false;
x0_models.reserve(12);
for (int i = 0; i < 12; ++i)
x0_models.push_back(g_SimplePool->GetObj(ArtifactPieceModels[i]));
2017-05-13 04:57:24 +00:00
}
2018-12-08 05:30:43 +00:00
int CArtifactDoll::GetArtifactHeadScanIndex(CAssetId scanId) {
for (int i = 0; i < 12; ++i)
2019-10-01 07:38:03 +00:00
if (ArtifactHeadScans[i] == scanId)
2018-12-08 05:30:43 +00:00
return i;
return -1;
2017-05-13 04:57:24 +00:00
}
2018-12-08 05:30:43 +00:00
CAssetId CArtifactDoll::GetArtifactHeadScanFromItemType(CPlayerState::EItemType item) {
if (item < CPlayerState::EItemType::Truth || item > CPlayerState::EItemType::Newborn)
return -1;
2019-10-01 07:38:03 +00:00
return ArtifactHeadScans[int(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();
for (int i = 0; i < 12; ++i) {
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType(i + 29))) {
2019-10-01 07:38:03 +00:00
CAssetId id = ArtifactHeadScans[i];
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();
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)
color = zeus::CColor::lerp(ArtifactPreColor, zeus::skWhite, 2.f * interp);
2018-12-08 05:30:43 +00:00
else
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
2018-12-08 05:30:43 +00:00
if (inArtifactCategory && i == selectedArtifact) {
float interp = (std::sin(CGraphics::GetSecondsMod900() * 2.f * M_PIF) + 1.f) * 0.5f;
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() {
x10_lights[0] = CLight::BuildDirectional(
(zeus::skForward + 0.25f * zeus::skRight + 0.1f * zeus::skDown).normalized(),
zeus::skWhite);
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() {
if (IsLoaded())
return true;
2017-05-13 04:57:24 +00:00
2018-12-08 05:30:43 +00:00
for (TLockedToken<CModel>& model : x0_models)
if (!model.IsLoaded())
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
}
2018-12-08 05:30:43 +00:00
} // namespace urde::MP1