From 83f3e3d4f1f861d1860347b05f1cfa08fce36122 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 20 Nov 2016 13:53:15 -0800 Subject: [PATCH] Various Implementations --- Runtime/CStateManager.cpp | 13 +++ Runtime/CStateManager.hpp | 1 + Runtime/Character/CModelData.hpp | 3 + Runtime/Character/CParticleDatabase.cpp | 5 ++ Runtime/Character/CParticleDatabase.hpp | 14 +-- Runtime/Collision/CCollisionResponseData.cpp | 2 +- Runtime/Collision/CCollisionResponseData.hpp | 2 +- Runtime/World/CActor.cpp | 23 +++-- Runtime/World/CActor.hpp | 8 +- Runtime/World/CFluidPlane.cpp | 13 +++ Runtime/World/CFluidPlane.hpp | 33 ++++++- Runtime/World/CFluidPlaneCPU.cpp | 13 +++ Runtime/World/CFluidPlaneCPU.hpp | 18 ++++ Runtime/World/CFluidPlaneDoor.cpp | 0 Runtime/World/CFluidPlaneDoor.hpp | 0 Runtime/World/CMakeLists.txt | 7 +- Runtime/World/CPlayer.cpp | 3 +- Runtime/World/CPlayer.hpp | 2 +- Runtime/World/CRipple.cpp | 7 ++ Runtime/World/CRipple.hpp | 35 ++++++++ Runtime/World/CRippleManager.cpp | 0 Runtime/World/CRippleManager.hpp | 0 Runtime/World/CScriptActorKeyframe.cpp | 33 +++++++ Runtime/World/CScriptActorKeyframe.hpp | 38 +++++++++ Runtime/World/CScriptTrigger.cpp | 7 +- Runtime/World/CScriptTrigger.hpp | 49 ++++++++--- Runtime/World/CScriptWater.cpp | 90 +++++++++++++++++--- Runtime/World/CScriptWater.hpp | 73 +++++++++++++--- Runtime/World/ScriptLoader.cpp | 29 +++++-- 29 files changed, 454 insertions(+), 67 deletions(-) create mode 100644 Runtime/World/CFluidPlane.cpp create mode 100644 Runtime/World/CFluidPlaneCPU.cpp create mode 100644 Runtime/World/CFluidPlaneCPU.hpp create mode 100644 Runtime/World/CFluidPlaneDoor.cpp create mode 100644 Runtime/World/CFluidPlaneDoor.hpp create mode 100644 Runtime/World/CRipple.cpp create mode 100644 Runtime/World/CRipple.hpp create mode 100644 Runtime/World/CRippleManager.cpp create mode 100644 Runtime/World/CRippleManager.hpp create mode 100644 Runtime/World/CScriptActorKeyframe.cpp create mode 100644 Runtime/World/CScriptActorKeyframe.hpp diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 351407854..8c46f8029 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -251,9 +251,22 @@ bool CStateManager::RenderLast(TUniqueId) return false; } +void CStateManager::AddDrawableActorPlane(const CActor& actor, const zeus::CPlane& plane, const zeus::CAABox& aabb) const +{ +#if 0 + actor.SetAddedToken(x8dc_ + 1); +#endif + g_Renderer->AddPlaneObject(static_cast(&actor), aabb, plane, 0); +} + void CStateManager::AddDrawableActor(const CActor& actor, const zeus::CVector3f& vec, const zeus::CAABox& aabb) const { +#if 0 + actor.SetAddedToken(x8dc_ + 1); +#endif + g_Renderer->AddDrawable(static_cast(&actor), vec, aabb, 0, + IRenderer::EDrawableSorting::SortedCallback); } void CStateManager::SpecialSkipCinematic() diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index a61f14dc1..e17074089 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -177,6 +177,7 @@ public: const std::weak_ptr&); bool RenderLast(TUniqueId); + void AddDrawableActorPlane(const CActor& actor, const zeus::CPlane&, const zeus::CAABox& aabb) const; void AddDrawableActor(const CActor& actor, const zeus::CVector3f& vec, const zeus::CAABox& aabb) const; void SpecialSkipCinematic(); void GetVisAreaId() const; diff --git a/Runtime/Character/CModelData.hpp b/Runtime/Character/CModelData.hpp index 137603a39..e59fbcc11 100644 --- a/Runtime/Character/CModelData.hpp +++ b/Runtime/Character/CModelData.hpp @@ -140,6 +140,9 @@ public: const CActorLights* lights, const CModelFlags& drawFlags); CAnimData* AnimationData() { return x10_animData.get(); } + const TLockedToken& GetNormalModel() const { return x1c_normalModel; } + const TLockedToken& GetXRayModel() const { return x2c_xrayModel; } + const TLockedToken& GetThermalModel() const { return x3c_infraModel; } bool IsNull() { return !x10_animData && !x1c_normalModel; } }; diff --git a/Runtime/Character/CParticleDatabase.cpp b/Runtime/Character/CParticleDatabase.cpp index 15e75a4e7..141c24f68 100644 --- a/Runtime/Character/CParticleDatabase.cpp +++ b/Runtime/Character/CParticleDatabase.cpp @@ -29,4 +29,9 @@ void CParticleDatabase::AddToRendererClipped(const zeus::CFrustum& frustum) { } +void CParticleDatabase::GetActiveParticleLightIds(std::vector&) +{ + +} + } diff --git a/Runtime/Character/CParticleDatabase.hpp b/Runtime/Character/CParticleDatabase.hpp index b0c774445..720c30a00 100644 --- a/Runtime/Character/CParticleDatabase.hpp +++ b/Runtime/Character/CParticleDatabase.hpp @@ -14,17 +14,21 @@ class CCharLayoutInfo; class CParticleDatabase { std::map> x3c_; + public: void CacheParticleDesc(const CCharacterInfo::CParticleResData& desc); void SetModulationColorAllActiveEffects(const zeus::CColor& color); void SuspendAllActiveEffects(CStateManager& stateMgr); - void StartEffect(const std::string& name, u32 flags, const CParticleData& data, - const zeus::CVector3f& scale, CStateManager& stateMgr, TAreaId aid, u32 unk1); - void Update(float dt, const CPoseAsTransforms& pose, const CCharLayoutInfo& charInfo, - const zeus::CTransform& xf, const zeus::CVector3f& vec, CStateManager& stateMgr); + void StartEffect(const std::string& name, u32 flags, const CParticleData& data, const zeus::CVector3f& scale, + CStateManager& stateMgr, TAreaId aid, u32 unk1); + void Update(float dt, const CPoseAsTransforms& pose, const CCharLayoutInfo& charInfo, const zeus::CTransform& xf, + const zeus::CVector3f& vec, CStateManager& stateMgr); void AddToRendererClipped(const zeus::CFrustum& frustum); + void GetActiveParticleLightIds(std::vector&); + void GetActiveParticleLightIdsFromParticleDB( + std::vector&, + const std::map, std::less>&); }; - } #endif // __URDE_CPARTICLEDATABASE_HPP__ diff --git a/Runtime/Collision/CCollisionResponseData.cpp b/Runtime/Collision/CCollisionResponseData.cpp index 5c683c7c7..6390b979b 100644 --- a/Runtime/Collision/CCollisionResponseData.cpp +++ b/Runtime/Collision/CCollisionResponseData.cpp @@ -256,7 +256,7 @@ s32 CCollisionResponseData::GetSoundEffectId(EWeaponCollisionResponseTypes type) EWeaponCollisionResponseTypes CCollisionResponseData::GetWorldCollisionResponseType(s32 id) { - if (id < 0 || id >= 32) + if (id < 0 || id >= s32(EWeaponCollisionResponseTypes::Unknown32)) return EWeaponCollisionResponseTypes::Default; return skWorldMaterialTable[id]; diff --git a/Runtime/Collision/CCollisionResponseData.hpp b/Runtime/Collision/CCollisionResponseData.hpp index 5eb97b019..4fcdfaaad 100644 --- a/Runtime/Collision/CCollisionResponseData.hpp +++ b/Runtime/Collision/CCollisionResponseData.hpp @@ -19,7 +19,7 @@ enum class EWeaponCollisionResponseTypes None, Default, Unknown2, Metal, Grass, Ice, Goo, Wood, Water, Mud, Lava, Sand, - Unknown12,Unknown13,Unknown14,Unknown15, + Projectile,Unknown13,Unknown14,Unknown15, EnemyNormal,EnemySpecial,EnemyShielded,Unknown19, Unknown20,Unknown21,Unknown22,Unknown23, Unknown24,Unknown25,Unknown26,Unknown27, diff --git a/Runtime/World/CActor.cpp b/Runtime/World/CActor.cpp index 6c26a7d0a..d4266d967 100644 --- a/Runtime/World/CActor.cpp +++ b/Runtime/World/CActor.cpp @@ -61,10 +61,11 @@ void CActor::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateMana case EScriptObjectMessage::InternalMessage12: // 34 { RemoveEmitter(); - /* TODO: Not sure about this - if (HasModelData() && x64_modelData->AnimationData() && x64_modelData->x28_) - x64_modelData->AnimationData().GetParticleDB().GetActiveParticleLightIds(mgr); - */ +#if 0 + if (HasModelData() && x64_modelData->AnimationData() && x64_modelData->GetNormalModel()) + x64_modelData->AnimationData()->GetParticleDB().GetActiveParticleLightIds(mgr); +#endif + } break; case EScriptObjectMessage::InternalMessage13: // 35 @@ -91,9 +92,12 @@ void CActor::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateMana CEntity::AcceptScriptMsg(msg, uid, mgr); } -zeus::CAABox CActor::CalculateRenderBounds() +void CActor::CalculateRenderBounds() { - return {}; + if (x64_modelData && (x64_modelData->AnimationData() || x64_modelData->GetNormalModel())) + x9c_aabox = x64_modelData->GetBounds(x34_transform); + else + x9c_aabox = zeus::CAABox(x34_transform.origin, x34_transform.origin); } const CHealthInfo* CActor::GetHealthInfo() const @@ -183,7 +187,7 @@ void CActor::OnScanStateChanged(EScanState state, CStateManager& mgr) } -zeus::CAABox CActor::GetSortingBounds(const zeus::CTransform &) const +zeus::CAABox CActor::GetSortingBounds(const CStateManager &) const { return {}; } @@ -311,6 +315,11 @@ void CActor::SetTranslation(const zeus::CVector3f &tr) xe4_29_ = true; } +void CActor::SetAddedToken(u32 tok) +{ + xcc_addedToken = tok; +} + float CActor::GetPitch() const { return zeus::CQuaternion(x34_transform.buildMatrix3f()).pitch(); diff --git a/Runtime/World/CActor.hpp b/Runtime/World/CActor.hpp index 4ccd45e82..403a4c94f 100644 --- a/Runtime/World/CActor.hpp +++ b/Runtime/World/CActor.hpp @@ -47,7 +47,7 @@ protected: TUniqueId xc4_fluidId = kInvalidUniqueId; TUniqueId xc6_ = kInvalidUniqueId; s32 xc8_ = -1; - s32 xcc_ = -1; + s32 xcc_addedToken = -1; float xd0_; u8 xd4_ = 0x7F; u32 xd8_ = 2; @@ -97,7 +97,7 @@ public: virtual void AddToRenderer(const zeus::CFrustum&, const CStateManager&) const {} virtual void Render(const CStateManager&) const {} virtual bool CanRenderUnsorted(const CStateManager&) const { return false; } - virtual zeus::CAABox CalculateRenderBounds(); + virtual void CalculateRenderBounds(); virtual const CHealthInfo* GetHealthInfo() const; virtual const CDamageVulnerability* GetDamageVulnerability() const; virtual const CDamageVulnerability* GetDamageVulnerability(const zeus::CVector3f&, const zeus::CVector3f&, const CDamageInfo&) const; @@ -111,7 +111,7 @@ public: CWeaponMode&, int); virtual void FluidFXThink(EFluidState, CScriptWater&, CStateManager&); virtual void OnScanStateChanged(EScanState, CStateManager&); - virtual zeus::CAABox GetSortingBounds(const zeus::CTransform&) const; + virtual zeus::CAABox GetSortingBounds(const CStateManager&) const; virtual void DoUserAnimEvent(CStateManager&, CInt32POINode&, EUserEventType); @@ -140,7 +140,7 @@ public: const CSfxHandle* GetSfxHandle() const; void SetSfxPitchBend(s32); void SetTranslation(const zeus::CVector3f& tr); - + void SetAddedToken(u32 tok); float GetPitch() const; float GetYaw() const; }; diff --git a/Runtime/World/CFluidPlane.cpp b/Runtime/World/CFluidPlane.cpp new file mode 100644 index 000000000..5d13b86d6 --- /dev/null +++ b/Runtime/World/CFluidPlane.cpp @@ -0,0 +1,13 @@ +#include "CFluidPlane.hpp" + +namespace urde +{ +CFluidPlane::CFluidPlane(u32, u32, u32, EFluidType, float, const urde::CFluidUVMotion&, float) +{ +} + +void CFluidPlane::Update() +{ + +} +} diff --git a/Runtime/World/CFluidPlane.hpp b/Runtime/World/CFluidPlane.hpp index f96ea4e2e..8a3619985 100644 --- a/Runtime/World/CFluidPlane.hpp +++ b/Runtime/World/CFluidPlane.hpp @@ -1,13 +1,44 @@ #ifndef __URDE_CFLUIDPLANE_HPP__ #define __URDE_CFLUIDPLANE_HPP__ +#include "RetroTypes.hpp" namespace urde { +class CFluidUVMotion; +class CRippleManager; class CFluidPlane { public: enum class EFluidType - {}; + { + Zero, + One, + Two, + Three, + Four, + Five + }; + +private: + u32 x4_; + u32 x8_; + u32 xc_; + float x40_; + EFluidType x44_; + float x48_; +public: + CFluidPlane(u32, u32, u32, EFluidType, float, const CFluidUVMotion&, float); + + virtual void Update(); + float GetAlpha() const; + EFluidType GetFluidType() const; + const CFluidUVMotion& GetUVMotion() const; + void GetColorTexture() const; + bool HasColorTexture() const; + void GetTexturePattern1() const; + bool HasTexturePattern1() const; + void GetTexturePattern2() const; + bool HasTexturePattern2() const; }; } diff --git a/Runtime/World/CFluidPlaneCPU.cpp b/Runtime/World/CFluidPlaneCPU.cpp new file mode 100644 index 000000000..fa0085c76 --- /dev/null +++ b/Runtime/World/CFluidPlaneCPU.cpp @@ -0,0 +1,13 @@ +#include "CFluidPlaneCPU.hpp" + +namespace urde +{ +CFluidPlaneCPU::CFluidPlaneCPU(u32 w1, u32 w2, u32 w3, u32 w4, u32 w5, u32 w6, float f1, u32 w7, u32 w8, + EFluidType fluidType, float f2, const zeus::CVector3f& v1, float f3, + const urde::CFluidUVMotion& motion, float f4, float f5, float f6, float f7, float f8, + float f9, float f10, float f11, float f12, float f13, float f14, float f15, float f16, + float f17) +: CFluidPlane(w1, w2, w3, fluidType, f3, motion, f17) +{ +} +} diff --git a/Runtime/World/CFluidPlaneCPU.hpp b/Runtime/World/CFluidPlaneCPU.hpp new file mode 100644 index 000000000..8a524a968 --- /dev/null +++ b/Runtime/World/CFluidPlaneCPU.hpp @@ -0,0 +1,18 @@ +#ifndef __URDE_CFLUIDPLANECPU_HPP__ +#define __URDE_CFLUIDPLANECPU_HPP__ + +#include "CFluidPlane.hpp" + +namespace urde +{ +class CFluidUVMotion; +class CFluidPlaneCPU : public CFluidPlane +{ +public: + CFluidPlaneCPU(u32, u32, u32, u32, u32, u32, float, u32, u32, EFluidType, float, const zeus::CVector3f&, + float, const CFluidUVMotion&, float, float, float, float, float, float, float, float, float, float, + float, float, float, float); +}; +} + +#endif // __URDE_CFLUIDPLANECPU_HPP__ diff --git a/Runtime/World/CFluidPlaneDoor.cpp b/Runtime/World/CFluidPlaneDoor.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/World/CFluidPlaneDoor.hpp b/Runtime/World/CFluidPlaneDoor.hpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/World/CMakeLists.txt b/Runtime/World/CMakeLists.txt index f63add2f8..c34ba1f73 100644 --- a/Runtime/World/CMakeLists.txt +++ b/Runtime/World/CMakeLists.txt @@ -54,6 +54,7 @@ set(WORLD_SOURCES CScriptSound.hpp CScriptSound.cpp CScriptGenerator.hpp CScriptGenerator.cpp CScriptDock.hpp CScriptDock.cpp + CScriptActorKeyframe.hpp CScriptActorKeyframe.cpp CScriptWater.hpp CScriptWater.cpp CScriptGrapplePoint.hpp CScriptGrapplePoint.cpp CScriptAreaAttributes.hpp CScriptAreaAttributes.cpp @@ -91,6 +92,10 @@ set(WORLD_SOURCES CHUDMemoParms.hpp CHUDMemoParms.cpp CWorldShadow.hpp CWorldShadow.cpp CGameLight.hpp CGameLight.cpp - CFluidPlane.hpp) + CFluidPlane.hpp CFluidPlane.cpp + CFluidPlaneCPU.hpp CFluidPlaneCPU.cpp + CFluidPlaneDoor.hpp CFluidPlaneDoor.cpp + CRippleManager.hpp CRippleManager.cpp + CRipple.hpp CRipple.cpp) runtime_add_list(World WORLD_SOURCES) diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index 630770e61..1b668bae3 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -169,9 +169,8 @@ void CPlayer::PreRender(CStateManager& mgr, const zeus::CFrustum&) { } -zeus::CAABox CPlayer::CalculateRenderBounds() +void CPlayer::CalculateRenderBounds() { - return {}; } void CPlayer::AddToRenderer(const zeus::CFrustum&, CStateManager&) diff --git a/Runtime/World/CPlayer.hpp b/Runtime/World/CPlayer.hpp index ab9c0b3a6..e1772cb4d 100644 --- a/Runtime/World/CPlayer.hpp +++ b/Runtime/World/CPlayer.hpp @@ -215,7 +215,7 @@ public: void Render(CStateManager& mgr) const; void RenderReflectedPlayer(CStateManager& mgr) const; void PreRender(CStateManager& mgr, const zeus::CFrustum&); - zeus::CAABox CalculateRenderBounds(); + void CalculateRenderBounds(); void AddToRenderer(const zeus::CFrustum&, CStateManager&); void ComputeFreeLook(const CFinalInput& input); void UpdateFreeLook(float dt); diff --git a/Runtime/World/CRipple.cpp b/Runtime/World/CRipple.cpp new file mode 100644 index 000000000..e27dcbefd --- /dev/null +++ b/Runtime/World/CRipple.cpp @@ -0,0 +1,7 @@ +#include "CRipple.hpp" +namespace urde +{ +CRipple::CRipple(TUniqueId, const zeus::CVector3f&, float) +{ +} +} diff --git a/Runtime/World/CRipple.hpp b/Runtime/World/CRipple.hpp new file mode 100644 index 000000000..dee8e76bd --- /dev/null +++ b/Runtime/World/CRipple.hpp @@ -0,0 +1,35 @@ +#ifndef __URDE_CRIPPLE_HPP__ +#define __URDE_CRIPPLE_HPP__ + +#include "RetroTypes.hpp" +#include "zeus/CVector3f.hpp" + +namespace urde +{ +class CRipple +{ +private: + TUniqueId x0_; + float x4_ = 0.f; + zeus::CVector3f x8_; + float x14_ = 2.f; + float x18_ = 12.f; + float x1c_ = 3.f; + float x20_ = 0.25f; + float x24_ = 0.00098039221f; +public: + CRipple(TUniqueId, const zeus::CVector3f&, float); + + void SetTime(float); + float GetTime() const; + float GetTimeFalloff() const; + TUniqueId GetUniqueId() const; + float GetFequency() const; + float GetAmplitude() const; + float GetOODistanceFalloff() const; + float GetDistanceFalloff() const; + zeus::CVector3f GetCenter() const; + float GetOOTimeFalloff() const; +}; +} +#endif // __URDE_CRIPPLE_HPP__ diff --git a/Runtime/World/CRippleManager.cpp b/Runtime/World/CRippleManager.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/World/CRippleManager.hpp b/Runtime/World/CRippleManager.hpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/World/CScriptActorKeyframe.cpp b/Runtime/World/CScriptActorKeyframe.cpp new file mode 100644 index 000000000..cc05ef0a2 --- /dev/null +++ b/Runtime/World/CScriptActorKeyframe.cpp @@ -0,0 +1,33 @@ +#include "CScriptActorKeyframe.hpp" + +namespace urde +{ +CScriptActorKeyframe::CScriptActorKeyframe(TUniqueId uid, const std::string& name, const CEntityInfo& info, s32 animId, + bool b1, float f1, bool b2, u32 w2, bool active, float totalPlayback) +: CEntity(uid, info, active, name), + x34_animationId(animId), + x38_(f1), + x3c_(totalPlayback), + x40_(f1), + x44_24_(b1), + x44_25_(b2), + x44_26_(w2) +{ +} + +void CScriptActorKeyframe::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) +{ + +} + +void CScriptActorKeyframe::Think(float dt, CStateManager& mgr) +{ + if (x44_25_) + ; +} + +void CScriptActorKeyframe::UpdateEntity(TUniqueId, CStateManager&) +{ + +} +} diff --git a/Runtime/World/CScriptActorKeyframe.hpp b/Runtime/World/CScriptActorKeyframe.hpp new file mode 100644 index 000000000..c0730f137 --- /dev/null +++ b/Runtime/World/CScriptActorKeyframe.hpp @@ -0,0 +1,38 @@ +#ifndef __URDE_CSCRIPTACTORKEYFRAME_HPP__ +#define __URDE_CSCRIPTACTORKEYFRAME_HPP__ + +#include "CEntity.hpp" + +namespace urde +{ +class CScriptActorKeyframe : public CEntity +{ +private: + s32 x34_animationId; + float x38_; + float x3c_; + float x40_; + union + { + struct + { + bool x44_24_ : 1; + bool x44_25_ : 1; + bool x44_26_ : 1; + bool x44_27_ : 1; + bool x44_28_ : 1; + bool x44_29_ : 1; + }; + u8 _dummy = 0; + }; +public: + CScriptActorKeyframe(TUniqueId uid, const std::string& name, const CEntityInfo& info, s32 w1, bool b1, float f1, + bool b2, u32 w2, bool active, float f2); + + void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr); + void Think(float, CStateManager &); + void UpdateEntity(TUniqueId, CStateManager&); +}; +} + +#endif // __URDE_CSCRIPTACTORKEYFRAME_HPP__ diff --git a/Runtime/World/CScriptTrigger.cpp b/Runtime/World/CScriptTrigger.cpp index ba63a1e41..cf22ab706 100644 --- a/Runtime/World/CScriptTrigger.cpp +++ b/Runtime/World/CScriptTrigger.cpp @@ -10,7 +10,7 @@ namespace urde CScriptTrigger::CScriptTrigger(TUniqueId uid, const std::string& name, const CEntityInfo& info, const zeus::CVector3f& pos, const zeus::CAABox& bounds, const CDamageInfo& dInfo, const zeus::CVector3f& forceField, - u32 triggerFlags, bool active, bool b2, bool b3) + ETriggerFlags triggerFlags, bool active, bool b2, bool b3) : CActor(uid, active, name, info, zeus::CTransform::Translate(pos), CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::ThirtyFour), CActorParameters::None(), kInvalidUniqueId), x100_damageInfo(dInfo), @@ -25,9 +25,8 @@ CScriptTrigger::CScriptTrigger(TUniqueId uid, const std::string& name, const CEn CScriptTrigger::CObjectTracker* CScriptTrigger::FindInhabitant(TUniqueId id) { - const auto& iter = std::find_if(xe8_inhabitants.begin(), xe8_inhabitants.end(), [&id](CObjectTracker& tr)->bool{ - return tr.GetObjectId() == id; - }); + const auto& iter = std::find(xe8_inhabitants.begin(), xe8_inhabitants.end(), id); + if (iter != xe8_inhabitants.end()) return &(*iter); return nullptr; diff --git a/Runtime/World/CScriptTrigger.hpp b/Runtime/World/CScriptTrigger.hpp index aabb21e53..dcaec01e9 100644 --- a/Runtime/World/CScriptTrigger.hpp +++ b/Runtime/World/CScriptTrigger.hpp @@ -6,30 +6,54 @@ namespace urde { + +// TODO - Phil: Figure out what each of the DetectProjectiles actually mean +enum class ETriggerFlags : u32 +{ + DetectPlayer = (1 << 0), + DetectAI = (1 << 1), + DetectProjectiles1 = (1 << 2), + DetectProjectiles2 = (1 << 3), + DetectProjectiles3 = (1 << 4), + DetectProjectiles4 = (1 << 5), + DetectBombs = (1 << 6), + Unknown1 = (1 << 7), + DetectProjectiles5 = (1 << 8), + DetectProjectiles6 = (1 << 9), + DetectProjectiles7 = (1 << 10), + KillOnEnter = (1 << 11), + DetectMorphedPlayer = (1 << 12), + ApplyForce = (1 << 13), + DetectPlayerIfInside = (1 << 14), + Unknown2 = (1 << 15), + DetectUnmorphedPlayer = (1 << 16), + BlockEnvironmentalEffects = (1 << 17) +}; +ENABLE_BITWISE_ENUM(ETriggerFlags) + class CScriptTrigger : public CActor { public: class CObjectTracker { TUniqueId x0_id; + public: - CObjectTracker(TUniqueId id) - : x0_id(id) - {} + CObjectTracker(TUniqueId id) : x0_id(id) {} TUniqueId GetObjectId() const { return x0_id; } + bool operator==(const CObjectTracker& other) { return x0_id == other.x0_id; } }; -private: - std::list xe8_inhabitants; /* Used to be CObjectTracker */ +protected: + std::list xe8_inhabitants; CDamageInfo x100_damageInfo; zeus::CVector3f x11c_forceField; float x128_forceMagnitude; - u32 x12c_flags; + ETriggerFlags x12c_flags; zeus::CAABox x130_bounds; - union - { + union { struct { bool x148_24_ : 1; @@ -41,11 +65,11 @@ private: }; u8 dummy = 0; }; + public: - CScriptTrigger(TUniqueId, const std::string& name, const CEntityInfo& info, - const zeus::CVector3f& pos, const zeus::CAABox&, - const CDamageInfo& dInfo, const zeus::CVector3f& orientedForce, - u32 triggerFlags, bool, bool, bool); + CScriptTrigger(TUniqueId, const std::string& name, const CEntityInfo& info, const zeus::CVector3f& pos, + const zeus::CAABox&, const CDamageInfo& dInfo, const zeus::CVector3f& orientedForce, + ETriggerFlags triggerFlags, bool, bool, bool); virtual void InhabitantRejected(CActor&, CStateManager&) {} virtual void InhabitantExited(CActor&, CStateManager&) {} @@ -57,7 +81,6 @@ public: rstl::optional_object GetTouchBounds() const; zeus::CAABox GetTriggerBoundsWR() const; }; - } #endif // __URDE_CSCRIPTTRIGGER_HPP__ diff --git a/Runtime/World/CScriptWater.cpp b/Runtime/World/CScriptWater.cpp index 5fe20c944..a168c8756 100644 --- a/Runtime/World/CScriptWater.cpp +++ b/Runtime/World/CScriptWater.cpp @@ -4,18 +4,86 @@ namespace urde { -CScriptWater::CScriptWater(CStateManager& mgr, TUniqueId uid, const std::string& name, - const CEntityInfo& info, const zeus::CVector3f& pos, const zeus::CAABox& box, - const urde::CDamageInfo& dInfo, zeus::CVector3f& orientedForce, u32 triggerFlags, - bool b1, bool b2, ResId, ResId, ResId, ResId, ResId, ResId, ResId, - const zeus::CVector3f&, float, float, float, bool active, CFluidPlane::EFluidType, - bool, float, const CFluidUVMotion&, - float, float, float, float, float, float, float, float, - const zeus::CColor&, const zeus::CColor&, ResId, ResId, ResId, ResId, - ResId, s32, s32, s32, s32, s32, float, u32, float, float, float, float, float, float, float, float, - const zeus::CColor&, urde::ResId, float, float, float, u32, u32, bool, s32, s32, const u32*) - : CScriptTrigger(uid, name, info, pos, box, dInfo, orientedForce, triggerFlags, active, false, false) +const float CScriptWater::kSplashScales[6] = +{ + 1.0f, 3.0f, 0.709f, + 1.19f, 0.709f, 1.f +}; + +CScriptWater::CScriptWater(CStateManager& mgr, TUniqueId uid, const std::string& name, const CEntityInfo& info, + const zeus::CVector3f& pos, const zeus::CAABox& box, const urde::CDamageInfo& dInfo, + zeus::CVector3f& orientedForce, ETriggerFlags triggerFlags, bool b1, bool b2, ResId, ResId, ResId, + ResId, ResId, ResId, ResId, const zeus::CVector3f&, float, float, float, bool active, + CFluidPlane::EFluidType, bool, float, const CFluidUVMotion&, float, float, float, float, + float, float, float, float, const zeus::CColor&, const zeus::CColor&, ResId, ResId, ResId, + ResId, ResId, s32, s32, s32, s32, s32, float, u32, float, float, float, float, float, float, + float, float, const zeus::CColor&, urde::ResId, float, float, float, u32, u32, bool, s32, + s32, const u32*) +: CScriptTrigger(uid, name, info, pos, box, dInfo, orientedForce, triggerFlags, active, false, false) { } +void CScriptWater::Think(float dt, CStateManager& mgr) { CScriptTrigger::Think(dt, mgr); } + +void CScriptWater::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId other, CStateManager& mgr) +{ + CScriptTrigger::AcceptScriptMsg(msg, other, mgr); +} + +void CScriptWater::PreRender(const zeus::CFrustum&, const CStateManager&) {} + +void CScriptWater::AddToRenderer(const zeus::CFrustum& /*frustum*/, const CStateManager& mgr) const +{ + zeus::CPlane plane; + plane.vec = x34_transform.origin.normalized(); + plane.d = x34_transform.origin.z + x130_bounds.max.z; + zeus::CAABox renderBounds = GetSortingBounds(mgr); + mgr.AddDrawableActorPlane(*this, plane, renderBounds); +} + +void CScriptWater::Render(const CStateManager&) const {} + +void CScriptWater::Touch(CActor&, CStateManager&) +{ +} + +void CScriptWater::CalculateRenderBounds() +{ + +} + +zeus::CAABox CScriptWater::GetSortingBounds(const CStateManager&) const +{ +} + +EWeaponCollisionResponseTypes CScriptWater::GetCollisionResponseType(const zeus::CVector3f&, const zeus::CVector3f&, CWeaponMode&, int) +{ + return EWeaponCollisionResponseTypes::Water; +} + +s16 CScriptWater::GetSplashSound(float dt) const +{ + return x29c_splashSounds[GetSplashIndex(dt)]; +} + +const TLockedToken& CScriptWater::GetSplashEffect(float dt) const +{ + return x268_splashEffects[GetSplashIndex(dt)]; +} + +float CScriptWater::GetSplashEffectScale(float dt) const +{ + if (std::fabs(dt - 1.f) < 0.0000099999997) + return kSplashScales[5]; + + u32 idx = GetSplashIndex(dt); + float s = dt - zeus::floorF(dt * 3.f); + return ((1.f - s) * (s * kSplashScales[idx * 2])) + kSplashScales[idx]; +} + +u32 CScriptWater::GetSplashIndex(float dt) const +{ + u32 idx = dt * 3.f; + return (idx < 3 ? idx : idx - 1); +} } diff --git a/Runtime/World/CScriptWater.hpp b/Runtime/World/CScriptWater.hpp index 4cc52245a..942429211 100644 --- a/Runtime/World/CScriptWater.hpp +++ b/Runtime/World/CScriptWater.hpp @@ -2,8 +2,7 @@ #define __URDE_CSCRIPTWATER_HPP__ #include "CScriptTrigger.hpp" -#include "CFluidPlane.hpp" - +#include "CFluidPlaneCPU.hpp" namespace urde { @@ -12,17 +11,69 @@ class CFluidUVMotion; class CScriptWater : public CScriptTrigger { +private: + static const float kSplashScales[6]; + u32 x150_ = 0; + std::unique_ptr x1b4_; + zeus::CVector3f x1b8_; + float x1f4_; + float x1f8_ = 0.f; + zeus::CVector3f x1d4_; + std::vector> x200_waterInhabitants; + u32 x210_; + float x214_; + float x218_; + float x21c_; + float x220_; + float x224_; + zeus::CColor x228_; + u32 x22c_; + u32 x230_; + u32 x234_; + u32 x238_; + u32 x248_; + u32 x24c_; + bool x25c_; + s16 x260_; + s16 x262_; + u32 x264_ = 0; + TLockedToken x268_splashEffects[5]; + s16 x29c_splashSounds[5]; public: - CScriptWater(CStateManager &,TUniqueId, const std::string& name, const CEntityInfo&, const zeus::CVector3f&, - const zeus::CAABox&, CDamageInfo const &, zeus::CVector3f&, u32, bool, bool, - ResId, ResId, ResId, ResId, ResId, ResId, ResId, - const zeus::CVector3f&, float, float, float, bool, CFluidPlane::EFluidType, bool, float, const CFluidUVMotion&, - float, float, float, float, float, float, float, float, const zeus::CColor&, const zeus::CColor&, - ResId, ResId, ResId, ResId, ResId, s32, s32, s32, s32, s32, - float, u32, float, float, float, float, float, float, float, float, - const zeus::CColor&, ResId, float, float, float, u32, u32, bool, s32, s32, const u32*); -}; + CScriptWater(CStateManager&, TUniqueId, const std::string& name, const CEntityInfo&, const zeus::CVector3f&, + const zeus::CAABox&, CDamageInfo const&, zeus::CVector3f&, ETriggerFlags, bool, bool, ResId, ResId, ResId, ResId, + ResId, ResId, ResId, const zeus::CVector3f&, float, float, float, bool, CFluidPlane::EFluidType, bool, + float, const CFluidUVMotion&, float, float, float, float, float, float, float, float, + const zeus::CColor&, const zeus::CColor&, ResId, ResId, ResId, ResId, ResId, s32, s32, s32, s32, s32, + float, u32, float, float, float, float, float, float, float, float, const zeus::CColor&, ResId, float, + float, float, u32, u32, bool, s32, s32, const u32*); + void Think(float, CStateManager&); + void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&); + void PreRender(const zeus::CFrustum&, const CStateManager&); + void AddToRenderer(const zeus::CFrustum&, const CStateManager&) const; + void Render(const CStateManager&) const; + void Touch(CActor &, CStateManager &); + void CalculateRenderBounds(); + zeus::CAABox GetSortingBounds(const CStateManager&) const; + void RenderSurface(); + EWeaponCollisionResponseTypes GetCollisionResponseType(const zeus::CVector3f&, const zeus::CVector3f&, CWeaponMode&, + int); + + void UpdateSplashInhabitants(CStateManager&); + s16 GetSplashSound(float) const; + const TLockedToken& GetSplashEffect(float) const; + float GetSplashEffectScale(float) const; + u32 GetSplashIndex(float) const; + void FluidPlane(); + zeus::CPlane GetWRSurfacePlane() const; + float GetSurfaceZ() const; + bool IsMorphing() const; + void SetMorphing(bool); + zeus::CColor GetSplashColor() const; + void SetFrustumPlanes(const zeus::CFrustum& frustum); + const zeus::CFrustum& GetFrustumPlanes() const; +}; } #endif // __URDE_CSCRIPTWATER_HPP__ diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index 4469263a6..fcf8e73e0 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -19,6 +19,7 @@ #include "CScriptTimer.hpp" #include "CScriptCounter.hpp" #include "CScriptDock.hpp" +#include "CScriptActorKeyframe.hpp" #include "CScriptWater.hpp" #include "CScriptEffect.hpp" #include "CScriptPlatform.hpp" @@ -503,8 +504,8 @@ CEntity* ScriptLoader::LoadTrigger(CStateManager& mgr, CInputStream& in, int pro zeus::CVector3f forceVec; forceVec.readBig(in); - u32 w1 = in.readUint32Big(); - bool b1 = in.readBool(); + ETriggerFlags flags = ETriggerFlags(in.readUint32Big()); + bool active = in.readBool(); bool b2 = in.readBool(); bool b3 = in.readBool(); @@ -513,7 +514,7 @@ CEntity* ScriptLoader::LoadTrigger(CStateManager& mgr, CInputStream& in, int pro const zeus::CTransform& areaXf = mgr.GetWorld()->GetGameAreas()[info.GetAreaId()]->GetTransform(); zeus::CVector3f orientedForce = areaXf.basis * forceVec; - return new CScriptTrigger(mgr.AllocateUniqueId(), *name, info, position, box, dInfo, orientedForce, w1, b1, b2, b3); + return new CScriptTrigger(mgr.AllocateUniqueId(), *name, info, position, box, dInfo, orientedForce, flags, active, b2, b3); } CEntity* ScriptLoader::LoadTimer(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) @@ -1141,7 +1142,21 @@ CEntity* ScriptLoader::LoadCameraShaker(CStateManager& mgr, CInputStream& in, in CEntity* ScriptLoader::LoadActorKeyframe(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { - return nullptr; + if (!EnsurePropertyCount(propCount, 7, "ActorKeyframe")) + return nullptr; + + const std::string* name = mgr.HashInstanceName(in); + s32 w1 = in.readInt32Big(); + bool b1 = in.readBool(); + float f1 = in.readFloatBig(); + bool active = in.readBool(); + u32 w2 = in.readUint32Big(); + float f2 = in.readFloatBig(); + + if (w1 == -1) + return nullptr; + + return new CScriptActorKeyframe(mgr.AllocateUniqueId(), *name, info, w1, b1, f1, false, w2, active, f2); } CEntity* ScriptLoader::LoadWater(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) @@ -1157,7 +1172,11 @@ CEntity* ScriptLoader::LoadWater(CStateManager& mgr, CInputStream& in, int propC CDamageInfo dInfo(in); zeus::CVector3f orientedForce; orientedForce.readBig(in); - u32 triggerFlags = in.readUint32Big() | 2044; + ETriggerFlags triggerFlags = ETriggerFlags(in.readUint32Big()) | ETriggerFlags::DetectProjectiles1 | + ETriggerFlags::DetectProjectiles2 | ETriggerFlags::DetectProjectiles3 | + ETriggerFlags::DetectProjectiles4 | ETriggerFlags::DetectBombs | + ETriggerFlags::Unknown1 | ETriggerFlags::DetectProjectiles5 | + ETriggerFlags::DetectProjectiles6 | ETriggerFlags::DetectProjectiles7; bool b1 = in.readBool(); bool displaySurface = in.readBool(); ResId textureId1 = in.readUint32Big();