Merge branch 'master' into physics3d-material
This commit is contained in:
commit
76043e4f2e
|
|
@ -60,6 +60,18 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
m_dynamicObjects.Remove(entity);
|
m_dynamicObjects.Remove(entity);
|
||||||
m_staticObjects.Insert(entity);
|
m_staticObjects.Insert(entity);
|
||||||
|
|
||||||
|
// If entities just got added to the system, teleport them to their NodeComponent position/rotation
|
||||||
|
// This will prevent the physics engine to mess with the scene while correcting position/rotation
|
||||||
|
if (justAdded)
|
||||||
|
{
|
||||||
|
auto& collision = entity->GetComponent<CollisionComponent3D>();
|
||||||
|
auto& node = entity->GetComponent<NodeComponent>();
|
||||||
|
|
||||||
|
Nz::RigidBody3D* physObj = collision.GetStaticBody();
|
||||||
|
physObj->SetPosition(node.GetPosition());
|
||||||
|
physObj->SetRotation(node.GetRotation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_world)
|
if (!m_world)
|
||||||
|
|
|
||||||
|
|
@ -69,15 +69,15 @@ namespace Nz
|
||||||
template<typename U, bool HasDestructor>
|
template<typename U, bool HasDestructor>
|
||||||
friend struct LuaClassImplFinalizerSetupProxy;
|
friend struct LuaClassImplFinalizerSetupProxy;
|
||||||
|
|
||||||
void PushClassInfo(LuaState& state);
|
int PushClassInfo(LuaState& state);
|
||||||
void SetupConstructor(LuaState& state);
|
void SetupConstructor(LuaState& state, int classInfoRef);
|
||||||
void SetupDefaultToString(LuaState& state);
|
void SetupDefaultToString(LuaState& state, int classInfoRef);
|
||||||
void SetupFinalizer(LuaState& state);
|
void SetupFinalizer(LuaState& state, int classInfoRef);
|
||||||
void SetupGetter(LuaState& state, LuaCFunction proxy);
|
void SetupGetter(LuaState& state, LuaCFunction proxy, int classInfoRef);
|
||||||
void SetupGlobalTable(LuaState& state);
|
void SetupGlobalTable(LuaState& state, int classInfoRef);
|
||||||
void SetupMetatable(LuaState& state);
|
void SetupMetatable(LuaState& state, int classInfoRef);
|
||||||
void SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex);
|
void SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex, int classInfoRef);
|
||||||
void SetupSetter(LuaState& state, LuaCFunction proxy);
|
void SetupSetter(LuaState& state, LuaCFunction proxy, int classInfoRef);
|
||||||
|
|
||||||
using ParentFunc = std::function<void(LuaState& state, T* instance)>;
|
using ParentFunc = std::function<void(LuaState& state, T* instance)>;
|
||||||
using InstanceGetter = std::function<T*(LuaState& state)>;
|
using InstanceGetter = std::function<T*(LuaState& state)>;
|
||||||
|
|
|
||||||
|
|
@ -80,15 +80,15 @@ namespace Nz
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::Register(LuaState& state)
|
void LuaClass<T>::Register(LuaState& state)
|
||||||
{
|
{
|
||||||
PushClassInfo(state);
|
int classInfoRef = PushClassInfo(state);
|
||||||
|
|
||||||
// Let's create the metatable which will be associated with every state.
|
// Let's create the metatable which will be associated with every state.
|
||||||
SetupMetatable(state);
|
SetupMetatable(state, classInfoRef);
|
||||||
|
|
||||||
if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_staticMethods.empty())
|
if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_staticMethods.empty())
|
||||||
SetupGlobalTable(state);
|
SetupGlobalTable(state, classInfoRef);
|
||||||
|
|
||||||
state.Pop(); // Pop our ClassInfo, which is now referenced by all our functions
|
state.DestroyReference(classInfoRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
@ -216,7 +216,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::PushClassInfo(LuaState& state)
|
int LuaClass<T>::PushClassInfo(LuaState& state)
|
||||||
{
|
{
|
||||||
// Our ClassInfo has to outlive the LuaClass, because we don't want to force the user to keep the LuaClass alive
|
// 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.
|
// To do that, each Registration creates a tiny shared_ptr wrapper whose life is directly managed by Lua.
|
||||||
|
|
@ -231,20 +231,22 @@ namespace Nz
|
||||||
state.PushCFunction(InfoDestructor, 1);
|
state.PushCFunction(InfoDestructor, 1);
|
||||||
state.SetField("__gc");
|
state.SetField("__gc");
|
||||||
state.SetMetatable(-2);
|
state.SetMetatable(-2);
|
||||||
|
|
||||||
|
return state.CreateReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetupConstructor(LuaState& state)
|
void LuaClass<T>::SetupConstructor(LuaState& state, int classInfoRef)
|
||||||
{
|
{
|
||||||
state.PushValue(1); // ClassInfo
|
state.PushReference(classInfoRef);
|
||||||
state.PushCFunction(ConstructorProxy, 1);
|
state.PushCFunction(ConstructorProxy, 1);
|
||||||
state.SetField("__call"); // ClassMeta.__call = ConstructorProxy
|
state.SetField("__call"); // ClassMeta.__call = ConstructorProxy
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetupDefaultToString(LuaState& state)
|
void LuaClass<T>::SetupDefaultToString(LuaState& state, int classInfoRef)
|
||||||
{
|
{
|
||||||
state.PushValue(1); // shared_ptr on UserData
|
state.PushReference(classInfoRef);
|
||||||
state.PushCFunction(ToStringProxy, 1);
|
state.PushCFunction(ToStringProxy, 1);
|
||||||
state.SetField("__tostring");
|
state.SetField("__tostring");
|
||||||
}
|
}
|
||||||
|
|
@ -255,9 +257,9 @@ namespace Nz
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct LuaClassImplFinalizerSetupProxy<T, true>
|
struct LuaClassImplFinalizerSetupProxy<T, true>
|
||||||
{
|
{
|
||||||
static void Setup(LuaState& state)
|
static void Setup(LuaState& state, int classInfoRef)
|
||||||
{
|
{
|
||||||
state.PushValue(1); // ClassInfo
|
state.PushReference(classInfoRef);
|
||||||
state.PushCFunction(LuaClass<T>::FinalizerProxy, 1);
|
state.PushCFunction(LuaClass<T>::FinalizerProxy, 1);
|
||||||
state.SetField("__gc");
|
state.SetField("__gc");
|
||||||
}
|
}
|
||||||
|
|
@ -266,21 +268,21 @@ namespace Nz
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct LuaClassImplFinalizerSetupProxy<T, false>
|
struct LuaClassImplFinalizerSetupProxy<T, false>
|
||||||
{
|
{
|
||||||
static void Setup(LuaState&)
|
static void Setup(LuaState&, int)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetupFinalizer(LuaState& state)
|
void LuaClass<T>::SetupFinalizer(LuaState& state, int classInfoRef)
|
||||||
{
|
{
|
||||||
LuaClassImplFinalizerSetupProxy<T, std::is_destructible<T>::value>::Setup(state);
|
LuaClassImplFinalizerSetupProxy<T, std::is_destructible<T>::value>::Setup(state, classInfoRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetupGetter(LuaState& state, LuaCFunction proxy)
|
void LuaClass<T>::SetupGetter(LuaState& state, LuaCFunction proxy, int classInfoRef)
|
||||||
{
|
{
|
||||||
state.PushValue(1); // ClassInfo
|
state.PushReference(classInfoRef);
|
||||||
state.PushValue(-2); // Metatable
|
state.PushValue(-2); // Metatable
|
||||||
state.PushCFunction(proxy, 2);
|
state.PushCFunction(proxy, 2);
|
||||||
|
|
||||||
|
|
@ -288,7 +290,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetupGlobalTable(LuaState& state)
|
void LuaClass<T>::SetupGlobalTable(LuaState& state, int classInfoRef)
|
||||||
{
|
{
|
||||||
// Create the global table
|
// Create the global table
|
||||||
state.PushTable(); // Class = {}
|
state.PushTable(); // Class = {}
|
||||||
|
|
@ -297,10 +299,10 @@ namespace Nz
|
||||||
state.PushTable(); // ClassMeta = {}
|
state.PushTable(); // ClassMeta = {}
|
||||||
|
|
||||||
if (m_info->constructor)
|
if (m_info->constructor)
|
||||||
SetupConstructor(state);
|
SetupConstructor(state, classInfoRef);
|
||||||
|
|
||||||
if (m_info->staticGetter)
|
if (m_info->staticGetter)
|
||||||
SetupGetter(state, StaticGetterProxy);
|
SetupGetter(state, StaticGetterProxy, classInfoRef);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Optimize by assigning the metatable instead of a search function
|
// Optimize by assigning the metatable instead of a search function
|
||||||
|
|
@ -309,7 +311,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_info->staticSetter)
|
if (m_info->staticSetter)
|
||||||
SetupSetter(state, StaticSetterProxy);
|
SetupSetter(state, StaticSetterProxy, classInfoRef);
|
||||||
|
|
||||||
m_info->staticMethods.reserve(m_staticMethods.size());
|
m_info->staticMethods.reserve(m_staticMethods.size());
|
||||||
for (auto& pair : m_staticMethods)
|
for (auto& pair : m_staticMethods)
|
||||||
|
|
@ -317,7 +319,7 @@ namespace Nz
|
||||||
std::size_t methodIndex = m_info->staticMethods.size();
|
std::size_t methodIndex = m_info->staticMethods.size();
|
||||||
m_info->staticMethods.push_back(pair.second);
|
m_info->staticMethods.push_back(pair.second);
|
||||||
|
|
||||||
SetupMethod(state, StaticMethodProxy, pair.first, methodIndex);
|
SetupMethod(state, StaticMethodProxy, pair.first, methodIndex, classInfoRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.SetMetatable(-2); // setmetatable(Class, ClassMeta), pops ClassMeta
|
state.SetMetatable(-2); // setmetatable(Class, ClassMeta), pops ClassMeta
|
||||||
|
|
@ -329,15 +331,15 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetupMetatable(LuaState& state)
|
void LuaClass<T>::SetupMetatable(LuaState& state, int classInfoRef)
|
||||||
{
|
{
|
||||||
if (!state.NewMetatable(m_info->name))
|
if (!state.NewMetatable(m_info->name))
|
||||||
NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance");
|
NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance");
|
||||||
{
|
{
|
||||||
SetupFinalizer(state);
|
SetupFinalizer(state, classInfoRef);
|
||||||
|
|
||||||
if (m_info->getter || !m_info->parentGetters.empty())
|
if (m_info->getter || !m_info->parentGetters.empty())
|
||||||
SetupGetter(state, GetterProxy);
|
SetupGetter(state, GetterProxy, classInfoRef);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Optimize by assigning the metatable instead of a search function
|
// Optimize by assigning the metatable instead of a search function
|
||||||
|
|
@ -347,11 +349,11 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_info->setter)
|
if (m_info->setter)
|
||||||
SetupSetter(state, SetterProxy);
|
SetupSetter(state, SetterProxy, classInfoRef);
|
||||||
|
|
||||||
// In case a __tostring method is missing, add a default implementation returning the class name
|
// In case a __tostring method is missing, add a default implementation returning the class name
|
||||||
if (m_methods.find("__tostring") == m_methods.end())
|
if (m_methods.find("__tostring") == m_methods.end())
|
||||||
SetupDefaultToString(state);
|
SetupDefaultToString(state, classInfoRef);
|
||||||
|
|
||||||
m_info->methods.reserve(m_methods.size());
|
m_info->methods.reserve(m_methods.size());
|
||||||
for (auto& pair : m_methods)
|
for (auto& pair : m_methods)
|
||||||
|
|
@ -359,16 +361,16 @@ namespace Nz
|
||||||
std::size_t methodIndex = m_info->methods.size();
|
std::size_t methodIndex = m_info->methods.size();
|
||||||
m_info->methods.push_back(pair.second);
|
m_info->methods.push_back(pair.second);
|
||||||
|
|
||||||
SetupMethod(state, MethodProxy, pair.first, methodIndex);
|
SetupMethod(state, MethodProxy, pair.first, methodIndex, classInfoRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.Pop(); //< Pops the metatable, it won't be collected before it's referenced by the Lua registry.
|
state.Pop(); //< Pops the metatable, it won't be collected before it's referenced by the Lua registry.
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex)
|
void LuaClass<T>::SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex, int classInfoRef)
|
||||||
{
|
{
|
||||||
state.PushValue(1); // ClassInfo
|
state.PushReference(classInfoRef);
|
||||||
state.PushInteger(methodIndex);
|
state.PushInteger(methodIndex);
|
||||||
state.PushCFunction(proxy, 2);
|
state.PushCFunction(proxy, 2);
|
||||||
|
|
||||||
|
|
@ -376,9 +378,9 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void LuaClass<T>::SetupSetter(LuaState& state, LuaCFunction proxy)
|
void LuaClass<T>::SetupSetter(LuaState& state, LuaCFunction proxy, int classInfoRef)
|
||||||
{
|
{
|
||||||
state.PushValue(1); // ClassInfo
|
state.PushReference(classInfoRef);
|
||||||
state.PushCFunction(proxy, 1);
|
state.PushCFunction(proxy, 1);
|
||||||
|
|
||||||
state.SetField("__newindex"); // Setter
|
state.SetField("__newindex"); // Setter
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue