From 664cbec76935e06877412bf189847af5de43501e Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 14 Apr 2017 19:49:01 -1000 Subject: [PATCH] Move some collision functions to CGameCollision.cpp --- Runtime/CStateManager.cpp | 52 +++------------------------- Runtime/CStateManager.hpp | 5 --- Runtime/Character/CActorLights.cpp | 2 +- Runtime/Collision/CGameCollision.cpp | 49 ++++++++++++++++++++++++-- Runtime/Collision/CGameCollision.hpp | 12 +++++-- 5 files changed, 63 insertions(+), 57 deletions(-) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 4ab4a73d8..79521cb88 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -1498,7 +1498,7 @@ bool CStateManager::TestRayDamage(const zeus::CVector3f& pos, const CActor& dama if (count == 0 || count == 1) return true; - return RayCollideDynamic(pos, dir, filter, nearList, &damagee, depth * origMag); + return CGameCollision::RayDynamicIntersectionBool(*this, pos, dir, filter, nearList, &damagee, depth * origMag); } bool CStateManager::RayCollideWorld(const zeus::CVector3f& pos, const zeus::CVector3f& damageeCenter, @@ -1519,9 +1519,9 @@ bool CStateManager::RayCollideWorldInternal(const zeus::CVector3f& pos, const ze float mag = vecToDamagee.magnitude(); zeus::CVector3f dir = vecToDamagee * (1.f / mag); - if (!RayCollideStatic(pos, dir, mag, filter)) + if (!CGameCollision::RayStaticIntersectionBool(*this, pos, dir, mag, filter)) return false; - return RayCollideDynamic(pos, dir, filter, nearList, damagee, mag); + return CGameCollision::RayDynamicIntersectionBool(*this, pos, dir, filter, nearList, damagee, mag); } bool CStateManager::MultiRayCollideWorld(const zeus::CMRay& ray, const CMaterialFilter& filter) @@ -1543,56 +1543,14 @@ bool CStateManager::MultiRayCollideWorld(const zeus::CMRay& ray, const CMaterial { zeus::CVector3f& useCrossed = (i & 2) ? negCrossed2 : crossed2; zeus::CVector3f& useRms = (i & 1) ? rms : negRms; - if (RayCollideStatic(ray.start + useCrossed + useRms, ray.dir, ray.length, filter)) + if (CGameCollision::RayStaticIntersectionBool(*this, ray.start + useCrossed + useRms, + ray.dir, ray.length, filter)) return true; } return false; } -bool CStateManager::RayCollideStatic(const zeus::CVector3f& start, const zeus::CVector3f& dir, float length, - const CMaterialFilter& filter) -{ - if (length <= 0.f) - length = 100000.f; - zeus::CLine line(start, dir); - for (const CGameArea& area : *x850_world) - { - const CAreaOctTree& collision = *area.GetPostConstructed()->x0_collision; - CAreaOctTree::Node root = collision.GetRootNode(); - if (!root.LineTest(line, filter, length)) - return false; - } - - return true; -} - -bool CStateManager::RayCollideDynamic(const zeus::CVector3f& pos, const zeus::CVector3f& dir, - const CMaterialFilter& filter, - const rstl::reserved_vector& nearList, - const CActor* damagee, float length) -{ - if (length <= 0.f) - length = 100000.f; - - for (TUniqueId id : nearList) - { - CEntity* ent = ObjectById(id); - if (TCastToPtr physActor = ent) - { - if (damagee && physActor->GetUniqueId() == damagee->GetUniqueId()) - continue; - zeus::CTransform xf = physActor->GetPrimitiveTransform(); - const CCollisionPrimitive* prim = physActor->GetCollisionPrimitive(); - CRayCastResult res = prim->CastRay(pos, dir, length, filter, xf); - if (!res.IsInvalid()) - return false; - } - } - - return true; -} - void CStateManager::TestBombHittingWater(const CActor& damager, const zeus::CVector3f& pos, CActor& damagee) { if (TCastToPtr wpn = const_cast(damager)) diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index 9cce3f776..622984eb5 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -336,11 +336,6 @@ public: const rstl::reserved_vector& nearList, const CActor* damagee); bool MultiRayCollideWorld(const zeus::CMRay& ray, const CMaterialFilter& filter); - bool RayCollideStatic(const zeus::CVector3f& start, const zeus::CVector3f& dir, float length, - const CMaterialFilter& filter); - bool RayCollideDynamic(const zeus::CVector3f& pos, const zeus::CVector3f& dir, - const CMaterialFilter& filter, const rstl::reserved_vector& nearList, - const CActor* damagee, float length); void TestBombHittingWater(const CActor& damager, const zeus::CVector3f& pos, CActor& damagee); bool ApplyLocalDamage(const zeus::CVector3f&, const zeus::CVector3f&, CActor&, float, const CWeaponMode&); diff --git a/Runtime/Character/CActorLights.cpp b/Runtime/Character/CActorLights.cpp index 4cbd43a3c..c1c328145 100644 --- a/Runtime/Character/CActorLights.cpp +++ b/Runtime/Character/CActorLights.cpp @@ -390,7 +390,7 @@ bool CActorLights::BuildAreaLightList(const CStateManager& mgr, const CGameArea& { /* Note brightest light contact */ delta = delta * 1.f / deltaMag; - actorToLightContact = CGameCollision::TestLightRayIntersection(area, vec, delta, deltaMag, filter); + actorToLightContact = CGameCollision::RayStaticIntersectionArea(area, vec, delta, deltaMag, filter); if (i == 0) { x299_24_inBrightLight = actorToLightContact; diff --git a/Runtime/Collision/CGameCollision.cpp b/Runtime/Collision/CGameCollision.cpp index a04cf3284..c773d6e4b 100644 --- a/Runtime/Collision/CGameCollision.cpp +++ b/Runtime/Collision/CGameCollision.cpp @@ -113,6 +113,24 @@ CGameCollision::RayStaticIntersection(const CStateManager& mgr, const zeus::CVec return ret; } +bool CGameCollision::RayStaticIntersectionBool(const CStateManager& mgr, const zeus::CVector3f& start, + const zeus::CVector3f& dir, float length, + const CMaterialFilter& filter) +{ + if (length <= 0.f) + length = 100000.f; + zeus::CLine line(start, dir); + for (const CGameArea& area : *mgr.GetWorld()) + { + const CAreaOctTree& collision = *area.GetPostConstructed()->x0_collision; + CAreaOctTree::Node root = collision.GetRootNode(); + if (!root.LineTest(line, filter, length)) + return false; + } + + return true; +} + CRayCastResult CGameCollision::RayDynamicIntersection(const CStateManager& mgr, TUniqueId& idOut, const zeus::CVector3f& pos, const zeus::CVector3f& dir, float length, const CMaterialFilter& filter, @@ -143,6 +161,33 @@ CGameCollision::RayDynamicIntersection(const CStateManager& mgr, TUniqueId& idOu return ret; } +bool CGameCollision::RayDynamicIntersectionBool(const CStateManager& mgr, + const zeus::CVector3f& pos, const zeus::CVector3f& dir, + const CMaterialFilter& filter, + const rstl::reserved_vector& nearList, + const CActor* damagee, float length) +{ + if (length <= 0.f) + length = 100000.f; + + for (TUniqueId id : nearList) + { + const CEntity* ent = mgr.GetObjectById(id); + if (TCastToConstPtr physActor = ent) + { + if (damagee && physActor->GetUniqueId() == damagee->GetUniqueId()) + continue; + zeus::CTransform xf = physActor->GetPrimitiveTransform(); + const CCollisionPrimitive* prim = physActor->GetCollisionPrimitive(); + CRayCastResult res = prim->CastRay(pos, dir, length, filter, xf); + if (!res.IsInvalid()) + return false; + } + } + + return true; +} + CRayCastResult CGameCollision::RayWorldIntersection(const CStateManager& mgr, TUniqueId& idOut, const zeus::CVector3f& pos, const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter, @@ -159,8 +204,8 @@ CGameCollision::RayWorldIntersection(const CStateManager& mgr, TUniqueId& idOut, return staticRes; } -bool CGameCollision::TestLightRayIntersection(const CGameArea& area, const zeus::CVector3f& pos, - const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter) +bool CGameCollision::RayStaticIntersectionArea(const CGameArea& area, const zeus::CVector3f& pos, + const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter) { if (mag <= 0.f) mag = 100000.f; diff --git a/Runtime/Collision/CGameCollision.hpp b/Runtime/Collision/CGameCollision.hpp index c245fd34f..102d98b24 100644 --- a/Runtime/Collision/CGameCollision.hpp +++ b/Runtime/Collision/CGameCollision.hpp @@ -39,14 +39,22 @@ public: void SendMaterialMessage(CStateManager&, const CMaterialList&, CActor&); static CRayCastResult RayStaticIntersection(const CStateManager& mgr, const zeus::CVector3f& pos, const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter); + static bool RayStaticIntersectionBool(const CStateManager& mgr, const zeus::CVector3f& start, + const zeus::CVector3f& dir, float length, + const CMaterialFilter& filter); static CRayCastResult RayDynamicIntersection(const CStateManager& mgr, TUniqueId& idOut, const zeus::CVector3f& pos, const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter, const rstl::reserved_vector& nearList); + static bool RayDynamicIntersectionBool(const CStateManager& mgr, + const zeus::CVector3f& pos, const zeus::CVector3f& dir, + const CMaterialFilter& filter, + const rstl::reserved_vector& nearList, + const CActor* damagee, float length); static CRayCastResult RayWorldIntersection(const CStateManager& mgr, TUniqueId& idOut, const zeus::CVector3f& pos, const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter, const rstl::reserved_vector& nearList); - static bool TestLightRayIntersection(const CGameArea& area, const zeus::CVector3f& pos, - const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter); + static bool RayStaticIntersectionArea(const CGameArea& area, const zeus::CVector3f& pos, + const zeus::CVector3f& dir, float mag, const CMaterialFilter& filter); }; }