JoltPhysics3D: Allow to construct components without using the system
This commit is contained in:
@@ -17,16 +17,21 @@ namespace Nz
|
||||
friend class JoltPhysics3DSystem;
|
||||
|
||||
public:
|
||||
using JoltCharacter::JoltCharacter;
|
||||
inline JoltCharacterComponent(const JoltCharacter::Settings& settings);
|
||||
JoltCharacterComponent(const JoltCharacterComponent&) = default;
|
||||
JoltCharacterComponent(JoltCharacterComponent&&) noexcept = default;
|
||||
~JoltCharacterComponent() = default;
|
||||
|
||||
JoltCharacterComponent& operator=(const JoltCharacterComponent&) = default;
|
||||
JoltCharacterComponent& operator=(JoltCharacterComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(JoltPhysWorld3D& world);
|
||||
|
||||
std::unique_ptr<JoltCharacter::Settings> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltRigidBody3DComponent.inl>
|
||||
#include <Nazara/JoltPhysics3D/Components/JoltCharacterComponent.inl>
|
||||
|
||||
#endif // NAZARA_JOLTPHYSICS3D_COMPONENTS_JOLTCHARACTERCOMPONENT_HPP
|
||||
|
||||
@@ -6,6 +6,17 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltCharacterComponent::JoltCharacterComponent(const JoltCharacter::Settings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<JoltCharacter::Settings>(settings);
|
||||
}
|
||||
|
||||
inline void JoltCharacterComponent::Construct(JoltPhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
Create(world, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/JoltPhysics3D/JoltRigidBody3D.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -17,13 +18,20 @@ namespace Nz
|
||||
friend class JoltPhysics3DSystem;
|
||||
|
||||
public:
|
||||
using JoltRigidBody3D::JoltRigidBody3D;
|
||||
inline JoltRigidBody3DComponent(const JoltRigidBody3D::DynamicSettings& settings);
|
||||
inline JoltRigidBody3DComponent(const JoltRigidBody3D::StaticSettings& settings);
|
||||
JoltRigidBody3DComponent(const JoltRigidBody3DComponent&) = default;
|
||||
JoltRigidBody3DComponent(JoltRigidBody3DComponent&&) noexcept = default;
|
||||
~JoltRigidBody3DComponent() = default;
|
||||
|
||||
JoltRigidBody3DComponent& operator=(const JoltRigidBody3DComponent&) = default;
|
||||
JoltRigidBody3DComponent& operator=(JoltRigidBody3DComponent&&) noexcept = default;
|
||||
|
||||
private:
|
||||
inline void Construct(JoltPhysWorld3D& world);
|
||||
|
||||
using Setting = std::variant<JoltRigidBody3D::DynamicSettings, JoltRigidBody3D::StaticSettings>;
|
||||
std::unique_ptr<Setting> m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,29 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/JoltPhysics3D/Debug.hpp>
|
||||
#include <cassert>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline JoltRigidBody3DComponent::JoltRigidBody3DComponent(const JoltRigidBody3D::DynamicSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline JoltRigidBody3DComponent::JoltRigidBody3DComponent(const JoltRigidBody3D::StaticSettings& settings)
|
||||
{
|
||||
m_settings = std::make_unique<Setting>(settings);
|
||||
}
|
||||
|
||||
inline void JoltRigidBody3DComponent::Construct(JoltPhysWorld3D& world)
|
||||
{
|
||||
assert(m_settings);
|
||||
std::visit([&](auto&& arg)
|
||||
{
|
||||
Create(world, arg);
|
||||
}, *m_settings);
|
||||
m_settings.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/JoltPhysics3D/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user