17#ifndef AGXCOLLIDE_COLLISIONGROUPHANDLER_H
18#define AGXCOLLIDE_COLLISIONGROUPHANDLER_H
147 agx::UInt32 generateNameId();
148 void setUniqueIdCounter(
agx::UInt32
id);
149 void setNameIdCounter(
agx::UInt32
id);
150 agx::Physics::CollisionGroupPtr restoreGroup(const
agx::Name& groupName,
agx::UInt32
id);
154 agx::Physics::CollisionGroupSetPtr getUnarySet(
agx::UInt32 groupId);
155 void internal_unreferenceSet(
agx::Physics::CollisionGroupSetPtr set);
157 void removeInactiveSets();
158 void registerNewSet(
agx::Physics::CollisionGroupSetPtr set);
188 {
return state >= ACTIVE; }
193 return state == VALID;
197 friend class GroupSetCache;
216 m_maxProbeLength = 0;
236 size_t numGroups = 0;
239 const GroupVector& groups = set.
groups();
241 for (; i < groups.size() && groups[i].
id() < group.
id(); ++i)
242 localGroups[numGroups++] = groups[i];
244 localGroups[numGroups++] = group;
246 for (; i < groups.size(); ++i)
247 localGroups[numGroups++] = groups[i];
250 agx::UInt32 bucketIndex = findBucket(localGroups, numGroups);
258 size_t numGroups = 0;
261 const GroupVector& groups = set.
groups();
262 for (
size_t i = 0; i < groups.size(); ++i)
264 if (groups[i].
id() == group.
id())
267 localGroups[numGroups++] = groups[i];
270 agx::UInt32 bucketIndex = findBucket(localGroups, numGroups);
279 const GroupVector& groups = set.
groups();
281 agx::UInt32 bucketIndex = findBucket(groups.begin(), groups.size());
288 const GroupVector& groups = set.
groups();
290 agx::UInt32 hashValue = calculateHash(groups.begin(), groups.size());
305 bucket = &m_buckets[(hashValue + offset * offset) %
m_capacity];
308 if (bucket->isValid() && compareGroups(groups.begin(), groups.size(), bucket->groupSet))
310 targetBucket = bucket;
315 if (!bucket->isValid() && !targetBucket)
316 targetBucket = bucket;
319 if (targetBucket && offset >= m_maxProbeLength)
329 return this->insert(set);
335 if (offset > m_maxProbeLength)
338 targetBucket->groupSet = set;
341 if (!targetBucket->isValid())
344 targetBucket->state = Bucket::VALID;
350 return find(set).isValid();
357 const GroupVector& groups = set.
groups();
359 agx::UInt32 bucketIndex = findBucket(groups.begin(), groups.size());
362 Bucket *bucket = &m_buckets[bucketIndex];
363 agxAssert(bucket->isValid() && compareGroups(groups.begin(), groups.size(), bucket->groupSet));
368 bucket->state = Bucket::ACTIVE;
378 agx::UInt32 hashValue = calculateHash(localGroups, numGroups);
381 const Bucket *bucket = &m_buckets[index];
384 if (bucket->isValid() && compareGroups(localGroups, numGroups, bucket->groupSet))
388 for (
size_t offset = 1; bucket->isActive() && offset <= m_maxProbeLength; offset++)
390 index = (hashValue + offset * offset) %
m_capacity;
391 bucket = &m_buckets[index];
393 if (bucket->isValid() && compareGroups(localGroups, numGroups, bucket->groupSet))
406 for (
size_t i = 0; i < numGroups; ++i)
416 const GroupVector& groups = set.
groups();
418 if (groups.size() != numGroups)
421 for (
size_t i = 0; i < groups.size(); ++i)
423 if (groups[i].
id() != localGroups[i].
id())
430 void rebuild(
size_t size)
436 Bucket *oldBuckets = m_buckets;
439 m_buckets = (
Bucket *)m_allocator.allocateBytes(
m_capacity *
sizeof(Bucket));
441 ::new (&m_buckets[i])
Bucket();
444 m_maxProbeLength = 0;
446 for (
size_t i = 0; i < oldNumBuckets; i++)
448 Bucket& bucket = oldBuckets[i];
450 if (bucket.isValid())
451 this->insert(bucket.groupSet);
454 m_allocator.deallocateBytes((
void *)oldBuckets, oldNumBuckets *
sizeof(Bucket));
457 void deallocateBuckets()
459 m_allocator.deallocateBytes(m_buckets,
m_capacity *
sizeof(Bucket));
476 GroupSetCache m_groupSetCache;
479 CollisionHash m_disabledSetCollisions;
480 CollisionHash m_disabledGroupCollisions;
487 CollisionGroupTable m_collisionGroupTable;
490 CollisionGroupNameTable m_collisionGroupNameTable;
#define AGX_DECLARE_POINTER_TYPES(type)
#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
agx::Physics::CollisionGroupSetPtr groupSet
Bucket & operator=(const Bucket &b)
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 agxData::EntityStorage * getCollisionGroupSetStorage() const
const CollisionHash & getDisabledGroupCollisions() const
agx::Physics::CollisionGroupPtr getGroup(const agx::Name &groupName)
const agxData::EntityStorage * getCollisionGroupStorage() const
agx::UInt32 generateUniqueId()
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
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
static CollisionGroupManager * defaultManager()
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
bool hasGroup(agx::UInt32 groupId) const
SymmetricCollisionGroupVector getDisabledCollisionGroupPairs() 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.
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
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()
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
This namespace consists of a set of classes for handling geometric intersection tests including boole...
std::ostream & operator<<(std::ostream &output, const BoundingAABB &bound)
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
std::pair< agx::Name, agx::Real > Bucket
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
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