Merge branch 'master' into vulkan

This commit is contained in:
Lynix
2018-01-16 21:15:58 +01:00
375 changed files with 133309 additions and 549 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -11,13 +11,15 @@
#include <malloc.h>
// with MSVC, using alloca with a size of zero returns a valid pointer
#define NAZARA_ALLOCA(size) _alloca(size)
#define NAZARA_ALLOCA_SUPPORT
#elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
#include <alloca.h>
#define NAZARA_ALLOCA(size) alloca(size)
// with Clang/GCC, using alloca with a size of zero does nothing good
#define NAZARA_ALLOCA(size) alloca(((size) > 0) ? (size) : 1)
#define NAZARA_ALLOCA_SUPPORT
#endif

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -70,11 +70,14 @@ namespace Nz
* \brief Calls the object destructor explicitly
*
* \param ptr Pointer to a previously constructed pointer on raw memory
*
* \remark This does not deallocate memory, and is a no-op on a null pointer
*/
template<typename T>
void PlacementDestroy(T* ptr)
{
ptr->~T();
if (ptr)
ptr->~T();
}
/*!

View File

@@ -63,7 +63,7 @@ namespace Nz
template<typename T>
SparsePtr<T>::SparsePtr(VoidPtr ptr, std::size_t stride)
{
assert(stride <= std::numeric_limits<int>::max());
assert(stride <= static_cast<unsigned int>(std::numeric_limits<int>::max()));
Reset(ptr, static_cast<int>(stride));
}

View File

@@ -168,6 +168,7 @@ namespace Nz
bool ToDouble(double* value) const;
bool ToInteger(long long* value, UInt8 radix = 10) const;
String ToLower(UInt32 flags = None) const;
std::string ToStdString() const;
String ToUpper(UInt32 flags = None) const;
String& Trim(UInt32 flags = None);
@@ -193,8 +194,6 @@ namespace Nz
typedef char value_type;
// Méthodes STD
operator std::string() const;
char& operator[](std::size_t pos);
char operator[](std::size_t pos) const;

View File

@@ -64,7 +64,7 @@ namespace Nz
NAZARA_CORE_API friend std::ostream& operator<<(std::ostream& o, const Id& id);
private:
Id(ThreadImpl* thread);
explicit Id(ThreadImpl* thread);
ThreadImpl* m_id = nullptr;
};

View File

@@ -214,6 +214,8 @@ namespace Nz
template<typename T>
void CullingList<T>::NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr)
{
NazaraUnused(oldPtr);
switch (type)
{
case CullTest::NoTest:

View File

@@ -69,15 +69,15 @@ namespace Nz
template<typename U, bool HasDestructor>
friend struct LuaClassImplFinalizerSetupProxy;
void PushClassInfo(LuaState& state);
void SetupConstructor(LuaState& state);
void SetupDefaultToString(LuaState& state);
void SetupFinalizer(LuaState& state);
void SetupGetter(LuaState& state, LuaCFunction proxy);
void SetupGlobalTable(LuaState& state);
void SetupMetatable(LuaState& state);
void SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex);
void SetupSetter(LuaState& state, LuaCFunction proxy);
int PushClassInfo(LuaState& state);
void SetupConstructor(LuaState& state, int classInfoRef);
void SetupDefaultToString(LuaState& state, int classInfoRef);
void SetupFinalizer(LuaState& state, int classInfoRef);
void SetupGetter(LuaState& state, LuaCFunction proxy, int classInfoRef);
void SetupGlobalTable(LuaState& state, int classInfoRef);
void SetupMetatable(LuaState& state, int classInfoRef);
void SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex, int classInfoRef);
void SetupSetter(LuaState& state, LuaCFunction proxy, int classInfoRef);
using ParentFunc = std::function<void(LuaState& state, T* instance)>;
using InstanceGetter = std::function<T*(LuaState& state)>;

View File

@@ -80,15 +80,15 @@ namespace Nz
template<class T>
void LuaClass<T>::Register(LuaState& state)
{
PushClassInfo(state);
int classInfoRef = PushClassInfo(state);
// Let's create the metatable which will be associated with every state.
SetupMetatable(state);
SetupMetatable(state, classInfoRef);
if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_staticMethods.empty())
SetupGlobalTable(state);
SetupGlobalTable(state, classInfoRef);
state.Pop(); // Pop our ClassInfo, which is now referenced by all our functions
state.DestroyReference(classInfoRef);
}
template<class T>
@@ -216,7 +216,7 @@ namespace Nz
}
template<class T>
void LuaClass<T>::PushClassInfo(LuaState& state)
int LuaClass<T>::PushClassInfo(LuaState& state)
{
// Our ClassInfo has to outlive the LuaClass, because we don't want to force the user to keep the LuaClass alive
// To do that, each Registration creates a tiny shared_ptr wrapper whose life is directly managed by Lua.
@@ -231,20 +231,22 @@ namespace Nz
state.PushCFunction(InfoDestructor, 1);
state.SetField("__gc");
state.SetMetatable(-2);
return state.CreateReference();
}
template<class T>
void LuaClass<T>::SetupConstructor(LuaState& state)
void LuaClass<T>::SetupConstructor(LuaState& state, int classInfoRef)
{
state.PushValue(1); // ClassInfo
state.PushReference(classInfoRef);
state.PushCFunction(ConstructorProxy, 1);
state.SetField("__call"); // ClassMeta.__call = ConstructorProxy
}
template<class T>
void LuaClass<T>::SetupDefaultToString(LuaState& state)
void LuaClass<T>::SetupDefaultToString(LuaState& state, int classInfoRef)
{
state.PushValue(1); // shared_ptr on UserData
state.PushReference(classInfoRef);
state.PushCFunction(ToStringProxy, 1);
state.SetField("__tostring");
}
@@ -255,9 +257,9 @@ namespace Nz
template<typename T>
struct LuaClassImplFinalizerSetupProxy<T, true>
{
static void Setup(LuaState& state)
static void Setup(LuaState& state, int classInfoRef)
{
state.PushValue(1); // ClassInfo
state.PushReference(classInfoRef);
state.PushCFunction(LuaClass<T>::FinalizerProxy, 1);
state.SetField("__gc");
}
@@ -266,21 +268,21 @@ namespace Nz
template<typename T>
struct LuaClassImplFinalizerSetupProxy<T, false>
{
static void Setup(LuaState&)
static void Setup(LuaState&, int)
{
}
};
template<class T>
void LuaClass<T>::SetupFinalizer(LuaState& state)
void LuaClass<T>::SetupFinalizer(LuaState& state, int classInfoRef)
{
LuaClassImplFinalizerSetupProxy<T, std::is_destructible<T>::value>::Setup(state);
LuaClassImplFinalizerSetupProxy<T, std::is_destructible<T>::value>::Setup(state, classInfoRef);
}
template<class T>
void LuaClass<T>::SetupGetter(LuaState& state, LuaCFunction proxy)
void LuaClass<T>::SetupGetter(LuaState& state, LuaCFunction proxy, int classInfoRef)
{
state.PushValue(1); // ClassInfo
state.PushReference(classInfoRef);
state.PushValue(-2); // Metatable
state.PushCFunction(proxy, 2);
@@ -288,7 +290,7 @@ namespace Nz
}
template<class T>
void LuaClass<T>::SetupGlobalTable(LuaState& state)
void LuaClass<T>::SetupGlobalTable(LuaState& state, int classInfoRef)
{
// Create the global table
state.PushTable(); // Class = {}
@@ -297,10 +299,10 @@ namespace Nz
state.PushTable(); // ClassMeta = {}
if (m_info->constructor)
SetupConstructor(state);
SetupConstructor(state, classInfoRef);
if (m_info->staticGetter)
SetupGetter(state, StaticGetterProxy);
SetupGetter(state, StaticGetterProxy, classInfoRef);
else
{
// Optimize by assigning the metatable instead of a search function
@@ -309,7 +311,7 @@ namespace Nz
}
if (m_info->staticSetter)
SetupSetter(state, StaticSetterProxy);
SetupSetter(state, StaticSetterProxy, classInfoRef);
m_info->staticMethods.reserve(m_staticMethods.size());
for (auto& pair : m_staticMethods)
@@ -317,7 +319,7 @@ namespace Nz
std::size_t methodIndex = m_info->staticMethods.size();
m_info->staticMethods.push_back(pair.second);
SetupMethod(state, StaticMethodProxy, pair.first, methodIndex);
SetupMethod(state, StaticMethodProxy, pair.first, methodIndex, classInfoRef);
}
state.SetMetatable(-2); // setmetatable(Class, ClassMeta), pops ClassMeta
@@ -329,15 +331,15 @@ namespace Nz
}
template<class T>
void LuaClass<T>::SetupMetatable(LuaState& state)
void LuaClass<T>::SetupMetatable(LuaState& state, int classInfoRef)
{
if (!state.NewMetatable(m_info->name))
NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance");
{
SetupFinalizer(state);
SetupFinalizer(state, classInfoRef);
if (m_info->getter || !m_info->parentGetters.empty())
SetupGetter(state, GetterProxy);
SetupGetter(state, GetterProxy, classInfoRef);
else
{
// Optimize by assigning the metatable instead of a search function
@@ -347,11 +349,11 @@ namespace Nz
}
if (m_info->setter)
SetupSetter(state, SetterProxy);
SetupSetter(state, SetterProxy, classInfoRef);
// In case a __tostring method is missing, add a default implementation returning the class name
if (m_methods.find("__tostring") == m_methods.end())
SetupDefaultToString(state);
SetupDefaultToString(state, classInfoRef);
m_info->methods.reserve(m_methods.size());
for (auto& pair : m_methods)
@@ -359,16 +361,16 @@ namespace Nz
std::size_t methodIndex = m_info->methods.size();
m_info->methods.push_back(pair.second);
SetupMethod(state, MethodProxy, pair.first, methodIndex);
SetupMethod(state, MethodProxy, pair.first, methodIndex, classInfoRef);
}
}
state.Pop(); //< Pops the metatable, it won't be collected before it's referenced by the Lua registry.
}
template<class T>
void LuaClass<T>::SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex)
void LuaClass<T>::SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex, int classInfoRef)
{
state.PushValue(1); // ClassInfo
state.PushReference(classInfoRef);
state.PushInteger(methodIndex);
state.PushCFunction(proxy, 2);
@@ -376,9 +378,9 @@ namespace Nz
}
template<class T>
void LuaClass<T>::SetupSetter(LuaState& state, LuaCFunction proxy)
void LuaClass<T>::SetupSetter(LuaState& state, LuaCFunction proxy, int classInfoRef)
{
state.PushValue(1); // ClassInfo
state.PushReference(classInfoRef);
state.PushCFunction(proxy, 1);
state.SetField("__newindex"); // Setter

View File

@@ -22,7 +22,7 @@ namespace Nz
public:
LuaInstance();
LuaInstance(const LuaInstance&) = delete;
LuaInstance(LuaInstance&& instance) = default;
LuaInstance(LuaInstance&& instance);
~LuaInstance();
inline std::size_t GetMemoryLimit() const;
@@ -33,7 +33,7 @@ namespace Nz
inline void SetTimeLimit(UInt32 limit);
LuaInstance& operator=(const LuaInstance&) = delete;
LuaInstance& operator=(LuaInstance&& instance) = default;
LuaInstance& operator=(LuaInstance&& instance);
private:
inline void SetMemoryUsage(std::size_t memoryUsage);

View File

@@ -30,6 +30,11 @@ namespace Nz
{
m_timeLimit = limit;
}
inline void LuaInstance::SetMemoryUsage(std::size_t memoryUsage)
{
m_memoryUsage = memoryUsage;
}
}
#include <Nazara/Lua/DebugOff.hpp>

View File

@@ -8,6 +8,7 @@
#define NAZARA_LUASTATE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Lua/Config.hpp>
#include <Nazara/Lua/Enums.hpp>
@@ -32,7 +33,7 @@ namespace Nz
{
public:
LuaState(const LuaState&) = default;
inline LuaState(LuaState&& instance) noexcept;
LuaState(LuaState&& instance) = default;
~LuaState() = default;
void ArgCheck(bool condition, unsigned int argNum, const char* error) const;
@@ -173,7 +174,7 @@ namespace Nz
void* ToUserdata(int index, const String& tname) const;
LuaState& operator=(const LuaState&) = default;
inline LuaState& operator=(LuaState&& instance) noexcept;
LuaState& operator=(LuaState&& instance) = default;
static int GetIndexOfUpValue(int upValue);
static LuaInstance& GetInstance(lua_State* internalState);
@@ -188,8 +189,8 @@ namespace Nz
static int ProxyFunc(lua_State* internalState);
MovablePtr<lua_State> m_state;
String m_lastError;
lua_State* m_state;
};
}

View File

@@ -19,13 +19,6 @@ namespace Nz
{
}
inline LuaState::LuaState(LuaState&& state) noexcept :
m_lastError(state.m_lastError),
m_state(state.m_state)
{
state.m_state = nullptr;
}
inline lua_State* LuaState::GetInternalState() const
{
return m_state;
@@ -776,16 +769,6 @@ namespace Nz
SetMetatable(tname);
}
inline LuaState& LuaState::operator=(LuaState&& state) noexcept
{
m_lastError = std::move(state.m_lastError);
m_state = state.m_state;
state.m_state = nullptr;
return *this;
}
template<typename T>
std::enable_if_t<std::is_signed<T>::value, T> LuaState::CheckBounds(int index, long long value) const
{

View File

@@ -81,7 +81,7 @@ namespace Nz
{
static_assert(sizeof(T) % sizeof(UInt32) == 0, "Assertion failed");
// The algorithm for logarithm in base 2 only works with numbers greather than 32 bits
// The algorithm for logarithm in base 2 only works with numbers greater than 32 bits
// This code subdivides the biggest number into 32 bits ones
for (int i = sizeof(T)-sizeof(UInt32); i >= 0; i -= sizeof(UInt32))
{

View File

@@ -238,7 +238,7 @@ namespace Nz
String error("Column out of range: (" + String::Number(column) + ") > 3");
NazaraError(error);
throw std::out_of_range(error);
throw std::out_of_range(error.ToStdString());
}
#endif
@@ -632,7 +632,7 @@ namespace Nz
String error("Row out of range: (" + String::Number(row) + ") > 3");
NazaraError(error);
throw std::out_of_range(error);
throw std::out_of_range(error.ToStdString());
}
#endif
@@ -1347,7 +1347,7 @@ namespace Nz
String error("Index out of range: (" + String::Number(x) + ", " + String::Number(y) +") > (3, 3)");
NazaraError(error);
throw std::out_of_range(error);
throw std::out_of_range(error.ToStdString());
}
#endif
@@ -1371,7 +1371,7 @@ namespace Nz
String error("Index out of range: (" + String::Number(x) + ", " + String::Number(y) +") > (3, 3)");
NazaraError(error);
throw std::out_of_range(error);
throw std::out_of_range(error.ToStdString());
}
#endif

View File

@@ -304,7 +304,7 @@ namespace Nz
ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")";
NazaraError(ss);
throw std::out_of_range(ss.ToString());
throw std::out_of_range(ss.ToString().ToStdString());
}
#endif
@@ -329,7 +329,7 @@ namespace Nz
ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")";
NazaraError(ss);
throw std::out_of_range(ss.ToString());
throw std::out_of_range(ss.ToString().ToStdString());
}
#endif

View File

@@ -579,7 +579,7 @@ namespace Nz
String error("Planes are parallel");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif

View File

@@ -607,7 +607,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -633,7 +633,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -723,7 +723,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -752,7 +752,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -1050,7 +1050,7 @@ Nz::Vector2<T> operator/(T scale, const Nz::Vector2<T>& vec)
Nz::String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif

View File

@@ -142,7 +142,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -726,7 +726,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -751,7 +751,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -839,7 +839,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
x /= vec.x;
@@ -866,7 +866,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
x /= scale;
@@ -1340,7 +1340,7 @@ Nz::Vector3<T> operator/(T scale, const Nz::Vector3<T>& vec)
Nz::String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif

View File

@@ -637,7 +637,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -663,7 +663,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -761,7 +761,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -792,7 +792,7 @@ namespace Nz
String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif
@@ -1113,7 +1113,7 @@ Nz::Vector4<T> operator/(T scale, const Nz::Vector4<T>& vec)
Nz::String error("Division by zero");
NazaraError(error);
throw std::domain_error(error);
throw std::domain_error(error.ToStdString());
}
#endif

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2017 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Network module"
// For conditions of distribution and use, see copyright notice in Config.hpp
@@ -8,6 +8,7 @@ namespace Nz
{
inline ENetPeer::ENetPeer(ENetHost* host, UInt16 peerId) :
m_host(host),
m_state(ENetPeerState::Disconnected),
m_incomingSessionID(0xFF),
m_outgoingSessionID(0xFF),
m_incomingPeerID(peerId),

View File

@@ -18,7 +18,13 @@ struct cpConstraint;
namespace Nz
{
class NAZARA_PHYSICS2D_API Constraint2D
class Constraint2D;
using Constraint2DConstRef = ObjectRef<const Constraint2D>;
using Constraint2DLibrary = ObjectLibrary<Constraint2D>;
using Constraint2DRef = ObjectRef<Constraint2D>;
class NAZARA_PHYSICS2D_API Constraint2D : public RefCounted
{
public:
Constraint2D(const Constraint2D&) = delete;
@@ -47,16 +53,24 @@ namespace Nz
Constraint2D& operator=(Constraint2D&& rhs);
protected:
Constraint2D(PhysWorld2D& world, cpConstraint* constraint);
Constraint2D(Nz::PhysWorld2D* world, cpConstraint* constraint);
MovablePtr<cpConstraint> m_constraint;
private:
static Constraint2DLibrary s_library;
};
class DampedSpringConstraint2D;
using DampedSpringConstraint2DConstRef = ObjectRef<const DampedSpringConstraint2D>;
using DampedSpringConstraint2DRef = ObjectRef<DampedSpringConstraint2D>;
class NAZARA_PHYSICS2D_API DampedSpring2D : public Constraint2D
class NAZARA_PHYSICS2D_API DampedSpringConstraint2D : public Constraint2D
{
public:
DampedSpring2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float restLength, float stiffness, float damping);
~DampedSpring2D() = default;
DampedSpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping);
~DampedSpringConstraint2D() = default;
float GetDamping() const;
Vector2f GetFirstAnchor() const;
@@ -69,13 +83,20 @@ namespace Nz
void SetRestLength(float newLength);
void SetSecondAnchor(const Vector2f& firstAnchor);
void SetStiffness(float newStiffness);
template<typename... Args> static DampedSpringConstraint2DRef New(Args&&... args);
};
class NAZARA_PHYSICS2D_API DampedRotarySpring2D : public Constraint2D
class DampedRotarySpringConstraint2D;
using DampedRotarySpringConstraint2DConstRef = ObjectRef<const DampedRotarySpringConstraint2D>;
using DampedRotarySpringConstraint2DRef = ObjectRef<DampedRotarySpringConstraint2D>;
class NAZARA_PHYSICS2D_API DampedRotarySpringConstraint2D : public Constraint2D
{
public:
DampedRotarySpring2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping);
~DampedRotarySpring2D() = default;
DampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping);
~DampedRotarySpringConstraint2D() = default;
float GetDamping() const;
float GetRestAngle() const;
@@ -84,36 +105,57 @@ namespace Nz
void SetDamping(float newDamping);
void SetRestAngle(float newAngle);
void SetStiffness(float newStiffness);
template<typename... Args> static DampedRotarySpringConstraint2DRef New(Args&&... args);
};
class GearConstraint2D;
using GearConstraint2DConstRef = ObjectRef<const GearConstraint2D>;
using GearConstraint2DRef = ObjectRef<GearConstraint2D>;
class NAZARA_PHYSICS2D_API GearJoint2D : public Constraint2D
class NAZARA_PHYSICS2D_API GearConstraint2D : public Constraint2D
{
public:
GearJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratio);
~GearJoint2D() = default;
GearConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratio);
~GearConstraint2D() = default;
float GetPhase() const;
float GetRatio() const;
void SetPhase(float phase);
void SetRatio(float ratio);
template<typename... Args> static GearConstraint2DRef New(Args&&... args);
};
class MotorConstraint2D;
using MotorConstraint2DConstRef = ObjectRef<const MotorConstraint2D>;
using MotorConstraint2DRef = ObjectRef<MotorConstraint2D>;
class NAZARA_PHYSICS2D_API MotorJoint2D : public Constraint2D
class NAZARA_PHYSICS2D_API MotorConstraint2D : public Constraint2D
{
public:
MotorJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float rate);
~MotorJoint2D() = default;
MotorConstraint2D(RigidBody2D& first, RigidBody2D& second, float rate);
~MotorConstraint2D() = default;
float GetRate() const;
void SetRate(float rate);
template<typename... Args> static MotorConstraint2DRef New(Args&&... args);
};
class NAZARA_PHYSICS2D_API PinJoint2D : public Constraint2D
class PinConstraint2D;
using PinConstraint2DConstRef = ObjectRef<const PinConstraint2D>;
using PinConstraint2DRef = ObjectRef<PinConstraint2D>;
class NAZARA_PHYSICS2D_API PinConstraint2D : public Constraint2D
{
public:
PinJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor);
~PinJoint2D() = default;
PinConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
~PinConstraint2D() = default;
float GetDistance() const;
Vector2f GetFirstAnchor() const;
@@ -122,27 +164,41 @@ namespace Nz
void SetDistance(float newDistance);
void SetFirstAnchor(const Vector2f& firstAnchor);
void SetSecondAnchor(const Vector2f& firstAnchor);
template<typename... Args> static PinConstraint2DRef New(Args&&... args);
};
class PivotConstraint2D;
using PivotConstraint2DConstRef = ObjectRef<const PivotConstraint2D>;
using PivotConstraint2DRef = ObjectRef<PivotConstraint2D>;
class NAZARA_PHYSICS2D_API PivotJoint2D : public Constraint2D
class NAZARA_PHYSICS2D_API PivotConstraint2D : public Constraint2D
{
public:
PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor);
PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor);
~PivotJoint2D() = default;
PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor);
PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor);
~PivotConstraint2D() = default;
Vector2f GetFirstAnchor() const;
Vector2f GetSecondAnchor() const;
void SetFirstAnchor(const Vector2f& firstAnchor);
void SetSecondAnchor(const Vector2f& firstAnchor);
template<typename... Args> static PivotConstraint2DRef New(Args&&... args);
};
class RatchetConstraint2D;
using RatchetConstraint2DConstRef = ObjectRef<const RatchetConstraint2D>;
using RatchetConstraint2DRef = ObjectRef<RatchetConstraint2D>;
class NAZARA_PHYSICS2D_API RatchetJoint2D : public Constraint2D
class NAZARA_PHYSICS2D_API RatchetConstraint2D : public Constraint2D
{
public:
RatchetJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratchet);
~RatchetJoint2D() = default;
RatchetConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratchet);
~RatchetConstraint2D() = default;
float GetAngle() const;
float GetPhase() const;
@@ -151,26 +207,40 @@ namespace Nz
void SetAngle(float angle);
void SetPhase(float phase);
void SetRatchet(float ratchet);
template<typename... Args> static RatchetConstraint2DRef New(Args&&... args);
};
class NAZARA_PHYSICS2D_API RotaryLimitJoint2D : public Constraint2D
class RotaryLimitConstraint2D;
using RotaryLimitConstraint2DConstRef = ObjectRef<const RotaryLimitConstraint2D>;
using RotaryLimitConstraint2DRef = ObjectRef<RotaryLimitConstraint2D>;
class NAZARA_PHYSICS2D_API RotaryLimitConstraint2D : public Constraint2D
{
public:
RotaryLimitJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle);
~RotaryLimitJoint2D() = default;
RotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle);
~RotaryLimitConstraint2D() = default;
float GetMaxAngle() const;
float GetMinAngle() const;
void SetMaxAngle(float maxAngle);
void SetMinAngle(float minAngle);
template<typename... Args> static RotaryLimitConstraint2DRef New(Args&&... args);
};
class NAZARA_PHYSICS2D_API SlideJoint2D : public Constraint2D
class SlideConstraint2D;
using SlideConstraint2DConstRef = ObjectRef<const SlideConstraint2D>;
using SlideConstraint2DRef = ObjectRef<SlideConstraint2D>;
class NAZARA_PHYSICS2D_API SlideConstraint2D : public Constraint2D
{
public:
SlideJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float min, float max);
~SlideJoint2D() = default;
SlideConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max);
~SlideConstraint2D() = default;
Vector2f GetFirstAnchor() const;
float GetMaxDistance() const;
@@ -181,6 +251,8 @@ namespace Nz
void SetMaxDistance(float newMaxDistance);
void SetMinDistance(float newMinDistance);
void SetSecondAnchor(const Vector2f& firstAnchor);
template<typename... Args> static SlideConstraint2DRef New(Args&&... args);
};
}

View File

@@ -8,6 +8,86 @@
namespace Nz
{
template<typename... Args>
DampedSpringConstraint2DRef DampedSpringConstraint2D::New(Args&&... args)
{
std::unique_ptr<DampedSpringConstraint2D> object(new DampedSpringConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
DampedRotarySpringConstraint2DRef DampedRotarySpringConstraint2D::New(Args&&... args)
{
std::unique_ptr<DampedRotarySpringConstraint2D> object(new DampedRotarySpringConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
GearConstraint2DRef GearConstraint2D::New(Args&&... args)
{
std::unique_ptr<GearConstraint2D> object(new GearConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
MotorConstraint2DRef MotorConstraint2D::New(Args&&... args)
{
std::unique_ptr<MotorConstraint2D> object(new MotorConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
PinConstraint2DRef PinConstraint2D::New(Args&&... args)
{
std::unique_ptr<PinConstraint2D> object(new PinConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
PivotConstraint2DRef PivotConstraint2D::New(Args&&... args)
{
std::unique_ptr<PivotConstraint2D> object(new PivotConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
RatchetConstraint2DRef RatchetConstraint2D::New(Args&&... args)
{
std::unique_ptr<RatchetConstraint2D> object(new RatchetConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
RotaryLimitConstraint2DRef RotaryLimitConstraint2D::New(Args&&... args)
{
std::unique_ptr<RotaryLimitConstraint2D> object(new RotaryLimitConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
SlideConstraint2DRef SlideConstraint2D::New(Args&&... args)
{
std::unique_ptr<SlideConstraint2D> object(new SlideConstraint2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Physics2D/DebugOff.hpp>

View File

@@ -74,10 +74,11 @@ namespace Nz
static constexpr std::size_t InvalidShapeIndex = std::numeric_limits<std::size_t>::max();
private:
void CopyBodyData(cpBody* body);
cpBody* Create(float mass = 1.f, float moment = 1.f);
void Destroy();
static void CopyBodyData(cpBody* from, cpBody* to);
std::vector<cpShape*> m_shapes;
Collider2DRef m_geom;
cpBody* m_handle;

View File

@@ -35,32 +35,38 @@ namespace Nz
void AddTorque(const Vector3f& torque, CoordSys coordSys = CoordSys_Global);
void EnableAutoSleep(bool autoSleep);
void EnableSimulation(bool simulation);
Boxf GetAABB() const;
Vector3f GetAngularDamping() const;
Vector3f GetAngularVelocity() const;
const Collider3DRef& GetGeom() const;
float GetGravityFactor() const;
NewtonBody* GetHandle() const;
float GetLinearDamping() const;
Vector3f GetLinearVelocity() const;
float GetMass() const;
Vector3f GetMassCenter(CoordSys coordSys = CoordSys_Local) const;
const Matrix4f& GetMatrix() const;
Vector3f GetPosition() const;
Quaternionf GetRotation() const;
Vector3f GetVelocity() const;
PhysWorld3D* GetWorld() const;
bool IsAutoSleepEnabled() const;
bool IsMoveable() const;
bool IsSimulationEnabled() const;
bool IsSleeping() const;
void SetAngularDamping(const Nz::Vector3f& angularDamping);
void SetAngularVelocity(const Vector3f& angularVelocity);
void SetGeom(Collider3DRef geom);
void SetGravityFactor(float gravityFactor);
void SetLinearDamping(float damping);
void SetLinearVelocity(const Vector3f& velocity);
void SetMass(float mass);
void SetMassCenter(const Vector3f& center);
void SetPosition(const Vector3f& position);
void SetRotation(const Quaternionf& rotation);
void SetVelocity(const Vector3f& velocity);
RigidBody3D& operator=(const RigidBody3D& object);
RigidBody3D& operator=(RigidBody3D&& object);