#include "CTangibleWorld.hpp" #include "Jolt/Core/Memory.h" #include "Jolt/RegisterTypes.h" #include #include "../Scene/CScene.hpp" #include "../Component/Rigidbody/CRigidBody.hpp" namespace CosmicCore { CTangibleWorld::~CTangibleWorld() { } void CTangibleWorld::initWorld() { JPH::RegisterDefaultAllocator(); JPH::Factory::sInstance = new JPH::Factory(); JPH::RegisterTypes(); m_tempAllocator = std::make_unique(10 * 1024 * 1024); m_jobSystem = std::make_unique(JPH::cMaxPhysicsJobs, JPH::cMaxPhysicsBarriers, JPH::thread::hardware_concurrency() - 1); m_physicsSystem.Init(cMaxBodies, cNumBodyMutexes, cMaxBodyPairs, cMaxContactConstraints, m_broadPhaseLayer, m_objectVsBroadPhase, m_objectLayerPairFilter); } void CTangibleWorld::updateWorld(float deltaTime){ m_physicsSystem.Update(deltaTime, 1, m_tempAllocator.get(), m_jobSystem.get()); auto& registry = getScene()->getECManager(); // accès via scene auto view = registry.registry.view(); for (auto entity : view) { auto& rb = registry.registry.get(entity); // ne sync que les bodies dynamiques et kinématiques if (rb.getBodyType() == EBodyType::Static) continue; registry.registry.get(entity).syncTransform(); } } void CTangibleWorld::destroy(){ getScene()->getECManager().registry.view().each([](CRigidBody& rb) { rb.destroy(); }); JPH::UnregisterTypes(); // Destroy the factory delete JPH::Factory::sInstance; JPH::Factory::sInstance = nullptr; } }