From 1ba68175e9b3594a0b93edd774cbebfd7e5836e1 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Fri, 4 Sep 2020 23:04:28 -0700 Subject: [PATCH] More CThardus imps, add CRandom16 stats --- Editor/ViewManager.cpp | 1 + Runtime/CRandom16.cpp | 6 ++ Runtime/CRandom16.hpp | 4 + Runtime/CStateManager.cpp | 5 +- Runtime/MP1/MP1.cpp | 2 + Runtime/MP1/World/CThardus.hpp | 1 + Runtime/MP1/World/CThardusRockProjectile.cpp | 108 +++++++++++++++++++ Runtime/MP1/World/CThardusRockProjectile.hpp | 44 ++++++-- Runtime/World/CPatterned.hpp | 2 +- 9 files changed, 161 insertions(+), 12 deletions(-) diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index 5252498ee..e65515048 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -120,6 +120,7 @@ void ViewManager::TestGameView::think() { } } + overlayText += fmt::format(FMT_STRING("CRandom16::Next calls: {}\n"), urde::CRandom16::GetNumNextCalls()); if (m_cvarCommons.m_debugOverlayShowResourceStats->toBoolean()) overlayText += fmt::format(FMT_STRING("Resource Objects: {}\n"), g_SimplePool->GetLiveObjects()); diff --git a/Runtime/CRandom16.cpp b/Runtime/CRandom16.cpp index 2441a1391..c59033224 100644 --- a/Runtime/CRandom16.cpp +++ b/Runtime/CRandom16.cpp @@ -4,5 +4,11 @@ namespace urde { CRandom16* CRandom16::g_randomNumber = nullptr; // &DefaultRandom; CGlobalRandom* CGlobalRandom::g_currentGlobalRandom = nullptr; //&DefaultGlobalRandom; +namespace { +u32 g_numNextCalls = 0; +}; +void CRandom16::IncrementNumNextCalls() { ++g_numNextCalls; } +u32 CRandom16::GetNumNextCalls() { return g_numNextCalls; } +void CRandom16::ResetNumNextCalls() { g_numNextCalls = 0; } } // namespace urde diff --git a/Runtime/CRandom16.hpp b/Runtime/CRandom16.hpp index 4b3354286..3d18ec7ea 100644 --- a/Runtime/CRandom16.hpp +++ b/Runtime/CRandom16.hpp @@ -12,6 +12,7 @@ public: explicit CRandom16(s32 seed = 99) : m_seed(seed) {} s32 Next() { + IncrementNumNextCalls(); m_seed = (m_seed * 0x41c64e6d) + 0x00003039; return (m_seed >> 16) & 0xffff; } @@ -28,6 +29,9 @@ public: static CRandom16* GetRandomNumber() { return g_randomNumber; } static void SetRandomNumber(CRandom16* rnd) { g_randomNumber = rnd; } + static void IncrementNumNextCalls(); + static u32 GetNumNextCalls(); + static void ResetNumNextCalls(); }; class CGlobalRandom { diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 5acf06637..946efb3a5 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -2779,10 +2779,7 @@ void CStateManager::DeferStateTransition(EStateManagerTransition t) { bool CStateManager::CanShowMapScreen() const { const CHintOptions::SHintState* curDispHint = g_GameState->HintOptions().GetCurrentDisplayedHint(); - if (curDispHint == nullptr || curDispHint->CanContinue()) { - return true; - } - return false; + return curDispHint == nullptr || curDispHint->CanContinue(); } std::pair CStateManager::CalculateScanCompletionRate() const { diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 3c21543e4..143bfce37 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -880,6 +880,7 @@ void CMain::WarmupShaders() { } return true; }); + m_warmupIt = m_warmupTags.begin(); @@ -887,6 +888,7 @@ void CMain::WarmupShaders() { } bool CMain::Proc() { + CRandom16::ResetNumNextCalls(); // Warmup cycle overrides update if (m_warmupTags.size()) return false; diff --git a/Runtime/MP1/World/CThardus.hpp b/Runtime/MP1/World/CThardus.hpp index 1e9f9bc62..732688c7c 100644 --- a/Runtime/MP1/World/CThardus.hpp +++ b/Runtime/MP1/World/CThardus.hpp @@ -172,6 +172,7 @@ class CThardus : public CPatterned { } zeus::CVector2f sub801dac30(CStateManager& mgr) const; + void sub801db148(CStateManager& mgr) const {} public: DEFINE_PATTERNED(Thardus); diff --git a/Runtime/MP1/World/CThardusRockProjectile.cpp b/Runtime/MP1/World/CThardusRockProjectile.cpp index d4a529c92..44a215f69 100644 --- a/Runtime/MP1/World/CThardusRockProjectile.cpp +++ b/Runtime/MP1/World/CThardusRockProjectile.cpp @@ -1,6 +1,21 @@ #include "Runtime/MP1/World/CThardusRockProjectile.hpp" +#include "Runtime/Camera/CCameraManager.hpp" +#include "Runtime/Camera/CFirstPersonCamera.hpp" +#include "Runtime/CStateManager.hpp" +#include "Runtime/Collision/CJointCollisionDescription.hpp" +#include "Runtime/World/CPlayer.hpp" + +#include "Runtime/MP1/World/CThardus.hpp" + +#include "TCastTo.hpp" // Generated file, do not modify include path namespace urde::MP1 { +namespace { +constexpr std::array skRockCollisions{{ + {"Rock_01_Collision_LCTR", 1.5f}, +}}; +} // namespace + CThardusRockProjectile::CThardusRockProjectile(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& modelData, const CActorParameters& aParms, const CPatternedInfo& patternedInfo, @@ -11,4 +26,97 @@ CThardusRockProjectile::CThardusRockProjectile(TUniqueId uid, std::string_view n EKnockBackVariant::Medium) , x57c_(std::move(mDataVec)) {} +void CThardusRockProjectile::Think(float dt, CStateManager& mgr) { + if (!GetActive()) { + return; + } + + CPatterned::Think(dt, mgr); +} + +void CThardusRockProjectile::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId other, CStateManager& mgr) { + CPatterned::AcceptScriptMsg(msg, other, mgr); +} + +void CThardusRockProjectile::Render(CStateManager& mgr) { CPatterned::Render(mgr); } + +void CThardusRockProjectile::Patrol(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg != EStateMsg::Update) { + return; + } + + GetBodyController()->GetCommandMgr().DeliverCmd( + CBCLocomotionCmd(zeus::skZero3f, (mgr.GetPlayer().GetTranslation() - GetTranslation()).normalized(), 1.f)); +} + +void CThardusRockProjectile::Dead(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg != EStateMsg::Activate) { + return; + } + + mgr.FreeScriptObject(GetUniqueId()); + SendScriptMsgs(EScriptObjectState::MassiveDeath, mgr, EScriptObjectMessage::None); + GenerateDeathExplosion(mgr); +} + +void CThardusRockProjectile::LoopedAttack(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg == EStateMsg::Activate) { + x5a4_ = true; + } else if (msg == EStateMsg::Update) { + zeus::CVector3f aimPos = mgr.GetPlayer().GetAimPosition(mgr, 0.f); + if (!x5bc_ || (aimPos - GetTranslation()).magSquared() <= x5c0_ * x5c0_) { + x5bc_ = false; + } else { + x5b0_ = x45c_steeringBehaviors.Arrival(*this, aimPos, 0.f); + x5bc_ = true; + } + + zeus::CVector3f movePos = x5b0_; + float radius = skRockCollisions[0].radius; + auto result = mgr.RayStaticIntersection(GetTranslation(), zeus::skDown, 100.f, + CMaterialFilter::MakeInclude({EMaterialTypes::Solid})); + + if (result.IsValid()) { + movePos = (x45c_steeringBehaviors.Separation(*this, result.GetPoint(), 2.f * radius) + x5b0_).normalized(); + } + GetBodyController()->GetCommandMgr().DeliverCmd(CBCLocomotionCmd{movePos, zeus::skZero3f, 1.f}); + } +} + +void CThardusRockProjectile::GetUp(CStateManager& mgr, EStateMsg msg, float dt) { + if (msg == EStateMsg::Activate) { + x574_ = EAnimState::NotReady; + } else if (msg == EStateMsg::Update) { + auto result = mgr.RayStaticIntersection(GetTranslation(), zeus::skDown, 2.f, + CMaterialFilter::MakeInclude({EMaterialTypes::Solid})); + if (result.IsInvalid()) { + CThardus* thardus = static_cast(mgr.ObjectById(x5d0_thardusId)); + if (thardus != nullptr && !x5dc_) { + x5dc_ = true; + sub80203824(mgr, x5cc_, result.GetPoint(), GetModelData()->GetScale(), 0); + } + } else if (mgr.GetCameraManager()->GetCurrentCameraId() == mgr.GetCameraManager()->GetFirstPersonCamera()->GetUniqueId()) { + + } + } +} + +void CThardusRockProjectile::Lurk(CStateManager& mgr, EStateMsg msg, float dt) { CAi::Lurk(mgr, msg, dt); } + +bool CThardusRockProjectile::Delay(CStateManager& mgr, float arg) { return x5a8_ < x330_stateMachineState.GetTime(); } + +bool CThardusRockProjectile::AnimOver(CStateManager& mgr, float arg) { return x574_ == EAnimState::Over; } + +bool CThardusRockProjectile::ShouldAttack(CStateManager& mgr, float arg) { + if (x5ac_ < x330_stateMachineState.GetTime() && x56c_ != 3) { + x56c_ = 2; + return true; + } + + return false; +} + +bool CThardusRockProjectile::HitSomething(CStateManager& mgr, float arg) { return x572_; } + +bool CThardusRockProjectile::ShouldMove(CStateManager& mgr, float arg) { return x56c_ != 0; } } // namespace urde::MP1 diff --git a/Runtime/MP1/World/CThardusRockProjectile.hpp b/Runtime/MP1/World/CThardusRockProjectile.hpp index b70afb813..e89686157 100644 --- a/Runtime/MP1/World/CThardusRockProjectile.hpp +++ b/Runtime/MP1/World/CThardusRockProjectile.hpp @@ -4,25 +4,55 @@ namespace urde::MP1 { class CThardusRockProjectile : public CPatterned { - float x568_; + float x568_ = 1.f; u32 x56c_ = 0; TUniqueId x570_ = kInvalidUniqueId; bool x572_ = false; - s32 x574_ = -1; - s32 x578_ = 0; + EAnimState x574_ = EAnimState::Invalid; + u32 x578_ = 0; std::vector> x57c_; - u32 x590_ = 0; - + std::vector x58c_; + CAssetId x59c_stateMachine; + u32 x5a0_ = 0; + bool x5a4_ = true; + float x5a8_ = 0.f; + float x5ac_ = 0.f; + zeus::CVector3f x5b0_ = zeus::skForward; + bool x5bc_ = true; + float x5c0_; + u32 x5c4_ = 0; + u32 x5c8_ = 0; + u32 x5cc_ = 0; + TUniqueId x5d0_thardusId = kInvalidUniqueId; + u32 x5d4_ = 0; + u32 x5d8_ = 0; + bool x5dc_ = false; + bool x5dd_ = false; + void sub80203824(CStateManager& mgr, u32 w1, const zeus::CVector3f& pos, const zeus::CVector3f& scale, u32 w2) {} public: DEFINE_PATTERNED(ThardusRockProjectile); CThardusRockProjectile(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& modelData, const CActorParameters& aParms, const CPatternedInfo& patternedInfo, - std::vector>&& mDataVec, CAssetId, float); + std::vector>&& mDataVec, CAssetId stateMachine, float); + void Think(float dt, CStateManager& mgr) override; + void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId other, CStateManager& mgr) override; + void Render(CStateManager& mgr) override; void sub80203d58() { x328_25_verticalMovement = false; x150_momentum = {0.f, 0.f, 2.f * -GetWeight()}; - x56c_ = 3; + x56c_= 3; } + + void Patrol(CStateManager& mgr, EStateMsg msg, float dt) override; + void Dead(CStateManager& mgr, EStateMsg msg, float dt) override; + void LoopedAttack(CStateManager& mgr, EStateMsg msg, float dt) override; + void GetUp(CStateManager& mgr, EStateMsg msg, float dt) override; + void Lurk(CStateManager& mgr, EStateMsg msg, float dt) override; + bool Delay(CStateManager& mgr, float arg) override; + bool AnimOver(CStateManager& mgr, float arg) override; + bool ShouldAttack(CStateManager& mgr, float arg) override; + bool HitSomething(CStateManager& mgr, float arg) override; + bool ShouldMove(CStateManager& mgr, float arg) override; }; } // namespace urde::MP1 diff --git a/Runtime/World/CPatterned.hpp b/Runtime/World/CPatterned.hpp index 8a8673786..7c2bf7e6f 100644 --- a/Runtime/World/CPatterned.hpp +++ b/Runtime/World/CPatterned.hpp @@ -84,7 +84,7 @@ public: enum class EBehaviourOrient { MoveDir, Constant, Destination }; enum class EBehaviourModifiers { Zero }; enum class EPatrolState { Invalid = -1, Patrol, Pause, Done }; - enum class EAnimState { NotReady, Ready, Repeat, Over }; + enum class EAnimState { NotReady, Ready, Repeat, Over, Invalid = -1 }; class CPatternNode { zeus::CVector3f x0_pos; zeus::CVector3f xc_forward;