3#include "Engine/Physics/CollisionProfile.h"
5#include <initializer_list>
11#include <unordered_map>
31 template <
typename ProfileEnum >
34 std::initializer_list<std::pair<ProfileEnum, std::string_view>> values
37 static_assert( std::is_enum_v<ProfileEnum>,
"Collision profiles must be enum values" );
39 auto & enumMap =
enumProfiles_[std::type_index(
typeid( ProfileEnum ) )];
40 for (
const auto & [value, name] : values )
42 const std::string fullName = domain +
"." + std::string( name );
44 enumMap[
static_cast<std::int64_t
>( value )] = handle;
51 template <
typename ProfileEnum >
54 static_assert( std::is_enum_v<ProfileEnum>,
"Collision profiles must be enum values" );
56 const auto domainIt =
enumProfiles_.find( std::type_index(
typeid( ProfileEnum ) ) );
62 const auto valueIt = domainIt->second.find(
static_cast<std::int64_t
>( value ) );
130 [[nodiscard]] std::vector<CollisionProfileHandle>
getProfiles()
const;
142 std::unordered_map<std::uint32_t, CollisionResponse>
responses;
153 std::unordered_map<std::type_index, std::unordered_map<std::int64_t, CollisionProfileHandle>>
enumProfiles_;
Registers collision profile names, enum mappings, and pair responses.
std::unordered_map< std::type_index, std::unordered_map< std::int64_t, CollisionProfileHandle > > enumProfiles_
CollisionResponse getResponse(CollisionProfileHandle profileA, CollisionProfileHandle profileB) const
Returns the configured response from one profile to another.
void registerEngineProfiles()
Registers the engine's built-in collision profiles and default responses.
std::vector< CollisionProfileHandle > getProfiles() const
Returns all valid registered collision profile handles.
CollisionResponse getResolvedResponse(CollisionProfileHandle profileA, CollisionProfileHandle profileB) const
Resolves the effective symmetric response for a profile pair.
ProfileData * findData(CollisionProfileHandle profile)
std::unordered_map< std::string, CollisionProfileHandle > profilesByName_
std::vector< ProfileData > profiles_
CollisionProfileHandle getFallbackProfile() const
Returns the fallback profile used when no valid profile is configured.
const std::string & getProfileName(CollisionProfileHandle profile) const
Returns the full registered name for a profile handle.
void registerProfileEnum(std::string domain, std::initializer_list< std::pair< ProfileEnum, std::string_view > > values)
Registers enum values as collision profiles under a domain prefix.
void setDefaultResponse(CollisionProfileHandle profile, CollisionResponse response)
const ProfileData * findData(CollisionProfileHandle profile) const
bool loadProfileResponses(const std::string &path)
Loads profile default and pair responses from a JSON file.
CollisionProfileHandle registerProfileName(const std::string &fullName)
Registers or returns a named collision profile.
void logMaskOverflowIfNeeded() const
bool profileCanBlockAny(CollisionProfileHandle profile) const
Returns whether the profile blocks at least one other profile.
std::uint16_t getBulletGroup(CollisionProfileHandle profile) const
Returns the Bullet collision group bit for a profile.
void setResponse(CollisionProfileHandle profileA, CollisionProfileHandle profileB, CollisionResponse response)
std::uint16_t getBulletMask(CollisionProfileHandle profile) const
Returns the Bullet collision mask bits for profiles this profile can block.
void warnAboutAsymmetricResponses() const
Logs configured response pairs where only one direction ignores collisions.
CollisionProfileHandle resolve(ProfileEnum value) const
Resolves a registered enum value to its collision profile handle.
CollisionProfileRegistry()
Creates a registry with an invalid profile slot at index zero.
CollisionProfileHandle findProfile(const std::string &fullName) const
Finds a profile by full name.
CollisionResponse
Collision response selected for a pair of collision profiles.
@ Block
Physical collision response and contact callback.
void setActiveCollisionProfileRegistry(CollisionProfileRegistry *registry)
Sets the process-wide collision profile registry used by physics helpers.
CollisionProfileRegistry * getActiveCollisionProfileRegistry()
Returns the process-wide active collision profile registry.
Registry handle for a collision profile name.
CollisionResponse defaultResponse
std::unordered_map< std::uint32_t, CollisionResponse > responses