Add Physics2D components and systems (WIP)

This commit is contained in:
Jérôme Leclercq
2022-03-16 08:24:57 +01:00
parent 9b1583501b
commit 19f6bdf7e0
12 changed files with 476 additions and 14 deletions

View File

@@ -0,0 +1,34 @@
// this file was automatically generated and should not be edited
/*
Nazara Engine - Physics2D module
Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_PHYSICS2D_COMPONENTS_HPP
#define NAZARA_PHYSICS2D_COMPONENTS_HPP
#include <Nazara/Physics2D/Components/RigidBody2DComponent.hpp>
#endif // NAZARA_PHYSICS2D_COMPONENTS_HPP

View File

@@ -0,0 +1,32 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Physics2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
#define NAZARA_PHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Physics2D/RigidBody2D.hpp>
namespace Nz
{
class NAZARA_PHYSICS2D_API RigidBody2DComponent : public RigidBody2D
{
friend class Physics2DSystem;
public:
using RigidBody2D::RigidBody2D;
RigidBody2DComponent(const RigidBody2DComponent&) = default;
RigidBody2DComponent(RigidBody2DComponent&&) noexcept = default;
~RigidBody2DComponent() = default;
RigidBody2DComponent& operator=(const RigidBody2DComponent&) = default;
RigidBody2DComponent& operator=(RigidBody2DComponent&&) noexcept = default;
};
}
#include <Nazara/Physics2D/Components/RigidBody2DComponent.inl>
#endif // NAZARA_PHYSICS2D_COMPONENTS_RIGIDBODY2DCOMPONENT_HPP

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Physics2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/Components/RigidBody2DComponent.hpp>
#include <Nazara/Physics2D/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Physics2D/DebugOff.hpp>

View File

@@ -110,9 +110,11 @@ namespace Nz
static constexpr std::size_t InvalidShapeIndex = std::numeric_limits<std::size_t>::max();
protected:
void Destroy();
private:
cpBody* Create(float mass = 1.f, float moment = 1.f);
void Destroy();
void RegisterToSpace();
void UnregisterFromSpace();

View File

@@ -0,0 +1,34 @@
// this file was automatically generated and should not be edited
/*
Nazara Engine - Physics2D module
Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_PHYSICS2D_SYSTEMS_HPP
#define NAZARA_PHYSICS2D_SYSTEMS_HPP
#include <Nazara/Physics2D/Systems/Physics2DSystem.hpp>
#endif // NAZARA_PHYSICS2D_SYSTEMS_HPP

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Physics2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
#define NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <Nazara/Physics2D/Components/RigidBody2DComponent.hpp>
#include <entt/entt.hpp>
namespace Nz
{
class NAZARA_PHYSICS2D_API Physics2DSystem
{
public:
Physics2DSystem(entt::registry& registry);
Physics2DSystem(const Physics2DSystem&) = delete;
Physics2DSystem(Physics2DSystem&&) = delete;
~Physics2DSystem();
template<typename... Args> RigidBody2DComponent CreateRigidBody(Args&&... args);
inline PhysWorld2D& GetPhysWorld();
inline const PhysWorld2D& GetPhysWorld() const;
void Update(entt::registry& registry, float elapsedTime);
Physics2DSystem& operator=(const Physics2DSystem&) = delete;
Physics2DSystem& operator=(Physics2DSystem&&) = delete;
private:
static void OnConstruct(entt::registry& registry, entt::entity entity);
entt::registry& m_registry;
entt::connection m_constructConnection;
PhysWorld2D m_physWorld;
};
}
#include <Nazara/Physics2D/Systems/Physics2DSystem.inl>
#endif // NAZARA_PHYSICS2D_SYSTEMS_PHYSICS2DSYSTEM_HPP

View File

@@ -0,0 +1,27 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Physics2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/Systems/Physics2DSystem.hpp>
#include <Nazara/Physics2D/Debug.hpp>
namespace Nz
{
template<typename... Args>
RigidBody2DComponent Physics2DSystem::CreateRigidBody(Args&&... args)
{
return RigidBody2DComponent(&m_physWorld, std::forward<Args>(args)...);
}
inline PhysWorld2D& Physics2DSystem::GetPhysWorld()
{
return m_physWorld;
}
inline const PhysWorld2D& Physics2DSystem::GetPhysWorld() const
{
return m_physWorld;
}
}
#include <Nazara/Physics2D/DebugOff.hpp>