From 2873eaefaa819296d075d8c645119ace84f3589a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Thu, 27 Aug 2020 19:26:14 +0200 Subject: [PATCH] SDK: Remove deprecated LuaBinding --- src/NazaraSDK/LuaBinding.cpp | 110 --- src/NazaraSDK/LuaBinding_Audio.cpp | 185 ----- src/NazaraSDK/LuaBinding_Math.cpp | 968 -------------------------- src/NazaraSDK/LuaBinding_Renderer.cpp | 76 -- src/NazaraSDK/LuaBinding_SDK.cpp | 320 --------- 5 files changed, 1659 deletions(-) delete mode 100644 src/NazaraSDK/LuaBinding.cpp delete mode 100644 src/NazaraSDK/LuaBinding_Audio.cpp delete mode 100644 src/NazaraSDK/LuaBinding_Math.cpp delete mode 100644 src/NazaraSDK/LuaBinding_Renderer.cpp delete mode 100644 src/NazaraSDK/LuaBinding_SDK.cpp diff --git a/src/NazaraSDK/LuaBinding.cpp b/src/NazaraSDK/LuaBinding.cpp deleted file mode 100644 index 9b990bdfd..000000000 --- a/src/NazaraSDK/LuaBinding.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::LuaBinding - * \brief NDK class that represents the binding between the engine & the SDK with the Lua scripting - */ - - /*! - * \brief Binds modules to Lua - */ - - LuaBinding::LuaBinding() : - // Core - clock("Clock"), - directory("Directory"), - file("File"), - stream("Stream"), - - // Math - eulerAngles("EulerAngles"), - matrix4d("Matrix4"), - quaternion("Quaternion"), - rect("Rect"), - vector2d("Vector2"), - vector3d("Vector3"), - - // Network - abstractSocket("AbstractSocket"), - ipAddress("IpAddress"), - - // Utility - abstractImage("AbstractImage"), - font("Font"), - keyboard("Keyboard"), - node("Node"), - - // SDK - application("Application"), - entity("Entity"), - nodeComponent("NodeComponent"), - velocityComponent("VelocityComponent"), - world("World") - - #ifndef NDK_SERVER - , - - // Audio - music("Music"), - sound("Sound"), - soundBuffer("SoundBuffer"), - soundEmitter("SoundEmitter"), - - // Graphics - abstractViewer("AbstractViewer"), - instancedRenderable("InstancedRenderable"), - material("Material"), - model("Model"), - sprite("Sprite"), - spriteLibrary("SpriteLibrary"), - textureLibrary("TextureLibrary"), - textureManager("TextureManager"), - - // Renderer - texture("Texture"), - - // SDK - cameraComponent("CameraComponent"), - console("Console"), - graphicsComponent("GraphicsComponent") - #endif - { - BindCore(); - BindMath(); - BindNetwork(); - BindSDK(); - BindUtility(); - - #ifndef NDK_SERVER - BindAudio(); - BindGraphics(); - BindRenderer(); - #endif - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the engine & SDK - */ - - void LuaBinding::RegisterClasses(Nz::LuaInstance& instance) - { - RegisterCore(instance); - RegisterMath(instance); - RegisterNetwork(instance); - RegisterSDK(instance); - RegisterUtility(instance); - - #ifndef NDK_SERVER - RegisterAudio(instance); - RegisterGraphics(instance); - RegisterRenderer(instance); - #endif - } -} diff --git a/src/NazaraSDK/LuaBinding_Audio.cpp b/src/NazaraSDK/LuaBinding_Audio.cpp deleted file mode 100644 index 60f504939..000000000 --- a/src/NazaraSDK/LuaBinding_Audio.cpp +++ /dev/null @@ -1,185 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include -#include -#include - -namespace Ndk -{ - /*! - * \brief Binds Audio module to Lua - */ - - void LuaBinding::BindAudio() - { - /*********************************** Nz::Music **********************************/ - music.Inherit(soundEmitter); - - music.BindDefaultConstructor(); - - //musicClass.SetMethod("Create", &Nz::Music::Create); - //musicClass.SetMethod("Destroy", &Nz::Music::Destroy); - - music.BindMethod("EnableLooping", &Nz::Music::EnableLooping); - - music.BindMethod("GetDuration", &Nz::Music::GetDuration); - music.BindMethod("GetFormat", &Nz::Music::GetFormat); - music.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset); - music.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount); - music.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate); - music.BindMethod("GetStatus", &Nz::Music::GetStatus); - - music.BindMethod("IsLooping", &Nz::Music::IsLooping); - - music.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams()); - - music.BindMethod("Pause", &Nz::Music::Pause); - music.BindMethod("Play", &Nz::Music::Play); - - music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset); - - music.BindMethod("Stop", &Nz::Music::Stop); - - // Manual - music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& instance, std::size_t /*argumentCount*/) -> int - { - Nz::StringStream ss("Music("); - ss << instance.GetFilePath() << ')'; - - lua.PushString(ss); - return 1; - }); - - /*********************************** Nz::Sound **********************************/ - sound.Inherit(soundEmitter); - - sound.BindDefaultConstructor(); - - sound.BindMethod("GetBuffer", &Nz::Sound::GetBuffer); - - sound.BindMethod("IsPlayable", &Nz::Sound::IsPlayable); - sound.BindMethod("IsPlaying", &Nz::Sound::IsPlaying); - - sound.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); - - sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); - - // Manual - sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& instance, std::size_t /*argumentCount*/) -> int - { - Nz::StringStream ss("Sound("); - if (const Nz::SoundBuffer* buffer = instance.GetBuffer()) - ss << buffer; - - ss << ')'; - - lua.PushString(ss); - return 1; - }); - - /*********************************** Nz::SoundBuffer **********************************/ - soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount) - { - NazaraUnused(lua); - NazaraUnused(argumentCount); - - Nz::PlacementNew(instance, Nz::SoundBuffer::New()); - return true; - }); - - soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy); - - soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration); - soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat); - soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount); - soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate); - - soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid); - - soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams()); - - soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported); - - // Manual - soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int - { - int index = 2; - Nz::AudioFormat format = lua.Check(&index); - unsigned int sampleCount = lua.Check(&index); - unsigned int sampleRate = lua.Check(&index); - - std::size_t bufferSize = 0; - const char* buffer = lua.CheckString(index, &bufferSize); - lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer"); - - lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast(buffer))); - return 1; - }); - - soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int - { - lua.PushString(reinterpret_cast(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16)); - return 1; - }); - - soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int - { - Nz::StringStream ss("SoundBuffer("); - if (instance->IsValid()) - { - Nz::String filePath = instance->GetFilePath(); - if (!filePath.IsEmpty()) - ss << "File: " << filePath << ", "; - - ss << "Duration: " << instance->GetDuration() / 1000.f << "s"; - } - ss << ')'; - - lua.PushString(ss); - return 1; - }); - - /*********************************** Nz::SoundEmitter **********************************/ - soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping); - soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization); - - soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation); - soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration); - soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance); - soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch); - soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset); - soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition); - soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus); - soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity); - soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume); - - soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping); - soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized); - - soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause); - soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play); - - soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation); - soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance); - soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch); - soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition); - soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity); - soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume); - - soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop); - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Audio classes - */ - - void LuaBinding::RegisterAudio(Nz::LuaInstance& instance) - { - music.Register(instance); - sound.Register(instance); - soundBuffer.Register(instance); - soundEmitter.Register(instance); - } -} diff --git a/src/NazaraSDK/LuaBinding_Math.cpp b/src/NazaraSDK/LuaBinding_Math.cpp deleted file mode 100644 index f777dce7f..000000000 --- a/src/NazaraSDK/LuaBinding_Math.cpp +++ /dev/null @@ -1,968 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include -#include -#include -#include - -namespace Ndk -{ - /*! - * \brief Binds Math module to Lua - */ - - void LuaBinding::BindMath() - { - /*********************************** Nz::EulerAngles **********************************/ - eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 1U); - - switch (argCount) - { - case 0: - Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero()); - return true; - - case 1: - Nz::PlacementNew(instance, *static_cast(lua.CheckUserdata(1, "EulerAngles"))); - return true; - - case 3: - Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3)); - return true; - } - - lua.Error("No matching overload for EulerAngles constructor"); - return false; - }); - - eulerAngles.BindMethod("Normalize", &Nz::EulerAnglesd::Normalize); - eulerAngles.BindMethod("ToQuaternion", &Nz::EulerAnglesd::ToQuaternion); - - eulerAngles.BindMethod("__tostring", &Nz::EulerAnglesd::ToString); - - eulerAngles.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) - { - std::size_t length; - const char* ypr = lua.CheckString(2, &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; - }); - - eulerAngles.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) - { - std::size_t length; - const char* ypr = lua.CheckString(2, &length); - double value = lua.CheckNumber(3); - - 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; - }); - - - /*********************************** Nz::Matrix4 **********************************/ - matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 3U); - - switch (argCount) - { - case 0: - Nz::PlacementNew(matrix, Nz::Matrix4d::Zero()); - return true; - - case 1: - if (lua.IsOfType(1, "Matrix4")) - Nz::PlacementNew(matrix, *static_cast(lua.ToUserdata(1))); - break; - - case 16: - { - double values[16]; - for (int i = 0; i < 16; ++i) - values[i] = lua.CheckNumber(i); - - Nz::PlacementNew(matrix, values); - - return true; - } - } - - lua.Error("No matching overload for constructor"); - return false; - }); - - matrix4d.BindMethod("ApplyRotation", &Nz::Matrix4d::ApplyRotation); - matrix4d.BindMethod("ApplyScale", &Nz::Matrix4d::ApplyScale); - matrix4d.BindMethod("ApplyTranslation", &Nz::Matrix4d::ApplyTranslation); - - matrix4d.BindMethod("Concatenate", &Nz::Matrix4d::Concatenate); - matrix4d.BindMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine); - - //matrix4d.BindMethod("GetColumn", &Nz::Matrix4d::GetColumn); - matrix4d.BindMethod("GetDeterminant", &Nz::Matrix4d::GetDeterminant); - matrix4d.BindMethod("GetDeterminantAffine", &Nz::Matrix4d::GetDeterminantAffine); - - matrix4d.BindMethod("GetInverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - Nz::Matrix4d result; - if (instance.GetInverse(&result)) - return lua.Push(true, result); - else - return lua.Push(false); - }); - - matrix4d.BindMethod("GetInverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - Nz::Matrix4d result; - if (instance.GetInverseAffine(&result)) - return lua.Push(true, result); - else - return lua.Push(false); - }); - - matrix4d.BindMethod("GetRotation", &Nz::Matrix4d::GetRotation); - - //matrix4d.BindMethod("GetRow", &Nz::Matrix4d::GetRow); - matrix4d.BindMethod("GetScale", &Nz::Matrix4d::GetScale); - matrix4d.BindMethod("GetSquaredScale", &Nz::Matrix4d::GetSquaredScale); - matrix4d.BindMethod("GetTranslation", &Nz::Matrix4d::GetTranslation); - - matrix4d.BindMethod("GetTransposed", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - Nz::Matrix4d result; - instance.GetTransposed(&result); - - return lua.Push(result); - }); - - matrix4d.BindMethod("HasNegativeScale", &Nz::Matrix4d::HasNegativeScale); - matrix4d.BindMethod("HasScale", &Nz::Matrix4d::HasScale); - - matrix4d.BindMethod("Inverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - bool succeeded; - instance.Inverse(&succeeded); - - return lua.Push(succeeded); - }); - - matrix4d.BindMethod("InverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - bool succeeded; - instance.InverseAffine(&succeeded); - - return lua.Push(succeeded); - }); - - matrix4d.BindMethod("IsAffine", &Nz::Matrix4d::IsAffine); - matrix4d.BindMethod("IsIdentity", &Nz::Matrix4d::IsIdentity); - - matrix4d.BindMethod("MakeIdentity", &Nz::Matrix4d::MakeIdentity); - matrix4d.BindMethod("MakeLookAt", &Nz::Matrix4d::MakeLookAt, Nz::Vector3d::Up()); - matrix4d.BindMethod("MakeOrtho", &Nz::Matrix4d::MakeOrtho, -1.0, 1.0); - matrix4d.BindMethod("MakePerspective", &Nz::Matrix4d::MakePerspective); - matrix4d.BindMethod("MakeRotation", &Nz::Matrix4d::MakeRotation); - matrix4d.BindMethod("MakeScale", &Nz::Matrix4d::MakeScale); - matrix4d.BindMethod("MakeTranslation", &Nz::Matrix4d::MakeTranslation); - matrix4d.BindMethod("MakeTransform", (Nz::Matrix4d&(Nz::Matrix4d::*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::MakeTransform, Nz::Vector3d::Unit()); - matrix4d.BindMethod("MakeViewMatrix", &Nz::Matrix4d::MakeViewMatrix); - matrix4d.BindMethod("MakeZero", &Nz::Matrix4d::MakeZero); - - matrix4d.BindMethod("Set", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 3U); - - int argIndex = 2; - switch (argCount) - { - case 1: - if (lua.IsOfType(argIndex, "Matrix4")) - instance.Set(*static_cast(lua.ToUserdata(argIndex))); - break; - - case 16: - { - double values[16]; - for (std::size_t i = 0; i < 16; ++i) - values[i] = lua.CheckNumber(argIndex++); - - instance.Set(values); - - return 0; - } - } - - lua.Error("No matching overload for method Set"); - return 0; - }); - - matrix4d.BindMethod("SetRotation", &Nz::Matrix4d::SetRotation); - matrix4d.BindMethod("SetScale", &Nz::Matrix4d::SetScale); - matrix4d.BindMethod("SetTranslation", &Nz::Matrix4d::SetTranslation); - - matrix4d.BindMethod("Transform", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Vector2")) - { - double z(lua.CheckNumber(argIndex+1, 0.0)); - double w(lua.CheckNumber(argIndex+2, 1.0)); - - return lua.Push(instance.Transform(*static_cast(lua.ToUserdata(argIndex)), z, w)); - } - else if (lua.IsOfType(argIndex, "Vector3")) - { - double w(lua.CheckNumber(argIndex+1, 1.0)); - - return lua.Push(instance.Transform(*static_cast(lua.ToUserdata(argIndex)), w)); - } - //else if (lua.IsOfType(2, "Vector4")) - // return lua.Push(instance.Transform(*static_cast(lua.ToUserdata(1)))); - - lua.Error("No matching overload for method Transform"); - return 0; - }); - - matrix4d.BindMethod("Transpose", &Nz::Matrix4d::Transpose); - - matrix4d.BindMethod("__tostring", &Nz::Matrix4d::ToString); - - matrix4d.BindStaticMethod("Concatenate", &Nz::Matrix4d::Concatenate); - matrix4d.BindStaticMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine); - matrix4d.BindStaticMethod("Identity", &Nz::Matrix4d::Identity); - matrix4d.BindStaticMethod("LookAt", &Nz::Matrix4d::LookAt, Nz::Vector3d::Up()); - matrix4d.BindStaticMethod("Ortho", &Nz::Matrix4d::Ortho, -1.0, 1.0); - matrix4d.BindStaticMethod("Perspective", &Nz::Matrix4d::Perspective); - matrix4d.BindStaticMethod("Rotate", &Nz::Matrix4d::Rotate); - matrix4d.BindStaticMethod("Scale", &Nz::Matrix4d::Scale); - matrix4d.BindStaticMethod("Translate", &Nz::Matrix4d::Translate); - matrix4d.BindStaticMethod("Transform", (Nz::Matrix4d(*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::Transform, Nz::Vector3d::Unit()); - matrix4d.BindStaticMethod("ViewMatrix", &Nz::Matrix4d::ViewMatrix); - matrix4d.BindStaticMethod("Zero", &Nz::Matrix4d::Zero); - - matrix4d.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) - { - bool succeeded = false; - std::size_t index = static_cast(lua.ToInteger(2, &succeeded)); - if (!succeeded || index < 1 || index > 16) - return false; - - lua.Push(instance[index - 1]); - return true; - }); - - matrix4d.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) - { - bool succeeded = false; - std::size_t index = static_cast(lua.ToInteger(2, &succeeded)); - if (!succeeded || index < 1 || index > 16) - return false; - - instance[index - 1] = lua.CheckNumber(3); - - return true; - }); - - /*********************************** Nz::Rect **********************************/ - rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 4U); - - switch (argCount) - { - case 0: - case 4: - PlacementNew(instance, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0), lua.CheckNumber(4, 0.0)); - return true; - - case 1: - { - if (lua.IsOfType(1, "Rect")) - PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else if (lua.IsOfType(1, Nz::LuaType_Table)) - { - // TODO => Faire sans avoir à mettre de nom dans la table et prendre les éléments un à un pour créer le Rectd - PlacementNew(instance, lua.CheckField("x", 1), - lua.CheckField("y", 1), - lua.CheckField("width", 1), - lua.CheckField("height", 1)); - } - else if (lua.IsOfType(1, "Vector2")) - PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else - break; - - return true; - } - - case 2: - { - if (lua.IsOfType(1, Nz::LuaType_Number) && lua.IsOfType(2, Nz::LuaType_Number)) - PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2)); - else if (lua.IsOfType(1, "Vector2") && lua.IsOfType(2, "Vector2")) - PlacementNew(instance, *static_cast(lua.ToUserdata(1)), *static_cast(lua.ToUserdata(2))); - else - break; - - return true; - } - } - - lua.Error("No matching overload for Rect constructor"); - return false; - }); - - rect.BindMethod("__tostring", &Nz::Rectd::ToString); - - rect.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - auto index = lua.CheckBoundInteger(2); - if (index < 1 || index > 4) - return false; - - lua.Push(instance[index - 1]); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xywh = lua.CheckString(2, &length); - - if (length != 1) - break; - - switch (xywh[0]) - { - case 'x': - lua.Push(instance.x); - return true; - - case 'y': - lua.Push(instance.y); - return true; - - case 'w': - lua.Push(instance.width); - return true; - - case 'h': - lua.Push(instance.height); - return true; - - default: - break; - } - break; - } - - default: - break; - } - - return false; - }); - - rect.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - auto index = lua.CheckBoundInteger(2); - if (index < 1 || index > 4) - return false; - - instance[index - 1] = lua.CheckNumber(2); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xywh = lua.CheckString(2, &length); - - if (length != 1) - break; - - double value = lua.CheckNumber(3); - - switch (xywh[0]) - { - case 'x': - instance.x = value; - return true; - - case 'y': - instance.y = value; - return true; - - case 'w': - instance.width = value; - return true; - - case 'h': - instance.height = value; - return true; - } - break; - } - - default: - break; - } - - return false; - }); - - /*********************************** Nz::Quaternion **********************************/ - quaternion.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 4U); - - switch (argCount) - { - case 0: - Nz::PlacementNew(instance, Nz::Quaterniond::Zero()); - return true; - - case 1: - { - if (lua.IsOfType(1, "EulerAngles")) - Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else if (lua.IsOfType(1, "Quaternion")) - Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else - break; - - return true; - } - - case 2: - Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector3"))); - return true; - - case 4: - Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4)); - return true; - - default: - break; - } - - lua.Error("No matching overload for Quaternion constructor"); - return false; - }); - - quaternion.BindMethod("ComputeW", &Nz::Quaterniond::ComputeW); - quaternion.BindMethod("Conjugate", &Nz::Quaterniond::Conjugate); - quaternion.BindMethod("DotProduct", &Nz::Quaterniond::DotProduct); - quaternion.BindMethod("GetConjugate", &Nz::Quaterniond::GetConjugate); - quaternion.BindMethod("GetInverse", &Nz::Quaterniond::GetInverse); - - quaternion.BindMethod("Inverse", &Nz::Quaterniond::Inverse); - quaternion.BindMethod("Magnitude", &Nz::Quaterniond::Magnitude); - - quaternion.BindMethod("SquaredMagnitude", &Nz::Quaterniond::SquaredMagnitude); - quaternion.BindMethod("ToEulerAngles", &Nz::Quaterniond::ToEulerAngles); - - quaternion.BindMethod("__tostring", &Nz::Quaterniond::ToString); - - quaternion.BindStaticMethod("Lerp", &Nz::Quaterniond::Lerp); - quaternion.BindStaticMethod("RotationBetween", &Nz::Quaterniond::RotationBetween); - quaternion.BindStaticMethod("Slerp", &Nz::Quaterniond::Slerp); - - quaternion.BindMethod("GetNormal", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int - { - double length; - - lua.Push(instance.GetNormal(&length)); - lua.Push(length); - - return 2; - }); - - quaternion.BindMethod("Normalize", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int - { - double length; - - instance.Normalize(&length); - lua.Push(1); //< instance - lua.Push(length); - - return 2; - }); - - quaternion.BindStaticMethod("Normalize", [] (Nz::LuaInstance& instance) -> int - { - int argIndex = 1; - Nz::Quaterniond quat = instance.Check(&argIndex); - - double length; - - instance.Push(Nz::Quaterniond::Normalize(quat, &length)); - instance.Push(length); - - return 2; - }); - - quaternion.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) - { - std::size_t length; - const char* wxyz = lua.CheckString(2, &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; - }); - - quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) - { - std::size_t length; - const char* wxyz = lua.CheckString(2, &length); - - if (length != 1) - return false; - - double value = lua.CheckNumber(3); - - 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; - - default: - break; - } - - return false; - }); - - /*********************************** Nz::Vector2 **********************************/ - vector2d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 2U); - - switch (argCount) - { - case 0: - case 2: - Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0)); - return true; - - case 1: - { - if (lua.IsOfType(1, Nz::LuaType_Number)) - Nz::PlacementNew(vector, lua.CheckNumber(1)); - else if (lua.IsOfType(1, "Vector2")) - Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1))); - else - break; - - return true; - } - } - - lua.Error("No matching overload for Vector2 constructor"); - return false; - }); - - vector2d.BindMethod("__tostring", &Nz::Vector2d::ToString); - - vector2d.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - long long index = lua.CheckInteger(2); - if (index < 1 || index > 2) - return false; - - lua.Push(instance[index - 1]); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xy = lua.CheckString(2, &length); - - if (length != 1) - break; - - switch (xy[0]) - { - case 'x': - lua.Push(instance.x); - return true; - - case 'y': - lua.Push(instance.y); - return true; - - default: - break; - } - break; - } - - default: - break; - } - - return false; - }); - - vector2d.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - long long index = lua.CheckInteger(2); - if (index < 1 || index > 2) - return false; - - instance[index - 1] = lua.CheckNumber(3); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xy = lua.CheckString(2, &length); - - if (length != 1) - break; - - double value = lua.CheckNumber(3); - - switch (xy[0]) - { - case 'x': - instance.x = value; - return true; - - case 'y': - instance.y = value; - return true; - - default: - break; - } - break; - } - - default: - break; - } - - return false; - }); - - /*********************************** Nz::Vector3 **********************************/ - vector3d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 3U); - - switch (argCount) - { - case 0: - case 3: - Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0)); - return true; - - case 1: - { - if (lua.IsOfType(1, Nz::LuaType_Number)) - Nz::PlacementNew(vector, lua.CheckNumber(1)); - else if (lua.IsOfType(1, "Vector2")) - Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1))); - else if (lua.IsOfType(1, "Vector3")) - Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1))); - else - break; - - return true; - } - - case 2: - { - if (lua.IsOfType(1, Nz::LuaType_Number)) - Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector2"))); - else if (lua.IsOfType(1, "Vector2")) - Nz::PlacementNew(vector, *static_cast(lua.ToUserdata(1)), lua.CheckNumber(2)); - else - break; - - return true; - } - } - - lua.Error("No matching overload for constructor"); - return false; - }); - - vector3d.BindMethod("__tostring", &Nz::Vector3d::ToString); - - vector3d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - long long index = lua.CheckInteger(2); - if (index < 1 || index > 3) - return false; - - lua.Push(instance[index - 1]); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xyz = lua.CheckString(2, &length); - - if (length != 1) - break; - - switch (xyz[0]) - { - case 'x': - lua.Push(instance.x); - return true; - - case 'y': - lua.Push(instance.y); - return true; - - case 'z': - lua.Push(instance.z); - return true; - - default: - break; - } - break; - } - - default: - break; - } - - return false; - }); - - vector3d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) - { - switch (lua.GetType(2)) - { - case Nz::LuaType_Number: - { - long long index = lua.CheckInteger(2); - if (index < 1 || index > 3) - return false; - - instance[index - 1] = lua.CheckNumber(3); - return true; - } - - case Nz::LuaType_String: - { - std::size_t length; - const char* xyz = lua.CheckString(2, &length); - - if (length != 1) - break; - - double value = lua.CheckNumber(3); - - switch (xyz[0]) - { - case 'x': - instance.x = value; - return true; - - case 'y': - instance.y = value; - return true; - - case 'z': - instance.z = value; - return true; - - default: - break; - } - break; - } - - default: - break; - } - - return false; - }); - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Math classes - */ - - void LuaBinding::RegisterMath(Nz::LuaInstance& instance) - { - eulerAngles.Register(instance); - matrix4d.Register(instance); - quaternion.Register(instance); - rect.Register(instance); - vector2d.Register(instance); - vector3d.Register(instance); - - quaternion.PushGlobalTable(instance); - { - instance.PushField("Identity", Nz::Quaterniond::Identity()); - instance.PushField("Zero", Nz::Quaterniond::Zero()); - } - instance.Pop(); - } -} diff --git a/src/NazaraSDK/LuaBinding_Renderer.cpp b/src/NazaraSDK/LuaBinding_Renderer.cpp deleted file mode 100644 index 9d52bb039..000000000 --- a/src/NazaraSDK/LuaBinding_Renderer.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2020 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 -#include - -namespace Ndk -{ - /*! - * \brief Binds Renderer module to Lua - */ - void LuaBinding::BindRenderer() - { - /*********************************** Nz::Texture ***********************************/ - texture.Inherit(abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef* - { - return reinterpret_cast(textureRef); //TODO: Make a ObjectRefCast - }); - - texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* instance, std::size_t /*argumentCount*/) - { - Nz::PlacementNew(instance, Nz::Texture::New()); - return true; - }); - - texture.BindMethod("Create", &Nz::Texture::Create, static_cast(1), 1U); - texture.BindMethod("Destroy", &Nz::Texture::Destroy); - - //texture.BindMethod("Download", &Nz::Texture::Download); - - texture.BindMethod("EnableMipmapping", &Nz::Texture::EnableMipmapping); - texture.BindMethod("EnsureMipmapsUpdate", &Nz::Texture::EnsureMipmapsUpdate); - texture.BindMethod("HasMipmaps", &Nz::Texture::HasMipmaps); - texture.BindMethod("InvalidateMipmaps", &Nz::Texture::InvalidateMipmaps); - texture.BindMethod("IsValid", &Nz::Texture::IsValid); - - texture.BindMethod("LoadFromFile", &Nz::Texture::LoadFromFile, true, Nz::ImageParams()); - //bool LoadFromImage(const Image& image, bool generateMipmaps = true); - //bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true); - //bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true); - - texture.BindMethod("LoadArrayFromFile", &Nz::Texture::LoadArrayFromFile, Nz::Vector2ui(2, 2), true, Nz::ImageParams()); - //bool LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); - //bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); - //bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); - - //bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); - //bool LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams()); - //bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); - //bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); - - texture.BindMethod("LoadFaceFromFile", &Nz::Texture::LoadFaceFromFile, Nz::ImageParams()); - //bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams()); - //bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams()); - - texture.BindMethod("SaveToFile", &Nz::Texture::SaveToFile, Nz::ImageParams()); - //bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams()); - - texture.BindMethod("SetMipmapRange", &Nz::Texture::SetMipmapRange); - - texture.BindStaticMethod("IsFormatSupported", &Nz::Texture::IsFormatSupported); - texture.BindStaticMethod("IsMipmappingSupported", &Nz::Texture::IsMipmappingSupported); - texture.BindStaticMethod("IsTypeSupported", &Nz::Texture::IsTypeSupported); - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Renderer classes - */ - void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance) - { - texture.Register(instance); - } -} diff --git a/src/NazaraSDK/LuaBinding_SDK.cpp b/src/NazaraSDK/LuaBinding_SDK.cpp deleted file mode 100644 index 64d30036c..000000000 --- a/src/NazaraSDK/LuaBinding_SDK.cpp +++ /dev/null @@ -1,320 +0,0 @@ -// Copyright (C) 2020 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 -#include - -namespace Ndk -{ - /*! - * \brief Binds SDK module to Lua - */ - - void LuaBinding::BindSDK() - { - /*********************************** Ndk::Application **********************************/ - - #ifndef NDK_SERVER - //application.SetMethod("AddWindow", &Application::AddWindow); - - application.BindMethod("EnableConsole", &Application::EnableConsole); - application.BindMethod("EnableFPSCounter", &Application::EnableFPSCounter); - - application.BindMethod("IsConsoleEnabled", &Application::IsConsoleEnabled); - application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled); - #endif - - application.BindMethod("AddWorld", [] (Nz::LuaInstance& lua, Application* instance, std::size_t /*argumentCount*/) -> int - { - lua.Push(instance->AddWorld().CreateHandle()); - return 1; - }); - - application.BindMethod("GetUpdateTime", &Application::GetUpdateTime); - application.BindMethod("Quit", &Application::Quit); - - /*********************************** Ndk::Console **********************************/ - #ifndef NDK_SERVER - console.Inherit(node, [] (ConsoleHandle* handle) -> Nz::Node* - { - return handle->GetObject(); - }); - - console.BindMethod("AddLine", &Console::AddLine, Nz::Color::White); - console.BindMethod("Clear", &Console::Clear); - console.BindMethod("GetCharacterSize", &Console::GetCharacterSize); - console.BindMethod("GetHistory", &Console::GetHistory); - console.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground); - console.BindMethod("GetInput", &Console::GetInput); - console.BindMethod("GetInputBackground", &Console::GetInputBackground); - console.BindMethod("GetSize", &Console::GetSize); - console.BindMethod("GetTextFont", &Console::GetTextFont); - - console.BindMethod("IsVisible", &Console::IsVisible); - - console.BindMethod("SendCharacter", &Console::SendCharacter); - //consoleClass.SetMethod("SendEvent", &Console::SendEvent); - - console.BindMethod("SetCharacterSize", &Console::SetCharacterSize); - console.BindMethod("SetSize", &Console::SetSize); - console.BindMethod("SetTextFont", &Console::SetTextFont); - - console.BindMethod("Show", &Console::Show, true); - #endif - - /*********************************** Ndk::Entity **********************************/ - entity.BindMethod("Enable", &Entity::Enable, true); - entity.BindMethod("GetId", &Entity::GetId); - entity.BindMethod("GetWorld", &Entity::GetWorld); - entity.BindMethod("Kill", &Entity::Kill); - entity.BindMethod("IsEnabled", &Entity::IsEnabled); - entity.BindMethod("IsValid", &Entity::IsValid); - entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents); - entity.BindMethod("__tostring", &EntityHandle::ToString); - - entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int - { - ComponentBinding* binding = QueryComponentIndex(instance); - - return binding->adder(instance, handle); - }); - - entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int - { - ComponentBinding* binding = QueryComponentIndex(instance); - - return binding->getter(instance, handle->GetComponent(binding->index)); - }); - - entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int - { - ComponentBinding* binding = QueryComponentIndex(instance); - - handle->RemoveComponent(binding->index); - return 0; - }); - - /*********************************** Ndk::NodeComponent **********************************/ - nodeComponent.Inherit(node, [] (NodeComponentHandle* handle) -> Nz::Node* - { - return handle->GetObject(); - }); - - /*********************************** Ndk::VelocityComponent **********************************/ - velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) - { - std::size_t length; - const char* member = lua.CheckString(2, &length); - - if (std::strcmp(member, "Linear") == 0) - { - lua.Push(instance->linearVelocity); - return true; - } - - return false; - }); - - velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) - { - std::size_t length; - const char* member = lua.CheckString(2, &length); - - int argIndex = 3; - if (std::strcmp(member, "Linear") == 0) - { - instance->linearVelocity = lua.Check(&argIndex); - return true; - } - - return false; - }); - - /*********************************** Ndk::World **********************************/ - world.BindMethod("CreateEntity", &World::CreateEntity); - world.BindMethod("CreateEntities", &World::CreateEntities); - world.BindMethod("Clear", &World::Clear); - - - #ifndef NDK_SERVER - /*********************************** Ndk::CameraComponent **********************************/ - cameraComponent.Inherit(abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer* - { - return handle->GetObject(); - }); - - cameraComponent.BindMethod("GetFOV", &Ndk::CameraComponent::GetFOV); - cameraComponent.BindMethod("GetLayer", &Ndk::CameraComponent::GetLayer); - - cameraComponent.BindMethod("SetFOV", &Ndk::CameraComponent::SetFOV); - cameraComponent.BindMethod("SetLayer", &Ndk::CameraComponent::SetLayer); - cameraComponent.BindMethod("SetProjectionType", &Ndk::CameraComponent::SetProjectionType); - cameraComponent.BindMethod("SetSize", (void(Ndk::CameraComponent::*)(const Nz::Vector2f&)) &Ndk::CameraComponent::SetSize); - //cameraComponent.BindMethod("SetTarget", &Ndk::CameraComponent::SetTarget); - cameraComponent.BindMethod("SetTargetRegion", &Ndk::CameraComponent::SetTargetRegion); - cameraComponent.BindMethod("SetViewport", &Ndk::CameraComponent::SetViewport); - cameraComponent.BindMethod("SetZFar", &Ndk::CameraComponent::SetZFar); - cameraComponent.BindMethod("SetZNear", &Ndk::CameraComponent::SetZNear); - - /*********************************** Ndk::GraphicsComponent **********************************/ - graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int - { - /* - void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0); - void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0); - */ - - std::size_t argCount = std::min(argumentCount, 3U); - - switch (argCount) - { - case 1: - { - int argIndex = 2; - instance->Attach(lua.Check(&argIndex)); - return 0; - } - - case 2: - { - int argIndex = 2; - Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); - - if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - { - int renderOrder = lua.Check(&argIndex); - - instance->Attach(renderable, renderOrder); - } - else if (lua.IsOfType(argIndex, "Matrix4")) - { - Nz::Matrix4f localMatrix = lua.Check(&argIndex); - - instance->Attach(renderable, localMatrix); - } - else - break; - - return 0; - } - - case 3: - { - int argIndex = 2; - Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); - Nz::Matrix4f localMatrix = lua.Check(&argIndex); - int renderOrder = lua.Check(&argIndex); - - instance->Attach(renderable, localMatrix, renderOrder); - return 0; - } - } - - lua.Error("No matching overload for method GetMemoryUsage"); - return 0; - }); - #endif - - - // Components functions - m_componentBinding.resize(BaseComponent::GetMaxComponentIndex()); - - BindComponent("Node"); - BindComponent("Velocity"); - - #ifndef NDK_SERVER - BindComponent("Camera"); - BindComponent("Graphics"); - #endif - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the SDK classes - */ - - void LuaBinding::RegisterSDK(Nz::LuaInstance& instance) - { - // Classes - application.Register(instance); - entity.Register(instance); - nodeComponent.Register(instance); - velocityComponent.Register(instance); - world.Register(instance); - - #ifndef NDK_SERVER - cameraComponent.Register(instance); - console.Register(instance); - graphicsComponent.Register(instance); - #endif - - // Enums - - // ComponentType (fake enumeration to expose component indexes) - instance.PushTable(0, m_componentBinding.size()); - { - for (const ComponentBinding& entry : m_componentBinding) - { - if (entry.name.IsEmpty()) - continue; - - instance.PushField(entry.name, entry.index); - } - } - instance.SetGlobal("ComponentType"); - } - - /*! - * \brief Gets the index of the component - * \return A pointer to the binding linked to a component - * - * \param instance Lua instance that will interact with the component - * \param argIndex Index of the component - */ - - LuaBinding::ComponentBinding* LuaBinding::QueryComponentIndex(Nz::LuaInstance& instance, int argIndex) - { - switch (instance.GetType(argIndex)) - { - case Nz::LuaType_Number: - { - ComponentIndex componentIndex = instance.Check(&argIndex); - if (componentIndex > m_componentBinding.size()) - { - instance.Error("Invalid component index"); - return nullptr; - } - - ComponentBinding& binding = m_componentBinding[componentIndex]; - if (binding.name.IsEmpty()) - { - instance.Error("Invalid component index"); - return nullptr; - } - - return &binding; - } - - case Nz::LuaType_String: - { - const char* key = instance.CheckString(argIndex); - auto it = m_componentBindingByName.find(key); - if (it == m_componentBindingByName.end()) - { - instance.Error("Invalid component name"); - return nullptr; - } - - return &m_componentBinding[it->second]; - } - - default: - break; - } - - instance.Error("Invalid component index at #" + Nz::String::Number(argIndex)); - return nullptr; - } -}