mirror of https://github.com/godotengine/godot
Improve performance of certain physics queries when using Jolt Physics
This commit is contained in:
parent
296de7da83
commit
5d2a54e6b1
|
|
@ -76,7 +76,7 @@ bool JoltPhysicsDirectSpaceState3D::_cast_motion_impl(const JPH::Shape &p_jolt_s
|
||||||
aabb_translated.Translate(motion);
|
aabb_translated.Translate(motion);
|
||||||
aabb.Encapsulate(aabb_translated);
|
aabb.Encapsulate(aabb_translated);
|
||||||
|
|
||||||
JoltQueryCollectorAnyMulti<JPH::CollideShapeBodyCollector, 2048> aabb_collector;
|
JoltQueryCollectorAnyMulti<JPH::CollideShapeBodyCollector, 1024> aabb_collector;
|
||||||
space->get_broad_phase_query().CollideAABox(aabb, aabb_collector, p_broad_phase_layer_filter, p_object_layer_filter);
|
space->get_broad_phase_query().CollideAABox(aabb, aabb_collector, p_broad_phase_layer_filter, p_object_layer_filter);
|
||||||
|
|
||||||
if (!aabb_collector.had_hit()) {
|
if (!aabb_collector.had_hit()) {
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,9 @@
|
||||||
#include "../jolt_project_settings.h"
|
#include "../jolt_project_settings.h"
|
||||||
#include "jolt_space_3d.h"
|
#include "jolt_space_3d.h"
|
||||||
|
|
||||||
#include "core/templates/local_vector.h"
|
|
||||||
|
|
||||||
#include "Jolt/Jolt.h"
|
#include "Jolt/Jolt.h"
|
||||||
|
|
||||||
|
#include "Jolt/Core/STLLocalAllocator.h"
|
||||||
#include "Jolt/Physics/Collision/InternalEdgeRemovingCollector.h"
|
#include "Jolt/Physics/Collision/InternalEdgeRemovingCollector.h"
|
||||||
#include "Jolt/Physics/Collision/Shape/Shape.h"
|
#include "Jolt/Physics/Collision/Shape/Shape.h"
|
||||||
|
|
||||||
|
|
@ -45,11 +44,16 @@ template <typename TBase, int TDefaultCapacity>
|
||||||
class JoltQueryCollectorAll final : public TBase {
|
class JoltQueryCollectorAll final : public TBase {
|
||||||
public:
|
public:
|
||||||
typedef typename TBase::ResultType Hit;
|
typedef typename TBase::ResultType Hit;
|
||||||
|
typedef JPH::Array<Hit, JPH::STLLocalAllocator<Hit, TDefaultCapacity>> HitArray;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JPH::Array<Hit> hits;
|
HitArray hits;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
JoltQueryCollectorAll() {
|
||||||
|
hits.reserve(TDefaultCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
bool had_hit() const {
|
bool had_hit() const {
|
||||||
return !hits.is_empty();
|
return !hits.is_empty();
|
||||||
}
|
}
|
||||||
|
|
@ -109,14 +113,17 @@ template <typename TBase, int TDefaultCapacity>
|
||||||
class JoltQueryCollectorAnyMulti final : public TBase {
|
class JoltQueryCollectorAnyMulti final : public TBase {
|
||||||
public:
|
public:
|
||||||
typedef typename TBase::ResultType Hit;
|
typedef typename TBase::ResultType Hit;
|
||||||
|
typedef JPH::Array<Hit, JPH::STLLocalAllocator<Hit, TDefaultCapacity>> HitArray;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JPH::Array<Hit> hits;
|
HitArray hits;
|
||||||
int max_hits = 0;
|
int max_hits = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit JoltQueryCollectorAnyMulti(int p_max_hits = TDefaultCapacity) :
|
explicit JoltQueryCollectorAnyMulti(int p_max_hits = TDefaultCapacity) :
|
||||||
max_hits(p_max_hits) {}
|
max_hits(p_max_hits) {
|
||||||
|
hits.reserve(TDefaultCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
bool had_hit() const {
|
bool had_hit() const {
|
||||||
return hits.size() > 0;
|
return hits.size() > 0;
|
||||||
|
|
@ -189,14 +196,17 @@ template <typename TBase, int TDefaultCapacity>
|
||||||
class JoltQueryCollectorClosestMulti final : public TBase {
|
class JoltQueryCollectorClosestMulti final : public TBase {
|
||||||
public:
|
public:
|
||||||
typedef typename TBase::ResultType Hit;
|
typedef typename TBase::ResultType Hit;
|
||||||
|
typedef JPH::Array<Hit, JPH::STLLocalAllocator<Hit, TDefaultCapacity + 1>> HitArray;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JPH::Array<Hit> hits;
|
HitArray hits;
|
||||||
int max_hits = 0;
|
int max_hits = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit JoltQueryCollectorClosestMulti(int p_max_hits = TDefaultCapacity) :
|
explicit JoltQueryCollectorClosestMulti(int p_max_hits = TDefaultCapacity) :
|
||||||
max_hits(p_max_hits) {}
|
max_hits(p_max_hits) {
|
||||||
|
hits.reserve(TDefaultCapacity + 1);
|
||||||
|
}
|
||||||
|
|
||||||
bool had_hit() const {
|
bool had_hit() const {
|
||||||
return hits.size() > 0;
|
return hits.size() > 0;
|
||||||
|
|
@ -220,7 +230,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void AddHit(const Hit &p_hit) override {
|
virtual void AddHit(const Hit &p_hit) override {
|
||||||
typename JPH::Array<Hit>::const_iterator E = hits.cbegin();
|
typename HitArray::const_iterator E = hits.cbegin();
|
||||||
for (; E != hits.cend(); ++E) {
|
for (; E != hits.cend(); ++E) {
|
||||||
if (p_hit.GetEarlyOutFraction() < E->GetEarlyOutFraction()) {
|
if (p_hit.GetEarlyOutFraction() < E->GetEarlyOutFraction()) {
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue