CAutoMapper: Use std::array where applicable

This commit is contained in:
Lioncash 2019-10-01 22:25:15 -04:00
parent a5d18002be
commit 23ca919c18
2 changed files with 42 additions and 38 deletions

View File

@ -22,27 +22,26 @@ void CAutoMapper::SAutoMapperRenderState::InterpolateWithClamp(const SAutoMapper
SAutoMapperRenderState& out, SAutoMapperRenderState& out,
const SAutoMapperRenderState& b, float t) { const SAutoMapperRenderState& b, float t) {
t = zeus::clamp(0.f, t, 1.f); t = zeus::clamp(0.f, t, 1.f);
float easeIn = zeus::clamp(0.f, t * t * t, 1.f); const float easeIn = zeus::clamp(0.f, t * t * t, 1.f);
float omt = 1.f - t; const float omt = 1.f - t;
float easeOut = zeus::clamp(0.f, 1.f - omt * omt * omt, 1.f); const float easeOut = zeus::clamp(0.f, 1.f - omt * omt * omt, 1.f);
float easeInOut; float easeInOut;
if (t >= 0.5f) if (t >= 0.5f) {
easeInOut = zeus::clamp(0.f, 0.5f * std::sqrt(2.f * t - 1.f) + 0.5f, 1.f); easeInOut = zeus::clamp(0.f, 0.5f * std::sqrt(2.f * t - 1.f) + 0.5f, 1.f);
else } else {
easeInOut = zeus::clamp(0.f, 1.f - (0.5f * std::sqrt(2.f * omt - 1.f) + 0.5f), 1.f); easeInOut = zeus::clamp(0.f, 1.f - (0.5f * std::sqrt(2.f * omt - 1.f) + 0.5f), 1.f);
}
float eases[5] = {}; const std::array<float, 5> eases{
eases[1] = t; 0.0f, t, easeOut, easeIn, easeInOut,
eases[2] = easeOut; };
eases[3] = easeIn;
eases[4] = easeInOut;
if (b.x44_viewportEase != Ease::None) { if (b.x44_viewportEase != Ease::None) {
float easeB = eases[int(b.x44_viewportEase)]; const float easeB = eases[size_t(b.x44_viewportEase)];
float easeA = 1.f - easeB; const float easeA = 1.f - easeB;
zeus::CVector2i vpA = a.GetViewportSize(); const zeus::CVector2i vpA = a.GetViewportSize();
zeus::CVector2i vpB = b.GetViewportSize(); const zeus::CVector2i vpB = b.GetViewportSize();
out.x0_viewportSize = zeus::CVector2i(vpB.x * easeB + vpA.x * easeA, vpB.y * easeB + vpA.y * easeA); out.x0_viewportSize = zeus::CVector2i(vpB.x * easeB + vpA.x * easeA, vpB.y * easeB + vpA.y * easeA);
} }
if (t == 1.f) if (t == 1.f)
@ -51,34 +50,34 @@ void CAutoMapper::SAutoMapperRenderState::InterpolateWithClamp(const SAutoMapper
out.m_getViewportSize = nullptr; out.m_getViewportSize = nullptr;
if (b.x48_camEase != Ease::None) { if (b.x48_camEase != Ease::None) {
float easeB = eases[int(b.x48_camEase)]; const float easeB = eases[size_t(b.x48_camEase)];
float easeA = 1.f - easeB; const float easeA = 1.f - easeB;
out.x8_camOrientation = zeus::CQuaternion::slerp(a.x8_camOrientation, b.x8_camOrientation, easeB); out.x8_camOrientation = zeus::CQuaternion::slerp(a.x8_camOrientation, b.x8_camOrientation, easeB);
out.x18_camDist = b.x18_camDist * easeB + a.x18_camDist * easeA; out.x18_camDist = b.x18_camDist * easeB + a.x18_camDist * easeA;
out.x1c_camAngle = b.x1c_camAngle * easeB + a.x1c_camAngle * easeA; out.x1c_camAngle = b.x1c_camAngle * easeB + a.x1c_camAngle * easeA;
} }
if (b.x4c_pointEase != Ease::None) { if (b.x4c_pointEase != Ease::None) {
float easeB = eases[int(b.x4c_pointEase)]; const float easeB = eases[size_t(b.x4c_pointEase)];
float easeA = 1.f - easeB; const float easeA = 1.f - easeB;
out.x20_areaPoint = b.x20_areaPoint * easeB + a.x20_areaPoint * easeA; out.x20_areaPoint = b.x20_areaPoint * easeB + a.x20_areaPoint * easeA;
} }
if (b.x50_depth1Ease != Ease::None) { if (b.x50_depth1Ease != Ease::None) {
float easeB = eases[int(b.x50_depth1Ease)]; const float easeB = eases[size_t(b.x50_depth1Ease)];
float easeA = 1.f - easeB; const float easeA = 1.f - easeB;
out.x2c_drawDepth1 = b.x2c_drawDepth1 * easeB + a.x2c_drawDepth1 * easeA; out.x2c_drawDepth1 = b.x2c_drawDepth1 * easeB + a.x2c_drawDepth1 * easeA;
} }
if (b.x54_depth2Ease != Ease::None) { if (b.x54_depth2Ease != Ease::None) {
float easeB = eases[int(b.x54_depth2Ease)]; const float easeB = eases[size_t(b.x54_depth2Ease)];
float easeA = 1.f - easeB; const float easeA = 1.f - easeB;
out.x30_drawDepth2 = b.x30_drawDepth2 * easeB + a.x30_drawDepth2 * easeA; out.x30_drawDepth2 = b.x30_drawDepth2 * easeB + a.x30_drawDepth2 * easeA;
} }
if (b.x58_alphaEase != Ease::None) { if (b.x58_alphaEase != Ease::None) {
float easeB = eases[int(b.x58_alphaEase)]; const float easeB = eases[size_t(b.x58_alphaEase)];
float easeA = 1.f - easeB; const float easeA = 1.f - easeB;
out.x34_alphaSurfaceVisited = b.x34_alphaSurfaceVisited * easeB + a.x34_alphaSurfaceVisited * easeA; out.x34_alphaSurfaceVisited = b.x34_alphaSurfaceVisited * easeB + a.x34_alphaSurfaceVisited * easeA;
out.x38_alphaOutlineVisited = b.x38_alphaOutlineVisited * easeB + a.x38_alphaOutlineVisited * easeA; out.x38_alphaOutlineVisited = b.x38_alphaOutlineVisited * easeB + a.x38_alphaOutlineVisited * easeA;
out.x3c_alphaSurfaceUnvisited = b.x3c_alphaSurfaceUnvisited * easeB + a.x3c_alphaSurfaceUnvisited * easeA; out.x3c_alphaSurfaceUnvisited = b.x3c_alphaSurfaceUnvisited * easeB + a.x3c_alphaSurfaceUnvisited * easeA;
@ -481,12 +480,12 @@ float CAutoMapper::GetFinalMapScreenCameraMoveSpeed() const {
} }
void CAutoMapper::ProcessMapRotateInput(const CFinalInput& input, const CStateManager& mgr) { void CAutoMapper::ProcessMapRotateInput(const CFinalInput& input, const CStateManager& mgr) {
float up = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleUp, input); const float up = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleUp, input);
float down = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleDown, input); const float down = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleDown, input);
float left = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleLeft, input); const float left = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleLeft, input);
float right = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleRight, input); const float right = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleRight, input);
float dirs[4] = {}; std::array<float, 4> dirs{};
bool mouseHeld = false; bool mouseHeld = false;
if (const auto& kbm = input.GetKBM()) { if (const auto& kbm = input.GetKBM()) {
if (kbm->m_mouseButtons[size_t(boo::EMouseButton::Primary)]) { if (kbm->m_mouseButtons[size_t(boo::EMouseButton::Primary)]) {
@ -503,7 +502,7 @@ void CAutoMapper::ProcessMapRotateInput(const CFinalInput& input, const CStateMa
} }
float maxMag = up; float maxMag = up;
int dirSlot = 0; size_t dirSlot = 0;
if (down > up) { if (down > up) {
maxMag = down; maxMag = down;
dirSlot = 1; dirSlot = 1;
@ -1471,21 +1470,25 @@ void CAutoMapper::Draw(const CStateManager& mgr, const zeus::CTransform& xf, flo
mapXf * zeus::CTransform::Translate(mapa->GetAreaPostTransform(*x24_world, loc.xc_areaId).origin) * mapXf * zeus::CTransform::Translate(mapa->GetAreaPostTransform(*x24_world, loc.xc_areaId).origin) *
zeus::CTransform::Translate(mapa->GetAreaCenterPoint()) * zeus::CTransform::Scale(objectScale) * camRot); zeus::CTransform::Translate(mapa->GetAreaCenterPoint()) * zeus::CTransform::Scale(objectScale) * camRot);
float beaconAlpha = 0.f; float beaconAlpha = 0.f;
if (loc.x0_showBeacon == 1) if (loc.x0_showBeacon == 1) {
beaconAlpha = loc.x4_beaconAlpha; beaconAlpha = loc.x4_beaconAlpha;
}
if (beaconAlpha > 0.f) { if (beaconAlpha > 0.f) {
CTexturedQuadFilter::Vert verts[4] = {{{-4.f, -8.f, 8.f}, {0.f, 1.f}}, const std::array<CTexturedQuadFilter::Vert, 4> verts{{
{{-4.f, -8.f, 0.f}, {0.f, 0.f}}, {{-4.f, -8.f, 8.f}, {0.f, 1.f}},
{{4.f, -8.f, 8.f}, {1.f, 1.f}}, {{-4.f, -8.f, 0.f}, {0.f, 0.f}},
{{4.f, -8.f, 0.f}, {1.f, 0.f}}}; {{4.f, -8.f, 8.f}, {1.f, 1.f}},
{{4.f, -8.f, 0.f}, {1.f, 0.f}},
}};
float alpha = beaconAlpha; float alpha = beaconAlpha;
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) { if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {
} else } else {
alpha *= xa8_renderStates[0].x34_alphaSurfaceVisited; alpha *= xa8_renderStates[0].x34_alphaSurfaceVisited;
}
alpha *= mapAlpha; alpha *= mapAlpha;
zeus::CColor color = zeus::skWhite; zeus::CColor color = zeus::skWhite;
color.a() = alpha; color.a() = alpha;
filter.drawVerts(color, verts); filter.drawVerts(color, verts.data());
} }
} }
} }

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <array>
#include <list> #include <list>
#include <memory> #include <memory>
#include <optional> #include <optional>
@ -144,7 +145,7 @@ private:
u32 x9c_worldIdx = 0; u32 x9c_worldIdx = 0;
TAreaId xa0_curAreaId; TAreaId xa0_curAreaId;
TAreaId xa4_otherAreaId; TAreaId xa4_otherAreaId;
SAutoMapperRenderState xa8_renderStates[3]; // xa8, x104, x160; current, next, prev std::array<SAutoMapperRenderState, 3> xa8_renderStates; // xa8, x104, x160; current, next, prev
EAutoMapperState x1bc_state = EAutoMapperState::MiniMap; EAutoMapperState x1bc_state = EAutoMapperState::MiniMap;
EAutoMapperState x1c0_nextState = EAutoMapperState::MiniMap; EAutoMapperState x1c0_nextState = EAutoMapperState::MiniMap;
float x1c4_interpDur = 0.f; float x1c4_interpDur = 0.f;