17 #ifndef AGXCOLLIDE_COLLISIONGROUPHANDLER_H 18 #define AGXCOLLIDE_COLLISIONGROUPHANDLER_H 112 const CollisionHash& getDisabledGroupCollisions()
const;
113 const CollisionHash& getDisabledSetCollisions()
const;
118 bool hasGroup(
const agx::Name& groupName)
const;
129 SymmetricCollisionGroupVector getDisabledCollisionGroupPairs()
const;
152 bool internal_canCollide(
const GroupIdHash& groups1,
const GroupIdHash& groups2);
153 void removeInactiveSets();
185 {
return state >= ACTIVE; }
190 return state == VALID;
194 friend class GroupSetCache;
213 m_maxProbeLength = 0;
231 agxAssert(
set &&
set.groups().size() + 1 < 1024);
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);
253 agxAssert(
set &&
set.groups().size() - 1 < 1024);
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();
285 const GroupVector& groups =
set.groups();
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)
341 targetBucket->state = Bucket::VALID;
347 return find(
set).isValid();
354 const GroupVector& groups =
set.groups();
359 Bucket *bucket = &m_buckets[bucketIndex];
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];
451 m_allocator.deallocateBytes((
void *)oldBuckets, oldNumBuckets *
sizeof(
Bucket));
454 void deallocateBuckets()
456 m_allocator.deallocateBytes(m_buckets, m_capacity *
sizeof(
Bucket));
473 GroupSetCache m_groupSetCache;
476 CollisionHash m_disabledSetCollisions;
477 CollisionHash m_disabledGroupCollisions;
484 CollisionGroupTable m_collisionGroupTable;
487 CollisionGroupNameTable m_collisionGroupNameTable;
bool canSetsCollide(agx::UInt32 set1, agx::UInt32 set2) const
agx::HashSet< agx::UInt32 > GroupIdHash
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...
AGXCORE_EXPORT UInt32 hash(const T &key)
AGXTERRAIN_EXPORT void clear()
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Data storage for a collection of entity instances of a specified EntityModel.
A component is an object containing other objects, enabling hierarchical structuring.
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Pointer to a entity instance of type Physics.CollisionGroup.
const CollisionHash & getDisabledGroupCollisions() const
std::pair< agx::Name, agx::Real > Bucket
#define AGXPHYSICS_EXPORT
AGXCORE_EXPORT const InvalidIndexStruct InvalidIndex
Representation of a name string.
Pointer to a entity instance of type Physics.CollisionGroupSet.
std::ostream & operator<<(std::ostream &output, const BoundingAABB &bound)
#define AGX_HASH_SET_GROW_THRESHOLD
#define AGX_HASH_SET_GROW_FACTOR
AGXCORE_EXPORT agx::UInt64 buildHashKey(agx::UInt32 id1, agx::UInt32 id2)
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
agx::HashSet< agx::UInt64 > CollisionHash
agx::HashSet< agx::Physics::CollisionGroupPtr > GroupHash
agx::Vector< agx::Physics::CollisionGroupSetPtr > GroupSetVector
Bucket & operator=(const Bucket &b)
agx::Vector< agx::Physics::CollisionGroupPtr > GroupVector
#define AGX_HASH_SET_MAX_PROBE_LENGTH
bool canGroupsCollide(agx::UInt32 group1, agx::UInt32 group2) const
agx::Vector< agx::SymmetricPair< agx::Physics::CollisionGroupPtr > > SymmetricCollisionGroupVector
AGXCORE_EXPORT int nextPrime(int n)
AGXPHYSICS_EXPORT bool setEnableCollisions(agx::RigidBody *rb1, agx::RigidBody *rb2, bool enable)
Enable or disable the collision between all geometries in RigidBody rb1 and RigidBody rb2...
#define AGX_HASH_SET_MIN_SIZE
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
const CollisionHash & getDisabledSetCollisions() const
agx::HashSet< agx::Physics::CollisionGroupSetPtr > GroupSetHash
Inheritance with partial specialization due to bug with ref_ptr containers.
agxData::EntityStorage * getStorage() const
AGXPHYSICS_EXPORT agx::UInt32 & id()
agx::Physics::CollisionGroupSetPtr groupSet
AGX_DECLARE_POINTER_TYPES(SpaceListener)