From baf4cb0e168cb040ae3c2ad5963af7d444c15383 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 19 Oct 2016 22:48:46 +0200 Subject: [PATCH 01/58] Lua/LuaClass: Add Reset method and default constructor --- include/Nazara/Lua/LuaClass.hpp | 4 ++++ include/Nazara/Lua/LuaClass.inl | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/Nazara/Lua/LuaClass.hpp b/include/Nazara/Lua/LuaClass.hpp index 567c3de7c..1d4aea327 100644 --- a/include/Nazara/Lua/LuaClass.hpp +++ b/include/Nazara/Lua/LuaClass.hpp @@ -34,6 +34,7 @@ namespace Nz using StaticIndexFunc = std::function; using StaticFunc = std::function; + LuaClass() = default; LuaClass(const String& name); void BindDefaultConstructor(); @@ -50,6 +51,9 @@ namespace Nz template void Inherit(LuaClass

& parent); template void Inherit(LuaClass

& parent, ConvertToParent

convertFunc); + void Reset(); + void Reset(const String& name); + void Register(LuaInstance& lua); void PushGlobalTable(LuaInstance& lua); diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl index ea53cf0cd..3d0befeaa 100644 --- a/include/Nazara/Lua/LuaClass.inl +++ b/include/Nazara/Lua/LuaClass.inl @@ -10,10 +10,9 @@ namespace Nz { template - LuaClass::LuaClass(const String& name) : - m_info(new ClassInfo) + LuaClass::LuaClass(const String& name) { - m_info->name = name; + Reset(name); } template @@ -58,6 +57,20 @@ namespace Nz }); } + + template + void LuaClass::Reset() + { + m_info.reset(); + } + + template + void LuaClass::Reset(const String& name) + { + m_info = std::make_shared(); + m_info->name = name; + } + template void LuaClass::Register(LuaInstance& lua) { From 6885e99ee7e5864d57439f81be16219e1f313b41 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 20 Oct 2016 17:24:22 +0200 Subject: [PATCH 02/58] SDK/Lua: Bind Matrix4 --- SDK/include/NDK/LuaAPI.inl | 256 +++++++++++++++++++++----------- SDK/include/NDK/LuaBinding.hpp | 1 + SDK/src/NDK/LuaBinding.cpp | 1 + SDK/src/NDK/LuaBinding_Math.cpp | 59 ++++++++ SDK/src/NDK/LuaBinding_SDK.cpp | 58 ++++++++ 5 files changed, 290 insertions(+), 85 deletions(-) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index 6f1b73234..e0682853a 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -143,6 +143,86 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param address Resulting IP address + */ + + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag) + { + switch (instance.GetType(index)) + { + case Nz::LuaType_String: + address->BuildFromAddress(instance.CheckString(index)); + return 1; + + default: + *address = *static_cast(instance.CheckUserdata(index, "IpAddress")); + return 1; + } + } + + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param quat Resulting quaternion + */ + + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Matrix4d* mat, TypeTag) + { + switch (instance.GetType(index)) + { + case Nz::LuaType_Table: + { + double values[16]; + for (std::size_t i = 0; i < 16; ++i) + { + instance.PushInteger(i + 1); + instance.GetTable(); + + values[i] = instance.CheckNumber(-1); + instance.Pop(); + } + + mat->Set(values); + return 1; + } + + default: + { + if (instance.IsOfType(index, "Matrix4")) + mat->Set(*static_cast(instance.ToUserdata(index))); + + return 1; + } + } + } + + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param quat Resulting quaternion + */ + + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Matrix4f* mat, TypeTag) + { + Matrix4d matDouble; + unsigned int ret = LuaImplQueryArg(instance, index, &matDouble, TypeTag()); + + mat->Set(matDouble); + return ret; + } + /*! * \brief Queries arguments for Lua * \return 1 in case of success @@ -165,6 +245,53 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param quat Resulting quaternion + */ + + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag) + { + switch (instance.GetType(index)) + { + case Nz::LuaType_Table: + quat->Set(instance.CheckField("w", index), instance.CheckField("x", index), instance.CheckField("y", index), instance.CheckField("z", index)); + return 1; + + default: + { + if (instance.IsOfType(index, "EulerAngles")) + quat->Set(*static_cast(instance.ToUserdata(index))); + else + quat->Set(*static_cast(instance.CheckUserdata(index, "Quaternion"))); + + return 1; + } + } + } + + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param quat Resulting quaternion + */ + + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag) + { + Quaterniond quatDouble; + unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag()); + + quat->Set(quatDouble); + return ret; + } + /*! * \brief Queries arguments for Lua * \return 1 in case of success @@ -222,76 +349,6 @@ namespace Nz return ret; } - /*! - * \brief Queries arguments for Lua - * \return 1 in case of success - * - * \param instance Lua instance to interact with - * \param index Index type - * \param quat Resulting quaternion - */ - - inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag) - { - switch (instance.GetType(index)) - { - case Nz::LuaType_Table: - quat->Set(instance.CheckField("w", index), instance.CheckField("x", index), instance.CheckField("y", index), instance.CheckField("z", index)); - return 1; - - default: - { - if (instance.IsOfType(index, "EulerAngles")) - quat->Set(*static_cast(instance.ToUserdata(index))); - else - quat->Set(*static_cast(instance.CheckUserdata(index, "Quaternion"))); - - return 1; - } - } - } - - /*! - * \brief Queries arguments for Lua - * \return 1 in case of success - * - * \param instance Lua instance to interact with - * \param index Index type - * \param quat Resulting quaternion - */ - - inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag) - { - Quaterniond quatDouble; - unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag()); - - quat->Set(quatDouble); - return ret; - } - - /*! - * \brief Queries arguments for Lua - * \return 1 in case of success - * - * \param instance Lua instance to interact with - * \param index Index type - * \param address Resulting IP address - */ - - inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag) - { - switch (instance.GetType(index)) - { - case Nz::LuaType_String: - address->BuildFromAddress(instance.CheckString(index)); - return 1; - - default: - *address = *static_cast(instance.CheckUserdata(index, "IpAddress")); - return 1; - } - } - /*! * \brief Queries arguments for Lua * \return 1 in case of success @@ -473,6 +530,7 @@ namespace Nz *renderable = *static_cast(instance.CheckUserdata(index, "InstancedRenderable")); else *renderable = *static_cast(instance.CheckUserdata(index, "Model")); + return 1; } @@ -619,6 +677,48 @@ namespace Nz return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting IP address + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress&& val, TypeTag) + { + instance.PushInstance("IpAddress", val); + return 1; + } + + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting rectangle + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, Matrix4d&& val, TypeTag) + { + instance.PushInstance("Matrix4", val); + return 1; + } + + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting rectangle + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, Matrix4f&& val, TypeTag) + { + instance.PushInstance("Matrix4", val); + return 1; + } + /*! * \brief Replies by value for Lua * \return 1 in case of success @@ -647,20 +747,6 @@ namespace Nz return 1; } - /*! - * \brief Replies by value for Lua - * \return 1 in case of success - * - * \param instance Lua instance to interact with - * \param val Resulting IP address - */ - - inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress&& val, TypeTag) - { - instance.PushInstance("IpAddress", val); - return 1; - } - /*! * \brief Replies by value for Lua * \return 1 in case of success @@ -669,7 +755,7 @@ namespace Nz * \param val Resulting rectangle */ - inline int LuaImplReplyVal(const LuaInstance& instance, Rectd&& val, TypeTag) + inline int LuaImplReplyVal(const LuaInstance& instance, Rectd&& val, TypeTag) { instance.PushInstance("Rect", val); return 1; diff --git a/SDK/include/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp index cb4fc24e5..6b4c15fc8 100644 --- a/SDK/include/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -45,6 +45,7 @@ namespace Ndk // Math Nz::LuaClass eulerAnglesClass; + Nz::LuaClass matrix4dClass; Nz::LuaClass quaternionClass; Nz::LuaClass rectClass; Nz::LuaClass vector2dClass; diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index 822654a39..a571c91df 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -23,6 +23,7 @@ namespace Ndk // Math eulerAnglesClass("EulerAngles"), + matrix4dClass("Matrix4"), quaternionClass("Quaternion"), rectClass("Rect"), vector2dClass("Vector2"), diff --git a/SDK/src/NDK/LuaBinding_Math.cpp b/SDK/src/NDK/LuaBinding_Math.cpp index f65259f50..0c6ff3b77 100644 --- a/SDK/src/NDK/LuaBinding_Math.cpp +++ b/SDK/src/NDK/LuaBinding_Math.cpp @@ -154,6 +154,64 @@ namespace Ndk return false; }); + + /*********************************** Nz::Matrix4 **********************************/ + matrix4dClass.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 (std::size_t 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; + }); + + matrix4dClass.BindMethod("__tostring", &Nz::Matrix4d::ToString); + + matrix4dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) + { + int argIndex = 1; + std::size_t index = lua.Check(&argIndex); + if (index < 1 || index > 16) + return false; + + lua.Push(instance[index - 1]); + return true; + }); + + matrix4dClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) + { + int argIndex = 1; + std::size_t index = lua.Check(&argIndex); + if (index < 1 || index > 16) + return false; + + instance[index - 1] = lua.CheckNumber(argIndex); + + return true; + }); + /*********************************** Nz::Rect **********************************/ rectClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect, std::size_t argumentCount) { @@ -694,6 +752,7 @@ namespace Ndk void LuaBinding::RegisterMath(Nz::LuaInstance& instance) { eulerAnglesClass.Register(instance); + matrix4dClass.Register(instance); quaternionClass.Register(instance); rectClass.Register(instance); vector2dClass.Register(instance); diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index af5cca5a8..fda6f7bb9 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -139,6 +139,64 @@ namespace Ndk #ifndef NDK_SERVER /*********************************** Ndk::GraphicsComponent **********************************/ + graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent *gfxComponent) -> int + { + /* + void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0); + void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0); + */ + + unsigned int argCount = std::min(lua.GetStackTop(), 1U); + + switch (argCount) + { + case 1: + { + int argIndex = 1; + gfxComponent->Attach(lua.Check(&argIndex)); + return 0; + } + + case 2: + { + int index = 1; + Nz::InstancedRenderableRef renderable = lua.Check(&index); + + if (lua.IsOfType(index, Nz::LuaType_Number)) + { + int renderOrder = lua.Check(&index); + + gfxComponent->Attach(renderable, renderOrder); + } + else if (lua.IsOfType(index, "Matrix4")) + { + Nz::Matrix4f localMatrix = lua.Check(&index); + int renderOrder = lua.Check(&index); + + gfxComponent->Attach(renderable, localMatrix, renderOrder); + } + else + break; + + return 0; + } + + case 3: + { + int index = 1; + Nz::InstancedRenderableRef renderable = lua.Check(&index); + Nz::Matrix4f localMatrix = lua.Check(&index); + int renderOrder = lua.Check(&index); + + gfxComponent->Attach(renderable, localMatrix, renderOrder); + return 0; + } + } + + lua.Error("No matching overload for method GetMemoryUsage"); + return 0; + }); + graphicsComponent.BindMethod("Attach", (void(Ndk::GraphicsComponent::*)(Nz::InstancedRenderableRef, int)) &GraphicsComponent::Attach, 0); #endif From 3c29bfe516b3c4f0ed9848511b022139391ca914 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 20 Oct 2016 23:44:12 +0200 Subject: [PATCH 03/58] Lua/LuaInstance: Make ArgCheck and ArgError const --- include/Nazara/Lua/LuaInstance.hpp | 8 ++++---- src/Nazara/Lua/LuaInstance.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/Nazara/Lua/LuaInstance.hpp b/include/Nazara/Lua/LuaInstance.hpp index c6d7c6385..974cb9579 100644 --- a/include/Nazara/Lua/LuaInstance.hpp +++ b/include/Nazara/Lua/LuaInstance.hpp @@ -34,10 +34,10 @@ namespace Nz inline LuaInstance(LuaInstance&& instance) noexcept; ~LuaInstance(); - void ArgCheck(bool condition, unsigned int argNum, const char* error); - void ArgCheck(bool condition, unsigned int argNum, const String& error); - int ArgError(unsigned int argNum, const char* error); - int ArgError(unsigned int argNum, const String& error); + void ArgCheck(bool condition, unsigned int argNum, const char* error) const; + void ArgCheck(bool condition, unsigned int argNum, const String& error) const; + int ArgError(unsigned int argNum, const char* error) const; + int ArgError(unsigned int argNum, const String& error) const; bool Call(unsigned int argCount); bool Call(unsigned int argCount, unsigned int resultCount); diff --git a/src/Nazara/Lua/LuaInstance.cpp b/src/Nazara/Lua/LuaInstance.cpp index f73c4a207..5162645b2 100644 --- a/src/Nazara/Lua/LuaInstance.cpp +++ b/src/Nazara/Lua/LuaInstance.cpp @@ -149,22 +149,22 @@ namespace Nz lua_close(m_state); } - void LuaInstance::ArgCheck(bool condition, unsigned int argNum, const char* error) + void LuaInstance::ArgCheck(bool condition, unsigned int argNum, const char* error) const { luaL_argcheck(m_state, condition, argNum, error); } - void LuaInstance::ArgCheck(bool condition, unsigned int argNum, const String& error) + void LuaInstance::ArgCheck(bool condition, unsigned int argNum, const String& error) const { luaL_argcheck(m_state, condition, argNum, error.GetConstBuffer()); } - int LuaInstance::ArgError(unsigned int argNum, const char* error) + int LuaInstance::ArgError(unsigned int argNum, const char* error) const { return luaL_argerror(m_state, argNum, error); } - int LuaInstance::ArgError(unsigned int argNum, const String& error) + int LuaInstance::ArgError(unsigned int argNum, const String& error) const { return luaL_argerror(m_state, argNum, error.GetConstBuffer()); } From a7d2d8cddde5b175ce020940d0219474c6803994 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 20 Oct 2016 23:53:22 +0200 Subject: [PATCH 04/58] Utility/AbstractImage: Inherit RefCounted --- include/Nazara/Renderer/Texture.hpp | 3 +-- include/Nazara/Utility/AbstractImage.hpp | 11 ++++++++++- include/Nazara/Utility/AbstractImage.inl | 16 ++++++++++++++++ include/Nazara/Utility/Image.hpp | 3 +-- src/Nazara/Utility/Image.cpp | 2 +- 5 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 include/Nazara/Utility/AbstractImage.inl diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index 2fd368b53..e789dbd91 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -31,7 +30,7 @@ namespace Nz struct TextureImpl; - class NAZARA_RENDERER_API Texture : public AbstractImage, public RefCounted, public Resource + class NAZARA_RENDERER_API Texture : public AbstractImage, public Resource { friend TextureLibrary; friend TextureManager; diff --git a/include/Nazara/Utility/AbstractImage.hpp b/include/Nazara/Utility/AbstractImage.hpp index 93821e105..ffeacbca4 100644 --- a/include/Nazara/Utility/AbstractImage.hpp +++ b/include/Nazara/Utility/AbstractImage.hpp @@ -8,6 +8,7 @@ #define NAZARA_ABSTRACTIMAGE_HPP #include +#include #include #include #include @@ -16,10 +17,16 @@ namespace Nz { - class NAZARA_UTILITY_API AbstractImage + class AbstractImage; + + using AbstractImageConstRef = ObjectRef; + using AbstractImageRef = ObjectRef; + + class NAZARA_UTILITY_API AbstractImage : public RefCounted { public: AbstractImage() = default; + inline AbstractImage(const AbstractImage& image); virtual ~AbstractImage(); UInt8 GetBytesPerPixel() const; @@ -43,4 +50,6 @@ namespace Nz }; } +#include + #endif // NAZARA_IMAGE_HPP diff --git a/include/Nazara/Utility/AbstractImage.inl b/include/Nazara/Utility/AbstractImage.inl new file mode 100644 index 000000000..d3f50fc84 --- /dev/null +++ b/include/Nazara/Utility/AbstractImage.inl @@ -0,0 +1,16 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + inline AbstractImage::AbstractImage(const AbstractImage& image) : + RefCounted() + { + } +} + +#include diff --git a/include/Nazara/Utility/Image.hpp b/include/Nazara/Utility/Image.hpp index d936ee4d8..029157885 100644 --- a/include/Nazara/Utility/Image.hpp +++ b/include/Nazara/Utility/Image.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -47,7 +46,7 @@ namespace Nz using ImageRef = ObjectRef; using ImageSaver = ResourceSaver; - class NAZARA_UTILITY_API Image : public AbstractImage, public RefCounted, public Resource + class NAZARA_UTILITY_API Image : public AbstractImage, public Resource { friend ImageLibrary; friend ImageLoader; diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index 4b780eef1..160c2ac90 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -52,7 +52,7 @@ namespace Nz } Image::Image(const Image& image) : - RefCounted(), + AbstractImage(image), Resource(), m_sharedImage(image.m_sharedImage) { From 7a0a8543c37dc4d450988e7efe0bdb8d51f09ea7 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 00:35:44 +0200 Subject: [PATCH 05/58] Renderer/Texture: Add override specifier --- include/Nazara/Renderer/Texture.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index e789dbd91..6d52beb6f 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -53,16 +53,16 @@ namespace Nz void EnsureMipmapsUpdate() const; - unsigned int GetDepth(UInt8 level = 0) const; - PixelFormatType GetFormat() const; - unsigned int GetHeight(UInt8 level = 0) const; - UInt8 GetLevelCount() const; - UInt8 GetMaxLevel() const; - std::size_t GetMemoryUsage() const; - std::size_t GetMemoryUsage(UInt8 level) const; - Vector3ui GetSize(UInt8 level = 0) const; - ImageType GetType() const; - unsigned int GetWidth(UInt8 level = 0) const; + unsigned int GetDepth(UInt8 level = 0) const override; + PixelFormatType GetFormat() const override; + unsigned int GetHeight(UInt8 level = 0) const override; + UInt8 GetLevelCount() const override; + UInt8 GetMaxLevel() const override; + std::size_t GetMemoryUsage() const override; + std::size_t GetMemoryUsage(UInt8 level) const override; + Vector3ui GetSize(UInt8 level = 0) const override; + ImageType GetType() const override; + unsigned int GetWidth(UInt8 level = 0) const override; bool HasMipmaps() const; @@ -101,9 +101,9 @@ namespace Nz bool Update(const Image& image, UInt8 level = 0); bool Update(const Image& image, const Boxui& box, UInt8 level = 0); bool Update(const Image& image, const Rectui& rect, unsigned int z = 0, UInt8 level = 0); - bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0); - bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0); - bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0); + bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override; + bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override; + bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override; // Fonctions OpenGL unsigned int GetOpenGLID() const; From 0c6f7131a6765e2cb5306ac75bf8db0433361984 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 01:58:37 +0200 Subject: [PATCH 06/58] Lua/LuaInstance: Fix warning when using default parameters --- include/Nazara/Lua/LuaInstance.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Nazara/Lua/LuaInstance.inl b/include/Nazara/Lua/LuaInstance.inl index c5cdc3b6b..e2b2c991f 100644 --- a/include/Nazara/Lua/LuaInstance.inl +++ b/include/Nazara/Lua/LuaInstance.inl @@ -266,7 +266,7 @@ namespace Nz template static unsigned int Process(const LuaInstance& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs) { - return LuaImplQueryArg(instance, argIndex, &std::get(args), std::get() - N + FirstDefArg - 1>(defArgs), TypeTag()); + return LuaImplQueryArg(instance, argIndex, &std::get(args), std::get() - N - 1>(defArgs), TypeTag()); } }; From 4cd6bdd14ae8b9ae6580a42de3e1efaad442e228 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 02:00:35 +0200 Subject: [PATCH 07/58] Sdk/Lua: Bind Texture class --- SDK/include/NDK/LuaAPI.inl | 67 +++++++++++++++++++++++++++++ SDK/include/NDK/LuaBinding.hpp | 5 ++- SDK/src/NDK/LuaBinding.cpp | 3 ++ SDK/src/NDK/LuaBinding_Renderer.cpp | 53 ++++++++++++++++++++++- 4 files changed, 125 insertions(+), 3 deletions(-) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index e0682853a..154c20a59 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -143,6 +143,24 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param params Resulting parameters for an image + */ + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, ImageParams* params, TypeTag) + { + instance.CheckType(index, Nz::LuaType_Table); + + params->levelCount = instance.CheckField("LevelCount"); + params->loadFormat = instance.CheckField("LoadFormat"); + + return 1; + } + /*! * \brief Queries arguments for Lua * \return 1 in case of success @@ -614,6 +632,22 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param fontRef Resulting reference to a font + */ + + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, TextureRef* textureRef, TypeTag) + { + *textureRef = *static_cast(instance.CheckUserdata(index, "Texture")); + + return 1; + } + #endif /*! @@ -630,6 +664,25 @@ namespace Nz return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting color + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, Color&& val, TypeTag) + { + instance.PushTable(); + instance.PushField("r", val.r); + instance.PushField("g", val.g); + instance.PushField("b", val.b); + instance.PushField("a", val.a); + + return 1; + } + /*! * \brief Replies by value for Lua * \return 1 in case of success @@ -803,6 +856,20 @@ namespace Nz return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param handle Resulting texture + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, TextureRef&& handle, TypeTag) + { + instance.PushInstance("Texture", handle); + return 1; + } + /*! * \brief Replies by value for Lua * \return 1 in case of success diff --git a/SDK/include/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp index 6b4c15fc8..61df55782 100644 --- a/SDK/include/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -56,7 +56,7 @@ namespace Ndk Nz::LuaClass ipAddressClass; // Utility - Nz::LuaClass abstractImage; + Nz::LuaClass abstractImage; Nz::LuaClass fontClass; Nz::LuaClass nodeClass; @@ -78,6 +78,9 @@ namespace Ndk Nz::LuaClass instancedRenderable; Nz::LuaClass modelClass; + // Renderer + Nz::LuaClass texture; + // SDK Nz::LuaClass consoleClass; Nz::LuaClass graphicsComponent; diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index a571c91df..10d6e2e42 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -58,6 +58,9 @@ namespace Ndk instancedRenderable("InstancedRenderable"), modelClass("Model"), + // Renderer + texture("Texture"), + // SDK consoleClass("Console"), graphicsComponent("GraphicsComponent") diff --git a/SDK/src/NDK/LuaBinding_Renderer.cpp b/SDK/src/NDK/LuaBinding_Renderer.cpp index 79f1780a3..8ffe76c69 100644 --- a/SDK/src/NDK/LuaBinding_Renderer.cpp +++ b/SDK/src/NDK/LuaBinding_Renderer.cpp @@ -10,9 +10,58 @@ namespace Ndk /*! * \brief Binds Renderer module to Lua */ - void LuaBinding::BindRenderer() { + /*********************************** Nz::Texture ***********************************/ + texture.Inherit(abstractImage, [] (Nz::TextureRef* texture) -> Nz::AbstractImageRef* + { + return reinterpret_cast(texture); //TODO: Make a ObjectRefCast + }); + + texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* texture, std::size_t /*argumentCount*/) + { + Nz::PlacementNew(texture, 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); } /*! @@ -20,8 +69,8 @@ namespace Ndk * * \param instance Lua instance that will interact with the Renderer classes */ - void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance) { + texture.Register(instance); } } \ No newline at end of file From 350c7dad5925730ded0fcbb0d58b586b3146c61f Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 02:00:51 +0200 Subject: [PATCH 08/58] Sdk/Lua: Bind Sprite class --- SDK/include/NDK/LuaAPI.inl | 50 ++++++++++++++++------------- SDK/include/NDK/LuaBinding.hpp | 1 + SDK/src/NDK/LuaBinding.cpp | 1 + SDK/src/NDK/LuaBinding_Graphics.cpp | 30 +++++++++++++++++ 4 files changed, 59 insertions(+), 23 deletions(-) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index 154c20a59..3697532f4 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -544,10 +544,14 @@ namespace Nz inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, InstancedRenderableRef* renderable, TypeTag) { - if (instance.IsOfType(index, "InstancedRenderable")) - *renderable = *static_cast(instance.CheckUserdata(index, "InstancedRenderable")); + if (instance.IsOfType(index, "InstancedRenderable") || + instance.IsOfType(index, "Model") || + instance.IsOfType(index, "Sprite")) + { + *renderable = *static_cast(instance.ToUserdata(index)); + } else - *renderable = *static_cast(instance.CheckUserdata(index, "Model")); + instance.ArgError(index, "is not a InstancedRenderable instance"); return 1; } @@ -650,20 +654,6 @@ namespace Nz #endif - /*! - * \brief Replies by value for Lua - * \return 1 in case of success - * - * \param instance Lua instance to interact with - * \param val Resulting euler angles - */ - - inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesd&& val, TypeTag) - { - instance.PushInstance("EulerAngles", val); - return 1; - } - /*! * \brief Replies by value for Lua * \return 1 in case of success @@ -691,6 +681,20 @@ namespace Nz * \param val Resulting euler angles */ + inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesd&& val, TypeTag) + { + instance.PushInstance("EulerAngles", val); + return 1; + } + + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting euler angles + */ + inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesf&& val, TypeTag) { instance.PushInstance("EulerAngles", val); @@ -847,12 +851,12 @@ namespace Nz * \return 1 in case of success * * \param instance Lua instance to interact with - * \param val Resulting vector2D + * \param handle Resulting texture */ - inline int LuaImplReplyVal(const LuaInstance& instance, Vector2d&& val, TypeTag) + inline int LuaImplReplyVal(const LuaInstance& instance, TextureRef&& handle, TypeTag) { - instance.PushInstance("Vector2", val); + instance.PushInstance("Texture", handle); return 1; } @@ -861,12 +865,12 @@ namespace Nz * \return 1 in case of success * * \param instance Lua instance to interact with - * \param handle Resulting texture + * \param val Resulting vector2D */ - inline int LuaImplReplyVal(const LuaInstance& instance, TextureRef&& handle, TypeTag) + inline int LuaImplReplyVal(const LuaInstance& instance, Vector2d&& val, TypeTag) { - instance.PushInstance("Texture", handle); + instance.PushInstance("Vector2", val); return 1; } diff --git a/SDK/include/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp index 61df55782..a82bae0c4 100644 --- a/SDK/include/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -77,6 +77,7 @@ namespace Ndk // Graphics Nz::LuaClass instancedRenderable; Nz::LuaClass modelClass; + Nz::LuaClass spriteClass; // Renderer Nz::LuaClass texture; diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index 10d6e2e42..784306fc4 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -57,6 +57,7 @@ namespace Ndk // Graphics instancedRenderable("InstancedRenderable"), modelClass("Model"), + spriteClass("Sprite"), // Renderer texture("Texture"), diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index af319417e..fdae54c56 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -42,6 +42,35 @@ namespace Ndk //modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence); modelClass.BindMethod("SetSkin", &Nz::Model::SetSkin); modelClass.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount); + + /*********************************** Nz::Sprite ***********************************/ + spriteClass.Inherit(instancedRenderable, [] (Nz::SpriteRef* sprite) -> Nz::InstancedRenderableRef* + { + return reinterpret_cast(sprite); //TODO: Make a ObjectRefCast + }); + + spriteClass.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* sprite, std::size_t /*argumentCount*/) + { + Nz::PlacementNew(sprite, Nz::Sprite::New()); + return true; + }); + + spriteClass.BindMethod("GetColor", &Nz::Sprite::GetColor); + spriteClass.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor); + //spriteClass.BindMethod("GetMaterial", &Nz::Sprite::GetMaterial); + spriteClass.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin); + spriteClass.BindMethod("GetSize", &Nz::Sprite::GetSize); + spriteClass.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords); + + spriteClass.BindMethod("SetColor", &Nz::Sprite::SetColor); + spriteClass.BindMethod("SetCornerColor", &Nz::Sprite::SetCornerColor); + spriteClass.BindMethod("SetDefaultMaterial", &Nz::Sprite::SetDefaultMaterial); + //spriteClass.BindMethod("SetMaterial", &Nz::Sprite::SetMaterial, true); + spriteClass.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin); + spriteClass.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize); + spriteClass.BindMethod("SetTexture", &Nz::Sprite::SetTexture, true); + spriteClass.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords); + spriteClass.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect); } /*! @@ -54,5 +83,6 @@ namespace Ndk { instancedRenderable.Register(instance); modelClass.Register(instance); + spriteClass.Register(instance); } } \ No newline at end of file From 6d597aa2bc00de6c541b5fb58dcb6f735df4b379 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 02:01:08 +0200 Subject: [PATCH 09/58] Sdk/Application: Cleanup --- SDK/src/NDK/Application.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/SDK/src/NDK/Application.cpp b/SDK/src/NDK/Application.cpp index 46e1db13d..f184d5b0b 100644 --- a/SDK/src/NDK/Application.cpp +++ b/SDK/src/NDK/Application.cpp @@ -98,9 +98,7 @@ namespace Ndk ++it; } - #endif - #ifndef NDK_SERVER if (m_exitOnClosedWindows && !hasAtLeastOneActiveWindow) return false; #endif From 6b6608ecccebc13655105b26cd84b323abf897d9 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 02:03:31 +0200 Subject: [PATCH 10/58] Sdk/LuaBinding: Remove "class" suffix from classes instances --- SDK/include/NDK/LuaBinding.hpp | 42 ++++---- SDK/src/NDK/LuaBinding.cpp | 42 ++++---- SDK/src/NDK/LuaBinding_Audio.cpp | 52 ++++----- SDK/src/NDK/LuaBinding_Core.cpp | 158 ++++++++++++++-------------- SDK/src/NDK/LuaBinding_Graphics.cpp | 54 +++++----- SDK/src/NDK/LuaBinding_Math.cpp | 60 +++++------ SDK/src/NDK/LuaBinding_Network.cpp | 36 +++---- SDK/src/NDK/LuaBinding_SDK.cpp | 68 ++++++------ SDK/src/NDK/LuaBinding_Utility.cpp | 128 +++++++++++----------- 9 files changed, 320 insertions(+), 320 deletions(-) diff --git a/SDK/include/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp index a82bae0c4..2b3d8d3a0 100644 --- a/SDK/include/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -38,52 +38,52 @@ namespace Ndk void RegisterClasses(Nz::LuaInstance& instance); // Core - Nz::LuaClass clockClass; - Nz::LuaClass directoryClass; - Nz::LuaClass fileClass; - Nz::LuaClass streamClass; + Nz::LuaClass clock; + Nz::LuaClass directory; + Nz::LuaClass file; + Nz::LuaClass stream; // Math - Nz::LuaClass eulerAnglesClass; - Nz::LuaClass matrix4dClass; - Nz::LuaClass quaternionClass; - Nz::LuaClass rectClass; - Nz::LuaClass vector2dClass; - Nz::LuaClass vector3dClass; + Nz::LuaClass eulerAngles; + Nz::LuaClass matrix4d; + Nz::LuaClass quaternion; + Nz::LuaClass rect; + Nz::LuaClass vector2d; + Nz::LuaClass vector3d; // Network - Nz::LuaClass abstractSocketClass; - Nz::LuaClass ipAddressClass; + Nz::LuaClass abstractSocket; + Nz::LuaClass ipAddress; // Utility Nz::LuaClass abstractImage; - Nz::LuaClass fontClass; - Nz::LuaClass nodeClass; + Nz::LuaClass font; + Nz::LuaClass node; // SDK Nz::LuaClass application; - Nz::LuaClass entityClass; + Nz::LuaClass entity; Nz::LuaClass nodeComponent; Nz::LuaClass velocityComponent; - Nz::LuaClass worldClass; + Nz::LuaClass world; #ifndef NDK_SERVER // Audio - Nz::LuaClass musicClass; - Nz::LuaClass soundClass; + Nz::LuaClass music; + Nz::LuaClass sound; Nz::LuaClass soundBuffer; Nz::LuaClass soundEmitter; // Graphics Nz::LuaClass instancedRenderable; - Nz::LuaClass modelClass; - Nz::LuaClass spriteClass; + Nz::LuaClass model; + Nz::LuaClass sprite; // Renderer Nz::LuaClass texture; // SDK - Nz::LuaClass consoleClass; + Nz::LuaClass console; Nz::LuaClass graphicsComponent; #endif diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index 784306fc4..c0399ab3a 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -16,54 +16,54 @@ namespace Ndk LuaBinding::LuaBinding() : // Core - clockClass("Clock"), - directoryClass("Directory"), - fileClass("File"), - streamClass("Stream"), + clock("Clock"), + directory("Directory"), + file("File"), + stream("Stream"), // Math - eulerAnglesClass("EulerAngles"), - matrix4dClass("Matrix4"), - quaternionClass("Quaternion"), - rectClass("Rect"), - vector2dClass("Vector2"), - vector3dClass("Vector3"), + eulerAngles("EulerAngles"), + matrix4d("Matrix4"), + quaternion("Quaternion"), + rect("Rect"), + vector2d("Vector2"), + vector3d("Vector3"), // Network - abstractSocketClass("AbstractSocket"), - ipAddressClass("IpAddress"), + abstractSocket("AbstractSocket"), + ipAddress("IpAddress"), // Utility abstractImage("AbstractImage"), - fontClass("Font"), - nodeClass("Node"), + font("Font"), + node("Node"), // SDK application("Application"), - entityClass("Entity"), + entity("Entity"), nodeComponent("NodeComponent"), velocityComponent("VelocityComponent"), - worldClass("World") + world("World") #ifndef NDK_SERVER , // Audio - musicClass("Music"), - soundClass("Sound"), + music("Music"), + sound("Sound"), soundBuffer("SoundBuffer"), soundEmitter("SoundEmitter"), // Graphics instancedRenderable("InstancedRenderable"), - modelClass("Model"), - spriteClass("Sprite"), + model("Model"), + sprite("Sprite"), // Renderer texture("Texture"), // SDK - consoleClass("Console"), + console("Console"), graphicsComponent("GraphicsComponent") #endif { diff --git a/SDK/src/NDK/LuaBinding_Audio.cpp b/SDK/src/NDK/LuaBinding_Audio.cpp index ed1538a78..7b81b0c8e 100644 --- a/SDK/src/NDK/LuaBinding_Audio.cpp +++ b/SDK/src/NDK/LuaBinding_Audio.cpp @@ -13,35 +13,35 @@ namespace Ndk void LuaBinding::BindAudio() { /*********************************** Nz::Music **********************************/ - musicClass.Inherit(soundEmitter); + music.Inherit(soundEmitter); - musicClass.BindDefaultConstructor(); + music.BindDefaultConstructor(); //musicClass.SetMethod("Create", &Nz::Music::Create); //musicClass.SetMethod("Destroy", &Nz::Music::Destroy); - musicClass.BindMethod("EnableLooping", &Nz::Music::EnableLooping); + music.BindMethod("EnableLooping", &Nz::Music::EnableLooping); - musicClass.BindMethod("GetDuration", &Nz::Music::GetDuration); - musicClass.BindMethod("GetFormat", &Nz::Music::GetFormat); - musicClass.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset); - musicClass.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount); - musicClass.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate); - musicClass.BindMethod("GetStatus", &Nz::Music::GetStatus); + 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); - musicClass.BindMethod("IsLooping", &Nz::Music::IsLooping); + music.BindMethod("IsLooping", &Nz::Music::IsLooping); - musicClass.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams()); + music.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams()); - musicClass.BindMethod("Pause", &Nz::Music::Pause); - musicClass.BindMethod("Play", &Nz::Music::Play); + music.BindMethod("Pause", &Nz::Music::Pause); + music.BindMethod("Play", &Nz::Music::Play); - musicClass.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset); + music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset); - musicClass.BindMethod("Stop", &Nz::Music::Stop); + music.BindMethod("Stop", &Nz::Music::Stop); // Manual - musicClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music) -> int + music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music) -> int { Nz::StringStream stream("Music("); stream << music.GetFilePath() << ')'; @@ -51,21 +51,21 @@ namespace Ndk }); /*********************************** Nz::Sound **********************************/ - soundClass.Inherit(soundEmitter); + sound.Inherit(soundEmitter); - soundClass.BindDefaultConstructor(); + sound.BindDefaultConstructor(); - soundClass.BindMethod("GetBuffer", &Nz::Sound::GetBuffer); + sound.BindMethod("GetBuffer", &Nz::Sound::GetBuffer); - soundClass.BindMethod("IsPlayable", &Nz::Sound::IsPlayable); - soundClass.BindMethod("IsPlaying", &Nz::Sound::IsPlaying); + sound.BindMethod("IsPlayable", &Nz::Sound::IsPlayable); + sound.BindMethod("IsPlaying", &Nz::Sound::IsPlaying); - soundClass.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); + sound.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); - soundClass.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); + sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); // Manual - soundClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int + sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int { Nz::StringStream stream("Sound("); if (const Nz::SoundBuffer* buffer = sound.GetBuffer()) @@ -177,8 +177,8 @@ namespace Ndk void LuaBinding::RegisterAudio(Nz::LuaInstance& instance) { - musicClass.Register(instance); - soundClass.Register(instance); + music.Register(instance); + sound.Register(instance); soundBuffer.Register(instance); soundEmitter.Register(instance); } diff --git a/SDK/src/NDK/LuaBinding_Core.cpp b/SDK/src/NDK/LuaBinding_Core.cpp index 01f2a2c01..12c559936 100644 --- a/SDK/src/NDK/LuaBinding_Core.cpp +++ b/SDK/src/NDK/LuaBinding_Core.cpp @@ -13,7 +13,7 @@ namespace Ndk void LuaBinding::BindCore() { /*********************************** Nz::Clock **********************************/ - clockClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock, std::size_t /*argumentCount*/) + clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock, std::size_t /*argumentCount*/) { int argIndex = 1; Nz::Int64 startingValue = lua.Check(&argIndex, 0); @@ -23,16 +23,16 @@ namespace Ndk return true; }); - clockClass.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds); - clockClass.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds); - clockClass.BindMethod("GetSeconds", &Nz::Clock::GetSeconds); - clockClass.BindMethod("IsPaused", &Nz::Clock::IsPaused); - clockClass.BindMethod("Pause", &Nz::Clock::Pause); - clockClass.BindMethod("Restart", &Nz::Clock::Restart); - clockClass.BindMethod("Unpause", &Nz::Clock::Unpause); + clock.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds); + clock.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds); + clock.BindMethod("GetSeconds", &Nz::Clock::GetSeconds); + clock.BindMethod("IsPaused", &Nz::Clock::IsPaused); + clock.BindMethod("Pause", &Nz::Clock::Pause); + clock.BindMethod("Restart", &Nz::Clock::Restart); + clock.BindMethod("Unpause", &Nz::Clock::Unpause); // Manual - clockClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int { + clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int { Nz::StringStream stream("Clock(Elapsed: "); stream << clock.GetSeconds(); stream << "s, Paused: "; @@ -44,7 +44,7 @@ namespace Ndk }); /********************************* Nz::Directory ********************************/ - directoryClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* directory, std::size_t argumentCount) + directory.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* directory, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 1U); @@ -63,29 +63,29 @@ namespace Ndk return false; }); - directoryClass.BindMethod("Close", &Nz::Directory::Close); - directoryClass.BindMethod("Exists", &Nz::Directory::Exists); - directoryClass.BindMethod("GetPath", &Nz::Directory::GetPath); - directoryClass.BindMethod("GetPattern", &Nz::Directory::GetPattern); - directoryClass.BindMethod("GetResultName", &Nz::Directory::GetResultName); - directoryClass.BindMethod("GetResultPath", &Nz::Directory::GetResultPath); - directoryClass.BindMethod("GetResultSize", &Nz::Directory::GetResultSize); - directoryClass.BindMethod("IsOpen", &Nz::Directory::IsOpen); - directoryClass.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory); - directoryClass.BindMethod("NextResult", &Nz::Directory::NextResult, true); - directoryClass.BindMethod("Open", &Nz::Directory::Open); - directoryClass.BindMethod("SetPath", &Nz::Directory::SetPath); - directoryClass.BindMethod("SetPattern", &Nz::Directory::SetPattern); + directory.BindMethod("Close", &Nz::Directory::Close); + directory.BindMethod("Exists", &Nz::Directory::Exists); + directory.BindMethod("GetPath", &Nz::Directory::GetPath); + directory.BindMethod("GetPattern", &Nz::Directory::GetPattern); + directory.BindMethod("GetResultName", &Nz::Directory::GetResultName); + directory.BindMethod("GetResultPath", &Nz::Directory::GetResultPath); + directory.BindMethod("GetResultSize", &Nz::Directory::GetResultSize); + directory.BindMethod("IsOpen", &Nz::Directory::IsOpen); + directory.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory); + directory.BindMethod("NextResult", &Nz::Directory::NextResult, true); + directory.BindMethod("Open", &Nz::Directory::Open); + directory.BindMethod("SetPath", &Nz::Directory::SetPath); + directory.BindMethod("SetPattern", &Nz::Directory::SetPattern); - directoryClass.BindStaticMethod("Copy", Nz::Directory::Copy); - directoryClass.BindStaticMethod("Create", Nz::Directory::Create); - directoryClass.BindStaticMethod("Exists", Nz::Directory::Exists); - directoryClass.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent); - directoryClass.BindStaticMethod("Remove", Nz::Directory::Remove); - directoryClass.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent); + directory.BindStaticMethod("Copy", Nz::Directory::Copy); + directory.BindStaticMethod("Create", Nz::Directory::Create); + directory.BindStaticMethod("Exists", Nz::Directory::Exists); + directory.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent); + directory.BindStaticMethod("Remove", Nz::Directory::Remove); + directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent); // Manual - directoryClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int { + directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int { Nz::StringStream stream("Directory("); stream << directory.GetPath(); stream << ')'; @@ -95,22 +95,22 @@ namespace Ndk }); /*********************************** Nz::Stream ***********************************/ - streamClass.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode); - streamClass.BindMethod("Flush", &Nz::Stream::Flush); - streamClass.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos); - streamClass.BindMethod("GetDirectory", &Nz::Stream::GetDirectory); - streamClass.BindMethod("GetPath", &Nz::Stream::GetPath); - streamClass.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode); - streamClass.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions); - streamClass.BindMethod("GetSize", &Nz::Stream::GetSize); - streamClass.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U); - streamClass.BindMethod("IsReadable", &Nz::Stream::IsReadable); - streamClass.BindMethod("IsSequential", &Nz::Stream::IsSequential); - streamClass.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled); - streamClass.BindMethod("IsWritable", &Nz::Stream::IsWritable); - streamClass.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos); + stream.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode); + stream.BindMethod("Flush", &Nz::Stream::Flush); + stream.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos); + stream.BindMethod("GetDirectory", &Nz::Stream::GetDirectory); + stream.BindMethod("GetPath", &Nz::Stream::GetPath); + stream.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode); + stream.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions); + stream.BindMethod("GetSize", &Nz::Stream::GetSize); + stream.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U); + stream.BindMethod("IsReadable", &Nz::Stream::IsReadable); + stream.BindMethod("IsSequential", &Nz::Stream::IsSequential); + stream.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled); + stream.BindMethod("IsWritable", &Nz::Stream::IsWritable); + stream.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos); - streamClass.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { + stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { int argIndex = 1; std::size_t length = lua.Check(&argIndex); @@ -122,7 +122,7 @@ namespace Ndk return 1; }); - streamClass.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { + stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { int argIndex = 1; std::size_t bufferSize = 0; @@ -136,9 +136,9 @@ namespace Ndk }); /*********************************** Nz::File ***********************************/ - fileClass.Inherit(streamClass); + file.Inherit(stream); - fileClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* file, std::size_t argumentCount) + file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* file, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 1U); @@ -171,37 +171,37 @@ namespace Ndk return false; }); - fileClass.BindMethod("Close", &Nz::File::Close); - fileClass.BindMethod("Copy", &Nz::File::Copy); - fileClass.BindMethod("Delete", &Nz::File::Delete); - fileClass.BindMethod("EndOfFile", &Nz::File::EndOfFile); - fileClass.BindMethod("Exists", &Nz::File::Exists); - fileClass.BindMethod("GetCreationTime", &Nz::File::GetCreationTime); - fileClass.BindMethod("GetFileName", &Nz::File::GetFileName); - fileClass.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); - fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); - fileClass.BindMethod("IsOpen", &Nz::File::IsOpen); - fileClass.BindMethod("Rename", &Nz::File::GetLastWriteTime); - fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); - fileClass.BindMethod("SetFile", &Nz::File::GetLastWriteTime); + file.BindMethod("Close", &Nz::File::Close); + file.BindMethod("Copy", &Nz::File::Copy); + file.BindMethod("Delete", &Nz::File::Delete); + file.BindMethod("EndOfFile", &Nz::File::EndOfFile); + file.BindMethod("Exists", &Nz::File::Exists); + file.BindMethod("GetCreationTime", &Nz::File::GetCreationTime); + file.BindMethod("GetFileName", &Nz::File::GetFileName); + file.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); + file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); + file.BindMethod("IsOpen", &Nz::File::IsOpen); + file.BindMethod("Rename", &Nz::File::GetLastWriteTime); + file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); + file.BindMethod("SetFile", &Nz::File::GetLastWriteTime); - fileClass.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath); - fileClass.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash); - fileClass.BindStaticMethod("Copy", &Nz::File::Copy); - fileClass.BindStaticMethod("Delete", &Nz::File::Delete); - fileClass.BindStaticMethod("Exists", &Nz::File::Exists); + file.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath); + file.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash); + file.BindStaticMethod("Copy", &Nz::File::Copy); + file.BindStaticMethod("Delete", &Nz::File::Delete); + file.BindStaticMethod("Exists", &Nz::File::Exists); //fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime); - fileClass.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory); + file.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory); //fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); //fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); - fileClass.BindStaticMethod("GetSize", &Nz::File::GetSize); - fileClass.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute); - fileClass.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath); - fileClass.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators); - fileClass.BindStaticMethod("Rename", &Nz::File::Rename); + file.BindStaticMethod("GetSize", &Nz::File::GetSize); + file.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute); + file.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath); + file.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators); + file.BindStaticMethod("Rename", &Nz::File::Rename); // Manual - fileClass.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int + file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 2U); @@ -224,7 +224,7 @@ namespace Ndk return 0; }); - fileClass.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int + file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 2U); @@ -246,7 +246,7 @@ namespace Ndk return 0; }); - fileClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { + file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { Nz::StringStream stream("File("); if (file.IsOpen()) stream << "Path: " << file.GetPath(); @@ -267,10 +267,10 @@ namespace Ndk void LuaBinding::RegisterCore(Nz::LuaInstance& instance) { // Classes - clockClass.Register(instance); - directoryClass.Register(instance); - fileClass.Register(instance); - streamClass.Register(instance); + clock.Register(instance); + directory.Register(instance); + file.Register(instance); + stream.Register(instance); // Enums diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index fdae54c56..69545ccdf 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -15,62 +15,62 @@ namespace Ndk /*********************************** Nz::InstancedRenderable ***********************************/ /*********************************** Nz::Model ***********************************/ - modelClass.Inherit(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef* + model.Inherit(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef* { return reinterpret_cast(model); //TODO: Make a ObjectRefCast }); - modelClass.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* model, std::size_t /*argumentCount*/) + model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* model, std::size_t /*argumentCount*/) { Nz::PlacementNew(model, Nz::Model::New()); return true; }); //modelClass.SetMethod("GetMaterial", &Nz::Model::GetMaterial); - modelClass.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount); + model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount); //modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh); - modelClass.BindMethod("GetSkin", &Nz::Model::GetSkin); - modelClass.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount); + model.BindMethod("GetSkin", &Nz::Model::GetSkin); + model.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount); - modelClass.BindMethod("IsAnimated", &Nz::Model::IsAnimated); - modelClass.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters()); + model.BindMethod("IsAnimated", &Nz::Model::IsAnimated); + model.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters()); - modelClass.BindMethod("Reset", &Nz::Model::Reset); + model.BindMethod("Reset", &Nz::Model::Reset); //modelClass.SetMethod("SetMaterial", &Nz::Model::SetMaterial); //modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh); //modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence); - modelClass.BindMethod("SetSkin", &Nz::Model::SetSkin); - modelClass.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount); + model.BindMethod("SetSkin", &Nz::Model::SetSkin); + model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount); /*********************************** Nz::Sprite ***********************************/ - spriteClass.Inherit(instancedRenderable, [] (Nz::SpriteRef* sprite) -> Nz::InstancedRenderableRef* + sprite.Inherit(instancedRenderable, [] (Nz::SpriteRef* sprite) -> Nz::InstancedRenderableRef* { return reinterpret_cast(sprite); //TODO: Make a ObjectRefCast }); - spriteClass.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* sprite, std::size_t /*argumentCount*/) + sprite.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* sprite, std::size_t /*argumentCount*/) { Nz::PlacementNew(sprite, Nz::Sprite::New()); return true; }); - spriteClass.BindMethod("GetColor", &Nz::Sprite::GetColor); - spriteClass.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor); + sprite.BindMethod("GetColor", &Nz::Sprite::GetColor); + sprite.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor); //spriteClass.BindMethod("GetMaterial", &Nz::Sprite::GetMaterial); - spriteClass.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin); - spriteClass.BindMethod("GetSize", &Nz::Sprite::GetSize); - spriteClass.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords); + sprite.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin); + sprite.BindMethod("GetSize", &Nz::Sprite::GetSize); + sprite.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords); - spriteClass.BindMethod("SetColor", &Nz::Sprite::SetColor); - spriteClass.BindMethod("SetCornerColor", &Nz::Sprite::SetCornerColor); - spriteClass.BindMethod("SetDefaultMaterial", &Nz::Sprite::SetDefaultMaterial); + sprite.BindMethod("SetColor", &Nz::Sprite::SetColor); + sprite.BindMethod("SetCornerColor", &Nz::Sprite::SetCornerColor); + sprite.BindMethod("SetDefaultMaterial", &Nz::Sprite::SetDefaultMaterial); //spriteClass.BindMethod("SetMaterial", &Nz::Sprite::SetMaterial, true); - spriteClass.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin); - spriteClass.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize); - spriteClass.BindMethod("SetTexture", &Nz::Sprite::SetTexture, true); - spriteClass.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords); - spriteClass.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect); + sprite.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin); + sprite.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize); + sprite.BindMethod("SetTexture", &Nz::Sprite::SetTexture, true); + sprite.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords); + sprite.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect); } /*! @@ -82,7 +82,7 @@ namespace Ndk void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance) { instancedRenderable.Register(instance); - modelClass.Register(instance); - spriteClass.Register(instance); + model.Register(instance); + sprite.Register(instance); } } \ No newline at end of file diff --git a/SDK/src/NDK/LuaBinding_Math.cpp b/SDK/src/NDK/LuaBinding_Math.cpp index 0c6ff3b77..989e2c28c 100644 --- a/SDK/src/NDK/LuaBinding_Math.cpp +++ b/SDK/src/NDK/LuaBinding_Math.cpp @@ -14,7 +14,7 @@ namespace Ndk void LuaBinding::BindMath() { /*********************************** Nz::EulerAngles **********************************/ - eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* angles, std::size_t argumentCount) + eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* angles, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 1U); @@ -37,9 +37,9 @@ namespace Ndk return false; }); - eulerAnglesClass.BindMethod("__tostring", &Nz::EulerAnglesd::ToString); + eulerAngles.BindMethod("__tostring", &Nz::EulerAnglesd::ToString); - eulerAnglesClass.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) + eulerAngles.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) { std::size_t length; const char* ypr = lua.CheckString(1, &length); @@ -96,7 +96,7 @@ namespace Ndk return false; }); - eulerAnglesClass.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) + eulerAngles.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) { std::size_t length; const char* ypr = lua.CheckString(1, &length); @@ -156,7 +156,7 @@ namespace Ndk /*********************************** Nz::Matrix4 **********************************/ - matrix4dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount) + matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 3U); @@ -187,9 +187,9 @@ namespace Ndk return false; }); - matrix4dClass.BindMethod("__tostring", &Nz::Matrix4d::ToString); + matrix4d.BindMethod("__tostring", &Nz::Matrix4d::ToString); - matrix4dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) + matrix4d.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) { int argIndex = 1; std::size_t index = lua.Check(&argIndex); @@ -200,7 +200,7 @@ namespace Ndk return true; }); - matrix4dClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) + matrix4d.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) { int argIndex = 1; std::size_t index = lua.Check(&argIndex); @@ -213,7 +213,7 @@ namespace Ndk }); /*********************************** Nz::Rect **********************************/ - rectClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect, std::size_t argumentCount) + rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 4U); @@ -261,9 +261,9 @@ namespace Ndk return false; }); - rectClass.BindMethod("__tostring", &Nz::Rectd::ToString); + rect.BindMethod("__tostring", &Nz::Rectd::ToString); - rectClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) + rect.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) { switch (lua.GetType(1)) { @@ -316,7 +316,7 @@ namespace Ndk return false; }); - rectClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) + rect.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) { switch (lua.GetType(1)) { @@ -369,7 +369,7 @@ namespace Ndk }); /*********************************** Nz::Quaternion **********************************/ - quaternionClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion, std::size_t argumentCount) + quaternion.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 4U); @@ -407,9 +407,9 @@ namespace Ndk return false; }); - quaternionClass.BindMethod("__tostring", &Nz::Quaterniond::ToString); + quaternion.BindMethod("__tostring", &Nz::Quaterniond::ToString); - quaternionClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) + quaternion.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) { std::size_t length; const char* wxyz = lua.CheckString(1, &length); @@ -439,7 +439,7 @@ namespace Ndk return false; }); - quaternionClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) + quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) { std::size_t length; const char* wxyz = lua.CheckString(1, &length); @@ -475,7 +475,7 @@ namespace Ndk }); /*********************************** Nz::Vector2 **********************************/ - vector2dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount) + vector2d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 2U); @@ -503,9 +503,9 @@ namespace Ndk return false; }); - vector2dClass.BindMethod("__tostring", &Nz::Vector2d::ToString); + vector2d.BindMethod("__tostring", &Nz::Vector2d::ToString); - vector2dClass.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) + vector2d.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) { switch (lua.GetType(1)) { @@ -550,7 +550,7 @@ namespace Ndk return false; }); - vector2dClass.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) + vector2d.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) { switch (lua.GetType(1)) { @@ -598,7 +598,7 @@ namespace Ndk }); /*********************************** Nz::Vector3 **********************************/ - vector3dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount) + vector3d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 3U); @@ -640,9 +640,9 @@ namespace Ndk return false; }); - vector3dClass.BindMethod("__tostring", &Nz::Vector3d::ToString); + vector3d.BindMethod("__tostring", &Nz::Vector3d::ToString); - vector3dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) + vector3d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) { switch (lua.GetType(1)) { @@ -691,7 +691,7 @@ namespace Ndk return false; }); - vector3dClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) + vector3d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) { switch (lua.GetType(1)) { @@ -751,11 +751,11 @@ namespace Ndk void LuaBinding::RegisterMath(Nz::LuaInstance& instance) { - eulerAnglesClass.Register(instance); - matrix4dClass.Register(instance); - quaternionClass.Register(instance); - rectClass.Register(instance); - vector2dClass.Register(instance); - vector3dClass.Register(instance); + eulerAngles.Register(instance); + matrix4d.Register(instance); + quaternion.Register(instance); + rect.Register(instance); + vector2d.Register(instance); + vector3d.Register(instance); } } diff --git a/SDK/src/NDK/LuaBinding_Network.cpp b/SDK/src/NDK/LuaBinding_Network.cpp index 689fc2d1d..430cd1208 100644 --- a/SDK/src/NDK/LuaBinding_Network.cpp +++ b/SDK/src/NDK/LuaBinding_Network.cpp @@ -12,16 +12,16 @@ namespace Ndk void LuaBinding::BindNetwork() { /*********************************** Nz::AbstractSocket **********************************/ - abstractSocketClass.BindMethod("Close", &Nz::AbstractSocket::Close); - abstractSocketClass.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking); - abstractSocketClass.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError); - abstractSocketClass.BindMethod("GetState", &Nz::AbstractSocket::GetState); - abstractSocketClass.BindMethod("GetType", &Nz::AbstractSocket::GetType); - abstractSocketClass.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled); - abstractSocketClass.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes); + abstractSocket.BindMethod("Close", &Nz::AbstractSocket::Close); + abstractSocket.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking); + abstractSocket.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError); + abstractSocket.BindMethod("GetState", &Nz::AbstractSocket::GetState); + abstractSocket.BindMethod("GetType", &Nz::AbstractSocket::GetType); + abstractSocket.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled); + abstractSocket.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes); /*********************************** Nz::IpAddress **********************************/ - ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* address, std::size_t argumentCount) + ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* address, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 9U); @@ -71,14 +71,14 @@ namespace Ndk return false; }); - ipAddressClass.BindMethod("GetPort", &Nz::IpAddress::GetPort); - ipAddressClass.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol); - ipAddressClass.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback); - ipAddressClass.BindMethod("IsValid", &Nz::IpAddress::IsValid); - ipAddressClass.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32); - ipAddressClass.BindMethod("__tostring", &Nz::IpAddress::ToString); + ipAddress.BindMethod("GetPort", &Nz::IpAddress::GetPort); + ipAddress.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol); + ipAddress.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback); + ipAddress.BindMethod("IsValid", &Nz::IpAddress::IsValid); + ipAddress.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32); + ipAddress.BindMethod("__tostring", &Nz::IpAddress::ToString); - ipAddressClass.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int + ipAddress.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int { Nz::String service; Nz::ResolveError error = Nz::ResolveError_Unknown; @@ -100,7 +100,7 @@ namespace Ndk } }); - ipAddressClass.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int + ipAddress.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int { Nz::ResolveError error = Nz::ResolveError_Unknown; @@ -145,8 +145,8 @@ namespace Ndk void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance) { // Classes - abstractSocketClass.Register(instance); - ipAddressClass.Register(instance); + abstractSocket.Register(instance); + ipAddress.Register(instance); // Enums diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index fda6f7bb9..61dc15751 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -36,58 +36,58 @@ namespace Ndk /*********************************** Ndk::Console **********************************/ #ifndef NDK_SERVER - consoleClass.Inherit(nodeClass, [] (ConsoleHandle* handle) -> Nz::Node* + console.Inherit(node, [] (ConsoleHandle* handle) -> Nz::Node* { return handle->GetObject(); }); - consoleClass.BindMethod("AddLine", &Console::AddLine, Nz::Color::White); - consoleClass.BindMethod("Clear", &Console::Clear); - consoleClass.BindMethod("GetCharacterSize", &Console::GetCharacterSize); - consoleClass.BindMethod("GetHistory", &Console::GetHistory); - consoleClass.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground); - consoleClass.BindMethod("GetInput", &Console::GetInput); - consoleClass.BindMethod("GetInputBackground", &Console::GetInputBackground); - consoleClass.BindMethod("GetSize", &Console::GetSize); - consoleClass.BindMethod("GetTextFont", &Console::GetTextFont); + 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); - consoleClass.BindMethod("IsVisible", &Console::IsVisible); + console.BindMethod("IsVisible", &Console::IsVisible); - consoleClass.BindMethod("SendCharacter", &Console::SendCharacter); + console.BindMethod("SendCharacter", &Console::SendCharacter); //consoleClass.SetMethod("SendEvent", &Console::SendEvent); - consoleClass.BindMethod("SetCharacterSize", &Console::SetCharacterSize); - consoleClass.BindMethod("SetSize", &Console::SetSize); - consoleClass.BindMethod("SetTextFont", &Console::SetTextFont); + console.BindMethod("SetCharacterSize", &Console::SetCharacterSize); + console.BindMethod("SetSize", &Console::SetSize); + console.BindMethod("SetTextFont", &Console::SetTextFont); - consoleClass.BindMethod("Show", &Console::Show, true); + console.BindMethod("Show", &Console::Show, true); #endif /*********************************** Ndk::Entity **********************************/ - entityClass.BindMethod("Enable", &Entity::Enable, true); - entityClass.BindMethod("GetId", &Entity::GetId); - entityClass.BindMethod("GetWorld", &Entity::GetWorld); - entityClass.BindMethod("Kill", &Entity::Kill); - entityClass.BindMethod("IsEnabled", &Entity::IsEnabled); - entityClass.BindMethod("IsValid", &Entity::IsValid); - entityClass.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents); - entityClass.BindMethod("__tostring", &EntityHandle::ToString); + 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); - entityClass.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int + entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int { ComponentBinding* binding = QueryComponentIndex(instance); return binding->adder(instance, handle); }); - entityClass.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int + entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int { ComponentBinding* binding = QueryComponentIndex(instance); return binding->getter(instance, handle->GetComponent(binding->index)); }); - entityClass.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int + entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int { ComponentBinding* binding = QueryComponentIndex(instance); @@ -96,7 +96,7 @@ namespace Ndk }); /*********************************** Ndk::NodeComponent **********************************/ - nodeComponent.Inherit(nodeClass, [] (NodeComponentHandle* handle) -> Nz::Node* + nodeComponent.Inherit(node, [] (NodeComponentHandle* handle) -> Nz::Node* { return handle->GetObject(); }); @@ -132,9 +132,9 @@ namespace Ndk }); /*********************************** Ndk::World **********************************/ - worldClass.BindMethod("CreateEntity", &World::CreateEntity); - worldClass.BindMethod("CreateEntities", &World::CreateEntities); - worldClass.BindMethod("Clear", &World::Clear); + world.BindMethod("CreateEntity", &World::CreateEntity); + world.BindMethod("CreateEntities", &World::CreateEntities); + world.BindMethod("Clear", &World::Clear); #ifndef NDK_SERVER @@ -222,13 +222,13 @@ namespace Ndk { // Classes application.Register(instance); - entityClass.Register(instance); + entity.Register(instance); nodeComponent.Register(instance); velocityComponent.Register(instance); - worldClass.Register(instance); + world.Register(instance); #ifndef NDK_SERVER - consoleClass.Register(instance); + console.Register(instance); graphicsComponent.Register(instance); #endif diff --git a/SDK/src/NDK/LuaBinding_Utility.cpp b/SDK/src/NDK/LuaBinding_Utility.cpp index 9966b6f21..5ee613e1e 100644 --- a/SDK/src/NDK/LuaBinding_Utility.cpp +++ b/SDK/src/NDK/LuaBinding_Utility.cpp @@ -93,19 +93,19 @@ namespace Ndk }); /*********************************** Nz::Font **********************************/ - fontClass.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* font, std::size_t /*argumentCount*/) + font.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* font, std::size_t /*argumentCount*/) { Nz::PlacementNew(font, Nz::Font::New()); return true; }); - fontClass.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache); - fontClass.BindMethod("ClearKerningCache", &Nz::Font::ClearKerningCache); - fontClass.BindMethod("ClearSizeInfoCache", &Nz::Font::ClearSizeInfoCache); + font.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache); + font.BindMethod("ClearKerningCache", &Nz::Font::ClearKerningCache); + font.BindMethod("ClearSizeInfoCache", &Nz::Font::ClearSizeInfoCache); - fontClass.BindMethod("Destroy", &Nz::Font::Destroy); + font.BindMethod("Destroy", &Nz::Font::Destroy); - fontClass.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance) -> int + font.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 2U); @@ -130,76 +130,76 @@ namespace Ndk return 0; }); - fontClass.BindMethod("GetFamilyName", &Nz::Font::GetFamilyName); - fontClass.BindMethod("GetKerning", &Nz::Font::GetKerning); - fontClass.BindMethod("GetGlyphBorder", &Nz::Font::GetGlyphBorder); - fontClass.BindMethod("GetMinimumStepSize", &Nz::Font::GetMinimumStepSize); - fontClass.BindMethod("GetSizeInfo", &Nz::Font::GetSizeInfo); - fontClass.BindMethod("GetStyleName", &Nz::Font::GetStyleName); + font.BindMethod("GetFamilyName", &Nz::Font::GetFamilyName); + font.BindMethod("GetKerning", &Nz::Font::GetKerning); + font.BindMethod("GetGlyphBorder", &Nz::Font::GetGlyphBorder); + font.BindMethod("GetMinimumStepSize", &Nz::Font::GetMinimumStepSize); + font.BindMethod("GetSizeInfo", &Nz::Font::GetSizeInfo); + font.BindMethod("GetStyleName", &Nz::Font::GetStyleName); - fontClass.BindMethod("IsValid", &Nz::Font::IsValid); + font.BindMethod("IsValid", &Nz::Font::IsValid); - fontClass.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::UInt32, const Nz::String&) const) &Nz::Font::Precache); + font.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::UInt32, const Nz::String&) const) &Nz::Font::Precache); - fontClass.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams()); + font.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams()); - fontClass.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder); - fontClass.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize); + font.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder); + font.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize); - fontClass.BindStaticMethod("GetDefault", &Nz::Font::GetDefault); - fontClass.BindStaticMethod("GetDefaultGlyphBorder", &Nz::Font::GetDefaultGlyphBorder); - fontClass.BindStaticMethod("GetDefaultMinimumStepSize", &Nz::Font::GetDefaultMinimumStepSize); + font.BindStaticMethod("GetDefault", &Nz::Font::GetDefault); + font.BindStaticMethod("GetDefaultGlyphBorder", &Nz::Font::GetDefaultGlyphBorder); + font.BindStaticMethod("GetDefaultMinimumStepSize", &Nz::Font::GetDefaultMinimumStepSize); - fontClass.BindStaticMethod("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder); - fontClass.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize); + font.BindStaticMethod("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder); + font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize); /*********************************** Nz::Node **********************************/ - nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward); + node.BindMethod("GetBackward", &Nz::Node::GetBackward); //nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds); - nodeClass.BindMethod("GetDown", &Nz::Node::GetDown); - nodeClass.BindMethod("GetForward", &Nz::Node::GetForward); - nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition); - nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation); - nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale); - nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition); + node.BindMethod("GetDown", &Nz::Node::GetDown); + node.BindMethod("GetForward", &Nz::Node::GetForward); + node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition); + node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation); + node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale); + node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition); //nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation); - nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale); - nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft); - nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType); + node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale); + node.BindMethod("GetLeft", &Nz::Node::GetLeft); + node.BindMethod("GetNodeType", &Nz::Node::GetNodeType); //nodeClass.SetMethod("GetParent", &Nz::Node::GetParent); - nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global); - nodeClass.BindMethod("GetRight", &Nz::Node::GetRight); + node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global); + node.BindMethod("GetRight", &Nz::Node::GetRight); //nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global); - nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global); + node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global); //nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix); - nodeClass.BindMethod("GetUp", &Nz::Node::GetUp); + node.BindMethod("GetUp", &Nz::Node::GetUp); - nodeClass.BindMethod("HasChilds", &Nz::Node::HasChilds); + node.BindMethod("HasChilds", &Nz::Node::HasChilds); - nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward); - nodeClass.BindMethod("GetDown", &Nz::Node::GetDown); - nodeClass.BindMethod("GetForward", &Nz::Node::GetForward); - nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition); - nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation); - nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale); - nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition); - nodeClass.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation); - nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale); - nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft); - nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType); - nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global); - nodeClass.BindMethod("GetRight", &Nz::Node::GetRight); - nodeClass.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global); - nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global); - nodeClass.BindMethod("GetUp", &Nz::Node::GetUp); + node.BindMethod("GetBackward", &Nz::Node::GetBackward); + node.BindMethod("GetDown", &Nz::Node::GetDown); + node.BindMethod("GetForward", &Nz::Node::GetForward); + node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition); + node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation); + node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale); + node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition); + node.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation); + node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale); + node.BindMethod("GetLeft", &Nz::Node::GetLeft); + node.BindMethod("GetNodeType", &Nz::Node::GetNodeType); + node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global); + node.BindMethod("GetRight", &Nz::Node::GetRight); + node.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global); + node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global); + node.BindMethod("GetUp", &Nz::Node::GetUp); - nodeClass.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition); - nodeClass.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation); + node.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition); + node.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation); - nodeClass.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local); - nodeClass.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local); + node.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local); + node.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local); - nodeClass.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { int argIndex = 1; @@ -210,7 +210,7 @@ namespace Ndk return 0; }); - nodeClass.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { int argIndex = 1; @@ -221,7 +221,7 @@ namespace Ndk return 0; }); - nodeClass.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 4U); @@ -247,7 +247,7 @@ namespace Ndk return 0; }); - nodeClass.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 4U); @@ -284,7 +284,7 @@ namespace Ndk return 0; }); - nodeClass.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 4U); @@ -321,7 +321,7 @@ namespace Ndk void LuaBinding::RegisterUtility(Nz::LuaInstance& instance) { abstractImage.Register(instance); - fontClass.Register(instance); - nodeClass.Register(instance); + font.Register(instance); + node.Register(instance); } } \ No newline at end of file From 8f84700628ed6787db7d48ccd98da7ca1bbdc8cc Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 02:12:23 +0200 Subject: [PATCH 11/58] Sdk/LuaAPI: Make GetBinding() initialize the binding in case it wasn't initialized --- SDK/include/NDK/LuaAPI.hpp | 2 +- SDK/include/NDK/LuaAPI.inl | 13 ------------- SDK/src/NDK/LuaAPI.cpp | 25 ++++++++++++++++++------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/SDK/include/NDK/LuaAPI.hpp b/SDK/include/NDK/LuaAPI.hpp index e19458d3f..bc4631e47 100644 --- a/SDK/include/NDK/LuaAPI.hpp +++ b/SDK/include/NDK/LuaAPI.hpp @@ -24,7 +24,7 @@ namespace Ndk LuaAPI() = delete; ~LuaAPI() = delete; - static inline LuaBinding* GetBinding(); + static LuaBinding* GetBinding(); static bool Initialize(); diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index 3697532f4..1ea81f597 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -24,19 +24,6 @@ #include #endif -namespace Ndk -{ - /*! - * \brief Gets the internal binding for Lua - * \return A pointer to the binding - */ - - inline LuaBinding* LuaAPI::GetBinding() - { - return s_binding; - } -} - namespace Nz { /*! diff --git a/SDK/src/NDK/LuaAPI.cpp b/SDK/src/NDK/LuaAPI.cpp index 1bf4eec35..fba28b2b3 100644 --- a/SDK/src/NDK/LuaAPI.cpp +++ b/SDK/src/NDK/LuaAPI.cpp @@ -1,6 +1,7 @@ // This file was automatically generated on 26 May 2014 at 01:05:31 #include +#include #include namespace Ndk @@ -11,6 +12,21 @@ namespace Ndk * \brief NDK class that represents the api used for Lua */ + /*! + * \brief Gets the internal binding for Lua + * \return A pointer to the binding + */ + LuaBinding* LuaAPI::GetBinding() + { + if (!s_binding && !Initialize()) + { + NazaraError("Failed to initialize binding"); + return nullptr; + } + + return s_binding; + } + /*! * \brief Initializes the LuaAPI module * \return true if initialization is successful @@ -30,13 +46,8 @@ namespace Ndk void LuaAPI::RegisterClasses(Nz::LuaInstance& instance) { - if (!s_binding && !Initialize()) - { - NazaraError("Failed to initialize binding"); - return; - } - - s_binding->RegisterClasses(instance); + Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true); + GetBinding()->RegisterClasses(instance); } /*! From b062b496cff7cad712e0ea3ab84a0a44007dad31 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 02:12:35 +0200 Subject: [PATCH 12/58] Fix compilation --- SDK/include/NDK/LuaAPI.inl | 1 + include/Nazara/Utility/AbstractImage.inl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index 1ea81f597..f24e16fd1 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/include/Nazara/Utility/AbstractImage.inl b/include/Nazara/Utility/AbstractImage.inl index d3f50fc84..b3e5fc417 100644 --- a/include/Nazara/Utility/AbstractImage.inl +++ b/include/Nazara/Utility/AbstractImage.inl @@ -7,7 +7,7 @@ namespace Nz { - inline AbstractImage::AbstractImage(const AbstractImage& image) : + inline AbstractImage::AbstractImage(const AbstractImage&) : RefCounted() { } From b1abe2aac8bcf0665594070bf81ae20a2c410087 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 02:22:12 +0200 Subject: [PATCH 13/58] =?UTF-8?q?SDK:=20Fix=20compilation=C2=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SDK/include/NDK/LuaAPI.inl | 1 + 1 file changed, 1 insertion(+) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index f24e16fd1..88fdb3a1f 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -22,6 +22,7 @@ #include #include #include +#include #include #endif From 373b8a70698b12a8d0ba6d119ea6a86ec77a150c Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 02:29:09 +0200 Subject: [PATCH 14/58] SDKServer: Fix compilation --- SDK/include/NDK/LuaAPI.inl | 57 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index 88fdb3a1f..1987bf7c1 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -835,20 +835,6 @@ namespace Nz return 1; } - /*! - * \brief Replies by value for Lua - * \return 1 in case of success - * - * \param instance Lua instance to interact with - * \param handle Resulting texture - */ - - inline int LuaImplReplyVal(const LuaInstance& instance, TextureRef&& handle, TypeTag) - { - instance.PushInstance("Texture", handle); - return 1; - } - /*! * \brief Replies by value for Lua * \return 1 in case of success @@ -1033,6 +1019,34 @@ namespace Nz #ifndef NDK_SERVER + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting sound buffer + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag) + { + instance.PushInstance("SoundBuffer", val); + return 1; + } + + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param handle Resulting texture + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, TextureRef&& handle, TypeTag) + { + instance.PushInstance("Texture", handle); + return 1; + } + /*! * \brief Replies by value for Lua * \return 1 in case of success @@ -1060,21 +1074,6 @@ namespace Nz instance.PushInstance("GraphicsComponent", handle); return 1; } - - /*! - * \brief Replies by value for Lua - * \return 1 in case of success - * - * \param instance Lua instance to interact with - * \param val Resulting sound buffer - */ - - inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag) - { - instance.PushInstance("SoundBuffer", val); - return 1; - } - #endif } From 3f7f12b625d6ab7275e291bbdd8d877e12352248 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 16:50:49 +0200 Subject: [PATCH 15/58] Lua/LuaClass: Refactor Register() implementation --- include/Nazara/Lua/LuaClass.hpp | 10 ++ include/Nazara/Lua/LuaClass.inl | 286 +++++++++++++++++--------------- 2 files changed, 161 insertions(+), 135 deletions(-) diff --git a/include/Nazara/Lua/LuaClass.hpp b/include/Nazara/Lua/LuaClass.hpp index 1d4aea327..64acc3763 100644 --- a/include/Nazara/Lua/LuaClass.hpp +++ b/include/Nazara/Lua/LuaClass.hpp @@ -66,6 +66,16 @@ namespace Nz void SetStaticSetter(StaticIndexFunc getter); private: + void PushClassInfo(LuaInstance& lua); + void SetupConstructor(LuaInstance& lua); + void SetupDefaultToString(LuaInstance& lua); + void SetupFinalizer(LuaInstance& lua); + void SetupGetter(LuaInstance& lua, LuaCFunction proxy); + void SetupGlobalTable(LuaInstance& lua); + void SetupMetatable(LuaInstance& lua); + void SetupMethod(LuaInstance& lua, LuaCFunction proxy, const String& name, std::size_t methodIndex); + void SetupSetter(LuaInstance& lua, LuaCFunction proxy); + using ParentFunc = std::function; using InstanceGetter = std::function; diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl index 3d0befeaa..44cb4ee0c 100644 --- a/include/Nazara/Lua/LuaClass.inl +++ b/include/Nazara/Lua/LuaClass.inl @@ -69,149 +69,25 @@ namespace Nz { m_info = std::make_shared(); m_info->name = name; + + m_info->instanceGetters[m_info->name] = [info = m_info] (LuaInstance& instance) + { + return static_cast(instance.CheckUserdata(1, info->name)); + }; } template void LuaClass::Register(LuaInstance& lua) { - // Le ClassInfo doit rester en vie jusqu'à la fin du script - // Obliger l'instance de LuaClass à rester en vie dans cette fin serait contraignant pour l'utilisateur - // J'utilise donc une astuce, la stocker dans une UserData associée avec chaque fonction de la metatable du type, - // cette UserData disposera d'un finalizer qui libérera le ClassInfo - // Ainsi c'est Lua qui va s'occuper de la destruction pour nous :-) - // De même, l'utilisation d'un shared_ptr permet de garder la structure en vie même si l'instance est libérée avant le LuaClass - std::shared_ptr* info = static_cast*>(lua.PushUserdata(sizeof(std::shared_ptr))); - PlacementNew(info, m_info); + PushClassInfo(lua); - // On créé la table qui contiendra une méthode (Le finalizer) pour libérer le ClassInfo - lua.PushTable(0, 1); - lua.PushLightUserdata(info); - lua.PushCFunction(InfoDestructor, 1); - lua.SetField("__gc"); - lua.SetMetatable(-2); // La table devient la metatable de l'UserData - - // Maintenant, nous allons associer l'UserData avec chaque fonction, de sorte qu'il reste en vie - // aussi longtemps que nécessaire, et que le pointeur soit transmis à chaque méthode - - if (!lua.NewMetatable(m_info->name)) - NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance"); - { - // Set the type in a __type field - lua.PushString(m_info->name); - lua.SetField("__type"); - - // In case a __tostring method is missing, add a default implementation returning the type - if (m_methods.find("__tostring") == m_methods.end()) - { - // Define the Finalizer - lua.PushValue(1); // shared_ptr on UserData - lua.PushCFunction(ToStringProxy, 1); - lua.SetField("__tostring"); - } - - // Define the Finalizer - lua.PushValue(1); - lua.PushCFunction(FinalizerProxy, 1); - lua.SetField("__gc"); - - if (m_info->getter || !m_info->parentGetters.empty()) - { - lua.PushValue(1); // shared_ptr on UserData - lua.PushValue(-2); // Metatable - lua.PushCFunction(GetterProxy, 2); - } - else - // Optimisation, plutôt que de rediriger vers une fonction C qui ne fera rien d'autre que rechercher - // dans la table, nous envoyons directement la table, de sorte que Lua fasse directement la recherche - // Ceci n'est possible que si nous n'avons ni getter, ni parent - lua.PushValue(-1); // Metatable - - lua.SetField("__index"); // Getter - - if (m_info->setter) - { - lua.PushValue(1); // shared_ptr on UserData - lua.PushCFunction(SetterProxy, 1); - lua.SetField("__newindex"); // Setter - } - - m_info->methods.reserve(m_methods.size()); - for (auto& pair : m_methods) - { - std::size_t methodIndex = m_info->methods.size(); - m_info->methods.push_back(pair.second); - - lua.PushValue(1); // shared_ptr on UserData - lua.PushInteger(methodIndex); - - lua.PushCFunction(MethodProxy, 2); - lua.SetField(pair.first); // Method name - } - - m_info->instanceGetters[m_info->name] = [info = m_info] (LuaInstance& instance) - { - return static_cast(instance.CheckUserdata(1, info->name)); - }; - } - lua.Pop(); // On pop la metatable + // Let's create the metatable which will be associated with every instance. + SetupMetatable(lua); if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_info->staticMethods.empty()) - { - // Création de l'instance globale - lua.PushTable(); // Class = {} + SetupGlobalTable(lua); - // Création de la metatable associée à la table globale - lua.PushTable(); // ClassMeta = {} - - if (m_info->constructor) - { - lua.PushValue(1); // ClassInfo - lua.PushCFunction(ConstructorProxy, 1); - lua.SetField("__call"); // ClassMeta.__call = ConstructorProxy - } - - if (m_info->staticGetter) - { - lua.PushValue(1); // shared_ptr on UserData - lua.PushValue(-2); // ClassMeta - lua.PushCFunction(StaticGetterProxy, 2); - } - else - // Optimisation, plutôt que de rediriger vers une fonction C qui ne fera rien d'autre que rechercher - // dans la table, nous envoyons directement la table, de sorte que Lua fasse directement la recherche - // Ceci n'est possible que si nous n'avons ni getter, ni parent - lua.PushValue(-1); // ClassMeta - - lua.SetField("__index"); // ClassMeta.__index = StaticGetterProxy/ClassMeta - - if (m_info->staticSetter) - { - lua.PushValue(1); // shared_ptr on UserData - lua.PushCFunction(StaticSetterProxy, 1); - lua.SetField("__newindex"); // ClassMeta.__newindex = StaticSetterProxy - } - - m_info->staticMethods.reserve(m_staticMethods.size()); - for (auto& pair : m_staticMethods) - { - std::size_t methodIndex = m_info->staticMethods.size(); - m_info->staticMethods.push_back(pair.second); - - lua.PushValue(1); // shared_ptr on UserData - lua.PushInteger(methodIndex); - - lua.PushCFunction(StaticMethodProxy, 2); - lua.SetField(pair.first); // ClassMeta.method = StaticMethodProxy - } - - lua.SetMetatable(-2); // setmetatable(Class, ClassMeta) - - lua.PushValue(-1); // Copie - lua.SetGlobal(m_info->name); // Class - - m_info->globalTableRef = lua.CreateReference(); - } - lua.Pop(); // On pop l'Userdata (contenant nos informations) + lua.Pop(); // Pop our ClassInfo, which is now referenced by all our functions } template @@ -338,6 +214,145 @@ namespace Nz m_info->staticSetter = setter; } + template + void LuaClass::PushClassInfo(LuaInstance& lua) + { + // Our ClassInfo has to outlive the LuaClass, because we don't want to force the user to keep the LuaClass alive + // To do that, each Registration creates a tiny shared_ptr wrapper whose life is directly managed by Lua. + // This shared_ptr object gets pushed as a up-value for every proxy function set in the metatable. + // This way, there is no way our ClassInfo gets freed before any instance and the global class gets destroyed. + std::shared_ptr* info = static_cast*>(lua.PushUserdata(sizeof(std::shared_ptr))); + PlacementNew(info, m_info); + + // Setup a tiny metatable to let Lua know how to destroy our ClassInfo + lua.PushTable(0, 1); + lua.PushLightUserdata(info); + lua.PushCFunction(InfoDestructor, 1); + lua.SetField("__gc"); + lua.SetMetatable(-2); + } + + template + void LuaClass::SetupConstructor(LuaInstance& lua) + { + lua.PushValue(1); // ClassInfo + lua.PushCFunction(ConstructorProxy, 1); + lua.SetField("__call"); // ClassMeta.__call = ConstructorProxy + } + + template + void LuaClass::SetupDefaultToString(LuaInstance& lua) + { + lua.PushValue(1); // shared_ptr on UserData + lua.PushCFunction(ToStringProxy, 1); + lua.SetField("__tostring"); + } + + template + void LuaClass::SetupFinalizer(LuaInstance& lua) + { + lua.PushValue(1); // ClassInfo + lua.PushCFunction(FinalizerProxy, 1); + lua.SetField("__gc"); + } + + template + void LuaClass::SetupGetter(LuaInstance& lua, LuaCFunction proxy) + { + if (m_info->getter || !m_info->parentGetters.empty()) + { + lua.PushValue(1); // ClassInfo + lua.PushValue(-2); // Metatable + lua.PushCFunction(proxy, 2); + } + else + // Optimize by assigning the metatable instead of a search function + // This is only possible if we have no custom getter nor parent + lua.PushValue(-1); // Metatable + + lua.SetField("__index"); // Getter + } + + template + void LuaClass::SetupGlobalTable(LuaInstance& lua) + { + // Create a metatable which will be used for our global table + lua.PushTable(); // ClassMeta = {} + + if (m_info->constructor) + SetupConstructor(lua); + + SetupGetter(lua, StaticGetterProxy); + + if (m_info->staticSetter) + SetupSetter(lua, StaticSetterProxy); + + m_info->staticMethods.reserve(m_staticMethods.size()); + for (auto& pair : m_staticMethods) + { + std::size_t methodIndex = m_info->staticMethods.size(); + m_info->staticMethods.push_back(pair.second); + + SetupMethod(lua, StaticMethodProxy, pair.first, methodIndex); + } + + // Now let's create the global table + lua.PushTable(); // Class = {} + lua.SetMetatable(-2); // setmetatable(Class, ClassMeta) + + lua.PushValue(-1); // As CreateReference() pops the table, push a copy + m_info->globalTableRef = lua.CreateReference(); + + lua.SetGlobal(m_info->name); // _G["Class"] = Class + } + + template + void LuaClass::SetupMetatable(LuaInstance& lua) + { + if (!lua.NewMetatable(m_info->name)) + NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance"); + { + SetupFinalizer(lua); + SetupGetter(lua, GetterProxy); + + if (m_info->setter) + SetupSetter(lua, SetterProxy); + + // In case a __tostring method is missing, add a default implementation returning the class name + if (m_methods.find("__tostring") == m_methods.end()) + SetupDefaultToString(lua); + + m_info->methods.reserve(m_methods.size()); + for (auto& pair : m_methods) + { + std::size_t methodIndex = m_info->methods.size(); + m_info->methods.push_back(pair.second); + + SetupMethod(lua, MethodProxy, pair.first, methodIndex); + } + } + lua.Pop(); //< Pops the metatable, it won't be collected before it's referenced by the Lua registry. + } + + template + void LuaClass::SetupMethod(LuaInstance& lua, LuaCFunction proxy, const String& name, std::size_t methodIndex) + { + lua.PushValue(1); // ClassInfo + lua.PushInteger(methodIndex); + lua.PushCFunction(proxy, 2); + + lua.SetField(name); // Method name + } + + template + void LuaClass::SetupSetter(LuaInstance& lua, LuaCFunction proxy) + { + lua.PushValue(1); // ClassInfo + lua.PushCFunction(proxy, 1); + + lua.SetField("__newindex"); // Setter + } + template int LuaClass::ConstructorProxy(lua_State* state) { @@ -445,7 +460,7 @@ namespace Nz T* instance = nullptr; if (lua.GetMetatable(1)) { - LuaType type = lua.GetField("__type"); + LuaType type = lua.GetField("__name"); if (type == LuaType_String) { String name = lua.ToString(-1); @@ -554,3 +569,4 @@ namespace Nz } #include +#include "LuaClass.hpp" From d6b6e26d317251f82a02d6f940837d3fa2be227d Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 17:24:45 +0200 Subject: [PATCH 16/58] Lua/LuaClass: Reference the destructor only if the class has one Allows to bind classes with deleted destructors --- include/Nazara/Lua/LuaClass.hpp | 5 ++++- include/Nazara/Lua/LuaClass.inl | 29 +++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/include/Nazara/Lua/LuaClass.hpp b/include/Nazara/Lua/LuaClass.hpp index 64acc3763..45c3d930b 100644 --- a/include/Nazara/Lua/LuaClass.hpp +++ b/include/Nazara/Lua/LuaClass.hpp @@ -66,6 +66,9 @@ namespace Nz void SetStaticSetter(StaticIndexFunc getter); private: + template + friend struct LuaClassImplFinalizerSetupProxy; + void PushClassInfo(LuaInstance& lua); void SetupConstructor(LuaInstance& lua); void SetupDefaultToString(LuaInstance& lua); @@ -75,7 +78,7 @@ namespace Nz void SetupMetatable(LuaInstance& lua); void SetupMethod(LuaInstance& lua, LuaCFunction proxy, const String& name, std::size_t methodIndex); void SetupSetter(LuaInstance& lua, LuaCFunction proxy); - + using ParentFunc = std::function; using InstanceGetter = std::function; diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl index 44cb4ee0c..6c609e731 100644 --- a/include/Nazara/Lua/LuaClass.inl +++ b/include/Nazara/Lua/LuaClass.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Lua scripting module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -251,9 +252,7 @@ namespace Nz template void LuaClass::SetupFinalizer(LuaInstance& lua) { - lua.PushValue(1); // ClassInfo - lua.PushCFunction(FinalizerProxy, 1); - lua.SetField("__gc"); + LuaClassImplFinalizerSetupProxy::value>::Setup(lua); } template @@ -353,6 +352,7 @@ namespace Nz lua.SetField("__newindex"); // Setter } + template int LuaClass::ConstructorProxy(lua_State* state) { @@ -566,7 +566,28 @@ namespace Nz lua.PushString(info->name); return 1; } + + template + struct LuaClassImplFinalizerSetupProxy; + + template + struct LuaClassImplFinalizerSetupProxy + { + static void Setup(LuaInstance& lua) + { + lua.PushValue(1); // ClassInfo + lua.PushCFunction(LuaClass::FinalizerProxy, 1); + lua.SetField("__gc"); + } + }; + + template + struct LuaClassImplFinalizerSetupProxy + { + static void Setup(LuaInstance&) + { + } + }; } #include -#include "LuaClass.hpp" From 511ded215b5da7b2609bfbb650c10778f42ad45c Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 17:32:20 +0200 Subject: [PATCH 17/58] Lua/LuaClass: Fix compilation --- include/Nazara/Lua/LuaClass.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Nazara/Lua/LuaClass.hpp b/include/Nazara/Lua/LuaClass.hpp index 45c3d930b..795cfe6ff 100644 --- a/include/Nazara/Lua/LuaClass.hpp +++ b/include/Nazara/Lua/LuaClass.hpp @@ -66,7 +66,7 @@ namespace Nz void SetStaticSetter(StaticIndexFunc getter); private: - template + template friend struct LuaClassImplFinalizerSetupProxy; void PushClassInfo(LuaInstance& lua); From 034f5cc8d77c8219f984b59fc69bfb6f5184b1db Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 17:32:40 +0200 Subject: [PATCH 18/58] Sdk/Lua: Bind SpriteLibrary --- SDK/include/NDK/LuaAPI.inl | 30 +++++++++++++++++++++++++++++ SDK/include/NDK/LuaBinding.hpp | 1 + SDK/src/NDK/LuaBinding.cpp | 1 + SDK/src/NDK/LuaBinding_Graphics.cpp | 9 +++++++++ 4 files changed, 41 insertions(+) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index 1987bf7c1..685603a6a 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -625,6 +625,22 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param renderable Resulting reference to a sprite + */ + + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SpriteRef* spriteRef, TypeTag) + { + *spriteRef = *static_cast(instance.CheckUserdata(index, "Sprite")); + + return 1; + } + /*! * \brief Queries arguments for Lua * \return 1 in case of success @@ -1033,6 +1049,20 @@ namespace Nz return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param handle Resulting sprite + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, SpriteRef&& handle, TypeTag) + { + instance.PushInstance("Sprite", handle); + return 1; + } + /*! * \brief Replies by value for Lua * \return 1 in case of success diff --git a/SDK/include/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp index 2b3d8d3a0..d22628470 100644 --- a/SDK/include/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -78,6 +78,7 @@ namespace Ndk Nz::LuaClass instancedRenderable; Nz::LuaClass model; Nz::LuaClass sprite; + Nz::LuaClass spriteLibrary; // Renderer Nz::LuaClass texture; diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index c0399ab3a..3a82ffe1a 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -58,6 +58,7 @@ namespace Ndk instancedRenderable("InstancedRenderable"), model("Model"), sprite("Sprite"), + spriteLibrary("SpriteLibrary"), // Renderer texture("Texture"), diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index 69545ccdf..3f59b7400 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -71,6 +71,14 @@ namespace Ndk sprite.BindMethod("SetTexture", &Nz::Sprite::SetTexture, true); sprite.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords); sprite.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect); + + /*********************************** Nz::SpriteLibrary ***********************************/ + + spriteLibrary.BindStaticMethod("Get", &Nz::SpriteLibrary::Get); + spriteLibrary.BindStaticMethod("Has", &Nz::SpriteLibrary::Has); + spriteLibrary.BindStaticMethod("Register", &Nz::SpriteLibrary::Register); + spriteLibrary.BindStaticMethod("Query", &Nz::SpriteLibrary::Query); + spriteLibrary.BindStaticMethod("Unregister", &Nz::SpriteLibrary::Unregister); } /*! @@ -84,5 +92,6 @@ namespace Ndk instancedRenderable.Register(instance); model.Register(instance); sprite.Register(instance); + spriteLibrary.Register(instance); } } \ No newline at end of file From 55a010e0de3541e9f579d65b32a44d6b9ab0e320 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 21 Oct 2016 17:39:04 +0200 Subject: [PATCH 19/58] Lua/LuaClass: Fix compilation --- include/Nazara/Lua/LuaClass.inl | 44 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl index 6c609e731..02ad685d8 100644 --- a/include/Nazara/Lua/LuaClass.inl +++ b/include/Nazara/Lua/LuaClass.inl @@ -249,6 +249,28 @@ namespace Nz lua.SetField("__tostring"); } + template + struct LuaClassImplFinalizerSetupProxy; + + template + struct LuaClassImplFinalizerSetupProxy + { + static void Setup(LuaInstance& lua) + { + lua.PushValue(1); // ClassInfo + lua.PushCFunction(LuaClass::FinalizerProxy, 1); + lua.SetField("__gc"); + } + }; + + template + struct LuaClassImplFinalizerSetupProxy + { + static void Setup(LuaInstance&) + { + } + }; + template void LuaClass::SetupFinalizer(LuaInstance& lua) { @@ -566,28 +588,6 @@ namespace Nz lua.PushString(info->name); return 1; } - - template - struct LuaClassImplFinalizerSetupProxy; - - template - struct LuaClassImplFinalizerSetupProxy - { - static void Setup(LuaInstance& lua) - { - lua.PushValue(1); // ClassInfo - lua.PushCFunction(LuaClass::FinalizerProxy, 1); - lua.SetField("__gc"); - } - }; - - template - struct LuaClassImplFinalizerSetupProxy - { - static void Setup(LuaInstance&) - { - } - }; } #include From 46e4bb41b5e3f7ec2950a0e45da15fba4b2dd6ca Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 24 Oct 2016 13:45:42 +0200 Subject: [PATCH 20/58] Lua/LuaClass: Fix global table --- include/Nazara/Lua/LuaClass.inl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl index 02ad685d8..faae84311 100644 --- a/include/Nazara/Lua/LuaClass.inl +++ b/include/Nazara/Lua/LuaClass.inl @@ -297,6 +297,9 @@ namespace Nz template void LuaClass::SetupGlobalTable(LuaInstance& lua) { + // Create the global table + lua.PushTable(); // Class = {} + // Create a metatable which will be used for our global table lua.PushTable(); // ClassMeta = {} @@ -317,9 +320,7 @@ namespace Nz SetupMethod(lua, StaticMethodProxy, pair.first, methodIndex); } - // Now let's create the global table - lua.PushTable(); // Class = {} - lua.SetMetatable(-2); // setmetatable(Class, ClassMeta) + lua.SetMetatable(-2); // setmetatable(Class, ClassMeta), pops ClassMeta lua.PushValue(-1); // As CreateReference() pops the table, push a copy m_info->globalTableRef = lua.CreateReference(); From bf31ee289ef99cedc891bb5085a06249a81acef1 Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 24 Oct 2016 14:25:02 +0200 Subject: [PATCH 21/58] Lua/LuaInstance: Add mutli-arg Push() --- include/Nazara/Lua/LuaInstance.hpp | 1 + include/Nazara/Lua/LuaInstance.inl | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/Nazara/Lua/LuaInstance.hpp b/include/Nazara/Lua/LuaInstance.hpp index 974cb9579..34a09d11a 100644 --- a/include/Nazara/Lua/LuaInstance.hpp +++ b/include/Nazara/Lua/LuaInstance.hpp @@ -123,6 +123,7 @@ namespace Nz void Pop(unsigned int n = 1U) const; template int Push(T arg) const; + template int Push(T firstArg, T2 secondArg, Args... args) const; void PushBoolean(bool value) const; void PushCFunction(LuaCFunction func, unsigned int upvalueCount = 0) const; template void PushField(const char* name, T&& arg, int tableIndex = -2) const; diff --git a/include/Nazara/Lua/LuaInstance.inl b/include/Nazara/Lua/LuaInstance.inl index e2b2c991f..c1eb48c34 100644 --- a/include/Nazara/Lua/LuaInstance.inl +++ b/include/Nazara/Lua/LuaInstance.inl @@ -606,6 +606,16 @@ namespace Nz return LuaImplReplyVal(*this, std::move(arg), TypeTag()); } + template + int LuaInstance::Push(T firstArg, T2 secondArg, Args... args) const + { + int valCount = 0; + valCount += Push(std::move(firstArg)); + valCount += Push(secondArg, std::forward(args)...); + + return valCount; + } + template void LuaInstance::PushField(const char* name, T&& arg, int tableIndex) const { From 2a08e19e7734509403de1c5122967b3f79e49d3c Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 25 Oct 2016 12:22:46 +0200 Subject: [PATCH 22/58] Sdk/Lua: Bind Material class --- SDK/include/NDK/LuaAPI.inl | 31 ++++ SDK/include/NDK/LuaBinding.hpp | 1 + SDK/src/NDK/LuaBinding.cpp | 1 + SDK/src/NDK/LuaBinding_Graphics.cpp | 246 +++++++++++++++++++++++++++- 4 files changed, 275 insertions(+), 4 deletions(-) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index 685603a6a..4d040c57a 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -545,6 +545,22 @@ namespace Nz return 1; } + /*! + * \brief Queries arguments for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param index Index type + * \param renderable Resulting reference to a material + */ + + inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MaterialRef* materialRef, TypeTag) + { + *materialRef = *static_cast(instance.CheckUserdata(index, "Material")); + + return 1; + } + /*! * \brief Queries arguments for Lua * \return 1 in case of success @@ -564,6 +580,7 @@ namespace Nz params->loadHeightMap = instance.CheckField("LoadHeightMap", params->loadHeightMap); params->loadNormalMap = instance.CheckField("LoadNormalMap", params->loadNormalMap); params->loadSpecularMap = instance.CheckField("LoadSpecularMap", params->loadSpecularMap); + params->shaderName = instance.CheckField("ShaderName", params->shaderName); return 1; } @@ -1035,6 +1052,20 @@ namespace Nz #ifndef NDK_SERVER + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param handle Resulting material + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, MaterialRef&& handle, TypeTag) + { + instance.PushInstance("Material", handle); + return 1; + } + /*! * \brief Replies by value for Lua * \return 1 in case of success diff --git a/SDK/include/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp index d22628470..f8de961e2 100644 --- a/SDK/include/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -76,6 +76,7 @@ namespace Ndk // Graphics Nz::LuaClass instancedRenderable; + Nz::LuaClass material; Nz::LuaClass model; Nz::LuaClass sprite; Nz::LuaClass spriteLibrary; diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index 3a82ffe1a..888e8fe4f 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -56,6 +56,7 @@ namespace Ndk // Graphics instancedRenderable("InstancedRenderable"), + material("Material"), model("Model"), sprite("Sprite"), spriteLibrary("SpriteLibrary"), diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index 3f59b7400..c36098c7a 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -14,6 +14,243 @@ namespace Ndk { /*********************************** Nz::InstancedRenderable ***********************************/ + /*********************************** Nz::Material ***********************************/ + material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount) + { + switch (argumentCount) + { + case 0: + Nz::PlacementNew(instance, Nz::Material::New()); + return true; + + case 1: + { + if (lua.IsOfType(1, "MaterialPipeline")) + { + Nz::PlacementNew(instance, Nz::Material::New(*static_cast(lua.ToUserdata(1)))); + return true; + } + else if (lua.IsOfType(1, "Material")) + { + Nz::PlacementNew(instance, Nz::Material::New(**static_cast(lua.ToUserdata(1)))); + return true; + } + else + { + int argIndex = 1; + Nz::PlacementNew(instance, Nz::Material::New(lua.Check(&argIndex))); + return true; + } + } + } + + lua.Error("No matching overload for constructor"); + return false; + }); + + material.BindMethod("Configure", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + { + if (lua.IsOfType(1, "MaterialPipeline")) + { + instance->Configure(*static_cast(lua.ToUserdata(1))); + return 0; + } + else + { + int argIndex = 1; + lua.Push(instance->Configure(lua.Check(&argIndex))); + return 1; + } + }); + + material.BindMethod("EnableAlphaTest", &Nz::Material::EnableAlphaTest); + material.BindMethod("EnableBlending", &Nz::Material::EnableBlending); + material.BindMethod("EnableColorWrite", &Nz::Material::EnableColorWrite); + material.BindMethod("EnableDepthBuffer", &Nz::Material::EnableDepthBuffer); + material.BindMethod("EnableDepthSorting", &Nz::Material::EnableDepthSorting); + material.BindMethod("EnableDepthWrite", &Nz::Material::EnableDepthWrite); + material.BindMethod("EnableFaceCulling", &Nz::Material::EnableFaceCulling); + material.BindMethod("EnableScissorTest", &Nz::Material::EnableScissorTest); + material.BindMethod("EnableShadowCasting", &Nz::Material::EnableShadowCasting); + material.BindMethod("EnableShadowReceive", &Nz::Material::EnableShadowReceive); + material.BindMethod("EnableStencilTest", &Nz::Material::EnableStencilTest); + + material.BindMethod("EnsurePipelineUpdate", &Nz::Material::EnsurePipelineUpdate); + + material.BindMethod("GetAlphaMap", &Nz::Material::GetAlphaMap); + material.BindMethod("GetAlphaThreshold", &Nz::Material::GetAlphaThreshold); + material.BindMethod("GetAmbientColor", &Nz::Material::GetAmbientColor); + material.BindMethod("GetDepthFunc", &Nz::Material::GetDepthFunc); + material.BindMethod("GetDepthMaterial", &Nz::Material::GetDepthMaterial); + material.BindMethod("GetDiffuseColor", &Nz::Material::GetDiffuseColor); + material.BindMethod("GetDiffuseMap", &Nz::Material::GetDiffuseMap); + //material.BindMethod("GetDiffuseSampler", &Nz::Material::GetDiffuseSampler); + material.BindMethod("GetDstBlend", &Nz::Material::GetDstBlend); + material.BindMethod("GetEmissiveMap", &Nz::Material::GetEmissiveMap); + material.BindMethod("GetFaceCulling", &Nz::Material::GetFaceCulling); + material.BindMethod("GetFaceFilling", &Nz::Material::GetFaceFilling); + material.BindMethod("GetHeightMap", &Nz::Material::GetHeightMap); + material.BindMethod("GetLineWidth", &Nz::Material::GetLineWidth); + material.BindMethod("GetNormalMap", &Nz::Material::GetNormalMap); + //material.BindMethod("GetPipeline", &Nz::Material::GetPipeline); + //material.BindMethod("GetPipelineInfo", &Nz::Material::GetPipelineInfo); + material.BindMethod("GetPointSize", &Nz::Material::GetPointSize); + //material.BindMethod("GetShader", &Nz::Material::GetShader); + material.BindMethod("GetShininess", &Nz::Material::GetShininess); + material.BindMethod("GetSpecularColor", &Nz::Material::GetSpecularColor); + material.BindMethod("GetSpecularMap", &Nz::Material::GetSpecularMap); + //material.BindMethod("GetSpecularSampler", &Nz::Material::GetSpecularSampler); + material.BindMethod("GetSrcBlend", &Nz::Material::GetSrcBlend); + + material.BindMethod("HasAlphaMap", &Nz::Material::HasAlphaMap); + material.BindMethod("HasDepthMaterial", &Nz::Material::HasDepthMaterial); + material.BindMethod("HasDiffuseMap", &Nz::Material::HasDiffuseMap); + material.BindMethod("HasEmissiveMap", &Nz::Material::HasEmissiveMap); + material.BindMethod("HasHeightMap", &Nz::Material::HasHeightMap); + material.BindMethod("HasNormalMap", &Nz::Material::HasNormalMap); + material.BindMethod("HasSpecularMap", &Nz::Material::HasSpecularMap); + + material.BindMethod("IsAlphaTestEnabled", &Nz::Material::IsAlphaTestEnabled); + material.BindMethod("IsBlendingEnabled", &Nz::Material::IsBlendingEnabled); + material.BindMethod("IsColorWriteEnabled", &Nz::Material::IsColorWriteEnabled); + material.BindMethod("IsDepthBufferEnabled", &Nz::Material::IsDepthBufferEnabled); + material.BindMethod("IsDepthSortingEnabled", &Nz::Material::IsDepthSortingEnabled); + material.BindMethod("IsDepthWriteEnabled", &Nz::Material::IsDepthWriteEnabled); + material.BindMethod("IsFaceCullingEnabled", &Nz::Material::IsFaceCullingEnabled); + material.BindMethod("IsScissorTestEnabled", &Nz::Material::IsScissorTestEnabled); + material.BindMethod("IsStencilTestEnabled", &Nz::Material::IsStencilTestEnabled); + material.BindMethod("IsShadowCastingEnabled", &Nz::Material::IsShadowCastingEnabled); + material.BindMethod("IsShadowReceiveEnabled", &Nz::Material::IsShadowReceiveEnabled); + + material.BindMethod("LoadFromFile", &Nz::Material::LoadFromFile); + + material.BindMethod("Reset", &Nz::Material::Reset); + + material.BindMethod("SetAlphaThreshold", &Nz::Material::SetAlphaThreshold); + material.BindMethod("SetAmbientColor", &Nz::Material::SetAmbientColor); + material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc); + material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc); + material.BindMethod("SetDepthMaterial", &Nz::Material::SetDepthMaterial); + material.BindMethod("SetDiffuseColor", &Nz::Material::SetDiffuseColor); + //material.BindMethod("SetDiffuseSampler", &Nz::Material::SetDiffuseSampler); + material.BindMethod("SetDstBlend", &Nz::Material::SetDstBlend); + material.BindMethod("SetFaceCulling", &Nz::Material::SetFaceCulling); + material.BindMethod("SetFaceFilling", &Nz::Material::SetFaceFilling); + material.BindMethod("SetLineWidth", &Nz::Material::SetLineWidth); + material.BindMethod("SetPointSize", &Nz::Material::SetPointSize); + material.BindMethod("SetShininess", &Nz::Material::SetShininess); + material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor); + material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor); + //material.BindMethod("SetSpecularSampler", &Nz::Material::SetSpecularSampler); + material.BindMethod("SetSrcBlend", &Nz::Material::SetSrcBlend); + + material.BindStaticMethod("GetDefault", &Nz::Material::GetDefault); + + material.BindMethod("SetAlphaMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + { + if (lua.IsOfType(1, "Texture")) + { + instance->SetAlphaMap(*static_cast(lua.ToUserdata(1))); + return 0; + } + else + { + int argIndex = 1; + lua.Push(instance->SetAlphaMap(lua.Check(&argIndex))); + return 1; + } + }); + + material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + { + if (lua.IsOfType(1, "Texture")) + { + instance->SetDiffuseMap(*static_cast(lua.ToUserdata(1))); + return 0; + } + else + { + int argIndex = 1; + lua.Push(instance->SetDiffuseMap(lua.Check(&argIndex))); + return 1; + } + }); + + material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + { + if (lua.IsOfType(1, "Texture")) + { + instance->SetEmissiveMap(*static_cast(lua.ToUserdata(1))); + return 0; + } + else + { + int argIndex = 1; + lua.Push(instance->SetEmissiveMap(lua.Check(&argIndex))); + return 1; + } + }); + + material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + { + if (lua.IsOfType(1, "Texture")) + { + instance->SetHeightMap(*static_cast(lua.ToUserdata(1))); + return 0; + } + else + { + int argIndex = 1; + lua.Push(instance->SetHeightMap(lua.Check(&argIndex))); + return 1; + } + }); + + material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + { + if (lua.IsOfType(1, "Texture")) + { + instance->SetNormalMap(*static_cast(lua.ToUserdata(1))); + return 0; + } + else + { + int argIndex = 1; + lua.Push(instance->SetNormalMap(lua.Check(&argIndex))); + return 1; + } + }); + + material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + { + if (lua.IsOfType(1, "UberShader")) + { + instance->SetShader(*static_cast(lua.ToUserdata(1))); + return 0; + } + else + { + int argIndex = 1; + lua.Push(instance->SetShader(lua.Check(&argIndex))); + return 1; + } + }); + + material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + { + if (lua.IsOfType(1, "Texture")) + { + instance->SetSpecularMap(*static_cast(lua.ToUserdata(1))); + return 0; + } + else + { + int argIndex = 1; + lua.Push(instance->SetSpecularMap(lua.Check(&argIndex))); + return 1; + } + }); + /*********************************** Nz::Model ***********************************/ model.Inherit(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef* { @@ -26,7 +263,7 @@ namespace Ndk return true; }); - //modelClass.SetMethod("GetMaterial", &Nz::Model::GetMaterial); + //model.BindMethod("GetMaterial", &Nz::Model::GetMaterial); model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount); //modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh); model.BindMethod("GetSkin", &Nz::Model::GetSkin); @@ -37,7 +274,7 @@ namespace Ndk model.BindMethod("Reset", &Nz::Model::Reset); - //modelClass.SetMethod("SetMaterial", &Nz::Model::SetMaterial); + //model.BindMethod("SetMaterial", &Nz::Model::SetMaterial); //modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh); //modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence); model.BindMethod("SetSkin", &Nz::Model::SetSkin); @@ -57,7 +294,7 @@ namespace Ndk sprite.BindMethod("GetColor", &Nz::Sprite::GetColor); sprite.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor); - //spriteClass.BindMethod("GetMaterial", &Nz::Sprite::GetMaterial); + sprite.BindMethod("GetMaterial", &Nz::Sprite::GetMaterial); sprite.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin); sprite.BindMethod("GetSize", &Nz::Sprite::GetSize); sprite.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords); @@ -65,7 +302,7 @@ namespace Ndk sprite.BindMethod("SetColor", &Nz::Sprite::SetColor); sprite.BindMethod("SetCornerColor", &Nz::Sprite::SetCornerColor); sprite.BindMethod("SetDefaultMaterial", &Nz::Sprite::SetDefaultMaterial); - //spriteClass.BindMethod("SetMaterial", &Nz::Sprite::SetMaterial, true); + sprite.BindMethod("SetMaterial", &Nz::Sprite::SetMaterial, true); sprite.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin); sprite.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize); sprite.BindMethod("SetTexture", &Nz::Sprite::SetTexture, true); @@ -90,6 +327,7 @@ namespace Ndk void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance) { instancedRenderable.Register(instance); + material.Register(instance); model.Register(instance); sprite.Register(instance); spriteLibrary.Register(instance); From b27cfd30afaeb17734a6c935e1c28d97e3c87dcf Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 25 Oct 2016 12:22:57 +0200 Subject: [PATCH 23/58] Sdk/VelocityComponent: Cleanup --- SDK/include/NDK/Components/VelocityComponent.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/SDK/include/NDK/Components/VelocityComponent.hpp b/SDK/include/NDK/Components/VelocityComponent.hpp index 33d97b030..909adf4d4 100644 --- a/SDK/include/NDK/Components/VelocityComponent.hpp +++ b/SDK/include/NDK/Components/VelocityComponent.hpp @@ -12,7 +12,6 @@ namespace Ndk { - class Entity; class VelocityComponent; using VelocityComponentHandle = Nz::ObjectHandle; From fa7d6a10b0f1b5609a77d525b51599a89ddbd078 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 25 Oct 2016 13:10:12 +0200 Subject: [PATCH 24/58] Lua/LuaInstance: Fix PushInstance memory corruption Whoops --- include/Nazara/Lua/LuaInstance.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/Nazara/Lua/LuaInstance.inl b/include/Nazara/Lua/LuaInstance.inl index c1eb48c34..ab563d301 100644 --- a/include/Nazara/Lua/LuaInstance.inl +++ b/include/Nazara/Lua/LuaInstance.inl @@ -658,7 +658,7 @@ namespace Nz template void LuaInstance::PushInstance(const char* tname, const T& instance) const { - T* userdata = static_cast(PushUserdata(sizeof(T*))); + T* userdata = static_cast(PushUserdata(sizeof(T))); PlacementNew(userdata, instance); SetMetatable(tname); @@ -667,7 +667,7 @@ namespace Nz template void LuaInstance::PushInstance(const char* tname, T&& instance) const { - T* userdata = static_cast(PushUserdata(sizeof(T*))); + T* userdata = static_cast(PushUserdata(sizeof(T))); PlacementNew(userdata, std::move(instance)); SetMetatable(tname); @@ -676,7 +676,7 @@ namespace Nz template void LuaInstance::PushInstance(const char* tname, Args&&... args) const { - T* userdata = static_cast(PushUserdata(sizeof(T*))); + T* userdata = static_cast(PushUserdata(sizeof(T))); PlacementNew(userdata, std::forward(args)...); SetMetatable(tname); From b5a32d7eb216ddc6225b7a1793e407d97c9c40fe Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 25 Oct 2016 13:14:16 +0200 Subject: [PATCH 25/58] Lua/LuaClass: Fix static methods --- include/Nazara/Lua/LuaClass.inl | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl index faae84311..4f0144fc8 100644 --- a/include/Nazara/Lua/LuaClass.inl +++ b/include/Nazara/Lua/LuaClass.inl @@ -280,16 +280,9 @@ namespace Nz template void LuaClass::SetupGetter(LuaInstance& lua, LuaCFunction proxy) { - if (m_info->getter || !m_info->parentGetters.empty()) - { - lua.PushValue(1); // ClassInfo - lua.PushValue(-2); // Metatable - lua.PushCFunction(proxy, 2); - } - else - // Optimize by assigning the metatable instead of a search function - // This is only possible if we have no custom getter nor parent - lua.PushValue(-1); // Metatable + lua.PushValue(1); // ClassInfo + lua.PushValue(-2); // Metatable + lua.PushCFunction(proxy, 2); lua.SetField("__index"); // Getter } @@ -306,7 +299,14 @@ namespace Nz if (m_info->constructor) SetupConstructor(lua); - SetupGetter(lua, StaticGetterProxy); + if (m_info->staticGetter) + SetupGetter(lua, StaticGetterProxy); + else + { + // Optimize by assigning the metatable instead of a search function + lua.PushValue(-1); // Metatable + lua.SetField("__index"); + } if (m_info->staticSetter) SetupSetter(lua, StaticSetterProxy); @@ -335,7 +335,16 @@ namespace Nz NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance"); { SetupFinalizer(lua); - SetupGetter(lua, GetterProxy); + + if (m_info->getter || !m_info->parentGetters.empty()) + SetupGetter(lua, GetterProxy); + else + { + // Optimize by assigning the metatable instead of a search function + // This is only possible if we have no custom getter nor parent + lua.PushValue(-1); // Metatable + lua.SetField("__index"); + } if (m_info->setter) SetupSetter(lua, SetterProxy); From d6f6b4421e00cfb2ccc8198464c8cf7ee654e106 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 25 Oct 2016 13:52:26 +0200 Subject: [PATCH 26/58] Sdk/Lua: Fix GraphicsComponent:Attach not taking other overloads into account --- SDK/src/NDK/LuaBinding_SDK.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index 61dc15751..3baab6f69 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -146,7 +146,7 @@ namespace Ndk void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0); */ - unsigned int argCount = std::min(lua.GetStackTop(), 1U); + unsigned int argCount = std::min(lua.GetStackTop(), 3U); switch (argCount) { @@ -171,9 +171,8 @@ namespace Ndk else if (lua.IsOfType(index, "Matrix4")) { Nz::Matrix4f localMatrix = lua.Check(&index); - int renderOrder = lua.Check(&index); - gfxComponent->Attach(renderable, localMatrix, renderOrder); + gfxComponent->Attach(renderable, localMatrix); } else break; @@ -196,8 +195,6 @@ namespace Ndk lua.Error("No matching overload for method GetMemoryUsage"); return 0; }); - - graphicsComponent.BindMethod("Attach", (void(Ndk::GraphicsComponent::*)(Nz::InstancedRenderableRef, int)) &GraphicsComponent::Attach, 0); #endif From b81b774c511a1271845f61bdb9923640e9f0bbe5 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 10:27:17 +0200 Subject: [PATCH 27/58] Core/ObjectRef: Fix <= operator between two ObjectRef --- include/Nazara/Core/ObjectRef.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Nazara/Core/ObjectRef.hpp b/include/Nazara/Core/ObjectRef.hpp index d1cd13ec0..6a69a22ee 100644 --- a/include/Nazara/Core/ObjectRef.hpp +++ b/include/Nazara/Core/ObjectRef.hpp @@ -56,7 +56,7 @@ namespace Nz template bool operator<(const T& lhs, const ObjectRef& rhs); template bool operator<(const ObjectRef& lhs, const T& rhs); - template bool operator<=(const ObjectRef, const ObjectRef& rhs); + template bool operator<=(const ObjectRef& lhs, const ObjectRef& rhs); template bool operator<=(const T& lhs, const ObjectRef& rhs); template bool operator<=(const ObjectRef& lhs, const T& rhs); From f867c20c7c7047a90e4a00f587f24ca218f30028 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 10:40:41 +0200 Subject: [PATCH 28/58] Core/ResourceManager: Fix Purge() compilation --- include/Nazara/Core/ResourceManager.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Nazara/Core/ResourceManager.inl b/include/Nazara/Core/ResourceManager.inl index edc85068b..6fec2aae0 100644 --- a/include/Nazara/Core/ResourceManager.inl +++ b/include/Nazara/Core/ResourceManager.inl @@ -78,7 +78,7 @@ namespace Nz while (it != Type::s_managerMap.end()) { const ObjectRef& ref = it->second; - if (ref.GetReferenceCount() == 1) // Are we the only ones to own the resource ? + if (ref->GetReferenceCount() == 1) // Are we the only ones to own the resource ? { NazaraDebug("Purging resource from file " + ref->GetFilePath()); Type::s_managerMap.erase(it++); // Then we erase it From e59bd4ba359b879ef1c4796c6a0a64c5b96e88d8 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 10:47:17 +0200 Subject: [PATCH 29/58] Matrix4: Fix GetColumn and GetRow code --- include/Nazara/Math/Matrix4.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 4cf2eaa6e..021cb6378 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -242,7 +242,7 @@ namespace Nz } #endif - T* ptr = (&m11) + column*4; + const T* ptr = (&m11) + column*4; return Vector4(ptr); } @@ -636,7 +636,7 @@ namespace Nz } #endif - T* ptr = &m11; + const T* ptr = &m11; return Vector4(ptr[row], ptr[row+4], ptr[row+8], ptr[row+12]); } From 9328a8124dec49fe8fa5ab4da654cd1efffd6468 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 10:47:36 +0200 Subject: [PATCH 30/58] Math/Quaternion: Fix compilation of operator* with double instance --- include/Nazara/Math/Quaternion.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/Nazara/Math/Quaternion.inl b/include/Nazara/Math/Quaternion.inl index bc672cd81..5c7df28cd 100644 --- a/include/Nazara/Math/Quaternion.inl +++ b/include/Nazara/Math/Quaternion.inl @@ -553,9 +553,9 @@ namespace Nz template Vector3 Quaternion::operator*(const Vector3& vec) const { - Vector3f quatVec(x, y, z); - Vector3f uv = quatVec.CrossProduct(vec); - Vector3f uuv = quatVec.CrossProduct(uv); + Vector3 quatVec(x, y, z); + Vector3 uv = quatVec.CrossProduct(vec); + Vector3 uuv = quatVec.CrossProduct(uv); uv *= F(2.0) * w; uuv *= F(2.0); From c58ec94e2d07c5d636c1db4a610588f9aceb3953 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 10:48:02 +0200 Subject: [PATCH 31/58] Core/Algorithm: Fix return type of Apply() --- include/Nazara/Core/Algorithm.hpp | 4 ++-- include/Nazara/Core/Algorithm.inl | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/Nazara/Core/Algorithm.hpp b/include/Nazara/Core/Algorithm.hpp index be25f4773..5bb461f26 100644 --- a/include/Nazara/Core/Algorithm.hpp +++ b/include/Nazara/Core/Algorithm.hpp @@ -20,8 +20,8 @@ namespace Nz class AbstractHash; class ByteArray; - template auto Apply(F&& fn, Tuple&& t); - template auto Apply(O& object, F&& fn, Tuple&& t); + template decltype(auto) Apply(F&& fn, Tuple&& t); + template decltype(auto) Apply(O& object, F&& fn, Tuple&& t); template ByteArray ComputeHash(HashType hash, const T& v); template ByteArray ComputeHash(AbstractHash* hash, const T& v); template constexpr std::size_t CountOf(T(&name)[N]) noexcept; diff --git a/include/Nazara/Core/Algorithm.inl b/include/Nazara/Core/Algorithm.inl index 15827144d..b02924446 100644 --- a/include/Nazara/Core/Algorithm.inl +++ b/include/Nazara/Core/Algorithm.inl @@ -19,13 +19,13 @@ namespace Nz { // http://www.cppsamples.com/common-tasks/apply-tuple-to-function.html template - auto ApplyImplFunc(F&& fn, Tuple&& t, std::index_sequence) + decltype(auto) ApplyImplFunc(F&& fn, Tuple&& t, std::index_sequence) { return std::forward(fn)(std::get(std::forward(t))...); } template - auto ApplyImplMethod(O& object, F&& fn, Tuple&& t, std::index_sequence) + decltype(auto) ApplyImplMethod(O& object, F&& fn, Tuple&& t, std::index_sequence) { return (object .* std::forward(fn))(std::get(std::forward(t))...); } @@ -44,7 +44,7 @@ namespace Nz * \see Apply */ template - auto Apply(F&& fn, Tuple&& t) + decltype(auto) Apply(F&& fn, Tuple&& t) { constexpr std::size_t tSize = std::tuple_size::type>::value; @@ -63,7 +63,7 @@ namespace Nz * \see Apply */ template - auto Apply(O& object, F&& fn, Tuple&& t) + decltype(auto) Apply(O& object, F&& fn, Tuple&& t) { constexpr std::size_t tSize = std::tuple_size::type>::value; From 5ffc5a8784905b1b243656f5570b13907e3982c9 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 11:22:35 +0200 Subject: [PATCH 32/58] Lua/LuaClass: Don't remove instance from the Lua stack The instance Lua entry now remains as the first index, shifting all the parameters indexes by 1 --- SDK/include/NDK/LuaBinding.hpp | 2 +- SDK/src/NDK/LuaBinding_Audio.cpp | 12 ++--- SDK/src/NDK/LuaBinding_Core.cpp | 32 ++++++------- SDK/src/NDK/LuaBinding_Graphics.cpp | 74 ++++++++++++++--------------- SDK/src/NDK/LuaBinding_Math.cpp | 72 ++++++++++++++-------------- SDK/src/NDK/LuaBinding_Network.cpp | 6 +-- SDK/src/NDK/LuaBinding_SDK.cpp | 40 ++++++++-------- SDK/src/NDK/LuaBinding_Utility.cpp | 46 +++++++++--------- include/Nazara/Lua/LuaClass.hpp | 2 +- include/Nazara/Lua/LuaClass.inl | 20 ++++---- include/Nazara/Lua/LuaInstance.inl | 20 +++++++- 11 files changed, 171 insertions(+), 155 deletions(-) diff --git a/SDK/include/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp index f8de961e2..da6d282d1 100644 --- a/SDK/include/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -124,7 +124,7 @@ namespace Ndk Nz::String name; }; - ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 1); + ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 2); std::vector m_componentBinding; std::unordered_map m_componentBindingByName; diff --git a/SDK/src/NDK/LuaBinding_Audio.cpp b/SDK/src/NDK/LuaBinding_Audio.cpp index 7b81b0c8e..46791b6c7 100644 --- a/SDK/src/NDK/LuaBinding_Audio.cpp +++ b/SDK/src/NDK/LuaBinding_Audio.cpp @@ -41,7 +41,7 @@ namespace Ndk music.BindMethod("Stop", &Nz::Music::Stop); // Manual - music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music) -> int + music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music, std::size_t /*argumentCount*/) -> int { Nz::StringStream stream("Music("); stream << music.GetFilePath() << ')'; @@ -65,7 +65,7 @@ namespace Ndk sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); // Manual - sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int + sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound, std::size_t /*argumentCount*/) -> int { Nz::StringStream stream("Sound("); if (const Nz::SoundBuffer* buffer = sound.GetBuffer()) @@ -101,9 +101,9 @@ namespace Ndk soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported); // Manual - soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int + soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int { - int index = 1; + int index = 2; Nz::AudioFormat format = lua.Check(&index); unsigned int sampleCount = lua.Check(&index); unsigned int sampleRate = lua.Check(&index); @@ -116,13 +116,13 @@ namespace Ndk return 1; }); - soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int + 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) -> int + soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int { Nz::StringStream stream("SoundBuffer("); if (instance->IsValid()) diff --git a/SDK/src/NDK/LuaBinding_Core.cpp b/SDK/src/NDK/LuaBinding_Core.cpp index 12c559936..dc149e3d0 100644 --- a/SDK/src/NDK/LuaBinding_Core.cpp +++ b/SDK/src/NDK/LuaBinding_Core.cpp @@ -15,7 +15,7 @@ namespace Ndk /*********************************** Nz::Clock **********************************/ clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock, std::size_t /*argumentCount*/) { - int argIndex = 1; + int argIndex = 2; Nz::Int64 startingValue = lua.Check(&argIndex, 0); bool paused = lua.Check(&argIndex, false); @@ -32,7 +32,7 @@ namespace Ndk clock.BindMethod("Unpause", &Nz::Clock::Unpause); // Manual - clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int { + clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock, std::size_t /*argumentCount*/) -> int { Nz::StringStream stream("Clock(Elapsed: "); stream << clock.GetSeconds(); stream << "s, Paused: "; @@ -48,7 +48,7 @@ namespace Ndk { std::size_t argCount = std::min(argumentCount, 1U); - int argIndex = 1; + int argIndex = 2; switch (argCount) { case 0: @@ -85,7 +85,7 @@ namespace Ndk directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent); // Manual - directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int { + directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory, std::size_t /*argumentCount*/) -> int { Nz::StringStream stream("Directory("); stream << directory.GetPath(); stream << ')'; @@ -110,8 +110,8 @@ namespace Ndk stream.BindMethod("IsWritable", &Nz::Stream::IsWritable); stream.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos); - stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { - int argIndex = 1; + stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream, std::size_t /*argumentCount*/) -> int { + int argIndex = 2; std::size_t length = lua.Check(&argIndex); @@ -122,8 +122,8 @@ namespace Ndk return 1; }); - stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { - int argIndex = 1; + stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream, std::size_t /*argumentCount*/) -> int { + int argIndex = 2; std::size_t bufferSize = 0; const char* buffer = lua.CheckString(argIndex, &bufferSize); @@ -142,7 +142,7 @@ namespace Ndk { std::size_t argCount = std::min(argumentCount, 1U); - int argIndex = 1; + int argIndex = 2; switch (argCount) { case 0: @@ -201,11 +201,11 @@ namespace Ndk file.BindStaticMethod("Rename", &Nz::File::Rename); // Manual - file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int + file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file, std::size_t argumentCount) -> int { - unsigned int argCount = std::min(lua.GetStackTop(), 2U); + std::size_t argCount = std::min(argumentCount, 2U); - int argIndex = 1; + int argIndex = 2; switch (argCount) { case 0: @@ -224,11 +224,11 @@ namespace Ndk return 0; }); - file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int + file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file, std::size_t argumentCount) -> int { - unsigned int argCount = std::min(lua.GetStackTop(), 2U); + std::size_t argCount = std::min(argumentCount, 2U); - int argIndex = 1; + int argIndex = 2; switch (argCount) { case 1: @@ -246,7 +246,7 @@ namespace Ndk return 0; }); - file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { + file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file, std::size_t /*argumentCount*/) -> int { Nz::StringStream stream("File("); if (file.IsOpen()) stream << "Path: " << file.GetPath(); diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index c36098c7a..597c0dc68 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -25,19 +25,19 @@ namespace Ndk case 1: { - if (lua.IsOfType(1, "MaterialPipeline")) + int argIndex = 1; + if (lua.IsOfType(argIndex, "MaterialPipeline")) { - Nz::PlacementNew(instance, Nz::Material::New(*static_cast(lua.ToUserdata(1)))); + Nz::PlacementNew(instance, Nz::Material::New(*static_cast(lua.ToUserdata(argIndex)))); return true; } - else if (lua.IsOfType(1, "Material")) + else if (lua.IsOfType(argIndex, "Material")) { - Nz::PlacementNew(instance, Nz::Material::New(**static_cast(lua.ToUserdata(1)))); + Nz::PlacementNew(instance, Nz::Material::New(**static_cast(lua.ToUserdata(argIndex)))); return true; } else { - int argIndex = 1; Nz::PlacementNew(instance, Nz::Material::New(lua.Check(&argIndex))); return true; } @@ -48,16 +48,16 @@ namespace Ndk return false; }); - material.BindMethod("Configure", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + material.BindMethod("Configure", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - if (lua.IsOfType(1, "MaterialPipeline")) + int argIndex = 2; + if (lua.IsOfType(argIndex, "MaterialPipeline")) { - instance->Configure(*static_cast(lua.ToUserdata(1))); + instance->Configure(*static_cast(lua.ToUserdata(argIndex))); return 0; } else { - int argIndex = 1; lua.Push(instance->Configure(lua.Check(&argIndex))); return 1; } @@ -146,106 +146,106 @@ namespace Ndk material.BindStaticMethod("GetDefault", &Nz::Material::GetDefault); - material.BindMethod("SetAlphaMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + material.BindMethod("SetAlphaMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - if (lua.IsOfType(1, "Texture")) + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) { - instance->SetAlphaMap(*static_cast(lua.ToUserdata(1))); + instance->SetAlphaMap(*static_cast(lua.ToUserdata(argIndex))); return 0; } else { - int argIndex = 1; lua.Push(instance->SetAlphaMap(lua.Check(&argIndex))); return 1; } }); - material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - if (lua.IsOfType(1, "Texture")) + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) { - instance->SetDiffuseMap(*static_cast(lua.ToUserdata(1))); + instance->SetDiffuseMap(*static_cast(lua.ToUserdata(argIndex))); return 0; } else { - int argIndex = 1; lua.Push(instance->SetDiffuseMap(lua.Check(&argIndex))); return 1; } }); - material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - if (lua.IsOfType(1, "Texture")) + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) { - instance->SetEmissiveMap(*static_cast(lua.ToUserdata(1))); + instance->SetEmissiveMap(*static_cast(lua.ToUserdata(argIndex))); return 0; } else { - int argIndex = 1; lua.Push(instance->SetEmissiveMap(lua.Check(&argIndex))); return 1; } }); - material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - if (lua.IsOfType(1, "Texture")) + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) { - instance->SetHeightMap(*static_cast(lua.ToUserdata(1))); + instance->SetHeightMap(*static_cast(lua.ToUserdata(argIndex))); return 0; } else { - int argIndex = 1; lua.Push(instance->SetHeightMap(lua.Check(&argIndex))); return 1; } }); - material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - if (lua.IsOfType(1, "Texture")) + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) { - instance->SetNormalMap(*static_cast(lua.ToUserdata(1))); + instance->SetNormalMap(*static_cast(lua.ToUserdata(argIndex))); return 0; } else { - int argIndex = 1; lua.Push(instance->SetNormalMap(lua.Check(&argIndex))); return 1; } }); - material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - if (lua.IsOfType(1, "UberShader")) + int argIndex = 2; + if (lua.IsOfType(argIndex, "UberShader")) { - instance->SetShader(*static_cast(lua.ToUserdata(1))); + instance->SetShader(*static_cast(lua.ToUserdata(argIndex))); return 0; } else { - int argIndex = 1; lua.Push(instance->SetShader(lua.Check(&argIndex))); return 1; } }); - material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance) -> int + material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int { - if (lua.IsOfType(1, "Texture")) + int argIndex = 2; + if (lua.IsOfType(argIndex, "Texture")) { - instance->SetSpecularMap(*static_cast(lua.ToUserdata(1))); + instance->SetSpecularMap(*static_cast(lua.ToUserdata(argIndex))); return 0; } else { - int argIndex = 1; lua.Push(instance->SetSpecularMap(lua.Check(&argIndex))); return 1; } diff --git a/SDK/src/NDK/LuaBinding_Math.cpp b/SDK/src/NDK/LuaBinding_Math.cpp index 989e2c28c..00707c9e3 100644 --- a/SDK/src/NDK/LuaBinding_Math.cpp +++ b/SDK/src/NDK/LuaBinding_Math.cpp @@ -42,7 +42,7 @@ namespace Ndk eulerAngles.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) { std::size_t length; - const char* ypr = lua.CheckString(1, &length); + const char* ypr = lua.CheckString(2, &length); switch (length) { @@ -99,8 +99,8 @@ namespace Ndk eulerAngles.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) { std::size_t length; - const char* ypr = lua.CheckString(1, &length); - double value = lua.CheckNumber(2); + const char* ypr = lua.CheckString(2, &length); + double value = lua.CheckNumber(3); switch (length) { @@ -191,9 +191,9 @@ namespace Ndk matrix4d.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) { - int argIndex = 1; - std::size_t index = lua.Check(&argIndex); - if (index < 1 || index > 16) + 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]); @@ -202,12 +202,12 @@ namespace Ndk matrix4d.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance) { - int argIndex = 1; - std::size_t index = lua.Check(&argIndex); - if (index < 1 || index > 16) + 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(argIndex); + instance[index - 1] = lua.CheckNumber(3); return true; }); @@ -265,11 +265,11 @@ namespace Ndk rect.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) { - switch (lua.GetType(1)) + switch (lua.GetType(2)) { case Nz::LuaType_Number: { - auto index = lua.CheckBoundInteger(1); + auto index = lua.CheckBoundInteger(2); if (index < 1 || index > 4) return false; @@ -280,7 +280,7 @@ namespace Ndk case Nz::LuaType_String: { std::size_t length; - const char* xywh = lua.CheckString(1, &length); + const char* xywh = lua.CheckString(2, &length); if (length != 1) break; @@ -318,11 +318,11 @@ namespace Ndk rect.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance) { - switch (lua.GetType(1)) + switch (lua.GetType(2)) { case Nz::LuaType_Number: { - auto index = lua.CheckBoundInteger(1); + auto index = lua.CheckBoundInteger(2); if (index < 1 || index > 4) return false; @@ -333,12 +333,12 @@ namespace Ndk case Nz::LuaType_String: { std::size_t length; - const char* xywh = lua.CheckString(1, &length); + const char* xywh = lua.CheckString(2, &length); if (length != 1) break; - double value = lua.CheckNumber(2); + double value = lua.CheckNumber(3); switch (xywh[0]) { @@ -412,7 +412,7 @@ namespace Ndk quaternion.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) { std::size_t length; - const char* wxyz = lua.CheckString(1, &length); + const char* wxyz = lua.CheckString(2, &length); if (length != 1) return false; @@ -442,12 +442,12 @@ namespace Ndk quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) { std::size_t length; - const char* wxyz = lua.CheckString(1, &length); + const char* wxyz = lua.CheckString(2, &length); if (length != 1) return false; - double value = lua.CheckNumber(2); + double value = lua.CheckNumber(3); switch (wxyz[0]) { @@ -507,11 +507,11 @@ namespace Ndk vector2d.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) { - switch (lua.GetType(1)) + switch (lua.GetType(2)) { case Nz::LuaType_Number: { - long long index = lua.CheckInteger(1); + long long index = lua.CheckInteger(2); if (index < 1 || index > 2) return false; @@ -522,7 +522,7 @@ namespace Ndk case Nz::LuaType_String: { std::size_t length; - const char* xy = lua.CheckString(1, &length); + const char* xy = lua.CheckString(2, &length); if (length != 1) break; @@ -552,27 +552,27 @@ namespace Ndk vector2d.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) { - switch (lua.GetType(1)) + switch (lua.GetType(2)) { case Nz::LuaType_Number: { - long long index = lua.CheckInteger(1); + long long index = lua.CheckInteger(2); if (index < 1 || index > 2) return false; - instance[index - 1] = lua.CheckNumber(2); + instance[index - 1] = lua.CheckNumber(3); return true; } case Nz::LuaType_String: { std::size_t length; - const char* xy = lua.CheckString(1, &length); + const char* xy = lua.CheckString(2, &length); if (length != 1) break; - double value = lua.CheckNumber(2); + double value = lua.CheckNumber(3); switch (xy[0]) { @@ -644,11 +644,11 @@ namespace Ndk vector3d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) { - switch (lua.GetType(1)) + switch (lua.GetType(2)) { case Nz::LuaType_Number: { - long long index = lua.CheckInteger(1); + long long index = lua.CheckInteger(2); if (index < 1 || index > 3) return false; @@ -659,7 +659,7 @@ namespace Ndk case Nz::LuaType_String: { std::size_t length; - const char* xyz = lua.CheckString(1, &length); + const char* xyz = lua.CheckString(2, &length); if (length != 1) break; @@ -693,27 +693,27 @@ namespace Ndk vector3d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) { - switch (lua.GetType(1)) + switch (lua.GetType(2)) { case Nz::LuaType_Number: { - long long index = lua.CheckInteger(1); + long long index = lua.CheckInteger(2); if (index < 1 || index > 3) return false; - instance[index - 1] = lua.CheckNumber(2); + instance[index - 1] = lua.CheckNumber(3); return true; } case Nz::LuaType_String: { std::size_t length; - const char* xyz = lua.CheckString(1, &length); + const char* xyz = lua.CheckString(2, &length); if (length != 1) break; - double value = lua.CheckNumber(2); + double value = lua.CheckNumber(3); switch (xyz[0]) { diff --git a/SDK/src/NDK/LuaBinding_Network.cpp b/SDK/src/NDK/LuaBinding_Network.cpp index 430cd1208..bd1105962 100644 --- a/SDK/src/NDK/LuaBinding_Network.cpp +++ b/SDK/src/NDK/LuaBinding_Network.cpp @@ -25,7 +25,7 @@ namespace Ndk { std::size_t argCount = std::min(argumentCount, 9U); - int argIndex = 1; + int argIndex = 2; switch (argCount) { case 0: @@ -83,7 +83,7 @@ namespace Ndk Nz::String service; Nz::ResolveError error = Nz::ResolveError_Unknown; - int argIndex = 1; + int argIndex = 2; Nz::String hostName = Nz::IpAddress::ResolveAddress(instance.Check(&argIndex), &service, &error); if (error == Nz::ResolveError_NoError) @@ -104,7 +104,7 @@ namespace Ndk { Nz::ResolveError error = Nz::ResolveError_Unknown; - int argIndex = 1; + int argIndex = 2; Nz::NetProtocol protocol = instance.Check(&argIndex); Nz::String hostname = instance.Check(&argIndex); Nz::String service = instance.Check(&argIndex, "http"); diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index 3baab6f69..3046f2483 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -25,7 +25,7 @@ namespace Ndk application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled); #endif - application.BindMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application) -> int + application.BindMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application, std::size_t /*argumentCount*/) -> int { instance.Push(application->AddWorld().CreateHandle()); return 1; @@ -73,21 +73,21 @@ namespace Ndk entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents); entity.BindMethod("__tostring", &EntityHandle::ToString); - entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int + 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) -> int + 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) -> int + entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int { ComponentBinding* binding = QueryComponentIndex(instance); @@ -105,7 +105,7 @@ namespace Ndk velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) { std::size_t length; - const char* member = lua.CheckString(1, &length); + const char* member = lua.CheckString(2, &length); if (std::strcmp(member, "Linear") == 0) { @@ -119,9 +119,9 @@ namespace Ndk velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) { std::size_t length; - const char* member = lua.CheckString(1, &length); + const char* member = lua.CheckString(2, &length); - int argIndex = 2; + int argIndex = 3; if (std::strcmp(member, "Linear") == 0) { instance->linearVelocity = lua.Check(&argIndex); @@ -139,38 +139,38 @@ namespace Ndk #ifndef NDK_SERVER /*********************************** Ndk::GraphicsComponent **********************************/ - graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent *gfxComponent) -> int + graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent *gfxComponent, 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); */ - unsigned int argCount = std::min(lua.GetStackTop(), 3U); + std::size_t argCount = std::min(argumentCount, 3U); switch (argCount) { case 1: { - int argIndex = 1; + int argIndex = 2; gfxComponent->Attach(lua.Check(&argIndex)); return 0; } case 2: { - int index = 1; - Nz::InstancedRenderableRef renderable = lua.Check(&index); + int argIndex = 2; + Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); - if (lua.IsOfType(index, Nz::LuaType_Number)) + if (lua.IsOfType(argIndex, Nz::LuaType_Number)) { - int renderOrder = lua.Check(&index); + int renderOrder = lua.Check(&argIndex); gfxComponent->Attach(renderable, renderOrder); } - else if (lua.IsOfType(index, "Matrix4")) + else if (lua.IsOfType(argIndex, "Matrix4")) { - Nz::Matrix4f localMatrix = lua.Check(&index); + Nz::Matrix4f localMatrix = lua.Check(&argIndex); gfxComponent->Attach(renderable, localMatrix); } @@ -182,10 +182,10 @@ namespace Ndk case 3: { - int index = 1; - Nz::InstancedRenderableRef renderable = lua.Check(&index); - Nz::Matrix4f localMatrix = lua.Check(&index); - int renderOrder = lua.Check(&index); + int argIndex = 2; + Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); + Nz::Matrix4f localMatrix = lua.Check(&argIndex); + int renderOrder = lua.Check(&argIndex); gfxComponent->Attach(renderable, localMatrix, renderOrder); return 0; diff --git a/SDK/src/NDK/LuaBinding_Utility.cpp b/SDK/src/NDK/LuaBinding_Utility.cpp index 5ee613e1e..5ae37f669 100644 --- a/SDK/src/NDK/LuaBinding_Utility.cpp +++ b/SDK/src/NDK/LuaBinding_Utility.cpp @@ -25,9 +25,9 @@ namespace Ndk abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed); abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap); - abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int + abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage, std::size_t argumentCount) -> int { - unsigned int argCount = std::min(lua.GetStackTop(), 1U); + std::size_t argCount = std::min(argumentCount, 1U); switch (argCount) { case 0: @@ -35,8 +35,8 @@ namespace Ndk case 1: { - int index = 1; - Nz::UInt8 level(lua.Check(&index)); + int argIndex = 2; + Nz::UInt8 level(lua.Check(&argIndex)); return lua.Push(abstractImage->GetMemoryUsage(level)); } @@ -46,10 +46,10 @@ namespace Ndk return 0; }); - abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int + abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage, std::size_t argumentCount) -> int { - unsigned int argCount = std::min(lua.GetStackTop(), 6U); - int argIndex = 1; + std::size_t argCount = std::min(argumentCount, 6U); + int argIndex = 2; std::size_t bufferSize = 0; const Nz::UInt8* pixels = reinterpret_cast(lua.CheckString(argIndex++, &bufferSize)); @@ -105,11 +105,11 @@ namespace Ndk font.BindMethod("Destroy", &Nz::Font::Destroy); - font.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance) -> int + font.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance, std::size_t argumentCount) -> int { - unsigned int argCount = std::min(lua.GetStackTop(), 2U); + std::size_t argCount = std::min(argumentCount, 2U); - int argIndex = 1; + int argIndex = 2; switch (argCount) { case 0: @@ -199,9 +199,9 @@ namespace Ndk node.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local); node.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local); - node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t /*argumentCount*/) -> int { - int argIndex = 1; + int argIndex = 2; Nz::Vector3f offset = lua.Check(&argIndex); Nz::CoordSys coordSys = lua.Check(&argIndex, Nz::CoordSys_Local); @@ -210,9 +210,9 @@ namespace Ndk return 0; }); - node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t /*argumentCount*/) -> int { - int argIndex = 1; + int argIndex = 2; Nz::Quaternionf rotation = lua.Check(&argIndex); Nz::CoordSys coordSys = lua.Check(&argIndex, Nz::CoordSys_Local); @@ -221,11 +221,11 @@ namespace Ndk return 0; }); - node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t argumentCount) -> int { - unsigned int argCount = std::min(lua.GetStackTop(), 4U); + std::size_t argCount = std::min(argumentCount, 4U); - int argIndex = 1; + int argIndex = 2; switch (argCount) { case 1: @@ -247,11 +247,11 @@ namespace Ndk return 0; }); - node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t argumentCount) -> int { - unsigned int argCount = std::min(lua.GetStackTop(), 4U); + std::size_t argCount = std::min(argumentCount, 4U); - int argIndex = 1; + int argIndex = 2; switch (argCount) { case 1: @@ -284,11 +284,11 @@ namespace Ndk return 0; }); - node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t argumentCount) -> int { - unsigned int argCount = std::min(lua.GetStackTop(), 4U); + std::size_t argCount = std::min(argumentCount, 4U); - int argIndex = 1; + int argIndex = 2; switch (argCount) { case 1: diff --git a/include/Nazara/Lua/LuaClass.hpp b/include/Nazara/Lua/LuaClass.hpp index 795cfe6ff..3085aed0f 100644 --- a/include/Nazara/Lua/LuaClass.hpp +++ b/include/Nazara/Lua/LuaClass.hpp @@ -26,7 +26,7 @@ namespace Nz friend class LuaClass; public: - using ClassFunc = std::function; + using ClassFunc = std::function; using ClassIndexFunc = std::function; using ConstructorFunc = std::function; template using ConvertToParent = std::function; diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl index 4f0144fc8..daf7a632a 100644 --- a/include/Nazara/Lua/LuaClass.inl +++ b/include/Nazara/Lua/LuaClass.inl @@ -85,7 +85,7 @@ namespace Nz // Let's create the metatable which will be associated with every instance. SetupMetatable(lua); - if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_info->staticMethods.empty()) + if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_staticMethods.empty()) SetupGlobalTable(lua); lua.Pop(); // Pop our ClassInfo, which is now referenced by all our functions @@ -127,7 +127,7 @@ namespace Nz { typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int + BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int { handler.ProcessArgs(lua); @@ -141,7 +141,7 @@ namespace Nz { typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int + BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int { handler.ProcessArgs(lua); @@ -155,7 +155,7 @@ namespace Nz { typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int + BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int { handler.ProcessArgs(lua); @@ -169,7 +169,7 @@ namespace Nz { typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int + BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int { handler.ProcessArgs(lua); @@ -449,7 +449,7 @@ namespace Nz { // Query from the metatable lua.GetMetatable(info->name); //< Metatable - lua.PushValue(1); //< Field + lua.PushValue(2); //< Field lua.GetTable(); // Metatable[Field] lua.Remove(-2); // Remove Metatable @@ -476,7 +476,6 @@ namespace Nz std::shared_ptr& info = *static_cast*>(lua.ToUserdata(lua.GetIndexOfUpValue(1))); T* instance = static_cast(lua.CheckUserdata(1, info->name)); - lua.Remove(1); //< Remove the instance from the Lua stack Get(info, lua, instance); return 1; @@ -501,8 +500,6 @@ namespace Nz instance = it->second(lua); } lua.Pop(2); - - lua.Remove(1); //< Remove the instance from the Lua stack } if (!instance) @@ -511,9 +508,11 @@ namespace Nz return 0; } + std::size_t argCount = lua.GetStackTop() - 1U; + unsigned int index = static_cast(lua.ToInteger(lua.GetIndexOfUpValue(2))); const ClassFunc& method = info->methods[index]; - return method(lua, *instance); + return method(lua, *instance, argCount); } template @@ -525,7 +524,6 @@ namespace Nz const ClassIndexFunc& setter = info->setter; T& instance = *static_cast(lua.CheckUserdata(1, info->name)); - lua.Remove(1); //< Remove the instance from the Lua stack if (!setter(lua, instance)) { diff --git a/include/Nazara/Lua/LuaInstance.inl b/include/Nazara/Lua/LuaInstance.inl index ab563d301..18c526e24 100644 --- a/include/Nazara/Lua/LuaInstance.inl +++ b/include/Nazara/Lua/LuaInstance.inl @@ -209,6 +209,24 @@ namespace Nz return LuaImplReplyVal(instance, val, TypeTag()); } + template + std::enable_if_t::value && !std::is_enum::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag) + { + return LuaImplReplyVal(instance, std::move(val), TypeTag()); + } + + template + std::enable_if_t::value && !std::is_enum::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag) + { + return LuaImplReplyVal(instance, std::move(val), TypeTag()); + } + + template + int LuaImplReplyVal(const LuaInstance& instance, T&& val, TypeTag) + { + return LuaImplReplyVal(instance, std::forward(val), TypeTag()); + } + inline int LuaImplReplyVal(const LuaInstance& instance, std::string&& val, TypeTag) { instance.PushString(val.c_str(), val.size()); @@ -375,7 +393,7 @@ namespace Nz void ProcessArgs(const LuaInstance& instance) const { - m_index = 1; + m_index = 2; //< 1 being the instance ProcessArgs<0, Args...>(instance); } From 1d7e1b46ffc50aab7d8c40f2369411d363f08ebe Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 11:23:24 +0200 Subject: [PATCH 33/58] Sdk/Lua: Bind more Matrix4 methods --- SDK/include/NDK/LuaAPI.inl | 8 +- SDK/src/NDK/LuaBinding_Math.cpp | 147 ++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 4 deletions(-) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index 4d040c57a..a47f67659 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -243,10 +243,10 @@ namespace Nz { instance.CheckType(index, Nz::LuaType_Table); - params->animated = instance.CheckField("Animated", params->animated); - params->center = instance.CheckField("Center", params->center); - params->flipUVs = instance.CheckField("FlipUVs", params->flipUVs); - //params->matrix = instance.CheckField("Matrix", params->matrix); + params->animated = instance.CheckField("Animated", params->animated); + params->center = instance.CheckField("Center", params->center); + params->flipUVs = instance.CheckField("FlipUVs", params->flipUVs); + params->matrix = instance.CheckField("Matrix", params->matrix); params->optimizeIndexBuffers = instance.CheckField("OptimizeIndexBuffers", params->optimizeIndexBuffers); return 1; diff --git a/SDK/src/NDK/LuaBinding_Math.cpp b/SDK/src/NDK/LuaBinding_Math.cpp index 00707c9e3..51a510238 100644 --- a/SDK/src/NDK/LuaBinding_Math.cpp +++ b/SDK/src/NDK/LuaBinding_Math.cpp @@ -187,8 +187,155 @@ namespace Ndk 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; From 9206cf65b58629deeec80a2315364383535982a7 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 11:28:34 +0200 Subject: [PATCH 34/58] Lua/LuaInstance: Optimize the T& method(...) case Instead of instancing a new T from Lua, the original userdata is now returned --- include/Nazara/Lua/LuaInstance.inl | 68 ++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/include/Nazara/Lua/LuaInstance.inl b/include/Nazara/Lua/LuaInstance.inl index 18c526e24..25f193675 100644 --- a/include/Nazara/Lua/LuaInstance.inl +++ b/include/Nazara/Lua/LuaInstance.inl @@ -412,6 +412,19 @@ namespace Nz return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag()); } + template + std::enable_if_t::value, int> Invoke(const LuaInstance& instance, T& object, T&(P::*func)(Args...)) const + { + T& r = Apply(object, func, m_args); + if (&r == &object) + { + instance.PushValue(1); //< Userdata + return 1; + } + else + return LuaImplReplyVal(instance, r, TypeTag()); + } + template std::enable_if_t::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const { @@ -427,11 +440,22 @@ namespace Nz return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag()); } + template + std::enable_if_t::value, int> Invoke(const LuaInstance& instance, const T& object, const T&(P::*func)(Args...) const) const + { + const T& r = Apply(object, func, m_args); + if (&r == &object) + { + instance.PushValue(1); //< Userdata + return 1; + } + else + return LuaImplReplyVal(instance, r, TypeTag()); + } + template std::enable_if_t::type>::value, int> Invoke(const LuaInstance& instance, T& object, void(P::*func)(Args...)) const { - NazaraUnused(instance); - if (!object) { instance.Error("Invalid object"); @@ -454,11 +478,28 @@ namespace Nz return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag()); } + template + std::enable_if_t::type>::value, int> Invoke(const LuaInstance& instance, T& object, typename PointedType::type&(P::*func)(Args...) const) const + { + if (!object) + { + instance.Error("Invalid object"); + return 0; + } + + const typename PointedType::type& r = Apply(*object, func, m_args); + if (&r == &*object) + { + instance.PushValue(1); //< Userdata + return 1; + } + else + return LuaImplReplyVal(instance, r, TypeTag()); + } + template std::enable_if_t::type>::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const { - NazaraUnused(instance); - if (!object) { instance.Error("Invalid object"); @@ -481,6 +522,25 @@ namespace Nz return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag()); } + template + std::enable_if_t::type>::value, int> Invoke(const LuaInstance& instance, const T& object, const typename PointedType::type&(P::*func)(Args...) const) const + { + if (!object) + { + instance.Error("Invalid object"); + return 0; + } + + const typename PointedType::type& r = Apply(*object, func, m_args); + if (&r == &*object) + { + instance.PushValue(1); //< Userdata + return 1; + } + else + return LuaImplReplyVal(instance, r, TypeTag()); + } + private: using ArgContainer = std::tuple>...>; using DefArgContainer = std::tuple>...>; From 6b1d1a1d64343f203014b89df02654e9a4b5a3f8 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 11:29:02 +0200 Subject: [PATCH 35/58] Sdk/Lua: Bind TextureLibrary and TextureManager --- SDK/include/NDK/LuaAPI.inl | 17 +++++++++++++++++ SDK/include/NDK/LuaBinding.hpp | 2 ++ SDK/src/NDK/LuaBinding.cpp | 2 ++ SDK/src/NDK/LuaBinding_Graphics.cpp | 20 ++++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index a47f67659..1ae2ddd43 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -756,6 +756,23 @@ namespace Nz return 1; } + /*! + * \brief Replies by value for Lua + * \return 1 in case of success + * + * \param instance Lua instance to interact with + * \param val Resulting ImageParams + */ + + inline int LuaImplReplyVal(const LuaInstance& instance, ImageParams&& val, TypeTag) + { + instance.PushTable(0, 2); + instance.PushField("LevelCount", val.levelCount); + instance.PushField("LoadFormat", val.loadFormat); + + return 1; + } + /*! * \brief Replies by value for Lua * \return 1 in case of success diff --git a/SDK/include/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp index da6d282d1..0eb083162 100644 --- a/SDK/include/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -80,6 +80,8 @@ namespace Ndk Nz::LuaClass model; Nz::LuaClass sprite; Nz::LuaClass spriteLibrary; + Nz::LuaClass textureLibrary; + Nz::LuaClass textureManager; // Renderer Nz::LuaClass texture; diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index 888e8fe4f..789427f26 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -60,6 +60,8 @@ namespace Ndk model("Model"), sprite("Sprite"), spriteLibrary("SpriteLibrary"), + textureLibrary("TextureLibrary"), + textureManager("TextureManager"), // Renderer texture("Texture"), diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index 597c0dc68..d6c0c532b 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -316,6 +316,24 @@ namespace Ndk spriteLibrary.BindStaticMethod("Register", &Nz::SpriteLibrary::Register); spriteLibrary.BindStaticMethod("Query", &Nz::SpriteLibrary::Query); spriteLibrary.BindStaticMethod("Unregister", &Nz::SpriteLibrary::Unregister); + + /*********************************** Nz::TextureLibrary ***********************************/ + + textureLibrary.BindStaticMethod("Get", &Nz::TextureLibrary::Get); + textureLibrary.BindStaticMethod("Has", &Nz::TextureLibrary::Has); + textureLibrary.BindStaticMethod("Register", &Nz::TextureLibrary::Register); + textureLibrary.BindStaticMethod("Query", &Nz::TextureLibrary::Query); + textureLibrary.BindStaticMethod("Unregister", &Nz::TextureLibrary::Unregister); + + /*********************************** Nz::TextureManager ***********************************/ + + textureManager.BindStaticMethod("Clear", &Nz::TextureManager::Clear); + textureManager.BindStaticMethod("Get", &Nz::TextureManager::Get); + textureManager.BindStaticMethod("GetDefaultParameters", &Nz::TextureManager::GetDefaultParameters); + textureManager.BindStaticMethod("Purge", &Nz::TextureManager::Purge); + textureManager.BindStaticMethod("Register", &Nz::TextureManager::Register); + textureManager.BindStaticMethod("SetDefaultParameters", &Nz::TextureManager::SetDefaultParameters); + textureManager.BindStaticMethod("Unregister", &Nz::TextureManager::Unregister); } /*! @@ -331,5 +349,7 @@ namespace Ndk model.Register(instance); sprite.Register(instance); spriteLibrary.Register(instance); + textureLibrary.Register(instance); + textureManager.Register(instance); } } \ No newline at end of file From 15a13025222e1fa4ee04a9b8e2e0789fcf3802fc Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 27 Oct 2016 18:30:11 +0200 Subject: [PATCH 36/58] SDK/Lua: Simplify graphics binding code --- SDK/src/NDK/LuaBinding_Graphics.cpp | 37 +++++++---------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index d6c0c532b..4a2b53422 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -155,10 +155,7 @@ namespace Ndk return 0; } else - { - lua.Push(instance->SetAlphaMap(lua.Check(&argIndex))); - return 1; - } + return lua.Push(instance->SetAlphaMap(lua.Check(&argIndex))); }); material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int @@ -170,10 +167,7 @@ namespace Ndk return 0; } else - { - lua.Push(instance->SetDiffuseMap(lua.Check(&argIndex))); - return 1; - } + return lua.Push(instance->SetDiffuseMap(lua.Check(&argIndex))); }); material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int @@ -185,10 +179,7 @@ namespace Ndk return 0; } else - { - lua.Push(instance->SetEmissiveMap(lua.Check(&argIndex))); - return 1; - } + return lua.Push(instance->SetEmissiveMap(lua.Check(&argIndex))); }); material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int @@ -200,10 +191,7 @@ namespace Ndk return 0; } else - { - lua.Push(instance->SetHeightMap(lua.Check(&argIndex))); - return 1; - } + return lua.Push(instance->SetHeightMap(lua.Check(&argIndex))); }); material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int @@ -215,10 +203,7 @@ namespace Ndk return 0; } else - { - lua.Push(instance->SetNormalMap(lua.Check(&argIndex))); - return 1; - } + return lua.Push(instance->SetNormalMap(lua.Check(&argIndex))); }); material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int @@ -230,10 +215,7 @@ namespace Ndk return 0; } else - { - lua.Push(instance->SetShader(lua.Check(&argIndex))); - return 1; - } + return lua.Push(instance->SetShader(lua.Check(&argIndex))); }); material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int @@ -245,10 +227,7 @@ namespace Ndk return 0; } else - { - lua.Push(instance->SetSpecularMap(lua.Check(&argIndex))); - return 1; - } + return lua.Push(instance->SetSpecularMap(lua.Check(&argIndex))); }); /*********************************** Nz::Model ***********************************/ @@ -352,4 +331,4 @@ namespace Ndk textureLibrary.Register(instance); textureManager.Register(instance); } -} \ No newline at end of file +} From 00c37c5917f738eedc597c3d8ccd34965514dcf5 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 28 Oct 2016 17:48:46 +0200 Subject: [PATCH 38/58] Regenerated global headers --- include/Nazara/Network.hpp | 5 ++++- include/Nazara/Physics2D.hpp | 8 ++++---- include/Nazara/Physics3D.hpp | 12 ++++++------ include/Nazara/Renderer.hpp | 3 ++- include/Nazara/Utility.hpp | 3 ++- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/Nazara/Network.hpp b/include/Nazara/Network.hpp index 72565a17f..45c923e2b 100644 --- a/include/Nazara/Network.hpp +++ b/include/Nazara/Network.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 03 Feb 2016 at 00:06:56 +// This file was automatically generated on 28 Oct 2016 at 17:47:08 /* Nazara Engine - Network module @@ -36,7 +36,10 @@ #include #include #include +#include +#include #include +#include #include #include #include diff --git a/include/Nazara/Physics2D.hpp b/include/Nazara/Physics2D.hpp index 9b4ce41f4..88170c3f2 100644 --- a/include/Nazara/Physics2D.hpp +++ b/include/Nazara/Physics2D.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 14 Oct 2016 at 18:58:18 +// This file was automatically generated on 28 Oct 2016 at 17:47:08 /* Nazara Engine - Physics 2D module @@ -29,11 +29,11 @@ #ifndef NAZARA_GLOBAL_PHYSICS2D_HPP #define NAZARA_GLOBAL_PHYSICS2D_HPP -#include -#include #include -#include #include +#include +#include +#include #include #endif // NAZARA_GLOBAL_PHYSICS2D_HPP diff --git a/include/Nazara/Physics3D.hpp b/include/Nazara/Physics3D.hpp index e9c84e757..85c8f33e3 100644 --- a/include/Nazara/Physics3D.hpp +++ b/include/Nazara/Physics3D.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 14 Oct 2016 at 18:58:18 +// This file was automatically generated on 28 Oct 2016 at 17:47:08 /* Nazara Engine - Physics 3D module @@ -29,11 +29,11 @@ #ifndef NAZARA_GLOBAL_PHYSICS3D_HPP #define NAZARA_GLOBAL_PHYSICS3D_HPP -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include #endif // NAZARA_GLOBAL_PHYSICS3D_HPP diff --git a/include/Nazara/Renderer.hpp b/include/Nazara/Renderer.hpp index b57d4c5a5..d9b720474 100644 --- a/include/Nazara/Renderer.hpp +++ b/include/Nazara/Renderer.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 24 Jun 2015 at 13:55:50 +// This file was automatically generated on 28 Oct 2016 at 17:47:08 /* Nazara Engine - Renderer module @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include diff --git a/include/Nazara/Utility.hpp b/include/Nazara/Utility.hpp index d7676277e..e5b4af0c1 100644 --- a/include/Nazara/Utility.hpp +++ b/include/Nazara/Utility.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 12 Jul 2016 at 17:44:43 +// This file was automatically generated on 28 Oct 2016 at 17:47:08 /* Nazara Engine - Utility module @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include From 28a232837126a829d8cd42eb4579a39f113313b3 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 28 Oct 2016 17:53:03 +0200 Subject: [PATCH 39/58] Global headers: Remove the generation date They should now generate the same input everytime --- SDK/include/NDK/Components.hpp | 2 +- SDK/include/NDK/Systems.hpp | 2 +- build/scripts/actions/generateheaders.lua | 2 +- include/Nazara/Audio.hpp | 2 +- include/Nazara/Core.hpp | 2 +- include/Nazara/Graphics.hpp | 2 +- include/Nazara/Lua.hpp | 2 +- include/Nazara/Math.hpp | 2 +- include/Nazara/Network.hpp | 2 +- include/Nazara/Noise.hpp | 2 +- include/Nazara/Physics2D.hpp | 2 +- include/Nazara/Physics3D.hpp | 2 +- include/Nazara/Renderer.hpp | 2 +- include/Nazara/Utility.hpp | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/SDK/include/NDK/Components.hpp b/SDK/include/NDK/Components.hpp index afa25ade8..3338e5f52 100644 --- a/SDK/include/NDK/Components.hpp +++ b/SDK/include/NDK/Components.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 30 Jul 2016 at 15:29:16 +// This file was automatically generated #pragma once diff --git a/SDK/include/NDK/Systems.hpp b/SDK/include/NDK/Systems.hpp index 287a2d61a..45a79bc6c 100644 --- a/SDK/include/NDK/Systems.hpp +++ b/SDK/include/NDK/Systems.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 30 Jul 2016 at 15:29:16 +// This file was automatically generated #pragma once diff --git a/build/scripts/actions/generateheaders.lua b/build/scripts/actions/generateheaders.lua index 943919a90..6bbd5782c 100644 --- a/build/scripts/actions/generateheaders.lua +++ b/build/scripts/actions/generateheaders.lua @@ -67,7 +67,7 @@ ACTION.Function = function () error("Failed to create header file (" .. v.Target .. "): " .. err) end - header:write("// This file was automatically generated on " .. os.date("%d %b %Y at %X") .. "\n\n") + header:write("// This file was automatically generated\n\n") if (v.Header) then header:write(v.Header) end diff --git a/include/Nazara/Audio.hpp b/include/Nazara/Audio.hpp index d0fd17d6f..5becbb066 100644 --- a/include/Nazara/Audio.hpp +++ b/include/Nazara/Audio.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 24 Jun 2015 at 13:55:50 +// This file was automatically generated /* Nazara Engine - Audio module diff --git a/include/Nazara/Core.hpp b/include/Nazara/Core.hpp index 5f3c85c4c..419ddaae9 100644 --- a/include/Nazara/Core.hpp +++ b/include/Nazara/Core.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 09 May 2016 at 17:07:09 +// This file was automatically generated /* Nazara Engine - Core module diff --git a/include/Nazara/Graphics.hpp b/include/Nazara/Graphics.hpp index b79e8e348..252110d9d 100644 --- a/include/Nazara/Graphics.hpp +++ b/include/Nazara/Graphics.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 15 Sep 2016 at 00:43:26 +// This file was automatically generated /* Nazara Engine - Graphics module diff --git a/include/Nazara/Lua.hpp b/include/Nazara/Lua.hpp index f73541cb8..a0e68204c 100644 --- a/include/Nazara/Lua.hpp +++ b/include/Nazara/Lua.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 24 Jun 2015 at 13:55:50 +// This file was automatically generated /* Nazara Engine - Lua scripting module diff --git a/include/Nazara/Math.hpp b/include/Nazara/Math.hpp index fd0239a61..9ee9a2351 100644 --- a/include/Nazara/Math.hpp +++ b/include/Nazara/Math.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 24 Jun 2015 at 13:55:50 +// This file was automatically generated /* Nazara Engine - Mathematics module diff --git a/include/Nazara/Network.hpp b/include/Nazara/Network.hpp index 45c923e2b..41b7fce71 100644 --- a/include/Nazara/Network.hpp +++ b/include/Nazara/Network.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 28 Oct 2016 at 17:47:08 +// This file was automatically generated /* Nazara Engine - Network module diff --git a/include/Nazara/Noise.hpp b/include/Nazara/Noise.hpp index e1d14460e..f8ecfb82e 100644 --- a/include/Nazara/Noise.hpp +++ b/include/Nazara/Noise.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 12 Jul 2016 at 17:44:43 +// This file was automatically generated /* Nazara Engine - Noise module diff --git a/include/Nazara/Physics2D.hpp b/include/Nazara/Physics2D.hpp index 88170c3f2..2c908ca79 100644 --- a/include/Nazara/Physics2D.hpp +++ b/include/Nazara/Physics2D.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 28 Oct 2016 at 17:47:08 +// This file was automatically generated /* Nazara Engine - Physics 2D module diff --git a/include/Nazara/Physics3D.hpp b/include/Nazara/Physics3D.hpp index 85c8f33e3..a40c40b9c 100644 --- a/include/Nazara/Physics3D.hpp +++ b/include/Nazara/Physics3D.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 28 Oct 2016 at 17:47:08 +// This file was automatically generated /* Nazara Engine - Physics 3D module diff --git a/include/Nazara/Renderer.hpp b/include/Nazara/Renderer.hpp index d9b720474..159b990de 100644 --- a/include/Nazara/Renderer.hpp +++ b/include/Nazara/Renderer.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 28 Oct 2016 at 17:47:08 +// This file was automatically generated /* Nazara Engine - Renderer module diff --git a/include/Nazara/Utility.hpp b/include/Nazara/Utility.hpp index e5b4af0c1..3734b919e 100644 --- a/include/Nazara/Utility.hpp +++ b/include/Nazara/Utility.hpp @@ -1,4 +1,4 @@ -// This file was automatically generated on 28 Oct 2016 at 17:47:08 +// This file was automatically generated /* Nazara Engine - Utility module From c7d011cd0063d8ab313c29304e3c29a5da7c9406 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 29 Oct 2016 02:07:48 +0200 Subject: [PATCH 40/58] Readme: Display Travis CI status for branch master only --- readme.md | 2 +- readme_fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index edb58080e..ea054e608 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ Platform | Build Status ------------ | ------------- Windows | [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/dj5qx7axym4uakmy/branch/master?svg=true)](https://ci.appveyor.com/project/DPSLynix/nazaraengine/branch/master) -Linux | [![Travis CI Build Status](https://travis-ci.org/DigitalPulseSoftware/NazaraEngine.svg)](https://travis-ci.org/DigitalPulseSoftware/NazaraEngine) +Linux | [![Travis CI Build Status](https://travis-ci.org/DigitalPulseSoftware/NazaraEngine.svg?branch=master)](https://travis-ci.org/DigitalPulseSoftware/NazaraEngine) # Nazara Engine diff --git a/readme_fr.md b/readme_fr.md index d7aff37b9..422be6a0e 100644 --- a/readme_fr.md +++ b/readme_fr.md @@ -1,7 +1,7 @@ Platforme | Build Status ------------ | ------------- Windows | [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/dj5qx7axym4uakmy/branch/master?svg=true)](https://ci.appveyor.com/project/DPSLynix/nazaraengine/branch/master) -Linux | [![Travis CI Build Status](https://travis-ci.org/DigitalPulseSoftware/NazaraEngine.svg)](https://travis-ci.org/DigitalPulseSoftware/NazaraEngine) +Linux | [![Travis CI Build Status](https://travis-ci.org/DigitalPulseSoftware/NazaraEngine.svg?branch=master)](https://travis-ci.org/DigitalPulseSoftware/NazaraEngine) # Nazara Engine From e087129d4a996eaaacf4d8fcb256b5d5d8af4c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 4 Nov 2016 18:14:52 +0100 Subject: [PATCH 41/58] Fix many errors and warnings found out by MinGW --- SDK/include/NDK/Application.inl | 8 +- .../NDK/Components/GraphicsComponent.hpp | 16 +- SDK/include/NDK/LuaAPI.inl | 2 +- SDK/src/NDK/LuaBinding_Audio.cpp | 30 +- SDK/src/NDK/LuaBinding_Core.cpp | 78 +- SDK/src/NDK/LuaBinding_Graphics.cpp | 16 +- SDK/src/NDK/LuaBinding_Math.cpp | 44 +- SDK/src/NDK/LuaBinding_Math.cpp.save-failed | 908 ++++++++++++++++++ SDK/src/NDK/LuaBinding_Network.cpp | 12 +- SDK/src/NDK/LuaBinding_Renderer.cpp | 12 +- SDK/src/NDK/LuaBinding_SDK.cpp | 16 +- SDK/src/NDK/LuaBinding_Utility.cpp | 48 +- include/Nazara/Graphics/TileMap.inl | 18 +- include/Nazara/Lua/LuaClass.inl | 12 +- include/Nazara/Lua/LuaInstance.inl | 8 +- include/Nazara/Math/Matrix4.inl | 2 +- include/Nazara/Math/Vector3.inl | 12 +- include/Nazara/Math/Vector4.inl | 16 +- include/Nazara/Network/IpAddress.inl | 8 +- include/Nazara/Physics2D/ConfigCheck.hpp | 6 +- include/Nazara/Physics2D/Debug.hpp | 4 +- include/Nazara/Physics2D/DebugOff.hpp | 2 +- include/Nazara/Physics3D/ConfigCheck.hpp | 4 +- include/Nazara/Physics3D/Debug.hpp | 2 +- include/Nazara/Physics3D/DebugOff.hpp | 2 +- include/Nazara/Physics3D/Enums.hpp | 2 +- src/Nazara/Core/File.cpp | 2 +- src/Nazara/Graphics/InstancedRenderable.cpp | 1 + src/Nazara/Network/NetPacket.cpp | 2 +- src/Nazara/Network/TcpClient.cpp | 2 +- src/Nazara/Network/Win32/SocketImpl.cpp | 4 + src/Nazara/Physics2D/Debug/NewOverload.cpp | 4 +- src/Nazara/Physics3D/Debug/NewOverload.cpp | 2 +- src/Nazara/Renderer/RenderTexture.cpp | 1 + src/Nazara/Utility/Formats/MTLParser.cpp | 6 +- src/Nazara/Utility/Formats/OBJParser.cpp | 22 +- src/Nazara/Utility/SimpleTextDrawer.cpp | 1 + src/Nazara/Utility/SoftwareBuffer.cpp | 2 +- 38 files changed, 1126 insertions(+), 211 deletions(-) create mode 100644 SDK/src/NDK/LuaBinding_Math.cpp.save-failed diff --git a/SDK/include/NDK/Application.inl b/SDK/include/NDK/Application.inl index d26a2daa8..0b4f2ce10 100644 --- a/SDK/include/NDK/Application.inl +++ b/SDK/include/NDK/Application.inl @@ -59,7 +59,7 @@ namespace Ndk * \param args Arguments used to create the window */ #ifndef NDK_SERVER - template + template T& Application::AddWindow(Args&&... args) { static_assert(std::is_base_of::value, "Type must inherit Window"); @@ -82,7 +82,7 @@ namespace Ndk * \param args Arguments used to create the world */ - template + template World& Application::AddWorld(Args&&... args) { m_worlds.emplace_back(std::forward(args)...); @@ -373,9 +373,9 @@ namespace Ndk { } - inline Application::WindowInfo::WindowInfo(std::unique_ptr&& window) : + inline Application::WindowInfo::WindowInfo(std::unique_ptr&& windowPtr) : renderTarget(nullptr), - window(std::move(window)) + window(std::move(windowPtr)) { } #endif diff --git a/SDK/include/NDK/Components/GraphicsComponent.hpp b/SDK/include/NDK/Components/GraphicsComponent.hpp index b536fc154..f8cd6d957 100644 --- a/SDK/include/NDK/Components/GraphicsComponent.hpp +++ b/SDK/include/NDK/Components/GraphicsComponent.hpp @@ -73,19 +73,19 @@ namespace Ndk { } - Renderable(Renderable&& renderable) noexcept : - renderableInvalidationSlot(std::move(renderable.renderableInvalidationSlot)), - renderableReleaseSlot(std::move(renderable.renderableReleaseSlot)), - data(std::move(renderable.data)), - renderable(std::move(renderable.renderable)), - dataUpdated(renderable.dataUpdated) + Renderable(Renderable&& rhs) noexcept : + renderableInvalidationSlot(std::move(rhs.renderableInvalidationSlot)), + renderableReleaseSlot(std::move(rhs.renderableReleaseSlot)), + data(std::move(rhs.data)), + renderable(std::move(rhs.renderable)), + dataUpdated(rhs.dataUpdated) { } ~Renderable() { // Disconnect release slot before releasing instanced renderable reference - renderableReleaseSlot.Disconnect(); + renderableReleaseSlot.Disconnect(); } Renderable& operator=(Renderable&& r) noexcept @@ -118,4 +118,4 @@ namespace Ndk #include #endif // NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP -#endif // NDK_SERVER \ No newline at end of file +#endif // NDK_SERVER diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index 1ae2ddd43..e50699528 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -223,7 +223,7 @@ namespace Nz inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Matrix4f* mat, TypeTag) { - Matrix4d matDouble; + Matrix4d matDouble = Matrix4d::Identity(); unsigned int ret = LuaImplQueryArg(instance, index, &matDouble, TypeTag()); mat->Set(matDouble); diff --git a/SDK/src/NDK/LuaBinding_Audio.cpp b/SDK/src/NDK/LuaBinding_Audio.cpp index 46791b6c7..60f504939 100644 --- a/SDK/src/NDK/LuaBinding_Audio.cpp +++ b/SDK/src/NDK/LuaBinding_Audio.cpp @@ -41,12 +41,12 @@ namespace Ndk music.BindMethod("Stop", &Nz::Music::Stop); // Manual - music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music, std::size_t /*argumentCount*/) -> int + music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& instance, std::size_t /*argumentCount*/) -> int { - Nz::StringStream stream("Music("); - stream << music.GetFilePath() << ')'; + Nz::StringStream ss("Music("); + ss << instance.GetFilePath() << ')'; - lua.PushString(stream); + lua.PushString(ss); return 1; }); @@ -65,15 +65,15 @@ namespace Ndk sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); // Manual - sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound, std::size_t /*argumentCount*/) -> int + sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& instance, std::size_t /*argumentCount*/) -> int { - Nz::StringStream stream("Sound("); - if (const Nz::SoundBuffer* buffer = sound.GetBuffer()) - stream << buffer; + Nz::StringStream ss("Sound("); + if (const Nz::SoundBuffer* buffer = instance.GetBuffer()) + ss << buffer; - stream << ')'; + ss << ')'; - lua.PushString(stream); + lua.PushString(ss); return 1; }); @@ -124,18 +124,18 @@ namespace Ndk soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int { - Nz::StringStream stream("SoundBuffer("); + Nz::StringStream ss("SoundBuffer("); if (instance->IsValid()) { Nz::String filePath = instance->GetFilePath(); if (!filePath.IsEmpty()) - stream << "File: " << filePath << ", "; + ss << "File: " << filePath << ", "; - stream << "Duration: " << instance->GetDuration() / 1000.f << "s"; + ss << "Duration: " << instance->GetDuration() / 1000.f << "s"; } - stream << ')'; + ss << ')'; - lua.PushString(stream); + lua.PushString(ss); return 1; }); diff --git a/SDK/src/NDK/LuaBinding_Core.cpp b/SDK/src/NDK/LuaBinding_Core.cpp index dc149e3d0..4a1e343f4 100644 --- a/SDK/src/NDK/LuaBinding_Core.cpp +++ b/SDK/src/NDK/LuaBinding_Core.cpp @@ -13,13 +13,13 @@ namespace Ndk void LuaBinding::BindCore() { /*********************************** Nz::Clock **********************************/ - clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock, std::size_t /*argumentCount*/) + clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t /*argumentCount*/) { int argIndex = 2; Nz::Int64 startingValue = lua.Check(&argIndex, 0); bool paused = lua.Check(&argIndex, false); - Nz::PlacementNew(clock, startingValue, paused); + Nz::PlacementNew(instance, startingValue, paused); return true; }); @@ -32,19 +32,19 @@ namespace Ndk clock.BindMethod("Unpause", &Nz::Clock::Unpause); // Manual - clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock, std::size_t /*argumentCount*/) -> int { - Nz::StringStream stream("Clock(Elapsed: "); - stream << clock.GetSeconds(); - stream << "s, Paused: "; - stream << clock.IsPaused(); - stream << ')'; + clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& instance, std::size_t /*argumentCount*/) -> int { + Nz::StringStream ss("Clock(Elapsed: "); + ss << instance.GetSeconds(); + ss << "s, Paused: "; + ss << instance.IsPaused(); + ss << ')'; - lua.PushString(stream); + lua.PushString(ss); return 1; }); /********************************* Nz::Directory ********************************/ - directory.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* directory, std::size_t argumentCount) + directory.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* instance, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 1U); @@ -52,11 +52,11 @@ namespace Ndk switch (argCount) { case 0: - Nz::PlacementNew(directory); + Nz::PlacementNew(instance); return true; case 1: - Nz::PlacementNew(directory, lua.Check(&argIndex)); + Nz::PlacementNew(instance, lua.Check(&argIndex)); return true; } @@ -85,12 +85,12 @@ namespace Ndk directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent); // Manual - directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory, std::size_t /*argumentCount*/) -> int { - Nz::StringStream stream("Directory("); - stream << directory.GetPath(); - stream << ')'; + directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int { + Nz::StringStream ss("Directory("); + ss << instance.GetPath(); + ss << ')'; - lua.PushString(stream); + lua.PushString(ss); return 1; }); @@ -110,35 +110,35 @@ namespace Ndk stream.BindMethod("IsWritable", &Nz::Stream::IsWritable); stream.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos); - stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream, std::size_t /*argumentCount*/) -> int { + stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int { int argIndex = 2; std::size_t length = lua.Check(&argIndex); std::unique_ptr buffer(new char[length]); - std::size_t readLength = stream.Read(buffer.get(), length); + std::size_t readLength = instance.Read(buffer.get(), length); lua.PushString(Nz::String(buffer.get(), readLength)); return 1; }); - stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream, std::size_t /*argumentCount*/) -> int { + stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int { int argIndex = 2; std::size_t bufferSize = 0; const char* buffer = lua.CheckString(argIndex, &bufferSize); - if (stream.IsTextModeEnabled()) - lua.Push(stream.Write(Nz::String(buffer, bufferSize))); + if (instance.IsTextModeEnabled()) + lua.Push(instance.Write(Nz::String(buffer, bufferSize))); else - lua.Push(stream.Write(buffer, bufferSize)); + lua.Push(instance.Write(buffer, bufferSize)); return 1; }); /*********************************** Nz::File ***********************************/ file.Inherit(stream); - file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* file, std::size_t argumentCount) + file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* instance, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 1U); @@ -146,14 +146,14 @@ namespace Ndk switch (argCount) { case 0: - Nz::PlacementNew(file); + Nz::PlacementNew(instance); return true; case 1: { Nz::String filePath = lua.Check(&argIndex); - Nz::PlacementNew(file, filePath); + Nz::PlacementNew(instance, filePath); return true; } @@ -162,7 +162,7 @@ namespace Ndk Nz::String filePath = lua.Check(&argIndex); Nz::UInt32 openMode = lua.Check(&argIndex); - Nz::PlacementNew(file, filePath, openMode); + Nz::PlacementNew(instance, filePath, openMode); return true; } } @@ -201,7 +201,7 @@ namespace Ndk file.BindStaticMethod("Rename", &Nz::File::Rename); // Manual - file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file, std::size_t argumentCount) -> int + file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int { std::size_t argCount = std::min(argumentCount, 2U); @@ -210,13 +210,13 @@ namespace Ndk { case 0: case 1: - return lua.Push(file.Open(lua.Check(&argIndex, Nz::OpenMode_NotOpen))); + return lua.Push(instance.Open(lua.Check(&argIndex, Nz::OpenMode_NotOpen))); case 2: { Nz::String filePath = lua.Check(&argIndex); Nz::UInt32 openMode = lua.Check(&argIndex, Nz::OpenMode_NotOpen); - return lua.Push(file.Open(filePath, openMode)); + return lua.Push(instance.Open(filePath, openMode)); } } @@ -224,7 +224,7 @@ namespace Ndk return 0; }); - file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file, std::size_t argumentCount) -> int + file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int { std::size_t argCount = std::min(argumentCount, 2U); @@ -232,13 +232,13 @@ namespace Ndk switch (argCount) { case 1: - return lua.Push(file.SetCursorPos(lua.Check(&argIndex))); + return lua.Push(instance.SetCursorPos(lua.Check(&argIndex))); case 2: { Nz::CursorPosition curPos = lua.Check(&argIndex); Nz::Int64 offset = lua.Check(&argIndex); - return lua.Push(file.SetCursorPos(curPos, offset)); + return lua.Push(instance.SetCursorPos(curPos, offset)); } } @@ -246,14 +246,14 @@ namespace Ndk return 0; }); - file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file, std::size_t /*argumentCount*/) -> int { - Nz::StringStream stream("File("); - if (file.IsOpen()) - stream << "Path: " << file.GetPath(); + file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t /*argumentCount*/) -> int { + Nz::StringStream ss("File("); + if (instance.IsOpen()) + ss << "Path: " << instance.GetPath(); - stream << ')'; + ss << ')'; - lua.PushString(stream); + lua.PushString(ss); return 1; }); } diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index 4a2b53422..d1cff2ef5 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -231,14 +231,14 @@ namespace Ndk }); /*********************************** Nz::Model ***********************************/ - model.Inherit(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef* + model.Inherit(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef* { - return reinterpret_cast(model); //TODO: Make a ObjectRefCast + return reinterpret_cast(modelRef); //TODO: Make a ObjectRefCast }); - model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* model, std::size_t /*argumentCount*/) + model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* instance, std::size_t /*argumentCount*/) { - Nz::PlacementNew(model, Nz::Model::New()); + Nz::PlacementNew(instance, Nz::Model::New()); return true; }); @@ -260,14 +260,14 @@ namespace Ndk model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount); /*********************************** Nz::Sprite ***********************************/ - sprite.Inherit(instancedRenderable, [] (Nz::SpriteRef* sprite) -> Nz::InstancedRenderableRef* + sprite.Inherit(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef* { - return reinterpret_cast(sprite); //TODO: Make a ObjectRefCast + return reinterpret_cast(spriteRef); //TODO: Make a ObjectRefCast }); - sprite.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* sprite, std::size_t /*argumentCount*/) + sprite.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* instance, std::size_t /*argumentCount*/) { - Nz::PlacementNew(sprite, Nz::Sprite::New()); + Nz::PlacementNew(instance, Nz::Sprite::New()); return true; }); diff --git a/SDK/src/NDK/LuaBinding_Math.cpp b/SDK/src/NDK/LuaBinding_Math.cpp index 51a510238..35ad13a2e 100644 --- a/SDK/src/NDK/LuaBinding_Math.cpp +++ b/SDK/src/NDK/LuaBinding_Math.cpp @@ -14,22 +14,22 @@ namespace Ndk void LuaBinding::BindMath() { /*********************************** Nz::EulerAngles **********************************/ - eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* angles, std::size_t argumentCount) + 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(angles, Nz::EulerAnglesd::Zero()); + Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero()); return true; case 1: - Nz::PlacementNew(angles, *static_cast(lua.CheckUserdata(1, "EulerAngles"))); + Nz::PlacementNew(instance, *static_cast(lua.CheckUserdata(1, "EulerAngles"))); return true; case 3: - Nz::PlacementNew(angles, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3)); + Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3)); return true; } @@ -154,7 +154,7 @@ namespace Ndk return false; }); - + /*********************************** Nz::Matrix4 **********************************/ matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount) { @@ -227,7 +227,7 @@ namespace Ndk { Nz::Matrix4d result; instance.GetTransposed(&result); - + return lua.Push(result); }); @@ -360,7 +360,7 @@ namespace Ndk }); /*********************************** Nz::Rect **********************************/ - rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect, std::size_t argumentCount) + rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* instance, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 4U); @@ -368,23 +368,23 @@ namespace Ndk { case 0: case 4: - PlacementNew(rect, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0), lua.CheckNumber(4, 0.0)); + 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(rect, *static_cast(lua.ToUserdata(1))); + 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(rect, lua.CheckField("x", 1), - lua.CheckField("y", 1), - lua.CheckField("width", 1), - lua.CheckField("height", 1)); + 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(rect, *static_cast(lua.ToUserdata(1))); + PlacementNew(instance, *static_cast(lua.ToUserdata(1))); else break; @@ -394,9 +394,9 @@ namespace Ndk case 2: { if (lua.IsOfType(1, Nz::LuaType_Number) && lua.IsOfType(2, Nz::LuaType_Number)) - PlacementNew(rect, lua.CheckNumber(1), lua.CheckNumber(2)); + PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2)); else if (lua.IsOfType(1, "Vector2") && lua.IsOfType(2, "Vector2")) - PlacementNew(rect, *static_cast(lua.ToUserdata(1)), *static_cast(lua.ToUserdata(2))); + PlacementNew(instance, *static_cast(lua.ToUserdata(1)), *static_cast(lua.ToUserdata(2))); else break; @@ -516,22 +516,22 @@ namespace Ndk }); /*********************************** Nz::Quaternion **********************************/ - quaternion.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion, std::size_t argumentCount) + 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(quaternion, Nz::Quaterniond::Zero()); + Nz::PlacementNew(instance, Nz::Quaterniond::Zero()); return true; case 1: { if (lua.IsOfType(1, "EulerAngles")) - Nz::PlacementNew(quaternion, *static_cast(lua.ToUserdata(1))); + Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); else if (lua.IsOfType(1, "Quaternion")) - Nz::PlacementNew(quaternion, *static_cast(lua.ToUserdata(1))); + Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); else break; @@ -539,11 +539,11 @@ namespace Ndk } case 2: - Nz::PlacementNew(quaternion, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector3"))); + Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector3"))); return true; case 4: - Nz::PlacementNew(quaternion, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4)); + Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4)); return true; default: diff --git a/SDK/src/NDK/LuaBinding_Math.cpp.save-failed b/SDK/src/NDK/LuaBinding_Math.cpp.save-failed new file mode 100644 index 000000000..6abec5c7b --- /dev/null +++ b/SDK/src/NDK/LuaBinding_Math.cpp.save-failed @@ -0,0 +1,908 @@ +// 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(angles, Nz::EulerAnglesd::Zero()); + return true; + + case 1: + Nz::PlacementNew(angles, *static_cast(lua.CheckUserdata(1, "EulerAngles"))); + return true; + + case 3: + Nz::PlacementNew(angles, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3)); + return true; + } + + lua.Error("No matching overload for EulerAngles constructor"); + return false; + }); + + 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 (std::size_t 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* rect, std::size_t argumentCount) + { + std::size_t argCount = std::min(argumentCount, 4U); + + switch (argCount) + { + case 0: + case 4: + PlacementNew(rect, 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(rect, *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(rect, lua.CheckField("x", 1), + lua.CheckField("y", 1), + lua.CheckField("width", 1), + lua.CheckField("height", 1)); + } + else if (lua.IsOfType(1, "Vector2")) + PlacementNew(rect, *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(rect, lua.CheckNumber(1), lua.CheckNumber(2)); + else if (lua.IsOfType(1, "Vector2") && lua.IsOfType(2, "Vector2")) + PlacementNew(rect, *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* quaternion, std::size_t argumentCount) + { + std::size_t argCount = std::min(argumentCount, 4U); + + switch (argCount) + { + case 0: + Nz::PlacementNew(quaternion, Nz::Quaterniond::Zero()); + return true; + + case 1: + { + if (lua.IsOfType(1, "EulerAngles")) + Nz::PlacementNew(quaternion, *static_cast(lua.ToUserdata(1))); + else if (lua.IsOfType(1, "Quaternion")) + Nz::PlacementNew(quaternion, *static_cast(lua.ToUserdata(1))); + else + break; + + return true; + } + + case 2: + Nz::PlacementNew(quaternion, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector3"))); + return true; + + case 4: + Nz::PlacementNew(quaternion, 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("__tostring", &Nz::Quaterniond::ToString); + + 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); + } +} diff --git a/SDK/src/NDK/LuaBinding_Network.cpp b/SDK/src/NDK/LuaBinding_Network.cpp index bd1105962..b51906481 100644 --- a/SDK/src/NDK/LuaBinding_Network.cpp +++ b/SDK/src/NDK/LuaBinding_Network.cpp @@ -21,7 +21,7 @@ namespace Ndk abstractSocket.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes); /*********************************** Nz::IpAddress **********************************/ - ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* address, std::size_t argumentCount) + ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* instance, std::size_t argumentCount) { std::size_t argCount = std::min(argumentCount, 9U); @@ -29,11 +29,11 @@ namespace Ndk switch (argCount) { case 0: - Nz::PlacementNew(address); + Nz::PlacementNew(instance); return true; case 1: - Nz::PlacementNew(address, lua.CheckString(argIndex)); + Nz::PlacementNew(instance, lua.CheckString(argIndex)); return true; case 4: @@ -45,7 +45,7 @@ namespace Ndk Nz::UInt8 d = lua.Check(&argIndex); Nz::UInt16 port = lua.Check(&argIndex, 0); - Nz::PlacementNew(address, a, b, c, d, port); + Nz::PlacementNew(instance, a, b, c, d, port); return true; } @@ -62,7 +62,7 @@ namespace Ndk Nz::UInt16 h = lua.Check(&argIndex); Nz::UInt16 port = lua.Check(&argIndex, 0); - Nz::PlacementNew(address, a, b, c, d, e, f, g, h, port); + Nz::PlacementNew(instance, a, b, c, d, e, f, g, h, port); return true; } } @@ -199,7 +199,7 @@ namespace Ndk instance.PushField("Unknown", Nz::ResolveError_Unknown); } instance.SetGlobal("ResolveError"); - + // Nz::SocketError static_assert(Nz::SocketError_Max + 1 == 15, "Nz::ResolveError has been updated but change was not reflected to Lua binding"); instance.PushTable(0, 15); diff --git a/SDK/src/NDK/LuaBinding_Renderer.cpp b/SDK/src/NDK/LuaBinding_Renderer.cpp index 8ffe76c69..1f1f9479f 100644 --- a/SDK/src/NDK/LuaBinding_Renderer.cpp +++ b/SDK/src/NDK/LuaBinding_Renderer.cpp @@ -13,14 +13,14 @@ namespace Ndk void LuaBinding::BindRenderer() { /*********************************** Nz::Texture ***********************************/ - texture.Inherit(abstractImage, [] (Nz::TextureRef* texture) -> Nz::AbstractImageRef* + texture.Inherit(abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef* { - return reinterpret_cast(texture); //TODO: Make a ObjectRefCast + return reinterpret_cast(textureRef); //TODO: Make a ObjectRefCast }); - texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* texture, std::size_t /*argumentCount*/) + texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* instance, std::size_t /*argumentCount*/) { - Nz::PlacementNew(texture, Nz::Texture::New()); + Nz::PlacementNew(instance, Nz::Texture::New()); return true; }); @@ -28,7 +28,7 @@ namespace Ndk 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); @@ -73,4 +73,4 @@ namespace Ndk { texture.Register(instance); } -} \ No newline at end of file +} diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index 3046f2483..880e49064 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -25,9 +25,9 @@ namespace Ndk application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled); #endif - application.BindMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application, std::size_t /*argumentCount*/) -> int + application.BindMethod("AddWorld", [] (Nz::LuaInstance& lua, Application* instance, std::size_t /*argumentCount*/) -> int { - instance.Push(application->AddWorld().CreateHandle()); + lua.Push(instance->AddWorld().CreateHandle()); return 1; }); @@ -59,7 +59,7 @@ namespace Ndk console.BindMethod("SetCharacterSize", &Console::SetCharacterSize); console.BindMethod("SetSize", &Console::SetSize); console.BindMethod("SetTextFont", &Console::SetTextFont); - + console.BindMethod("Show", &Console::Show, true); #endif @@ -139,7 +139,7 @@ namespace Ndk #ifndef NDK_SERVER /*********************************** Ndk::GraphicsComponent **********************************/ - graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent *gfxComponent, std::size_t argumentCount) -> int + graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int { /* void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0); @@ -153,7 +153,7 @@ namespace Ndk case 1: { int argIndex = 2; - gfxComponent->Attach(lua.Check(&argIndex)); + instance->Attach(lua.Check(&argIndex)); return 0; } @@ -166,13 +166,13 @@ namespace Ndk { int renderOrder = lua.Check(&argIndex); - gfxComponent->Attach(renderable, renderOrder); + instance->Attach(renderable, renderOrder); } else if (lua.IsOfType(argIndex, "Matrix4")) { Nz::Matrix4f localMatrix = lua.Check(&argIndex); - gfxComponent->Attach(renderable, localMatrix); + instance->Attach(renderable, localMatrix); } else break; @@ -187,7 +187,7 @@ namespace Ndk Nz::Matrix4f localMatrix = lua.Check(&argIndex); int renderOrder = lua.Check(&argIndex); - gfxComponent->Attach(renderable, localMatrix, renderOrder); + instance->Attach(renderable, localMatrix, renderOrder); return 0; } } diff --git a/SDK/src/NDK/LuaBinding_Utility.cpp b/SDK/src/NDK/LuaBinding_Utility.cpp index 5ae37f669..e693ce35c 100644 --- a/SDK/src/NDK/LuaBinding_Utility.cpp +++ b/SDK/src/NDK/LuaBinding_Utility.cpp @@ -25,20 +25,20 @@ namespace Ndk abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed); abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap); - abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage, std::size_t argumentCount) -> int + abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int { std::size_t argCount = std::min(argumentCount, 1U); switch (argCount) { case 0: - return lua.Push(abstractImage->GetMemoryUsage()); + return lua.Push(instance->GetMemoryUsage()); case 1: { int argIndex = 2; Nz::UInt8 level(lua.Check(&argIndex)); - return lua.Push(abstractImage->GetMemoryUsage(level)); + return lua.Push(instance->GetMemoryUsage(level)); } } @@ -46,7 +46,7 @@ namespace Ndk return 0; }); - abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage, std::size_t argumentCount) -> int + abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int { std::size_t argCount = std::min(argumentCount, 6U); int argIndex = 2; @@ -62,7 +62,7 @@ namespace Ndk Nz::UInt8 level = lua.Check(&argIndex, 0); ///TODO: Buffer checks (Nz::ByteBufferView ?) - return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level)); + return lua.Push(instance->Update(pixels, srcWidth, srcHeight, level)); } /* Disabled until Box and Rect have been ported else if (lua.IsOfType(2, "Box")) @@ -93,9 +93,9 @@ namespace Ndk }); /*********************************** Nz::Font **********************************/ - font.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* font, std::size_t /*argumentCount*/) + font.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* instance, std::size_t /*argumentCount*/) { - Nz::PlacementNew(font, Nz::Font::New()); + Nz::PlacementNew(instance, Nz::Font::New()); return true; }); @@ -199,29 +199,29 @@ namespace Ndk node.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local); node.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local); - node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t /*argumentCount*/) -> int + node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int { int argIndex = 2; Nz::Vector3f offset = lua.Check(&argIndex); Nz::CoordSys coordSys = lua.Check(&argIndex, Nz::CoordSys_Local); - node.Move(offset, coordSys); + instance.Move(offset, coordSys); return 0; }); - node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t /*argumentCount*/) -> int + node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int { int argIndex = 2; Nz::Quaternionf rotation = lua.Check(&argIndex); Nz::CoordSys coordSys = lua.Check(&argIndex, Nz::CoordSys_Local); - node.Rotate(rotation, coordSys); + instance.Rotate(rotation, coordSys); return 0; }); - node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t argumentCount) -> int + node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int { std::size_t argCount = std::min(argumentCount, 4U); @@ -231,15 +231,15 @@ namespace Ndk case 1: { if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - node.Scale(lua.Check(&argIndex)); + instance.Scale(lua.Check(&argIndex)); else - node.Scale(lua.Check(&argIndex)); + instance.Scale(lua.Check(&argIndex)); return 0; } case 3: - node.Scale(lua.Check(&argIndex)); + instance.Scale(lua.Check(&argIndex)); return 0; } @@ -247,7 +247,7 @@ namespace Ndk return 0; }); - node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t argumentCount) -> int + node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int { std::size_t argCount = std::min(argumentCount, 4U); @@ -261,10 +261,10 @@ namespace Ndk { float scale = lua.Check(&argIndex); Nz::CoordSys coordSys = lua.Check(&argIndex, Nz::CoordSys_Local); - node.SetScale(scale, coordSys); + instance.SetScale(scale, coordSys); } else - node.SetScale(lua.Check(&argIndex)); + instance.SetScale(lua.Check(&argIndex)); return 0; } @@ -275,7 +275,7 @@ namespace Ndk Nz::Vector3f scale = lua.Check(&argIndex); Nz::CoordSys coordSys = lua.Check(&argIndex, Nz::CoordSys_Local); - node.SetScale(scale, coordSys); + instance.SetScale(scale, coordSys); return 0; } } @@ -284,7 +284,7 @@ namespace Ndk return 0; }); - node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t argumentCount) -> int + node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int { std::size_t argCount = std::min(argumentCount, 4U); @@ -294,16 +294,16 @@ namespace Ndk case 1: { if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - node.SetInitialScale(lua.Check(&argIndex)); + instance.SetInitialScale(lua.Check(&argIndex)); else - node.SetInitialScale(lua.Check(&argIndex)); + instance.SetInitialScale(lua.Check(&argIndex)); return 0; } case 2: case 3: - node.SetInitialScale(lua.Check(&argIndex)); + instance.SetInitialScale(lua.Check(&argIndex)); return 0; } @@ -324,4 +324,4 @@ namespace Ndk font.Register(instance); node.Register(instance); } -} \ No newline at end of file +} diff --git a/include/Nazara/Graphics/TileMap.inl b/include/Nazara/Graphics/TileMap.inl index 4473a8600..f8faa7b54 100644 --- a/include/Nazara/Graphics/TileMap.inl +++ b/include/Nazara/Graphics/TileMap.inl @@ -29,7 +29,7 @@ namespace Nz m_isometricModeEnabled(false) { NazaraAssert(m_tiles.size() != 0U, "Invalid map size"); - NazaraAssert(m_tileSize.x != 0U && m_tileSize.y != 0U, "Invalid tile size"); + NazaraAssert(m_tileSize.x > 0 && m_tileSize.y > 0, "Invalid tile size"); NazaraAssert(m_layers.size() != 0U, "Invalid material count"); for (Layer& layer : m_layers) @@ -175,7 +175,7 @@ namespace Nz * \param color The multiplicative color applied to the tile * \param materialIndex The material which will be used for rendering this tile * - * \remark The material at [materialIndex] must have a valid diffuse map before using this function, + * \remark The material at [materialIndex] must have a valid diffuse map before using this function, * as the size of the material diffuse map is used to compute normalized texture coordinates before returning. * * \see EnableTiles @@ -253,7 +253,7 @@ namespace Nz Rectf unnormalizedCoords(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height); EnableTiles(unnormalizedCoords, color, materialIndex); } - + /*! * \brief Enable and sets tileCount tiles at positions contained at tilesPos location, enabling rendering at those locations * @@ -434,14 +434,14 @@ namespace Nz * * \param TileMap The other TileMap */ - inline TileMap& TileMap::operator=(const TileMap& TileMap) + inline TileMap& TileMap::operator=(const TileMap& tileMap) { - InstancedRenderable::operator=(TileMap); + InstancedRenderable::operator=(tileMap); - m_layers = TileMap.m_layers; - m_mapSize = TileMap.m_mapSize; - m_tiles = TileMap.m_tiles; - m_tileSize = TileMap.m_tileSize; + m_layers = tileMap.m_layers; + m_mapSize = tileMap.m_mapSize; + m_tiles = tileMap.m_tiles; + m_tileSize = tileMap.m_tileSize; // We do not copy final vertices because it's highly probable that our parameters are modified and they must be regenerated InvalidateBoundingVolume(); diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl index daf7a632a..3168ba43d 100644 --- a/include/Nazara/Lua/LuaClass.inl +++ b/include/Nazara/Lua/LuaClass.inl @@ -129,7 +129,7 @@ namespace Nz BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int { - handler.ProcessArgs(lua); + handler.ProcessArguments(lua); return handler.Invoke(lua, object, func); }); @@ -143,7 +143,7 @@ namespace Nz BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int { - handler.ProcessArgs(lua); + handler.ProcessArguments(lua); return handler.Invoke(lua, object, func); }); @@ -157,7 +157,7 @@ namespace Nz BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int { - handler.ProcessArgs(lua); + handler.ProcessArguments(lua); return handler.Invoke(lua, object, func); }); @@ -171,7 +171,7 @@ namespace Nz BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int { - handler.ProcessArgs(lua); + handler.ProcessArguments(lua); return handler.Invoke(lua, object, func); }); @@ -203,7 +203,7 @@ namespace Nz BindStaticMethod(name, [func, handler] (LuaInstance& lua) -> int { - handler.ProcessArgs(lua); + handler.ProcessArguments(lua); return handler.Invoke(lua, func); }); @@ -335,7 +335,7 @@ namespace Nz NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance"); { SetupFinalizer(lua); - + if (m_info->getter || !m_info->parentGetters.empty()) SetupGetter(lua, GetterProxy); else diff --git a/include/Nazara/Lua/LuaInstance.inl b/include/Nazara/Lua/LuaInstance.inl index 25f193675..9bc20c73a 100644 --- a/include/Nazara/Lua/LuaInstance.inl +++ b/include/Nazara/Lua/LuaInstance.inl @@ -59,7 +59,7 @@ namespace Nz m_memoryUsage = instance.m_memoryUsage; m_state = instance.m_state; m_timeLimit = instance.m_timeLimit; - + instance.m_state = nullptr; return *this; @@ -320,7 +320,7 @@ namespace Nz { } - void ProcessArgs(const LuaInstance& instance) const + void ProcessArguments(const LuaInstance& instance) const { m_index = 1; ProcessArgs<0, Args...>(instance); @@ -391,7 +391,7 @@ namespace Nz { } - void ProcessArgs(const LuaInstance& instance) const + void ProcessArguments(const LuaInstance& instance) const { m_index = 2; //< 1 being the instance ProcessArgs<0, Args...>(instance); @@ -714,7 +714,7 @@ namespace Nz PushFunction([func, handler] (LuaInstance& lua) -> int { - handler.ProcessArgs(lua); + handler.ProcessArguments(lua); return handler.Invoke(lua, func); }); diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 021cb6378..f045ac28a 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -792,7 +792,7 @@ namespace Nz template bool Matrix4::IsAffine() const { - return m14 == F(0.0) && m24 == F(0.0) && m34 == F(0.0) && m44 == F(1.0); + return NumberEquals(m14, F(0.0)) && NumberEquals(m24, F(0.0)) && NumberEquals(m34, F(0.0)) && NumberEquals(m44, F(1.0)); } /*! diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index 555286024..604cbfb86 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -911,9 +911,9 @@ namespace Nz template bool Vector3::operator<(const Vector3& vec) const { - if (x == vec.x) + if (NumberEquals(x, vec.x)) { - if (y == vec.y) + if (NumberEquals(y, vec.y)) return z < vec.z; else return y < vec.y; @@ -931,10 +931,10 @@ namespace Nz template bool Vector3::operator<=(const Vector3& vec) const { - if (x == vec.x) + if (NumberEquals(x, vec.x)) { - if (y == vec.y) - return z <= vec.z; + if (NumberEquals(y, vec.y)) + return NumberEquals(z, vec.z) || z < vec.z; else return y < vec.y; } @@ -1371,7 +1371,7 @@ namespace std } }; } - + #undef F #include diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 190d31b99..f3cad0a31 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -843,11 +843,11 @@ namespace Nz template bool Vector4::operator<(const Vector4& vec) const { - if (x == vec.x) + if (NumberEquals(x, vec.x)) { - if (y == vec.y) + if (NumberEquals(y, vec.y)) { - if (z == vec.z) + if (NumberEquals(z, vec.z)) return w < vec.w; else return z < vec.z; @@ -869,12 +869,12 @@ namespace Nz template bool Vector4::operator<=(const Vector4& vec) const { - if (x == vec.x) + if (NumberEquals(x, vec.x)) { - if (y == vec.y) + if (NumberEquals(y, vec.y)) { - if (z == vec.z) - return w <= vec.w; + if (NumberEquals(z, vec.z)) + return NumberEquals(w, vec.w) || w < vec.w; else return z < vec.z; } @@ -1144,7 +1144,7 @@ namespace std } }; } - + #undef F #include diff --git a/include/Nazara/Network/IpAddress.inl b/include/Nazara/Network/IpAddress.inl index 1eaef4341..ed06b1af7 100644 --- a/include/Nazara/Network/IpAddress.inl +++ b/include/Nazara/Network/IpAddress.inl @@ -380,7 +380,7 @@ namespace std // This is SDBM adapted for IP addresses, tested to generate the least collisions possible // (It doesn't mean it cannot be improved though) - std::size_t hash = 0; + std::size_t h = 0; switch (ip.GetProtocol()) { case Nz::NetProtocol_Any: @@ -389,20 +389,20 @@ namespace std case Nz::NetProtocol_IPv4: { - hash = ip.ToUInt32() + (hash << 6) + (hash << 16) - hash; + h = ip.ToUInt32() + (h << 6) + (h << 16) - h; break; } case Nz::NetProtocol_IPv6: { Nz::IpAddress::IPv6 v6 = ip.ToIPv6(); for (std::size_t i = 0; i < v6.size(); i++) - hash = v6[i] + (hash << 6) + (hash << 16) - hash; + h = v6[i] + (h << 6) + (h << 16) - h; break; } } - return ip.GetPort() + (hash << 6) + (hash << 16) - hash; + return ip.GetPort() + (h << 6) + (h << 16) - h; } }; } diff --git a/include/Nazara/Physics2D/ConfigCheck.hpp b/include/Nazara/Physics2D/ConfigCheck.hpp index 4689d6e68..3b3b90afc 100644 --- a/include/Nazara/Physics2D/ConfigCheck.hpp +++ b/include/Nazara/Physics2D/ConfigCheck.hpp @@ -10,9 +10,9 @@ /// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp // On force la valeur de MANAGE_MEMORY en mode debug -#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS_MANAGE_MEMORY - #undef NAZARA_PHYSICS_MANAGE_MEMORY - #define NAZARA_PHYSICS3D_MANAGE_MEMORY 0 +#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS2D_MANAGE_MEMORY + #undef NAZARA_PHYSICS2D_MANAGE_MEMORY + #define NAZARA_PHYSICS2D_MANAGE_MEMORY 0 #endif #endif // NAZARA_CONFIG_CHECK_PHYSICS_HPP diff --git a/include/Nazara/Physics2D/Debug.hpp b/include/Nazara/Physics2D/Debug.hpp index f9cebc624..729491e7c 100644 --- a/include/Nazara/Physics2D/Debug.hpp +++ b/include/Nazara/Physics2D/Debug.hpp @@ -2,7 +2,7 @@ // This file is part of the "Nazara Engine - Physics 2D module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include -#if NAZARA_PHYSICS_MANAGE_MEMORY +#include +#if NAZARA_PHYSICS2D_MANAGE_MEMORY #include #endif diff --git a/include/Nazara/Physics2D/DebugOff.hpp b/include/Nazara/Physics2D/DebugOff.hpp index dd95ffe34..ffbd0a25a 100644 --- a/include/Nazara/Physics2D/DebugOff.hpp +++ b/include/Nazara/Physics2D/DebugOff.hpp @@ -3,7 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp // On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp -#if NAZARA_PHYSICS_MANAGE_MEMORY +#if NAZARA_PHYSICS2D_MANAGE_MEMORY #undef delete #undef new #endif diff --git a/include/Nazara/Physics3D/ConfigCheck.hpp b/include/Nazara/Physics3D/ConfigCheck.hpp index 6b1c82073..012cc426c 100644 --- a/include/Nazara/Physics3D/ConfigCheck.hpp +++ b/include/Nazara/Physics3D/ConfigCheck.hpp @@ -10,8 +10,8 @@ /// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp // On force la valeur de MANAGE_MEMORY en mode debug -#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS_MANAGE_MEMORY - #undef NAZARA_PHYSICS_MANAGE_MEMORY +#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS3D_MANAGE_MEMORY + #undef NAZARA_PHYSICS3D_MANAGE_MEMORY #define NAZARA_PHYSICS3D_MANAGE_MEMORY 0 #endif diff --git a/include/Nazara/Physics3D/Debug.hpp b/include/Nazara/Physics3D/Debug.hpp index f70a8b570..ef111fb96 100644 --- a/include/Nazara/Physics3D/Debug.hpp +++ b/include/Nazara/Physics3D/Debug.hpp @@ -3,6 +3,6 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#if NAZARA_PHYSICS_MANAGE_MEMORY +#if NAZARA_PHYSICS3D_MANAGE_MEMORY #include #endif diff --git a/include/Nazara/Physics3D/DebugOff.hpp b/include/Nazara/Physics3D/DebugOff.hpp index 595f0ad94..b8b84c240 100644 --- a/include/Nazara/Physics3D/DebugOff.hpp +++ b/include/Nazara/Physics3D/DebugOff.hpp @@ -3,7 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp // On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp -#if NAZARA_PHYSICS_MANAGE_MEMORY +#if NAZARA_PHYSICS3D_MANAGE_MEMORY #undef delete #undef new #endif diff --git a/include/Nazara/Physics3D/Enums.hpp b/include/Nazara/Physics3D/Enums.hpp index 1b8920cbc..b01c9bb83 100644 --- a/include/Nazara/Physics3D/Enums.hpp +++ b/include/Nazara/Physics3D/Enums.hpp @@ -25,6 +25,6 @@ namespace Nz ColliderType3D_Max = ColliderType3D_Tree }; -}; +} #endif // NAZARA_ENUMS_PHYSICS3D_HPP diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 131ceb7f3..1fd77546f 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -906,5 +906,5 @@ namespace Nz } return true; - }; + } } diff --git a/src/Nazara/Graphics/InstancedRenderable.cpp b/src/Nazara/Graphics/InstancedRenderable.cpp index ef5f62b96..e927e2d22 100644 --- a/src/Nazara/Graphics/InstancedRenderable.cpp +++ b/src/Nazara/Graphics/InstancedRenderable.cpp @@ -94,6 +94,7 @@ namespace Nz void InstancedRenderable::UpdateData(InstanceData* instanceData) const { NazaraAssert(instanceData, "Invalid instance data"); + NazaraUnused(instanceData); } InstancedRenderableLibrary::LibraryMap InstancedRenderable::s_library; diff --git a/src/Nazara/Network/NetPacket.cpp b/src/Nazara/Network/NetPacket.cpp index 0823f5258..dcac9e178 100644 --- a/src/Nazara/Network/NetPacket.cpp +++ b/src/Nazara/Network/NetPacket.cpp @@ -146,7 +146,7 @@ namespace Nz if (!m_buffer) m_buffer = std::make_unique(); - m_buffer->Resize(static_cast(cursorPos)); + m_buffer->Resize(minCapacity); m_memoryStream.SetBuffer(m_buffer.get(), openMode); m_memoryStream.SetCursorPos(cursorPos); diff --git a/src/Nazara/Network/TcpClient.cpp b/src/Nazara/Network/TcpClient.cpp index 1c84dc498..2be3d44cf 100644 --- a/src/Nazara/Network/TcpClient.cpp +++ b/src/Nazara/Network/TcpClient.cpp @@ -385,7 +385,7 @@ namespace Nz * \remark Produces a NazaraError because it is a special stream */ - bool TcpClient::SetCursorPos(UInt64 offset) + bool TcpClient::SetCursorPos(UInt64 /*offset*/) { NazaraError("SetCursorPos() cannot be used on sequential streams"); return false; diff --git a/src/Nazara/Network/Win32/SocketImpl.cpp b/src/Nazara/Network/Win32/SocketImpl.cpp index 628d29807..5a02b4bae 100644 --- a/src/Nazara/Network/Win32/SocketImpl.cpp +++ b/src/Nazara/Network/Win32/SocketImpl.cpp @@ -437,6 +437,10 @@ namespace Nz return result; #else + NazaraUnused(fdarray); + NazaraUnused(nfds); + NazaraUnused(timeout); + if (error) *error = SocketError_NotSupported; diff --git a/src/Nazara/Physics2D/Debug/NewOverload.cpp b/src/Nazara/Physics2D/Debug/NewOverload.cpp index bd3153d1d..0c82acc94 100644 --- a/src/Nazara/Physics2D/Debug/NewOverload.cpp +++ b/src/Nazara/Physics2D/Debug/NewOverload.cpp @@ -2,8 +2,8 @@ // This file is part of the "Nazara Engine - Physics 2D module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include -#if NAZARA_PHYSICS_MANAGE_MEMORY +#include +#if NAZARA_PHYSICS2D_MANAGE_MEMORY #include #include // Nécessaire ? diff --git a/src/Nazara/Physics3D/Debug/NewOverload.cpp b/src/Nazara/Physics3D/Debug/NewOverload.cpp index 18092514c..b87984066 100644 --- a/src/Nazara/Physics3D/Debug/NewOverload.cpp +++ b/src/Nazara/Physics3D/Debug/NewOverload.cpp @@ -3,7 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include -#if NAZARA_PHYSICS_MANAGE_MEMORY +#if NAZARA_PHYSICS3D_MANAGE_MEMORY #include #include // Nécessaire ? diff --git a/src/Nazara/Renderer/RenderTexture.cpp b/src/Nazara/Renderer/RenderTexture.cpp index 647b8ff91..d90ba5f1a 100644 --- a/src/Nazara/Renderer/RenderTexture.cpp +++ b/src/Nazara/Renderer/RenderTexture.cpp @@ -795,6 +795,7 @@ namespace Nz NazaraAssert(attachmentIndex < m_impl->attachments.size(), "Invalid attachment index"); NazaraAssert(!m_impl->attachments[attachmentIndex].isBuffer, "Invalid attachment state"); NazaraUnused(texture); + NazaraUnused(attachmentIndex); InvalidateTargets(); } diff --git a/src/Nazara/Utility/Formats/MTLParser.cpp b/src/Nazara/Utility/Formats/MTLParser.cpp index 1bbed892f..c3b60a6e5 100644 --- a/src/Nazara/Utility/Formats/MTLParser.cpp +++ b/src/Nazara/Utility/Formats/MTLParser.cpp @@ -331,19 +331,19 @@ namespace Nz Emit(mat.specular.b / 255.f); EmitLine(); - if (mat.alpha != 1.f) + if (!NumberEquals(mat.alpha, 1.f)) { Emit("d "); EmitLine(mat.alpha); } - if (mat.refractionIndex != 1.f) + if (!NumberEquals(mat.refractionIndex, 1.f)) { Emit("ni "); EmitLine(mat.refractionIndex); } - if (mat.shininess != 1.f) + if (!NumberEquals(mat.shininess, 1.f)) { Emit("ns "); EmitLine(mat.shininess); diff --git a/src/Nazara/Utility/Formats/OBJParser.cpp b/src/Nazara/Utility/Formats/OBJParser.cpp index 3b03b7f78..eed0ee2b1 100644 --- a/src/Nazara/Utility/Formats/OBJParser.cpp +++ b/src/Nazara/Utility/Formats/OBJParser.cpp @@ -128,17 +128,17 @@ namespace Nz UInt32 faceReserve = 0; UInt32 vertexReserve = 0; unsigned int matCount = 0; - auto GetMaterial = [&] (const String& meshName, const String& matName) -> Mesh* + auto GetMaterial = [&] (const String& mesh, const String& mat) -> Mesh* { - auto& map = meshesByName[meshName]; - auto it = map.find(matName); + auto& map = meshesByName[mesh]; + auto it = map.find(mat); if (it == map.end()) - it = map.insert(std::make_pair(matName, MatPair(Mesh(), matCount++))).first; + it = map.insert(std::make_pair(mat, MatPair(Mesh(), matCount++))).first; - Mesh& mesh = it->second.first; + Mesh& meshData = it->second.first; - mesh.faces.reserve(faceReserve); - mesh.vertices.reserve(vertexReserve); + meshData.faces.reserve(faceReserve); + meshData.vertices.reserve(vertexReserve); faceReserve = 0; vertexReserve = 0; @@ -550,19 +550,19 @@ namespace Nz EmitLine(pair.second.size()); EmitLine(); - for (std::size_t meshIndex : pair.second) + for (std::size_t index : pair.second) { - const Mesh& mesh = m_meshes[meshIndex]; + const Mesh& mesh = m_meshes[index]; Emit("g "); EmitLine(mesh.name); EmitLine(); - + Emit("# face count: "); EmitLine(mesh.faces.size()); Emit("# vertex count: "); EmitLine(mesh.vertices.size()); - + for (const Face& face : mesh.faces) { Emit('f'); diff --git a/src/Nazara/Utility/SimpleTextDrawer.cpp b/src/Nazara/Utility/SimpleTextDrawer.cpp index 03a95f35a..0d06fa0ba 100644 --- a/src/Nazara/Utility/SimpleTextDrawer.cpp +++ b/src/Nazara/Utility/SimpleTextDrawer.cpp @@ -75,6 +75,7 @@ namespace Nz Font* SimpleTextDrawer::GetFont(std::size_t index) const { NazaraAssert(index == 0, "Font index out of range"); + NazaraUnused(index); return m_font; } diff --git a/src/Nazara/Utility/SoftwareBuffer.cpp b/src/Nazara/Utility/SoftwareBuffer.cpp index 081f0fda3..040017c1e 100644 --- a/src/Nazara/Utility/SoftwareBuffer.cpp +++ b/src/Nazara/Utility/SoftwareBuffer.cpp @@ -11,7 +11,7 @@ namespace Nz { - SoftwareBuffer::SoftwareBuffer(Buffer* /*parent*/, BufferType type) + SoftwareBuffer::SoftwareBuffer(Buffer* /*parent*/, BufferType /*type*/) { } From 482eeafdb7a1470cd350e42c392ad8b74b84fda9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 4 Nov 2016 18:31:15 +0100 Subject: [PATCH 43/58] Remove save-failed file --- .gitignore | 1 + SDK/src/NDK/LuaBinding_Math.cpp.save-failed | 908 -------------------- 2 files changed, 1 insertion(+), 908 deletions(-) delete mode 100644 SDK/src/NDK/LuaBinding_Math.cpp.save-failed diff --git a/.gitignore b/.gitignore index 0801d2577..897acbca3 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ build/scripts/features/index.html doc # Codeblocks +*.save-failed build/**/*.cbp build/**/*.cbp build/**/*.cbTemp diff --git a/SDK/src/NDK/LuaBinding_Math.cpp.save-failed b/SDK/src/NDK/LuaBinding_Math.cpp.save-failed deleted file mode 100644 index 6abec5c7b..000000000 --- a/SDK/src/NDK/LuaBinding_Math.cpp.save-failed +++ /dev/null @@ -1,908 +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(angles, Nz::EulerAnglesd::Zero()); - return true; - - case 1: - Nz::PlacementNew(angles, *static_cast(lua.CheckUserdata(1, "EulerAngles"))); - return true; - - case 3: - Nz::PlacementNew(angles, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3)); - return true; - } - - lua.Error("No matching overload for EulerAngles constructor"); - return false; - }); - - 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 (std::size_t 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* rect, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 4U); - - switch (argCount) - { - case 0: - case 4: - PlacementNew(rect, 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(rect, *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(rect, lua.CheckField("x", 1), - lua.CheckField("y", 1), - lua.CheckField("width", 1), - lua.CheckField("height", 1)); - } - else if (lua.IsOfType(1, "Vector2")) - PlacementNew(rect, *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(rect, lua.CheckNumber(1), lua.CheckNumber(2)); - else if (lua.IsOfType(1, "Vector2") && lua.IsOfType(2, "Vector2")) - PlacementNew(rect, *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* quaternion, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 4U); - - switch (argCount) - { - case 0: - Nz::PlacementNew(quaternion, Nz::Quaterniond::Zero()); - return true; - - case 1: - { - if (lua.IsOfType(1, "EulerAngles")) - Nz::PlacementNew(quaternion, *static_cast(lua.ToUserdata(1))); - else if (lua.IsOfType(1, "Quaternion")) - Nz::PlacementNew(quaternion, *static_cast(lua.ToUserdata(1))); - else - break; - - return true; - } - - case 2: - Nz::PlacementNew(quaternion, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector3"))); - return true; - - case 4: - Nz::PlacementNew(quaternion, 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("__tostring", &Nz::Quaterniond::ToString); - - 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); - } -} From c4ad52235ffa1582424f67510c20310f9230a43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 4 Nov 2016 22:24:56 +0100 Subject: [PATCH 44/58] Utility/Win32: Fix Window title when using NAZARA_UTILITY_THREADED_WINDOW --- src/Nazara/Utility/Win32/WindowImpl.cpp | 6 +++--- src/Nazara/Utility/Win32/WindowImpl.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Nazara/Utility/Win32/WindowImpl.cpp b/src/Nazara/Utility/Win32/WindowImpl.cpp index b494a7789..8a4ce99f4 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.cpp +++ b/src/Nazara/Utility/Win32/WindowImpl.cpp @@ -154,7 +154,7 @@ namespace Nz // On attend que la fenêtre soit créée mutex.Lock(); - m_thread = Thread(WindowThread, &m_handle, win32StyleEx, title.GetWideString().data(), win32Style, x, y, width, height, this, &mutex, &condition); + m_thread = Thread(WindowThread, &m_handle, win32StyleEx, title, win32Style, x, y, width, height, this, &mutex, &condition); condition.Wait(&mutex); mutex.Unlock(); #else @@ -1178,10 +1178,10 @@ namespace Nz } #if NAZARA_UTILITY_THREADED_WINDOW - void WindowImpl::WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, WindowImpl* window, Mutex* mutex, ConditionVariable* condition) + void WindowImpl::WindowThread(HWND* handle, DWORD styleEx, const String& title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, WindowImpl* window, Mutex* mutex, ConditionVariable* condition) { HWND& winHandle = *handle; - winHandle = CreateWindowExW(styleEx, className, title, style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), window); + winHandle = CreateWindowExW(styleEx, className, title.GetWideString().data(), style, x, y, width, height, nullptr, nullptr, GetModuleHandle(nullptr), window); mutex->Lock(); condition->Signal(); diff --git a/src/Nazara/Utility/Win32/WindowImpl.hpp b/src/Nazara/Utility/Win32/WindowImpl.hpp index b0fcf8ae0..2e7078b32 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.hpp +++ b/src/Nazara/Utility/Win32/WindowImpl.hpp @@ -89,7 +89,7 @@ namespace Nz static LRESULT CALLBACK MessageHandler(HWND window, UINT message, WPARAM wParam, LPARAM lParam); static UInt32 RetrieveStyle(HWND window); #if NAZARA_UTILITY_THREADED_WINDOW - static void WindowThread(HWND* handle, DWORD styleEx, const wchar_t* title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, WindowImpl* window, Mutex* mutex, ConditionVariable* condition); + static void WindowThread(HWND* handle, DWORD styleEx, const String& title, DWORD style, unsigned int x, unsigned int y, unsigned int width, unsigned int height, WindowImpl* window, Mutex* mutex, ConditionVariable* condition); #endif HCURSOR m_cursor; From 12f68779631ce29918e004ac3708532a3783dabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 4 Nov 2016 22:25:16 +0100 Subject: [PATCH 45/58] Fix some warnings --- include/Nazara/Core/ConditionVariable.hpp | 2 +- src/Nazara/Utility/Window.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/Nazara/Core/ConditionVariable.hpp b/include/Nazara/Core/ConditionVariable.hpp index f6aeafe9b..19ab9e863 100644 --- a/include/Nazara/Core/ConditionVariable.hpp +++ b/include/Nazara/Core/ConditionVariable.hpp @@ -29,7 +29,7 @@ namespace Nz bool Wait(Mutex* mutex, UInt32 timeout); ConditionVariable& operator=(const ConditionVariable&) = delete; - inline ConditionVariable& operator=(ConditionVariable&& condition) noexcept; + ConditionVariable& operator=(ConditionVariable&& condition) noexcept; private: ConditionVariableImpl* m_impl; diff --git a/src/Nazara/Utility/Window.cpp b/src/Nazara/Utility/Window.cpp index 078ff2bc5..203ad7c71 100644 --- a/src/Nazara/Utility/Window.cpp +++ b/src/Nazara/Utility/Window.cpp @@ -335,6 +335,7 @@ namespace Nz void Window::ProcessEvents(bool block) { NazaraAssert(m_impl, "Window not created"); + NazaraUnused(block); #if !NAZARA_UTILITY_THREADED_WINDOW m_impl->ProcessEvents(block); From 581cc989de3b1332d51589e7cb4502903772e072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 4 Nov 2016 22:57:07 +0100 Subject: [PATCH 46/58] Utility/Win32: Fix cached position never getting updated with threaded windows Closes #104 --- src/Nazara/Utility/Win32/WindowImpl.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Nazara/Utility/Win32/WindowImpl.cpp b/src/Nazara/Utility/Win32/WindowImpl.cpp index 8a4ce99f4..0c1d23050 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.cpp +++ b/src/Nazara/Utility/Win32/WindowImpl.cpp @@ -792,12 +792,17 @@ namespace Nz RECT windowRect; GetWindowRect(m_handle, &windowRect); - WindowEvent event; - event.type = WindowEventType_Moved; - event.position.x = windowRect.left; - event.position.y = windowRect.top; - m_parent->PushEvent(event); + Vector2i position(windowRect.left, windowRect.top); + if (m_position != position) + { + m_position = position; + WindowEvent event; + event.type = WindowEventType_Moved; + event.position.x = position.x; + event.position.y = position.y; + m_parent->PushEvent(event); + } break; } From 6ebe29ceb453dceaa9739f3a2c47b200a9839b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Fri, 4 Nov 2016 23:18:36 +0100 Subject: [PATCH 47/58] Utility/Win32: Generate only one WindowEvent_Moved per movement When not using threaded windows. Fixed #105 --- src/Nazara/Utility/Win32/WindowImpl.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Nazara/Utility/Win32/WindowImpl.cpp b/src/Nazara/Utility/Win32/WindowImpl.cpp index 0c1d23050..0c193cfaa 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.cpp +++ b/src/Nazara/Utility/Win32/WindowImpl.cpp @@ -789,6 +789,11 @@ namespace Nz case WM_MOVE: { + #if !NAZARA_UTILITY_THREADED_WINDOW + if (m_sizemove) + break; + #endif + RECT windowRect; GetWindowRect(m_handle, &windowRect); From 5aeb9f8d592162a9ace3a692af56b81fa733e540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 6 Nov 2016 11:17:19 +0100 Subject: [PATCH 48/58] Build: Add CodeBlocks target to premake5 --- build/scripts/actions/codeblocks.lua | 6 + .../actions/codeblocks/_codeblocks.lua | 44 ++++ .../scripts/actions/codeblocks/codeblocks.lua | 67 +++++ .../actions/codeblocks/codeblocks_project.lua | 243 ++++++++++++++++++ .../codeblocks/codeblocks_workspace.lua | 44 ++++ build/scripts/common.lua | 70 ++--- 6 files changed, 441 insertions(+), 33 deletions(-) create mode 100644 build/scripts/actions/codeblocks.lua create mode 100644 build/scripts/actions/codeblocks/_codeblocks.lua create mode 100644 build/scripts/actions/codeblocks/codeblocks.lua create mode 100644 build/scripts/actions/codeblocks/codeblocks_project.lua create mode 100644 build/scripts/actions/codeblocks/codeblocks_workspace.lua diff --git a/build/scripts/actions/codeblocks.lua b/build/scripts/actions/codeblocks.lua new file mode 100644 index 000000000..2a1f8b249 --- /dev/null +++ b/build/scripts/actions/codeblocks.lua @@ -0,0 +1,6 @@ +if (PremakeVersion >= 50) then + dofile("codeblocks/_codeblocks.lua") + dofile("codeblocks/codeblocks.lua") +end + +ACTION.Manual = true diff --git a/build/scripts/actions/codeblocks/_codeblocks.lua b/build/scripts/actions/codeblocks/_codeblocks.lua new file mode 100644 index 000000000..6a52bc404 --- /dev/null +++ b/build/scripts/actions/codeblocks/_codeblocks.lua @@ -0,0 +1,44 @@ +-- +-- _codeblocks.lua +-- Define the Code::Blocks action(s). +-- Copyright (c) 2002-2011 Jason Perkins and the Premake project +-- + local p = premake + + p.modules.codeblocks = {} + p.modules.codeblocks._VERSION = p._VERSION + + local codeblocks = p.modules.codeblocks + + newaction { + trigger = "codeblocks", + shortname = "Code::Blocks", + description = "Generate Code::Blocks project files", + + valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" }, + + valid_languages = { "C", "C++" }, + + valid_tools = { + cc = { "clang", "gcc", "ow" }, + }, + + onWorkspace = function(wks) + p.modules.codeblocks.generateWorkspace(wks) + end, + + onProject = function(prj) + p.modules.codeblocks.generateProject(prj) + end, + + onCleanWorkspace = function(wks) + p.clean.file(wks, wks.name .. ".workspace") + p.clean.file(wks, wks.name .. ".workspace.layout") + end, + + onCleanProject = function(prj) + p.clean.file(prj, prj.name .. ".workspace") + p.clean.file(prj, prj.name .. ".depend") + p.clean.file(prj, prj.name .. ".layout") + end + } diff --git a/build/scripts/actions/codeblocks/codeblocks.lua b/build/scripts/actions/codeblocks/codeblocks.lua new file mode 100644 index 000000000..ebd8d11fa --- /dev/null +++ b/build/scripts/actions/codeblocks/codeblocks.lua @@ -0,0 +1,67 @@ +-- +-- codeblocks_workspace.lua +-- Generate a Code::Blocks workspace. +-- Copyright (c) 2009 Jason Perkins and the Premake project +-- + + local p = premake + + p.modules.codeblocks = {} + p.modules.codeblocks._VERSION = p._VERSION + + local codeblocks = p.modules.codeblocks + local project = p.project + + + function codeblocks.cfgname(cfg) + local cfgname = cfg.buildcfg + if codeblocks.workspace.multiplePlatforms then + cfgname = string.format("%s|%s", cfg.platform, cfg.buildcfg) + end + return cfgname + end + + function codeblocks.esc(value) + local result = value:gsub('"', '"') + result = result:gsub('<', '<') + result = result:gsub('>', '>') + return result + end + + function codeblocks.generateWorkspace(wks) + p.eol("\r\n") + p.indent("\t") + p.escaper(codeblocks.esc) + + p.generate(wks, ".workspace", codeblocks.workspace.generate) + end + + function codeblocks.generateProject(prj) + p.eol("\r\n") + p.indent("\t") + p.escaper(codeblocks.esc) + + if project.iscpp(prj) then + p.generate(prj, ".cbp", codeblocks.project.generate) + end + end + + function codeblocks.cleanWorkspace(wks) + p.clean.file(wks, wks.name .. ".workspace") + p.clean.file(wks, wks.name .. ".workspace.layout") + end + + function codeblocks.cleanProject(prj) + p.clean.file(prj, prj.name .. ".workspace") + p.clean.file(prj, prj.name .. ".depend") + p.clean.file(prj, prj.name .. ".layout") + end + + function codeblocks.cleanTarget(prj) + -- TODO.. + end + + include("codeblocks_workspace.lua") + include("codeblocks_project.lua") + + diff --git a/build/scripts/actions/codeblocks/codeblocks_project.lua b/build/scripts/actions/codeblocks/codeblocks_project.lua new file mode 100644 index 000000000..9882d5fbe --- /dev/null +++ b/build/scripts/actions/codeblocks/codeblocks_project.lua @@ -0,0 +1,243 @@ +-- +-- codeblocks_cbp.lua +-- Generate a Code::Blocks C/C++ project. +-- Copyright (c) 2009, 2011 Jason Perkins and the Premake project +-- + + local p = premake + local project = p.project + local config = p.config + local tree = p.tree + local codeblocks = p.modules.codeblocks + + codeblocks.project = {} + local m = codeblocks.project + m.elements = {} + + m.ctools = { + gcc = "gcc", + msc = "Visual C++", + } + + function m.getcompilername(cfg) + local tool = _OPTIONS.cc or cfg.toolset or p.GCC + + local toolset = p.tools[tool] + if not toolset then + error("Invalid toolset '" + (_OPTIONS.cc or cfg.toolset) + "'") + end + + return m.ctools[tool] + end + + function m.getcompiler(cfg) + local toolset = p.tools[_OPTIONS.cc or cfg.toolset or p.GCC] + if not toolset then + error("Invalid toolset '" + (_OPTIONS.cc or cfg.toolset) + "'") + end + return toolset + end + + function m.header(prj) + _p('') + _p('') + _p(1,'') + + -- write project block header + _p(1,'') + _p(2,'') + _p('') + end + + m.elements.project = function(prj) + return { + m.header, + m.configurations, + m.files, + m.extensions, + m.footer + } + end + +-- +-- Project: Generate the CodeBlocks project file. +-- + function m.generate(prj) + p.utf8() + + p.callArray(m.elements.project, prj) + end + + function m.configurations(prj) + -- write configuration blocks + _p(2,'') + local platforms = {} + for cfg in project.eachconfig(prj) do + local found = false + for k,v in pairs(platforms) do + if (v.platform == cfg.platform) then + table.insert(v.configs, cfg) + found = true + break + end + end + + if (not found) then + table.insert(platforms, {platform = cfg.platform, configs = {cfg}}) + end + end + + for k,platform in pairs(platforms) do + for k,cfg in pairs(platform.configs) do + local compiler = m.getcompiler(cfg) + + _p(3,'', cfg.longname) + + _p(4,'') + end + end + _p(2,'') + end + +-- +-- Write out a list of the source code files in the project. +-- + + function m.files(prj) + local pchheader + if (prj.pchheader) then + pchheader = path.getrelative(prj.location, prj.pchheader) + end + + local tr = project.getsourcetree(prj) + tree.traverse(tr, { + -- source files are handled at the leaves + onleaf = function(node, depth) + if node.relpath == node.vpath then + _p(2,'', node.relpath) + else + _p(2,'', node.name) + _p(3,'') + + end, + }, false, 1) + end + + function m.extensions(prj) + for cfg in project.eachconfig(prj) do + if cfg.debugenvs and #cfg.debugenvs > 0 then + --Assumption: if gcc is being used then so is gdb although this section will be ignored by + --other debuggers. If using gcc and not gdb it will silently not pass the + --environment arguments to the debugger + if m.getcompilername(cfg) == "gcc" then + _p(3,'') + _p(4,'', p.esc(cfg.longname)) + local args = '' + local sz = #cfg.debugenvs + for idx, v in ipairs(cfg.debugenvs) do + args = args .. 'set env ' .. v + if sz ~= idx then args = args .. ' ' end + end + _p(5,'',args) + _p(4,'') + _p(3,'') + else + error('Sorry at this moment there is no support for debug environment variables with this debugger and codeblocks') + end + end + end + end diff --git a/build/scripts/actions/codeblocks/codeblocks_workspace.lua b/build/scripts/actions/codeblocks/codeblocks_workspace.lua new file mode 100644 index 000000000..3de935877 --- /dev/null +++ b/build/scripts/actions/codeblocks/codeblocks_workspace.lua @@ -0,0 +1,44 @@ +-- +-- Name: codelite/codelite_workspace.lua +-- Purpose: Generate a CodeLite workspace. +-- Author: Ryan Pusztai +-- Modified by: Andrea Zanellato +-- Manu Evans +-- Created: 2013/05/06 +-- Copyright: (c) 2008-2015 Jason Perkins and the Premake project +-- + + local p = premake + local project = p.project + local workspace = p.workspace + local tree = p.tree + local codeblocks = p.modules.codeblocks + + codeblocks.workspace = {} + local m = codeblocks.workspace + +-- +-- Generate a CodeBlocks workspace +-- + function m.generate(wks) + p.utf8() + + _p('') + _p('') + _p(1,'', wks.name) + + for prj in workspace.eachproject(wks) do + local fname = path.join(path.getrelative(wks.location, prj.location), prj.name) + local active = iif(prj.project == wks.projects[1], ' active="1"', '') + + _p(2,'', fname, active) + for _,dep in ipairs(project.getdependencies(prj)) do + _p(3,'', path.join(path.getrelative(wks.location, dep.location), dep.name)) + end + + _p(2,'') + end + + _p(1,'') + _p('') + end \ No newline at end of file diff --git a/build/scripts/common.lua b/build/scripts/common.lua index 423ebad0d..42a565fd6 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -14,6 +14,12 @@ function NazaraBuild:Execute() return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien end + if (PremakeVersion >= 50) then + filter { "kind:SharedLib", "action:codeblocks or codelite or gmake or xcode3 or xcode4" } + implibprefix "lib" + implibextension ".a" + end + local platformData if (os.is64bit()) then platformData = {"x64", "x32"} @@ -721,7 +727,7 @@ function NazaraBuild:MakeInstallCommands(infoTable) for k,v in pairs(self.InstallDir) do local destPath = path.translate(path.isabsolute(k) and k or "../../" .. k) - postbuildcommands({[[xcopy "%{path.translate(cfg.linktarget.relpath):sub(1, -5) .. ".dll"}" "]] .. destPath .. [[\" /E /Y]]}) + postbuildcommands({[[xcopy "%{path.translate(cfg.buildtarget.relpath)}" "]] .. destPath .. [[\" /E /Y]]}) end for k,fileName in pairs(table.join(infoTable.Libraries, infoTable.DynLib)) do @@ -877,40 +883,38 @@ function NazaraBuild:Process(infoTable) end function NazaraBuild:RegisterAction(actionTable) - if (actionTable.Name == nil or type(actionTable.Name) ~= "string" or string.len(actionTable.Name) == 0) then - return false, "Invalid action name" + if (not actionTable.Manual) then + if (actionTable.Name == nil or type(actionTable.Name) ~= "string" or string.len(actionTable.Name) == 0) then + return false, "Invalid action name" + end + + local lowerCaseName = string.lower(actionTable.Name) + if (self.Actions[lowerCaseName] ~= nil) then + return false, "This action name is already in use" + end + + if (actionTable.Description == nil or type(actionTable.Description) ~= "string") then + return false, "Action description is invalid" + end + + if (string.len(actionTable.Description) == 0) then + return false, "Action description is empty" + end + + if (actionTable.Function == nil or type(actionTable.Function) ~= "function") then + return false, "Action function is invalid" + end + + self.Actions[lowerCaseName] = actionTable + + newaction + { + trigger = lowerCaseName, + description = actionTable.Description, + execute = function () actionTable:Function() end + } end - local lowerCaseName = string.lower(actionTable.Name) - if (self.Actions[lowerCaseName] ~= nil) then - return false, "This action name is already in use" - end - - if (actionTable.Description == nil or type(actionTable.Description) ~= "string") then - return false, "Action description is invalid" - end - - if (string.len(actionTable.Description) == 0) then - return false, "Action description is empty" - end - - if (self.Actions[actionTable.name] ~= nil) then - return false, "Action name \"" .. actionTable.name .. " is already registred" - end - - if (actionTable.Function == nil or type(actionTable.Function) ~= "function") then - return false, "Action function is invalid" - end - - self.Actions[lowerCaseName] = actionTable - - newaction - { - trigger = lowerCaseName, - description = actionTable.Description, - execute = function () actionTable:Function() end - } - return true end From 88000ab2e4dd6a2cc565cf4023ea7ddf03c4d62f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 6 Nov 2016 21:30:37 +0100 Subject: [PATCH 49/58] Build: Upgrade to Premake5-alpha10, get rid of Premake4 --- build/Build_CodeBlocks.bat | 2 +- build/scripts/actions/codeblocks.lua | 6 +- build/scripts/common.lua | 443 ++++++++++----------------- 3 files changed, 162 insertions(+), 289 deletions(-) diff --git a/build/Build_CodeBlocks.bat b/build/Build_CodeBlocks.bat index 439c5efac..5e6c23c44 100644 --- a/build/Build_CodeBlocks.bat +++ b/build/Build_CodeBlocks.bat @@ -1 +1 @@ -premake4 codeblocks \ No newline at end of file +premake5 codeblocks \ No newline at end of file diff --git a/build/scripts/actions/codeblocks.lua b/build/scripts/actions/codeblocks.lua index 2a1f8b249..f96a6d591 100644 --- a/build/scripts/actions/codeblocks.lua +++ b/build/scripts/actions/codeblocks.lua @@ -1,6 +1,4 @@ -if (PremakeVersion >= 50) then - dofile("codeblocks/_codeblocks.lua") - dofile("codeblocks/codeblocks.lua") -end +dofile("codeblocks/_codeblocks.lua") +dofile("codeblocks/codeblocks.lua") ACTION.Manual = true diff --git a/build/scripts/common.lua b/build/scripts/common.lua index 42a565fd6..402484e06 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -9,27 +9,103 @@ function NazaraBuild:AddInstallPath(path) self.InstallDir[path] = true end +function NazaraBuild:FilterLibDirectory(prefix, func) + filter({"action:codeblocks or codelite or gmake", "architecture:x86", "system:Windows"}) + func(prefix .. "mingw/x86") + + filter({"action:codeblocks or codelite or gmake", "architecture:x86_64", "system:Windows"}) + func(prefix .. "mingw/x64") + + filter({"action:codeblocks or codelite or gmake", "architecture:x86", "system:not Windows"}) + func(prefix .. "gmake/x86") + + filter({"action:codeblocks or codelite or gmake", "architecture:x86_64", "system:not Windows"}) + func(prefix .. "gmake/x64") + + filter({"action:vs*", "architecture:x86"}) + func(prefix .. "msvc/x86") + + filter({"action:vs*", "architecture:x86_64"}) + func(prefix .. "msvc/x64") + + filter({"action:xcode3 or xcode4", "architecture:x86"}) + func(prefix .. "xcode/x86") + + filter({"action:xcode3 or xcode4", "architecture:x86_64"}) + func(prefix .. "xcode/x64") + + filter({}) +end + function NazaraBuild:Execute() - if (_ACTION == nil) then -- Si aucune action n'est spécifiée + if (_ACTION == nil) then -- If no action is specified, the user probably only wants to know how all of this works return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien end - if (PremakeVersion >= 50) then - filter { "kind:SharedLib", "action:codeblocks or codelite or gmake or xcode3 or xcode4" } - implibprefix "lib" - implibextension ".a" - end + + local clangGccActions = "action:" .. table.concat({"codeblocks", "codelite", "gmake", "xcode3", "xcode4"}, " or ") local platformData if (os.is64bit()) then - platformData = {"x64", "x32"} + platformData = {"x64", "x86"} else - platformData = {"x32", "x64"} + platformData = {"x86", "x64"} end - if (self.Actions[_ACTION] == nil) then - local makeLibDir = os.is("windows") and "mingw" or "gmake" + flags({ + "C++14", + "MultiProcessorCompile", + "NoMinimalRebuild" + }) + self:FilterLibDirectory("../extlibs/lib/", libdirs) + + -- Fixes Premake stuff + filter({"kind:SharedLib", clangGccActions}) + implibprefix("lib") + filter({"kind:*Lib", clangGccActions, "system:Windows"}) + implibextension(".a") + filter({"kind:StaticLib", clangGccActions}) + targetextension(".a") + targetprefix("lib") + + -- General configuration + filter("kind:*Lib") + pic("On") + + filter({"kind:*Lib", "configurations:DebugStatic"}) + targetsuffix("-s-d") + + filter({"kind:*Lib", "configurations:ReleaseStatic"}) + targetsuffix("-s") + + filter({"kind:*Lib", "configurations:DebugDynamic"}) + targetsuffix("-d") + + filter("configurations:Debug*") + symbols("On") + + -- Setup some optimizations for release + filter("configurations:Release*") + flags("NoFramePointer") + optimize("Speed") + rtti("Off") + vectorextensions("SSE2") + + filter("configurations:*Static") + kind("StaticLib") + + filter("configurations:*Dynamic") + kind("SharedLib") + + -- Enable SSE math and vectorization optimizations + filter({"configurations:Release*", clangGccActions}) + buildoptions("-mfpmath=sse") + buildoptions("-ftree-vectorize") + + filter({}) + + if (self.Actions[_ACTION] == nil) then if (self.Config["BuildDependencies"]) then workspace("NazaraExtlibs") platforms(platformData) @@ -40,63 +116,18 @@ function NazaraBuild:Execute() "ReleaseStatic" }) + self:FilterLibDirectory("../extlibs/lib/", targetdir) + + filter(clangGccActions) + buildoptions("-U__STRICT_ANSI__") + + filter({}) + includedirs("../extlibs/include") libdirs("../extlibs/lib/common") location(_ACTION) kind("StaticLib") - configuration({"codeblocks or codelite or gmake", "x32"}) - libdirs("../extlibs/lib/" .. makeLibDir .. "/x86") - targetdir("../extlibs/lib/" .. makeLibDir .. "/x86") - - configuration({"codeblocks or codelite or gmake", "x64"}) - libdirs("../extlibs/lib/" .. makeLibDir .. "/x64") - targetdir("../extlibs/lib/" .. makeLibDir .. "/x64") - - configuration("vs*") - buildoptions({"/MP", "/bigobj"}) -- Multiprocessus build and big .obj - - configuration({"vs*", "x32"}) - libdirs("../extlibs/lib/msvc/x86") - targetdir("../extlibs/lib/msvc/x86") - - configuration({"vs*", "x64"}) - libdirs("../extlibs/lib/msvc/x64") - targetdir("../extlibs/lib/msvc/x64") - - configuration({"xcode3 or xcode4", "x32"}) - libdirs("../extlibs/lib/xcode/x86") - targetdir("../extlibs/lib/xcode/x86") - - configuration({"xcode3 or xcode4", "x64"}) - libdirs("../extlibs/lib/xcode/x64") - targetdir("../extlibs/lib/xcode/x64") - - configuration("Debug*") - flags("Symbols") - - configuration("Release*") - flags("NoFramePointer") - optimize("Speed") - rtti("Off") - vectorextensions("SSE2") - - configuration({"Release*", "codeblocks or codelite or gmake or xcode3 or xcode4"}) - buildoptions("-mfpmath=sse") -- Utilisation du SSE pour les calculs flottants - buildoptions("-ftree-vectorize") -- Activation de la vectorisation du code - - configuration("DebugStatic") - targetsuffix("-s-d") - - configuration("ReleaseStatic") - targetsuffix("-s") - - configuration({"not windows", "codeblocks or codelite or gmake or xcode3 or xcode4"}) - buildoptions("-fPIC") - - configuration("codeblocks or codelite or gmake or xcode3 or xcode4") - buildoptions({"-std=c++14", "-U__STRICT_ANSI__"}) - for k, libTable in ipairs(self.OrderedExtLibs) do project(libTable.Name) @@ -111,25 +142,44 @@ function NazaraBuild:Execute() includedirs(libTable.Includes) links(libTable.Libraries) - configuration("x32") + filter("architecture:x86") libdirs(libTable.LibraryPaths.x86) - configuration("x64") + filter("architecture:x86_64") libdirs(libTable.LibraryPaths.x64) for k,v in pairs(libTable.ConfigurationLibraries) do - configuration(k) - links(v) + filter(k) + links(v) end - configuration({}) + filter({}) end end + -- General settings + filter("architecture:x86_64") + defines("NAZARA_PLATFORM_x64") + + filter("configurations:Debug*") + defines("NAZARA_DEBUG") + + filter("configurations:*Static") + defines("NAZARA_STATIC") + + filter("kind:*Lib") + defines("NAZARA_BUILD") + + filter({"system:not Windows", clangGccActions}) + buildoptions("-fvisibility=hidden") + + -- Add lib/conf/arch to library search path + self:FilterLibDirectory("../lib/", libdirs) + + -- Start defining projects workspace("NazaraEngine") platforms(platformData) - -- Configuration générale configurations({ -- "DebugStatic", -- "ReleaseStatic", @@ -140,36 +190,13 @@ function NazaraBuild:Execute() language("C++") location(_ACTION) - configuration("Debug*") - defines("NAZARA_DEBUG") - flags("Symbols") - - configuration("Release*") - flags("NoFramePointer") - optimize("Speed") - vectorextensions("SSE2") - - configuration({"Release*", "codeblocks or codelite or gmake or xcode3 or xcode4"}) - buildoptions("-mfpmath=sse") -- Utilisation du SSE pour les calculs flottants - buildoptions("-ftree-vectorize") -- Activation de la vectorisation du code - - configuration("*Static") - defines("NAZARA_STATIC") - - configuration("codeblocks or codelite or gmake or xcode3 or xcode4") - buildoptions("-std=c++14") - - configuration({"linux or bsd or macosx", "gmake"}) - buildoptions("-fvisibility=hidden") - configuration("vs*") buildoptions({"/MP", "/bigobj"}) -- Multiprocessus build and big .obj flags("NoMinimalRebuild") defines("_CRT_SECURE_NO_WARNINGS") defines("_SCL_SECURE_NO_WARNINGS") - - -- Spécification des modules + -- Modules if (_OPTIONS["united"]) then project("NazaraEngine") end @@ -181,78 +208,12 @@ function NazaraBuild:Execute() location(_ACTION .. "/modules") - defines("NAZARA_BUILD") - includedirs({ "../include", "../src/", "../extlibs/include" }) - libdirs("../lib") - libdirs("../extlibs/lib/common") - - configuration("x32") - libdirs(moduleTable.LibraryPaths.x86) - - configuration("x64") - defines("NAZARA_PLATFORM_x64") - libdirs(moduleTable.LibraryPaths.x64) - - configuration({"codeblocks or codelite or gmake", "x32"}) - libdirs("../extlibs/lib/" .. makeLibDir .. "/x86") - libdirs("../lib/" .. makeLibDir .. "/x86") - targetdir("../lib/" .. makeLibDir .. "/x86") - - configuration({"codeblocks or codelite or gmake", "x64"}) - libdirs("../extlibs/lib/" .. makeLibDir .. "/x64") - libdirs("../lib/" .. makeLibDir .. "/x64") - targetdir("../lib/" .. makeLibDir .. "/x64") - - -- Copy the module binaries to the example folder - self:MakeInstallCommands(moduleTable) - - configuration({"vs*", "x32"}) - libdirs("../extlibs/lib/msvc/x86") - libdirs("../lib/msvc/x86") - targetdir("../lib/msvc/x86") - - configuration({"vs*", "x64"}) - libdirs("../extlibs/lib/msvc/x64") - libdirs("../lib/msvc/x64") - targetdir("../lib/msvc/x64") - - configuration({"xcode3 or xcode4", "x32"}) - libdirs("../extlibs/lib/xcode/x86") - libdirs("../lib/xcode/x86") - targetdir("../lib/xcode/x86") - - configuration({"xcode3 or xcode4", "x64"}) - libdirs("../extlibs/lib/xcode/x64") - libdirs("../lib/xcode/x64") - targetdir("../lib/xcode/x64") - - configuration("*Static") - defines("NAZARA_STATIC") - kind("StaticLib") - - configuration("*Dynamic") - kind("SharedLib") - - configuration("DebugStatic") - targetsuffix("-s-d") - - configuration("ReleaseStatic") - targetsuffix("-s") - - configuration("DebugDynamic") - targetsuffix("-d") - - configuration("Release*") - rtti(moduleTable.EnableRTTI and "On" or "Off") - - configuration({}) - files(moduleTable.Files) excludes(moduleTable.FilesExcluded) @@ -261,6 +222,23 @@ function NazaraBuild:Execute() includedirs(moduleTable.Includes) links(moduleTable.Libraries) + libdirs({ + "../extlibs/lib/common", + "../lib" + }) + + -- Output to lib/conf/arch + self:FilterLibDirectory("../lib/", targetdir) + + -- Copy the module binaries to the example folder + self:MakeInstallCommands(moduleTable) + + filter("architecture:x86") + libdirs(moduleTable.LibraryPaths.x86) + + filter("architecture:x86_64") + libdirs(moduleTable.LibraryPaths.x64) + for k,v in pairs(moduleTable.ConfigurationLibraries) do configuration(k) links(v) @@ -294,7 +272,7 @@ function NazaraBuild:Execute() kind("WindowedApp") end else - assert(false, "Invalid tool Kind") + assert(false, "Invalid tool kind") end includedirs({ @@ -302,94 +280,10 @@ function NazaraBuild:Execute() "../extlibs/include" }) - libdirs("../lib") - libdirs("../extlibs/lib/common") - - configuration("x32") - libdirs(toolTable.LibraryPaths.x86) - - configuration("x64") - defines("NAZARA_PLATFORM_x64") - libdirs(toolTable.LibraryPaths.x64) - - configuration({"codeblocks or codelite or gmake", "x32"}) - libdirs("../extlibs/lib/" .. makeLibDir .. "/x86") - libdirs("../lib/" .. makeLibDir .. "/x86") - if (toolTable.Kind == "library") then - targetdir(toolTable.TargetDirectory .. "/" .. makeLibDir .. "/x86") - elseif (toolTable.Kind == "plugin") then - targetdir("../plugins/lib/" .. makeLibDir .. "/x86") - end - - configuration({"codeblocks or codelite or gmake", "x64"}) - libdirs("../extlibs/lib/" .. makeLibDir .. "/x64") - libdirs("../lib/" .. makeLibDir .. "/x64") - if (toolTable.Kind == "library") then - targetdir(toolTable.TargetDirectory .. "/" .. makeLibDir .. "/x64") - elseif (toolTable.Kind == "plugin") then - targetdir("../plugins/lib/" .. makeLibDir .. "/x64") - end - - configuration({"vs*", "x32"}) - libdirs("../extlibs/lib/msvc/x86") - libdirs("../lib/msvc/x86") - if (toolTable.Kind == "library") then - targetdir(toolTable.TargetDirectory .. "/msvc/x86") - elseif (toolTable.Kind == "plugin") then - targetdir("../plugins/lib/msvc/x86") - end - - configuration({"vs*", "x64"}) - libdirs("../extlibs/lib/msvc/x64") - libdirs("../lib/msvc/x64") - if (toolTable.Kind == "library") then - targetdir(toolTable.TargetDirectory .. "/msvc/x64") - elseif (toolTable.Kind == "plugin") then - targetdir("../plugins/lib/msvc/x64") - end - - configuration({"xcode3 or xcode4", "x32"}) - libdirs("../extlibs/lib/xcode/x86") - libdirs("../lib/xcode/x86") - if (toolTable.Kind == "library") then - targetdir(toolTable.TargetDirectory .. "/xcode/x86") - elseif (toolTable.Kind == "plugin") then - targetdir("../plugins/lib/xcode/x86") - end - - configuration({"xcode3 or xcode4", "x64"}) - libdirs("../extlibs/lib/xcode/x64") - libdirs("../lib/xcode/x64") - if (toolTable.Kind == "library") then - targetdir(toolTable.TargetDirectory .. "/xcode/x64") - elseif (toolTable.Kind == "plugin") then - targetdir("../plugins/lib/xcode/x64") - end - - configuration("*Static") - defines("NAZARA_STATIC") - - configuration("Release*") - rtti(toolTable.EnableRTTI and "On" or "Off") - - if (toolTable.Kind == "library" or toolTable.Kind == "plugin") then - configuration("*Static") - kind("StaticLib") - - configuration("*Dynamic") - kind("SharedLib") - - configuration("DebugStatic") - targetsuffix("-s-d") - - configuration("ReleaseStatic") - targetsuffix("-s") - - configuration("DebugDynamic") - targetsuffix("-d") - end - - configuration({}) + libdirs({ + "../extlibs/lib/common", + "../lib" + }) files(toolTable.Files) excludes(toolTable.FilesExcluded) @@ -399,12 +293,25 @@ function NazaraBuild:Execute() includedirs(toolTable.Includes) links(toolTable.Libraries) + -- Output to lib/conf/arch + if (toolTable.Kind == "library") then + self:FilterLibDirectory(toolTable.TargetDirectory .. "/", targetdir) + elseif (toolTable.Kind == "plugin") then + self:FilterLibDirectory("../plugins/lib/", targetdir) + end + + filter("architecture:x86") + libdirs(toolTable.LibraryPaths.x86) + + filter("architecture:x86_64") + libdirs(toolTable.LibraryPaths.x64) + for k,v in pairs(toolTable.ConfigurationLibraries) do - configuration(k) + filter(k) links(v) end - configuration({}) + filter({}) end for k, exampleTable in ipairs(self.OrderedExamples) do @@ -435,7 +342,6 @@ function NazaraBuild:Execute() "../extlibs/include" }) libdirs("../lib") - targetdir(destPath) files(exampleTable.Files) excludes(exampleTable.FilesExcluded) @@ -444,41 +350,14 @@ function NazaraBuild:Execute() flags(exampleTable.Flags) includedirs(exampleTable.Includes) links(exampleTable.Libraries) - - configuration("Release*") - rtti(exampleTable.EnableRTTI and "On" or "Off") - - configuration("x32") - libdirs(exampleTable.LibraryPaths.x86) - - configuration("x64") - defines("NAZARA_PLATFORM_x64") - libdirs(exampleTable.LibraryPaths.x64) - - configuration({"codeblocks or codelite or gmake", "x32"}) - libdirs("../lib/" .. makeLibDir .. "/x86") - - configuration({"codeblocks or codelite or gmake", "x64"}) - libdirs("../lib/" .. makeLibDir .. "/x64") - - configuration({"vs*", "x32"}) - libdirs("../lib/msvc/x86") - - configuration({"vs*", "x64"}) - libdirs("../lib/msvc/x64") - - configuration({"xcode3 or xcode4", "x32"}) - libdirs("../lib/xcode/x86") - - configuration({"xcode3 or xcode4", "x64"}) - libdirs("../lib/xcode/x64") + targetdir(destPath) for k,v in pairs(exampleTable.ConfigurationLibraries) do - configuration(k) + filter(k) links(v) end - configuration({}) + filter({}) end end end @@ -718,10 +597,6 @@ function NazaraBuild:LoadConfig() end function NazaraBuild:MakeInstallCommands(infoTable) - if (PremakeVersion < 50) then - return - end - if (os.is("windows")) then configuration("*Dynamic") From 9e9b01eff5eb3454f056a2bbee6b2e5377cbb135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 6 Nov 2016 21:30:49 +0100 Subject: [PATCH 50/58] .gitignore: Ignore GMake build files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 897acbca3..831ce911d 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,9 @@ build/**/*.workspace # CodeLite build/**/*.project +# GMake +build/**/*.make + # Visual Studio build/**/*.pdb build/**/*.filters From 6500d088e9034fe963fc4abb18655ab11cffa0a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 6 Nov 2016 21:59:48 +0100 Subject: [PATCH 51/58] Build: Fix some premake5 weirdness It seems some options are global and other local to the workspace (flags and buildoptions could be defined outside of the workspace, defines couldn't) --- build/scripts/common.lua | 157 +++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 74 deletions(-) diff --git a/build/scripts/common.lua b/build/scripts/common.lua index 402484e06..e7c685857 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -42,7 +42,6 @@ function NazaraBuild:Execute() return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien end - local clangGccActions = "action:" .. table.concat({"codeblocks", "codelite", "gmake", "xcode3", "xcode4"}, " or ") local platformData @@ -52,59 +51,6 @@ function NazaraBuild:Execute() platformData = {"x86", "x64"} end - flags({ - "C++14", - "MultiProcessorCompile", - "NoMinimalRebuild" - }) - - self:FilterLibDirectory("../extlibs/lib/", libdirs) - - -- Fixes Premake stuff - filter({"kind:SharedLib", clangGccActions}) - implibprefix("lib") - filter({"kind:*Lib", clangGccActions, "system:Windows"}) - implibextension(".a") - filter({"kind:StaticLib", clangGccActions}) - targetextension(".a") - targetprefix("lib") - - -- General configuration - filter("kind:*Lib") - pic("On") - - filter({"kind:*Lib", "configurations:DebugStatic"}) - targetsuffix("-s-d") - - filter({"kind:*Lib", "configurations:ReleaseStatic"}) - targetsuffix("-s") - - filter({"kind:*Lib", "configurations:DebugDynamic"}) - targetsuffix("-d") - - filter("configurations:Debug*") - symbols("On") - - -- Setup some optimizations for release - filter("configurations:Release*") - flags("NoFramePointer") - optimize("Speed") - rtti("Off") - vectorextensions("SSE2") - - filter("configurations:*Static") - kind("StaticLib") - - filter("configurations:*Dynamic") - kind("SharedLib") - - -- Enable SSE math and vectorization optimizations - filter({"configurations:Release*", clangGccActions}) - buildoptions("-mfpmath=sse") - buildoptions("-ftree-vectorize") - - filter({}) - if (self.Actions[_ACTION] == nil) then if (self.Config["BuildDependencies"]) then workspace("NazaraExtlibs") @@ -116,6 +62,7 @@ function NazaraBuild:Execute() "ReleaseStatic" }) + self:PrepareGeneric() self:FilterLibDirectory("../extlibs/lib/", targetdir) filter(clangGccActions) @@ -156,30 +103,16 @@ function NazaraBuild:Execute() filter({}) end end - - -- General settings - filter("architecture:x86_64") - defines("NAZARA_PLATFORM_x64") - - filter("configurations:Debug*") - defines("NAZARA_DEBUG") - - filter("configurations:*Static") - defines("NAZARA_STATIC") - - filter("kind:*Lib") - defines("NAZARA_BUILD") - - filter({"system:not Windows", clangGccActions}) - buildoptions("-fvisibility=hidden") - - -- Add lib/conf/arch to library search path - self:FilterLibDirectory("../lib/", libdirs) - + -- Start defining projects workspace("NazaraEngine") platforms(platformData) + self:PrepareMainWorkspace() + + -- Add lib/conf/arch to library search path + self:FilterLibDirectory("../lib/", libdirs) + configurations({ -- "DebugStatic", -- "ReleaseStatic", @@ -757,6 +690,82 @@ function NazaraBuild:Process(infoTable) return true end +function NazaraBuild:PrepareGeneric() + flags({ + "C++14", + "MultiProcessorCompile", + "NoMinimalRebuild" + }) + + self:FilterLibDirectory("../extlibs/lib/", libdirs) + + -- Fixes Premake stuff + filter({"kind:SharedLib", clangGccActions}) + implibprefix("lib") + filter({"kind:*Lib", clangGccActions, "system:Windows"}) + implibextension(".a") + filter({"kind:StaticLib", clangGccActions}) + targetextension(".a") + targetprefix("lib") + + -- General configuration + filter("kind:*Lib") + pic("On") + + filter({"kind:*Lib", "configurations:DebugStatic"}) + targetsuffix("-s-d") + + filter({"kind:*Lib", "configurations:ReleaseStatic"}) + targetsuffix("-s") + + filter({"kind:*Lib", "configurations:DebugDynamic"}) + targetsuffix("-d") + + filter("configurations:Debug*") + symbols("On") + + -- Setup some optimizations for release + filter("configurations:Release*") + flags("NoFramePointer") + optimize("Speed") + rtti("Off") + vectorextensions("SSE2") + + filter("configurations:*Static") + kind("StaticLib") + + filter("configurations:*Dynamic") + kind("SharedLib") + + -- Enable SSE math and vectorization optimizations + filter({"configurations:Release*", clangGccActions}) + buildoptions("-mfpmath=sse") + buildoptions("-ftree-vectorize") + + filter({}) +end + +function NazaraBuild:PrepareMainWorkspace() + self:PrepareGeneric() + + filter("architecture:x86_64") + defines("NAZARA_PLATFORM_x64") + + filter("configurations:Debug*") + defines("NAZARA_DEBUG") + + filter("configurations:*Static") + defines("NAZARA_STATIC") + + filter("kind:*Lib") + defines("NAZARA_BUILD") + + filter({"system:not Windows", clangGccActions}) + buildoptions("-fvisibility=hidden") + + filter({}) +end + function NazaraBuild:RegisterAction(actionTable) if (not actionTable.Manual) then if (actionTable.Name == nil or type(actionTable.Name) ~= "string" or string.len(actionTable.Name) == 0) then From 5e48f8b8b3ab536e494a4fe68beb62937ed92b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 6 Nov 2016 22:04:47 +0100 Subject: [PATCH 52/58] Build: Fix install commands --- build/scripts/common.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/build/scripts/common.lua b/build/scripts/common.lua index e7c685857..0e46c9b9c 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -531,8 +531,10 @@ end function NazaraBuild:MakeInstallCommands(infoTable) if (os.is("windows")) then - configuration("*Dynamic") - + filter("kind:SharedLib") + + postbuildmessage("Copying " .. infoTable.Name .. " library and its dependencies to install/executable directories...") + for k,v in pairs(self.InstallDir) do local destPath = path.translate(path.isabsolute(k) and k or "../../" .. k) postbuildcommands({[[xcopy "%{path.translate(cfg.buildtarget.relpath)}" "]] .. destPath .. [[\" /E /Y]]}) @@ -541,24 +543,24 @@ function NazaraBuild:MakeInstallCommands(infoTable) for k,fileName in pairs(table.join(infoTable.Libraries, infoTable.DynLib)) do local paths = {} for k,v in pairs(infoTable.BinaryPaths.x86) do - table.insert(paths, {"x32", v .. "/" .. fileName .. ".dll"}) - table.insert(paths, {"x32", v .. "/lib" .. fileName .. ".dll"}) + table.insert(paths, {"x86", v .. "/" .. fileName .. ".dll"}) + table.insert(paths, {"x86", v .. "/lib" .. fileName .. ".dll"}) end for k,v in pairs(infoTable.BinaryPaths.x64) do - table.insert(paths, {"x64", v .. "/" .. fileName .. ".dll"}) - table.insert(paths, {"x64", v .. "/lib" .. fileName .. ".dll"}) + table.insert(paths, {"x86_64", v .. "/" .. fileName .. ".dll"}) + table.insert(paths, {"x86_64", v .. "/lib" .. fileName .. ".dll"}) end for k,v in pairs(paths) do - local config = v[1] + local arch = v[1] local srcPath = v[2] if (os.isfile(srcPath)) then if (infoTable.Kind == "plugin") then srcPath = "../../" .. srcPath end - configuration(config) + filter("architecture:" .. arch) for k,v in pairs(self.ExecutableDir) do local srcPath = path.isabsolute(srcPath) and path.translate(srcPath) or [[%{path.translate(cfg.linktarget.relpath:sub(1, -#cfg.linktarget.name - 1) .. "../../]] .. srcPath .. [[")}]] @@ -568,6 +570,8 @@ function NazaraBuild:MakeInstallCommands(infoTable) end end end + + filter({}) end end From 0de741a541178df6e6e56baef40fde3fcda55d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 6 Nov 2016 22:25:13 +0100 Subject: [PATCH 53/58] Build: Fix MSVC creating .a .. --- build/scripts/common.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/build/scripts/common.lua b/build/scripts/common.lua index 0e46c9b9c..dc340a12e 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -1,4 +1,7 @@ -NazaraBuild = {} -- L'équivalent d'un namespace en Lua est une table +NazaraBuild = {} + +-- I wish Premake had a way to know the compiler in advance +local clangGccActions = "action:" .. table.concat({"codeblocks", "codelite", "gmake", "xcode3", "xcode4"}, " or ") function NazaraBuild:AddExecutablePath(path) self.ExecutableDir[path] = true @@ -42,8 +45,6 @@ function NazaraBuild:Execute() return -- Alors l'utilisateur voulait probablement savoir comment utiliser le programme, on ne fait rien end - local clangGccActions = "action:" .. table.concat({"codeblocks", "codelite", "gmake", "xcode3", "xcode4"}, " or ") - local platformData if (os.is64bit()) then platformData = {"x64", "x86"} From 0f14a57b2e1a4552b9280929fe07b79767893aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 6 Nov 2016 22:41:22 +0100 Subject: [PATCH 54/58] Build: Cleanup common.lua --- build/scripts/common.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/build/scripts/common.lua b/build/scripts/common.lua index dc340a12e..2fed34c43 100644 --- a/build/scripts/common.lua +++ b/build/scripts/common.lua @@ -124,12 +124,6 @@ function NazaraBuild:Execute() language("C++") location(_ACTION) - configuration("vs*") - buildoptions({"/MP", "/bigobj"}) -- Multiprocessus build and big .obj - flags("NoMinimalRebuild") - defines("_CRT_SECURE_NO_WARNINGS") - defines("_SCL_SECURE_NO_WARNINGS") - -- Modules if (_OPTIONS["united"]) then project("NazaraEngine") @@ -174,11 +168,11 @@ function NazaraBuild:Execute() libdirs(moduleTable.LibraryPaths.x64) for k,v in pairs(moduleTable.ConfigurationLibraries) do - configuration(k) + filter(k) links(v) end - configuration({}) + filter({}) end -- Tools @@ -753,6 +747,11 @@ end function NazaraBuild:PrepareMainWorkspace() self:PrepareGeneric() + filter("action:vs*") + buildoptions({"/MP", "/bigobj"}) -- Multiprocessus build and big .obj + defines("_CRT_SECURE_NO_WARNINGS") + defines("_SCL_SECURE_NO_WARNINGS") + filter("architecture:x86_64") defines("NAZARA_PLATFORM_x64") From 4f01e13b09ab1b8cc176c934e90d072125b17572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 6 Nov 2016 23:12:08 +0100 Subject: [PATCH 55/58] Sdk: Fix typo --- SDK/include/NDK/Prerequesites.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDK/include/NDK/Prerequesites.hpp b/SDK/include/NDK/Prerequesites.hpp index a2305c70f..78b894ccc 100644 --- a/SDK/include/NDK/Prerequesites.hpp +++ b/SDK/include/NDK/Prerequesites.hpp @@ -29,7 +29,7 @@ // Importation/Exportation of the API #if defined(NAZARA_STATIC) - #define #define NDK_API + #define NDK_API #else #ifdef NDK_BUILD #define NDK_API NAZARA_EXPORT From 638467f8791ba7752eb3f201a853c7f8d7345e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sun, 6 Nov 2016 23:49:10 +0100 Subject: [PATCH 56/58] Build: Fix codeblocks debug and object directory --- build/scripts/actions/codeblocks/codeblocks_project.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/scripts/actions/codeblocks/codeblocks_project.lua b/build/scripts/actions/codeblocks/codeblocks_project.lua index 9882d5fbe..acfede4c2 100644 --- a/build/scripts/actions/codeblocks/codeblocks_project.lua +++ b/build/scripts/actions/codeblocks/codeblocks_project.lua @@ -102,10 +102,10 @@ _p(4,'