Merge remote-tracking branch 'refs/remotes/origin/master' into gui
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Nz
|
||||
|
||||
virtual void EnableStdReplication(bool enable) = 0;
|
||||
|
||||
virtual bool IsStdReplicationEnabled() = 0;
|
||||
virtual bool IsStdReplicationEnabled() const = 0;
|
||||
|
||||
virtual void Write(const String& string) = 0;
|
||||
virtual void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr);
|
||||
|
||||
@@ -20,8 +20,8 @@ namespace Nz
|
||||
class AbstractHash;
|
||||
class ByteArray;
|
||||
|
||||
template<typename F, typename Tuple> auto Apply(F&& fn, Tuple&& t);
|
||||
template<typename O, typename F, typename Tuple> auto Apply(O& object, F&& fn, Tuple&& t);
|
||||
template<typename F, typename Tuple> decltype(auto) Apply(F&& fn, Tuple&& t);
|
||||
template<typename O, typename F, typename Tuple> decltype(auto) Apply(O& object, F&& fn, Tuple&& t);
|
||||
template<typename T> ByteArray ComputeHash(HashType hash, const T& v);
|
||||
template<typename T> ByteArray ComputeHash(AbstractHash* hash, const T& v);
|
||||
template<typename T, std::size_t N> constexpr std::size_t CountOf(T(&name)[N]) noexcept;
|
||||
|
||||
@@ -19,13 +19,13 @@ namespace Nz
|
||||
{
|
||||
// http://www.cppsamples.com/common-tasks/apply-tuple-to-function.html
|
||||
template<typename F, typename Tuple, size_t... S>
|
||||
auto ApplyImplFunc(F&& fn, Tuple&& t, std::index_sequence<S...>)
|
||||
decltype(auto) ApplyImplFunc(F&& fn, Tuple&& t, std::index_sequence<S...>)
|
||||
{
|
||||
return std::forward<F>(fn)(std::get<S>(std::forward<Tuple>(t))...);
|
||||
}
|
||||
|
||||
template<typename O, typename F, typename Tuple, size_t... S>
|
||||
auto ApplyImplMethod(O& object, F&& fn, Tuple&& t, std::index_sequence<S...>)
|
||||
decltype(auto) ApplyImplMethod(O& object, F&& fn, Tuple&& t, std::index_sequence<S...>)
|
||||
{
|
||||
return (object .* std::forward<F>(fn))(std::get<S>(std::forward<Tuple>(t))...);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ namespace Nz
|
||||
* \see Apply
|
||||
*/
|
||||
template<typename F, typename Tuple>
|
||||
auto Apply(F&& fn, Tuple&& t)
|
||||
decltype(auto) Apply(F&& fn, Tuple&& t)
|
||||
{
|
||||
constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value;
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Nz
|
||||
* \see Apply
|
||||
*/
|
||||
template<typename O, typename F, typename Tuple>
|
||||
auto Apply(O& object, F&& fn, Tuple&& t)
|
||||
decltype(auto) Apply(O& object, F&& fn, Tuple&& t)
|
||||
{
|
||||
constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value;
|
||||
|
||||
@@ -123,9 +123,8 @@ namespace Nz
|
||||
* \see CountOf
|
||||
*/
|
||||
template<typename T, std::size_t N>
|
||||
constexpr std::size_t CountOf(T(&name)[N]) noexcept
|
||||
constexpr std::size_t CountOf(T(&)[N]) noexcept
|
||||
{
|
||||
// NazaraUnused(name); //< Because "body of function is not a return-statement" >.>
|
||||
return N;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ namespace Nz
|
||||
void EnableTimeLogging(bool enable);
|
||||
void EnableStdReplication(bool enable) override;
|
||||
|
||||
bool IsStdReplicationEnabled() override;
|
||||
bool IsTimeLoggingEnabled();
|
||||
bool IsStdReplicationEnabled() const override;
|
||||
bool IsTimeLoggingEnabled() const;
|
||||
|
||||
void Write(const String& string) override;
|
||||
void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override;
|
||||
|
||||
@@ -71,6 +71,8 @@ namespace Nz
|
||||
template<typename T>
|
||||
HandledObject<T>& HandledObject<T>::operator=(const HandledObject& object)
|
||||
{
|
||||
NazaraUnused(object);
|
||||
|
||||
// Nothing to do
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Nz
|
||||
template<typename T> bool operator<(const T& lhs, const ObjectRef<T>& rhs);
|
||||
template<typename T> bool operator<(const ObjectRef<T>& lhs, const T& rhs);
|
||||
|
||||
template<typename T> bool operator<=(const ObjectRef<T>, const ObjectRef<T>& rhs);
|
||||
template<typename T> bool operator<=(const ObjectRef<T>& lhs, const ObjectRef<T>& rhs);
|
||||
template<typename T> bool operator<=(const T& lhs, const ObjectRef<T>& rhs);
|
||||
template<typename T> bool operator<=(const ObjectRef<T>& lhs, const T& rhs);
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Nz
|
||||
while (it != Type::s_managerMap.end())
|
||||
{
|
||||
const ObjectRef<Type>& ref = it->second;
|
||||
if (ref.GetReferenceCount() == 1) // Are we the only ones to own the resource ?
|
||||
if (ref->GetReferenceCount() == 1) // Are we the only ones to own the resource ?
|
||||
{
|
||||
NazaraDebug("Purging resource from file " + ref->GetFilePath());
|
||||
Type::s_managerMap.erase(it++); // Then we erase it
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Nz
|
||||
|
||||
void EnableStdReplication(bool enable) override;
|
||||
|
||||
bool IsStdReplicationEnabled() override;
|
||||
bool IsStdReplicationEnabled() const override;
|
||||
|
||||
void Write(const String& string) override;
|
||||
void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override;
|
||||
|
||||
@@ -78,7 +78,6 @@ namespace Nz
|
||||
Color m_color;
|
||||
MaterialRef m_material;
|
||||
Recti m_localBounds;
|
||||
mutable bool m_verticesUpdated;
|
||||
float m_scale;
|
||||
|
||||
static TextSpriteLibrary::LibraryMap s_library;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Nz
|
||||
friend class LuaClass;
|
||||
|
||||
public:
|
||||
using ClassFunc = std::function<int(LuaInstance& lua, T& instance)>;
|
||||
using ClassFunc = std::function<int(LuaInstance& lua, T& instance, std::size_t argumentCount)>;
|
||||
using ClassIndexFunc = std::function<bool(LuaInstance& lua, T& instance)>;
|
||||
using ConstructorFunc = std::function<bool(LuaInstance& lua, T* instance, std::size_t argumentCount)>;
|
||||
template<typename P> using ConvertToParent = std::function<P*(T*)>;
|
||||
@@ -34,6 +34,7 @@ namespace Nz
|
||||
using StaticIndexFunc = std::function<bool(LuaInstance& lua)>;
|
||||
using StaticFunc = std::function<int(LuaInstance& lua)>;
|
||||
|
||||
LuaClass() = default;
|
||||
LuaClass(const String& name);
|
||||
|
||||
void BindDefaultConstructor();
|
||||
@@ -50,6 +51,9 @@ namespace Nz
|
||||
template<class P> void Inherit(LuaClass<P>& parent);
|
||||
template<class P> void Inherit(LuaClass<P>& parent, ConvertToParent<P> convertFunc);
|
||||
|
||||
void Reset();
|
||||
void Reset(const String& name);
|
||||
|
||||
void Register(LuaInstance& lua);
|
||||
|
||||
void PushGlobalTable(LuaInstance& lua);
|
||||
@@ -62,6 +66,19 @@ namespace Nz
|
||||
void SetStaticSetter(StaticIndexFunc getter);
|
||||
|
||||
private:
|
||||
template<typename U, bool HasDestructor>
|
||||
friend struct LuaClassImplFinalizerSetupProxy;
|
||||
|
||||
void PushClassInfo(LuaInstance& lua);
|
||||
void SetupConstructor(LuaInstance& lua);
|
||||
void SetupDefaultToString(LuaInstance& lua);
|
||||
void SetupFinalizer(LuaInstance& lua);
|
||||
void SetupGetter(LuaInstance& lua, LuaCFunction proxy);
|
||||
void SetupGlobalTable(LuaInstance& lua);
|
||||
void SetupMetatable(LuaInstance& lua);
|
||||
void SetupMethod(LuaInstance& lua, LuaCFunction proxy, const String& name, std::size_t methodIndex);
|
||||
void SetupSetter(LuaInstance& lua, LuaCFunction proxy);
|
||||
|
||||
using ParentFunc = std::function<void(LuaInstance& lua, T* instance)>;
|
||||
using InstanceGetter = std::function<T*(LuaInstance& lua)>;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// This file is part of the "Nazara Engine - Lua scripting module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Lua/LuaClass.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <type_traits>
|
||||
@@ -10,10 +11,9 @@
|
||||
namespace Nz
|
||||
{
|
||||
template<class T>
|
||||
LuaClass<T>::LuaClass(const String& name) :
|
||||
m_info(new ClassInfo)
|
||||
LuaClass<T>::LuaClass(const String& name)
|
||||
{
|
||||
m_info->name = name;
|
||||
Reset(name);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -58,147 +58,37 @@ namespace Nz
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::Reset()
|
||||
{
|
||||
m_info.reset();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::Reset(const String& name)
|
||||
{
|
||||
m_info = std::make_shared<ClassInfo>();
|
||||
m_info->name = name;
|
||||
|
||||
m_info->instanceGetters[m_info->name] = [info = m_info] (LuaInstance& instance)
|
||||
{
|
||||
return static_cast<T*>(instance.CheckUserdata(1, info->name));
|
||||
};
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::Register(LuaInstance& lua)
|
||||
{
|
||||
// Le ClassInfo doit rester en vie jusqu'à la fin du script
|
||||
// Obliger l'instance de LuaClass à rester en vie dans cette fin serait contraignant pour l'utilisateur
|
||||
// J'utilise donc une astuce, la stocker dans une UserData associée avec chaque fonction de la metatable du type,
|
||||
// cette UserData disposera d'un finalizer qui libérera le ClassInfo
|
||||
// Ainsi c'est Lua qui va s'occuper de la destruction pour nous :-)
|
||||
// De même, l'utilisation d'un shared_ptr permet de garder la structure en vie même si l'instance est libérée avant le LuaClass
|
||||
std::shared_ptr<ClassInfo>* info = static_cast<std::shared_ptr<ClassInfo>*>(lua.PushUserdata(sizeof(std::shared_ptr<ClassInfo>)));
|
||||
PlacementNew(info, m_info);
|
||||
PushClassInfo(lua);
|
||||
|
||||
// On créé la table qui contiendra une méthode (Le finalizer) pour libérer le ClassInfo
|
||||
lua.PushTable(0, 1);
|
||||
lua.PushLightUserdata(info);
|
||||
lua.PushCFunction(InfoDestructor, 1);
|
||||
lua.SetField("__gc");
|
||||
lua.SetMetatable(-2); // La table devient la metatable de l'UserData
|
||||
// Let's create the metatable which will be associated with every instance.
|
||||
SetupMetatable(lua);
|
||||
|
||||
// Maintenant, nous allons associer l'UserData avec chaque fonction, de sorte qu'il reste en vie
|
||||
// aussi longtemps que nécessaire, et que le pointeur soit transmis à chaque méthode
|
||||
if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_staticMethods.empty())
|
||||
SetupGlobalTable(lua);
|
||||
|
||||
if (!lua.NewMetatable(m_info->name))
|
||||
NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance");
|
||||
{
|
||||
// Set the type in a __type field
|
||||
lua.PushString(m_info->name);
|
||||
lua.SetField("__type");
|
||||
|
||||
// In case a __tostring method is missing, add a default implementation returning the type
|
||||
if (m_methods.find("__tostring") == m_methods.end())
|
||||
{
|
||||
// Define the Finalizer
|
||||
lua.PushValue(1); // shared_ptr on UserData
|
||||
lua.PushCFunction(ToStringProxy, 1);
|
||||
lua.SetField("__tostring");
|
||||
}
|
||||
|
||||
// Define the Finalizer
|
||||
lua.PushValue(1);
|
||||
lua.PushCFunction(FinalizerProxy, 1);
|
||||
lua.SetField("__gc");
|
||||
|
||||
if (m_info->getter || !m_info->parentGetters.empty())
|
||||
{
|
||||
lua.PushValue(1); // shared_ptr on UserData
|
||||
lua.PushValue(-2); // Metatable
|
||||
lua.PushCFunction(GetterProxy, 2);
|
||||
}
|
||||
else
|
||||
// Optimisation, plutôt que de rediriger vers une fonction C qui ne fera rien d'autre que rechercher
|
||||
// dans la table, nous envoyons directement la table, de sorte que Lua fasse directement la recherche
|
||||
// Ceci n'est possible que si nous n'avons ni getter, ni parent
|
||||
lua.PushValue(-1); // Metatable
|
||||
|
||||
lua.SetField("__index"); // Getter
|
||||
|
||||
if (m_info->setter)
|
||||
{
|
||||
lua.PushValue(1); // shared_ptr on UserData
|
||||
lua.PushCFunction(SetterProxy, 1);
|
||||
lua.SetField("__newindex"); // Setter
|
||||
}
|
||||
|
||||
m_info->methods.reserve(m_methods.size());
|
||||
for (auto& pair : m_methods)
|
||||
{
|
||||
std::size_t methodIndex = m_info->methods.size();
|
||||
m_info->methods.push_back(pair.second);
|
||||
|
||||
lua.PushValue(1); // shared_ptr on UserData
|
||||
lua.PushInteger(methodIndex);
|
||||
|
||||
lua.PushCFunction(MethodProxy, 2);
|
||||
lua.SetField(pair.first); // Method name
|
||||
}
|
||||
|
||||
m_info->instanceGetters[m_info->name] = [info = m_info] (LuaInstance& instance)
|
||||
{
|
||||
return static_cast<T*>(instance.CheckUserdata(1, info->name));
|
||||
};
|
||||
}
|
||||
lua.Pop(); // On pop la metatable
|
||||
|
||||
if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_info->staticMethods.empty())
|
||||
{
|
||||
// Création de l'instance globale
|
||||
lua.PushTable(); // Class = {}
|
||||
|
||||
// Création de la metatable associée à la table globale
|
||||
lua.PushTable(); // ClassMeta = {}
|
||||
|
||||
if (m_info->constructor)
|
||||
{
|
||||
lua.PushValue(1); // ClassInfo
|
||||
lua.PushCFunction(ConstructorProxy, 1);
|
||||
lua.SetField("__call"); // ClassMeta.__call = ConstructorProxy
|
||||
}
|
||||
|
||||
if (m_info->staticGetter)
|
||||
{
|
||||
lua.PushValue(1); // shared_ptr on UserData
|
||||
lua.PushValue(-2); // ClassMeta
|
||||
lua.PushCFunction(StaticGetterProxy, 2);
|
||||
}
|
||||
else
|
||||
// Optimisation, plutôt que de rediriger vers une fonction C qui ne fera rien d'autre que rechercher
|
||||
// dans la table, nous envoyons directement la table, de sorte que Lua fasse directement la recherche
|
||||
// Ceci n'est possible que si nous n'avons ni getter, ni parent
|
||||
lua.PushValue(-1); // ClassMeta
|
||||
|
||||
lua.SetField("__index"); // ClassMeta.__index = StaticGetterProxy/ClassMeta
|
||||
|
||||
if (m_info->staticSetter)
|
||||
{
|
||||
lua.PushValue(1); // shared_ptr on UserData
|
||||
lua.PushCFunction(StaticSetterProxy, 1);
|
||||
lua.SetField("__newindex"); // ClassMeta.__newindex = StaticSetterProxy
|
||||
}
|
||||
|
||||
m_info->staticMethods.reserve(m_staticMethods.size());
|
||||
for (auto& pair : m_staticMethods)
|
||||
{
|
||||
std::size_t methodIndex = m_info->staticMethods.size();
|
||||
m_info->staticMethods.push_back(pair.second);
|
||||
|
||||
lua.PushValue(1); // shared_ptr on UserData
|
||||
lua.PushInteger(methodIndex);
|
||||
|
||||
lua.PushCFunction(StaticMethodProxy, 2);
|
||||
lua.SetField(pair.first); // ClassMeta.method = StaticMethodProxy
|
||||
}
|
||||
|
||||
lua.SetMetatable(-2); // setmetatable(Class, ClassMeta)
|
||||
|
||||
lua.PushValue(-1); // Copie
|
||||
lua.SetGlobal(m_info->name); // Class
|
||||
|
||||
m_info->globalTableRef = lua.CreateReference();
|
||||
}
|
||||
lua.Pop(); // On pop l'Userdata (contenant nos informations)
|
||||
lua.Pop(); // Pop our ClassInfo, which is now referenced by all our functions
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -237,7 +127,7 @@ namespace Nz
|
||||
{
|
||||
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
|
||||
|
||||
BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int
|
||||
BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
handler.ProcessArgs(lua);
|
||||
|
||||
@@ -251,7 +141,7 @@ namespace Nz
|
||||
{
|
||||
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
|
||||
|
||||
BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int
|
||||
BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
handler.ProcessArgs(lua);
|
||||
|
||||
@@ -265,7 +155,7 @@ namespace Nz
|
||||
{
|
||||
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
|
||||
|
||||
BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int
|
||||
BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
handler.ProcessArgs(lua);
|
||||
|
||||
@@ -279,7 +169,7 @@ namespace Nz
|
||||
{
|
||||
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
|
||||
|
||||
BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int
|
||||
BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int
|
||||
{
|
||||
handler.ProcessArgs(lua);
|
||||
|
||||
@@ -325,6 +215,176 @@ namespace Nz
|
||||
m_info->staticSetter = setter;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::PushClassInfo(LuaInstance& lua)
|
||||
{
|
||||
// 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.
|
||||
// This shared_ptr object gets pushed as a up-value for every proxy function set in the metatable.
|
||||
// This way, there is no way our ClassInfo gets freed before any instance and the global class gets destroyed.
|
||||
std::shared_ptr<ClassInfo>* info = static_cast<std::shared_ptr<ClassInfo>*>(lua.PushUserdata(sizeof(std::shared_ptr<ClassInfo>)));
|
||||
PlacementNew(info, m_info);
|
||||
|
||||
// Setup a tiny metatable to let Lua know how to destroy our ClassInfo
|
||||
lua.PushTable(0, 1);
|
||||
lua.PushLightUserdata(info);
|
||||
lua.PushCFunction(InfoDestructor, 1);
|
||||
lua.SetField("__gc");
|
||||
lua.SetMetatable(-2);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::SetupConstructor(LuaInstance& lua)
|
||||
{
|
||||
lua.PushValue(1); // ClassInfo
|
||||
lua.PushCFunction(ConstructorProxy, 1);
|
||||
lua.SetField("__call"); // ClassMeta.__call = ConstructorProxy
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::SetupDefaultToString(LuaInstance& lua)
|
||||
{
|
||||
lua.PushValue(1); // shared_ptr on UserData
|
||||
lua.PushCFunction(ToStringProxy, 1);
|
||||
lua.SetField("__tostring");
|
||||
}
|
||||
|
||||
template<typename T, bool HasDestructor>
|
||||
struct LuaClassImplFinalizerSetupProxy;
|
||||
|
||||
template<typename T>
|
||||
struct LuaClassImplFinalizerSetupProxy<T, true>
|
||||
{
|
||||
static void Setup(LuaInstance& lua)
|
||||
{
|
||||
lua.PushValue(1); // ClassInfo
|
||||
lua.PushCFunction(LuaClass<T>::FinalizerProxy, 1);
|
||||
lua.SetField("__gc");
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct LuaClassImplFinalizerSetupProxy<T, false>
|
||||
{
|
||||
static void Setup(LuaInstance&)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::SetupFinalizer(LuaInstance& lua)
|
||||
{
|
||||
LuaClassImplFinalizerSetupProxy<T, std::is_destructible<T>::value>::Setup(lua);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::SetupGetter(LuaInstance& lua, LuaCFunction proxy)
|
||||
{
|
||||
lua.PushValue(1); // ClassInfo
|
||||
lua.PushValue(-2); // Metatable
|
||||
lua.PushCFunction(proxy, 2);
|
||||
|
||||
lua.SetField("__index"); // Getter
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::SetupGlobalTable(LuaInstance& lua)
|
||||
{
|
||||
// Create the global table
|
||||
lua.PushTable(); // Class = {}
|
||||
|
||||
// Create a metatable which will be used for our global table
|
||||
lua.PushTable(); // ClassMeta = {}
|
||||
|
||||
if (m_info->constructor)
|
||||
SetupConstructor(lua);
|
||||
|
||||
if (m_info->staticGetter)
|
||||
SetupGetter(lua, StaticGetterProxy);
|
||||
else
|
||||
{
|
||||
// Optimize by assigning the metatable instead of a search function
|
||||
lua.PushValue(-1); // Metatable
|
||||
lua.SetField("__index");
|
||||
}
|
||||
|
||||
if (m_info->staticSetter)
|
||||
SetupSetter(lua, StaticSetterProxy);
|
||||
|
||||
m_info->staticMethods.reserve(m_staticMethods.size());
|
||||
for (auto& pair : m_staticMethods)
|
||||
{
|
||||
std::size_t methodIndex = m_info->staticMethods.size();
|
||||
m_info->staticMethods.push_back(pair.second);
|
||||
|
||||
SetupMethod(lua, StaticMethodProxy, pair.first, methodIndex);
|
||||
}
|
||||
|
||||
lua.SetMetatable(-2); // setmetatable(Class, ClassMeta), pops ClassMeta
|
||||
|
||||
lua.PushValue(-1); // As CreateReference() pops the table, push a copy
|
||||
m_info->globalTableRef = lua.CreateReference();
|
||||
|
||||
lua.SetGlobal(m_info->name); // _G["Class"] = Class
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::SetupMetatable(LuaInstance& lua)
|
||||
{
|
||||
if (!lua.NewMetatable(m_info->name))
|
||||
NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance");
|
||||
{
|
||||
SetupFinalizer(lua);
|
||||
|
||||
if (m_info->getter || !m_info->parentGetters.empty())
|
||||
SetupGetter(lua, GetterProxy);
|
||||
else
|
||||
{
|
||||
// Optimize by assigning the metatable instead of a search function
|
||||
// This is only possible if we have no custom getter nor parent
|
||||
lua.PushValue(-1); // Metatable
|
||||
lua.SetField("__index");
|
||||
}
|
||||
|
||||
if (m_info->setter)
|
||||
SetupSetter(lua, SetterProxy);
|
||||
|
||||
// In case a __tostring method is missing, add a default implementation returning the class name
|
||||
if (m_methods.find("__tostring") == m_methods.end())
|
||||
SetupDefaultToString(lua);
|
||||
|
||||
m_info->methods.reserve(m_methods.size());
|
||||
for (auto& pair : m_methods)
|
||||
{
|
||||
std::size_t methodIndex = m_info->methods.size();
|
||||
m_info->methods.push_back(pair.second);
|
||||
|
||||
SetupMethod(lua, MethodProxy, pair.first, methodIndex);
|
||||
}
|
||||
}
|
||||
lua.Pop(); //< Pops the metatable, it won't be collected before it's referenced by the Lua registry.
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::SetupMethod(LuaInstance& lua, LuaCFunction proxy, const String& name, std::size_t methodIndex)
|
||||
{
|
||||
lua.PushValue(1); // ClassInfo
|
||||
lua.PushInteger(methodIndex);
|
||||
lua.PushCFunction(proxy, 2);
|
||||
|
||||
lua.SetField(name); // Method name
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void LuaClass<T>::SetupSetter(LuaInstance& lua, LuaCFunction proxy)
|
||||
{
|
||||
lua.PushValue(1); // ClassInfo
|
||||
lua.PushCFunction(proxy, 1);
|
||||
|
||||
lua.SetField("__newindex"); // Setter
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
int LuaClass<T>::ConstructorProxy(lua_State* state)
|
||||
{
|
||||
@@ -389,7 +449,7 @@ namespace Nz
|
||||
{
|
||||
// Query from the metatable
|
||||
lua.GetMetatable(info->name); //< Metatable
|
||||
lua.PushValue(1); //< Field
|
||||
lua.PushValue(2); //< Field
|
||||
lua.GetTable(); // Metatable[Field]
|
||||
|
||||
lua.Remove(-2); // Remove Metatable
|
||||
@@ -416,7 +476,6 @@ namespace Nz
|
||||
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(lua.ToUserdata(lua.GetIndexOfUpValue(1)));
|
||||
|
||||
T* instance = static_cast<T*>(lua.CheckUserdata(1, info->name));
|
||||
lua.Remove(1); //< Remove the instance from the Lua stack
|
||||
|
||||
Get(info, lua, instance);
|
||||
return 1;
|
||||
@@ -432,7 +491,7 @@ namespace Nz
|
||||
T* instance = nullptr;
|
||||
if (lua.GetMetatable(1))
|
||||
{
|
||||
LuaType type = lua.GetField("__type");
|
||||
LuaType type = lua.GetField("__name");
|
||||
if (type == LuaType_String)
|
||||
{
|
||||
String name = lua.ToString(-1);
|
||||
@@ -441,8 +500,6 @@ namespace Nz
|
||||
instance = it->second(lua);
|
||||
}
|
||||
lua.Pop(2);
|
||||
|
||||
lua.Remove(1); //< Remove the instance from the Lua stack
|
||||
}
|
||||
|
||||
if (!instance)
|
||||
@@ -451,9 +508,11 @@ namespace Nz
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::size_t argCount = lua.GetStackTop() - 1U;
|
||||
|
||||
unsigned int index = static_cast<unsigned int>(lua.ToInteger(lua.GetIndexOfUpValue(2)));
|
||||
const ClassFunc& method = info->methods[index];
|
||||
return method(lua, *instance);
|
||||
return method(lua, *instance, argCount);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -465,7 +524,6 @@ namespace Nz
|
||||
const ClassIndexFunc& setter = info->setter;
|
||||
|
||||
T& instance = *static_cast<T*>(lua.CheckUserdata(1, info->name));
|
||||
lua.Remove(1); //< Remove the instance from the Lua stack
|
||||
|
||||
if (!setter(lua, instance))
|
||||
{
|
||||
|
||||
@@ -34,10 +34,10 @@ namespace Nz
|
||||
inline LuaInstance(LuaInstance&& instance) noexcept;
|
||||
~LuaInstance();
|
||||
|
||||
void ArgCheck(bool condition, unsigned int argNum, const char* error);
|
||||
void ArgCheck(bool condition, unsigned int argNum, const String& error);
|
||||
int ArgError(unsigned int argNum, const char* error);
|
||||
int ArgError(unsigned int argNum, const String& error);
|
||||
void ArgCheck(bool condition, unsigned int argNum, const char* error) const;
|
||||
void ArgCheck(bool condition, unsigned int argNum, const String& error) const;
|
||||
int ArgError(unsigned int argNum, const char* error) const;
|
||||
int ArgError(unsigned int argNum, const String& error) const;
|
||||
|
||||
bool Call(unsigned int argCount);
|
||||
bool Call(unsigned int argCount, unsigned int resultCount);
|
||||
@@ -123,6 +123,7 @@ namespace Nz
|
||||
void Pop(unsigned int n = 1U) const;
|
||||
|
||||
template<typename T> int Push(T arg) const;
|
||||
template<typename T, typename T2, typename... Args> int Push(T firstArg, T2 secondArg, Args... args) const;
|
||||
void PushBoolean(bool value) const;
|
||||
void PushCFunction(LuaCFunction func, unsigned int upvalueCount = 0) const;
|
||||
template<typename T> void PushField(const char* name, T&& arg, int tableIndex = -2) const;
|
||||
|
||||
@@ -209,6 +209,24 @@ namespace Nz
|
||||
return LuaImplReplyVal(instance, val, TypeTag<T>());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<!std::is_arithmetic<T>::value && !std::is_enum<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T&>)
|
||||
{
|
||||
return LuaImplReplyVal(instance, std::move(val), TypeTag<T>());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<!std::is_arithmetic<T>::value && !std::is_enum<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<const T&>)
|
||||
{
|
||||
return LuaImplReplyVal(instance, std::move(val), TypeTag<T>());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int LuaImplReplyVal(const LuaInstance& instance, T&& val, TypeTag<T&&>)
|
||||
{
|
||||
return LuaImplReplyVal(instance, std::forward<T>(val), TypeTag<T>());
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, std::string&& val, TypeTag<std::string>)
|
||||
{
|
||||
instance.PushString(val.c_str(), val.size());
|
||||
@@ -266,7 +284,7 @@ namespace Nz
|
||||
template<std::size_t N, std::size_t FirstDefArg, typename ArgType, typename ArgContainer, typename DefArgContainer>
|
||||
static unsigned int Process(const LuaInstance& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs)
|
||||
{
|
||||
return LuaImplQueryArg(instance, argIndex, &std::get<N>(args), std::get<std::tuple_size<DefArgContainer>() - N + FirstDefArg - 1>(defArgs), TypeTag<ArgType>());
|
||||
return LuaImplQueryArg(instance, argIndex, &std::get<N>(args), std::get<FirstDefArg + std::tuple_size<DefArgContainer>() - N - 1>(defArgs), TypeTag<ArgType>());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -375,7 +393,7 @@ namespace Nz
|
||||
|
||||
void ProcessArgs(const LuaInstance& instance) const
|
||||
{
|
||||
m_index = 1;
|
||||
m_index = 2; //< 1 being the instance
|
||||
ProcessArgs<0, Args...>(instance);
|
||||
}
|
||||
|
||||
@@ -394,6 +412,19 @@ namespace Nz
|
||||
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
|
||||
}
|
||||
|
||||
template<typename T, typename P>
|
||||
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, T& object, T&(P::*func)(Args...)) const
|
||||
{
|
||||
T& r = Apply(object, func, m_args);
|
||||
if (&r == &object)
|
||||
{
|
||||
instance.PushValue(1); //< Userdata
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return LuaImplReplyVal(instance, r, TypeTag<T&>());
|
||||
}
|
||||
|
||||
template<typename T, typename P>
|
||||
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
|
||||
{
|
||||
@@ -409,11 +440,22 @@ namespace Nz
|
||||
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
|
||||
}
|
||||
|
||||
template<typename T, typename P>
|
||||
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, const T& object, const T&(P::*func)(Args...) const) const
|
||||
{
|
||||
const T& r = Apply(object, func, m_args);
|
||||
if (&r == &object)
|
||||
{
|
||||
instance.PushValue(1); //< Userdata
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return LuaImplReplyVal(instance, r, TypeTag<T&>());
|
||||
}
|
||||
|
||||
template<typename T, typename P>
|
||||
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, T& object, void(P::*func)(Args...)) const
|
||||
{
|
||||
NazaraUnused(instance);
|
||||
|
||||
if (!object)
|
||||
{
|
||||
instance.Error("Invalid object");
|
||||
@@ -436,11 +478,28 @@ namespace Nz
|
||||
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
|
||||
}
|
||||
|
||||
template<typename T, typename P>
|
||||
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, T& object, typename PointedType<T>::type&(P::*func)(Args...) const) const
|
||||
{
|
||||
if (!object)
|
||||
{
|
||||
instance.Error("Invalid object");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const typename PointedType<T>::type& r = Apply(*object, func, m_args);
|
||||
if (&r == &*object)
|
||||
{
|
||||
instance.PushValue(1); //< Userdata
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return LuaImplReplyVal(instance, r, TypeTag<T&>());
|
||||
}
|
||||
|
||||
template<typename T, typename P>
|
||||
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
|
||||
{
|
||||
NazaraUnused(instance);
|
||||
|
||||
if (!object)
|
||||
{
|
||||
instance.Error("Invalid object");
|
||||
@@ -463,6 +522,25 @@ namespace Nz
|
||||
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
|
||||
}
|
||||
|
||||
template<typename T, typename P>
|
||||
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, const T& object, const typename PointedType<T>::type&(P::*func)(Args...) const) const
|
||||
{
|
||||
if (!object)
|
||||
{
|
||||
instance.Error("Invalid object");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const typename PointedType<T>::type& r = Apply(*object, func, m_args);
|
||||
if (&r == &*object)
|
||||
{
|
||||
instance.PushValue(1); //< Userdata
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return LuaImplReplyVal(instance, r, TypeTag<T&>());
|
||||
}
|
||||
|
||||
private:
|
||||
using ArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<Args>>...>;
|
||||
using DefArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<DefArgs>>...>;
|
||||
@@ -606,6 +684,16 @@ namespace Nz
|
||||
return LuaImplReplyVal(*this, std::move(arg), TypeTag<T>());
|
||||
}
|
||||
|
||||
template<typename T, typename T2, typename... Args>
|
||||
int LuaInstance::Push(T firstArg, T2 secondArg, Args... args) const
|
||||
{
|
||||
int valCount = 0;
|
||||
valCount += Push(std::move(firstArg));
|
||||
valCount += Push(secondArg, std::forward<Args>(args)...);
|
||||
|
||||
return valCount;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void LuaInstance::PushField(const char* name, T&& arg, int tableIndex) const
|
||||
{
|
||||
@@ -648,7 +736,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
void LuaInstance::PushInstance(const char* tname, const T& instance) const
|
||||
{
|
||||
T* userdata = static_cast<T*>(PushUserdata(sizeof(T*)));
|
||||
T* userdata = static_cast<T*>(PushUserdata(sizeof(T)));
|
||||
PlacementNew(userdata, instance);
|
||||
|
||||
SetMetatable(tname);
|
||||
@@ -657,7 +745,7 @@ namespace Nz
|
||||
template<typename T>
|
||||
void LuaInstance::PushInstance(const char* tname, T&& instance) const
|
||||
{
|
||||
T* userdata = static_cast<T*>(PushUserdata(sizeof(T*)));
|
||||
T* userdata = static_cast<T*>(PushUserdata(sizeof(T)));
|
||||
PlacementNew(userdata, std::move(instance));
|
||||
|
||||
SetMetatable(tname);
|
||||
@@ -666,7 +754,7 @@ namespace Nz
|
||||
template<typename T, typename... Args>
|
||||
void LuaInstance::PushInstance(const char* tname, Args&&... args) const
|
||||
{
|
||||
T* userdata = static_cast<T*>(PushUserdata(sizeof(T*)));
|
||||
T* userdata = static_cast<T*>(PushUserdata(sizeof(T)));
|
||||
PlacementNew(userdata, std::forward<Args>(args)...);
|
||||
|
||||
SetMetatable(tname);
|
||||
|
||||
@@ -242,7 +242,7 @@ namespace Nz
|
||||
}
|
||||
#endif
|
||||
|
||||
T* ptr = (&m11) + column*4;
|
||||
const T* ptr = (&m11) + column*4;
|
||||
return Vector4<T>(ptr);
|
||||
}
|
||||
|
||||
@@ -636,7 +636,7 @@ namespace Nz
|
||||
}
|
||||
#endif
|
||||
|
||||
T* ptr = &m11;
|
||||
const T* ptr = &m11;
|
||||
return Vector4<T>(ptr[row], ptr[row+4], ptr[row+8], ptr[row+12]);
|
||||
}
|
||||
|
||||
|
||||
@@ -553,9 +553,9 @@ namespace Nz
|
||||
template<typename T>
|
||||
Vector3<T> Quaternion<T>::operator*(const Vector3<T>& vec) const
|
||||
{
|
||||
Vector3f quatVec(x, y, z);
|
||||
Vector3f uv = quatVec.CrossProduct(vec);
|
||||
Vector3f uuv = quatVec.CrossProduct(uv);
|
||||
Vector3<T> quatVec(x, y, z);
|
||||
Vector3<T> uv = quatVec.CrossProduct(vec);
|
||||
Vector3<T> uuv = quatVec.CrossProduct(uv);
|
||||
uv *= F(2.0) * w;
|
||||
uuv *= F(2.0);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_VECTOR2_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -119,6 +120,11 @@ template<typename T> std::ostream& operator<<(std::ostream& out, const Nz::Vecto
|
||||
template<typename T> Nz::Vector2<T> operator*(T scale, const Nz::Vector2<T>& vec);
|
||||
template<typename T> Nz::Vector2<T> operator/(T scale, const Nz::Vector2<T>& vec);
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<class T> struct hash<Nz::Vector2<T>>;
|
||||
}
|
||||
|
||||
#include <Nazara/Math/Vector2.inl>
|
||||
|
||||
#endif // NAZARA_VECTOR2_HPP
|
||||
|
||||
@@ -1057,6 +1057,29 @@ Nz::Vector2<T> operator/(T scale, const Nz::Vector2<T>& vec)
|
||||
return Nz::Vector2<T>(scale / vec.x, scale / vec.y);
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<class T>
|
||||
struct hash<Nz::Vector2<T>>
|
||||
{
|
||||
/*!
|
||||
* \brief Specialisation of std to hash
|
||||
* \return Result of the hash
|
||||
*
|
||||
* \param v Vector2 to hash
|
||||
*/
|
||||
std::size_t operator()(const Nz::Vector2<T>& v) const
|
||||
{
|
||||
std::size_t seed {};
|
||||
|
||||
Nz::HashCombine(seed, v.x);
|
||||
Nz::HashCombine(seed, v.y);
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_VECTOR3_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -141,6 +142,11 @@ template<typename T> std::ostream& operator<<(std::ostream& out, const Nz::Vecto
|
||||
template<typename T> Nz::Vector3<T> operator*(T scale, const Nz::Vector3<T>& vec);
|
||||
template<typename T> Nz::Vector3<T> operator/(T scale, const Nz::Vector3<T>& vec);
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<class T> struct hash<Nz::Vector3<T>>;
|
||||
}
|
||||
|
||||
#include <Nazara/Math/Vector3.inl>
|
||||
|
||||
#endif // NAZARA_VECTOR3_HPP
|
||||
|
||||
@@ -1347,6 +1347,31 @@ Nz::Vector3<T> operator/(T scale, const Nz::Vector3<T>& vec)
|
||||
return Nz::Vector3<T>(scale / vec.x, scale / vec.y, scale / vec.z);
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<class T>
|
||||
struct hash<Nz::Vector3<T>>
|
||||
{
|
||||
/*!
|
||||
* \brief Specialisation of std to hash
|
||||
* \return Result of the hash
|
||||
*
|
||||
* \param v Vector3 to hash
|
||||
*/
|
||||
|
||||
std::size_t operator()(const Nz::Vector3<T>& v) const
|
||||
{
|
||||
std::size_t seed {};
|
||||
|
||||
Nz::HashCombine(seed, v.x);
|
||||
Nz::HashCombine(seed, v.y);
|
||||
Nz::HashCombine(seed, v.z);
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_VECTOR4_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -117,6 +118,11 @@ template<typename T> std::ostream& operator<<(std::ostream& out, const Nz::Vecto
|
||||
template<typename T> Nz::Vector4<T> operator*(T scale, const Nz::Vector4<T>& vec);
|
||||
template<typename T> Nz::Vector4<T> operator/(T scale, const Nz::Vector4<T>& vec);
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<class T> struct hash<Nz::Vector4<T>>;
|
||||
}
|
||||
|
||||
#include <Nazara/Math/Vector4.inl>
|
||||
|
||||
#endif // NAZARA_VECTOR4_HPP
|
||||
|
||||
@@ -1120,6 +1120,31 @@ Nz::Vector4<T> operator/(T scale, const Nz::Vector4<T>& vec)
|
||||
return Nz::Vector4<T>(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w);
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<class T>
|
||||
struct hash<Nz::Vector4<T>>
|
||||
{
|
||||
/*!
|
||||
* \brief Specialisation of std to hash
|
||||
* \return Result of the hash
|
||||
*
|
||||
* \param v Vector4 to hash
|
||||
*/
|
||||
std::size_t operator()(const Nz::Vector4<T>& v) const
|
||||
{
|
||||
std::size_t seed {};
|
||||
|
||||
Nz::HashCombine(seed, v.x);
|
||||
Nz::HashCombine(seed, v.y);
|
||||
Nz::HashCombine(seed, v.z);
|
||||
Nz::HashCombine(seed, v.w);
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Nz
|
||||
*/
|
||||
|
||||
inline IpAddress::IpAddress(const UInt8& a, const UInt8& b, const UInt8& c, const UInt8& d, UInt16 port) :
|
||||
IpAddress(IPv4{a, b, c, d}, port)
|
||||
IpAddress(IPv4{{a, b, c, d}}, port)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Nz
|
||||
*/
|
||||
|
||||
inline IpAddress::IpAddress(const UInt16& a, const UInt16& b, const UInt16& c, const UInt16& d, const UInt16& e, const UInt16& f, const UInt16& g, const UInt16& h, UInt16 port) :
|
||||
IpAddress(IPv6{a, b, c, d, e, f, g, h}, port)
|
||||
IpAddress(IPv6{{a, b, c, d, e, f, g, h}}, port)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -79,8 +79,8 @@ namespace Nz
|
||||
PendingPacket m_pendingPacket;
|
||||
UInt64 m_keepAliveInterval;
|
||||
UInt64 m_keepAliveTime;
|
||||
bool m_isLowDelayEnabled;
|
||||
bool m_isKeepAliveEnabled;
|
||||
bool m_isLowDelayEnabled;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,6 @@ namespace Nz
|
||||
|
||||
private:
|
||||
const NoiseBase& m_source;
|
||||
float m_value;
|
||||
float m_remainder;
|
||||
float m_offset;
|
||||
float m_weight;
|
||||
float m_signal;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENUMS_PHYSICS_HPP
|
||||
#define NAZARA_ENUMS_PHYSICS_HPP
|
||||
|
||||
enum GeomType
|
||||
{
|
||||
GeomType_Box,
|
||||
GeomType_Capsule,
|
||||
GeomType_Cone,
|
||||
GeomType_Compound,
|
||||
GeomType_ConvexHull,
|
||||
GeomType_Cylinder,
|
||||
GeomType_Heightfield,
|
||||
GeomType_Null,
|
||||
GeomType_Scene,
|
||||
GeomType_Sphere,
|
||||
GeomType_Tree,
|
||||
|
||||
GeomType_Max = GeomType_Tree
|
||||
};
|
||||
|
||||
#endif // NAZARA_ENUMS_PHYSICS_HPP
|
||||
@@ -1,273 +0,0 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GEOM_HPP
|
||||
#define NAZARA_GEOM_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/PrimitiveList.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
#include <Nazara/Physics/Enums.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
class NewtonCollision;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
///TODO: CollisionModifier
|
||||
///TODO: HeightfieldGeom
|
||||
///TODO: PlaneGeom ?
|
||||
///TODO: SceneGeom
|
||||
///TODO: TreeGeom
|
||||
|
||||
class PhysGeom;
|
||||
class PhysWorld;
|
||||
|
||||
using PhysGeomConstRef = ObjectRef<const PhysGeom>;
|
||||
using PhysGeomLibrary = ObjectLibrary<PhysGeom>;
|
||||
using PhysGeomRef = ObjectRef<PhysGeom>;
|
||||
|
||||
class NAZARA_PHYSICS_API PhysGeom : public RefCounted
|
||||
{
|
||||
friend PhysGeomLibrary;
|
||||
friend class Physics;
|
||||
|
||||
public:
|
||||
PhysGeom() = default;
|
||||
PhysGeom(const PhysGeom&) = delete;
|
||||
PhysGeom(PhysGeom&&) = delete;
|
||||
virtual ~PhysGeom();
|
||||
|
||||
Boxf ComputeAABB(const Vector3f& translation, const Quaternionf& rotation, const Vector3f& scale) const;
|
||||
virtual Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const;
|
||||
virtual void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const;
|
||||
virtual float ComputeVolume() const;
|
||||
|
||||
NewtonCollision* GetHandle(PhysWorld* world) const;
|
||||
virtual GeomType GetType() const = 0;
|
||||
|
||||
PhysGeom& operator=(const PhysGeom&) = delete;
|
||||
PhysGeom& operator=(PhysGeom&&) = delete;
|
||||
|
||||
static PhysGeomRef Build(const PrimitiveList& list);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnPhysGeomRelease, const PhysGeom* /*physGeom*/);
|
||||
|
||||
protected:
|
||||
virtual NewtonCollision* CreateHandle(PhysWorld* world) const = 0;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
mutable std::unordered_map<PhysWorld*, NewtonCollision*> m_handles;
|
||||
|
||||
static PhysGeomLibrary::LibraryMap s_library;
|
||||
};
|
||||
|
||||
class BoxGeom;
|
||||
|
||||
using BoxGeomConstRef = ObjectRef<const BoxGeom>;
|
||||
using BoxGeomRef = ObjectRef<BoxGeom>;
|
||||
|
||||
class NAZARA_PHYSICS_API BoxGeom : public PhysGeom
|
||||
{
|
||||
public:
|
||||
BoxGeom(const Vector3f& lengths, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
BoxGeom(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
|
||||
float ComputeVolume() const override;
|
||||
|
||||
Vector3f GetLengths() const;
|
||||
GeomType GetType() const override;
|
||||
|
||||
template<typename... Args> static BoxGeomRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||
|
||||
Matrix4f m_matrix;
|
||||
Vector3f m_lengths;
|
||||
};
|
||||
|
||||
class CapsuleGeom;
|
||||
|
||||
using CapsuleGeomConstRef = ObjectRef<const CapsuleGeom>;
|
||||
using CapsuleGeomRef = ObjectRef<CapsuleGeom>;
|
||||
|
||||
class NAZARA_PHYSICS_API CapsuleGeom : public PhysGeom
|
||||
{
|
||||
public:
|
||||
CapsuleGeom(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
CapsuleGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
GeomType GetType() const override;
|
||||
|
||||
template<typename... Args> static CapsuleGeomRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||
|
||||
Matrix4f m_matrix;
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class CompoundGeom;
|
||||
|
||||
using CompoundGeomConstRef = ObjectRef<const CompoundGeom>;
|
||||
using CompoundGeomRef = ObjectRef<CompoundGeom>;
|
||||
|
||||
class NAZARA_PHYSICS_API CompoundGeom : public PhysGeom
|
||||
{
|
||||
public:
|
||||
CompoundGeom(PhysGeom** geoms, std::size_t geomCount);
|
||||
|
||||
const std::vector<PhysGeomRef>& GetGeoms() const;
|
||||
GeomType GetType() const override;
|
||||
|
||||
template<typename... Args> static CompoundGeomRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||
|
||||
std::vector<PhysGeomRef> m_geoms;
|
||||
};
|
||||
|
||||
class ConeGeom;
|
||||
|
||||
using ConeGeomConstRef = ObjectRef<const ConeGeom>;
|
||||
using ConeGeomRef = ObjectRef<ConeGeom>;
|
||||
|
||||
class NAZARA_PHYSICS_API ConeGeom : public PhysGeom
|
||||
{
|
||||
public:
|
||||
ConeGeom(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
ConeGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
GeomType GetType() const override;
|
||||
|
||||
template<typename... Args> static ConeGeomRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||
|
||||
Matrix4f m_matrix;
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class ConvexHullGeom;
|
||||
|
||||
using ConvexHullGeomConstRef = ObjectRef<const ConvexHullGeom>;
|
||||
using ConvexHullGeomRef = ObjectRef<ConvexHullGeom>;
|
||||
|
||||
class NAZARA_PHYSICS_API ConvexHullGeom : public PhysGeom
|
||||
{
|
||||
public:
|
||||
ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride = sizeof(Vector3f), float tolerance = 0.002f, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
GeomType GetType() const override;
|
||||
|
||||
template<typename... Args> static ConvexHullGeomRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||
|
||||
std::vector<Vector3f> m_vertices;
|
||||
Matrix4f m_matrix;
|
||||
float m_tolerance;
|
||||
unsigned int m_vertexStride;
|
||||
};
|
||||
|
||||
class CylinderGeom;
|
||||
|
||||
using CylinderGeomConstRef = ObjectRef<const CylinderGeom>;
|
||||
using CylinderGeomRef = ObjectRef<CylinderGeom>;
|
||||
|
||||
class NAZARA_PHYSICS_API CylinderGeom : public PhysGeom
|
||||
{
|
||||
public:
|
||||
CylinderGeom(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
CylinderGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
GeomType GetType() const override;
|
||||
|
||||
template<typename... Args> static CylinderGeomRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||
|
||||
Matrix4f m_matrix;
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NullGeom;
|
||||
|
||||
using NullGeomConstRef = ObjectRef<const NullGeom>;
|
||||
using NullGeomRef = ObjectRef<NullGeom>;
|
||||
|
||||
class NAZARA_PHYSICS_API NullGeom : public PhysGeom
|
||||
{
|
||||
public:
|
||||
NullGeom();
|
||||
|
||||
void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const override;
|
||||
|
||||
GeomType GetType() const override;
|
||||
|
||||
template<typename... Args> static NullGeomRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||
};
|
||||
|
||||
class SphereGeom;
|
||||
|
||||
using SphereGeomConstRef = ObjectRef<const SphereGeom>;
|
||||
using SphereGeomRef = ObjectRef<SphereGeom>;
|
||||
|
||||
class NAZARA_PHYSICS_API SphereGeom : public PhysGeom
|
||||
{
|
||||
public:
|
||||
SphereGeom(float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
SphereGeom(float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
|
||||
float ComputeVolume() const override;
|
||||
|
||||
float GetRadius() const;
|
||||
GeomType GetType() const override;
|
||||
|
||||
template<typename... Args> static SphereGeomRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld* world) const override;
|
||||
|
||||
Vector3f m_position;
|
||||
float m_radius;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics/Geom.inl>
|
||||
|
||||
#endif // NAZARA_PHYSWORLD_HPP
|
||||
@@ -1,83 +0,0 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Physics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename... Args>
|
||||
BoxGeomRef BoxGeom::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<BoxGeom> object(new BoxGeom(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
CapsuleGeomRef CapsuleGeom::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<CapsuleGeom> object(new CapsuleGeom(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
CompoundGeomRef CompoundGeom::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<CompoundGeom> object(new CompoundGeom(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
ConeGeomRef ConeGeom::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<ConeGeom> object(new ConeGeom(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
ConvexHullGeomRef ConvexHullGeom::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<ConvexHullGeom> object(new ConvexHullGeom(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
CylinderGeomRef CylinderGeom::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<CylinderGeom> object(new CylinderGeom(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
NullGeomRef NullGeom::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<NullGeom> object(new NullGeom(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
SphereGeomRef SphereGeom::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<SphereGeom> object(new SphereGeom(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics/DebugOff.hpp>
|
||||
@@ -1,7 +1,7 @@
|
||||
// This file was automatically generated on 24 Jun 2015 at 13:55:50
|
||||
// This file was automatically generated on 14 Oct 2016 at 18:58:18
|
||||
|
||||
/*
|
||||
Nazara Engine - Physics module
|
||||
Nazara Engine - Physics 2D module
|
||||
|
||||
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
@@ -26,14 +26,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GLOBAL_PHYSICS_HPP
|
||||
#define NAZARA_GLOBAL_PHYSICS_HPP
|
||||
#ifndef NAZARA_GLOBAL_PHYSICS2D_HPP
|
||||
#define NAZARA_GLOBAL_PHYSICS2D_HPP
|
||||
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
#include <Nazara/Physics/Enums.hpp>
|
||||
#include <Nazara/Physics/Geom.hpp>
|
||||
#include <Nazara/Physics/Physics.hpp>
|
||||
#include <Nazara/Physics/PhysObject.hpp>
|
||||
#include <Nazara/Physics/PhysWorld.hpp>
|
||||
#include <Nazara/Physics2D/PhysWorld2D.hpp>
|
||||
#include <Nazara/Physics2D/Physics2D.hpp>
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
#include <Nazara/Physics2D/Enums.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/RigidBody2D.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_PHYSICS_HPP
|
||||
#endif // NAZARA_GLOBAL_PHYSICS2D_HPP
|
||||
132
include/Nazara/Physics2D/Collider2D.hpp
Normal file
132
include/Nazara/Physics2D/Collider2D.hpp
Normal file
@@ -0,0 +1,132 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_COLLIDER2D_HPP
|
||||
#define NAZARA_COLLIDER2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/Enums.hpp>
|
||||
#include <vector>
|
||||
|
||||
struct cpShape;
|
||||
struct cpSpace;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Collider2D;
|
||||
class RigidBody2D;
|
||||
|
||||
using Collider2DConstRef = ObjectRef<const Collider2D>;
|
||||
using Collider2DLibrary = ObjectLibrary<Collider2D>;
|
||||
using Collider2DRef = ObjectRef<Collider2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API Collider2D : public RefCounted
|
||||
{
|
||||
friend Collider2DLibrary;
|
||||
friend RigidBody2D;
|
||||
|
||||
public:
|
||||
Collider2D() = default;
|
||||
Collider2D(const Collider2D&) = delete;
|
||||
Collider2D(Collider2D&&) = delete;
|
||||
virtual ~Collider2D();
|
||||
|
||||
virtual float ComputeInertialMatrix(float mass) const = 0;
|
||||
|
||||
virtual ColliderType2D GetType() const = 0;
|
||||
|
||||
Collider2D& operator=(const Collider2D&) = delete;
|
||||
Collider2D& operator=(Collider2D&&) = delete;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnColliderRelease, const Collider2D* /*collider*/);
|
||||
|
||||
protected:
|
||||
virtual std::vector<cpShape*> CreateShapes(RigidBody2D* body) const = 0;
|
||||
|
||||
static Collider2DLibrary::LibraryMap s_library;
|
||||
};
|
||||
|
||||
class BoxCollider2D;
|
||||
|
||||
using BoxCollider2DConstRef = ObjectRef<const BoxCollider2D>;
|
||||
using BoxCollider2DRef = ObjectRef<BoxCollider2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API BoxCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
BoxCollider2D(const Vector2f& size, float radius = 0.f);
|
||||
BoxCollider2D(const Rectf& rect, float radius = 0.f);
|
||||
|
||||
float ComputeInertialMatrix(float mass) const override;
|
||||
|
||||
inline const Rectf& GetRect() const;
|
||||
inline Vector2f GetSize() const;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
template<typename... Args> static BoxCollider2DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
std::vector<cpShape*> CreateShapes(RigidBody2D* body) const override;
|
||||
|
||||
Rectf m_rect;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class CircleCollider2D;
|
||||
|
||||
using CircleCollider2DConstRef = ObjectRef<const CircleCollider2D>;
|
||||
using CircleCollider2DRef = ObjectRef<CircleCollider2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API CircleCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
CircleCollider2D(float radius, const Vector2f& offset = Vector2f::Zero());
|
||||
|
||||
float ComputeInertialMatrix(float mass) const override;
|
||||
|
||||
inline float GetRadius() const;
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
template<typename... Args> static CircleCollider2DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
std::vector<cpShape*> CreateShapes(RigidBody2D* body) const override;
|
||||
|
||||
Vector2f m_offset;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NullCollider2D;
|
||||
|
||||
using NullCollider2DConstRef = ObjectRef<const NullCollider2D>;
|
||||
using NullCollider2DRef = ObjectRef<NullCollider2D>;
|
||||
|
||||
class NAZARA_PHYSICS2D_API NullCollider2D : public Collider2D
|
||||
{
|
||||
public:
|
||||
NullCollider2D() = default;
|
||||
|
||||
float ComputeInertialMatrix(float mass) const override;
|
||||
|
||||
ColliderType2D GetType() const override;
|
||||
|
||||
template<typename... Args> static NullCollider2DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
std::vector<cpShape*> CreateShapes(RigidBody2D* body) const override;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/Collider2D.inl>
|
||||
|
||||
#endif // NAZARA_COLLIDER2D_HPP
|
||||
54
include/Nazara/Physics2D/Collider2D.inl
Normal file
54
include/Nazara/Physics2D/Collider2D.inl
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Physics2D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const Rectf& BoxCollider2D::GetRect() const
|
||||
{
|
||||
return m_rect;
|
||||
}
|
||||
|
||||
inline Vector2f BoxCollider2D::GetSize() const
|
||||
{
|
||||
return m_rect.GetLengths();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
BoxCollider2DRef BoxCollider2D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<BoxCollider2D> object(new BoxCollider2D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
inline float CircleCollider2D::GetRadius() const
|
||||
{
|
||||
return m_radius;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
CircleCollider2DRef CircleCollider2D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<CircleCollider2D> object(new CircleCollider2D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
NullCollider2DRef NullCollider2D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<NullCollider2D> object(new NullCollider2D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Nazara Engine - Physics module
|
||||
Nazara Engine - Physics 2D module
|
||||
|
||||
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
@@ -24,28 +24,28 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_PHYSICS_HPP
|
||||
#define NAZARA_CONFIG_PHYSICS_HPP
|
||||
#ifndef NAZARA_CONFIG_PHYSICS2D_HPP
|
||||
#define NAZARA_CONFIG_PHYSICS2D_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Utilise un manager de mémoire pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
|
||||
#define NAZARA_PHYSICS_MANAGE_MEMORY 0
|
||||
#define NAZARA_PHYSICS2D_MANAGE_MEMORY 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_PHYSICS_SAFE 1
|
||||
#define NAZARA_PHYSICS2D_SAFE 1
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/Physics/ConfigCheck.hpp>
|
||||
#include <Nazara/Physics2D/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_PHYSICS_API
|
||||
#define NAZARA_PHYSICS2D_API
|
||||
#else
|
||||
#ifdef NAZARA_PHYSICS_BUILD
|
||||
#define NAZARA_PHYSICS_API NAZARA_EXPORT
|
||||
#ifdef NAZARA_PHYSICS2D_BUILD
|
||||
#define NAZARA_PHYSICS2D_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_PHYSICS_API NAZARA_IMPORT
|
||||
#define NAZARA_PHYSICS2D_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CONFIG_PHYSICS_HPP
|
||||
#endif // NAZARA_CONFIG_PHYSICS3D_HPP
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics module"
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
@@ -12,7 +12,7 @@
|
||||
// On force la valeur de MANAGE_MEMORY en mode debug
|
||||
#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS_MANAGE_MEMORY
|
||||
#undef NAZARA_PHYSICS_MANAGE_MEMORY
|
||||
#define NAZARA_PHYSICS_MANAGE_MEMORY 0
|
||||
#define NAZARA_PHYSICS3D_MANAGE_MEMORY 0
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CONFIG_CHECK_PHYSICS_HPP
|
||||
@@ -1,8 +1,8 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics module"
|
||||
// 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/Physics/Config.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#if NAZARA_PHYSICS_MANAGE_MEMORY
|
||||
#include <Nazara/Core/Debug/NewRedefinition.hpp>
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics module"
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
|
||||
24
include/Nazara/Physics2D/Enums.hpp
Normal file
24
include/Nazara/Physics2D/Enums.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENUMS_PHYSICS2D_HPP
|
||||
#define NAZARA_ENUMS_PHYSICS2D_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum ColliderType2D
|
||||
{
|
||||
ColliderType2D_Box,
|
||||
ColliderType2D_Convex,
|
||||
ColliderType2D_Circle,
|
||||
ColliderType2D_Null,
|
||||
ColliderType2D_Segment,
|
||||
|
||||
ColliderType2D_Max = ColliderType2D_Segment
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_ENUMS_PHYSICS2D_HPP
|
||||
46
include/Nazara/Physics2D/PhysWorld2D.hpp
Normal file
46
include/Nazara/Physics2D/PhysWorld2D.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSWORLD2D_HPP
|
||||
#define NAZARA_PHYSWORLD2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
|
||||
struct cpSpace;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS2D_API PhysWorld2D
|
||||
{
|
||||
public:
|
||||
PhysWorld2D();
|
||||
PhysWorld2D(const PhysWorld2D&) = delete;
|
||||
PhysWorld2D(PhysWorld2D&&) = delete; ///TODO
|
||||
~PhysWorld2D();
|
||||
|
||||
Vector2f GetGravity() const;
|
||||
cpSpace* GetHandle() const;
|
||||
float GetStepSize() const;
|
||||
|
||||
void SetGravity(const Vector2f& gravity);
|
||||
void SetSolverModel(unsigned int model);
|
||||
void SetStepSize(float stepSize);
|
||||
|
||||
void Step(float timestep);
|
||||
|
||||
PhysWorld2D& operator=(const PhysWorld2D&) = delete;
|
||||
PhysWorld2D& operator=(PhysWorld2D&&) = delete; ///TODO
|
||||
|
||||
private:
|
||||
cpSpace* m_handle;
|
||||
float m_stepSize;
|
||||
float m_timestepAccumulator;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PHYSWORLD2D_HPP
|
||||
33
include/Nazara/Physics2D/Physics2D.hpp
Normal file
33
include/Nazara/Physics2D/Physics2D.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS2D_HPP
|
||||
#define NAZARA_PHYSICS2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS2D_API Physics2D
|
||||
{
|
||||
public:
|
||||
Physics2D() = delete;
|
||||
~Physics2D() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PHYSICS2D_HPP
|
||||
74
include/Nazara/Physics2D/RigidBody2D.hpp
Normal file
74
include/Nazara/Physics2D/RigidBody2D.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 2D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_RIGIDBODY2D_HPP
|
||||
#define NAZARA_RIGIDBODY2D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics2D/Config.hpp>
|
||||
#include <Nazara/Physics2D/Collider2D.hpp>
|
||||
|
||||
struct cpBody;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PhysWorld2D;
|
||||
|
||||
class NAZARA_PHYSICS2D_API RigidBody2D
|
||||
{
|
||||
public:
|
||||
RigidBody2D(PhysWorld2D* world, float mass);
|
||||
RigidBody2D(PhysWorld2D* world, float mass, Collider2DRef geom);
|
||||
RigidBody2D(const RigidBody2D& object);
|
||||
RigidBody2D(RigidBody2D&& object);
|
||||
~RigidBody2D();
|
||||
|
||||
void AddForce(const Vector2f& force, CoordSys coordSys = CoordSys_Global);
|
||||
void AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys = CoordSys_Global);
|
||||
void AddTorque(float torque);
|
||||
|
||||
Rectf GetAABB() const;
|
||||
float GetAngularVelocity() const;
|
||||
Vector2f GetCenterOfGravity(CoordSys coordSys = CoordSys_Local) const;
|
||||
const Collider2DRef& GetGeom() const;
|
||||
cpBody* GetHandle() const;
|
||||
float GetMass() const;
|
||||
Vector2f GetPosition() const;
|
||||
float GetRotation() const;
|
||||
Vector2f GetVelocity() const;
|
||||
|
||||
bool IsMoveable() const;
|
||||
bool IsSleeping() const;
|
||||
|
||||
void SetAngularVelocity(float angularVelocity);
|
||||
void SetMass(float mass);
|
||||
void SetMassCenter(const Vector2f& center);
|
||||
void SetPosition(const Vector2f& position);
|
||||
void SetRotation(float rotation);
|
||||
void SetVelocity(const Vector2f& velocity);
|
||||
|
||||
RigidBody2D& operator=(const RigidBody2D& object);
|
||||
RigidBody2D& operator=(RigidBody2D&& object);
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
void SetGeom(Collider2DRef geom);
|
||||
|
||||
std::vector<cpShape*> m_shapes;
|
||||
Collider2DRef m_geom;
|
||||
cpBody* m_handle;
|
||||
PhysWorld2D* m_world;
|
||||
float m_gravityFactor;
|
||||
float m_mass;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RIGIDBODY3D_HPP
|
||||
39
include/Nazara/Physics3D.hpp
Normal file
39
include/Nazara/Physics3D.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// This file was automatically generated on 14 Oct 2016 at 18:58:18
|
||||
|
||||
/*
|
||||
Nazara Engine - Physics 3D module
|
||||
|
||||
Copyright (C) 2015 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_GLOBAL_PHYSICS3D_HPP
|
||||
#define NAZARA_GLOBAL_PHYSICS3D_HPP
|
||||
|
||||
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
||||
#include <Nazara/Physics3D/Physics3D.hpp>
|
||||
#include <Nazara/Physics3D/RigidBody3D.hpp>
|
||||
#include <Nazara/Physics3D/Enums.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_PHYSICS3D_HPP
|
||||
273
include/Nazara/Physics3D/Collider3D.hpp
Normal file
273
include/Nazara/Physics3D/Collider3D.hpp
Normal file
@@ -0,0 +1,273 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_COLLIDER3D_HPP
|
||||
#define NAZARA_COLLIDER3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/PrimitiveList.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/SparsePtr.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Enums.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
class NewtonCollision;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
///TODO: CollisionModifier
|
||||
///TODO: HeightfieldGeom
|
||||
///TODO: PlaneGeom ?
|
||||
///TODO: SceneGeom
|
||||
///TODO: TreeGeom
|
||||
|
||||
class Collider3D;
|
||||
class PhysWorld3D;
|
||||
|
||||
using Collider3DConstRef = ObjectRef<const Collider3D>;
|
||||
using Collider3DLibrary = ObjectLibrary<Collider3D>;
|
||||
using Collider3DRef = ObjectRef<Collider3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API Collider3D : public RefCounted
|
||||
{
|
||||
friend Collider3DLibrary;
|
||||
friend class Physics3D;
|
||||
|
||||
public:
|
||||
Collider3D() = default;
|
||||
Collider3D(const Collider3D&) = delete;
|
||||
Collider3D(Collider3D&&) = delete;
|
||||
virtual ~Collider3D();
|
||||
|
||||
Boxf ComputeAABB(const Vector3f& translation, const Quaternionf& rotation, const Vector3f& scale) const;
|
||||
virtual Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const;
|
||||
virtual void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const;
|
||||
virtual float ComputeVolume() const;
|
||||
|
||||
NewtonCollision* GetHandle(PhysWorld3D* world) const;
|
||||
virtual ColliderType3D GetType() const = 0;
|
||||
|
||||
Collider3D& operator=(const Collider3D&) = delete;
|
||||
Collider3D& operator=(Collider3D&&) = delete;
|
||||
|
||||
static Collider3DRef Build(const PrimitiveList& list);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnColliderRelease, const Collider3D* /*collider*/);
|
||||
|
||||
protected:
|
||||
virtual NewtonCollision* CreateHandle(PhysWorld3D* world) const = 0;
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
mutable std::unordered_map<PhysWorld3D*, NewtonCollision*> m_handles;
|
||||
|
||||
static Collider3DLibrary::LibraryMap s_library;
|
||||
};
|
||||
|
||||
class BoxCollider3D;
|
||||
|
||||
using BoxCollider3DConstRef = ObjectRef<const BoxCollider3D>;
|
||||
using BoxCollider3DRef = ObjectRef<BoxCollider3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API BoxCollider3D : public Collider3D
|
||||
{
|
||||
public:
|
||||
BoxCollider3D(const Vector3f& lengths, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
BoxCollider3D(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
|
||||
float ComputeVolume() const override;
|
||||
|
||||
Vector3f GetLengths() const;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
template<typename... Args> static BoxCollider3DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
|
||||
|
||||
Matrix4f m_matrix;
|
||||
Vector3f m_lengths;
|
||||
};
|
||||
|
||||
class CapsuleCollider3D;
|
||||
|
||||
using CapsuleCollider3DConstRef = ObjectRef<const CapsuleCollider3D>;
|
||||
using CapsuleCollider3DRef = ObjectRef<CapsuleCollider3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API CapsuleCollider3D : public Collider3D
|
||||
{
|
||||
public:
|
||||
CapsuleCollider3D(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
CapsuleCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
template<typename... Args> static CapsuleCollider3DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
|
||||
|
||||
Matrix4f m_matrix;
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class CompoundCollider3D;
|
||||
|
||||
using CompoundCollider3DConstRef = ObjectRef<const CompoundCollider3D>;
|
||||
using CompoundCollider3DRef = ObjectRef<CompoundCollider3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API CompoundCollider3D : public Collider3D
|
||||
{
|
||||
public:
|
||||
CompoundCollider3D(Collider3D** geoms, std::size_t geomCount);
|
||||
|
||||
const std::vector<Collider3DRef>& GetGeoms() const;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
template<typename... Args> static CompoundCollider3DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
|
||||
|
||||
std::vector<Collider3DRef> m_geoms;
|
||||
};
|
||||
|
||||
class ConeCollider3D;
|
||||
|
||||
using ConeCollider3DConstRef = ObjectRef<const ConeCollider3D>;
|
||||
using ConeCollider3DRef = ObjectRef<ConeCollider3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API ConeCollider3D : public Collider3D
|
||||
{
|
||||
public:
|
||||
ConeCollider3D(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
ConeCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
template<typename... Args> static ConeCollider3DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
|
||||
|
||||
Matrix4f m_matrix;
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class ConvexCollider3D;
|
||||
|
||||
using ConvexCollider3DConstRef = ObjectRef<const ConvexCollider3D>;
|
||||
using ConvexCollider3DRef = ObjectRef<ConvexCollider3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API ConvexCollider3D : public Collider3D
|
||||
{
|
||||
public:
|
||||
ConvexCollider3D(SparsePtr<const Vector3f> vertices, unsigned int vertexCount, float tolerance = 0.002f, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
ConvexCollider3D(SparsePtr<const Vector3f> vertices, unsigned int vertexCount, float tolerance, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
template<typename... Args> static ConvexCollider3DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
|
||||
|
||||
std::vector<Vector3f> m_vertices;
|
||||
Matrix4f m_matrix;
|
||||
float m_tolerance;
|
||||
};
|
||||
|
||||
class CylinderCollider3D;
|
||||
|
||||
using CylinderCollider3DConstRef = ObjectRef<const CylinderCollider3D>;
|
||||
using CylinderCollider3DRef = ObjectRef<CylinderCollider3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API CylinderCollider3D : public Collider3D
|
||||
{
|
||||
public:
|
||||
CylinderCollider3D(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
CylinderCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
float GetLength() const;
|
||||
float GetRadius() const;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
template<typename... Args> static CylinderCollider3DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
|
||||
|
||||
Matrix4f m_matrix;
|
||||
float m_length;
|
||||
float m_radius;
|
||||
};
|
||||
|
||||
class NullCollider3D;
|
||||
|
||||
using NullCollider3DConstRef = ObjectRef<const NullCollider3D>;
|
||||
using NullCollider3DRef = ObjectRef<NullCollider3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API NullCollider3D : public Collider3D
|
||||
{
|
||||
public:
|
||||
NullCollider3D();
|
||||
|
||||
void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const override;
|
||||
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
template<typename... Args> static NullCollider3DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
|
||||
};
|
||||
|
||||
class SphereCollider3D;
|
||||
|
||||
using SphereCollider3DConstRef = ObjectRef<const SphereCollider3D>;
|
||||
using SphereCollider3DRef = ObjectRef<SphereCollider3D>;
|
||||
|
||||
class NAZARA_PHYSICS3D_API SphereCollider3D : public Collider3D
|
||||
{
|
||||
public:
|
||||
SphereCollider3D(float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
SphereCollider3D(float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
|
||||
float ComputeVolume() const override;
|
||||
|
||||
float GetRadius() const;
|
||||
ColliderType3D GetType() const override;
|
||||
|
||||
template<typename... Args> static SphereCollider3DRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
|
||||
|
||||
Vector3f m_position;
|
||||
float m_radius;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/Collider3D.inl>
|
||||
|
||||
#endif // NAZARA_COLLIDER3D_HPP
|
||||
83
include/Nazara/Physics3D/Collider3D.inl
Normal file
83
include/Nazara/Physics3D/Collider3D.inl
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename... Args>
|
||||
BoxCollider3DRef BoxCollider3D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<BoxCollider3D> object(new BoxCollider3D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
CapsuleCollider3DRef CapsuleCollider3D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<CapsuleCollider3D> object(new CapsuleCollider3D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
CompoundCollider3DRef CompoundCollider3D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<CompoundCollider3D> object(new CompoundCollider3D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
ConeCollider3DRef ConeCollider3D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<ConeCollider3D> object(new ConeCollider3D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
ConvexCollider3DRef ConvexCollider3D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<ConvexCollider3D> object(new ConvexCollider3D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
CylinderCollider3DRef CylinderCollider3D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<CylinderCollider3D> object(new CylinderCollider3D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
NullCollider3DRef NullCollider3D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<NullCollider3D> object(new NullCollider3D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
SphereCollider3DRef SphereCollider3D::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<SphereCollider3D> object(new SphereCollider3D(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Physics3D/DebugOff.hpp>
|
||||
51
include/Nazara/Physics3D/Config.hpp
Normal file
51
include/Nazara/Physics3D/Config.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Nazara Engine - Physics 3D module
|
||||
|
||||
Copyright (C) 2015 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_CONFIG_PHYSICS3D_HPP
|
||||
#define NAZARA_CONFIG_PHYSICS3D_HPP
|
||||
|
||||
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
|
||||
|
||||
// Utilise un manager de mémoire pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
|
||||
#define NAZARA_PHYSICS3D_MANAGE_MEMORY 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_PHYSICS3D_SAFE 1
|
||||
|
||||
/// Vérification des valeurs et types de certaines constantes
|
||||
#include <Nazara/Physics3D/ConfigCheck.hpp>
|
||||
|
||||
#if defined(NAZARA_STATIC)
|
||||
#define NAZARA_PHYSICS3D_API
|
||||
#else
|
||||
#ifdef NAZARA_PHYSICS3D_BUILD
|
||||
#define NAZARA_PHYSICS3D_API NAZARA_EXPORT
|
||||
#else
|
||||
#define NAZARA_PHYSICS3D_API NAZARA_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CONFIG_PHYSICS3D_HPP
|
||||
18
include/Nazara/Physics3D/ConfigCheck.hpp
Normal file
18
include/Nazara/Physics3D/ConfigCheck.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CONFIG_CHECK_PHYSICS_HPP
|
||||
#define NAZARA_CONFIG_CHECK_PHYSICS_HPP
|
||||
|
||||
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
|
||||
|
||||
// On force la valeur de MANAGE_MEMORY en mode debug
|
||||
#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS_MANAGE_MEMORY
|
||||
#undef NAZARA_PHYSICS_MANAGE_MEMORY
|
||||
#define NAZARA_PHYSICS3D_MANAGE_MEMORY 0
|
||||
#endif
|
||||
|
||||
#endif // NAZARA_CONFIG_CHECK_PHYSICS_HPP
|
||||
8
include/Nazara/Physics3D/Debug.hpp
Normal file
8
include/Nazara/Physics3D/Debug.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#if NAZARA_PHYSICS_MANAGE_MEMORY
|
||||
#include <Nazara/Core/Debug/NewRedefinition.hpp>
|
||||
#endif
|
||||
9
include/Nazara/Physics3D/DebugOff.hpp
Normal file
9
include/Nazara/Physics3D/DebugOff.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
|
||||
#if NAZARA_PHYSICS_MANAGE_MEMORY
|
||||
#undef delete
|
||||
#undef new
|
||||
#endif
|
||||
30
include/Nazara/Physics3D/Enums.hpp
Normal file
30
include/Nazara/Physics3D/Enums.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics 3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_ENUMS_PHYSICS3D_HPP
|
||||
#define NAZARA_ENUMS_PHYSICS3D_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum ColliderType3D
|
||||
{
|
||||
ColliderType3D_Box,
|
||||
ColliderType3D_Capsule,
|
||||
ColliderType3D_Cone,
|
||||
ColliderType3D_Compound,
|
||||
ColliderType3D_ConvexHull,
|
||||
ColliderType3D_Cylinder,
|
||||
ColliderType3D_Heightfield,
|
||||
ColliderType3D_Null,
|
||||
ColliderType3D_Scene,
|
||||
ColliderType3D_Sphere,
|
||||
ColliderType3D_Tree,
|
||||
|
||||
ColliderType3D_Max = ColliderType3D_Tree
|
||||
};
|
||||
};
|
||||
|
||||
#endif // NAZARA_ENUMS_PHYSICS3D_HPP
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics module"
|
||||
// This file is part of the "Nazara Engine - Physics 3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
@@ -10,19 +10,19 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
|
||||
class NewtonWorld;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS_API PhysWorld
|
||||
class NAZARA_PHYSICS3D_API PhysWorld3D
|
||||
{
|
||||
public:
|
||||
PhysWorld();
|
||||
PhysWorld(const PhysWorld&) = delete;
|
||||
PhysWorld(PhysWorld&&) = delete; ///TODO
|
||||
~PhysWorld();
|
||||
PhysWorld3D();
|
||||
PhysWorld3D(const PhysWorld3D&) = delete;
|
||||
PhysWorld3D(PhysWorld3D&&) = delete; ///TODO
|
||||
~PhysWorld3D();
|
||||
|
||||
Vector3f GetGravity() const;
|
||||
NewtonWorld* GetHandle() const;
|
||||
@@ -34,8 +34,8 @@ namespace Nz
|
||||
|
||||
void Step(float timestep);
|
||||
|
||||
PhysWorld& operator=(const PhysWorld&) = delete;
|
||||
PhysWorld& operator=(PhysWorld&&) = delete; ///TODO
|
||||
PhysWorld3D& operator=(const PhysWorld3D&) = delete;
|
||||
PhysWorld3D& operator=(PhysWorld3D&&) = delete; ///TODO
|
||||
|
||||
private:
|
||||
Vector3f m_gravity;
|
||||
@@ -1,23 +1,23 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics module"
|
||||
// This file is part of the "Nazara Engine - Physics 3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSICS_HPP
|
||||
#define NAZARA_PHYSICS_HPP
|
||||
#ifndef NAZARA_PHYSICS3D_HPP
|
||||
#define NAZARA_PHYSICS3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_PHYSICS_API Physics
|
||||
class NAZARA_PHYSICS3D_API Physics3D
|
||||
{
|
||||
public:
|
||||
Physics() = delete;
|
||||
~Physics() = delete;
|
||||
Physics3D() = delete;
|
||||
~Physics3D() = delete;
|
||||
|
||||
static unsigned int GetMemoryUsed();
|
||||
|
||||
@@ -32,4 +32,4 @@ namespace Nz
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PHYSICS_HPP
|
||||
#endif // NAZARA_PHYSICS3D_HPP
|
||||
@@ -1,34 +1,34 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Physics module"
|
||||
// This file is part of the "Nazara Engine - Physics 3D module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_PHYSOBJECT_HPP
|
||||
#define NAZARA_PHYSOBJECT_HPP
|
||||
#ifndef NAZARA_RIGIDBODY3D_HPP
|
||||
#define NAZARA_RIGIDBODY3D_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics/Config.hpp>
|
||||
#include <Nazara/Physics/Geom.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <Nazara/Physics3D/Collider3D.hpp>
|
||||
|
||||
class NewtonBody;
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class PhysWorld;
|
||||
class PhysWorld3D;
|
||||
|
||||
class NAZARA_PHYSICS_API PhysObject
|
||||
class NAZARA_PHYSICS3D_API RigidBody3D
|
||||
{
|
||||
public:
|
||||
PhysObject(PhysWorld* world, const Matrix4f& mat = Matrix4f::Identity());
|
||||
PhysObject(PhysWorld* world, PhysGeomRef geom, const Matrix4f& mat = Matrix4f::Identity());
|
||||
PhysObject(const PhysObject& object);
|
||||
PhysObject(PhysObject&& object);
|
||||
~PhysObject();
|
||||
RigidBody3D(PhysWorld3D* world, const Matrix4f& mat = Matrix4f::Identity());
|
||||
RigidBody3D(PhysWorld3D* world, Collider3DRef geom, const Matrix4f& mat = Matrix4f::Identity());
|
||||
RigidBody3D(const RigidBody3D& object);
|
||||
RigidBody3D(RigidBody3D&& object);
|
||||
~RigidBody3D();
|
||||
|
||||
void AddForce(const Vector3f& force, CoordSys coordSys = CoordSys_Global);
|
||||
void AddForce(const Vector3f& force, const Vector3f& point, CoordSys coordSys = CoordSys_Global);
|
||||
@@ -38,7 +38,7 @@ namespace Nz
|
||||
|
||||
Boxf GetAABB() const;
|
||||
Vector3f GetAngularVelocity() const;
|
||||
const PhysGeomRef& GetGeom() const;
|
||||
const Collider3DRef& GetGeom() const;
|
||||
float GetGravityFactor() const;
|
||||
NewtonBody* GetHandle() const;
|
||||
float GetMass() const;
|
||||
@@ -53,7 +53,7 @@ namespace Nz
|
||||
bool IsSleeping() const;
|
||||
|
||||
void SetAngularVelocity(const Vector3f& angularVelocity);
|
||||
void SetGeom(PhysGeomRef geom);
|
||||
void SetGeom(Collider3DRef geom);
|
||||
void SetGravityFactor(float gravityFactor);
|
||||
void SetMass(float mass);
|
||||
void SetMassCenter(const Vector3f& center);
|
||||
@@ -61,23 +61,23 @@ namespace Nz
|
||||
void SetRotation(const Quaternionf& rotation);
|
||||
void SetVelocity(const Vector3f& velocity);
|
||||
|
||||
PhysObject& operator=(const PhysObject& object);
|
||||
PhysObject& operator=(PhysObject&& object);
|
||||
RigidBody3D& operator=(const RigidBody3D& object);
|
||||
RigidBody3D& operator=(RigidBody3D&& object);
|
||||
|
||||
private:
|
||||
void UpdateBody();
|
||||
static void ForceAndTorqueCallback(const NewtonBody* body, float timeStep, int threadIndex);
|
||||
static void TransformCallback(const NewtonBody* body, const float* matrix, int threadIndex);
|
||||
|
||||
Collider3DRef m_geom;
|
||||
Matrix4f m_matrix;
|
||||
PhysGeomRef m_geom;
|
||||
Vector3f m_forceAccumulator;
|
||||
Vector3f m_torqueAccumulator;
|
||||
NewtonBody* m_body;
|
||||
PhysWorld* m_world;
|
||||
PhysWorld3D* m_world;
|
||||
float m_gravityFactor;
|
||||
float m_mass;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_PHYSOBJECT_HPP
|
||||
#endif // NAZARA_RIGIDBODY3D_HPP
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
@@ -31,7 +30,7 @@ namespace Nz
|
||||
|
||||
struct TextureImpl;
|
||||
|
||||
class NAZARA_RENDERER_API Texture : public AbstractImage, public RefCounted, public Resource
|
||||
class NAZARA_RENDERER_API Texture : public AbstractImage, public Resource
|
||||
{
|
||||
friend TextureLibrary;
|
||||
friend TextureManager;
|
||||
@@ -54,16 +53,16 @@ namespace Nz
|
||||
|
||||
void EnsureMipmapsUpdate() const;
|
||||
|
||||
unsigned int GetDepth(UInt8 level = 0) const;
|
||||
PixelFormatType GetFormat() const;
|
||||
unsigned int GetHeight(UInt8 level = 0) const;
|
||||
UInt8 GetLevelCount() const;
|
||||
UInt8 GetMaxLevel() const;
|
||||
std::size_t GetMemoryUsage() const;
|
||||
std::size_t GetMemoryUsage(UInt8 level) const;
|
||||
Vector3ui GetSize(UInt8 level = 0) const;
|
||||
ImageType GetType() const;
|
||||
unsigned int GetWidth(UInt8 level = 0) const;
|
||||
unsigned int GetDepth(UInt8 level = 0) const override;
|
||||
PixelFormatType GetFormat() const override;
|
||||
unsigned int GetHeight(UInt8 level = 0) const override;
|
||||
UInt8 GetLevelCount() const override;
|
||||
UInt8 GetMaxLevel() const override;
|
||||
std::size_t GetMemoryUsage() const override;
|
||||
std::size_t GetMemoryUsage(UInt8 level) const override;
|
||||
Vector3ui GetSize(UInt8 level = 0) const override;
|
||||
ImageType GetType() const override;
|
||||
unsigned int GetWidth(UInt8 level = 0) const override;
|
||||
|
||||
bool HasMipmaps() const;
|
||||
|
||||
@@ -102,9 +101,9 @@ namespace Nz
|
||||
bool Update(const Image& image, UInt8 level = 0);
|
||||
bool Update(const Image& image, const Boxui& box, UInt8 level = 0);
|
||||
bool Update(const Image& image, const Rectui& rect, unsigned int z = 0, UInt8 level = 0);
|
||||
bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||
bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||
bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||
|
||||
// Fonctions OpenGL
|
||||
unsigned int GetOpenGLID() const;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_ABSTRACTIMAGE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
@@ -16,10 +17,16 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_UTILITY_API AbstractImage
|
||||
class AbstractImage;
|
||||
|
||||
using AbstractImageConstRef = ObjectRef<const AbstractImage>;
|
||||
using AbstractImageRef = ObjectRef<AbstractImage>;
|
||||
|
||||
class NAZARA_UTILITY_API AbstractImage : public RefCounted
|
||||
{
|
||||
public:
|
||||
AbstractImage() = default;
|
||||
inline AbstractImage(const AbstractImage& image);
|
||||
virtual ~AbstractImage();
|
||||
|
||||
UInt8 GetBytesPerPixel() const;
|
||||
@@ -43,4 +50,6 @@ namespace Nz
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/AbstractImage.inl>
|
||||
|
||||
#endif // NAZARA_IMAGE_HPP
|
||||
|
||||
16
include/Nazara/Utility/AbstractImage.inl
Normal file
16
include/Nazara/Utility/AbstractImage.inl
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/AbstractImage.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline AbstractImage::AbstractImage(const AbstractImage&) :
|
||||
RefCounted()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
@@ -71,7 +71,6 @@ namespace Nz
|
||||
mutable StringStream m_outputStream;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_lineCount;
|
||||
unsigned int m_streamFlags;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
@@ -47,7 +46,7 @@ namespace Nz
|
||||
using ImageRef = ObjectRef<Image>;
|
||||
using ImageSaver = ResourceSaver<Image, ImageParams>;
|
||||
|
||||
class NAZARA_UTILITY_API Image : public AbstractImage, public RefCounted, public Resource
|
||||
class NAZARA_UTILITY_API Image : public AbstractImage, public Resource
|
||||
{
|
||||
friend ImageLibrary;
|
||||
friend ImageLoader;
|
||||
|
||||
@@ -111,8 +111,8 @@ namespace Nz
|
||||
if (content <= PixelFormatContent_Undefined || content > PixelFormatContent_Max)
|
||||
return false;
|
||||
|
||||
std::array<const Nz::Bitset<>*, 4> masks = {&redMask, &greenMask, &blueMask, &alphaMask};
|
||||
std::array<PixelFormatSubType, 4> types = {redType, greenType, blueType, alphaType};
|
||||
std::array<const Nz::Bitset<>*, 4> masks = { {&redMask, &greenMask, &blueMask, &alphaMask} };
|
||||
std::array<PixelFormatSubType, 4> types = { {redType, greenType, blueType, alphaType} };
|
||||
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user