Sdk: Add binding of SDK
Former-commit-id: 4bad2b5db52a2fe459ad7802eb4a894fe3bf006e
This commit is contained in:
parent
809c340edc
commit
1ecc52c718
|
|
@ -28,6 +28,7 @@ namespace Ndk
|
||||||
static void Register_Math(Nz::LuaInstance& instance);
|
static void Register_Math(Nz::LuaInstance& instance);
|
||||||
static void Register_Network(Nz::LuaInstance& instance);
|
static void Register_Network(Nz::LuaInstance& instance);
|
||||||
static void Register_Renderer(Nz::LuaInstance& instance);
|
static void Register_Renderer(Nz::LuaInstance& instance);
|
||||||
|
static void Register_SDK(Nz::LuaInstance& instance);
|
||||||
static void Register_Utility(Nz::LuaInstance& instance);
|
static void Register_Utility(Nz::LuaInstance& instance);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,222 @@
|
||||||
// This file is part of the "Nazara Development Kit"
|
// This file is part of the "Nazara Development Kit"
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
#include <Nazara/Audio/SoundBuffer.hpp>
|
|
||||||
#include <Nazara/Lua/LuaInstance.hpp>
|
#include <Nazara/Lua/LuaInstance.hpp>
|
||||||
|
#include <Nazara/Math/EulerAngles.hpp>
|
||||||
|
#include <Nazara/Math/Quaternion.hpp>
|
||||||
#include <Nazara/Math/Vector3.hpp>
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/Entity.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
#include <Nazara/Audio/SoundBuffer.hpp>
|
||||||
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesd* angles, TypeTag<EulerAnglesd>)
|
||||||
|
{
|
||||||
|
switch (instance.GetType(index))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Table:
|
||||||
|
angles->Set(instance.CheckField<double>("pitch", index), instance.CheckField<double>("yaw", index), instance.CheckField<double>("roll", index));
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (instance.IsOfType(index, "EulerAngles"))
|
||||||
|
angles->Set(*(*static_cast<EulerAnglesd**>(instance.ToUserdata(index))));
|
||||||
|
else
|
||||||
|
angles->Set(*(*static_cast<Quaterniond**>(instance.CheckUserdata(index, "Quaternion"))));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesf* angles, TypeTag<EulerAnglesf>)
|
||||||
|
{
|
||||||
|
EulerAnglesd anglesDouble;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &anglesDouble, TypeTag<EulerAnglesd>());
|
||||||
|
|
||||||
|
angles->Set(anglesDouble);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
|
||||||
|
{
|
||||||
|
switch (instance.GetType(index))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Table:
|
||||||
|
quat->Set(instance.CheckField<double>("w", index), instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", index));
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (instance.IsOfType(index, "EulerAngles"))
|
||||||
|
quat->Set(*(*static_cast<EulerAnglesd**>(instance.ToUserdata(index))));
|
||||||
|
else
|
||||||
|
quat->Set(*(*static_cast<Quaterniond**>(instance.CheckUserdata(index, "Quaternion"))));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag<Quaternionf>)
|
||||||
|
{
|
||||||
|
Quaterniond quatDouble;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag<Quaterniond>());
|
||||||
|
|
||||||
|
quat->Set(quatDouble);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag<IpAddress>)
|
||||||
|
{
|
||||||
|
switch (instance.GetType(index))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
address->BuildFromAddress(instance.CheckString(index));
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
*address = *(*static_cast<IpAddress**>(instance.CheckUserdata(index, "IpAddress")));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2d* vec, TypeTag<Vector2d>)
|
||||||
|
{
|
||||||
|
switch (instance.GetType(index))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
if (index < 0 && index > -2)
|
||||||
|
instance.Error("Vector2 expected, two numbers are required to convert it");
|
||||||
|
|
||||||
|
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1));
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
case Nz::LuaType_Table:
|
||||||
|
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index));
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
vec->Set(*(*static_cast<Vector2d**>(instance.CheckUserdata(index, "Vector2"))));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2f* vec, TypeTag<Vector2f>)
|
||||||
|
{
|
||||||
|
Vector2d vecDouble;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
|
||||||
|
|
||||||
|
vec->Set(vecDouble);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2ui* vec, TypeTag<Vector2ui>)
|
||||||
|
{
|
||||||
|
Vector2d vecDouble;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
|
||||||
|
|
||||||
|
vec->Set(vecDouble);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3d* vec, TypeTag<Vector3d>)
|
||||||
|
{
|
||||||
|
switch (instance.GetType(index))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
if (index < 0 && index > -3)
|
||||||
|
instance.Error("Vector3 expected, three numbers are required to convert it");
|
||||||
|
|
||||||
|
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1), instance.CheckNumber(index + 2));
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
case Nz::LuaType_Table:
|
||||||
|
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", index));
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
vec->Set(*(*static_cast<Vector3d**>(instance.CheckUserdata(index, "Vector3"))));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3f* vec, TypeTag<Vector3f>)
|
||||||
|
{
|
||||||
|
Vector3d vecDouble;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
|
||||||
|
|
||||||
|
vec->Set(vecDouble);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3ui* vec, TypeTag<Vector3ui>)
|
||||||
|
{
|
||||||
|
Vector3d vecDouble;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
|
||||||
|
|
||||||
|
vec->Set(vecDouble);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, InstancedRenderableRef* renderable, TypeTag<InstancedRenderableRef>)
|
||||||
|
{
|
||||||
|
if (instance.IsOfType(index, "InstancedRenderable"))
|
||||||
|
*renderable = *(*static_cast<InstancedRenderableRef**>(instance.CheckUserdata(index, "InstancedRenderable")));
|
||||||
|
else
|
||||||
|
*renderable = *(*static_cast<InstancedRenderableRef**>(instance.CheckUserdata(index, "Model")));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MaterialParams* params, TypeTag<MaterialParams>)
|
||||||
|
{
|
||||||
|
instance.CheckType(index, Nz::LuaType_Table);
|
||||||
|
|
||||||
|
params->loadAlphaMap = instance.CheckField<bool>("LoadAlphaMap", params->loadAlphaMap);
|
||||||
|
params->loadDiffuseMap = instance.CheckField<bool>("LoadDiffuseMap", params->loadDiffuseMap);
|
||||||
|
params->loadEmissiveMap = instance.CheckField<bool>("LoadEmissiveMap", params->loadEmissiveMap);
|
||||||
|
params->loadHeightMap = instance.CheckField<bool>("LoadHeightMap", params->loadHeightMap);
|
||||||
|
params->loadNormalMap = instance.CheckField<bool>("LoadNormalMap", params->loadNormalMap);
|
||||||
|
params->loadSpecularMap = instance.CheckField<bool>("LoadSpecularMap", params->loadSpecularMap);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MeshParams* params, TypeTag<MeshParams>)
|
||||||
|
{
|
||||||
|
instance.CheckType(index, Nz::LuaType_Table);
|
||||||
|
|
||||||
|
params->animated = instance.CheckField<bool>("Animated", params->animated);
|
||||||
|
params->center = instance.CheckField<bool>("Center", params->center);
|
||||||
|
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
|
||||||
|
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
|
||||||
|
params->scale = instance.CheckField<Vector3f>("Scale", params->scale);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, ModelParameters* params, TypeTag<ModelParameters>)
|
||||||
|
{
|
||||||
|
instance.CheckType(index, Nz::LuaType_Table);
|
||||||
|
|
||||||
|
params->loadMaterials = instance.CheckField<bool>("LoadMaterials", params->loadMaterials);
|
||||||
|
|
||||||
|
LuaImplQueryArg(instance, -1, ¶ms->material, TypeTag<MaterialParams>());
|
||||||
|
LuaImplQueryArg(instance, -1, ¶ms->mesh, TypeTag<MeshParams>());
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SoundBufferParams* params, TypeTag<SoundBufferParams>)
|
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SoundBufferParams* params, TypeTag<SoundBufferParams>)
|
||||||
{
|
{
|
||||||
instance.CheckType(index, Nz::LuaType_Table);
|
instance.CheckType(index, Nz::LuaType_Table);
|
||||||
|
|
@ -17,50 +226,31 @@ namespace Nz
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
inline unsigned int LuaImplQueryArg(const LuaInstance& lua, int index, Vector3d* vec, TypeTag<Vector3d>)
|
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesd val, TypeTag<EulerAnglesd>)
|
||||||
{
|
{
|
||||||
switch (lua.GetType(index))
|
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
|
||||||
{
|
return 1;
|
||||||
case Nz::LuaType_Number:
|
|
||||||
if (index < 0 && index > -3)
|
|
||||||
lua.Error("Vector3 expected, three numbers are required to convert it");
|
|
||||||
|
|
||||||
vec->Set(lua.CheckNumber(index), lua.CheckNumber(index + 1), lua.CheckNumber(index + 2));
|
|
||||||
return 3;
|
|
||||||
|
|
||||||
case Nz::LuaType_Table:
|
|
||||||
vec->Set(lua.CheckField<double>("x", index), lua.CheckField<double>("y", index), lua.CheckField<double>("z", index));
|
|
||||||
return 3;
|
|
||||||
|
|
||||||
default:
|
|
||||||
vec->Set(*(*static_cast<Vector3d**>(lua.CheckUserdata(index, "Vector3"))));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned int LuaImplQueryArg(const LuaInstance& lua, int index, Vector3f* vec, TypeTag<Vector3f>)
|
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesf val, TypeTag<EulerAnglesf>)
|
||||||
{
|
{
|
||||||
Vector3d vecDouble;
|
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
|
||||||
unsigned int ret = LuaImplQueryArg(lua, index, &vecDouble, TypeTag<Vector3d>());
|
return 1;
|
||||||
|
|
||||||
vec->Set(vecDouble);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned int LuaImplQueryArg(const LuaInstance& lua, int index, Vector3ui* vec, TypeTag<Vector3ui>)
|
inline int LuaImplReplyVal(const LuaInstance& instance, Quaterniond val, TypeTag<Quaterniond>)
|
||||||
{
|
{
|
||||||
Vector3d vecDouble;
|
instance.PushInstance<Quaterniond>("Quaternion", val);
|
||||||
unsigned int ret = LuaImplQueryArg(lua, index, &vecDouble, TypeTag<Vector3d>());
|
return 1;
|
||||||
|
|
||||||
vec->Set(vecDouble);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Quaternionf val, TypeTag<Quaternionf>)
|
||||||
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
|
|
||||||
{
|
{
|
||||||
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
|
instance.PushInstance<Quaterniond>("Quaternion", val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,4 +277,48 @@ namespace Nz
|
||||||
instance.PushInstance<Vector3d>("Vector3", val);
|
instance.PushInstance<Vector3d>("Vector3", val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Entity* ptr, TypeTag<Ndk::Entity*>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Ndk::EntityHandle>("Entity", ptr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::EntityHandle handle, TypeTag<Ndk::EntityHandle>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Ndk::EntityHandle>("Entity", handle);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::NodeComponentHandle handle, TypeTag<Ndk::NodeComponentHandle>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Ndk::NodeComponentHandle>("NodeComponent", handle);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::World* ptr, TypeTag<Ndk::World*>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Ndk::WorldHandle>("World", ptr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::WorldHandle handle, TypeTag<Ndk::WorldHandle>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Ndk::WorldHandle>("World", handle);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::GraphicsComponentHandle handle, TypeTag<Ndk::GraphicsComponentHandle>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<Ndk::GraphicsComponentHandle>("GraphicsComponent", handle);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
|
||||||
|
{
|
||||||
|
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,37 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
void LuaAPI::Register_Graphics(Nz::LuaInstance& instance)
|
void LuaAPI::Register_Graphics(Nz::LuaInstance& instance)
|
||||||
{
|
{
|
||||||
|
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable("InstancedRenderable");
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::ModelRef> modelClass("Model");
|
||||||
|
modelClass.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef*
|
||||||
|
{
|
||||||
|
return reinterpret_cast<Nz::InstancedRenderableRef*>(model); //TODO: Make a ObjectRefCast
|
||||||
|
});
|
||||||
|
|
||||||
|
modelClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::ModelRef*
|
||||||
|
{
|
||||||
|
return new Nz::ModelRef(new Nz::Model);
|
||||||
|
});
|
||||||
|
|
||||||
|
//modelClass.SetMethod("GetMaterial", &Nz::Model::GetMaterial);
|
||||||
|
modelClass.SetMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
|
||||||
|
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
|
||||||
|
modelClass.SetMethod("GetSkin", &Nz::Model::GetSkin);
|
||||||
|
modelClass.SetMethod("GetSkinCount", &Nz::Model::GetSkinCount);
|
||||||
|
|
||||||
|
modelClass.SetMethod("IsAnimated", &Nz::Model::IsAnimated);
|
||||||
|
modelClass.SetMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
|
||||||
|
|
||||||
|
modelClass.SetMethod("Reset", &Nz::Model::Reset);
|
||||||
|
|
||||||
|
//modelClass.SetMethod("SetMaterial", &Nz::Model::SetMaterial);
|
||||||
|
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
|
||||||
|
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
||||||
|
modelClass.SetMethod("SetSkin", &Nz::Model::SetSkin);
|
||||||
|
modelClass.SetMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
||||||
|
|
||||||
|
instancedRenderable.Register(instance);
|
||||||
|
modelClass.Register(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,243 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
void LuaAPI::Register_Math(Nz::LuaInstance& instance)
|
void LuaAPI::Register_Math(Nz::LuaInstance& instance)
|
||||||
{
|
{
|
||||||
|
/*********************************** Nz::EulerAngles **********************************/
|
||||||
|
Nz::LuaClass<Nz::EulerAnglesd> eulerAnglesClass("EulerAngles");
|
||||||
|
|
||||||
|
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::EulerAnglesd*
|
||||||
|
{
|
||||||
|
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return new Nz::EulerAnglesd(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
return new Nz::EulerAnglesd(*(*static_cast<Nz::EulerAnglesd**>(lua.CheckUserdata(1, "EulerAngles"))));
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
return new Nz::EulerAnglesd(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for EulerAngles constructor");
|
||||||
|
return nullptr;
|
||||||
|
});
|
||||||
|
|
||||||
|
eulerAnglesClass.SetMethod("__tostring", &Nz::EulerAnglesd::ToString);
|
||||||
|
|
||||||
|
eulerAnglesClass.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* ypr = lua.CheckString(1, &length);
|
||||||
|
|
||||||
|
switch (length)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
switch (ypr[0])
|
||||||
|
{
|
||||||
|
case 'p':
|
||||||
|
lua.Push(instance.pitch);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.yaw);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
lua.Push(instance.roll);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lua.Push(instance.yaw);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lua.Push(instance.roll);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lua.Push(instance.pitch);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
eulerAnglesClass.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* ypr = lua.CheckString(1, &length);
|
||||||
|
double value = lua.CheckNumber(2);
|
||||||
|
|
||||||
|
switch (length)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
switch (ypr[0])
|
||||||
|
{
|
||||||
|
case 'p':
|
||||||
|
instance.pitch = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.yaw = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
instance.roll = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
instance.yaw = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
instance.roll = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
instance.pitch = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
eulerAnglesClass.Register(instance);
|
||||||
|
|
||||||
|
/*********************************** Nz::Quaternion **********************************/
|
||||||
|
Nz::LuaClass<Nz::Quaterniond> quaternionClass("Quaternion");
|
||||||
|
|
||||||
|
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Quaterniond*
|
||||||
|
{
|
||||||
|
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return new Nz::Quaterniond(1.0, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(1, "EulerAngles"))
|
||||||
|
return new Nz::Quaterniond(*(*static_cast<Nz::EulerAnglesd**>(lua.ToUserdata(1))));
|
||||||
|
else if (lua.IsOfType(1, "Quaternion"))
|
||||||
|
return new Nz::Quaterniond(*(*static_cast<Nz::Quaterniond**>(lua.ToUserdata(1))));
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
return new Nz::Quaterniond(lua.CheckNumber(1), *(*static_cast<Nz::Vector3d**>(lua.CheckUserdata(2, "Vector3"))));
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
return new Nz::Quaterniond(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for Quaternion constructor");
|
||||||
|
return nullptr;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternionClass.SetMethod("__tostring", &Nz::Quaterniond::ToString);
|
||||||
|
|
||||||
|
quaternionClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* wxyz = lua.CheckString(1, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
switch (wxyz[0])
|
||||||
|
{
|
||||||
|
case 'w':
|
||||||
|
lua.Push(instance.w);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'x':
|
||||||
|
lua.Push(instance.x);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
lua.Push(instance.z);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternionClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* wxyz = lua.CheckString(1, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
double value = lua.CheckNumber(2);
|
||||||
|
|
||||||
|
switch (wxyz[0])
|
||||||
|
{
|
||||||
|
case 'w':
|
||||||
|
instance.w = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'x':
|
||||||
|
instance.x = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.y = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
instance.z = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternionClass.Register(instance);
|
||||||
|
|
||||||
/*********************************** Nz::Vector2 **********************************/
|
/*********************************** Nz::Vector2 **********************************/
|
||||||
Nz::LuaClass<Nz::Vector2d> vector2dClass("Vector2");
|
Nz::LuaClass<Nz::Vector2d> vector2dClass("Vector2");
|
||||||
|
|
||||||
|
|
@ -25,7 +262,7 @@ namespace Ndk
|
||||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||||
return new Nz::Vector2d(lua.CheckNumber(1));
|
return new Nz::Vector2d(lua.CheckNumber(1));
|
||||||
else if (lua.IsOfType(1, "Vector2"))
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
return new Nz::Vector2d(*(*static_cast<Nz::Vector2d*>(lua.ToUserdata(1))));
|
return new Nz::Vector2d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -42,8 +279,14 @@ namespace Ndk
|
||||||
switch (lua.GetType(1))
|
switch (lua.GetType(1))
|
||||||
{
|
{
|
||||||
case Nz::LuaType_Number:
|
case Nz::LuaType_Number:
|
||||||
lua.Push(instance[lua.CheckInteger(1)]);
|
{
|
||||||
|
long long index = lua.CheckInteger(1);
|
||||||
|
if (index < 1 || index > 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
case Nz::LuaType_String:
|
case Nz::LuaType_String:
|
||||||
{
|
{
|
||||||
|
|
@ -80,7 +323,7 @@ namespace Ndk
|
||||||
if (index < 1 || index > 2)
|
if (index < 1 || index > 2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
instance[index] = lua.CheckNumber(2);
|
instance[index - 1] = lua.CheckNumber(2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,11 +371,11 @@ namespace Ndk
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||||
return new Nz::Vector3d(lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
return new Nz::Vector3d(lua.CheckNumber(1), *(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||||
else if (lua.IsOfType(1, "Vector2"))
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d*>(lua.ToUserdata(1))));
|
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||||
else if (lua.IsOfType(1, "Vector3"))
|
else if (lua.IsOfType(1, "Vector3"))
|
||||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector3d*>(lua.ToUserdata(1))));
|
return new Nz::Vector3d(*(*static_cast<Nz::Vector3d**>(lua.ToUserdata(1))));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +383,7 @@ namespace Ndk
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||||
return new Nz::Vector3d(lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(1, "Vector2")));
|
return new Nz::Vector3d(lua.CheckNumber(1), *(*static_cast<Nz::Vector2d**>(lua.CheckUserdata(1, "Vector2"))));
|
||||||
else if (lua.IsOfType(1, "Vector2"))
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))), lua.CheckNumber(2));
|
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))), lua.CheckNumber(2));
|
||||||
|
|
||||||
|
|
@ -159,8 +402,14 @@ namespace Ndk
|
||||||
switch (lua.GetType(1))
|
switch (lua.GetType(1))
|
||||||
{
|
{
|
||||||
case Nz::LuaType_Number:
|
case Nz::LuaType_Number:
|
||||||
lua.Push(instance[lua.CheckInteger(1)]);
|
{
|
||||||
|
long long index = lua.CheckInteger(1);
|
||||||
|
if (index < 1 || index > 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
case Nz::LuaType_String:
|
case Nz::LuaType_String:
|
||||||
{
|
{
|
||||||
|
|
@ -201,7 +450,7 @@ namespace Ndk
|
||||||
if (index < 1 || index > 3)
|
if (index < 1 || index > 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
instance[index] = lua.CheckNumber(2);
|
instance[index - 1] = lua.CheckNumber(2);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,313 @@
|
||||||
|
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
#include <Nazara/Renderer.hpp>
|
||||||
|
#include <Nazara/Utility.hpp>
|
||||||
|
#include <Nazara/Lua/LuaClass.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
int AddNilComponent(Nz::LuaInstance& lua, EntityHandle&)
|
||||||
|
{
|
||||||
|
lua.PushNil();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||||
|
{
|
||||||
|
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||||
|
|
||||||
|
T& component = handle->AddComponent<T>();
|
||||||
|
lua.Push(component.CreateHandle());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AddComponent(Nz::LuaInstance& lua, EntityHandle& handle, ComponentIndex index)
|
||||||
|
{
|
||||||
|
std::vector<int(*)(Nz::LuaInstance&, EntityHandle&)> componentAdder(BaseComponent::GetMaxComponentIndex(), AddNilComponent);
|
||||||
|
componentAdder[GraphicsComponent::componentIndex] = &AddComponentOfType<GraphicsComponent>;
|
||||||
|
componentAdder[NodeComponent::componentIndex] = &AddComponentOfType<NodeComponent>;
|
||||||
|
|
||||||
|
if (index > componentAdder.size())
|
||||||
|
{
|
||||||
|
lua.Error("Invalid component index");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return componentAdder[index](lua, handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
int PushNilComponent(Nz::LuaInstance& lua, BaseComponent&)
|
||||||
|
{
|
||||||
|
lua.PushNil();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||||
|
{
|
||||||
|
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||||
|
|
||||||
|
T& rightComponent = static_cast<T&>(component);
|
||||||
|
lua.Push(rightComponent.CreateHandle());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PushComponent(Nz::LuaInstance& lua, BaseComponent& component)
|
||||||
|
{
|
||||||
|
std::vector<int(*)(Nz::LuaInstance&, BaseComponent&)> componentConverter(BaseComponent::GetMaxComponentIndex(), PushNilComponent);
|
||||||
|
componentConverter[GraphicsComponent::componentIndex] = &PushComponentOfType<GraphicsComponent>;
|
||||||
|
componentConverter[NodeComponent::componentIndex] = &PushComponentOfType<NodeComponent>;
|
||||||
|
|
||||||
|
ComponentIndex index = component.GetIndex();
|
||||||
|
|
||||||
|
if (index > componentConverter.size())
|
||||||
|
{
|
||||||
|
lua.Error("Invalid component index");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return componentConverter[index](lua, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaAPI::Register_SDK(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent("GraphicsComponent");
|
||||||
|
|
||||||
|
graphicsComponent.SetMethod("Attach", &GraphicsComponent::Attach, 0);
|
||||||
|
|
||||||
|
graphicsComponent.Register(instance);
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::Node> nodeClass("Node"); //< TODO: Move to Utility
|
||||||
|
|
||||||
|
nodeClass.SetMethod("GetBackward", &Nz::Node::GetBackward);
|
||||||
|
//nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds);
|
||||||
|
nodeClass.SetMethod("GetDown", &Nz::Node::GetDown);
|
||||||
|
nodeClass.SetMethod("GetForward", &Nz::Node::GetForward);
|
||||||
|
nodeClass.SetMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||||
|
nodeClass.SetMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||||
|
nodeClass.SetMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||||
|
nodeClass.SetMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||||
|
//nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||||
|
nodeClass.SetMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||||
|
nodeClass.SetMethod("GetLeft", &Nz::Node::GetLeft);
|
||||||
|
nodeClass.SetMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||||
|
//nodeClass.SetMethod("GetParent", &Nz::Node::GetParent);
|
||||||
|
nodeClass.SetMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||||
|
nodeClass.SetMethod("GetRight", &Nz::Node::GetRight);
|
||||||
|
//nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||||
|
nodeClass.SetMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||||
|
//nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix);
|
||||||
|
nodeClass.SetMethod("GetUp", &Nz::Node::GetUp);
|
||||||
|
|
||||||
|
nodeClass.SetMethod("HasChilds", &Nz::Node::HasChilds);
|
||||||
|
|
||||||
|
nodeClass.SetMethod("GetBackward", &Nz::Node::GetBackward);
|
||||||
|
nodeClass.SetMethod("GetDown", &Nz::Node::GetDown);
|
||||||
|
nodeClass.SetMethod("GetForward", &Nz::Node::GetForward);
|
||||||
|
nodeClass.SetMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||||
|
nodeClass.SetMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||||
|
nodeClass.SetMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||||
|
nodeClass.SetMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||||
|
nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||||
|
nodeClass.SetMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||||
|
nodeClass.SetMethod("GetLeft", &Nz::Node::GetLeft);
|
||||||
|
nodeClass.SetMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||||
|
nodeClass.SetMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||||
|
nodeClass.SetMethod("GetRight", &Nz::Node::GetRight);
|
||||||
|
nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||||
|
nodeClass.SetMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||||
|
nodeClass.SetMethod("GetUp", &Nz::Node::GetUp);
|
||||||
|
|
||||||
|
nodeClass.SetMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
|
||||||
|
nodeClass.SetMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation);
|
||||||
|
|
||||||
|
nodeClass.SetMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
|
||||||
|
nodeClass.SetMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
|
||||||
|
|
||||||
|
nodeClass.SetMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 1;
|
||||||
|
|
||||||
|
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
node.Move(offset, coordSys);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
nodeClass.SetMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 1;
|
||||||
|
|
||||||
|
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
node.Rotate(rotation, coordSys);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
nodeClass.SetMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||||
|
{
|
||||||
|
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||||
|
|
||||||
|
int argIndex = 1;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
node.Scale(lua.Check<float>(&argIndex));
|
||||||
|
else
|
||||||
|
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method Scale");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
nodeClass.SetMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||||
|
{
|
||||||
|
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||||
|
|
||||||
|
int argIndex = 1;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
{
|
||||||
|
float scale = lua.Check<float>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
node.SetScale(scale, coordSys);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
node.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
|
||||||
|
node.SetScale(scale, coordSys);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method SetScale");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
nodeClass.SetMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||||
|
{
|
||||||
|
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||||
|
|
||||||
|
int argIndex = 1;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
node.SetInitialScale(lua.Check<float>(&argIndex));
|
||||||
|
else
|
||||||
|
node.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
node.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method SetInitialScale");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
nodeClass.Register(instance);
|
||||||
|
|
||||||
|
Nz::LuaClass<NodeComponentHandle> nodeComponent("NodeComponent");
|
||||||
|
nodeComponent.Inherit<Nz::Node>(nodeClass, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||||
|
{
|
||||||
|
return handle->GetObject();
|
||||||
|
});
|
||||||
|
|
||||||
|
nodeComponent.Register(instance);
|
||||||
|
|
||||||
|
Nz::LuaClass<EntityHandle> entityClass("Entity");
|
||||||
|
|
||||||
|
entityClass.SetMethod("Enable", &Entity::Enable);
|
||||||
|
entityClass.SetMethod("GetId", &Entity::GetId);
|
||||||
|
entityClass.SetMethod("GetWorld", &Entity::GetWorld);
|
||||||
|
entityClass.SetMethod("Kill", &Entity::Kill);
|
||||||
|
entityClass.SetMethod("IsEnabled", &Entity::IsEnabled);
|
||||||
|
entityClass.SetMethod("IsValid", &Entity::IsValid);
|
||||||
|
entityClass.SetMethod("RemoveComponent", (void(Entity::*)(ComponentIndex)) &Entity::RemoveComponent);
|
||||||
|
entityClass.SetMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
|
||||||
|
entityClass.SetMethod("__tostring", &EntityHandle::ToString);
|
||||||
|
|
||||||
|
entityClass.SetMethod("AddComponent", [] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||||
|
{
|
||||||
|
int index = 1;
|
||||||
|
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||||
|
|
||||||
|
return AddComponent(lua, handle, componentIndex);
|
||||||
|
});
|
||||||
|
|
||||||
|
entityClass.SetMethod("GetComponent", [] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||||
|
{
|
||||||
|
int index = 1;
|
||||||
|
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||||
|
|
||||||
|
if (!handle->HasComponent(componentIndex))
|
||||||
|
{
|
||||||
|
lua.PushNil();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PushComponent(lua, handle->GetComponent(componentIndex));
|
||||||
|
});
|
||||||
|
|
||||||
|
entityClass.Register(instance);
|
||||||
|
|
||||||
|
Nz::LuaClass<WorldHandle> worldClass("World");
|
||||||
|
|
||||||
|
worldClass.SetMethod("CreateEntity", &World::CreateEntity);
|
||||||
|
worldClass.SetMethod("CreateEntities", &World::CreateEntities);
|
||||||
|
worldClass.SetMethod("Clear", &World::Clear);
|
||||||
|
|
||||||
|
worldClass.Register(instance);
|
||||||
|
|
||||||
|
instance.PushTable(0, 2);
|
||||||
|
{
|
||||||
|
instance.PushInteger(GraphicsComponent::componentIndex);
|
||||||
|
instance.SetField("Graphics");
|
||||||
|
|
||||||
|
instance.PushInteger(NodeComponent::componentIndex);
|
||||||
|
instance.SetField("Node");
|
||||||
|
}
|
||||||
|
instance.SetGlobal("ComponentType");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue