Merge remote-tracking branch 'refs/remotes/origin/master' into reflection-mapping
This commit is contained in:
@@ -69,7 +69,7 @@ namespace Nz
|
||||
SlotListIndex index;
|
||||
};
|
||||
|
||||
void Disconnect(const SlotPtr& slot);
|
||||
void Disconnect(const SlotPtr& slot) noexcept;
|
||||
|
||||
SlotList m_slots;
|
||||
mutable SlotListIndex m_slotIterator;
|
||||
@@ -84,17 +84,17 @@ namespace Nz
|
||||
public:
|
||||
Connection() = default;
|
||||
Connection(const Connection& connection) = default;
|
||||
Connection(Connection&& connection) = default;
|
||||
Connection(Connection&& connection) noexcept;
|
||||
~Connection() = default;
|
||||
|
||||
template<typename... ConnectArgs>
|
||||
void Connect(BaseClass& signal, ConnectArgs&&... args);
|
||||
void Disconnect();
|
||||
void Disconnect() noexcept;
|
||||
|
||||
bool IsConnected() const;
|
||||
|
||||
Connection& operator=(const Connection& connection) = default;
|
||||
Connection& operator=(Connection&& connection) = default;
|
||||
Connection& operator=(Connection&& connection) noexcept;
|
||||
|
||||
private:
|
||||
Connection(const SlotPtr& slot);
|
||||
@@ -113,12 +113,12 @@ namespace Nz
|
||||
ConnectionGuard(const Connection& connection);
|
||||
ConnectionGuard(const ConnectionGuard& connection) = delete;
|
||||
ConnectionGuard(Connection&& connection);
|
||||
ConnectionGuard(ConnectionGuard&& connection) = default;
|
||||
ConnectionGuard(ConnectionGuard&& connection) noexcept = default;
|
||||
~ConnectionGuard();
|
||||
|
||||
template<typename... ConnectArgs>
|
||||
void Connect(BaseClass& signal, ConnectArgs&&... args);
|
||||
void Disconnect();
|
||||
void Disconnect() noexcept;
|
||||
|
||||
Connection& GetConnection();
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace Nz
|
||||
ConnectionGuard& operator=(const Connection& connection);
|
||||
ConnectionGuard& operator=(const ConnectionGuard& connection) = delete;
|
||||
ConnectionGuard& operator=(Connection&& connection);
|
||||
ConnectionGuard& operator=(ConnectionGuard&& connection);
|
||||
ConnectionGuard& operator=(ConnectionGuard&& connection) noexcept;
|
||||
|
||||
private:
|
||||
Connection m_connection;
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
void Signal<Args...>::Disconnect(const SlotPtr& slot)
|
||||
void Signal<Args...>::Disconnect(const SlotPtr& slot) noexcept
|
||||
{
|
||||
NazaraAssert(slot, "Invalid slot pointer");
|
||||
NazaraAssert(slot->index < m_slots.size(), "Invalid slot index");
|
||||
@@ -246,6 +246,18 @@ namespace Nz
|
||||
* \brief Core class that represents a connection attached to a signal
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Signal::Connection object with by move semantic
|
||||
*
|
||||
* \param connection Connection object to move
|
||||
*/
|
||||
template<typename... Args>
|
||||
Signal<Args...>::Connection::Connection(Connection&& connection) noexcept :
|
||||
m_ptr(std::move(connection.m_ptr))
|
||||
{
|
||||
connection.m_ptr.reset(); //< Fuck you GCC 4.9
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Signal::Connection object with a slot
|
||||
*
|
||||
@@ -277,7 +289,7 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
void Signal<Args...>::Connection::Disconnect()
|
||||
void Signal<Args...>::Connection::Disconnect() noexcept
|
||||
{
|
||||
if (SlotPtr ptr = m_ptr.lock())
|
||||
ptr->signal->Disconnect(ptr);
|
||||
@@ -294,6 +306,20 @@ namespace Nz
|
||||
return !m_ptr.expired();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Signal::ConnectionGuard object by move semantic
|
||||
*
|
||||
* \param connection Connection to move
|
||||
*/
|
||||
template<typename... Args>
|
||||
typename Signal<Args...>::Connection& Signal<Args...>::Connection::operator=(Connection&& connection) noexcept
|
||||
{
|
||||
m_ptr = std::move(connection.m_ptr);
|
||||
connection.m_ptr.reset(); //< Fuck you GCC 4.9
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \class Nz::Signal::ConnectionGuard
|
||||
* \brief Core class that represents a RAII for a connection attached to a signal
|
||||
@@ -353,7 +379,7 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
void Signal<Args...>::ConnectionGuard::Disconnect()
|
||||
void Signal<Args...>::ConnectionGuard::Disconnect() noexcept
|
||||
{
|
||||
m_connection.Disconnect();
|
||||
}
|
||||
@@ -406,8 +432,11 @@ namespace Nz
|
||||
template<typename... Args>
|
||||
typename Signal<Args...>::ConnectionGuard& Signal<Args...>::ConnectionGuard::operator=(Connection&& connection)
|
||||
{
|
||||
m_connection.Disconnect();
|
||||
m_connection = std::move(connection);
|
||||
if (&connection != this)
|
||||
{
|
||||
m_connection.Disconnect();
|
||||
m_connection = std::move(connection);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -420,10 +449,13 @@ namespace Nz
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
typename Signal<Args...>::ConnectionGuard& Signal<Args...>::ConnectionGuard::operator=(ConnectionGuard&& connection)
|
||||
typename Signal<Args...>::ConnectionGuard& Signal<Args...>::ConnectionGuard::operator=(ConnectionGuard&& connection) noexcept
|
||||
{
|
||||
m_connection.Disconnect();
|
||||
m_connection = std::move(connection.m_connection);
|
||||
if (&connection != this)
|
||||
{
|
||||
m_connection.Disconnect();
|
||||
m_connection = std::move(connection.m_connection);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -42,13 +42,19 @@ namespace Nz
|
||||
|
||||
virtual float ComputeInertialMatrix(float mass) const = 0;
|
||||
|
||||
inline Nz::UInt32 GetCategoryMask() const;
|
||||
inline Nz::UInt32 GetCollisionGroup() const;
|
||||
inline unsigned int GetCollisionId() const;
|
||||
inline Nz::UInt32 GetCollisionMask() const;
|
||||
|
||||
virtual ColliderType2D GetType() const = 0;
|
||||
|
||||
inline bool IsTrigger() const;
|
||||
|
||||
inline void SetCollisionId(unsigned long typeId);
|
||||
inline void SetCategoryMask(Nz::UInt32 categoryMask);
|
||||
inline void SetCollisionGroup(Nz::UInt32 groupId);
|
||||
inline void SetCollisionId(unsigned int typeId);
|
||||
inline void SetCollisionMask(Nz::UInt32 mask);
|
||||
inline void SetTrigger(bool trigger);
|
||||
|
||||
Collider2D& operator=(const Collider2D&) = delete;
|
||||
@@ -61,7 +67,10 @@ namespace Nz
|
||||
virtual std::vector<cpShape*> CreateShapes(RigidBody2D* body) const = 0;
|
||||
|
||||
bool m_trigger;
|
||||
Nz::UInt32 m_categoryMask;
|
||||
Nz::UInt32 m_collisionGroup;
|
||||
unsigned int m_collisionId;
|
||||
Nz::UInt32 m_collisionMask;
|
||||
|
||||
private:
|
||||
virtual std::vector<cpShape*> GenerateShapes(RigidBody2D* body) const;
|
||||
|
||||
@@ -2,32 +2,66 @@
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Collider2D::Collider2D() :
|
||||
m_trigger(false),
|
||||
m_categoryMask(0xFFFFFFFF),
|
||||
m_collisionGroup(0),
|
||||
m_collisionId(0),
|
||||
m_trigger(false)
|
||||
m_collisionMask(0xFFFFFFFF)
|
||||
{
|
||||
}
|
||||
|
||||
inline Nz::UInt32 Collider2D::GetCategoryMask() const
|
||||
{
|
||||
return m_categoryMask;
|
||||
}
|
||||
|
||||
inline Nz::UInt32 Collider2D::GetCollisionGroup() const
|
||||
{
|
||||
return m_collisionGroup;
|
||||
}
|
||||
|
||||
inline unsigned int Collider2D::GetCollisionId() const
|
||||
{
|
||||
return m_collisionId;
|
||||
}
|
||||
|
||||
inline Nz::UInt32 Collider2D::GetCollisionMask() const
|
||||
{
|
||||
return m_collisionMask;
|
||||
}
|
||||
|
||||
inline bool Collider2D::IsTrigger() const
|
||||
{
|
||||
return m_trigger;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionId(unsigned long typeId)
|
||||
inline void Collider2D::SetCategoryMask(Nz::UInt32 categoryMask)
|
||||
{
|
||||
m_categoryMask = categoryMask;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionGroup(Nz::UInt32 groupId)
|
||||
{
|
||||
m_collisionGroup = groupId;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionId(unsigned int typeId)
|
||||
{
|
||||
m_collisionId = typeId;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetCollisionMask(Nz::UInt32 mask)
|
||||
{
|
||||
m_collisionMask = mask;
|
||||
}
|
||||
|
||||
inline void Collider2D::SetTrigger(bool trigger)
|
||||
{
|
||||
m_trigger = trigger;
|
||||
@@ -108,4 +142,3 @@ namespace Nz
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
#include "Collider2D.hpp"
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
#define NAZARA_PHYSWORLD2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -18,10 +20,10 @@ struct cpSpace;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class RigidBody2D;
|
||||
|
||||
class NAZARA_PHYSICS2D_API PhysWorld2D
|
||||
{
|
||||
friend RigidBody2D;
|
||||
|
||||
using ContactEndCallback = void(*)(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata);
|
||||
using ContactPreSolveCallback = bool(*)(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata);
|
||||
using ContactPostSolveCallback = void(*)(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata);
|
||||
@@ -29,6 +31,8 @@ namespace Nz
|
||||
|
||||
public:
|
||||
struct Callback;
|
||||
struct NearestQueryResult;
|
||||
struct RaycastHit;
|
||||
|
||||
PhysWorld2D();
|
||||
PhysWorld2D(const PhysWorld2D&) = delete;
|
||||
@@ -39,6 +43,12 @@ namespace Nz
|
||||
cpSpace* GetHandle() const;
|
||||
float GetStepSize() const;
|
||||
|
||||
bool NearestBodyQuery(const Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RigidBody2D** nearestBody = nullptr);
|
||||
bool NearestBodyQuery(const Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, NearestQueryResult* result);
|
||||
|
||||
bool RaycastQuery(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<RaycastHit>* hitInfos);
|
||||
bool RaycastQueryFirst(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RaycastHit* hitInfo = nullptr);
|
||||
|
||||
void RegisterCallbacks(unsigned int collisionId, const Callback& callbacks);
|
||||
void RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, const Callback& callbacks);
|
||||
|
||||
@@ -59,10 +69,47 @@ namespace Nz
|
||||
void* userdata;
|
||||
};
|
||||
|
||||
struct NearestQueryResult
|
||||
{
|
||||
Nz::RigidBody2D* nearestBody;
|
||||
Nz::Vector2f closestPoint;
|
||||
Nz::Vector2f fraction;
|
||||
float distance;
|
||||
};
|
||||
|
||||
struct RaycastHit
|
||||
{
|
||||
Nz::RigidBody2D* nearestBody;
|
||||
Nz::Vector2f hitPos;
|
||||
Nz::Vector2f hitNormal;
|
||||
float fraction;
|
||||
};
|
||||
|
||||
NazaraSignal(OnPhysWorld2DPreStep, const PhysWorld2D* /*physWorld*/);
|
||||
NazaraSignal(OnPhysWorld2DPostStep, const PhysWorld2D* /*physWorld*/);
|
||||
|
||||
private:
|
||||
void InitCallbacks(cpCollisionHandler* handler, const Callback& callbacks);
|
||||
|
||||
using PostStep = std::function<void(Nz::RigidBody2D* body)>;
|
||||
|
||||
void OnRigidBodyMoved(RigidBody2D* oldPointer, RigidBody2D* newPointer);
|
||||
void OnRigidBodyRelease(RigidBody2D* rigidBody);
|
||||
|
||||
void RegisterPostStep(RigidBody2D* rigidBody, PostStep&& func);
|
||||
|
||||
struct PostStepContainer
|
||||
{
|
||||
NazaraSlot(RigidBody2D, OnRigidBody2DMove, onMovedSlot);
|
||||
NazaraSlot(RigidBody2D, OnRigidBody2DRelease, onReleaseSlot);
|
||||
|
||||
std::vector<PostStep> funcs;
|
||||
};
|
||||
|
||||
static_assert(std::is_nothrow_move_constructible<PostStepContainer>::value, "PostStepContainer should be noexcept MoveConstructible");
|
||||
|
||||
std::unordered_map<cpCollisionHandler*, std::unique_ptr<Callback>> m_callbacks;
|
||||
std::unordered_map<RigidBody2D*, PostStepContainer> m_rigidPostSteps;
|
||||
cpSpace* m_handle;
|
||||
float m_stepSize;
|
||||
float m_timestepAccumulator;
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace Nz
|
||||
|
||||
void AddForce(const Vector2f& force, CoordSys coordSys = CoordSys_Global);
|
||||
void AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys = CoordSys_Global);
|
||||
void AddImpulse(const Vector2f& impulse, CoordSys coordSys = CoordSys_Global);
|
||||
void AddImpulse(const Vector2f& impulse, const Vector2f& point, CoordSys coordSys = CoordSys_Global);
|
||||
void AddTorque(float torque);
|
||||
|
||||
Rectf GetAABB() const;
|
||||
|
||||
Reference in New Issue
Block a user