From cd3bba2f0e6e6885f02547680f03b0a4a29be550 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 20 Jun 2018 14:57:57 -1000 Subject: [PATCH] Working grapple beam --- Runtime/Character/CAnimData.cpp | 6 +-- Runtime/Collision/CMetroidAreaCollider.cpp | 13 +++--- Runtime/GuiSys/CCompoundTargetReticle.cpp | 8 ++-- Runtime/MP1/CFrontEndUI.cpp | 2 +- Runtime/Particle/CParticleSwoosh.cpp | 4 +- Runtime/Particle/CParticleSwoosh.hpp | 10 ++-- Runtime/Weapon/CGrappleArm.cpp | 3 +- Runtime/World/CPlayer.cpp | 9 +++- Runtime/World/CScriptGrapplePoint.cpp | 54 +++++++++++++++++++--- Runtime/World/CScriptGrapplePoint.hpp | 7 ++- 10 files changed, 85 insertions(+), 31 deletions(-) diff --git a/Runtime/Character/CAnimData.cpp b/Runtime/Character/CAnimData.cpp index 03e2eb96a..216940639 100644 --- a/Runtime/Character/CAnimData.cpp +++ b/Runtime/Character/CAnimData.cpp @@ -735,9 +735,9 @@ void CAnimData::SetAnimation(const CAnimPlaybackParms& parms, bool noTrans) { if (parms.GetAnimationId() == x40c_playbackParms.GetAnimationId() || (parms.GetSecondAnimationId() == x40c_playbackParms.GetSecondAnimationId() && - parms.GetBlendFactor() == x40c_playbackParms.GetBlendFactor() && - parms.GetBlendFactor() != 1.f) || - parms.GetSecondAnimationId() == -1) + parms.GetSecondAnimationId() != -1) || + (parms.GetBlendFactor() == x40c_playbackParms.GetBlendFactor() && + parms.GetBlendFactor() != 1.f)) { if (x220_29_animationJustStarted) return; diff --git a/Runtime/Collision/CMetroidAreaCollider.cpp b/Runtime/Collision/CMetroidAreaCollider.cpp index 33f4227e2..479124a40 100644 --- a/Runtime/Collision/CMetroidAreaCollider.cpp +++ b/Runtime/Collision/CMetroidAreaCollider.cpp @@ -211,8 +211,7 @@ static zeus::CVector3f ClipRayToPlane(const zeus::CVector3f& a, const zeus::CVec bool CMetroidAreaCollider::ConvexPolyCollision(const zeus::CPlane* planes, const zeus::CVector3f* verts, zeus::CAABox& aabb) { - /* FIXME: HACK: Increasing the size from 20 to 128 to give us more headroom, we should try and trim this back down to a more reasonable size */ - rstl::reserved_vector vecs[2]; + rstl::reserved_vector vecs[2]; g_CalledClip += 1; g_RejectedByClip -= 1; @@ -225,8 +224,8 @@ bool CMetroidAreaCollider::ConvexPolyCollision(const zeus::CPlane* planes, const int otherVecIdx = 1; for (int i=0 ; i<6 ; ++i) { - rstl::reserved_vector& vec = vecs[vecIdx]; - rstl::reserved_vector& otherVec = vecs[otherVecIdx]; + rstl::reserved_vector& vec = vecs[vecIdx]; + rstl::reserved_vector& otherVec = vecs[otherVecIdx]; otherVec.clear(); bool inFrontOf = planes[i].pointToPlaneDist(vec.front()) >= 0.f; @@ -235,8 +234,10 @@ bool CMetroidAreaCollider::ConvexPolyCollision(const zeus::CPlane* planes, const const zeus::CVector3f& b = vec[(j + 1) % vec.size()]; if (inFrontOf) otherVec.push_back(vec[j]); - if ((planes[i].pointToPlaneDist(b) >= 0.f) ^ inFrontOf) + bool nextInFrontOf = planes[i].pointToPlaneDist(b) >= 0.f; + if (nextInFrontOf ^ inFrontOf) otherVec.push_back(ClipRayToPlane(vec[j], b, planes[i])); + inFrontOf = nextInFrontOf; } if (otherVec.empty()) @@ -246,7 +247,7 @@ bool CMetroidAreaCollider::ConvexPolyCollision(const zeus::CPlane* planes, const otherVecIdx ^= 1; } - rstl::reserved_vector& accumVec = vecs[otherVecIdx ^ 1]; + rstl::reserved_vector& accumVec = vecs[otherVecIdx ^ 1]; for (const zeus::CVector3f& point : accumVec) aabb.accumulateBounds(point); diff --git a/Runtime/GuiSys/CCompoundTargetReticle.cpp b/Runtime/GuiSys/CCompoundTargetReticle.cpp index d9c30407f..0ba1e5fe1 100644 --- a/Runtime/GuiSys/CCompoundTargetReticle.cpp +++ b/Runtime/GuiSys/CCompoundTargetReticle.cpp @@ -172,7 +172,7 @@ void CCompoundTargetReticle::Update(float dt, const CStateManager& mgr) xc4_chargeGauge.x0_model.Lock(); else xc4_chargeGauge.x0_model.Unlock(); - if (scan) + if (!scan) x94_grapple.Lock(); else x94_grapple.Unlock(); @@ -492,12 +492,12 @@ void CCompoundTargetReticle::DrawGrapplePoint(const CScriptGrapplePoint& point, color = g_tweakTargeting->GetLockedGrapplePointSelectColor(); else color = g_tweakTargeting->GetGrapplePointSelectColor(); - color = zeus::CColor::lerp(color, g_tweakTargeting->GetGrapplePointColor(), t); + color = zeus::CColor::lerp(g_tweakTargeting->GetGrapplePointColor(), color, t); zeus::CMatrix3f scale( CalculateClampedScale(orbitPos, 1.f, g_tweakTargeting->GetGrappleClampMin(), g_tweakTargeting->GetGrappleClampMax(), mgr) * - (1.f - t) * g_tweakTargeting->GetGrappleScale() + t * g_tweakTargeting->GetGrappleSelectScale()); - zeus::CTransform modelXf(scale, orbitPos); + ((1.f - t) * g_tweakTargeting->GetGrappleScale() + t * g_tweakTargeting->GetGrappleSelectScale())); + zeus::CTransform modelXf(rot * scale, orbitPos); CGraphics::SetModelMatrix(modelXf); CModelFlags flags(7, 0, 0, color); x94_grapple->Draw(flags); diff --git a/Runtime/MP1/CFrontEndUI.cpp b/Runtime/MP1/CFrontEndUI.cpp index 1dd4bb57f..533fa6405 100644 --- a/Runtime/MP1/CFrontEndUI.cpp +++ b/Runtime/MP1/CFrontEndUI.cpp @@ -2016,7 +2016,7 @@ CFrontEndUI::CFrontEndUI() m_touchBar = NewFrontEndUITouchBar(); m_touchBar->SetPhase(CFrontEndUITouchBar::EPhase::None); - //x14_phase = EPhase::ExitFrontEnd; + x14_phase = EPhase::ExitFrontEnd; } void CFrontEndUI::StartSlideShow(CArchitectureQueue& queue) diff --git a/Runtime/Particle/CParticleSwoosh.cpp b/Runtime/Particle/CParticleSwoosh.cpp index 7dda91948..5f0b6ec99 100644 --- a/Runtime/Particle/CParticleSwoosh.cpp +++ b/Runtime/Particle/CParticleSwoosh.cpp @@ -233,9 +233,9 @@ bool CParticleSwoosh::Update(double dt) timeElem->GetValue(x28_curFrame, time); x30_curTime += std::max(0.0, dt * time); - while (!x1d0_26_disableUpdate && evalTime < x30_curTime) + while (x1d0_26_forceOneUpdate || evalTime < x30_curTime) { - x1d0_26_disableUpdate = false; + x1d0_26_forceOneUpdate = false; x158_curParticle += 1; if (x158_curParticle >= x15c_swooshes.size()) diff --git a/Runtime/Particle/CParticleSwoosh.hpp b/Runtime/Particle/CParticleSwoosh.hpp index f727e8d00..81fa984d9 100644 --- a/Runtime/Particle/CParticleSwoosh.hpp +++ b/Runtime/Particle/CParticleSwoosh.hpp @@ -80,7 +80,7 @@ class CParticleSwoosh : public CParticleGen { bool x1d0_24_emitting : 1; bool x1d0_25_AALP : 1; - bool x1d0_26_disableUpdate : 1; + bool x1d0_26_forceOneUpdate : 1; bool x1d0_27_renderGaps : 1; bool x1d0_28_LLRD : 1; bool x1d0_29_VLS1 : 1; @@ -162,7 +162,7 @@ public: void DoWarmupUpdate() { - x1d0_26_disableUpdate = true; + x1d0_26_forceOneUpdate = true; Update(0.0); } @@ -170,7 +170,7 @@ public: { for (int i=0 ; iGetObj(SObjectTag{FOURCC('PART'), g_tweakGunRes->xb8_grappleClaw})), x36c_grappleHitDesc(g_SimplePool->GetObj(SObjectTag{FOURCC('PART'), g_tweakGunRes->xbc_grappleHit})), x378_grappleMuzzleDesc(g_SimplePool->GetObj(SObjectTag{FOURCC('PART'), g_tweakGunRes->xc0_grappleMuzzle})), - x384_grappleSwooshDesc(g_SimplePool->GetObj(SObjectTag{FOURCC('PART'), g_tweakGunRes->xc4_grappleSwoosh})), + x384_grappleSwooshDesc(g_SimplePool->GetObj(SObjectTag{FOURCC('SWHC'), g_tweakGunRes->xc4_grappleSwoosh})), x390_grappleSegmentGen(std::make_unique(x354_grappleSegmentDesc)), x394_grappleClawGen(std::make_unique(x360_grappleClawDesc)), x398_grappleHitGen(std::make_unique(x36c_grappleHitDesc)), @@ -272,6 +272,7 @@ void CGrappleArm::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, case EUserEventType::Projectile: if (x3b2_27_armMoving) return; + x3b2_25_beamActive = true; x398_grappleHitGen = std::make_unique(x36c_grappleHitDesc); x39c_grappleMuzzleGen = std::make_unique(x378_grappleMuzzleDesc); x338_beamT = 0.f; diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index 8cb1785ee..e0fbefd16 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -3771,8 +3771,10 @@ void CPlayer::ApplyGrappleForces(const CFinalInput& input, CStateManager& mgr, f { zeus::CVector3f pointToPlayerFlat = pointToPlayer; pointToPlayerFlat.z = 0.f; + zeus::CVector3f pointAtPlayerHeight = point->GetTranslation(); + pointAtPlayerHeight.z = GetTranslation().z; zeus::CVector3f playerToGrapplePlane = - point->GetTranslation() + turnRot.transform(pointToPlayerFlat) - GetTranslation(); + pointAtPlayerHeight + turnRot.transform(pointToPlayerFlat) - GetTranslation(); if (playerToGrapplePlane.canBeNormalized()) pullVec += playerToGrapplePlane / dt; } @@ -3876,7 +3878,7 @@ void CPlayer::UpdateGrappleState(const CFinalInput& input, CStateManager& mgr) } else { - if (!g_tweakPlayer->GetGrappleJumpMode() && x3d8_grappleJumpTimeout <= 0.f) + if (g_tweakPlayer->GetGrappleJumpMode() == 0 && x3d8_grappleJumpTimeout <= 0.f) ApplyGrappleJump(mgr); BreakGrapple(EPlayerOrbitRequest::StopOrbit, mgr); } @@ -3946,7 +3948,10 @@ void CPlayer::UpdateGrappleState(const CFinalInput& input, CStateManager& mgr) break; } break; + default: + break; } + break; case EGrappleState::None: x3b8_grappleState = EGrappleState::Firing; x490_gun->GetGrappleArm().Activate(true); diff --git a/Runtime/World/CScriptGrapplePoint.cpp b/Runtime/World/CScriptGrapplePoint.cpp index 3309ab556..ee8dc281e 100644 --- a/Runtime/World/CScriptGrapplePoint.cpp +++ b/Runtime/World/CScriptGrapplePoint.cpp @@ -9,12 +9,11 @@ namespace urde CScriptGrapplePoint::CScriptGrapplePoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform &transform, bool active, const CGrappleParameters ¶ms) - : CActor(uid, active, name, info, transform, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::Orbit), - CActorParameters::None(), - kInvalidUniqueId), - xe8_(x34_transform.origin - 0.5f, - x34_transform.origin + 0.5f), - x100_parameters(params) +: CActor(uid, active, name, info, transform, CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::Orbit), + CActorParameters::None(), + kInvalidUniqueId), + xe8_touchBounds(x34_transform.origin - 0.5f, x34_transform.origin + 0.5f), + x100_parameters(params) { } @@ -23,4 +22,47 @@ void CScriptGrapplePoint::Accept(IVisitor& visitor) visitor.Visit(this); } +void CScriptGrapplePoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) +{ + switch (msg) + { + case EScriptObjectMessage::Activate: + if (!GetActive()) + { + AddMaterial(EMaterialTypes::Orbit, mgr); + SetActive(true); + } + break; + case EScriptObjectMessage::Deactivate: + if (GetActive()) + { + RemoveMaterial(EMaterialTypes::Orbit, mgr); + SetActive(false); + } + break; + default: + break; + } +} + +void CScriptGrapplePoint::Think(float, CStateManager&) +{ + // Empty +} + +void CScriptGrapplePoint::Render(const CStateManager&) const +{ + // Empty +} + +std::experimental::optional CScriptGrapplePoint::GetTouchBounds() const +{ + return {xe8_touchBounds}; +} + +void CScriptGrapplePoint::AddToRenderer(const zeus::CFrustum&, const CStateManager& mgr) const +{ + CActor::EnsureRendered(mgr); +} + } diff --git a/Runtime/World/CScriptGrapplePoint.hpp b/Runtime/World/CScriptGrapplePoint.hpp index a71e3f57b..3cd512dfc 100644 --- a/Runtime/World/CScriptGrapplePoint.hpp +++ b/Runtime/World/CScriptGrapplePoint.hpp @@ -8,13 +8,18 @@ namespace urde { class CScriptGrapplePoint : public CActor { - zeus::CAABox xe8_; + zeus::CAABox xe8_touchBounds; CGrappleParameters x100_parameters; public: CScriptGrapplePoint(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& transform, bool active, const CGrappleParameters& params); void Accept(IVisitor& visitor); + void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&); + void Think(float, CStateManager&); + void Render(const CStateManager&) const; + std::experimental::optional GetTouchBounds() const; + void AddToRenderer(const zeus::CFrustum&, const CStateManager&) const; const CGrappleParameters& GetGrappleParameters() const { return x100_parameters; } }; }