Optimize physics simulation collisions pair cache

This commit is contained in:
Wojtek Figat
2021-07-08 10:10:19 +02:00
parent d86dfbb973
commit d5db9dd00c
3 changed files with 27 additions and 15 deletions

View File

@@ -556,6 +556,18 @@ public:
SetCapacity(0, false);
}
/// <summary>
/// Swaps the contents of collection with the other object without copy operation. Performs fast internal data exchange.
/// </summary>
/// <param name="other">The other collection.</param>
void Swap(Dictionary& other)
{
::Swap(_elementsCount, other._elementsCount);
::Swap(_deletedCount, other._deletedCount);
::Swap(_size, other._size);
_allocation.Swap(other._allocation);
}
public:
/// <summary>

View File

@@ -2,11 +2,9 @@
#include "SimulationEventCallback.h"
#include "Utilities.h"
#include "FlaxEngine.Gen.h"
#include "Colliders/Collider.h"
#include "Joints/Joint.h"
#include "Actors/RigidBody.h"
#include "Engine/Core/Log.h"
#include <ThirdParty/PhysX/extensions/PxJoint.h>
#include <ThirdParty/PhysX/PxShape.h>
@@ -39,6 +37,20 @@ namespace
}
}
void SimulationEventCallback::Clear()
{
PrevCollisions.Swap(Collisions);
Collisions.Clear();
NewCollisions.Clear();
RemovedCollisions.Clear();
NewTriggerPairs.Clear();
LostTriggerPairs.Clear();
BrokenJoints.Clear();
}
void SimulationEventCallback::CollectResults()
{
// Generate new collisions

View File

@@ -60,19 +60,7 @@ public:
/// <summary>
/// Clears the data.
/// </summary>
void Clear()
{
PrevCollisions = Collisions;
Collisions.Clear();
NewCollisions.Clear();
RemovedCollisions.Clear();
NewTriggerPairs.Clear();
LostTriggerPairs.Clear();
BrokenJoints.Clear();
}
void Clear();
/// <summary>
/// Generates the new/old/removed collisions and a valid trigger pairs.