From a840cc7afb3321171b8bfc2122f52a322784f11d Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Mon, 15 Aug 2016 13:43:04 -0700 Subject: [PATCH] CBodyState and CStateMachine work --- Runtime/CScanDisplay.hpp | 2 + Runtime/Character/CBodyController.cpp | 0 Runtime/Character/CBodyController.hpp | 76 +++++++++++++++++++++++ Runtime/Character/CBodyState.cpp | 0 Runtime/Character/CBodyState.hpp | 13 +--- Runtime/Character/CBodyStateCmdMgr.cpp | 0 Runtime/Character/CBodyStateCmdMgr.hpp | 75 ++++++++++++++++++++++ Runtime/Character/CMakeLists.txt | 5 +- Runtime/Character/CharacterCommon.hpp | 37 +++++++++++ Runtime/Particle/CParticleDataFactory.cpp | 2 +- Runtime/Particle/CRealElement.cpp | 2 +- Runtime/Particle/CRealElement.hpp | 4 +- Runtime/World/CAiFuncMap.hpp | 2 + Runtime/World/CGameArea.cpp | 1 + Runtime/World/CMakeLists.txt | 1 + Runtime/World/CPatterned.hpp | 8 +-- Runtime/World/CStateMachine.cpp | 64 +++++++++++++++++++ Runtime/World/CStateMachine.hpp | 46 ++++++++------ 18 files changed, 296 insertions(+), 42 deletions(-) create mode 100644 Runtime/Character/CBodyController.cpp create mode 100644 Runtime/Character/CBodyController.hpp create mode 100644 Runtime/Character/CBodyState.cpp create mode 100644 Runtime/Character/CBodyStateCmdMgr.cpp create mode 100644 Runtime/Character/CBodyStateCmdMgr.hpp create mode 100644 Runtime/Character/CharacterCommon.hpp diff --git a/Runtime/CScanDisplay.hpp b/Runtime/CScanDisplay.hpp index cebad560a..15a852326 100644 --- a/Runtime/CScanDisplay.hpp +++ b/Runtime/CScanDisplay.hpp @@ -6,6 +6,7 @@ #include "zeus/CVector2f.hpp" #include "zeus/CQuaternion.hpp" #include "CScannableObjectInfo.hpp" +#include "Graphics/CTexture.hpp" namespace urde { @@ -48,6 +49,7 @@ public: struct SBucketBackground { }; + public: CScanDisplay() = default; void StartScan(TUniqueId, const CScannableObjectInfo&, CGuiTextPane*, CGuiWidget*, float); diff --git a/Runtime/Character/CBodyController.cpp b/Runtime/Character/CBodyController.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Character/CBodyController.hpp b/Runtime/Character/CBodyController.hpp new file mode 100644 index 000000000..d3b37b334 --- /dev/null +++ b/Runtime/Character/CBodyController.hpp @@ -0,0 +1,76 @@ +#ifndef __URDE_CBODYCONTROLLER_HPP__ +#define __URDE_CBODYCONTROLLER_HPP__ + +#include "RetroTypes.hpp" +#include "zeus/CQuaternion.hpp" +#include "CharacterCommon.hpp" + +namespace urde +{ + +class CActor; +class CAnimPlaybackParms; +class CFinalInput; +class CPASAnimParmData; +class CRandom16; +class CStateManager; +class CBodyController +{ +public: + CBodyController(CActor&, float, EBodyType); + void GetCurrentStateId() const; + void GetComandMgr(); + void SetDoDeathAnims(bool); + bool IsElectrocuting() const; + bool IsOnFire() const; + bool IsFrozen() const; + void GetBodyStateInfo() const; + bool GetIsActive() const; + void BodyStateInfo(); + float GetTurnSpeed() const; + pas::ELocomotionType GetLocomotionType() const; + void GetOwner(); + bool IsAnimationOver() const; + void EnableAnimation(bool); + bool ShouldPlayDeathAnims() const; + void GetCurrentAnimId() const; + void Activate(CStateManager&); + void GetCurrentAdditiveState(); + void SetState(pas::EAnimationState); + void Update(float, CStateManager&); + void Deactivate(); + bool ShouldBeHurled() const; + bool HasBodyState(pas::EAnimationState); + pas::EFallState GetFallState() const; + void SetFallState(pas::EFallState); + void UpdateBody(float, CStateManager&); + void SetAdditiveState(pas::EAnimationState); + void SetTurnSpeed(float); + void SetCurrentAnimation(const CAnimPlaybackParms&, bool, bool); + void GetAnimTimeRemaining() const; + void SetPlaybackRate(float); + void MultiplyPlaybackRate(float); + void SetDeltaRotation(const zeus::CQuaternion&); + void FaceDirection(const zeus::CVector3f&, float); + void FaceDirection3D(const zeus::CVector3f&, float); + void HasBodyInfo(CActor&); + void ProcessInput(const CFinalInput&); + void GetPASDatabase() const; + void PlayBestAnimation(const CPASAnimParmData&, CRandom16&); + void LoopBestAnimation(const CPASAnimParmData&, CRandom16&); + void Freeze(float, float, float); + void UnFreeze(); + void GetPercentageFrozen() const; + void SetOnFire(float); + void DouseFlames(); + void SetElectrocuting(float); + void DouseElectrocuting(); + void UpdateFrozenInfo(float, CStateManager&); + void GetCurrentAdditiveStateId() const; + EBodyType GetBodyType() const; + bool HasBeenFrozen() const; + void GetOwner() const; +}; +} + +#endif // __URDE_CBODYCONTROLLER_HPP__ diff --git a/Runtime/Character/CBodyState.cpp b/Runtime/Character/CBodyState.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Character/CBodyState.hpp b/Runtime/Character/CBodyState.hpp index 1469fb773..90727bf7b 100644 --- a/Runtime/Character/CBodyState.hpp +++ b/Runtime/Character/CBodyState.hpp @@ -1,21 +1,10 @@ #ifndef CBODYSTATE_HPP #define CBODYSTATE_HPP #include "RetroTypes.hpp" +#include "CharacterCommon.hpp" namespace urde { -namespace pas -{ -enum class ELocomotionType -{ -}; - -enum class ELocomotionAnim -{ -}; - -} - class CBodyController; class CStateManager; class CBodyState diff --git a/Runtime/Character/CBodyStateCmdMgr.cpp b/Runtime/Character/CBodyStateCmdMgr.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Character/CBodyStateCmdMgr.hpp b/Runtime/Character/CBodyStateCmdMgr.hpp new file mode 100644 index 000000000..426887f8e --- /dev/null +++ b/Runtime/Character/CBodyStateCmdMgr.hpp @@ -0,0 +1,75 @@ +#ifndef __URDE_CBODYSTATECMDMGR_HPP__ +#define __URDE_CBODYSTATECMDMGR_HPP__ + +#include "RetroTypes.hpp" +#include "CharacterCommon.hpp" +#include "zeus/CVector3f.hpp" + +namespace urde +{ +class CBodyStateCmd; +class CBCMeleeAttackCmd; +class CBCProjectileAttackCmd; +class CBCStepCmd; +class CBCJumpCmd; +class CBCGenerateCmd; +class CBCKnockBackCmd; +class CBCHurledCmd; +class CBCGetupCmd; +class CBCLoopReactionCmd; +class CBCKnockDownCmd; +class CBCSlideCmd; +class CBCScriptedCmd; +class CBCCoverCmd; +class CBCWallHangCmd; +class CBCAdditiveAimCmd; +class CBCLocomotionCmd; +class CBCAdditiveAimCmd; +class CBCAdditiveReactionCmd; +class CBCLoopAttackCmd; +class CBodyStateCmdMgr +{ +public: + enum class ESteeringBlendMode + { + }; +private: +public: + CBodyStateCmdMgr() = default; + void DeliverCmd(EBodyStateCmd); + void DeliverCmd(const CBodyStateCmd&); + void DeliverCmd(const CBCProjectileAttackCmd&); + void DeliverCmd(const CBCMeleeAttackCmd&); + void DeliverCmd(const CBCStepCmd&); + void DeliverCmd(const CBCGenerateCmd&); + void DeliverCmd(const CBCJumpCmd&); + void DeliverCmd(const CBCSlideCmd&); + void DeliverCmd(const CBCKnockBackCmd&); + void DeliverCmd(const CBCHurledCmd&); + void DeliverCmd(const CBCGetupCmd&); + void DeliverCmd(const CBCLoopReactionCmd&); + void DeliverCmd(const CBCKnockDownCmd&); + void DeliverCmd(const CBCScriptedCmd&); + void DeliverCmd(const CBCCoverCmd&); + void DeliverCmd(const CBCWallHangCmd&); + void DeliverCmd(const CBCAdditiveAimCmd&); + void DeliverCmd(const CBCLocomotionCmd&); + void DeliverCmd(const CBCAdditiveReactionCmd&); + void DeliverCmd(const CBCLoopAttackCmd&); + void DeliverTargetVector(const zeus::CVector3f&); + void DeliverAdditiveTargetVector(const zeus::CVector3f&); + void SetSteeringBlendSpeed(float); + void SetSteeringBlendMode(ESteeringBlendMode); + void SetSteeringSpeedRange(float, float); + void BlendSteeringCmds(); + void Reset(); + void ClearLocomtionCmds(); + void GetCmd(EBodyStateCmd); + zeus::CVector3f GetTargetVector() const; + void GetFaceVector() const; + void GetMoveVector() const; + s32 GetNumSteerCmds() const; + zeus::CVector3f GetAdditiveTargetVector() const; +}; +} +#endif // __URDE_CBODYSTATECMDMGR_HPP__ diff --git a/Runtime/Character/CMakeLists.txt b/Runtime/Character/CMakeLists.txt index cd6179c52..dedae5209 100644 --- a/Runtime/Character/CMakeLists.txt +++ b/Runtime/Character/CMakeLists.txt @@ -1,4 +1,5 @@ set(CHARACTER_SOURCES + CharacterCommon.hpp CAssetFactory.hpp CAssetFactory.cpp CCharacterFactory.hpp CCharacterFactory.cpp CModelData.hpp CModelData.cpp @@ -78,6 +79,8 @@ set(CHARACTER_SOURCES CAdditiveAnimPlayback.hpp CAdditiveAnimPlayback.cpp CActorLights.hpp CActorLights.cpp CAnimSysContext.hpp - CBodyState.hpp) + CBodyState.hpp CBodyState.cpp + CBodyStateCmdMgr.hpp CBodyStateCmdMgr.cpp + CBodyController.hpp CBodyController.cpp) runtime_add_list(Character CHARACTER_SOURCES) diff --git a/Runtime/Character/CharacterCommon.hpp b/Runtime/Character/CharacterCommon.hpp new file mode 100644 index 000000000..dfad77abe --- /dev/null +++ b/Runtime/Character/CharacterCommon.hpp @@ -0,0 +1,37 @@ +#ifndef __URDE_PASTYPES_HPP__ +#define __URDE_PASTYPES_HPP__ + +namespace urde +{ +namespace pas +{ +enum class ELocomotionType +{ +}; + +enum class ELocomotionAnim +{ +}; + +enum class EAnimationState +{ +}; + +enum class EFallState +{ +}; +} + +enum class EBodyType +{ + One, + Two = 2, + Three +}; +enum class EBodyStateCmd +{ + +}; +} + +#endif // __URDE_PASTYPES_HPP__ diff --git a/Runtime/Particle/CParticleDataFactory.cpp b/Runtime/Particle/CParticleDataFactory.cpp index fd1fcb0b4..bbc4f54f3 100644 --- a/Runtime/Particle/CParticleDataFactory.cpp +++ b/Runtime/Particle/CParticleDataFactory.cpp @@ -578,7 +578,7 @@ CRealElement* CParticleDataFactory::GetRealElement(CInputStream& in) { CRealElement* a = GetRealElement(in); CRealElement* b = GetRealElement(in); - return new CREISWT(a, b); + return new CREInitialSwitch(a, b); } case SBIG('CLTN'): { diff --git a/Runtime/Particle/CRealElement.cpp b/Runtime/Particle/CRealElement.cpp index 6be857c6c..a9c1c1a94 100644 --- a/Runtime/Particle/CRealElement.cpp +++ b/Runtime/Particle/CRealElement.cpp @@ -200,7 +200,7 @@ bool CRESineWave::GetValue(int frame, float& valOut) const return false; } -bool CREISWT::GetValue(int frame, float& valOut) const +bool CREInitialSwitch::GetValue(int frame, float& valOut) const { if (frame == 0) x4_a->GetValue(frame, valOut); diff --git a/Runtime/Particle/CRealElement.hpp b/Runtime/Particle/CRealElement.hpp index 423b8915c..d7ffde125 100644 --- a/Runtime/Particle/CRealElement.hpp +++ b/Runtime/Particle/CRealElement.hpp @@ -155,12 +155,12 @@ public: bool GetValue(int frame, float& valOut) const; }; -class CREISWT : public CRealElement +class CREInitialSwitch : public CRealElement { std::unique_ptr x4_a; std::unique_ptr x8_b; public: - CREISWT(CRealElement* a, CRealElement* b) + CREInitialSwitch(CRealElement* a, CRealElement* b) : x4_a(a), x8_b(b) {} bool GetValue(int frame, float& valOut) const; }; diff --git a/Runtime/World/CAiFuncMap.hpp b/Runtime/World/CAiFuncMap.hpp index db04e13e7..786a72623 100644 --- a/Runtime/World/CAiFuncMap.hpp +++ b/Runtime/World/CAiFuncMap.hpp @@ -14,8 +14,10 @@ class CStateManager; class CAi; typedef void (CAi::*CAiStateFunc)(CStateManager&, EStateMsg, float); typedef bool (CAi::*CAiTriggerFunc)(CStateManager&, float); + class CAiFuncMap { + static const std::vector gkStateNames; std::unordered_map x0_stateFuncs; std::unordered_map x10_triggerFuncs; public: diff --git a/Runtime/World/CGameArea.cpp b/Runtime/World/CGameArea.cpp index 5770dcfe9..0b142d429 100644 --- a/Runtime/World/CGameArea.cpp +++ b/Runtime/World/CGameArea.cpp @@ -671,6 +671,7 @@ void CGameArea::AllocNewAreaData(int offset, int size) bool CGameArea::Invalidate(CStateManager& mgr) { + return false; } void CGameArea::CullDeadAreaRequests() diff --git a/Runtime/World/CMakeLists.txt b/Runtime/World/CMakeLists.txt index df758cb30..3a9530fc9 100644 --- a/Runtime/World/CMakeLists.txt +++ b/Runtime/World/CMakeLists.txt @@ -24,6 +24,7 @@ set(WORLD_SOURCES CActor.hpp CActor.cpp CAi.hpp CAi.cpp CAiFuncMap.hpp CAiFuncMap.cpp + CStateMachine.hpp CStateMachine.cpp CPatterned.hpp CPatterned.cpp CPathFindArea.hpp CPathFindArea.cpp CPathFindRegion.hpp CPathFindRegion.cpp diff --git a/Runtime/World/CPatterned.hpp b/Runtime/World/CPatterned.hpp index 32850e49b..b9081bc52 100644 --- a/Runtime/World/CPatterned.hpp +++ b/Runtime/World/CPatterned.hpp @@ -2,18 +2,12 @@ #define __URDE_CPATTERNED_HPP__ #include "CAi.hpp" +#include "Character/CBodyController.hpp" namespace urde { class CPatternedInfo; -enum class EBodyType -{ - One, - Two = 2, - Three -}; - class CPatterned : public CAi { public: diff --git a/Runtime/World/CStateMachine.cpp b/Runtime/World/CStateMachine.cpp index 0563b3ead..12392240c 100644 --- a/Runtime/World/CStateMachine.cpp +++ b/Runtime/World/CStateMachine.cpp @@ -5,6 +5,42 @@ namespace urde { CStateMachine::CStateMachine(CInputStream& in) { +#if 0 + u32 stateCount = in.readUint32Big(); + + x0_states.reserve(stateCount); + + for (u32 i = 0 ; i& CStateMachine::GetStateVector() const { return x0_states; } + +float CStateMachineState::GetTime() const +{ + return 0.f; +} + +const std::vector* CStateMachineState::GetStateVector() const +{ + if (!x0_machine) + return nullptr; + + return &x0_machine->GetStateVector(); +} + +void CStateMachineState::Setup(const CStateMachine *machine) +{ + x0_machine = machine; + x4_state = nullptr; + x8_ = 0.f; + xc_ = 0.f; + x10_= 0.f; +} + +std::string CStateMachineState::GetName() const +{ + return {}; +} + } diff --git a/Runtime/World/CStateMachine.hpp b/Runtime/World/CStateMachine.hpp index 78b12f2e6..3a2baba04 100644 --- a/Runtime/World/CStateMachine.hpp +++ b/Runtime/World/CStateMachine.hpp @@ -10,10 +10,13 @@ class CAiState; class CStateManager; class CAiTrigger { - + u32 x0_ = 0; + u32 x4_ = 0; + u32 x8_ = 0; float xc_ = 0.f; - u32 x10_; - bool x18_; + u32 x10_ = 0; + u32 x14_ = 0; + bool x18_ = false; public: CAiTrigger() = default; bool GetAnd(); @@ -40,17 +43,17 @@ class CAiState u32 x20_; u32 x24_; u32 x28_; - u32 x2c_; + u32 x2c_numTriggers; u32 x30_; public: CAiState(CAiStateFunc func, const char* name) {} - u32 GetNumTriggers() const; + s32 GetNumTriggers() const; CAiTrigger& GetTrig(s32) const; const char* GetName() const; void SetTriggers(CAiTrigger* triggers); - void SetNumTriggers(s32 numTriggers); + void SetNumTriggers(s32 numTriggers) { x2c_numTriggers = numTriggers; } void CallFunc(CStateManager& mgr, CAi& ai, EStateMsg msg, float delta) const { if (x0_func) @@ -71,24 +74,24 @@ public: class CStateMachineState { - const CStateMachine* x0_ = nullptr; + const CStateMachine* x0_machine = nullptr; CAiState* x4_state = nullptr; float x8_ = 0; float xc_ = 0; float x10_ = 0; + union + { + struct + { + bool x18_24_ : 1; + }; + u32 dummy = 0; + }; public: CStateMachineState()=default; - void Setup(const CStateMachine* machine) - { - x0_ = machine; - x4_state = nullptr; - x8_ = 0.f; - xc_ = 0.f; - x10_= 0.f; - } - void SetDelay(float); - float GetDelay() const; + void GetActorState() const; + float GetTime() const; void Update(CStateManager& mgr, CAi& ai, float delta) { @@ -96,7 +99,14 @@ public: if (x4_state) x4_state->CallFunc(mgr, ai, EStateMsg::One, delta); } - + void SetState(CStateManager&, CAi&, s32); + void SetState(CStateManager &, CAi &, const std::string&); + const std::vector* GetStateVector() const; + void Setup(const CStateMachine* machine); + std::string GetName() const; + void SetDelay(float); + void GetRandom() const; + float GetDelay() const; }; }