17 #ifndef AGXCOLLIDE_COLLISIONGROUPHANDLER_H
18 #define AGXCOLLIDE_COLLISIONGROUPHANDLER_H
153 void removeInactiveSets();
185 {
return state >= ACTIVE; }
190 return state == VALID;
194 friend class GroupSetCache;
213 m_maxProbeLength = 0;
233 size_t numGroups = 0;
236 const GroupVector& groups = set.
groups();
238 for (; i < groups.size() && groups[i].
id() < group.
id(); ++i)
239 localGroups[numGroups++] = groups[i];
241 localGroups[numGroups++] = group;
243 for (; i < groups.size(); ++i)
244 localGroups[numGroups++] = groups[i];
247 agx::UInt32 bucketIndex = findBucket(localGroups, numGroups);
255 size_t numGroups = 0;
258 const GroupVector& groups = set.
groups();
259 for (
size_t i = 0; i < groups.size(); ++i)
261 if (groups[i].
id() == group.
id())
264 localGroups[numGroups++] = groups[i];
267 agx::UInt32 bucketIndex = findBucket(localGroups, numGroups);
276 const GroupVector& groups = set.
groups();
278 agx::UInt32 bucketIndex = findBucket(groups.begin(), groups.size());
285 const GroupVector& groups = set.
groups();
287 agx::UInt32 hashValue = calculateHash(groups.begin(), groups.size());
302 bucket = &m_buckets[(hashValue + offset * offset) %
m_capacity];
305 if (bucket->isValid() && compareGroups(groups.begin(), groups.size(), bucket->groupSet))
307 targetBucket = bucket;
312 if (!bucket->isValid() && !targetBucket)
313 targetBucket = bucket;
316 if (targetBucket && offset >= m_maxProbeLength)
326 return this->insert(set);
332 if (offset > m_maxProbeLength)
335 targetBucket->groupSet = set;
338 if (!targetBucket->isValid())
341 targetBucket->state = Bucket::VALID;
347 return find(set).isValid();
354 const GroupVector& groups = set.
groups();
356 agx::UInt32 bucketIndex = findBucket(groups.begin(), groups.size());
359 Bucket *bucket = &m_buckets[bucketIndex];
360 agxAssert(bucket->isValid() && compareGroups(groups.begin(), groups.size(), bucket->groupSet));
365 bucket->state = Bucket::ACTIVE;
375 agx::UInt32 hashValue = calculateHash(localGroups, numGroups);
378 const Bucket *bucket = &m_buckets[index];
381 if (bucket->isValid() && compareGroups(localGroups, numGroups, bucket->groupSet))
385 for (
size_t offset = 1; bucket->isActive() && offset <= m_maxProbeLength; offset++)
387 index = (hashValue + offset * offset) %
m_capacity;
388 bucket = &m_buckets[index];
390 if (bucket->isValid() && compareGroups(localGroups, numGroups, bucket->groupSet))
403 for (
size_t i = 0; i < numGroups; ++i)
413 const GroupVector& groups = set.
groups();
415 if (groups.size() != numGroups)
418 for (
size_t i = 0; i < groups.size(); ++i)
420 if (groups[i].
id() != localGroups[i].
id())
427 void rebuild(
size_t size)
433 Bucket *oldBuckets = m_buckets;
438 ::
new (&m_buckets[i])
Bucket();
441 m_maxProbeLength = 0;
443 for (
size_t i = 0; i < oldNumBuckets; i++)
445 Bucket& bucket = oldBuckets[i];
447 if (bucket.isValid())
448 this->insert(bucket.groupSet);
451 m_allocator.deallocateBytes((
void *)oldBuckets, oldNumBuckets *
sizeof(
Bucket));
454 void deallocateBuckets()
473 GroupSetCache m_groupSetCache;
476 CollisionHash m_disabledSetCollisions;
477 CollisionHash m_disabledGroupCollisions;
484 CollisionGroupTable m_collisionGroupTable;
487 CollisionGroupNameTable m_collisionGroupNameTable;
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXPHYSICS_EXPORT
#define AGX_HASH_SET_MIN_SIZE
#define AGX_HASH_SET_MAX_PROBE_LENGTH
#define AGX_HASH_SET_GROW_FACTOR
#define AGX_HASH_SET_GROW_THRESHOLD
Bucket & operator=(const Bucket &b)
agx::Physics::CollisionGroupSetPtr groupSet
agx::Physics::CollisionGroupSetPtr getExtendedSet(agx::Physics::CollisionGroupSetPtr set, agx::UInt32 groupId, bool unreferenceOldSet=true)
Extend an existing group set by adding an additional group (can be nullptr pointer)
const CollisionHash & getDisabledGroupCollisions() const
agx::Physics::CollisionGroupPtr getGroup(const agx::Name &groupName)
void internal_restore(agxStream::InputArchive &in)
agx::UInt32 generateUniqueId()
static CollisionGroupManager * defaultManager()
static void printSet(const agx::Physics::CollisionGroupSetPtr &set)
static bool hasGroup(agx::Physics::CollisionGroupSetPtr set, agx::UInt32 groupId)
void unreferenceSet(agx::Physics::CollisionGroupSetPtr set)
Unreference a set when it is no longer used.
bool canSetsCollide(agx::UInt32 set1, agx::UInt32 set2) const
static bool hasGroup(agx::Physics::CollisionGroupSetPtr set, const agx::Name &groupName)
agx::HashSet< agx::Physics::CollisionGroupPtr > GroupHash
bool canGroupsCollide(agx::UInt32 group1, agx::UInt32 group2) const
virtual ~CollisionGroupManager()
void setEnableCollisions(agx::UInt32 groupId1, agx::UInt32 groupId2, bool flag)
Enable/disable collisions between two groups.
agx::Vector< agx::Physics::CollisionGroupPtr > GroupVector
static bool verify(agx::Physics::CollisionGroupSetPtr set)
agx::HashSet< agx::UInt32 > GroupIdHash
agx::Vector< agx::Physics::CollisionGroupSetPtr > GroupSetVector
agx::Physics::CollisionGroupSetPtr getExtendedSetFromAddedSet(agx::Physics::CollisionGroupSetPtr set, agx::Physics::CollisionGroupSetPtr set2, bool unreferenceOldSet=true)
Extend an existing group set by adding an additional group set.
const CollisionHash & getDisabledSetCollisions() const
agx::Physics::CollisionGroupPtr getGroup(agx::UInt32 groupId)
agx::Physics::CollisionGroupSetPtr getMatchingSet(agx::Physics::CollisionGroupSetPtr set)
Get the matching set stored in another CollisionGroupManager NOTE: The old set must be manually unref...
agx::HashSet< agx::Physics::CollisionGroupSetPtr > GroupSetHash
const agxData::EntityStorage * getCollisionGroupStorage() const
bool hasGroup(agx::UInt32 groupId) const
SymmetricCollisionGroupVector getDisabledCollisionGroupPairs() const
const agxData::EntityStorage * getCollisionGroupSetStorage() const
bool hasGroup(const agx::Name &groupName) const
agx::HashSet< agx::UInt64 > CollisionHash
agx::Physics::CollisionGroupSetPtr getReducedSet(agx::Physics::CollisionGroupSetPtr set, agx::UInt32 groupId, bool unreferenceOldSet=true)
Reduce an existing group set by removing a group.
agx::Vector< agx::SymmetricPair< agx::Physics::CollisionGroupPtr > > SymmetricCollisionGroupVector
agx::UInt32 getGroupId(const agx::Name &groupName)
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
agxData::EntityStorage * getStorage() const
Data storage for a collection of entity instances of a specified EntityModel.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
A component is an object containing other objects, enabling hierarchical structuring.
bool contains(const KeyT &key) const
Boolean query to test existence of an element.
Inheritance with partial specialization due to bug with ref_ptr containers.
Representation of a name string.
Pointer to a entity instance of type Physics.CollisionGroup.
AGXPHYSICS_EXPORT agx::UInt32 & id()
Pointer to a entity instance of type Physics.CollisionGroupSet.
AGXPHYSICS_EXPORT agx::Vector< agx::Physics::CollisionGroupPtr > & groups()
This namespace consists of a set of classes for handling geometric intersection tests including boole...
std::ostream & operator<<(std::ostream &output, const BoundingAABB &bound)
AGX_DECLARE_POINTER_TYPES(SpaceListener)
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
std::pair< agx::Name, agx::Real > Bucket
AGXTERRAIN_EXPORT void clear()
AGXCORE_EXPORT UInt32 hash(const T &key)
AGXCORE_EXPORT int nextPrime(int n)
AGXCORE_EXPORT agx::UInt64 buildHashKey(agx::UInt32 id1, agx::UInt32 id2)
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)