From 40cd8a798778c2bb14cd5606ea0319f514973bf5 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 19 Jan 2019 02:29:27 +0100 Subject: [PATCH] Physics2D/RigidBody2D: Add ForEachArbiter method --- ChangeLog.md | 1 + .../NDK/Components/PhysicsComponent2D.hpp | 2 ++ .../NDK/Components/PhysicsComponent2D.inl | 9 +++++++++ include/Nazara/Physics2D/RigidBody2D.hpp | 2 ++ src/Nazara/Physics2D/RigidBody2D.cpp | 16 ++++++++++++++++ 5 files changed, 30 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 7ca8835ef..7ad72fb66 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -158,6 +158,7 @@ Nazara Engine: - Added LuaState::RawEqual - Fixed LuaCoroutine movement assignation operator - Added Arbiter2D::GetBodies +- Added RigidBody2D::ForEachArbiter Nazara Development Kit: - Added ImageWidget (#139) diff --git a/SDK/include/NDK/Components/PhysicsComponent2D.hpp b/SDK/include/NDK/Components/PhysicsComponent2D.hpp index 696a8f99d..38a8c0608 100644 --- a/SDK/include/NDK/Components/PhysicsComponent2D.hpp +++ b/SDK/include/NDK/Components/PhysicsComponent2D.hpp @@ -38,6 +38,8 @@ namespace Ndk inline void EnableNodeSynchronization(bool nodeSynchronization); + inline void ForEachArbiter(const std::function& callback); + inline Nz::Rectf GetAABB() const; inline float GetAngularDamping() const; inline Nz::RadianAnglef GetAngularVelocity() const; diff --git a/SDK/include/NDK/Components/PhysicsComponent2D.inl b/SDK/include/NDK/Components/PhysicsComponent2D.inl index dd90b5f9a..74de89e65 100644 --- a/SDK/include/NDK/Components/PhysicsComponent2D.inl +++ b/SDK/include/NDK/Components/PhysicsComponent2D.inl @@ -138,6 +138,15 @@ namespace Ndk m_entity->Invalidate(); } + /*! + TODO + */ + inline void PhysicsComponent2D::ForEachArbiter(const std::function& callback) + { + NazaraAssert(m_object, "Invalid physics object"); + + return m_object->ForEachArbiter(callback); + } /*! * \brief Gets the AABB of the physics object * \return AABB of the object diff --git a/include/Nazara/Physics2D/RigidBody2D.hpp b/include/Nazara/Physics2D/RigidBody2D.hpp index 39dbb0b83..da5646fb0 100644 --- a/include/Nazara/Physics2D/RigidBody2D.hpp +++ b/include/Nazara/Physics2D/RigidBody2D.hpp @@ -41,6 +41,8 @@ namespace Nz void EnableSimulation(bool simulation); + void ForEachArbiter(std::function callback); + Rectf GetAABB() const; inline float GetAngularDamping() const; RadianAnglef GetAngularVelocity() const; diff --git a/src/Nazara/Physics2D/RigidBody2D.cpp b/src/Nazara/Physics2D/RigidBody2D.cpp index cbeb23cd1..1f4ca07a4 100644 --- a/src/Nazara/Physics2D/RigidBody2D.cpp +++ b/src/Nazara/Physics2D/RigidBody2D.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -175,6 +176,21 @@ namespace Nz } } + void RigidBody2D::ForEachArbiter(std::function callback) + { + using CallbackType = decltype(callback); + + auto RealCallback = [](cpBody* body, cpArbiter* arbiter, void* data) + { + CallbackType& cb = *static_cast(data); + + Arbiter2D nzArbiter(arbiter); + cb(nzArbiter); + }; + + cpBodyEachArbiter(m_handle, RealCallback, &callback); + } + Rectf RigidBody2D::GetAABB() const { if (m_shapes.empty())