little fixes (#183)

* Update

* Add: [Get/Set]AngularDaming for standardization

* Fix: Name error

* Add: [Get/Set][AngularDamping/MomentOfInertia] in PhysicsComponent2D

* Forgot in last commit

* Add: param coordSys in [PhysicsComponent2D/RigidBody2D]::SetMassCenter

* Add: Some forgotten inline

* Fix little error

* Fix: Indentation before case

* Move and Change GetCenterOfGravity

* Rename m_world into m_physWorld

* Rename GetWorld int GetPhysWorld

* Update: PhysicsSystem2D became an interface of PhysWorld2D

* Update Collison/PhysicsComponent because GetWorld was renamed

* Update tests

* Update: Make the interface usable with Entity instead of PhysicsComponent

* Update: Make GetPhysWorld private

* Update PhysicsSystem2D.hpp

* Update: indent

* Remove: useless blank line

* update order(?)

* Update PhysicsSystem2D.hpp

* Add calls to GetPhysWorld to attempt a nullptr value

* update include

* little fix

* add some missing inline
This commit is contained in:
Faymoon 2018-08-14 18:44:41 +02:00 committed by Jérôme Leclercq
parent 9ecfe31637
commit beca6e7dd5
5 changed files with 55 additions and 77 deletions

View File

@ -23,49 +23,49 @@ namespace Ndk
PhysicsComponent3D(const PhysicsComponent3D& physics); PhysicsComponent3D(const PhysicsComponent3D& physics);
~PhysicsComponent3D() = default; ~PhysicsComponent3D() = default;
void AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global); inline void AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global); inline void AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys = Nz::CoordSys_Global); inline void AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void EnableAutoSleep(bool autoSleep); inline void EnableAutoSleep(bool autoSleep);
void EnableNodeSynchronization(bool nodeSynchronization); inline void EnableNodeSynchronization(bool nodeSynchronization);
Nz::Boxf GetAABB() const; inline Nz::Boxf GetAABB() const;
Nz::Vector3f GetAngularDamping() const; inline Nz::Vector3f GetAngularDamping() const;
Nz::Vector3f GetAngularVelocity() const; inline Nz::Vector3f GetAngularVelocity() const;
float GetGravityFactor() const; inline float GetGravityFactor() const;
float GetLinearDamping() const; inline float GetLinearDamping() const;
Nz::Vector3f GetLinearVelocity() const; inline Nz::Vector3f GetLinearVelocity() const;
float GetMass() const; inline float GetMass() const;
Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const; inline Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
const Nz::Matrix4f& GetMatrix() const; inline const Nz::Matrix4f& GetMatrix() const;
Nz::Vector3f GetPosition() const; inline Nz::Vector3f GetPosition() const;
Nz::Quaternionf GetRotation() const; inline Nz::Quaternionf GetRotation() const;
bool IsAutoSleepEnabled() const; inline bool IsAutoSleepEnabled() const;
bool IsMoveable() const; inline bool IsMoveable() const;
bool IsNodeSynchronizationEnabled() const; inline bool IsNodeSynchronizationEnabled() const;
bool IsSleeping() const; inline bool IsSleeping() const;
void SetAngularDamping(const Nz::Vector3f& angularDamping); inline void SetAngularDamping(const Nz::Vector3f& angularDamping);
void SetAngularVelocity(const Nz::Vector3f& angularVelocity); inline void SetAngularVelocity(const Nz::Vector3f& angularVelocity);
void SetGravityFactor(float gravityFactor); inline void SetGravityFactor(float gravityFactor);
void SetLinearDamping(float damping); inline void SetLinearDamping(float damping);
void SetLinearVelocity(const Nz::Vector3f& velocity); inline void SetLinearVelocity(const Nz::Vector3f& velocity);
void SetMass(float mass); inline void SetMass(float mass);
void SetMassCenter(const Nz::Vector3f& center); inline void SetMassCenter(const Nz::Vector3f& center);
void SetMaterial(const Nz::String& materialName); inline void SetMaterial(const Nz::String& materialName);
void SetMaterial(int materialIndex); inline void SetMaterial(int materialIndex);
void SetPosition(const Nz::Vector3f& position); inline void SetPosition(const Nz::Vector3f& position);
void SetRotation(const Nz::Quaternionf& rotation); inline void SetRotation(const Nz::Quaternionf& rotation);
static ComponentIndex componentIndex; static ComponentIndex componentIndex;
private: private:
void ApplyPhysicsState(Nz::RigidBody3D& rigidBody) const; inline void ApplyPhysicsState(Nz::RigidBody3D& rigidBody) const;
void CopyPhysicsState(const Nz::RigidBody3D& rigidBody); inline void CopyPhysicsState(const Nz::RigidBody3D& rigidBody);
Nz::RigidBody3D* GetRigidBody(); inline Nz::RigidBody3D* GetRigidBody();
const Nz::RigidBody3D& GetRigidBody() const; inline const Nz::RigidBody3D& GetRigidBody() const;
void OnAttached() override; void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override; void OnComponentAttached(BaseComponent& component) override;

View File

@ -114,8 +114,8 @@ namespace Ndk
private: private:
void CreatePhysWorld() const; void CreatePhysWorld() const;
const EntityHandle& GetEntityFromBody(const Nz::RigidBody2D& body) const; const EntityHandle& GetEntityFromBody(const Nz::RigidBody2D& body) const;
Nz::PhysWorld2D& GetPhysWorld(); inline Nz::PhysWorld2D& GetPhysWorld();
const Nz::PhysWorld2D& GetPhysWorld() const; inline const Nz::PhysWorld2D& GetPhysWorld() const;
void OnEntityValidation(Entity* entity, bool justAdded) override; void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override; void OnUpdate(float elapsedTime) override;

View File

@ -6,79 +6,57 @@ namespace Ndk
{ {
inline float PhysicsSystem2D::GetDamping() const inline float PhysicsSystem2D::GetDamping() const
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); return GetPhysWorld().GetDamping();
return m_physWorld->GetDamping();
} }
inline Nz::Vector2f PhysicsSystem2D::GetGravity() const inline Nz::Vector2f PhysicsSystem2D::GetGravity() const
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); return GetPhysWorld().GetGravity();
return m_physWorld->GetGravity();
} }
inline std::size_t PhysicsSystem2D::GetIterationCount() const inline std::size_t PhysicsSystem2D::GetIterationCount() const
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); return GetPhysWorld().GetIterationCount();
return m_physWorld->GetIterationCount();
} }
inline std::size_t PhysicsSystem2D::GetMaxStepCount() const inline std::size_t PhysicsSystem2D::GetMaxStepCount() const
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); return GetPhysWorld().GetMaxStepCount();
return m_physWorld->GetMaxStepCount();
} }
inline float PhysicsSystem2D::GetStepSize() const inline float PhysicsSystem2D::GetStepSize() const
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); return GetPhysWorld().GetStepSize();
return m_physWorld->GetStepSize();
} }
inline void PhysicsSystem2D::SetDamping(float dampingValue) inline void PhysicsSystem2D::SetDamping(float dampingValue)
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); GetPhysWorld().SetDamping(dampingValue);
m_physWorld->SetDamping(dampingValue);
} }
inline void PhysicsSystem2D::SetGravity(const Nz::Vector2f& gravity) inline void PhysicsSystem2D::SetGravity(const Nz::Vector2f& gravity)
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); GetPhysWorld().SetGravity(gravity);
m_physWorld->SetGravity(gravity);
} }
inline void PhysicsSystem2D::SetIterationCount(std::size_t iterationCount) inline void PhysicsSystem2D::SetIterationCount(std::size_t iterationCount)
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); GetPhysWorld().SetIterationCount(iterationCount);
m_physWorld->SetIterationCount(iterationCount);
} }
inline void PhysicsSystem2D::SetMaxStepCount(std::size_t maxStepCount) inline void PhysicsSystem2D::SetMaxStepCount(std::size_t maxStepCount)
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); GetPhysWorld().SetMaxStepCount(maxStepCount);
m_physWorld->SetMaxStepCount(maxStepCount);
} }
inline void PhysicsSystem2D::SetStepSize(float stepSize) inline void PhysicsSystem2D::SetStepSize(float stepSize)
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); GetPhysWorld().SetStepSize(stepSize);
m_physWorld->SetStepSize(stepSize);
} }
inline void PhysicsSystem2D::UseSpatialHash(float cellSize, std::size_t entityCount) inline void PhysicsSystem2D::UseSpatialHash(float cellSize, std::size_t entityCount)
{ {
NazaraAssert(m_physWorld, "Invalid physics world"); GetPhysWorld().UseSpatialHash(cellSize, entityCount);
m_physWorld->UseSpatialHash(cellSize, entityCount);
} }
/*! /*!

View File

@ -59,7 +59,7 @@ namespace Ndk
worldOptions.userdata = options.userdata; worldOptions.userdata = options.userdata;
m_physWorld->DebugDraw(worldOptions, drawShapes, drawConstraints, drawCollisions); GetPhysWorld().DebugDraw(worldOptions, drawShapes, drawConstraints, drawCollisions);
} }
const EntityHandle& PhysicsSystem2D::GetEntityFromBody(const Nz::RigidBody2D& body) const const EntityHandle& PhysicsSystem2D::GetEntityFromBody(const Nz::RigidBody2D& body) const
@ -76,7 +76,7 @@ namespace Ndk
bool PhysicsSystem2D::NearestBodyQuery(const Nz::Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, EntityHandle* nearestBody) bool PhysicsSystem2D::NearestBodyQuery(const Nz::Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, EntityHandle* nearestBody)
{ {
Nz::RigidBody2D* body; Nz::RigidBody2D* body;
bool res = m_physWorld->NearestBodyQuery(from, maxDistance, collisionGroup, categoryMask, collisionMask, &body); bool res = GetPhysWorld().NearestBodyQuery(from, maxDistance, collisionGroup, categoryMask, collisionMask, &body);
(*nearestBody) = GetEntityFromBody(*body); (*nearestBody) = GetEntityFromBody(*body);
@ -86,7 +86,7 @@ namespace Ndk
bool PhysicsSystem2D::NearestBodyQuery(const Nz::Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, NearestQueryResult* result) bool PhysicsSystem2D::NearestBodyQuery(const Nz::Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, NearestQueryResult* result)
{ {
Nz::PhysWorld2D::NearestQueryResult queryResult; Nz::PhysWorld2D::NearestQueryResult queryResult;
bool res = m_physWorld->NearestBodyQuery(from, maxDistance, collisionGroup, categoryMask, collisionMask, &queryResult); bool res = GetPhysWorld().NearestBodyQuery(from, maxDistance, collisionGroup, categoryMask, collisionMask, &queryResult);
result->nearestBody = GetEntityFromBody(*queryResult.nearestBody); result->nearestBody = GetEntityFromBody(*queryResult.nearestBody);
result->closestPoint = std::move(queryResult.closestPoint); result->closestPoint = std::move(queryResult.closestPoint);
@ -99,7 +99,7 @@ namespace Ndk
bool PhysicsSystem2D::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 PhysicsSystem2D::RaycastQuery(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<RaycastHit>* hitInfos)
{ {
std::vector<Nz::PhysWorld2D::RaycastHit> queryResult; std::vector<Nz::PhysWorld2D::RaycastHit> queryResult;
bool res = m_physWorld->RaycastQuery(from, to, radius, collisionGroup, categoryMask, collisionMask, &queryResult); bool res = GetPhysWorld().RaycastQuery(from, to, radius, collisionGroup, categoryMask, collisionMask, &queryResult);
for (auto& hitResult : queryResult) for (auto& hitResult : queryResult)
{ {
@ -117,7 +117,7 @@ namespace Ndk
bool PhysicsSystem2D::RaycastQueryFirst(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RaycastHit* hitInfo) bool PhysicsSystem2D::RaycastQueryFirst(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RaycastHit* hitInfo)
{ {
Nz::PhysWorld2D::RaycastHit queryResult; Nz::PhysWorld2D::RaycastHit queryResult;
bool res = m_physWorld->RaycastQueryFirst(from, to, radius, collisionGroup, categoryMask, collisionMask, &queryResult); bool res = GetPhysWorld().RaycastQueryFirst(from, to, radius, collisionGroup, categoryMask, collisionMask, &queryResult);
hitInfo->body = GetEntityFromBody(*queryResult.nearestBody); hitInfo->body = GetEntityFromBody(*queryResult.nearestBody);
hitInfo->hitPos = std::move(queryResult.hitPos); hitInfo->hitPos = std::move(queryResult.hitPos);
@ -130,7 +130,7 @@ namespace Ndk
void PhysicsSystem2D::RegionQuery(const Nz::Rectf& boundingBox, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<EntityHandle>* bodies) void PhysicsSystem2D::RegionQuery(const Nz::Rectf& boundingBox, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<EntityHandle>* bodies)
{ {
std::vector<Nz::RigidBody2D*> queryResult; std::vector<Nz::RigidBody2D*> queryResult;
m_physWorld->RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, &queryResult); GetPhysWorld().RegionQuery(boundingBox, collisionGroup, categoryMask, collisionMask, &queryResult);
for (auto& body : queryResult) for (auto& body : queryResult)
{ {

View File

@ -29,7 +29,7 @@ struct tcp_keepalive
#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4) #define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4)
#endif #endif
#include <Winsock2.h> #include <winsock2.h>
#include <Nazara/Network/Debug.hpp> #include <Nazara/Network/Debug.hpp>