// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - BulletPhysics3D module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_BULLETPHYSICS3D_SYSTEMS_BULLETPHYSICS3DSYSTEM_HPP #define NAZARA_BULLETPHYSICS3D_SYSTEMS_BULLETPHYSICS3DSYSTEM_HPP #include #include #include #include #include #include #include #include namespace Nz { class NAZARA_BULLETPHYSICS3D_API BulletPhysics3DSystem { public: static constexpr Int64 ExecutionOrder = 0; using Components = TypeList; struct RaycastHit; BulletPhysics3DSystem(entt::registry& registry); BulletPhysics3DSystem(const BulletPhysics3DSystem&) = delete; BulletPhysics3DSystem(BulletPhysics3DSystem&&) = delete; ~BulletPhysics3DSystem(); template BulletRigidBody3DComponent CreateRigidBody(Args&&... args); void Dump(); inline BulletPhysWorld3D& GetPhysWorld(); inline const BulletPhysWorld3D& GetPhysWorld() const; bool RaycastQuery(const Vector3f& from, const Vector3f& to, const FunctionRef(const RaycastHit& hitInfo)>& callback); bool RaycastQueryFirst(const Vector3f& from, const Vector3f& to, RaycastHit* hitInfo = nullptr); void Update(Time elapsedTime); BulletPhysics3DSystem& operator=(const BulletPhysics3DSystem&) = delete; BulletPhysics3DSystem& operator=(BulletPhysics3DSystem&&) = delete; struct RaycastHit : BulletPhysWorld3D::RaycastHit { entt::handle hitEntity; }; private: void OnConstruct(entt::registry& registry, entt::entity entity); void OnDestruct(entt::registry& registry, entt::entity entity); std::size_t m_activeObjectCount; std::size_t m_stepCount; std::vector m_physicsEntities; entt::registry& m_registry; entt::observer m_physicsConstructObserver; entt::scoped_connection m_constructConnection; entt::scoped_connection m_destructConnection; BulletPhysWorld3D m_physWorld; Time m_physicsTime; Time m_updateTime; }; } #include #endif // NAZARA_BULLETPHYSICS3D_SYSTEMS_BULLETPHYSICS3DSYSTEM_HPP