diff --git a/SDK/include/NDK/Application.hpp b/SDK/include/NDK/Application.hpp index 69e97bdce..23417bcd8 100644 --- a/SDK/include/NDK/Application.hpp +++ b/SDK/include/NDK/Application.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -83,7 +82,6 @@ namespace Ndk struct ConsoleOverlay { Console* console; - Nz::LuaInstance lua; NazaraSlot(Nz::EventHandler, OnEvent, eventSlot); NazaraSlot(Nz::EventHandler, OnKeyPressed, keyPressedSlot); diff --git a/SDK/include/NDK/Lua/LuaBinding.hpp b/SDK/include/NDK/Lua/LuaBinding.hpp deleted file mode 100644 index 2a14cb5a5..000000000 --- a/SDK/include/NDK/Lua/LuaBinding.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_HPP -#define NDK_LUABINDING_HPP - -#include -#include -#include - -namespace Ndk -{ - class NDK_API LuaBinding - { - friend class LuaBinding_SDK; - - public: - LuaBinding(); - ~LuaBinding() = default; - - template void BindComponent(const Nz::String& name); - - void RegisterClasses(Nz::LuaState& state); - - std::unique_ptr core; - std::unique_ptr math; - std::unique_ptr network; - std::unique_ptr sdk; - std::unique_ptr utility; - - #ifndef NDK_SERVER - std::unique_ptr audio; - std::unique_ptr graphics; - std::unique_ptr renderer; - std::unique_ptr platform; - #endif - - private: - template - static int AddComponentOfType(Nz::LuaState& lua, EntityHandle& handle); - - template - static int PushComponentOfType(Nz::LuaState& lua, BaseComponent& component); - - using AddComponentFunc = int(*)(Nz::LuaState&, EntityHandle&); - using GetComponentFunc = int(*)(Nz::LuaState&, BaseComponent&); - - struct ComponentBinding - { - AddComponentFunc adder; - ComponentIndex index; - GetComponentFunc getter; - Nz::String name; - }; - - ComponentBinding* QueryComponentIndex(Nz::LuaState& lua, int argIndex = 2); - - std::vector m_componentBinding; - std::unordered_map m_componentBindingByName; - }; -} - -#include - -#endif // NDK_LUABINDING_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding.inl b/SDK/include/NDK/Lua/LuaBinding.inl deleted file mode 100644 index 95ea207ab..000000000 --- a/SDK/include/NDK/Lua/LuaBinding.inl +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -namespace Ndk -{ - namespace Detail - { - template - struct AddComponentIf; - - template<> - struct AddComponentIf - { - template - static int AddComponent(Nz::LuaState& lua, EntityHandle& handle) - { - T& component = handle->AddComponent(); - lua.Push(component.CreateHandle()); - return 1; - } - }; - - template<> - struct AddComponentIf - { - template - static int AddComponent(Nz::LuaState& lua, EntityHandle& /*handle*/) - { - lua.Error("Component has no default constructor and cannot be created from Lua yet"); - return 0; - } - }; - } - - /*! - * \brief Binds a component to a name - * - * \param name Name used to retrieve the component - * - * \remark Produces a NazaraAssert if name is empty - */ - template - void LuaBinding::BindComponent(const Nz::String& name) - { - NazaraAssert(!name.IsEmpty(), "Component name cannot be empty"); - - static_assert(std::is_base_of::value, "ComponentType must inherit BaseComponent"); - - ComponentBinding binding; - binding.adder = &Detail::AddComponentIf::value>::template AddComponent; - binding.getter = &PushComponentOfType; - binding.index = T::componentIndex; - binding.name = name; - - if (m_componentBinding.size() <= T::componentIndex) - m_componentBinding.resize(T::componentIndex + 1); - - m_componentBinding[T::componentIndex] = std::move(binding); - m_componentBindingByName[name] = T::componentIndex; - } - - template - int LuaBinding::PushComponentOfType(Nz::LuaState& lua, BaseComponent& component) - { - T& rightComponent = static_cast(component); - lua.Push(rightComponent.CreateHandle()); - return 1; - } -} diff --git a/SDK/include/NDK/Lua/LuaBinding_Audio.hpp b/SDK/include/NDK/Lua/LuaBinding_Audio.hpp deleted file mode 100644 index f2ee8c1ac..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_Audio.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_AUDIO_HPP -#define NDK_LUABINDING_AUDIO_HPP - -#include -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API LuaBinding_Audio : public LuaBinding_Base - { - public: - LuaBinding_Audio(LuaBinding& binding); - ~LuaBinding_Audio() = default; - - void Register(Nz::LuaState& state) override; - - Nz::LuaClass music; - Nz::LuaClass sound; - Nz::LuaClass soundBuffer; - Nz::LuaClass soundEmitter; - }; -} - -#endif // NDK_LUABINDING_CORE_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding_Base.hpp b/SDK/include/NDK/Lua/LuaBinding_Base.hpp deleted file mode 100644 index 5a52e0bc2..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_Base.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_BASE_HPP -#define NDK_LUABINDING_BASE_HPP - -#include -#include -#include - -namespace Ndk -{ - class LuaBinding; - - class LuaBinding_Audio; - class LuaBinding_Core; - class LuaBinding_Graphics; - class LuaBinding_Math; - class LuaBinding_Network; - class LuaBinding_Renderer; - class LuaBinding_SDK; - class LuaBinding_Utility; - class LuaBinding_Platform; - - class NDK_API LuaBinding_Base - { - public: - LuaBinding_Base(LuaBinding& binding); - virtual ~LuaBinding_Base(); - - virtual void Register(Nz::LuaState& state) = 0; - - // Implementation lies in the respective .cpp files (still searching for a cleaner way..) - static std::unique_ptr BindCore(LuaBinding& binding); - static std::unique_ptr BindMath(LuaBinding& binding); - static std::unique_ptr BindNetwork(LuaBinding& binding); - static std::unique_ptr BindSDK(LuaBinding& binding); - static std::unique_ptr BindUtility(LuaBinding& binding); - - #ifndef NDK_SERVER - static std::unique_ptr BindAudio(LuaBinding& binding); - static std::unique_ptr BindGraphics(LuaBinding& binding); - static std::unique_ptr BindRenderer(LuaBinding& binding); - static std::unique_ptr BindPlatform(LuaBinding& binding); - #endif - - protected: - LuaBinding& m_binding; - }; -} - -#endif // NDK_LUABINDING_BASE_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding_Core.hpp b/SDK/include/NDK/Lua/LuaBinding_Core.hpp deleted file mode 100644 index 4277936e0..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_Core.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_CORE_HPP -#define NDK_LUABINDING_CORE_HPP - -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API LuaBinding_Core : public LuaBinding_Base - { - public: - LuaBinding_Core(LuaBinding& binding); - ~LuaBinding_Core() = default; - - void Register(Nz::LuaState& state) override; - - Nz::LuaClass clock; - Nz::LuaClass file; - Nz::LuaClass stream; - }; -} - -#endif // NDK_LUABINDING_CORE_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding_Graphics.hpp b/SDK/include/NDK/Lua/LuaBinding_Graphics.hpp deleted file mode 100644 index 7a804dd0f..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_Graphics.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_GRAPHICS_HPP -#define NDK_LUABINDING_GRAPHICS_HPP - -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API LuaBinding_Graphics : public LuaBinding_Base - { - public: - LuaBinding_Graphics(LuaBinding& binding); - ~LuaBinding_Graphics() = default; - - void Register(Nz::LuaState& state) override; - - Nz::LuaClass abstractViewer; - Nz::LuaClass instancedRenderable; - Nz::LuaClass material; - Nz::LuaClass model; - Nz::LuaClass sprite; - Nz::LuaClass spriteLibrary; - }; -} - -#endif // NDK_LUABINDING_GRAPHICS_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding_Math.hpp b/SDK/include/NDK/Lua/LuaBinding_Math.hpp deleted file mode 100644 index 5849a7c33..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_Math.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_MATH_HPP -#define NDK_LUABINDING_MATH_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API LuaBinding_Math : public LuaBinding_Base - { - public: - LuaBinding_Math(LuaBinding& binding); - ~LuaBinding_Math() = default; - - void Register(Nz::LuaState& state) override; - - Nz::LuaClass eulerAngles; - Nz::LuaClass matrix4d; - Nz::LuaClass quaternion; - Nz::LuaClass rect; - Nz::LuaClass vector2d; - Nz::LuaClass vector3d; - }; -} - -#endif // NDK_LUABINDING_MATH_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding_Network.hpp b/SDK/include/NDK/Lua/LuaBinding_Network.hpp deleted file mode 100644 index 1b7f32f27..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_Network.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_NETWORK_HPP -#define NDK_LUABINDING_NETWORK_HPP - -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API LuaBinding_Network : public LuaBinding_Base - { - public: - LuaBinding_Network(LuaBinding& binding); - ~LuaBinding_Network() = default; - - void Register(Nz::LuaState& state) override; - - Nz::LuaClass abstractSocket; - Nz::LuaClass ipAddress; - Nz::LuaClass udpSocket; - }; -} - -#endif // NDK_LUABINDING_NETWORK_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding_Platform.hpp b/SDK/include/NDK/Lua/LuaBinding_Platform.hpp deleted file mode 100644 index 2d28841e7..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_Platform.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_SYSTEM_HPP -#define NDK_LUABINDING_SYSTEM_HPP - -#include -#include - -namespace Ndk -{ - class NDK_API LuaBinding_Platform : public LuaBinding_Base - { - public: - LuaBinding_Platform(LuaBinding& binding); - ~LuaBinding_Platform() = default; - - void Register(Nz::LuaState& state) override; - - // Platform - Nz::LuaClass keyboard; - }; -} - -#endif // NDK_LUABINDING_SYSTEM_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding_Renderer.hpp b/SDK/include/NDK/Lua/LuaBinding_Renderer.hpp deleted file mode 100644 index daa75e4af..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_Renderer.hpp +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_RENDERER_HPP -#define NDK_LUABINDING_RENDERER_HPP - -#include -#include - -namespace Ndk -{ - class NDK_API LuaBinding_Renderer : public LuaBinding_Base - { - public: - LuaBinding_Renderer(LuaBinding& binding); - ~LuaBinding_Renderer() = default; - - void Register(Nz::LuaState& state) override; - - Nz::LuaClass texture; - Nz::LuaClass textureLibrary; - Nz::LuaClass textureManager; - }; -} - -#endif // NDK_LUABINDING_RENDERER_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding_SDK.hpp b/SDK/include/NDK/Lua/LuaBinding_SDK.hpp deleted file mode 100644 index a663edce4..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_SDK.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_SDK_HPP -#define NDK_LUABINDING_SDK_HPP - -#include -#include -#include -#include -#include - -namespace Ndk -{ - class Application; - - class NDK_API LuaBinding_SDK : public LuaBinding_Base - { - public: - LuaBinding_SDK(LuaBinding& binding); - ~LuaBinding_SDK() = default; - - void Register(Nz::LuaState& state) override; - - Nz::LuaClass application; - Nz::LuaClass entity; - Nz::LuaClass nodeComponent; - Nz::LuaClass velocityComponent; - Nz::LuaClass world; - - #ifndef NDK_SERVER - Nz::LuaClass cameraComponent; - Nz::LuaClass console; - Nz::LuaClass graphicsComponent; - #endif - - }; -} - -#endif // NDK_LUABINDING_SDK_HPP diff --git a/SDK/include/NDK/Lua/LuaBinding_Utility.hpp b/SDK/include/NDK/Lua/LuaBinding_Utility.hpp deleted file mode 100644 index 6f7fde64b..000000000 --- a/SDK/include/NDK/Lua/LuaBinding_Utility.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUABINDING_UTILITY_HPP -#define NDK_LUABINDING_UTILITY_HPP - -#include -#include -#include -#include - -namespace Ndk -{ - class NDK_API LuaBinding_Utility : public LuaBinding_Base - { - public: - LuaBinding_Utility(LuaBinding& binding); - ~LuaBinding_Utility() = default; - - void Register(Nz::LuaState& state) override; - - // Utility - Nz::LuaClass abstractImage; - Nz::LuaClass font; - Nz::LuaClass node; - }; -} - -#endif // NDK_LUABINDING_UTILITY_HPP diff --git a/SDK/include/NDK/LuaAPI.hpp b/SDK/include/NDK/LuaAPI.hpp deleted file mode 100644 index 457ffb980..000000000 --- a/SDK/include/NDK/LuaAPI.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#pragma once - -#ifndef NDK_LUAINTERFACE_HPP -#define NDK_LUAINTERFACE_HPP - -#include - -namespace Nz -{ - class LuaState; -} - -namespace Ndk -{ - class LuaBinding; - - class NDK_API LuaAPI - { - public: - LuaAPI() = delete; - ~LuaAPI() = delete; - - static LuaBinding* GetBinding(); - - static bool Initialize(); - - static void RegisterClasses(Nz::LuaState& state); - - static void Uninitialize(); - - private: - static LuaBinding* s_binding; - }; -} - -#include - -#endif // NDK_LUAINTERFACE_HPP diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl deleted file mode 100644 index b867e90fe..000000000 --- a/SDK/include/NDK/LuaAPI.inl +++ /dev/null @@ -1,687 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef NDK_SERVER -#include -#include -#include -#include -#include -#endif - -namespace Nz -{ - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Color* color, TypeTag) - { - state.CheckType(index, Nz::LuaType_Table); - - color->r = state.CheckField("r", index); - color->g = state.CheckField("g", index); - color->b = state.CheckField("b", index); - color->a = state.CheckField("a", 255, index); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, EulerAnglesd* angles, TypeTag) - { - switch (state.GetType(index)) - { - case Nz::LuaType_Table: - angles->Set(state.CheckField("pitch", index), state.CheckField("yaw", index), state.CheckField("roll", index)); - return 1; - - default: - { - if (state.IsOfType(index, "EulerAngles")) - angles->Set(*static_cast(state.ToUserdata(index))); - else - angles->Set(*static_cast(state.CheckUserdata(index, "Quaternion"))); - - return 1; - } - } - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, EulerAnglesf* angles, TypeTag) - { - EulerAnglesd anglesDouble; - unsigned int ret = LuaImplQueryArg(state, index, &anglesDouble, TypeTag()); - - angles->Set(anglesDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, FontRef* fontRef, TypeTag) - { - *fontRef = *static_cast(state.CheckUserdata(index, "Font")); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, FontParams* params, TypeTag) - { - NazaraUnused(params); - - state.CheckType(index, Nz::LuaType_Table); - - // Structure is empty for now - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, ImageParams* params, TypeTag) - { - state.CheckType(index, Nz::LuaType_Table); - - params->levelCount = state.CheckField("LevelCount"); - params->loadFormat = state.CheckField("LoadFormat"); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, IpAddress* address, TypeTag) - { - switch (state.GetType(index)) - { - case Nz::LuaType_String: - address->BuildFromAddress(state.CheckString(index)); - return 1; - - default: - *address = *static_cast(state.CheckUserdata(index, "IpAddress")); - return 1; - } - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Matrix4d* mat, TypeTag) - { - switch (state.GetType(index)) - { - case Nz::LuaType_Table: - { - double values[16]; - for (std::size_t i = 0; i < 16; ++i) - { - state.PushInteger(i + 1); - state.GetTable(); - - values[i] = state.CheckNumber(-1); - state.Pop(); - } - - *mat = Matrix4d(values); - return 1; - } - - default: - { - if (state.IsOfType(index, "Matrix4")) - *mat = *static_cast(state.ToUserdata(index)); - - return 1; - } - } - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Matrix4f* mat, TypeTag) - { - Matrix4d matDouble = Matrix4d::Identity(); - unsigned int ret = LuaImplQueryArg(state, index, &matDouble, TypeTag()); - - mat->Set(matDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, MeshParams* params, TypeTag) - { - state.CheckType(index, Nz::LuaType_Table); - - params->animated = state.CheckField("Animated", params->animated); - params->center = state.CheckField("Center", params->center); - params->matrix = state.CheckField("Matrix", params->matrix); - params->optimizeIndexBuffers = state.CheckField("OptimizeIndexBuffers", params->optimizeIndexBuffers); - params->texCoordOffset = state.CheckField("TexCoordOffset", params->texCoordOffset); - params->texCoordScale = state.CheckField("TexCoordScale", params->texCoordScale); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Quaterniond* quat, TypeTag) - { - switch (state.GetType(index)) - { - case Nz::LuaType_Table: - quat->Set(state.CheckField("w", index), state.CheckField("x", index), state.CheckField("y", index), state.CheckField("z", index)); - return 1; - - default: - { - if (state.IsOfType(index, "EulerAngles")) - quat->Set(*static_cast(state.ToUserdata(index))); - else - quat->Set(*static_cast(state.CheckUserdata(index, "Quaternion"))); - - return 1; - } - } - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Quaternionf* quat, TypeTag) - { - Quaterniond quatDouble; - unsigned int ret = LuaImplQueryArg(state, index, &quatDouble, TypeTag()); - - quat->Set(quatDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Rectd* rect, TypeTag) - { - state.CheckType(index, LuaType_Table); - - rect->x = state.CheckField("x", index); - rect->y = state.CheckField("y", index); - rect->width = state.CheckField("width", index); - rect->height = state.CheckField("height", index); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Rectf* rect, TypeTag) - { - Rectd rectDouble; - unsigned int ret = LuaImplQueryArg(state, index, &rectDouble, TypeTag()); - - rect->Set(rectDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Recti* rect, TypeTag) - { - Rectd rectDouble; - unsigned int ret = LuaImplQueryArg(state, index, &rectDouble, TypeTag()); - - rect->Set(rectDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Rectui* rect, TypeTag) - { - Rectd rectDouble; - unsigned int ret = LuaImplQueryArg(state, index, &rectDouble, TypeTag()); - - rect->Set(rectDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector2d* vec, TypeTag) - { - switch (state.GetType(index)) - { - case Nz::LuaType_Number: - if (index < 0 && index > -2) - state.Error("Vector2 expected, two numbers are required to convert it"); - - vec->Set(state.CheckNumber(index), state.CheckNumber(index + 1)); - return 2; - - case Nz::LuaType_Table: - vec->Set(state.CheckField("x", index), state.CheckField("y", index)); - return 1; - - default: - vec->Set(*static_cast(state.CheckUserdata(index, "Vector2"))); - return 1; - } - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector2f* vec, TypeTag) - { - Vector2d vecDouble; - unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag()); - - vec->Set(vecDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector2ui* vec, TypeTag) - { - Vector2d vecDouble; - unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag()); - - vec->Set(vecDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector2i* vec, TypeTag) - { - Vector2d vecDouble; - unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag()); - - vec->Set(vecDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector3d* vec, TypeTag) - { - switch (state.GetType(index)) - { - case Nz::LuaType_Number: - if (index < 0 && index > -3) - state.Error("Vector3 expected, three numbers are required to convert it"); - - vec->Set(state.CheckNumber(index), state.CheckNumber(index + 1), state.CheckNumber(index + 2, 0.0)); - return 3; - - case Nz::LuaType_Table: - vec->Set(state.CheckField("x", index), state.CheckField("y", index), state.CheckField("z", 0.0, index)); - return 1; - - default: - vec->Set(*static_cast(state.CheckUserdata(index, "Vector3"))); - return 1; - } - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector3f* vec, TypeTag) - { - Vector3d vecDouble; - unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag()); - - vec->Set(vecDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector3ui* vec, TypeTag) - { - Vector3d vecDouble; - unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag()); - - vec->Set(vecDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector3i* vec, TypeTag) - { - Vector3d vecDouble; - unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag()); - - vec->Set(vecDouble); - return ret; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Ndk::Entity** handle, TypeTag) - { - if (!state.IsOfType(index, LuaType_Nil)) - *handle = *static_cast(state.CheckUserdata(index, "Entity")); - else - *handle = nullptr; - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Ndk::EntityHandle* handle, TypeTag) - { - if (!state.IsOfType(index, LuaType_Nil)) - *handle = *static_cast(state.CheckUserdata(index, "Entity")); - else - handle->Reset(); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Ndk::WorldHandle* handle, TypeTag) - { - *handle = *static_cast(state.CheckUserdata(index, "World")); - - return 1; - } - -#ifndef NDK_SERVER - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, InstancedRenderableRef* renderable, TypeTag) - { - if (state.IsOfType(index, "InstancedRenderable") || - state.IsOfType(index, "Model") || - state.IsOfType(index, "Sprite")) - { - *renderable = *static_cast(state.ToUserdata(index)); - } - else - state.ArgError(index, "is not a InstancedRenderable instance"); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, MaterialRef* materialRef, TypeTag) - { - *materialRef = *static_cast(state.CheckUserdata(index, "Material")); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, MaterialParams* params, TypeTag) - { - state.CheckType(index, Nz::LuaType_Table); - - params->loadAlphaMap = state.CheckField("LoadAlphaMap", params->loadAlphaMap); - params->loadDiffuseMap = state.CheckField("LoadDiffuseMap", params->loadDiffuseMap); - params->loadEmissiveMap = state.CheckField("LoadEmissiveMap", params->loadEmissiveMap); - params->loadHeightMap = state.CheckField("LoadHeightMap", params->loadHeightMap); - params->loadNormalMap = state.CheckField("LoadNormalMap", params->loadNormalMap); - params->loadSpecularMap = state.CheckField("LoadSpecularMap", params->loadSpecularMap); - params->shaderName = state.CheckField("ShaderName", params->shaderName); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, ModelParameters* params, TypeTag) - { - state.CheckType(index, Nz::LuaType_Table); - - params->loadMaterials = state.CheckField("LoadMaterials", params->loadMaterials); - - LuaImplQueryArg(state, -1, ¶ms->material, TypeTag()); - LuaImplQueryArg(state, -1, ¶ms->mesh, TypeTag()); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, SoundBufferParams* params, TypeTag) - { - state.CheckType(index, Nz::LuaType_Table); - - params->forceMono = state.CheckField("ForceMono", params->forceMono); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, SoundStreamParams* params, TypeTag) - { - state.CheckType(index, Nz::LuaType_Table); - - params->forceMono = state.CheckField("ForceMono", params->forceMono); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, SpriteRef* spriteRef, TypeTag) - { - *spriteRef = *static_cast(state.CheckUserdata(index, "Sprite")); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& state, int index, TextureRef* textureRef, TypeTag) - { - *textureRef = *static_cast(state.CheckUserdata(index, "Texture")); - - return 1; - } -#endif - - inline int LuaImplReplyVal(const LuaState& state, Color&& val, TypeTag) - { - state.PushTable(); - state.PushField("r", val.r); - state.PushField("g", val.g); - state.PushField("b", val.b); - state.PushField("a", val.a); - - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, EulerAnglesd&& val, TypeTag) - { - state.PushInstance("EulerAngles", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, EulerAnglesf&& val, TypeTag) - { - state.PushInstance("EulerAngles", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, FontRef&& val, TypeTag) - { - state.PushInstance("Font", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Font::SizeInfo&& val, TypeTag) - { - state.PushTable(); - state.PushField("LineHeight", val.lineHeight); - state.PushField("SpaceAdvance", val.spaceAdvance); - state.PushField("UnderlinePosition", val.underlinePosition); - state.PushField("UnderlineThickness", val.underlineThickness); - - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, ImageParams&& val, TypeTag) - { - state.PushTable(0, 2); - state.PushField("LevelCount", val.levelCount); - state.PushField("LoadFormat", val.loadFormat); - - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, IpAddress&& val, TypeTag) - { - state.PushInstance("IpAddress", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Matrix4d&& val, TypeTag) - { - state.PushInstance("Matrix4", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Matrix4f&& val, TypeTag) - { - state.PushInstance("Matrix4", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Quaterniond&& val, TypeTag) - { - state.PushInstance("Quaternion", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Quaternionf&& val, TypeTag) - { - state.PushInstance("Quaternion", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Rectd&& val, TypeTag) - { - state.PushInstance("Rect", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Rectf&& val, TypeTag) - { - state.PushInstance("Rect", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Recti&& val, TypeTag) - { - state.PushInstance("Rect", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Rectui&& val, TypeTag) - { - state.PushInstance("Rect", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Vector2d&& val, TypeTag) - { - state.PushInstance("Vector2", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Vector2f&& val, TypeTag) - { - state.PushInstance("Vector2", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Vector2ui&& val, TypeTag) - { - state.PushInstance("Vector2", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Vector2i&& val, TypeTag) - { - state.PushInstance("Vector2", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Vector3d&& val, TypeTag) - { - state.PushInstance("Vector3", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Vector3f&& val, TypeTag) - { - state.PushInstance("Vector3", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Vector3ui&& val, TypeTag) - { - state.PushInstance("Vector3", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Vector3i&& val, TypeTag) - { - state.PushInstance("Vector3", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::Entity* ptr, TypeTag) - { - state.PushInstance("Entity", ptr); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::Application* ptr, TypeTag) - { - state.PushInstance("Application", ptr); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::EntityHandle&& handle, TypeTag) - { - state.PushInstance("Entity", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::NodeComponentHandle&& handle, TypeTag) - { - state.PushInstance("NodeComponent", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::VelocityComponentHandle&& handle, TypeTag) - { - state.PushInstance("VelocityComponent", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::World* ptr, TypeTag) - { - state.PushInstance("World", ptr); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::WorldHandle&& handle, TypeTag) - { - state.PushInstance("World", handle); - return 1; - } - -#ifndef NDK_SERVER - inline int LuaImplReplyVal(const LuaState& state, MaterialRef&& handle, TypeTag) - { - state.PushInstance("Material", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, ModelRef&& handle, TypeTag) - { - state.PushInstance("Model", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, const SoundBuffer* val, TypeTag) - { - state.PushInstance("SoundBuffer", val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, SoundBufferRef&& handle, TypeTag) - { - state.PushInstance("SoundBuffer", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, SpriteRef&& handle, TypeTag) - { - state.PushInstance("Sprite", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, TextureRef&& handle, TypeTag) - { - state.PushInstance("Texture", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::CameraComponentHandle&& handle, TypeTag) - { - state.PushInstance("CameraComponent", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::ConsoleHandle&& handle, TypeTag) - { - state.PushInstance("Console", handle); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& state, Ndk::GraphicsComponentHandle&& handle, TypeTag) - { - state.PushInstance("GraphicsComponent", handle); - return 1; - } -#endif - -} diff --git a/SDK/src/NDK/Application.cpp b/SDK/src/NDK/Application.cpp index cf6fcdbb5..b9a7047b4 100644 --- a/SDK/src/NDK/Application.cpp +++ b/SDK/src/NDK/Application.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #endif @@ -151,14 +150,7 @@ namespace Ndk else windowDimensions.MakeZero(); - Nz::LuaInstance& lua = overlay->lua; - overlay->console = info.canvas->Add(); - overlay->console->OnCommand.Connect([&lua](Ndk::Console* console, const Nz::String& command) - { - if (!lua.Execute(command)) - console->AddLine(lua.GetLastError(), Nz::Color::Red); - }); Console& consoleRef = *overlay->console; consoleRef.Resize({float(windowDimensions.x), windowDimensions.y / 4.f}); @@ -170,40 +162,6 @@ namespace Ndk consoleRef.AddLine(str); }); - lua.LoadLibraries(); - LuaAPI::RegisterClasses(lua); - - // Override "print" function to add a line in the console - lua.PushFunction([&consoleRef] (Nz::LuaState& state) - { - Nz::StringStream stream; - - unsigned int argCount = state.GetStackTop(); - state.GetGlobal("tostring"); - for (unsigned int i = 1; i <= argCount; ++i) - { - state.PushValue(-1); // tostring function - state.PushValue(i); // argument - state.Call(1, 1); - - std::size_t length; - const char* str = state.CheckString(-1, &length); - if (i > 1) - stream << '\t'; - - stream << Nz::String(str, length); - state.Pop(1); - } - - consoleRef.AddLine(stream); - return 0; - }); - lua.SetGlobal("print"); - - // Define a few base variables to allow our interface to interact with the application - lua.PushGlobal("Application", Ndk::Application::Instance()); - lua.PushGlobal("Console", consoleRef.CreateHandle()); - // Setup a few event callback to handle the console Nz::EventHandler& eventHandler = info.window->GetEventHandler(); diff --git a/SDK/src/NDK/Lua/LuaBinding.cpp b/SDK/src/NDK/Lua/LuaBinding.cpp deleted file mode 100644 index 4bca51e19..000000000 --- a/SDK/src/NDK/Lua/LuaBinding.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::LuaBinding - * \brief NDK class that represents the binding between the engine & the SDK with the Lua scripting - */ - - /*! - * \brief Binds modules to Lua - */ - - LuaBinding::LuaBinding() - { - core = LuaBinding_Base::BindCore(*this); - math = LuaBinding_Base::BindMath(*this); - network = LuaBinding_Base::BindNetwork(*this); - utility = LuaBinding_Base::BindUtility(*this); - - #ifndef NDK_SERVER - audio = LuaBinding_Base::BindAudio(*this); - renderer = LuaBinding_Base::BindRenderer(*this); - graphics = LuaBinding_Base::BindGraphics(*this); - platform = LuaBinding_Base::BindPlatform(*this); - #endif - - sdk = LuaBinding_Base::BindSDK(*this); - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the engine & SDK - */ - - void LuaBinding::RegisterClasses(Nz::LuaState& state) - { - core->Register(state); - math->Register(state); - network->Register(state); - sdk->Register(state); - utility->Register(state); - - #ifndef NDK_SERVER - audio->Register(state); - graphics->Register(state); - renderer->Register(state); - platform->Register(state); - #endif - - // ComponentType (fake enumeration to expose component indexes) - state.PushTable(0, m_componentBinding.size()); - { - for (const ComponentBinding& entry : m_componentBinding) - { - if (entry.name.IsEmpty()) - continue; - - state.PushField(entry.name, entry.index); - } - } - state.SetGlobal("ComponentType"); - } -} diff --git a/SDK/src/NDK/Lua/LuaBinding_Audio.cpp b/SDK/src/NDK/Lua/LuaBinding_Audio.cpp deleted file mode 100644 index df97a7d38..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_Audio.cpp +++ /dev/null @@ -1,198 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include -#include -#include - -namespace Ndk -{ - std::unique_ptr LuaBinding_Base::BindAudio(LuaBinding& binding) - { - return std::make_unique(binding); - } - - LuaBinding_Audio::LuaBinding_Audio(LuaBinding& binding) : - LuaBinding_Base(binding) - { - /*********************************** Nz::SoundEmitter **********************************/ - soundEmitter.Reset("SoundEmitter"); - { - soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping); - soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization); - - soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation); - soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration); - soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance); - soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch); - soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset); - soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition); - soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus); - soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity); - soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume); - - soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping); - soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized); - - soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause); - soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play); - - soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation); - soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance); - soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch); - soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition); - soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity); - soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume); - - soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop); - } - - /*********************************** Nz::Music **********************************/ - music.Reset("Music"); - { - music.Inherit(soundEmitter); - - music.BindDefaultConstructor(); - - //musicClass.SetMethod("Create", &Nz::Music::Create); - //musicClass.SetMethod("Destroy", &Nz::Music::Destroy); - - music.BindMethod("EnableLooping", &Nz::Music::EnableLooping); - - music.BindMethod("GetDuration", &Nz::Music::GetDuration); - music.BindMethod("GetFormat", &Nz::Music::GetFormat); - music.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset); - music.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount); - music.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate); - music.BindMethod("GetStatus", &Nz::Music::GetStatus); - - music.BindMethod("IsLooping", &Nz::Music::IsLooping); - - music.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::SoundStreamParams()); - - music.BindMethod("Pause", &Nz::Music::Pause); - music.BindMethod("Play", &Nz::Music::Play); - - music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset); - - music.BindMethod("Stop", &Nz::Music::Stop); - - // Manual - music.BindMethod("__tostring", [] (Nz::LuaState& lua, Nz::Music& instance, std::size_t /*argumentCount*/) -> int - { - Nz::StringStream ss("Music("); - ss << instance.GetFilePath().generic_u8string() << ')'; - - lua.PushString(ss); - return 1; - }); - } - - /*********************************** Nz::Sound **********************************/ - sound.Reset("Sound"); - { - sound.Inherit(soundEmitter); - - sound.BindDefaultConstructor(); - - sound.BindMethod("GetBuffer", &Nz::Sound::GetBuffer); - - sound.BindMethod("IsPlayable", &Nz::Sound::IsPlayable); - sound.BindMethod("IsPlaying", &Nz::Sound::IsPlaying); - - sound.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); - - sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); - - // Manual - sound.BindMethod("__tostring", [] (Nz::LuaState& lua, Nz::Sound& instance, std::size_t /*argumentCount*/) -> int - { - Nz::StringStream ss("Sound("); - if (const Nz::SoundBuffer* buffer = instance.GetBuffer()) - ss << buffer; - - ss << ')'; - - lua.PushString(ss); - return 1; - }); - } - - /*********************************** Nz::SoundBuffer **********************************/ - soundBuffer.Reset("SoundBuffer"); - { - soundBuffer.SetConstructor([] (Nz::LuaState& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount) - { - NazaraUnused(lua); - NazaraUnused(argumentCount); - - Nz::PlacementNew(instance, Nz::SoundBuffer::New()); - return true; - }); - - soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy); - - soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration); - soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat); - soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount); - soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate); - - soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid); - - soundBuffer.BindStaticMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams()); - - soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported); - - // Manual - soundBuffer.BindMethod("Create", [] (Nz::LuaState& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int - { - int index = 2; - Nz::AudioFormat format = lua.Check(&index); - unsigned int sampleCount = lua.Check(&index); - unsigned int sampleRate = lua.Check(&index); - - std::size_t bufferSize = 0; - const char* buffer = lua.CheckString(index, &bufferSize); - lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer"); - - lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast(buffer))); - return 1; - }); - - soundBuffer.BindMethod("GetSamples", [] (Nz::LuaState& 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::LuaState& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int - { - Nz::StringStream ss("SoundBuffer("); - if (instance->IsValid()) - { - std::filesystem::path filePath = instance->GetFilePath(); - if (!filePath.empty()) - ss << "File: " << filePath.generic_u8string() << ", "; - - ss << "Duration: " << instance->GetDuration() / 1000.f << "s"; - } - ss << ')'; - - lua.PushString(ss); - return 1; - }); - } - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Audio classes - */ - void LuaBinding_Audio::Register(Nz::LuaState& state) - { - music.Register(state); - sound.Register(state); - soundBuffer.Register(state); - soundEmitter.Register(state); - } -} diff --git a/SDK/src/NDK/Lua/LuaBinding_Base.cpp b/SDK/src/NDK/Lua/LuaBinding_Base.cpp deleted file mode 100644 index b9bd44c57..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_Base.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include - -namespace Ndk -{ - LuaBinding_Base::LuaBinding_Base(LuaBinding& binding) : - m_binding(binding) - { - } - - LuaBinding_Base::~LuaBinding_Base() = default; -} diff --git a/SDK/src/NDK/Lua/LuaBinding_Core.cpp b/SDK/src/NDK/Lua/LuaBinding_Core.cpp deleted file mode 100644 index 49a7642f4..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_Core.cpp +++ /dev/null @@ -1,279 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include -#include -#include - -namespace Ndk -{ - std::unique_ptr LuaBinding_Base::BindCore(LuaBinding& binding) - { - return std::make_unique(binding); - } - - LuaBinding_Core::LuaBinding_Core(LuaBinding& binding) : - LuaBinding_Base(binding) - { - /*********************************** Nz::Stream ***********************************/ - stream.Reset("Stream"); - { - 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); - - stream.BindMethod("Read", [] (Nz::LuaState& 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 = instance.Read(buffer.get(), length); - - lua.PushString(Nz::String(buffer.get(), readLength)); - return 1; - }); - - stream.BindMethod("Write", [] (Nz::LuaState& 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 (instance.IsTextModeEnabled()) - lua.Push(instance.Write(Nz::String(buffer, bufferSize))); - else - lua.Push(instance.Write(buffer, bufferSize)); - return 1; - }); - } - - /*********************************** Nz::Clock **********************************/ - clock.Reset("Clock"); - { - clock.SetConstructor([] (Nz::LuaState& lua, Nz::Clock* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 2U); - - int argIndex = 2; - switch (argCount) - { - case 0: - Nz::PlacementNew(instance); - return true; - - case 1: - { - Nz::Int64 startingValue = lua.Check(&argIndex, 0); - - Nz::PlacementNew(instance, startingValue); - return true; - } - - case 2: - { - Nz::Int64 startingValue = lua.Check(&argIndex, 0); - bool paused = lua.Check(&argIndex, false); - - Nz::PlacementNew(instance, startingValue, paused); - return true; - } - } - - lua.Error("No matching overload for Clock constructor"); - return false; - }); - - 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 - clock.BindMethod("__tostring", [] (Nz::LuaState& 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(ss); - return 1; - }); - } - - /*********************************** Nz::File ***********************************/ - file.Reset("File"); - { - file.Inherit(stream); - - file.SetConstructor([] (Nz::LuaState& lua, Nz::File* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 1U); - - int argIndex = 2; - switch (argCount) - { - case 0: - Nz::PlacementNew(instance); - return true; - - case 1: - { - std::string filePath = lua.Check(&argIndex); - - Nz::PlacementNew(instance, filePath); - return true; - } - - case 2: - { - std::string filePath = lua.Check(&argIndex); - Nz::UInt32 openMode = lua.Check(&argIndex); - - Nz::PlacementNew(instance, filePath, openMode); - return true; - } - } - - lua.Error("No matching overload for File constructor"); - return false; - }); - - 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("GetFileName", &Nz::File::GetFileName); - file.BindMethod("IsOpen", &Nz::File::IsOpen); - - // Manual - file.BindMethod("Open", [] (Nz::LuaState& lua, Nz::File& instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 2U); - - int argIndex = 2; - switch (argCount) - { - case 0: - case 1: - return lua.Push(instance.Open(lua.Check(&argIndex, Nz::OpenMode_NotOpen))); - - case 2: - { - std::string filePath = lua.Check(&argIndex); - Nz::UInt32 openMode = lua.Check(&argIndex, Nz::OpenMode_NotOpen); - return lua.Push(instance.Open(filePath, openMode)); - } - } - - lua.Error("No matching overload for method Open"); - return 0; - }); - - file.BindMethod("SetCursorPos", [] (Nz::LuaState& lua, Nz::File& instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 2U); - - int argIndex = 2; - switch (argCount) - { - case 1: - 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(instance.SetCursorPos(curPos, offset)); - } - } - - lua.Error("No matching overload for method SetCursorPos"); - return 0; - }); - - file.BindMethod("__tostring", [] (Nz::LuaState& lua, Nz::File& instance, std::size_t /*argumentCount*/) -> int { - Nz::StringStream ss("File("); - if (instance.IsOpen()) - ss << "Path: " << instance.GetPath().generic_u8string(); - - ss << ')'; - - lua.PushString(ss); - return 1; - }); - } - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Core classes - */ - void LuaBinding_Core::Register(Nz::LuaState& state) - { - // Classes - clock.Register(state); - file.Register(state); - stream.Register(state); - - // Enums - - // Nz::CursorPosition - static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 3); - { - state.PushField("AtBegin", Nz::CursorPosition_AtBegin); - state.PushField("AtCurrent", Nz::CursorPosition_AtCurrent); - state.PushField("AtEnd", Nz::CursorPosition_AtEnd); - } - state.SetGlobal("CursorPosition"); - - // Nz::HashType - static_assert(Nz::HashType_Max + 1 == 10, "Nz::HashType has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 10); - { - state.PushField("CRC32", Nz::HashType_CRC32); - state.PushField("CRC64", Nz::HashType_CRC64); - state.PushField("Fletcher16", Nz::HashType_Fletcher16); - state.PushField("MD5", Nz::HashType_MD5); - state.PushField("SHA1", Nz::HashType_SHA1); - state.PushField("SHA224", Nz::HashType_SHA224); - state.PushField("SHA256", Nz::HashType_SHA256); - state.PushField("SHA384", Nz::HashType_SHA384); - state.PushField("SHA512", Nz::HashType_SHA512); - state.PushField("Whirlpool", Nz::HashType_Whirlpool); - } - state.SetGlobal("HashType"); - - // Nz::OpenMode - static_assert(Nz::OpenMode_Max + 1 == 8, "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding"); - state.PushTable(0, Nz::OpenMode_Max + 1); - { - state.PushField("Append", Nz::OpenMode_Append); - state.PushField("NotOpen", Nz::OpenMode_NotOpen); - state.PushField("Lock", Nz::OpenMode_Lock); - state.PushField("ReadOnly", Nz::OpenMode_ReadOnly); - state.PushField("ReadWrite", Nz::OpenMode_ReadWrite); - state.PushField("Text", Nz::OpenMode_Text); - state.PushField("Truncate", Nz::OpenMode_Truncate); - state.PushField("WriteOnly", Nz::OpenMode_WriteOnly); - } - state.SetGlobal("OpenMode"); - } -} diff --git a/SDK/src/NDK/Lua/LuaBinding_Graphics.cpp b/SDK/src/NDK/Lua/LuaBinding_Graphics.cpp deleted file mode 100644 index 5ed660089..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_Graphics.cpp +++ /dev/null @@ -1,498 +0,0 @@ -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - std::unique_ptr LuaBinding_Base::BindGraphics(LuaBinding& binding) - { - return std::make_unique(binding); - } - - LuaBinding_Graphics::LuaBinding_Graphics(LuaBinding& binding) : - LuaBinding_Base(binding) - { - /*********************************** Nz::AbstractViewer ***********************************/ - abstractViewer.Reset("AbstractViewer"); - { - abstractViewer.BindMethod("GetAspectRatio", &Nz::AbstractViewer::GetAspectRatio); - abstractViewer.BindMethod("GetEyePosition", &Nz::AbstractViewer::GetEyePosition); - abstractViewer.BindMethod("GetForward", &Nz::AbstractViewer::GetForward); - //abstractViewer.BindMethod("GetFrustum", &Nz::AbstractViewer::GetFrustum); - abstractViewer.BindMethod("GetProjectionMatrix", &Nz::AbstractViewer::GetProjectionMatrix); - //abstractViewer.BindMethod("GetTarget", &Nz::AbstractViewer::GetTarget); - abstractViewer.BindMethod("GetViewMatrix", &Nz::AbstractViewer::GetViewMatrix); - abstractViewer.BindMethod("GetViewport", &Nz::AbstractViewer::GetViewport); - abstractViewer.BindMethod("GetZFar", &Nz::AbstractViewer::GetZFar); - abstractViewer.BindMethod("GetZNear", &Nz::AbstractViewer::GetZNear); - } - - /*********************************** Nz::InstancedRenderable ***********************************/ - instancedRenderable.Reset("InstancedRenderable"); - { - instancedRenderable.BindMethod("GetMaterial", [] (Nz::LuaState& lua, Nz::InstancedRenderable* instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 2U); - switch (argCount) - { - case 0: - case 1: - { - int argIndex = 2; - std::size_t matIndex(lua.Check(&argIndex, 0)); - - return lua.Push(instance->GetMaterial(matIndex)); - } - - case 2: - { - int argIndex = 2; - std::size_t skinIndex(lua.Check(&argIndex)); - std::size_t matIndex(lua.Check(&argIndex)); - - return lua.Push(instance->GetMaterial(skinIndex, matIndex)); - } - } - - lua.Error("No matching overload for method GetMaterial"); - return 0; - }); - - instancedRenderable.BindMethod("GetMaterialCount", &Nz::InstancedRenderable::GetMaterialCount); - instancedRenderable.BindMethod("GetSkin", &Nz::InstancedRenderable::GetSkin); - instancedRenderable.BindMethod("GetSkinCount", &Nz::InstancedRenderable::GetSkinCount); - - instancedRenderable.BindMethod("SetSkin", &Nz::InstancedRenderable::SetSkin); - instancedRenderable.BindMethod("SetSkinCount", &Nz::InstancedRenderable::SetSkinCount); - } - - /*********************************** Nz::Material ***********************************/ - material.Reset("Material"); - { - material.SetConstructor([] (Nz::LuaState& lua, Nz::MaterialRef* instance, std::size_t argumentCount) - { - switch (argumentCount) - { - case 0: - Nz::PlacementNew(instance, Nz::Material::New()); - return true; - - case 1: - { - int argIndex = 1; - if (lua.IsOfType(argIndex, "MaterialPipeline")) - { - Nz::PlacementNew(instance, Nz::Material::New(*static_cast(lua.ToUserdata(argIndex)))); - return true; - } - else if (lua.IsOfType(argIndex, "Material")) - { - Nz::PlacementNew(instance, Nz::Material::New(**static_cast(lua.ToUserdata(argIndex)))); - return true; - } - else - { - Nz::PlacementNew(instance, Nz::Material::New(lua.Check(&argIndex))); - return true; - } - } - } - - lua.Error("No matching overload for constructor"); - return false; - }); - - material.BindMethod("Configure", [] (Nz::LuaState& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "MaterialPipeline")) - { - instance->Configure(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - { - 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("EnableReflectionMapping", &Nz::Material::EnableReflectionMapping); - 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("GetReflectionMode", &Nz::Material::GetReflectionMode); - //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("IsReflectionMappingEnabled", &Nz::Material::IsReflectionMappingEnabled); - 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("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("SetReflectionMode", &Nz::Material::SetReflectionMode); - 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.BindStaticMethod("LoadFromFile", &Nz::Material::LoadFromFile, Nz::MaterialParams()); - - material.BindMethod("SetAlphaMap", [] (Nz::LuaState& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) - { - instance->SetAlphaMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetAlphaMap(lua.Check(&argIndex))); - }); - - material.BindMethod("SetDiffuseMap", [] (Nz::LuaState& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) - { - instance->SetDiffuseMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetDiffuseMap(lua.Check(&argIndex))); - }); - - material.BindMethod("SetEmissiveMap", [] (Nz::LuaState& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) - { - instance->SetEmissiveMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetEmissiveMap(lua.Check(&argIndex))); - }); - - material.BindMethod("SetHeightMap", [] (Nz::LuaState& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) - { - instance->SetHeightMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetHeightMap(lua.Check(&argIndex))); - }); - - material.BindMethod("SetNormalMap", [] (Nz::LuaState& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) - { - instance->SetNormalMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetNormalMap(lua.Check(&argIndex))); - }); - - material.BindMethod("SetShader", [] (Nz::LuaState& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "UberShader")) - { - instance->SetShader(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetShader(lua.Check(&argIndex))); - }); - - material.BindMethod("SetSpecularMap", [] (Nz::LuaState& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) - { - instance->SetSpecularMap(*static_cast(lua.ToUserdata(argIndex))); - return 0; - } - else - return lua.Push(instance->SetSpecularMap(lua.Check(&argIndex))); - }); - } - - /*********************************** Nz::Model ***********************************/ - model.Reset("Model"); - { - model.Inherit(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef* - { - return reinterpret_cast(modelRef); //TODO: Make a ObjectRefCast - }); - - model.SetConstructor([] (Nz::LuaState& /*lua*/, Nz::ModelRef* instance, std::size_t /*argumentCount*/) - { - Nz::PlacementNew(instance, Nz::Model::New()); - return true; - }); - - //modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh); - - model.BindMethod("IsAnimated", &Nz::Model::IsAnimated); - - model.BindMethod("SetMaterial", [] (Nz::LuaState& lua, Nz::Model* instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 3U); - switch (argCount) - { - case 2: - { - int argIndex = 2; - if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - { - std::size_t matIndex(lua.Check(&argIndex)); - Nz::MaterialRef mat(lua.Check(&argIndex)); - - instance->SetMaterial(matIndex, std::move(mat)); - return 0; - } - else if (lua.IsOfType(argIndex, Nz::LuaType_String)) - { - std::string subMesh(lua.Check(&argIndex)); - Nz::MaterialRef mat(lua.Check(&argIndex)); - - instance->SetMaterial(subMesh, std::move(mat)); - return 0; - } - - break; - } - - case 3: - { - int argIndex = 2; - if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - { - std::size_t skinIndex(lua.Check(&argIndex)); - std::size_t matIndex(lua.Check(&argIndex)); - Nz::MaterialRef mat(lua.Check(&argIndex)); - - instance->SetMaterial(skinIndex, matIndex, std::move(mat)); - return 0; - } - else if (lua.IsOfType(argIndex, Nz::LuaType_String)) - { - std::size_t skinIndex(lua.Check(&argIndex)); - std::string subMesh(lua.Check(&argIndex)); - Nz::MaterialRef materialRef(lua.Check(&argIndex)); - - instance->SetMaterial(skinIndex, subMesh, std::move(materialRef)); - return 0; - } - - break; - } - } - - lua.Error("No matching overload for method SetMaterial"); - return 0; - }); - - //modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh); - //modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence); - - model.BindStaticMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters()); - } - - /*********************************** Nz::Sprite ***********************************/ - sprite.Reset("Sprite"); - { - sprite.Inherit(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef* - { - return reinterpret_cast(spriteRef); //TODO: Make a ObjectRefCast - }); - - sprite.SetConstructor([] (Nz::LuaState& /*lua*/, Nz::SpriteRef* instance, std::size_t /*argumentCount*/) - { - Nz::PlacementNew(instance, Nz::Sprite::New()); - return true; - }); - - sprite.BindMethod("GetColor", &Nz::Sprite::GetColor); - sprite.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor); - sprite.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin); - sprite.BindMethod("GetSize", &Nz::Sprite::GetSize); - sprite.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords); - - sprite.BindMethod("SetColor", &Nz::Sprite::SetColor); - sprite.BindMethod("SetCornerColor", &Nz::Sprite::SetCornerColor); - sprite.BindMethod("SetDefaultMaterial", &Nz::Sprite::SetDefaultMaterial); - sprite.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin); - sprite.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize); - sprite.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords); - sprite.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect); - - sprite.BindMethod("SetMaterial", [] (Nz::LuaState& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Material")) - { - bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); - - instance->SetMaterial(*static_cast(lua.ToUserdata(argIndex)), resizeSprite); - } - else if (lua.IsOfType(argIndex, Nz::LuaType_String)) - { - bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); - - instance->SetMaterial(lua.ToString(argIndex), resizeSprite); - } - else if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - { - std::size_t skinIndex(lua.Check(&argIndex)); - bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); - - if (lua.IsOfType(argIndex, "Material")) - instance->SetMaterial(skinIndex, *static_cast(lua.ToUserdata(argIndex)), resizeSprite); - else - instance->SetMaterial(skinIndex, lua.Check(&argIndex), resizeSprite); - } - - return 0; - }); - - sprite.BindMethod("SetTexture", [] (Nz::LuaState& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "Texture")) - { - bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); - - instance->SetTexture(*static_cast(lua.ToUserdata(argIndex)), resizeSprite); - } - else if (lua.IsOfType(argIndex, Nz::LuaType_String)) - { - bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); - - instance->SetTexture(lua.ToString(argIndex), resizeSprite); - } - else if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - { - std::size_t skinIndex(lua.Check(&argIndex)); - bool resizeSprite = lua.CheckBoolean(argIndex + 1, true); - - if (lua.IsOfType(argIndex, "Texture")) - instance->SetTexture(skinIndex, *static_cast(lua.ToUserdata(argIndex)), resizeSprite); - else - instance->SetTexture(skinIndex, lua.Check(&argIndex), resizeSprite); - } - - return 0; - }); - } - - /*********************************** Nz::SpriteLibrary ***********************************/ - spriteLibrary.Reset("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); - } - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Graphics classes - */ - - void LuaBinding_Graphics::Register(Nz::LuaState& state) - { - abstractViewer.Register(state); - instancedRenderable.Register(state); - material.Register(state); - model.Register(state); - sprite.Register(state); - spriteLibrary.Register(state); - - // Nz::ReflectionMode - static_assert(Nz::ReflectionMode_Max + 1 == 3, "Nz::ReflectionMode has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 3); - { - state.PushField("Probe", Nz::ReflectionMode_Probe); - state.PushField("RealTime", Nz::ReflectionMode_RealTime); - state.PushField("Skybox", Nz::ReflectionMode_Skybox); - } - state.SetGlobal("ReflectionMode"); - } -} diff --git a/SDK/src/NDK/Lua/LuaBinding_Math.cpp b/SDK/src/NDK/Lua/LuaBinding_Math.cpp deleted file mode 100644 index 15deebfab..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_Math.cpp +++ /dev/null @@ -1,986 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include -#include -#include -#include - -namespace Ndk -{ - std::unique_ptr LuaBinding_Base::BindMath(LuaBinding& binding) - { - return std::make_unique(binding); - } - - LuaBinding_Math::LuaBinding_Math(LuaBinding& binding) : - LuaBinding_Base(binding) - { - /*********************************** Nz::EulerAngles **********************************/ - eulerAngles.Reset("EulerAngles"); - { - eulerAngles.SetConstructor([] (Nz::LuaState& lua, Nz::EulerAnglesd* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 3U); - - switch (argCount) - { - case 0: - Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero()); - return true; - - case 1: - Nz::PlacementNew(instance, *static_cast(lua.CheckUserdata(1, "EulerAngles"))); - return true; - - case 3: - Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3)); - return true; - } - - lua.Error("No matching overload for EulerAngles constructor"); - return false; - }); - - eulerAngles.BindMethod("Normalize", &Nz::EulerAnglesd::Normalize); - eulerAngles.BindMethod("ToQuaternion", &Nz::EulerAnglesd::ToQuaternion); - - eulerAngles.BindMethod("__tostring", &Nz::EulerAnglesd::ToString); - - eulerAngles.SetGetter([] (Nz::LuaState& 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::LuaState& 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.Reset("Matrix4"); - { - matrix4d.SetConstructor([] (Nz::LuaState& lua, Nz::Matrix4d* matrix, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 3U); - - switch (argCount) - { - case 0: - Nz::PlacementNew(matrix, Nz::Matrix4d::Zero()); - return true; - - case 1: - if (lua.IsOfType(1, "Matrix4")) - Nz::PlacementNew(matrix, *static_cast(lua.ToUserdata(1))); - break; - - case 16: - { - double values[16]; - for (int i = 0; i < 16; ++i) - values[i] = lua.CheckNumber(i); - - Nz::PlacementNew(matrix, values); - - return true; - } - } - - lua.Error("No matching overload for constructor"); - return false; - }); - - matrix4d.BindMethod("ApplyRotation", &Nz::Matrix4d::ApplyRotation); - matrix4d.BindMethod("ApplyScale", &Nz::Matrix4d::ApplyScale); - matrix4d.BindMethod("ApplyTranslation", &Nz::Matrix4d::ApplyTranslation); - - matrix4d.BindMethod("Concatenate", &Nz::Matrix4d::Concatenate); - matrix4d.BindMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine); - - //matrix4d.BindMethod("GetColumn", &Nz::Matrix4d::GetColumn); - matrix4d.BindMethod("GetDeterminant", &Nz::Matrix4d::GetDeterminant); - matrix4d.BindMethod("GetDeterminantAffine", &Nz::Matrix4d::GetDeterminantAffine); - - matrix4d.BindMethod("GetInverse", [] (Nz::LuaState& 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::LuaState& 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::LuaState& 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::LuaState& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int - { - bool succeeded; - instance.Inverse(&succeeded); - - return lua.Push(succeeded); - }); - - matrix4d.BindMethod("InverseAffine", [] (Nz::LuaState& 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::LuaState& 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 = *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 = Nz::Matrix4d(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::LuaState& 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::LuaState& 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::LuaState& 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.Reset("Rect"); - { - rect.SetConstructor([] (Nz::LuaState& lua, Nz::Rectd* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 4U); - - switch (argCount) - { - case 0: - case 4: - PlacementNew(instance, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0), lua.CheckNumber(4, 0.0)); - return true; - - case 1: - { - if (lua.IsOfType(1, "Rect")) - PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else if (lua.IsOfType(1, Nz::LuaType_Table)) - { - // TODO => Faire sans avoir à mettre de nom dans la table et prendre les éléments un à un pour créer le Rectd - PlacementNew(instance, lua.CheckField("x", 1), - lua.CheckField("y", 1), - lua.CheckField("width", 1), - lua.CheckField("height", 1)); - } - else if (lua.IsOfType(1, "Vector2")) - PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else - break; - - return true; - } - - case 2: - { - if (lua.IsOfType(1, Nz::LuaType_Number) && lua.IsOfType(2, Nz::LuaType_Number)) - PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2)); - else if (lua.IsOfType(1, "Vector2") && lua.IsOfType(2, "Vector2")) - PlacementNew(instance, *static_cast(lua.ToUserdata(1)), *static_cast(lua.ToUserdata(2))); - else - break; - - return true; - } - } - - lua.Error("No matching overload for Rect constructor"); - return false; - }); - - rect.BindMethod("__tostring", &Nz::Rectd::ToString); - - rect.SetGetter([] (Nz::LuaState& 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::LuaState& 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.Reset("Quaternion"); - { - quaternion.SetConstructor([] (Nz::LuaState& lua, Nz::Quaterniond* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 4U); - - switch (argCount) - { - case 0: - Nz::PlacementNew(instance, Nz::Quaterniond::Zero()); - return true; - - case 1: - { - if (lua.IsOfType(1, "EulerAngles")) - Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else if (lua.IsOfType(1, "Quaternion")) - Nz::PlacementNew(instance, *static_cast(lua.ToUserdata(1))); - else - break; - - return true; - } - - case 2: - Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast(lua.CheckUserdata(2, "Vector3"))); - return true; - - case 4: - Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4)); - return true; - - default: - break; - } - - lua.Error("No matching overload for Quaternion constructor"); - return false; - }); - - quaternion.BindMethod("ComputeW", &Nz::Quaterniond::ComputeW); - quaternion.BindMethod("Conjugate", &Nz::Quaterniond::Conjugate); - quaternion.BindMethod("DotProduct", &Nz::Quaterniond::DotProduct); - quaternion.BindMethod("GetConjugate", &Nz::Quaterniond::GetConjugate); - quaternion.BindMethod("GetInverse", &Nz::Quaterniond::GetInverse); - - quaternion.BindMethod("Inverse", &Nz::Quaterniond::Inverse); - quaternion.BindMethod("Magnitude", &Nz::Quaterniond::Magnitude); - - quaternion.BindMethod("SquaredMagnitude", &Nz::Quaterniond::SquaredMagnitude); - quaternion.BindMethod("ToEulerAngles", &Nz::Quaterniond::ToEulerAngles); - - quaternion.BindMethod("__tostring", &Nz::Quaterniond::ToString); - - quaternion.BindStaticMethod("Lerp", &Nz::Quaterniond::Lerp); - quaternion.BindStaticMethod("RotationBetween", &Nz::Quaterniond::RotationBetween); - quaternion.BindStaticMethod("Slerp", &Nz::Quaterniond::Slerp); - - quaternion.BindMethod("GetNormal", [] (Nz::LuaState& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int - { - double length; - - lua.Push(instance.GetNormal(&length)); - lua.Push(length); - - return 2; - }); - - quaternion.BindMethod("Normalize", [] (Nz::LuaState& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int - { - double length; - - instance.Normalize(&length); - lua.Push(1); //< instance - lua.Push(length); - - return 2; - }); - - quaternion.BindStaticMethod("Normalize", [] (Nz::LuaState& state) -> int - { - int argIndex = 1; - Nz::Quaterniond quat = state.Check(&argIndex); - - double length; - - state.Push(Nz::Quaterniond::Normalize(quat, &length)); - state.Push(length); - - return 2; - }); - - quaternion.SetGetter([] (Nz::LuaState& 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::LuaState& 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.Reset("Vector2"); - { - vector2d.SetConstructor([] (Nz::LuaState& 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::LuaState& 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::LuaState& 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.Reset("Vector3"); - { - vector3d.SetConstructor([] (Nz::LuaState& 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::LuaState& 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::LuaState& 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_Math::Register(Nz::LuaState& state) - { - eulerAngles.Register(state); - matrix4d.Register(state); - quaternion.Register(state); - rect.Register(state); - vector2d.Register(state); - vector3d.Register(state); - - quaternion.PushGlobalTable(state); - { - state.PushField("Identity", Nz::Quaterniond::Identity()); - state.PushField("Zero", Nz::Quaterniond::Zero()); - } - state.Pop(); - } -} diff --git a/SDK/src/NDK/Lua/LuaBinding_Network.cpp b/SDK/src/NDK/Lua/LuaBinding_Network.cpp deleted file mode 100644 index f3f82264a..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_Network.cpp +++ /dev/null @@ -1,314 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include -#include - -namespace Ndk -{ - std::unique_ptr LuaBinding_Base::BindNetwork(LuaBinding& binding) - { - return std::make_unique(binding); - } - - LuaBinding_Network::LuaBinding_Network(LuaBinding& binding) : - LuaBinding_Base(binding) - { - /*********************************** Nz::AbstractSocket **********************************/ - abstractSocket.Reset("AbstractSocket"); - { - 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 **********************************/ - ipAddress.Reset("IpAddress"); - { - ipAddress.SetConstructor([] (Nz::LuaState& lua, Nz::IpAddress* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 9U); - - int argIndex = 1; - switch (argCount) - { - case 0: - Nz::PlacementNew(instance); - return true; - - case 1: - Nz::PlacementNew(instance, lua.CheckString(argIndex)); - return true; - - case 4: - case 5: - { - Nz::UInt8 a = lua.Check(&argIndex); - Nz::UInt8 b = lua.Check(&argIndex); - Nz::UInt8 c = lua.Check(&argIndex); - Nz::UInt8 d = lua.Check(&argIndex); - Nz::UInt16 port = lua.Check(&argIndex, 0); - - Nz::PlacementNew(instance, a, b, c, d, port); - return true; - } - - case 8: - case 9: - { - Nz::UInt16 a = lua.Check(&argIndex); - Nz::UInt16 b = lua.Check(&argIndex); - Nz::UInt16 c = lua.Check(&argIndex); - Nz::UInt16 d = lua.Check(&argIndex); - Nz::UInt16 e = lua.Check(&argIndex); - Nz::UInt16 f = lua.Check(&argIndex); - Nz::UInt16 g = lua.Check(&argIndex); - Nz::UInt16 h = lua.Check(&argIndex); - Nz::UInt16 port = lua.Check(&argIndex, 0); - - Nz::PlacementNew(instance, a, b, c, d, e, f, g, h, port); - return true; - } - } - - lua.Error("No matching overload for constructor"); - return false; - }); - - 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); - - ipAddress.BindStaticMethod("ResolveAddress", [] (Nz::LuaState& state) -> int - { - Nz::String service; - Nz::ResolveError error = Nz::ResolveError_Unknown; - - int argIndex = 2; - Nz::String hostName = Nz::IpAddress::ResolveAddress(state.Check(&argIndex), &service, &error); - - if (error == Nz::ResolveError_NoError) - { - state.Push(hostName); - state.Push(service); - return 2; - } - else - { - state.PushBoolean(false); - state.Push(error); - return 2; - } - }); - - ipAddress.BindStaticMethod("ResolveHostname", [] (Nz::LuaState& state) -> int - { - Nz::ResolveError error = Nz::ResolveError_Unknown; - - int argIndex = 2; - Nz::NetProtocol protocol = state.Check(&argIndex); - Nz::String hostname = state.Check(&argIndex); - Nz::String service = state.Check(&argIndex, "http"); - - std::vector addresses = Nz::IpAddress::ResolveHostname(protocol, hostname, service, &error); - if (error == Nz::ResolveError_NoError) - { - int index = 1; - state.PushTable(addresses.size()); - for (Nz::HostnameInfo& info : addresses) - { - state.PushInteger(index++); - state.PushTable(0, 4); - state.PushField("Address", std::move(info.address)); - state.PushField("CanonicalName", std::move(info.canonicalName)); - state.PushField("Protocol", std::move(info.protocol)); - state.PushField("SocketType", std::move(info.socketType)); - state.SetTable(); - } - - return 1; - } - else - { - state.PushBoolean(false); - state.Push(error); - return 2; - } - }); - } - - udpSocket.Reset("UdpSocket"); - { - udpSocket.Inherit(abstractSocket); - - udpSocket.BindDefaultConstructor(); - - udpSocket.BindMethod("Create", &Nz::UdpSocket::Create); - udpSocket.BindMethod("EnableBroadcasting", &Nz::UdpSocket::EnableBroadcasting); - udpSocket.BindMethod("GetBoundAddress", &Nz::UdpSocket::GetBoundAddress); - udpSocket.BindMethod("GetBoundPort", &Nz::UdpSocket::GetBoundPort); - udpSocket.BindMethod("IsBroadcastingEnabled", &Nz::UdpSocket::IsBroadcastingEnabled); - udpSocket.BindMethod("QueryMaxDatagramSize", &Nz::UdpSocket::QueryMaxDatagramSize); - - udpSocket.BindMethod("Bind", [](Nz::LuaState& lua, Nz::UdpSocket& socket, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - if (lua.IsOfType(argIndex, "IpAddress")) - return lua.Push(socket.Bind(*static_cast(lua.ToUserdata(argIndex)))); - else - return lua.Push(socket.Bind(lua.Check(&argIndex))); - }); - - udpSocket.BindMethod("Receive", [](Nz::LuaState& lua, Nz::UdpSocket& socket, std::size_t /*argumentCount*/) -> int - { - Nz::IpAddress from; - - std::array buffer; - std::size_t received; - if (socket.Receive(buffer.data(), buffer.size(), &from, &received)) - { - lua.PushBoolean(true); - lua.PushString(from.ToString()); - lua.PushString(buffer.data(), received); - return 3; - } - - lua.PushBoolean(false); - return 1; - }); - - udpSocket.BindMethod("Send", [](Nz::LuaState& lua, Nz::UdpSocket& socket, std::size_t /*argumentCount*/) -> int - { - int argIndex = 2; - Nz::String to = lua.Check(&argIndex); - - std::size_t bufferLength; - const char* buffer = lua.CheckString(argIndex, &bufferLength); - - std::size_t sent; - bool ret; - if ((ret = socket.Send(Nz::IpAddress(to), buffer, bufferLength, &sent)) != true) - sent = 0; - - return lua.Push(std::make_pair(ret, sent)); - }); - } - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Network classes - */ - void LuaBinding_Network::Register(Nz::LuaState& state) - { - // Classes - abstractSocket.Register(state); - ipAddress.Register(state); - udpSocket.Register(state); - - // Enums - - // Nz::NetProtocol - static_assert(Nz::NetProtocol_Max + 1 == 4, "Nz::NetProtocol has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 4); - { - state.PushField("Any", Nz::NetProtocol_Any); - state.PushField("IPv4", Nz::NetProtocol_IPv4); - state.PushField("IPv6", Nz::NetProtocol_IPv6); - state.PushField("Unknown", Nz::NetProtocol_Unknown); - } - state.SetGlobal("NetProtocol"); - - // Nz::PacketPriority - static_assert(Nz::PacketPriority_Max + 1 == 4, "Nz::PacketPriority has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 6); - { - state.PushField("High", Nz::PacketPriority_High); - state.PushField("Highest", Nz::PacketPriority_Highest); - state.PushField("Immediate", Nz::PacketPriority_Immediate); - state.PushField("Medium", Nz::PacketPriority_Medium); - state.PushField("Low", Nz::PacketPriority_Low); - state.PushField("Lowest", Nz::PacketPriority_Lowest); - } - state.SetGlobal("PacketPriority"); - - // Nz::PacketReliability - static_assert(Nz::PacketReliability_Max + 1 == 3, "Nz::PacketReliability has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 3); - { - state.PushField("Reliable", Nz::PacketReliability_Reliable); - state.PushField("ReliableOrdered", Nz::PacketReliability_ReliableOrdered); - state.PushField("Unreliable", Nz::PacketReliability_Unreliable); - } - state.SetGlobal("PacketReliability"); - - // Nz::ResolveError - static_assert(Nz::ResolveError_Max + 1 == 9, "Nz::ResolveError has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 9); - { - state.PushField("Internal", Nz::ResolveError_Internal); - state.PushField("ResourceError", Nz::ResolveError_ResourceError); - state.PushField("NoError", Nz::ResolveError_NoError); - state.PushField("NonRecoverable", Nz::ResolveError_NonRecoverable); - state.PushField("NotFound", Nz::ResolveError_NotFound); - state.PushField("NotInitialized", Nz::ResolveError_NotInitialized); - state.PushField("ProtocolNotSupported", Nz::ResolveError_ProtocolNotSupported); - state.PushField("TemporaryFailure", Nz::ResolveError_TemporaryFailure); - state.PushField("Unknown", Nz::ResolveError_Unknown); - } - state.SetGlobal("ResolveError"); - - // Nz::SocketError - static_assert(Nz::SocketError_Max + 1 == 16, "Nz::SocketError has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 16); - { - state.PushField("AddressNotAvailable", Nz::SocketError_AddressNotAvailable); - state.PushField("ConnectionClosed", Nz::SocketError_ConnectionClosed); - state.PushField("ConnectionRefused", Nz::SocketError_ConnectionRefused); - state.PushField("DatagramSize", Nz::SocketError_DatagramSize); - state.PushField("Internal", Nz::SocketError_Internal); - state.PushField("Interrupted", Nz::SocketError_Interrupted); - state.PushField("Packet", Nz::SocketError_Packet); - state.PushField("NetworkError", Nz::SocketError_NetworkError); - state.PushField("NoError", Nz::SocketError_NoError); - state.PushField("NotInitialized", Nz::SocketError_NotInitialized); - state.PushField("NotSupported", Nz::SocketError_NotSupported); - state.PushField("ResolveError", Nz::SocketError_ResolveError); - state.PushField("ResourceError", Nz::SocketError_ResourceError); - state.PushField("TimedOut", Nz::SocketError_TimedOut); - state.PushField("Unknown", Nz::SocketError_Unknown); - state.PushField("UnreachableHost", Nz::SocketError_UnreachableHost); - } - state.SetGlobal("SocketError"); - - // Nz::SocketState - static_assert(Nz::SocketState_Max + 1 == 5, "Nz::SocketState has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 5); - { - state.PushField("Bound", Nz::SocketState_Bound); - state.PushField("Connecting", Nz::SocketState_Connecting); - state.PushField("Connected", Nz::SocketState_Connected); - state.PushField("NotConnected", Nz::SocketState_NotConnected); - state.PushField("Resolving", Nz::SocketState_Resolving); - } - state.SetGlobal("SocketState"); - - // Nz::SocketType - static_assert(Nz::SocketType_Max + 1 == 4, "Nz::SocketState has been updated but change was not reflected to Lua binding"); - state.PushTable(0, 4); - { - state.PushField("Raw", Nz::SocketType_Raw); - state.PushField("TCP", Nz::SocketType_TCP); - state.PushField("UDP", Nz::SocketType_UDP); - state.PushField("Unknown", Nz::SocketType_Unknown); - } - state.SetGlobal("SocketType"); - } -} diff --git a/SDK/src/NDK/Lua/LuaBinding_Platform.cpp b/SDK/src/NDK/Lua/LuaBinding_Platform.cpp deleted file mode 100644 index 2a2b02e7e..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_Platform.cpp +++ /dev/null @@ -1,133 +0,0 @@ -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - std::unique_ptr LuaBinding_Base::BindPlatform(LuaBinding& binding) - { - return std::make_unique(binding); - } - - LuaBinding_Platform::LuaBinding_Platform(LuaBinding& binding) : - LuaBinding_Base(binding) - { - /*********************************** Nz::Keyboard **********************************/ - keyboard.Reset("Keyboard"); - { - keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName); - keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed); - } - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Utility classes - */ - void LuaBinding_Platform::Register(Nz::LuaState& state) - { - keyboard.Register(state); - - keyboard.PushGlobalTable(state); - { - static_assert(Nz::Keyboard::Count == 121, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding"); - - state.PushField("Undefined", Nz::Keyboard::Undefined); - - // A-Z - for (std::size_t i = 0; i < 26; ++i) - state.PushField(Nz::String('A' + char(i)), Nz::Keyboard::A + i); - - // Numerical - for (std::size_t i = 0; i < 10; ++i) - { - state.PushField("Num" + Nz::String::Number(i), Nz::Keyboard::Num0 + i); - state.PushField("Numpad" + Nz::String::Number(i), Nz::Keyboard::Numpad0 + i); - } - - // F1-F15 - for (std::size_t i = 0; i < 15; ++i) - state.PushField('F' + Nz::String::Number(i+1), Nz::Keyboard::F1 + i); - - // And all the others... - state.PushField("Down", Nz::Keyboard::Down); - state.PushField("Left", Nz::Keyboard::Left); - state.PushField("Right", Nz::Keyboard::Right); - state.PushField("Up", Nz::Keyboard::Up); - - state.PushField("Add", Nz::Keyboard::Add); - state.PushField("Decimal", Nz::Keyboard::Decimal); - state.PushField("Divide", Nz::Keyboard::Divide); - state.PushField("Multiply", Nz::Keyboard::Multiply); - state.PushField("Subtract", Nz::Keyboard::Subtract); - - state.PushField("Backslash", Nz::Keyboard::Backslash); - state.PushField("Backspace", Nz::Keyboard::Backspace); - state.PushField("Clear", Nz::Keyboard::Clear); - state.PushField("Comma", Nz::Keyboard::Comma); - state.PushField("Dash", Nz::Keyboard::Dash); - state.PushField("Delete", Nz::Keyboard::Delete); - state.PushField("End", Nz::Keyboard::End); - state.PushField("Equal", Nz::Keyboard::Equal); - state.PushField("Escape", Nz::Keyboard::Escape); - state.PushField("Home", Nz::Keyboard::Home); - state.PushField("Insert", Nz::Keyboard::Insert); - state.PushField("LAlt", Nz::Keyboard::LAlt); - state.PushField("LBracket", Nz::Keyboard::LBracket); - state.PushField("LControl", Nz::Keyboard::LControl); - state.PushField("LShift", Nz::Keyboard::LShift); - state.PushField("LSystem", Nz::Keyboard::LSystem); - state.PushField("PageDown", Nz::Keyboard::PageDown); - state.PushField("PageUp", Nz::Keyboard::PageUp); - state.PushField("Pause", Nz::Keyboard::Pause); - state.PushField("Period", Nz::Keyboard::Period); - state.PushField("Print", Nz::Keyboard::Print); - state.PushField("PrintScreen", Nz::Keyboard::PrintScreen); - state.PushField("Quote", Nz::Keyboard::Quote); - state.PushField("RAlt", Nz::Keyboard::RAlt); - state.PushField("RBracket", Nz::Keyboard::RBracket); - state.PushField("RControl", Nz::Keyboard::RControl); - state.PushField("Return", Nz::Keyboard::Return); - state.PushField("RShift", Nz::Keyboard::RShift); - state.PushField("RSystem", Nz::Keyboard::RSystem); - state.PushField("Semicolon", Nz::Keyboard::Semicolon); - state.PushField("Slash", Nz::Keyboard::Slash); - state.PushField("Space", Nz::Keyboard::Space); - state.PushField("Tab", Nz::Keyboard::Tab); - state.PushField("Tilde", Nz::Keyboard::Tilde); - state.PushField("Browser_Back", Nz::Keyboard::Browser_Back); - state.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites); - state.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward); - state.PushField("Browser_Home", Nz::Keyboard::Browser_Home); - state.PushField("Browser_Refresh", Nz::Keyboard::Browser_Refresh); - state.PushField("Browser_Search", Nz::Keyboard::Browser_Search); - state.PushField("Browser_Stop", Nz::Keyboard::Browser_Stop); - state.PushField("Media_Next", Nz::Keyboard::Media_Next); - state.PushField("Media_Play", Nz::Keyboard::Media_Play); - state.PushField("Media_Previous", Nz::Keyboard::Media_Previous); - state.PushField("Media_Stop", Nz::Keyboard::Media_Stop); - state.PushField("Volume_Down", Nz::Keyboard::Volume_Down); - state.PushField("Volume_Mute", Nz::Keyboard::Volume_Mute); - state.PushField("Volume_Up", Nz::Keyboard::Volume_Up); - state.PushField("CapsLock", Nz::Keyboard::CapsLock); - state.PushField("NumLock", Nz::Keyboard::NumLock); - state.PushField("ScrollLock", Nz::Keyboard::ScrollLock); - } - state.Pop(); - - static_assert(Nz::WindowStyle_Max + 1 == 6, "Nz::WindowStyle has been updated but change was not reflected to Lua binding"); - state.PushTable(0, Nz::WindowStyle_Max + 1); - { - state.PushField("None", Nz::WindowStyle_None); - state.PushField("Fullscreen", Nz::WindowStyle_Fullscreen); - state.PushField("Closable", Nz::WindowStyle_Closable); - state.PushField("Resizable", Nz::WindowStyle_Resizable); - state.PushField("Titlebar", Nz::WindowStyle_Titlebar); - state.PushField("Threaded", Nz::WindowStyle_Threaded); - } - state.SetGlobal("WindowStyle"); - } -} diff --git a/SDK/src/NDK/Lua/LuaBinding_Renderer.cpp b/SDK/src/NDK/Lua/LuaBinding_Renderer.cpp deleted file mode 100644 index 8aacf2a1f..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_Renderer.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq, Arnaud Cadot -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include - -namespace Ndk -{ - std::unique_ptr LuaBinding_Base::BindRenderer(LuaBinding& binding) - { - return std::make_unique(binding); - } - - LuaBinding_Renderer::LuaBinding_Renderer(LuaBinding& binding) : - LuaBinding_Base(binding) - { - LuaBinding_Utility& utility = static_cast(*m_binding.utility); - - /*********************************** Nz::Texture ***********************************/ - texture.Reset("Texture"); - { - texture.Inherit(utility.abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef* - { - return reinterpret_cast(textureRef); //TODO: Make a ObjectRefCast - }); - - texture.SetConstructor([] (Nz::LuaState& /*lua*/, Nz::TextureRef* instance, std::size_t /*argumentCount*/) - { - Nz::PlacementNew(instance, Nz::Texture::New()); - return true; - }); - - texture.BindMethod("Create", &Nz::Texture::Create, static_cast(1), 1U); - texture.BindMethod("Destroy", &Nz::Texture::Destroy); - - //texture.BindMethod("Download", &Nz::Texture::Download); - - texture.BindMethod("EnableMipmapping", &Nz::Texture::EnableMipmapping); - texture.BindMethod("EnsureMipmapsUpdate", &Nz::Texture::EnsureMipmapsUpdate); - texture.BindMethod("HasMipmaps", &Nz::Texture::HasMipmaps); - texture.BindMethod("InvalidateMipmaps", &Nz::Texture::InvalidateMipmaps); - texture.BindMethod("IsValid", &Nz::Texture::IsValid); - - texture.BindMethod("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); - - texture.BindStaticMethod("LoadFromFile", &Nz::Texture::LoadFromFile, true, Nz::ImageParams()); - //TextureRef LoadFromImage(const Image& image, bool generateMipmaps = true); - //TextureRef LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true); - //TextureRef LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true); - - texture.BindStaticMethod("LoadArrayFromFile", &Nz::Texture::LoadArrayFromFile, Nz::Vector2ui(2, 2), true, Nz::ImageParams()); - //TextureRef LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); - //TextureRef LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); - //TextureRef LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2)); - - //TextureRef LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); - //TextureRef LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams()); - //TextureRef LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); - //TextureRef LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams()); - } - - /*********************************** Nz::TextureLibrary ***********************************/ - textureLibrary.Reset("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.Reset("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); - } - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Renderer classes - */ - void LuaBinding_Renderer::Register(Nz::LuaState& state) - { - texture.Register(state); - textureLibrary.Register(state); - textureManager.Register(state); - } -} diff --git a/SDK/src/NDK/Lua/LuaBinding_SDK.cpp b/SDK/src/NDK/Lua/LuaBinding_SDK.cpp deleted file mode 100644 index 805f7742d..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_SDK.cpp +++ /dev/null @@ -1,354 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq, Arnaud Cadot -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include -#include -#include - -#ifndef NDK_SERVER -#include -#endif - -namespace Ndk -{ - std::unique_ptr LuaBinding_Base::BindSDK(LuaBinding& binding) - { - return std::make_unique(binding); - } - - LuaBinding_SDK::LuaBinding_SDK(LuaBinding& binding) : - LuaBinding_Base(binding) - { - #ifndef NDK_SERVER - LuaBinding_Graphics& graphics = static_cast(*m_binding.graphics); - #endif - - LuaBinding_Utility& utility = static_cast(*m_binding.utility); - - /*********************************** Ndk::Application **********************************/ - application.Reset("Application"); - { - #ifndef NDK_SERVER - //application.SetMethod("AddWindow", &Application::AddWindow); - - application.BindMethod("EnableConsole", &Application::EnableConsole); - application.BindMethod("EnableFPSCounter", &Application::EnableFPSCounter); - - application.BindMethod("IsConsoleEnabled", &Application::IsConsoleEnabled); - application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled); - #endif - - application.BindMethod("AddWorld", [] (Nz::LuaState& lua, Application* instance, std::size_t /*argumentCount*/) -> int - { - lua.Push(instance->AddWorld().CreateHandle()); - return 1; - }); - - application.BindMethod("GetUpdateTime", &Application::GetUpdateTime); - application.BindMethod("Quit", &Application::Quit); - } - - /*********************************** Ndk::Console **********************************/ - #ifndef NDK_SERVER - console.Reset("Console"); - { - console.Inherit(utility.node, [] (ConsoleHandle* handle) -> Nz::Node* - { - return handle->GetObject(); - }); - - console.BindMethod("AddLine", &Console::AddLine, Nz::Color::White); - console.BindMethod("Clear", &Console::Clear); - console.BindMethod("GetCharacterSize", &Console::GetCharacterSize); - //console.BindMethod("GetHistory", &Console::GetHistory); - //console.BindMethod("GetInput", &Console::GetInput); - console.BindMethod("GetTextFont", &Console::GetTextFont); - - console.BindMethod("IsValidHandle", &ConsoleHandle::IsValid); - - console.BindMethod("SetCharacterSize", &Console::SetCharacterSize); - console.BindMethod("SetTextFont", &Console::SetTextFont); - } - #endif - - /*********************************** Ndk::Entity **********************************/ - entity.Reset("Entity"); - { - entity.BindMethod("Enable", &Entity::Enable, true); - entity.BindMethod("GetId", &Entity::GetId); - entity.BindMethod("GetWorld", &Entity::GetWorld); - entity.BindMethod("Kill", &Entity::Kill); - entity.BindMethod("IsEnabled", &Entity::IsEnabled); - entity.BindMethod("IsValid", &Entity::IsValid); - entity.BindMethod("IsValidHandle", &EntityHandle::IsValid); - entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents); - entity.BindMethod("__tostring", &EntityHandle::ToString); - - entity.BindMethod("AddComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int - { - LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state); - - return bindingComponent->adder(state, handle); - }); - - entity.BindMethod("HasComponent", [this](Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int - { - LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state); - - state.PushBoolean(handle->HasComponent(bindingComponent->index)); - return 1; - }); - - entity.BindMethod("GetComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int - { - LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state); - - return bindingComponent->getter(state, handle->GetComponent(bindingComponent->index)); - }); - - entity.BindMethod("RemoveComponent", [this] (Nz::LuaState& state, EntityHandle& handle, std::size_t /*argumentCount*/) -> int - { - LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(state); - - handle->RemoveComponent(bindingComponent->index); - return 0; - }); - } - - /*********************************** Ndk::NodeComponent **********************************/ - nodeComponent.Reset("NodeComponent"); - { - nodeComponent.BindMethod("IsValidHandle", &NodeComponentHandle::IsValid); - - nodeComponent.Inherit(utility.node, [] (NodeComponentHandle* handle) -> Nz::Node* - { - return handle->GetObject(); - }); - } - - /*********************************** Ndk::VelocityComponent **********************************/ - velocityComponent.Reset("VelocityComponent"); - { - velocityComponent.BindMethod("IsValidHandle", &VelocityComponentHandle::IsValid); - - velocityComponent.SetGetter([] (Nz::LuaState& lua, VelocityComponentHandle& instance) - { - std::size_t length; - const char* member = lua.CheckString(2, &length); - - if (std::strcmp(member, "Linear") == 0) - { - lua.Push(instance->linearVelocity); - return true; - } - - return false; - }); - - velocityComponent.SetSetter([] (Nz::LuaState& lua, VelocityComponentHandle& instance) - { - std::size_t length; - const char* member = lua.CheckString(2, &length); - - int argIndex = 3; - if (std::strcmp(member, "Linear") == 0) - { - instance->linearVelocity = lua.Check(&argIndex); - return true; - } - - return false; - }); - } - - /*********************************** Ndk::World **********************************/ - world.Reset("World"); - { - world.BindMethod("CreateEntity", &World::CreateEntity); - world.BindMethod("CreateEntities", &World::CreateEntities); - world.BindMethod("Clear", &World::Clear); - world.BindMethod("DisableProfiler", &World::DisableProfiler); - world.BindMethod("EnableProfiler", &World::EnableProfiler); - world.BindMethod("IsProfilerEnabled", &World::IsProfilerEnabled); - world.BindMethod("Refresh", &World::Refresh); - world.BindMethod("ResetProfiler", &World::ResetProfiler); - world.BindMethod("Update", &World::Update); - - world.BindMethod("IsValidHandle", &WorldHandle::IsValid); - } - - #ifndef NDK_SERVER - /*********************************** Ndk::CameraComponent **********************************/ - cameraComponent.Reset("CameraComponent"); - { - cameraComponent.Inherit(graphics.abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer* - { - return handle->GetObject(); - }); - - cameraComponent.BindMethod("GetFOV", &CameraComponent::GetFOV); - cameraComponent.BindMethod("GetLayer", &CameraComponent::GetLayer); - - cameraComponent.BindMethod("IsValidHandle", &CameraComponentHandle::IsValid); - - cameraComponent.BindMethod("SetFOV", &CameraComponent::SetFOV); - cameraComponent.BindMethod("SetLayer", &CameraComponent::SetLayer); - cameraComponent.BindMethod("SetProjectionType", &CameraComponent::SetProjectionType); - cameraComponent.BindMethod("SetSize", (void(CameraComponent::*)(const Nz::Vector2f&)) &CameraComponent::SetSize); - //cameraComponent.BindMethod("SetTarget", &CameraComponent::SetTarget); - cameraComponent.BindMethod("SetTargetRegion", &CameraComponent::SetTargetRegion); - cameraComponent.BindMethod("SetViewport", &CameraComponent::SetViewport); - cameraComponent.BindMethod("SetZFar", &CameraComponent::SetZFar); - cameraComponent.BindMethod("SetZNear", &CameraComponent::SetZNear); - } - - /*********************************** Ndk::GraphicsComponent **********************************/ - graphicsComponent.Reset("GraphicsComponent"); - { - graphicsComponent.BindMethod("Attach", [] (Nz::LuaState& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int - { - /* - void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0); - void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0); - */ - - std::size_t argCount = std::min(argumentCount, 3U); - - switch (argCount) - { - case 1: - { - int argIndex = 2; - instance->Attach(lua.Check(&argIndex)); - return 0; - } - - case 2: - { - int argIndex = 2; - Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); - - if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - { - int renderOrder = lua.Check(&argIndex); - - instance->Attach(renderable, renderOrder); - } - else if (lua.IsOfType(argIndex, "Matrix4")) - { - Nz::Matrix4f localMatrix = lua.Check(&argIndex); - - instance->Attach(renderable, localMatrix); - } - else - break; - - return 0; - } - - case 3: - { - int argIndex = 2; - Nz::InstancedRenderableRef renderable = lua.Check(&argIndex); - Nz::Matrix4f localMatrix = lua.Check(&argIndex); - int renderOrder = lua.Check(&argIndex); - - instance->Attach(renderable, localMatrix, renderOrder); - return 0; - } - } - - lua.Error("No matching overload for method GetMemoryUsage"); - return 0; - }); - - graphicsComponent.BindMethod("IsValidHandle", &GraphicsComponentHandle::IsValid); - } - #endif - - // Components functions - m_binding.BindComponent("Node"); - m_binding.BindComponent("Velocity"); - - #ifndef NDK_SERVER - m_binding.BindComponent("Camera"); - m_binding.BindComponent("Graphics"); - #endif - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the SDK classes - */ - void LuaBinding_SDK::Register(Nz::LuaState& state) - { - // Classes - application.Register(state); - entity.Register(state); - nodeComponent.Register(state); - velocityComponent.Register(state); - world.Register(state); - - #ifndef NDK_SERVER - cameraComponent.Register(state); - console.Register(state); - graphicsComponent.Register(state); - #endif - - // Enums - } - - /*! - * \brief Gets the index of the component - * \return A pointer to the binding linked to a component - * - * \param instance Lua instance that will interact with the component - * \param argIndex Index of the component - */ - LuaBinding::ComponentBinding* LuaBinding::QueryComponentIndex(Nz::LuaState& state, int argIndex) - { - switch (state.GetType(argIndex)) - { - case Nz::LuaType_Number: - { - ComponentIndex componentIndex = state.Check(&argIndex); - if (componentIndex > m_componentBinding.size()) - { - state.Error("Invalid component index"); - return nullptr; - } - - ComponentBinding& binding = m_componentBinding[componentIndex]; - if (binding.name.IsEmpty()) - { - state.Error("Invalid component index"); - return nullptr; - } - - return &binding; - } - - case Nz::LuaType_String: - { - const char* key = state.CheckString(argIndex); - auto it = m_componentBindingByName.find(key); - if (it == m_componentBindingByName.end()) - { - state.Error("Invalid component name"); - return nullptr; - } - - return &m_componentBinding[it->second]; - } - - default: - break; - } - - state.Error("Invalid component index at #" + Nz::String::Number(argIndex)); - return nullptr; - } -} diff --git a/SDK/src/NDK/Lua/LuaBinding_Utility.cpp b/SDK/src/NDK/Lua/LuaBinding_Utility.cpp deleted file mode 100644 index 262620b12..000000000 --- a/SDK/src/NDK/Lua/LuaBinding_Utility.cpp +++ /dev/null @@ -1,338 +0,0 @@ -// This file is part of the "Nazara Development Kit" -// For conditions of distribution and use, see copyright notice in Prerequisites.hpp - -#include -#include - -namespace Ndk -{ - std::unique_ptr LuaBinding_Base::BindUtility(LuaBinding& binding) - { - return std::make_unique(binding); - } - - LuaBinding_Utility::LuaBinding_Utility(LuaBinding& binding) : - LuaBinding_Base(binding) - { - /*********************************** Nz::AbstractImage **********************************/ - abstractImage.Reset("AbstractImage"); - { - abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel); - abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast(0)); - abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat); - abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast(0)); - abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount); - abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel); - abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast(0)); - abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType); - abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast(0)); - abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed); - abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap); - - abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaState& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 1U); - switch (argCount) - { - case 0: - return lua.Push(instance->GetMemoryUsage()); - - case 1: - { - int argIndex = 2; - Nz::UInt8 level(lua.Check(&argIndex)); - - return lua.Push(instance->GetMemoryUsage(level)); - } - } - - lua.Error("No matching overload for method GetMemoryUsage"); - return 0; - }); - - abstractImage.BindMethod("Update", [] (Nz::LuaState& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int - { - 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)); - - if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number)) - { - // bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) - unsigned int srcWidth = lua.Check(&argIndex, 0); - unsigned int srcHeight = lua.Check(&argIndex, 0); - Nz::UInt8 level = lua.Check(&argIndex, 0); - - ///TODO: Buffer checks (Nz::ByteBufferView ?) - return lua.Push(instance->Update(pixels, srcWidth, srcHeight, level)); - } - /* Disabled until Box and Rect have been ported - else if (lua.IsOfType(2, "Box")) - { - // bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) - Nz::Boxui box = lua.Check(&argIndex); - unsigned int srcWidth = lua.Check(&argIndex, 0); - unsigned int srcHeight = lua.Check(&argIndex, 0); - Nz::UInt8 level = lua.Check(&argIndex, 0); - - ///TODO: Buffer checks (Nz::ByteBufferView ?) - return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level)); - } - else if (lua.IsOfType(2, "Rect")) - { - // bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) - Nz::Rectui box = lua.Check(&argIndex); - unsigned int srcWidth = lua.Check(&argIndex, 0); - unsigned int srcHeight = lua.Check(&argIndex, 0); - Nz::UInt8 level = lua.Check(&argIndex, 0); - - ///TODO: Buffer checks (Nz::ByteBufferView ?) - return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level)); - }*/ - - lua.Error("No matching overload for method Update"); - return 0; - }); - } - - /*********************************** Nz::Font **********************************/ - font.Reset("Font"); - { - font.SetConstructor([] (Nz::LuaState& /*lua*/, Nz::FontRef* instance, std::size_t /*argumentCount*/) - { - Nz::PlacementNew(instance, Nz::Font::New()); - return true; - }); - - font.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache); - font.BindMethod("ClearKerningCache", &Nz::Font::ClearKerningCache); - font.BindMethod("ClearSizeInfoCache", &Nz::Font::ClearSizeInfoCache); - - font.BindMethod("Destroy", &Nz::Font::Destroy); - - font.BindMethod("GetCachedGlyphCount", [] (Nz::LuaState& lua, Nz::FontRef& instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 2U); - - int argIndex = 2; - switch (argCount) - { - case 0: - lua.Push(instance->GetCachedGlyphCount()); - return 1; - - case 3: - { - unsigned int characterSize = lua.Check(&argIndex); - Nz::TextStyleFlags style = lua.Check(&argIndex); - float outlineThickness = lua.Check(&argIndex); - - lua.Push(instance->GetCachedGlyphCount(characterSize, style, outlineThickness)); - return 1; - } - } - - lua.Error("No matching overload for method GetCachedGlyphCount"); - return 0; - }); - - 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); - - font.BindMethod("IsValid", &Nz::Font::IsValid); - - font.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::TextStyleFlags, float, const Nz::String&) const) &Nz::Font::Precache); - - font.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder); - font.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize); - - font.BindStaticMethod("GetDefault", &Nz::Font::GetDefault); - font.BindStaticMethod("GetDefaultGlyphBorder", &Nz::Font::GetDefaultGlyphBorder); - font.BindStaticMethod("GetDefaultMinimumStepSize", &Nz::Font::GetDefaultMinimumStepSize); - - font.BindStaticMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams()); - - font.BindStaticMethod("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder); - font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize); - } - - /*********************************** Nz::Node **********************************/ - node.Reset("Node"); - { - node.BindMethod("GetBackward", &Nz::Node::GetBackward); - //nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds); - 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); - node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale); - node.BindMethod("GetLeft", &Nz::Node::GetLeft); - node.BindMethod("GetNodeType", &Nz::Node::GetNodeType); - //nodeClass.SetMethod("GetParent", &Nz::Node::GetParent); - node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global); - node.BindMethod("GetRight", &Nz::Node::GetRight); - //nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global); - node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global); - //nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix); - node.BindMethod("GetUp", &Nz::Node::GetUp); - - node.BindMethod("HasChilds", &Nz::Node::HasChilds); - - 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); - - node.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition); - node.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation); - - 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::LuaState& 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); - instance.Move(offset, coordSys); - - return 0; - }); - - node.BindMethod("Rotate", [] (Nz::LuaState& 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); - instance.Rotate(rotation, coordSys); - - return 0; - }); - - node.BindMethod("Scale", [] (Nz::LuaState& lua, Nz::Node& instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 4U); - - int argIndex = 2; - switch (argCount) - { - case 1: - { - if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - instance.Scale(lua.Check(&argIndex)); - else - instance.Scale(lua.Check(&argIndex)); - - return 0; - } - - case 3: - instance.Scale(lua.Check(&argIndex)); - return 0; - } - - lua.Error("No matching overload for method Scale"); - return 0; - }); - - node.BindMethod("SetScale", [] (Nz::LuaState& lua, Nz::Node& instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 4U); - - int argIndex = 2; - switch (argCount) - { - case 1: - case 2: - { - if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - { - float scale = lua.Check(&argIndex); - Nz::CoordSys coordSys = lua.Check(&argIndex, Nz::CoordSys_Local); - instance.SetScale(scale, coordSys); - } - else - instance.SetScale(lua.Check(&argIndex)); - - return 0; - } - - case 3: - case 4: - { - Nz::Vector3f scale = lua.Check(&argIndex); - Nz::CoordSys coordSys = lua.Check(&argIndex, Nz::CoordSys_Local); - - instance.SetScale(scale, coordSys); - return 0; - } - } - - lua.Error("No matching overload for method SetScale"); - return 0; - }); - - node.BindMethod("SetInitialScale", [] (Nz::LuaState& lua, Nz::Node& instance, std::size_t argumentCount) -> int - { - std::size_t argCount = std::min(argumentCount, 4U); - - int argIndex = 2; - switch (argCount) - { - case 1: - { - if (lua.IsOfType(argIndex, Nz::LuaType_Number)) - instance.SetInitialScale(lua.Check(&argIndex)); - else - instance.SetInitialScale(lua.Check(&argIndex)); - - return 0; - } - - case 2: - case 3: - instance.SetInitialScale(lua.Check(&argIndex)); - return 0; - } - - lua.Error("No matching overload for method SetInitialScale"); - return 0; - }); - } - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the Utility classes - */ - void LuaBinding_Utility::Register(Nz::LuaState& state) - { - abstractImage.Register(state); - font.Register(state); - node.Register(state); - } -} diff --git a/SDK/src/NDK/LuaAPI.cpp b/SDK/src/NDK/LuaAPI.cpp deleted file mode 100644 index 3a82d2130..000000000 --- a/SDK/src/NDK/LuaAPI.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// This file was automatically generated on 26 May 2014 at 01:05:31 - -#include -#include -#include - -namespace Ndk -{ - /*! - * \ingroup NDK - * \class Ndk::LuaAPI - * \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 - */ - - bool LuaAPI::Initialize() - { - s_binding = new LuaBinding; - return true; - } - - /*! - * \brief Registers the classes that will be used by the Lua instance - * - * \param instance Lua instance that will interact with the engine & SDK - */ - - void LuaAPI::RegisterClasses(Nz::LuaState& state) - { - Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true); - GetBinding()->RegisterClasses(state); - } - - /*! - * \brief Uninitializes the LuaAPI module - */ - - void LuaAPI::Uninitialize() - { - delete s_binding; - } - - LuaBinding* LuaAPI::s_binding = nullptr; -} diff --git a/SDK/src/NDK/Sdk.cpp b/SDK/src/NDK/Sdk.cpp index 341e6f0d5..c6a6de027 100644 --- a/SDK/src/NDK/Sdk.cpp +++ b/SDK/src/NDK/Sdk.cpp @@ -7,8 +7,6 @@ #include #include #include -#include -#include #include #include #include @@ -70,8 +68,6 @@ namespace Ndk // Initialize the engine first // Shared modules - Nz::Lua::Initialize(); - Nz::Noise::Initialize(); Nz::Physics2D::Initialize(); Nz::Physics3D::Initialize(); Nz::Utility::Initialize(); @@ -178,8 +174,6 @@ namespace Ndk #endif // Shared modules - Nz::Lua::Uninitialize(); - Nz::Noise::Uninitialize(); Nz::Physics2D::Uninitialize(); Nz::Physics3D::Uninitialize(); Nz::Utility::Uninitialize(); diff --git a/build/scripts/modules/lua.lua b/build/scripts/modules/lua.lua deleted file mode 100644 index 96fe0cbc1..000000000 --- a/build/scripts/modules/lua.lua +++ /dev/null @@ -1,7 +0,0 @@ --- Quelle ironie -MODULE.Name = "Lua" - -MODULE.Libraries = { - "lua", - "NazaraCore" -} diff --git a/build/scripts/modules/noise.lua b/build/scripts/modules/noise.lua deleted file mode 100644 index 155cd83be..000000000 --- a/build/scripts/modules/noise.lua +++ /dev/null @@ -1,5 +0,0 @@ -MODULE.Name = "Noise" - -MODULE.Libraries = { - "NazaraCore" -} diff --git a/examples/FirstScene/main.cpp b/examples/FirstScene/main.cpp index 06e9fd97c..4952106a8 100644 --- a/examples/FirstScene/main.cpp +++ b/examples/FirstScene/main.cpp @@ -13,7 +13,6 @@ */ #include // Horloges -#include // Module de scripting #include // Module graphique #include // Module de rendu #include // Module utilitaire @@ -22,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -264,10 +262,6 @@ int main() application.EnableConsole(true); application.EnableFPSCounter(true); - Ndk::Application::ConsoleOverlay& consoleOverlay = application.GetConsoleOverlay(); - consoleOverlay.lua.PushGlobal("Spaceship", spaceship->CreateHandle()); - consoleOverlay.lua.PushGlobal("World", world->CreateHandle()); - //Gestion des Evenements Nz::EventHandler& eventHandler = window.GetEventHandler(); diff --git a/examples/Particles/LogoDemo.cpp b/examples/Particles/LogoDemo.cpp index f04ce43ad..a4d31ef8d 100644 --- a/examples/Particles/LogoDemo.cpp +++ b/examples/Particles/LogoDemo.cpp @@ -126,7 +126,7 @@ ParticleDemo("Logo", sharedData) Nz::ImageParams params; params.loadFormat = Nz::PixelFormatType_RGBA8; - m_logo = Nz::Image::LoadFromFile("resources/Logo.png", params); + m_logo = Nz::Image::LoadFromFile("E:/Twitch/avatar_interested.png", params); if (!m_logo) NazaraError("Failed to load logo!"); diff --git a/examples/Particles/main.cpp b/examples/Particles/main.cpp index 7f1571989..2d77811a4 100644 --- a/examples/Particles/main.cpp +++ b/examples/Particles/main.cpp @@ -1,9 +1,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -38,6 +36,8 @@ int main() Nz::RenderWindow& window = app.AddWindow(mode, "Nazara demo - Particles", Nz::WindowStyle_Closable, targetParams); //Nz::RenderWindow& window = app.AddWindow(Nz::VideoMode(1920, 1080), "Nazara demo - Particles", Nz::WindowStyle_Fullscreen, targetParams); + app.EnableFPSCounter(true); + Ndk::World& world3D = app.AddWorld(); Ndk::World& world2D = app.AddWorld(); diff --git a/examples/Tut00/main.cpp b/examples/Tut00/main.cpp index a1029eb99..d3018f5e8 100644 --- a/examples/Tut00/main.cpp +++ b/examples/Tut00/main.cpp @@ -1,9 +1,7 @@ -#include +#include #include #include -#include #include -#include #include #include #include diff --git a/include/Nazara/Lua.hpp b/include/Nazara/Lua.hpp deleted file mode 100644 index bd7ddb24c..000000000 --- a/include/Nazara/Lua.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// This file was automatically generated - -/* - Nazara Engine - Lua scripting module - - Copyright (C) 2015 Jérôme Leclercq (lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_GLOBAL_LUA_HPP -#define NAZARA_GLOBAL_LUA_HPP - -#include -#include -#include -#include -#include -#include -#include - -#endif // NAZARA_GLOBAL_LUA_HPP diff --git a/include/Nazara/Lua/Config.hpp b/include/Nazara/Lua/Config.hpp deleted file mode 100644 index 6536233f6..000000000 --- a/include/Nazara/Lua/Config.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - Nazara Engine - Lua scripting module - - Copyright (C) 2015 Jérôme Leclercq (lynix680@gmail.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_LUA_HPP -#define NAZARA_CONFIG_LUA_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Utilise un manager de mémoire pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes) -#define NAZARA_LUA_MANAGE_MEMORY 0 - -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) -#define NAZARA_LUA_SAFE 1 - -/// Vérification des valeurs et types de certaines constantes -#include - -#if defined(NAZARA_STATIC) - #define NAZARA_LUA_API -#else - #ifdef NAZARA_LUA_BUILD - #define NAZARA_LUA_API NAZARA_EXPORT - #else - #define NAZARA_LUA_API NAZARA_IMPORT - #endif -#endif - -#endif // NAZARA_CONFIG_LUA_HPP diff --git a/include/Nazara/Lua/ConfigCheck.hpp b/include/Nazara/Lua/ConfigCheck.hpp deleted file mode 100644 index ee3010113..000000000 --- a/include/Nazara/Lua/ConfigCheck.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_CONFIG_CHECK_LUA_HPP -#define NAZARA_CONFIG_CHECK_LUA_HPP - -/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp - -// On force la valeur de MANAGE_MEMORY en mode debug -#if defined(NAZARA_DEBUG) && !NAZARA_LUA_MANAGE_MEMORY - #undef NAZARA_LUA_MANAGE_MEMORY - #define NAZARA_LUA_MANAGE_MEMORY 0 -#endif - -#endif // NAZARA_CONFIG_CHECK_LUA_HPP diff --git a/include/Nazara/Lua/Debug.hpp b/include/Nazara/Lua/Debug.hpp deleted file mode 100644 index 991f620a2..000000000 --- a/include/Nazara/Lua/Debug.hpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_LUA_MANAGE_MEMORY - #include -#endif diff --git a/include/Nazara/Lua/DebugOff.hpp b/include/Nazara/Lua/DebugOff.hpp deleted file mode 100644 index 59c38fd94..000000000 --- a/include/Nazara/Lua/DebugOff.hpp +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp -#if NAZARA_LUA_MANAGE_MEMORY - #undef delete - #undef new -#endif diff --git a/include/Nazara/Lua/Enums.hpp b/include/Nazara/Lua/Enums.hpp deleted file mode 100644 index e92f058d5..000000000 --- a/include/Nazara/Lua/Enums.hpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_ENUMS_LUA_HPP -#define NAZARA_ENUMS_LUA_HPP - -#include - -namespace Nz -{ - enum LuaBindMode - { - LuaBindMode_Table, - LuaBindMode_Userdata, - - LuaBindMode_Max = LuaBindMode_Userdata - }; - - enum LuaComparison - { - LuaComparison_Equality, - LuaComparison_Less, - LuaComparison_LessOrEqual, - - LuaComparison_Max = LuaComparison_LessOrEqual - }; - - enum LuaLib - { - LuaLib_Coroutine, - LuaLib_Debug, - LuaLib_Math, - LuaLib_Io, - LuaLib_Package, - LuaLib_Os, - LuaLib_String, - LuaLib_Table, - LuaLib_Utf8, - - LuaLib_Max = LuaLib_Utf8 - }; - - enum LuaOperation - { - LuaOperation_Addition, - LuaOperation_BitwiseAnd, - LuaOperation_BitwiseLeftShift, - LuaOperation_BitwiseNot, - LuaOperation_BitwiseOr, - LuaOperation_BitwideRightShift, - LuaOperation_BitwiseXOr, - LuaOperation_Division, - LuaOperation_Exponentiation, - LuaOperation_FloorDivision, - LuaOperation_Modulo, - LuaOperation_Multiplication, - LuaOperation_Negation, - LuaOperation_Substraction, - - LuaOperation_Max = LuaOperation_Substraction - }; - - enum LuaType - { - LuaType_Boolean, - LuaType_Function, - LuaType_LightUserdata, - LuaType_Nil, - LuaType_Number, - LuaType_None, - LuaType_String, - LuaType_Table, - LuaType_Thread, - LuaType_Userdata, - - LuaType_Max = LuaType_Userdata - }; - - template<> - struct EnumAsFlags - { - static constexpr LuaLib max = LuaLib_Max; - }; - - using LuaLibFlags = Flags; - - constexpr LuaLibFlags LuaLib_All = LuaLibFlags(LuaLibFlags::ValueMask); -} - -#endif // NAZARA_ENUMS_LUA_HPP diff --git a/include/Nazara/Lua/Lua.hpp b/include/Nazara/Lua/Lua.hpp deleted file mode 100644 index d884a22b9..000000000 --- a/include/Nazara/Lua/Lua.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_LUA_HPP -#define NAZARA_LUA_HPP - -#include -#include - -namespace Nz -{ - class NAZARA_LUA_API Lua - { - public: - Lua() = delete; - ~Lua() = delete; - - static bool Initialize(); - - static bool IsInitialized(); - - static void Uninitialize(); - - private: - static unsigned int s_moduleReferenceCounter; - }; -} - -#endif // NAZARA_LUA_HPP diff --git a/include/Nazara/Lua/LuaClass.hpp b/include/Nazara/Lua/LuaClass.hpp deleted file mode 100644 index 79558a3b6..000000000 --- a/include/Nazara/Lua/LuaClass.hpp +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_LUACLASS_HPP -#define NAZARA_LUACLASS_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - template - class LuaClass - { - template - friend class LuaClass; - - public: - using ClassFunc = std::function; - using ClassIndexFunc = std::function; - using ConstructorFunc = std::function; - template using ConvertToParent = std::function; - using FinalizerFunc = std::function; - using StaticIndexFunc = std::function; - using StaticFunc = std::function; - - LuaClass() = default; - LuaClass(const String& name); - - void BindDefaultConstructor(); - - void BindMethod(const String& name, ClassFunc method); - template std::enable_if_t::value> BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs); - template std::enable_if_t::value> BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs); - template std::enable_if_t::type>::value> BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs); - template std::enable_if_t::type>::value> BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs); - - void BindStaticMethod(const String& name, StaticFunc func); - template void BindStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs); - - template void Inherit(LuaClass

& parent); - template void Inherit(LuaClass

& parent, ConvertToParent

convertFunc); - - void Reset(); - void Reset(const String& name); - - void Register(LuaState& state); - - void PushGlobalTable(LuaState& state); - - void SetConstructor(ConstructorFunc constructor); - void SetFinalizer(FinalizerFunc finalizer); - void SetGetter(ClassIndexFunc getter); - void SetSetter(ClassIndexFunc setter); - void SetStaticGetter(StaticIndexFunc getter); - void SetStaticSetter(StaticIndexFunc getter); - - private: - template - friend struct LuaClassImplFinalizerSetupProxy; - - int PushClassInfo(LuaState& state); - void SetupConstructor(LuaState& state, int classInfoRef); - void SetupDefaultToString(LuaState& state, int classInfoRef); - void SetupFinalizer(LuaState& state, int classInfoRef); - void SetupGetter(LuaState& state, LuaCFunction proxy, int classInfoRef); - void SetupGlobalTable(LuaState& state, int classInfoRef); - void SetupMetatable(LuaState& state, int classInfoRef); - void SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex, int classInfoRef); - void SetupSetter(LuaState& state, LuaCFunction proxy, int classInfoRef); - - using ParentFunc = std::function; - using InstanceGetter = std::function; - - struct ClassInfo - { - std::vector methods; - std::vector parentGetters; - std::vector staticMethods; - std::unordered_map instanceGetters; - ClassIndexFunc getter; - ClassIndexFunc setter; - ConstructorFunc constructor; - FinalizerFunc finalizer; - StaticIndexFunc staticGetter; - StaticIndexFunc staticSetter; - String name; - int globalTableRef = -1; - }; - - static int ConstructorProxy(lua_State* internalState); - static int FinalizerProxy(lua_State* internalState); - static int InfoDestructor(lua_State* internalState); - static void Get(const std::shared_ptr& info, LuaState& state, T* instance); - static int GetterProxy(lua_State* internalState); - static int MethodProxy(lua_State* internalState); - static int SetterProxy(lua_State* internalState); - static int StaticGetterProxy(lua_State* internalState); - static int StaticMethodProxy(lua_State* internalState); - static int StaticSetterProxy(lua_State* internalState); - static int ToStringProxy(lua_State* internalState); - - std::map m_methods; - std::map m_staticMethods; - std::shared_ptr m_info; - }; -} - -#include - -#endif // NAZARA_LUACLASS_HPP diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl deleted file mode 100644 index 86ab9b311..000000000 --- a/include/Nazara/Lua/LuaClass.inl +++ /dev/null @@ -1,603 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// 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 -#include - -namespace Nz -{ - template - LuaClass::LuaClass(const String& name) - { - Reset(name); - } - - template - inline void LuaClass::BindDefaultConstructor() - { - SetConstructor([] (Nz::LuaState& state, T* instance, std::size_t argumentCount) - { - NazaraUnused(state); - NazaraUnused(argumentCount); - - PlacementNew(instance); - return true; - }); - } - - template - template - inline void LuaClass::Inherit(LuaClass

& parent) - { - Inherit

(parent, [] (T* instance) -> P* - { - return static_cast(instance); - }); - } - - template - template - inline void LuaClass::Inherit(LuaClass

& parent, ConvertToParent

convertFunc) - { - static_assert(!std::is_same::value || std::is_base_of::value, "P must be a base of T"); - - std::shared_ptr::ClassInfo>& parentInfo = parent.m_info; - - parentInfo->instanceGetters[m_info->name] = [info = m_info, convertFunc] (LuaState& state) -> P* - { - return convertFunc(static_cast(state.CheckUserdata(1, info->name))); - }; - - m_info->parentGetters.emplace_back([parentInfo, convertFunc] (LuaState& state, T* instance) - { - LuaClass

::Get(parentInfo, state, convertFunc(instance)); - }); - } - - - template - void LuaClass::Reset() - { - m_info.reset(); - } - - template - void LuaClass::Reset(const String& name) - { - m_info = std::make_shared(); - m_info->name = name; - - m_info->instanceGetters[m_info->name] = [info = m_info] (LuaState& state) - { - return static_cast(state.CheckUserdata(1, info->name)); - }; - } - - template - void LuaClass::Register(LuaState& state) - { - int classInfoRef = PushClassInfo(state); - - // Let's create the metatable which will be associated with every state. - SetupMetatable(state, classInfoRef); - - if (m_info->constructor || m_info->staticGetter || m_info->staticSetter || !m_staticMethods.empty()) - SetupGlobalTable(state, classInfoRef); - - state.DestroyReference(classInfoRef); - } - - template - void LuaClass::PushGlobalTable(LuaState& state) - { - state.PushReference(m_info->globalTableRef); - } - - template - void LuaClass::SetConstructor(ConstructorFunc constructor) - { - m_info->constructor = constructor; - } - - template - void LuaClass::SetFinalizer(FinalizerFunc finalizer) - { - m_info->finalizer = finalizer; - } - - template - void LuaClass::SetGetter(ClassIndexFunc getter) - { - m_info->getter = getter; - } - - template - void LuaClass::BindMethod(const String& name, ClassFunc method) - { - m_methods[name] = method; - } - - template - template - std::enable_if_t::value> LuaClass::BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs) - { - typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - - BindMethod(name, [func, handler] (LuaState& state, T& object, std::size_t /*argumentCount*/) -> int - { - handler.ProcessArguments(state); - - return handler.Invoke(state, object, func); - }); - } - - template - template - std::enable_if_t::value> LuaClass::BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs) - { - typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - - BindMethod(name, [func, handler] (LuaState& state, T& object, std::size_t /*argumentCount*/) -> int - { - handler.ProcessArguments(state); - - return handler.Invoke(state, object, func); - }); - } - - template - template - std::enable_if_t::type>::value> LuaClass::BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs) - { - typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - - BindMethod(name, [func, handler] (LuaState& state, T& object, std::size_t /*argumentCount*/) -> int - { - handler.ProcessArguments(state); - - return handler.Invoke(state, object, func); - }); - } - - template - template - std::enable_if_t::type>::value> LuaClass::BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs) - { - typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - - BindMethod(name, [func, handler] (LuaState& state, T& object, std::size_t /*argumentCount*/) -> int - { - handler.ProcessArguments(state); - - return handler.Invoke(state, object, func); - }); - } - - template - void LuaClass::SetSetter(ClassIndexFunc setter) - { - m_info->setter = setter; - } - - template - void LuaClass::SetStaticGetter(StaticIndexFunc getter) - { - m_info->staticGetter = getter; - } - - template - void LuaClass::BindStaticMethod(const String& name, StaticFunc method) - { - m_staticMethods[name] = method; - } - - template - template - void LuaClass::BindStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs) - { - typename LuaImplFunctionProxy::template Impl handler(std::forward(defArgs)...); - - BindStaticMethod(name, [func, handler] (LuaState& state) -> int - { - handler.ProcessArguments(state); - - return handler.Invoke(state, func); - }); - } - - template - void LuaClass::SetStaticSetter(StaticIndexFunc setter) - { - m_info->staticSetter = setter; - } - - template - int LuaClass::PushClassInfo(LuaState& state) - { - // 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*>(state.PushUserdata(sizeof(std::shared_ptr))); - PlacementNew(info, m_info); - - // Setup a tiny metatable to let Lua know how to destroy our ClassInfo - state.PushTable(0, 1); - state.PushLightUserdata(info); - state.PushCFunction(InfoDestructor, 1); - state.SetField("__gc"); - state.SetMetatable(-2); - - return state.CreateReference(); - } - - template - void LuaClass::SetupConstructor(LuaState& state, int classInfoRef) - { - state.PushReference(classInfoRef); - state.PushCFunction(ConstructorProxy, 1); - state.SetField("__call"); // ClassMeta.__call = ConstructorProxy - } - - template - void LuaClass::SetupDefaultToString(LuaState& state, int classInfoRef) - { - state.PushReference(classInfoRef); - state.PushCFunction(ToStringProxy, 1); - state.SetField("__tostring"); - } - - template - struct LuaClassImplFinalizerSetupProxy; - - template - struct LuaClassImplFinalizerSetupProxy - { - static void Setup(LuaState& state, int classInfoRef) - { - state.PushReference(classInfoRef); - state.PushCFunction(LuaClass::FinalizerProxy, 1); - state.SetField("__gc"); - } - }; - - template - struct LuaClassImplFinalizerSetupProxy - { - static void Setup(LuaState&, int) - { - } - }; - - template - void LuaClass::SetupFinalizer(LuaState& state, int classInfoRef) - { - LuaClassImplFinalizerSetupProxy::value>::Setup(state, classInfoRef); - } - - template - void LuaClass::SetupGetter(LuaState& state, LuaCFunction proxy, int classInfoRef) - { - state.PushReference(classInfoRef); - state.PushValue(-2); // Metatable - state.PushCFunction(proxy, 2); - - state.SetField("__index"); // Getter - } - - template - void LuaClass::SetupGlobalTable(LuaState& state, int classInfoRef) - { - // Create the global table - state.PushTable(); // Class = {} - - // Create a metatable which will be used for our global table - state.PushTable(); // ClassMeta = {} - - if (m_info->constructor) - SetupConstructor(state, classInfoRef); - - if (m_info->staticGetter) - SetupGetter(state, StaticGetterProxy, classInfoRef); - else - { - // Optimize by assigning the metatable instead of a search function - state.PushValue(-1); // Metatable - state.SetField("__index"); - } - - if (m_info->staticSetter) - SetupSetter(state, StaticSetterProxy, classInfoRef); - - 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(state, StaticMethodProxy, pair.first, methodIndex, classInfoRef); - } - - state.SetMetatable(-2); // setmetatable(Class, ClassMeta), pops ClassMeta - - state.PushValue(-1); // As CreateReference() pops the table, push a copy - m_info->globalTableRef = state.CreateReference(); - - state.SetGlobal(m_info->name); // _G["Class"] = Class - } - - template - void LuaClass::SetupMetatable(LuaState& state, int classInfoRef) - { - if (!state.NewMetatable(m_info->name)) - NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance"); - { - SetupFinalizer(state, classInfoRef); - - if (m_info->getter || !m_info->parentGetters.empty()) - SetupGetter(state, GetterProxy, classInfoRef); - else - { - // Optimize by assigning the metatable instead of a search function - // This is only possible if we have no custom getter nor parent - state.PushValue(-1); // Metatable - state.SetField("__index"); - } - - if (m_info->setter) - SetupSetter(state, SetterProxy, classInfoRef); - - // In case a __tostring method is missing, add a default implementation returning the class name - if (m_methods.find("__tostring") == m_methods.end()) - SetupDefaultToString(state, classInfoRef); - - 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(state, MethodProxy, pair.first, methodIndex, classInfoRef); - } - } - state.Pop(); //< Pops the metatable, it won't be collected before it's referenced by the Lua registry. - } - - template - void LuaClass::SetupMethod(LuaState& state, LuaCFunction proxy, const String& name, std::size_t methodIndex, int classInfoRef) - { - state.PushReference(classInfoRef); - state.PushInteger(methodIndex); - state.PushCFunction(proxy, 2); - - state.SetField(name); // Method name - } - - template - void LuaClass::SetupSetter(LuaState& state, LuaCFunction proxy, int classInfoRef) - { - state.PushReference(classInfoRef); - state.PushCFunction(proxy, 1); - - state.SetField("__newindex"); // Setter - } - - - template - int LuaClass::ConstructorProxy(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - const ConstructorFunc& constructor = info->constructor; - - state.Remove(1); // On enlève l'argument "table" du stack - - std::size_t argCount = state.GetStackTop(); - - T* instance = static_cast(state.PushUserdata(sizeof(T))); - - if (!constructor(state, instance, argCount)) - { - state.Error("Constructor failed"); - return 0; // Normalement jamais exécuté (l'erreur provoquant une exception) - } - - state.SetMetatable(info->name); - return 1; - } - - template - int LuaClass::FinalizerProxy(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - const FinalizerFunc& finalizer = info->finalizer; - - T* instance = static_cast(state.CheckUserdata(1, info->name)); - state.Remove(1); //< Remove the instance from the Lua stack - - if (!finalizer || finalizer(state, *instance)) - instance->~T(); - - return 0; - } - - template - int LuaClass::InfoDestructor(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - state.DestroyReference(info->globalTableRef); - - using namespace std; // Obligatoire pour le destructeur - info.~shared_ptr(); // Si vous voyez une autre façon de faire, je suis preneur - - return 0; - } - - template - void LuaClass::Get(const std::shared_ptr& info, LuaState& state, T* instance) - { - const ClassIndexFunc& getter = info->getter; - - if (!getter || !getter(state, *instance)) - { - // Query from the metatable - state.GetMetatable(info->name); //< Metatable - state.PushValue(2); //< Field - state.GetTable(); // Metatable[Field] - - state.Remove(-2); // Remove Metatable - - if (!state.IsValid(-1)) - { - for (const ParentFunc& parentGetter : info->parentGetters) - { - state.Pop(); //< Pop the last nil value - - parentGetter(state, instance); - if (state.IsValid(-1)) - return; - } - } - } - } - - template - int LuaClass::GetterProxy(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - - T* instance = static_cast(state.CheckUserdata(1, info->name)); - - Get(info, state, instance); - return 1; - } - - template - int LuaClass::MethodProxy(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - - T* instance = nullptr; - if (state.GetMetatable(1)) - { - LuaType type = state.GetField("__name"); - if (type == LuaType_String) - { - String name = state.ToString(-1); - auto it = info->instanceGetters.find(name); - if (it != info->instanceGetters.end()) - instance = it->second(state); - } - state.Pop(2); - } - - if (!instance) - { - state.Error("Method cannot be called without an object"); - return 0; - } - - std::size_t argCount = state.GetStackTop() - 1U; - - unsigned int index = static_cast(state.ToInteger(state.GetIndexOfUpValue(2))); - const ClassFunc& method = info->methods[index]; - return method(state, *instance, argCount); - } - - template - int LuaClass::SetterProxy(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - const ClassIndexFunc& setter = info->setter; - - T& instance = *static_cast(state.CheckUserdata(1, info->name)); - - if (!setter(state, instance)) - { - std::size_t length; - const char* str = state.ToString(2, &length); - - state.Error("Class \"" + info->name + "\" has no field \"" + String(str, length) + "\")"); - } - - return 1; - } - - template - int LuaClass::StaticGetterProxy(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - const StaticIndexFunc& getter = info->staticGetter; - - if (!getter(state)) - { - // On accède alors à la table - state.PushValue(state.GetIndexOfUpValue(2)); - state.PushValue(-2); - state.GetTable(); - } - - return 1; - } - - template - int LuaClass::StaticMethodProxy(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - unsigned int index = static_cast(state.ToInteger(state.GetIndexOfUpValue(2))); - const StaticFunc& method = info->staticMethods[index]; - - return method(state); - } - - template - int LuaClass::StaticSetterProxy(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - const StaticIndexFunc& setter = info->staticSetter; - - if (!setter(state)) - { - std::size_t length; - const char* str = state.ToString(2, &length); - - state.Error("Class \"" + info->name + "\" has no static field \"" + String(str, length) + ')'); - } - - return 1; - } - - template - int LuaClass::ToStringProxy(lua_State* internalState) - { - LuaState state = LuaInstance::GetState(internalState); - - std::shared_ptr& info = *static_cast*>(state.ToUserdata(state.GetIndexOfUpValue(1))); - - state.PushString(info->name); - return 1; - } -} - -#include diff --git a/include/Nazara/Lua/LuaCoroutine.hpp b/include/Nazara/Lua/LuaCoroutine.hpp deleted file mode 100644 index 753aa8a4f..000000000 --- a/include/Nazara/Lua/LuaCoroutine.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_LUACOROUTINE_HPP -#define NAZARA_LUACOROUTINE_HPP - -#include -#include - -namespace Nz -{ - class NAZARA_LUA_API LuaCoroutine : public LuaState - { - friend class LuaState; - - public: - LuaCoroutine(const LuaCoroutine&) = delete; - inline LuaCoroutine(LuaCoroutine&& instance); - ~LuaCoroutine(); - - bool CanResume() const; - - Ternary Resume(unsigned int argCount = 0); - - LuaCoroutine& operator=(const LuaCoroutine&) = delete; - inline LuaCoroutine& operator=(LuaCoroutine&& instance); - - private: - LuaCoroutine(lua_State* internalState, int refIndex); - - bool Run(int argCount, int resultCount, int errHandler) override; - - int m_ref; - }; -} - -#include - -#endif // NAZARA_LUACOROUTINE_HPP diff --git a/include/Nazara/Lua/LuaCoroutine.inl b/include/Nazara/Lua/LuaCoroutine.inl deleted file mode 100644 index 43a3f87cb..000000000 --- a/include/Nazara/Lua/LuaCoroutine.inl +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -namespace Nz -{ - inline LuaCoroutine::LuaCoroutine(LuaCoroutine&& instance) : - LuaState(std::move(instance)), - m_ref(instance.m_ref) - { - instance.m_ref = -1; - } - - inline LuaCoroutine& LuaCoroutine::operator=(LuaCoroutine&& instance) - { - LuaState::operator=(std::move(instance)); - - std::swap(m_ref, instance.m_ref); - - return *this; - } -} diff --git a/include/Nazara/Lua/LuaInstance.hpp b/include/Nazara/Lua/LuaInstance.hpp deleted file mode 100644 index c45a77a94..000000000 --- a/include/Nazara/Lua/LuaInstance.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_LUAINSTANCE_HPP -#define NAZARA_LUAINSTANCE_HPP - -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_LUA_API LuaInstance : public LuaState - { - friend class LuaCoroutine; - friend class LuaState; - - public: - LuaInstance(); - LuaInstance(const LuaInstance&) = delete; - LuaInstance(LuaInstance&& instance); - ~LuaInstance(); - - inline std::size_t GetMemoryLimit() const; - inline std::size_t GetMemoryUsage() const; - inline UInt32 GetTimeLimit() const; - - void LoadLibraries(LuaLibFlags libFlags = LuaLib_All); - - inline void SetMemoryLimit(std::size_t memoryLimit); - inline void SetTimeLimit(UInt32 limit); - - LuaInstance& operator=(const LuaInstance&) = delete; - LuaInstance& operator=(LuaInstance&& instance); - - private: - inline void SetMemoryUsage(std::size_t memoryUsage); - - static void* MemoryAllocator(void *ud, void *ptr, std::size_t osize, std::size_t nsize); - static void TimeLimiter(lua_State* internalState, lua_Debug* debug); - - std::size_t m_memoryLimit; - std::size_t m_memoryUsage; - UInt32 m_timeLimit; - Clock m_clock; - unsigned int m_level; - }; -} - -#include - -#endif // NAZARA_LUAINSTANCE_HPP diff --git a/include/Nazara/Lua/LuaInstance.inl b/include/Nazara/Lua/LuaInstance.inl deleted file mode 100644 index 21d9b061e..000000000 --- a/include/Nazara/Lua/LuaInstance.inl +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include - -namespace Nz -{ - inline std::size_t LuaInstance::GetMemoryLimit() const - { - return m_memoryLimit; - } - - inline std::size_t LuaInstance::GetMemoryUsage() const - { - return m_memoryUsage; - } - - inline UInt32 LuaInstance::GetTimeLimit() const - { - return m_timeLimit; - } - - inline void LuaInstance::SetMemoryLimit(std::size_t memoryLimit) - { - m_memoryLimit = memoryLimit; - } - - inline void LuaInstance::SetTimeLimit(UInt32 limit) - { - m_timeLimit = limit; - } - - inline void LuaInstance::SetMemoryUsage(std::size_t memoryUsage) - { - m_memoryUsage = memoryUsage; - } -} - -#include diff --git a/include/Nazara/Lua/LuaState.hpp b/include/Nazara/Lua/LuaState.hpp deleted file mode 100644 index 8f401a6c3..000000000 --- a/include/Nazara/Lua/LuaState.hpp +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua scripting module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_LUASTATE_HPP -#define NAZARA_LUASTATE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct lua_Debug; -struct lua_State; - -namespace Nz -{ - class LuaCoroutine; - class LuaInstance; - class LuaState; - class Stream; - - using LuaCFunction = int (*)(lua_State* internalState); - using LuaFunction = std::function; - - class NAZARA_LUA_API LuaState - { - public: - LuaState(const LuaState&) = default; - LuaState(LuaState&& instance) = default; - ~LuaState() = default; - - 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); - bool CallWithHandler(unsigned int argCount, int errorHandler); - bool CallWithHandler(unsigned int argCount, unsigned int resultCount, int errorHandler); - - template T Check(int* index) const; - template T Check(int* index, T defValue) const; - void CheckAny(int index) const; - bool CheckBoolean(int index) const; - bool CheckBoolean(int index, bool defValue) const; - template T CheckBoundInteger(int index) const; - template T CheckBoundInteger(int index, T defValue) const; - template T CheckField(const char* fieldName, int tableIndex = -1) const; - template T CheckField(const String& fieldName, int tableIndex = -1) const; - template T CheckField(const char* fieldName, T defValue, int tableIndex = -1) const; - template T CheckField(const String& fieldName, T defValue, int tableIndex = -1) const; - long long CheckInteger(int index) const; - long long CheckInteger(int index, long long defValue) const; - template T CheckGlobal(const char* fieldName) const; - template T CheckGlobal(const String& fieldName) const; - template T CheckGlobal(const char* fieldName, T defValue) const; - template T CheckGlobal(const String& fieldName, T defValue) const; - double CheckNumber(int index) const; - double CheckNumber(int index, double defValue) const; - void CheckStack(int space, const char* error = nullptr) const; - void CheckStack(int space, const String& error) const; - const char* CheckString(int index, std::size_t* length = nullptr) const; - const char* CheckString(int index, const char* defValue, std::size_t* length = nullptr) const; - void CheckType(int index, LuaType type) const; - void* CheckUserdata(int index, const char* tname) const; - void* CheckUserdata(int index, const String& tname) const; - - bool Compare(int index1, int index2, LuaComparison comparison) const; - void Compute(LuaOperation operation) const; - - void Concatenate(int count) const; - - int CreateReference(); - void DestroyReference(int ref); - - String DumpStack() const; - - void Error(const char* message) const; - void Error(const String& message) const; - - bool Execute(const String& code, int errorHandler = 0); - bool ExecuteFromFile(const std::filesystem::path& filePath, int errorHandler = 0); - bool ExecuteFromMemory(const void* data, std::size_t size, int errorHandler = 0); - bool ExecuteFromStream(Stream& stream, int errorHandler = 0); - - int GetAbsIndex(int index) const; - LuaType GetField(const char* fieldName, int tableIndex = -1) const; - LuaType GetField(const String& fieldName, int tableIndex = -1) const; - LuaType GetGlobal(const char* name) const; - LuaType GetGlobal(const String& name) const; - inline lua_State* GetInternalState() const; - inline String GetLastError() const; - LuaType GetMetatable(const char* tname) const; - LuaType GetMetatable(const String& tname) const; - bool GetMetatable(int index) const; - unsigned int GetStackTop() const; - LuaType GetTable(int index = -2) const; - LuaType GetTableRaw(int index = -2) const; - LuaType GetType(int index) const; - const char* GetTypeName(LuaType type) const; - - void Insert(int index) const; - - bool IsOfType(int index, LuaType type) const; - bool IsOfType(int index, const char* tname) const; - bool IsOfType(int index, const String& tname) const; - bool IsValid(int index) const; - - bool Load(const String& code); - bool LoadFromFile(const std::filesystem::path& filePath); - bool LoadFromMemory(const void* data, std::size_t size); - bool LoadFromStream(Stream& stream); - - long long Length(int index) const; - std::size_t LengthRaw(int index) const; - - void MoveTo(LuaState* instance, int n) const; - - LuaCoroutine NewCoroutine(); - bool NewMetatable(const char* str); - bool NewMetatable(const String& str); - bool Next(int index = -2) const; - - 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; - template void PushField(const String& name, T&& arg, int tableIndex = -2) const; - void PushFunction(LuaFunction func) const; - template void PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const; - template void PushGlobal(const char* name, T&& arg); - template void PushGlobal(const String& name, T&& arg); - template void PushInstance(const char* tname, T&& instance) const; - template void PushInstance(const char* tname, Args&&... args) const; - void PushInteger(long long value) const; - void PushLightUserdata(void* value) const; - void PushMetatable(const char* str) const; - void PushMetatable(const String& str) const; - void PushNil() const; - void PushNumber(double value) const; - void PushReference(int ref) const; - void PushString(const char* str) const; - void PushString(const char* str, std::size_t size) const; - void PushString(const String& str) const; - void PushTable(std::size_t sequenceElementCount = 0, std::size_t arrayElementCount = 0) const; - void* PushUserdata(std::size_t size) const; - void PushValue(int index) const; - - bool RawEqual(int index1, int index2) const; - - void Remove(int index) const; - void Replace(int index) const; - - void SetField(const char* name, int tableIndex = -2) const; - void SetField(const String& name, int tableIndex = -2) const; - void SetGlobal(const char* name); - void SetGlobal(const String& name); - void SetMetatable(const char* tname) const; - void SetMetatable(const String& tname) const; - void SetMetatable(int index) const; - void SetTable(int index = -3) const; - void SetTableRaw(int index = -3) const; - - bool ToBoolean(int index) const; - long long ToInteger(int index, bool* succeeded = nullptr) const; - double ToNumber(int index, bool* succeeded = nullptr) const; - const void* ToPointer(int index) const; - const char* ToString(int index, std::size_t* length = nullptr) const; - void* ToUserdata(int index) const; - void* ToUserdata(int index, const char* tname) const; - void* ToUserdata(int index, const String& tname) const; - - void Traceback(const char* message = nullptr, int level = 0); - - LuaState& operator=(const LuaState&) = default; - LuaState& operator=(LuaState&& instance) = default; - - static int GetIndexOfUpValue(int upValue); - static LuaInstance& GetInstance(lua_State* internalState); - static inline LuaState GetState(lua_State* internalState); - - protected: - LuaState(lua_State* internalState); - - template std::enable_if_t::value, T> CheckBounds(int index, long long value) const; - template std::enable_if_t::value, T> CheckBounds(int index, long long value) const; - virtual bool Run(int argCount, int resultCount, int errHandler); - - static int ProxyFunc(lua_State* internalState); - - MovablePtr m_state; - String m_lastError; - }; -} - -#include - -#endif // NAZARA_LUASTATE_HPP diff --git a/include/Nazara/Lua/LuaState.inl b/include/Nazara/Lua/LuaState.inl deleted file mode 100644 index a3a71ef65..000000000 --- a/include/Nazara/Lua/LuaState.inl +++ /dev/null @@ -1,843 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// 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 -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - inline LuaState::LuaState(lua_State* internalState) : - m_state(internalState) - { - } - - inline lua_State* LuaState::GetInternalState() const - { - return m_state; - } - - inline String LuaState::GetLastError() const - { - return m_lastError; - } - - // Functions args - inline unsigned int LuaImplQueryArg(const LuaState& instance, int index, bool* arg, TypeTag) - { - *arg = instance.CheckBoolean(index); - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& instance, int index, bool* arg, bool defValue, TypeTag) - { - *arg = instance.CheckBoolean(index, defValue); - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& instance, int index, std::filesystem::path* arg, TypeTag) - { - std::size_t strLength = 0; - const char* str = instance.CheckString(index, &strLength); - - arg->assign(std::string_view(str, strLength)); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& instance, int index, std::string* arg, TypeTag) - { - std::size_t strLength = 0; - const char* str = instance.CheckString(index, &strLength); - - arg->assign(str, strLength); - - return 1; - } - - inline unsigned int LuaImplQueryArg(const LuaState& instance, int index, String* arg, TypeTag) - { - std::size_t strLength = 0; - const char* str = instance.CheckString(index, &strLength); - - arg->Set(str, strLength); - - return 1; - } - - template - std::enable_if_t::value && !IsEnumFlag::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag) - { - using UnderlyingT = std::underlying_type_t; - return LuaImplQueryArg(instance, index, reinterpret_cast(arg), TypeTag()); - } - - template - std::enable_if_t::value && !IsEnumFlag::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, T defValue, TypeTag) - { - using UnderlyingT = std::underlying_type_t; - return LuaImplQueryArg(instance, index, reinterpret_cast(arg), static_cast(defValue), TypeTag()); - } - - template - std::enable_if_t::value && IsEnumFlag::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag) - { - using UnderlyingT = std::underlying_type_t; - - UnderlyingT pot2Val; - unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, TypeTag()); - - *arg = static_cast(IntegralLog2Pot(pot2Val)); - return ret; - } - - template - std::enable_if_t::value && IsEnumFlag::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, T defValue, TypeTag) - { - using UnderlyingT = std::underlying_type_t; - - UnderlyingT pot2Val; - unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, 1U << static_cast(defValue), TypeTag()); - - *arg = static_cast(IntegralLog2Pot(pot2Val)); - return ret; - } - - template - unsigned int LuaImplQueryArg(const LuaState& instance, int index, Flags* arg, TypeTag>) - { - *arg = Flags(instance.CheckBoundInteger(index)); - return 1; - } - - template - std::enable_if_t::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag) - { - *arg = static_cast(instance.CheckNumber(index)); - return 1; - } - - template - std::enable_if_t::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, T defValue, TypeTag) - { - *arg = static_cast(instance.CheckNumber(index, static_cast(defValue))); - return 1; - } - - template - std::enable_if_t::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag) - { - *arg = instance.CheckBoundInteger(index); - return 1; - } - - template - std::enable_if_t::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, T defValue, TypeTag) - { - *arg = instance.CheckBoundInteger(index, defValue); - return 1; - } - - template - std::enable_if_t::value && !std::is_enum::value && !std::is_floating_point::value, unsigned int> LuaImplQueryArg(const LuaState& instance, int index, T* arg, const T& defValue, TypeTag tag) - { - if (instance.IsValid(index)) - return LuaImplQueryArg(instance, index, arg, tag); - else - { - *arg = defValue; - return 1; - } - } - - template - unsigned int LuaImplQueryArg(const LuaState& instance, int index, T* arg, TypeTag) - { - return LuaImplQueryArg(instance, index, arg, TypeTag()); - } - - template - unsigned int LuaImplQueryArg(const LuaState& instance, int index, T* arg, const T& defValue, TypeTag) - { - return LuaImplQueryArg(instance, index, arg, defValue, TypeTag()); - } - - template - unsigned int LuaImplQueryArg(const LuaState& instance, int index, std::vector* container, TypeTag>) - { - instance.CheckType(index, Nz::LuaType_Table); - std::size_t pos = 1; - - container->clear(); - for (;;) - { - Nz::CallOnExit popStack { [&instance]() { instance.Pop(); } }; - instance.PushInteger(pos++); - - int tableIndex = (index < 0) ? index - 1 : index; - if (instance.GetTable(tableIndex) == Nz::LuaType_Nil) - break; - - T arg; - if (LuaImplQueryArg(instance, -1, &arg, TypeTag()) != 1) - { - instance.Error("Type needs more than one place to be initialized"); - return 0; - } - - container->push_back(arg); - } - - return 1; - } - - // Function returns - inline int LuaImplReplyVal(const LuaState& instance, bool val, TypeTag) - { - instance.PushBoolean(val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& instance, double val, TypeTag) - { - instance.PushNumber(val); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& instance, float val, TypeTag) - { - instance.PushNumber(val); - return 1; - } - - template - std::enable_if_t::value && !IsEnumFlag::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag) - { - using EnumT = typename std::underlying_type::type; - return LuaImplReplyVal(instance, static_cast(val), TypeTag()); - } - - template - std::enable_if_t::value && IsEnumFlag::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag) - { - Flags flags(val); - return LuaImplReplyVal(instance, flags, TypeTag()); - } - - template - int LuaImplReplyVal(const LuaState& instance, Flags val, TypeTag>) - { - instance.PushInteger(typename Flags::BitField(val)); - return 1; - } - - template - std::enable_if_t::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag) - { - instance.PushInteger(val); - return 1; - } - - template - std::enable_if_t::value || std::is_enum::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag) - { - return LuaImplReplyVal(instance, val, TypeTag()); - } - - template - std::enable_if_t::value || std::is_enum::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag) - { - return LuaImplReplyVal(instance, val, TypeTag()); - } - - template - std::enable_if_t::value && !std::is_enum::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag) - { - return LuaImplReplyVal(instance, std::move(val), TypeTag()); - } - - template - std::enable_if_t::value && !std::is_enum::value, int> LuaImplReplyVal(const LuaState& instance, T val, TypeTag) - { - return LuaImplReplyVal(instance, std::move(val), TypeTag()); - } - - template - int LuaImplReplyVal(const LuaState& instance, T&& val, TypeTag) - { - return LuaImplReplyVal(instance, std::forward(val), TypeTag()); - } - - inline int LuaImplReplyVal(const LuaState& instance, std::string&& val, TypeTag) - { - instance.PushString(val.c_str(), val.size()); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& instance, std::filesystem::path&& val, TypeTag) - { - return LuaImplReplyVal(instance, val.generic_u8string(), TypeTag()); - } - - template - inline int LuaImplReplyVal(const LuaState& instance, std::vector&& valContainer, TypeTag>) - { - std::size_t index = 1; - instance.PushTable(valContainer.size()); - for (T& val : valContainer) - { - instance.PushInteger(index++); - if (LuaImplReplyVal(instance, std::move(val), TypeTag()) != 1) - { - instance.Error("Couldn't create table: type need more than one place to store"); - return 0; - } - instance.SetTable(); - } - - return 1; - } - - inline int LuaImplReplyVal(const LuaState& instance, ByteArray&& val, TypeTag) - { - instance.PushString(reinterpret_cast(val.GetConstBuffer()), val.GetSize()); - return 1; - } - - inline int LuaImplReplyVal(const LuaState& instance, String&& val, TypeTag) - { - instance.PushString(std::move(val)); - return 1; - } - - template - int LuaImplReplyVal(const LuaState& instance, std::pair&& val, TypeTag>) - { - int retVal = 0; - - retVal += LuaImplReplyVal(instance, std::move(val.first), TypeTag()); - retVal += LuaImplReplyVal(instance, std::move(val.second), TypeTag()); - - return retVal; - } - - template - struct LuaImplArgProcesser; - - template<> - struct LuaImplArgProcesser - { - template - static unsigned int Process(const LuaState& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs) - { - return LuaImplQueryArg(instance, argIndex, &std::get(args), std::get() - N - 1>(defArgs), TypeTag()); - } - }; - - template<> - struct LuaImplArgProcesser - { - template - static unsigned int Process(const LuaState& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs) - { - NazaraUnused(defArgs); - - return LuaImplQueryArg(instance, argIndex, &std::get(args), TypeTag()); - } - }; - - template - class LuaImplFunctionProxy - { - public: - template - class Impl - { - static constexpr std::size_t ArgCount = sizeof...(Args); - static constexpr std::size_t DefArgCount = sizeof...(DefArgs); - - static_assert(ArgCount >= DefArgCount, "There cannot be more default arguments than argument"); - - static constexpr std::size_t FirstDefArg = ArgCount - DefArgCount; - - public: - Impl(DefArgs... defArgs) : - m_defaultArgs(std::forward(defArgs)...) - { - } - - void ProcessArguments(const LuaState& instance) const - { - m_index = 1; - ProcessArgs<0, Args...>(instance); - } - - int Invoke(const LuaState& instance, void(*func)(Args...)) const - { - NazaraUnused(instance); - - Apply(func, m_args); - return 0; - } - - template - int Invoke(const LuaState& instance, Ret(*func)(Args...)) const - { - return LuaImplReplyVal(instance, std::move(Apply(func, m_args)), TypeTag()); - } - - private: - using ArgContainer = std::tuple>...>; - using DefArgContainer = std::tuple>...>; - - template - void ProcessArgs(const LuaState& instance) const - { - NazaraUnused(instance); - - // No argument to process - } - - template - void ProcessArgs(const LuaState& instance) const - { - LuaImplArgProcesser<(N >= FirstDefArg)>::template Process(instance, m_index, m_args, m_defaultArgs); - } - - template - void ProcessArgs(const LuaState& instance) const - { - ProcessArgs(instance); - ProcessArgs(instance); - } - - mutable ArgContainer m_args; - DefArgContainer m_defaultArgs; - mutable unsigned int m_index; - }; - }; - - template - class LuaImplMethodProxy - { - public: - template - class Impl - { - static constexpr std::size_t ArgCount = sizeof...(Args); - static constexpr std::size_t DefArgCount = sizeof...(DefArgs); - - static_assert(ArgCount >= DefArgCount, "There cannot be more default arguments than argument"); - - static constexpr std::size_t FirstDefArg = ArgCount - DefArgCount; - - public: - Impl(DefArgs... defArgs) : - m_defaultArgs(std::forward(defArgs)...) - { - } - - void ProcessArguments(const LuaState& instance) const - { - m_index = 2; //< 1 being the instance - ProcessArgs<0, Args...>(instance); - } - - template - std::enable_if_t::value, int> Invoke(const LuaState& instance, T& object, void(P::*func)(Args...)) const - { - NazaraUnused(instance); - - Apply(object, func, m_args); - return 0; - } - - template - std::enable_if_t::value, int> Invoke(const LuaState& instance, T& object, Ret(P::*func)(Args...)) const - { - return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag()); - } - - template - std::enable_if_t::value, int> Invoke(const LuaState& 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 LuaState& instance, const T& object, void(P::*func)(Args...) const) const - { - NazaraUnused(instance); - - Apply(object, func, m_args); - return 0; - } - - template - std::enable_if_t::value, int> Invoke(const LuaState& instance, const T& object, Ret(P::*func)(Args...) const) const - { - return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag()); - } - - template - std::enable_if_t::value, int> Invoke(const LuaState& 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 LuaState& instance, T& object, void(P::*func)(Args...)) const - { - if (!object) - { - instance.Error("Invalid object"); - return 0; - } - - Apply(*object, func, m_args); - return 0; - } - - template - std::enable_if_t::type>::value, int> Invoke(const LuaState& instance, T& object, Ret(P::*func)(Args...)) const - { - if (!object) - { - instance.Error("Invalid object"); - return 0; - } - - return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag()); - } - - template - std::enable_if_t::type>::value, int> Invoke(const LuaState& 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 LuaState& instance, const T& object, void(P::*func)(Args...) const) const - { - if (!object) - { - instance.Error("Invalid object"); - return 0; - } - - Apply(*object, func, m_args); - return 0; - } - - template - std::enable_if_t::type>::value, int> Invoke(const LuaState& instance, const T& object, Ret(P::*func)(Args...) const) const - { - if (!object) - { - instance.Error("Invalid object"); - return 0; - } - - return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag()); - } - - template - std::enable_if_t::type>::value, int> Invoke(const LuaState& 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>...>; - - template - void ProcessArgs(const LuaState& instance) const - { - NazaraUnused(instance); - - // No argument to process - } - - template - void ProcessArgs(const LuaState& instance) const - { - m_index += LuaImplArgProcesser<(N >= FirstDefArg)>::template Process(instance, m_index, m_args, m_defaultArgs); - } - - template - void ProcessArgs(const LuaState& instance) const - { - ProcessArgs(instance); - ProcessArgs(instance); - } - - mutable ArgContainer m_args; - DefArgContainer m_defaultArgs; - mutable unsigned int m_index; - }; - }; - - template - T LuaState::Check(int* index) const - { - NazaraAssert(index, "Invalid index pointer"); - - T object; - *index += LuaImplQueryArg(*this, *index, &object, TypeTag()); - - return object; - } - - template - T LuaState::Check(int* index, T defValue) const - { - NazaraAssert(index, "Invalid index pointer"); - - T object; - *index += LuaImplQueryArg(*this, *index, &object, defValue, TypeTag()); - - return object; - } - - template - inline T LuaState::CheckBoundInteger(int index) const - { - return CheckBounds(index, CheckInteger(index)); - } - - template - inline T LuaState::CheckBoundInteger(int index, T defValue) const - { - return CheckBounds(index, CheckInteger(index, defValue)); - } - - template - T LuaState::CheckField(const char* fieldName, int tableIndex) const - { - T object; - - GetField(fieldName, tableIndex); - tableIndex += LuaImplQueryArg(*this, -1, &object, TypeTag()); - Pop(); - - return object; - } - - template - T LuaState::CheckField(const String& fieldName, int tableIndex) const - { - return CheckField(fieldName.GetConstBuffer(), tableIndex); - } - - template - T LuaState::CheckField(const char* fieldName, T defValue, int tableIndex) const - { - T object; - - GetField(fieldName, tableIndex); - tableIndex += LuaImplQueryArg(*this, -1, &object, defValue, TypeTag()); - Pop(); - - return object; - } - - template - T LuaState::CheckField(const String& fieldName, T defValue, int tableIndex) const - { - return CheckField(fieldName.GetConstBuffer(), defValue, tableIndex); - } - - template - T LuaState::CheckGlobal(const char* fieldName) const - { - T object; - - GetGlobal(fieldName); - LuaImplQueryArg(*this, -1, &object, TypeTag()); - Pop(); - - return object; - } - - template - T LuaState::CheckGlobal(const String& fieldName) const - { - return CheckGlobal(fieldName.GetConstBuffer()); - } - - template - T LuaState::CheckGlobal(const char* fieldName, T defValue) const - { - T object; - - GetGlobal(fieldName); - LuaImplQueryArg(*this, -1, &object, defValue, TypeTag()); - Pop(); - - return object; - } - - template - T LuaState::CheckGlobal(const String& fieldName, T defValue) const - { - return CheckGlobal(fieldName.GetConstBuffer(), defValue); - } - - template - int LuaState::Push(T arg) const - { - return LuaImplReplyVal(*this, std::move(arg), TypeTag()); - } - - template - int LuaState::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 LuaState::PushField(const char* name, T&& arg, int tableIndex) const - { - Push(std::forward(arg)); - SetField(name, tableIndex); - } - - template - void LuaState::PushField(const String& name, T&& arg, int tableIndex) const - { - PushField(name.GetConstBuffer(), std::forward(arg), tableIndex); - } - - template - void LuaState::PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const - { - typename LuaImplFunctionProxy::template Impl handler(std::forward(defArgs)...); - - PushFunction([func, handler] (LuaState& lua) -> int - { - handler.ProcessArguments(lua); - - return handler.Invoke(lua, func); - }); - } - - template - void LuaState::PushGlobal(const char* name, T&& arg) - { - Push(std::forward(arg)); - SetGlobal(name); - } - - template - void LuaState::PushGlobal(const String& name, T&& arg) - { - PushGlobal(name.GetConstBuffer(), std::forward(arg)); - } - - template - void LuaState::PushInstance(const char* tname, T&& instance) const - { - T* userdata = static_cast(PushUserdata(sizeof(T))); - PlacementNew(userdata, std::move(instance)); - - SetMetatable(tname); - } - - template - void LuaState::PushInstance(const char* tname, Args&&... args) const - { - T* userdata = static_cast(PushUserdata(sizeof(T))); - PlacementNew(userdata, std::forward(args)...); - - SetMetatable(tname); - } - - template - std::enable_if_t::value, T> LuaState::CheckBounds(int index, long long value) const - { - constexpr long long minBounds = std::numeric_limits::min(); - constexpr long long maxBounds = std::numeric_limits::max(); - if (value < minBounds || value > maxBounds) - { - Nz::StringStream stream; - stream << "Argument #" << index << " is outside value range [" << minBounds << ", " << maxBounds << "] (" << value << ')'; - Error(stream); - } - - return static_cast(value); - } - - template - std::enable_if_t::value, T> LuaState::CheckBounds(int index, long long value) const - { - unsigned long long uValue = static_cast(value); - constexpr unsigned long long minBounds = 0; - constexpr unsigned long long maxBounds = std::numeric_limits::max(); - if (uValue < minBounds || uValue > maxBounds) - { - Nz::StringStream stream; - stream << "Argument #" << index << " is outside value range [" << minBounds << ", " << maxBounds << "] (" << value << ')'; - Error(stream); - } - - return static_cast(uValue); - } - - inline LuaState LuaState::GetState(lua_State* internalState) - { - return LuaState(internalState); - } -} diff --git a/include/Nazara/Noise.hpp b/include/Nazara/Noise.hpp deleted file mode 100644 index f8ecfb82e..000000000 --- a/include/Nazara/Noise.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// This file was automatically generated - -/* - Nazara Engine - Noise module - - Copyright (C) 2016 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_GLOBAL_NOISE_HPP -#define NAZARA_GLOBAL_NOISE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif // NAZARA_GLOBAL_NOISE_HPP diff --git a/include/Nazara/Noise/Config.hpp b/include/Nazara/Noise/Config.hpp deleted file mode 100644 index afe6d577e..000000000 --- a/include/Nazara/Noise/Config.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - Nazara Engine - Noise module - - Copyright (C) 2016 Rémi "Overdrivr" Bèges (remi.beges@laposte.net) - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef NAZARA_CONFIG_NOISE_HPP -#define NAZARA_CONFIG_NOISE_HPP - -/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci - -// Utilise un manager de mémoire pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes) -#define NAZARA_NOISE_MANAGE_MEMORY 0 - -// Active les tests de sécurité basés sur le code (Conseillé pour le développement) -#define NAZARA_NOISE_SAFE 1 - -/// Vérification des valeurs et types de certaines constantes -#include - -#if defined(NAZARA_STATIC) - #define NAZARA_NOISE_API -#else - #ifdef NAZARA_NOISE_BUILD - #define NAZARA_NOISE_API NAZARA_EXPORT - #else - #define NAZARA_NOISE_API NAZARA_IMPORT - #endif -#endif - -#endif // NAZARA_CONFIG_MODULENAME_HPP diff --git a/include/Nazara/Noise/ConfigCheck.hpp b/include/Nazara/Noise/ConfigCheck.hpp deleted file mode 100644 index 93a90e13f..000000000 --- a/include/Nazara/Noise/ConfigCheck.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_CONFIG_CHECK_NOISE_HPP -#define NAZARA_CONFIG_CHECK_NOISE_HPP - -/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp - -// On force la valeur de MANAGE_MEMORY en mode debug -#if defined(NAZARA_DEBUG) && !NAZARA_NOISE_MANAGE_MEMORY - #undef NAZARA_NOISE_MANAGE_MEMORY - #define NAZARA_NOISE_MANAGE_MEMORY 0 -#endif - -#endif // NAZARA_CONFIG_CHECK_NOISE_HPP diff --git a/include/Nazara/Noise/Debug.hpp b/include/Nazara/Noise/Debug.hpp deleted file mode 100644 index 4068c5a95..000000000 --- a/include/Nazara/Noise/Debug.hpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_NOISE_MANAGE_MEMORY - #include -#endif diff --git a/include/Nazara/Noise/DebugOff.hpp b/include/Nazara/Noise/DebugOff.hpp deleted file mode 100644 index a0ca07927..000000000 --- a/include/Nazara/Noise/DebugOff.hpp +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp -#if NAZARA_NOISE_MANAGE_MEMORY - #undef delete - #undef new -#endif diff --git a/include/Nazara/Noise/Enums.hpp b/include/Nazara/Noise/Enums.hpp deleted file mode 100644 index fdc2b7ec3..000000000 --- a/include/Nazara/Noise/Enums.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_ENUMS_NOISE_HPP -#define NAZARA_ENUMS_NOISE_HPP - -namespace Nz -{ - enum WorleyFunction - { - WorleyFunction_F1 = 0, - WorleyFunction_F2 = 1, - WorleyFunction_F3 = 2, - WorleyFunction_F4 = 3 - }; -} -#endif // NAZARA_ENUMS_NOISE_HPP diff --git a/include/Nazara/Noise/FBM.hpp b/include/Nazara/Noise/FBM.hpp deleted file mode 100644 index 743ab41fc..000000000 --- a/include/Nazara/Noise/FBM.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_FBM_HPP -#define NAZARA_FBM_HPP - -#include -#include - -namespace Nz -{ - class NAZARA_NOISE_API FBM : public MixerBase - { - public: - FBM(const NoiseBase& source); - FBM(const FBM&) = delete; - ~FBM() = default; - - float Get(float x, float y, float scale) const override; - float Get(float x, float y, float z, float scale) const override; - float Get(float x, float y, float z, float w, float scale) const override; - - FBM& operator=(const FBM&) = delete; - - private: - const NoiseBase& m_source; - }; -} - -#endif // NAZARA_FBM_HPP diff --git a/include/Nazara/Noise/HybridMultiFractal.hpp b/include/Nazara/Noise/HybridMultiFractal.hpp deleted file mode 100644 index da2456e40..000000000 --- a/include/Nazara/Noise/HybridMultiFractal.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_HYBRIDMULTIFRACTAL_HPP -#define NAZARA_HYBRIDMULTIFRACTAL_HPP - -#include -#include - -namespace Nz -{ - class NAZARA_NOISE_API HybridMultiFractal : public MixerBase - { - public: - HybridMultiFractal(const NoiseBase & source); - HybridMultiFractal(const HybridMultiFractal&) = delete; - ~HybridMultiFractal() = default; - - float Get(float x, float y, float scale) const override; - float Get(float x, float y, float z, float scale) const override; - float Get(float x, float y, float z, float w, float scale) const override; - - HybridMultiFractal& operator=(const HybridMultiFractal&) = delete; - - private: - const NoiseBase& m_source; - }; -} - -#endif // NAZARA_HYBRIDMULTIFRACTAL_HPP diff --git a/include/Nazara/Noise/MixerBase.hpp b/include/Nazara/Noise/MixerBase.hpp deleted file mode 100644 index f509c0493..000000000 --- a/include/Nazara/Noise/MixerBase.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_MIXERBASE_HPP -#define NAZARA_MIXERBASE_HPP - -#include -#include - -namespace Nz -{ - class NAZARA_NOISE_API MixerBase - { - public: - MixerBase(); - virtual ~MixerBase() = default; - - virtual float Get(float x, float y, float scale) const = 0; - virtual float Get(float x, float y, float z, float scale) const = 0; - virtual float Get(float x, float y, float z, float w, float scale) const = 0; - - float GetHurstParameter() const; - float GetLacunarity() const; - float GetOctaveNumber() const; - - void SetParameters(float hurst, float lacunarity, float octaves); - - protected: - float m_hurst; - float m_lacunarity; - float m_octaves; - std::vector m_exponent_array; - float m_sum; - - private: - void Recompute(); - }; -} - -#endif // NAZARA_MIXERBASE_HPP diff --git a/include/Nazara/Noise/Noise.hpp b/include/Nazara/Noise/Noise.hpp deleted file mode 100644 index eb27d1a26..000000000 --- a/include/Nazara/Noise/Noise.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_NOISE_HPP -#define NAZARA_NOISE_HPP - -#include -#include - -namespace Nz -{ - class NAZARA_NOISE_API Noise - { - public: - Noise() = delete; - ~Noise() = delete; - - static bool Initialize(); - - static bool IsInitialized(); - - static void Uninitialize(); - - private: - static unsigned int s_moduleReferenceCounter; - }; -} - -#endif // NAZARA_NOISE_HPP diff --git a/include/Nazara/Noise/NoiseBase.hpp b/include/Nazara/Noise/NoiseBase.hpp deleted file mode 100644 index e19339316..000000000 --- a/include/Nazara/Noise/NoiseBase.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_NOISEBASE_HPP -#define NAZARA_NOISEBASE_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_NOISE_API NoiseBase - { - public: - NoiseBase(unsigned int seed = 0); - virtual ~NoiseBase() = default; - - virtual float Get(float x, float y, float scale) const = 0; - virtual float Get(float x, float y, float z, float scale) const = 0; - virtual float Get(float x, float y, float z, float w, float scale) const = 0; - float GetScale(); - - void SetScale(float scale); - void SetSeed(unsigned int seed); - - void Shuffle(); - - protected: - std::array m_permutations; - float m_scale; - - static std::array s_gradients2; - static std::array s_gradients3; - static std::array s_gradients4; - - private: - std::mt19937 m_randomEngine; - }; -} - -#endif // NAZARA_NOISEBASE_HPP diff --git a/include/Nazara/Noise/NoiseTools.hpp b/include/Nazara/Noise/NoiseTools.hpp deleted file mode 100644 index b3fd1bada..000000000 --- a/include/Nazara/Noise/NoiseTools.hpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_NOISETOOLS_HPP -#define NAZARA_NOISETOOLS_HPP - -namespace Nz -{ - int fastfloor(float n); - int JenkinsHash(int a, int b, int c); -} - -#endif // NAZARA_NOISETOOLS_HPP diff --git a/include/Nazara/Noise/Perlin.hpp b/include/Nazara/Noise/Perlin.hpp deleted file mode 100644 index 480af41bd..000000000 --- a/include/Nazara/Noise/Perlin.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_PERLIN_HPP -#define NAZARA_PERLIN_HPP - -#include -#include -#include - -namespace Nz -{ - class NAZARA_NOISE_API Perlin : public NoiseBase - { - public: - Perlin() = default; - Perlin(unsigned int seed); - ~Perlin() = default; - - float Get(float x, float y, float scale) const override; - float Get(float x, float y, float z, float scale) const override; - float Get(float x, float y, float z, float w, float scale) const override; - }; -} - -#endif // NAZARA_PERLIN_HPP diff --git a/include/Nazara/Noise/Simplex.hpp b/include/Nazara/Noise/Simplex.hpp deleted file mode 100644 index cbe037821..000000000 --- a/include/Nazara/Noise/Simplex.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_SIMPLEX_HPP -#define NAZARA_SIMPLEX_HPP - -#include -#include -#include - -namespace Nz -{ - class NAZARA_NOISE_API Simplex : public NoiseBase - { - public: - Simplex() = default; - Simplex(unsigned int seed); - ~Simplex() = default; - - float Get(float x, float y, float scale) const override; - float Get(float x, float y, float z, float scale) const override; - float Get(float x, float y, float z, float w, float scale) const override; - }; -} - -#endif // NAZARA_SIMPLEX_HPP diff --git a/include/Nazara/Noise/Worley.hpp b/include/Nazara/Noise/Worley.hpp deleted file mode 100644 index 22e6b86e5..000000000 --- a/include/Nazara/Noise/Worley.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#ifndef NAZARA_WORLEY_HPP -#define NAZARA_WORLEY_HPP - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_NOISE_API Worley : public NoiseBase - { - public: - Worley(); - Worley(unsigned int seed); - ~Worley() = default; - - float Get(float x, float y, float scale) const override; - float Get(float x, float y, float z, float scale) const override; - float Get(float x, float y, float z, float w, float scale) const override; - - void Set(WorleyFunction func); - - private: - void SquareTest(int xi, int yi, float x, float y, std::map & featurePoints) const; - - WorleyFunction m_function; - }; -} - -#endif // NAZARA_WORLEY_HPP diff --git a/src/Nazara/Lua/Debug/NewOverload.cpp b/src/Nazara/Lua/Debug/NewOverload.cpp deleted file mode 100644 index 8c83e037e..000000000 --- a/src/Nazara/Lua/Debug/NewOverload.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Lua module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_LUA_MANAGE_MEMORY - -#include -#include // Nécessaire ? - -void* operator new(std::size_t size) -{ - return Nz::MemoryManager::Allocate(size, false); -} - -void* operator new[](std::size_t size) -{ - return Nz::MemoryManager::Allocate(size, true); -} - -void operator delete(void* pointer) noexcept -{ - Nz::MemoryManager::Free(pointer, false); -} - -void operator delete[](void* pointer) noexcept -{ - Nz::MemoryManager::Free(pointer, true); -} - -#endif // NAZARA_LUA_MANAGE_MEMORY diff --git a/src/Nazara/Lua/Lua.cpp b/src/Nazara/Lua/Lua.cpp deleted file mode 100644 index 83ec20a86..000000000 --- a/src/Nazara/Lua/Lua.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// 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 -#include -#include - -namespace Nz -{ - bool Lua::Initialize() - { - if (s_moduleReferenceCounter > 0) - { - s_moduleReferenceCounter++; - return true; // Déjà initialisé - } - - // Initialisation des dépendances - if (!Core::Initialize()) - { - NazaraError("Failed to initialize core module"); - return false; - } - - s_moduleReferenceCounter++; - - // Initialisation du module - - NazaraNotice("Initialized: Lua module"); - return true; - } - - bool Lua::IsInitialized() - { - return s_moduleReferenceCounter != 0; - } - - void Lua::Uninitialize() - { - if (s_moduleReferenceCounter != 1) - { - // Le module est soit encore utilisé, soit pas initialisé - if (s_moduleReferenceCounter > 1) - s_moduleReferenceCounter--; - - return; - } - - // Libération du module - s_moduleReferenceCounter = 0; - - NazaraNotice("Uninitialized: Lua module"); - - // Libération des dépendances - Core::Uninitialize(); - } - - unsigned int Lua::s_moduleReferenceCounter = 0; -} diff --git a/src/Nazara/Lua/LuaCoroutine.cpp b/src/Nazara/Lua/LuaCoroutine.cpp deleted file mode 100644 index ad3f40736..000000000 --- a/src/Nazara/Lua/LuaCoroutine.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// 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 - -namespace Nz -{ - LuaCoroutine::LuaCoroutine(lua_State* internalState, int refIndex) : - LuaState(internalState), - m_ref(refIndex) - { - } - - LuaCoroutine::~LuaCoroutine() - { - if (m_ref >= 0) - DestroyReference(m_ref); - } - - bool LuaCoroutine::CanResume() const - { - return lua_status(m_state) == LUA_YIELD; - } - - Ternary LuaCoroutine::Resume(unsigned int argCount) - { - LuaInstance& instance = GetInstance(m_state); - if (instance.m_level++ == 0) - instance.m_clock.Restart(); - - int status = lua_resume(m_state, nullptr, argCount); - instance.m_level--; - - if (status == LUA_OK) - return Ternary_True; - else if (status == LUA_YIELD) - return Ternary_Unknown; - else - { - m_lastError = ToString(-1); - Pop(); - return Ternary_False; - } - } - - bool LuaCoroutine::Run(int argCount, int /*resultCount*/, int /*errHandler*/) - { - return Resume(argCount) != Ternary_False; - } -} diff --git a/src/Nazara/Lua/LuaInstance.cpp b/src/Nazara/Lua/LuaInstance.cpp deleted file mode 100644 index eb9e4e48f..000000000 --- a/src/Nazara/Lua/LuaInstance.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// 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 -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - int AtPanic(lua_State* internalState) - { - String lastError(lua_tostring(internalState, -1)); - - throw std::runtime_error("Lua panic: " + lastError.ToStdString()); - } - } - - LuaInstance::LuaInstance() : - LuaState(nullptr), - m_memoryLimit(0), - m_memoryUsage(0), - m_timeLimit(1000), - m_level(0) - { - m_state = lua_newstate(MemoryAllocator, this); - lua_atpanic(m_state, AtPanic); - lua_sethook(m_state, TimeLimiter, LUA_MASKCOUNT, 1000); - } - - LuaInstance::LuaInstance(LuaInstance&& instance) : - LuaState(std::move(instance)) - { - std::swap(m_memoryLimit, instance.m_memoryLimit); - std::swap(m_memoryUsage, instance.m_memoryUsage); - std::swap(m_timeLimit, instance.m_timeLimit); - std::swap(m_clock, instance.m_clock); - std::swap(m_level, instance.m_level); - - if (m_state) - lua_setallocf(m_state, MemoryAllocator, this); - - if (instance.m_state) - lua_setallocf(instance.m_state, MemoryAllocator, &instance); - } - - LuaInstance::~LuaInstance() - { - if (m_state) - lua_close(m_state); - } - - void LuaInstance::LoadLibraries(LuaLibFlags libFlags) - { - // From luaL_openlibs - std::array libs; - std::size_t libCount = 0; - - libs[libCount++] = { "_G", luaopen_base }; - - if (libFlags & LuaLib_Coroutine) - libs[libCount++] = { LUA_COLIBNAME, luaopen_coroutine }; - - if (libFlags & LuaLib_Debug) - libs[libCount++] = { LUA_DBLIBNAME, luaopen_debug }; - - if (libFlags & LuaLib_Io) - libs[libCount++] = { LUA_IOLIBNAME, luaopen_io }; - - if (libFlags & LuaLib_Math) - libs[libCount++] = { LUA_MATHLIBNAME, luaopen_math }; - - if (libFlags & LuaLib_Os) - libs[libCount++] = { LUA_OSLIBNAME, luaopen_os }; - - if (libFlags & LuaLib_Package) - libs[libCount++] = { LUA_LOADLIBNAME, luaopen_package }; - - if (libFlags & LuaLib_String) - libs[libCount++] = { LUA_STRLIBNAME, luaopen_string }; - - if (libFlags & LuaLib_Table) - libs[libCount++] = { LUA_TABLIBNAME, luaopen_table }; - - if (libFlags & LuaLib_Utf8) - libs[libCount++] = { LUA_UTF8LIBNAME, luaopen_utf8 }; - - for (std::size_t i = 0; i < libCount; ++i) - { - luaL_requiref(m_state, libs[i].name, libs[i].func, 1); - lua_pop(m_state, 1); /* remove lib */ - } - } - - LuaInstance& LuaInstance::operator=(LuaInstance&& instance) - { - LuaState::operator=(std::move(instance)); - - std::swap(m_memoryLimit, instance.m_memoryLimit); - std::swap(m_memoryUsage, instance.m_memoryUsage); - std::swap(m_timeLimit, instance.m_timeLimit); - std::swap(m_clock, instance.m_clock); - std::swap(m_level, instance.m_level); - - if (m_state) - lua_setallocf(m_state, MemoryAllocator, this); - - if (instance.m_state) - lua_setallocf(instance.m_state, MemoryAllocator, &instance); - - return *this; - } - - void* LuaInstance::MemoryAllocator(void* ud, void* ptr, std::size_t osize, std::size_t nsize) - { - LuaInstance* instance = static_cast(ud); - std::size_t memoryLimit = instance->GetMemoryLimit(); - std::size_t memoryUsage = instance->GetMemoryUsage(); - - if (nsize == 0) - { - assert(memoryUsage >= osize); - - instance->SetMemoryUsage(memoryUsage - osize); - std::free(ptr); - - return nullptr; - } - else - { - std::size_t usage = memoryUsage + nsize; - if (ptr) - usage -= osize; - - if (memoryLimit != 0 && usage > memoryLimit) - { - NazaraError("Lua memory usage is over memory limit (" + String::Number(usage) + " > " + String::Number(memoryLimit) + ')'); - return nullptr; - } - - instance->SetMemoryUsage(usage); - - return std::realloc(ptr, nsize); - } - } - - void LuaInstance::TimeLimiter(lua_State* internalState, lua_Debug* debug) - { - NazaraUnused(debug); - - LuaInstance* instance; - lua_getallocf(internalState, reinterpret_cast(&instance)); - - if (instance->m_clock.GetMilliseconds() > instance->GetTimeLimit()) - luaL_error(internalState, "maximum execution time exceeded"); - } -} diff --git a/src/Nazara/Lua/LuaState.cpp b/src/Nazara/Lua/LuaState.cpp deleted file mode 100644 index c18367c30..000000000 --- a/src/Nazara/Lua/LuaState.cpp +++ /dev/null @@ -1,875 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// 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 -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - LuaType FromLuaType(int type) - { - switch (type) - { - case LUA_TBOOLEAN: - return LuaType_Boolean; - - case LUA_TFUNCTION: - return LuaType_Function; - - case LUA_TLIGHTUSERDATA: - return LuaType_LightUserdata; - - case LUA_TNIL: - return LuaType_Nil; - - case LUA_TNONE: - return LuaType_None; - - case LUA_TNUMBER: - return LuaType_Number; - - case LUA_TSTRING: - return LuaType_String; - - case LUA_TTABLE: - return LuaType_Table; - - case LUA_TTHREAD: - return LuaType_Thread; - - case LUA_TUSERDATA: - return LuaType_Userdata; - - default: - return LuaType_None; - } - } - - struct StreamData - { - Stream* stream; - char buffer[NAZARA_CORE_FILE_BUFFERSIZE]; - }; - - const char* StreamReader(lua_State* internalState, void* data, std::size_t* size) - { - NazaraUnused(internalState); - - StreamData* streamData = static_cast(data); - - if (streamData->stream->EndOfStream()) - return nullptr; - else - { - *size = streamData->stream->Read(streamData->buffer, NAZARA_CORE_FILE_BUFFERSIZE); - return streamData->buffer; - } - } - - int s_comparisons[] = { - LUA_OPEQ, // LuaComparison_Equality - LUA_OPLT, // LuaComparison_Less - LUA_OPLE // LuaComparison_LessOrEqual - }; - - static_assert(sizeof(s_comparisons)/sizeof(int) == LuaComparison_Max+1, "Lua comparison array is incomplete"); - - int s_operations[] = { - LUA_OPADD, // LuaOperation_Addition - LUA_OPBAND, // LuaOperation_BitwiseAnd - LUA_OPSHL, // LuaOperation_BitwiseLeftShift - LUA_OPBNOT, // LuaOperation_BitwiseNot - LUA_OPBOR, // LuaOperation_BitwiseOr - LUA_OPSHR, // LuaOperation_BitwiseRightShift - LUA_OPBXOR, // LuaOperation_BitwiseXOr - LUA_OPDIV, // LuaOperation_Division - LUA_OPPOW, // LuaOperation_Exponentiation - LUA_OPIDIV, // LuaOperation_FloorDivision - LUA_OPMUL, // LuaOperation_Multiplication - LUA_OPMOD, // LuaOperation_Modulo - LUA_OPUNM, // LuaOperation_Negation - LUA_OPSUB // LuaOperation_Substraction - }; - - static_assert(sizeof(s_operations)/sizeof(int) == LuaOperation_Max+1, "Lua operation array is incomplete"); - - int s_types[] = { - LUA_TBOOLEAN, // LuaType_Boolean - LUA_TFUNCTION, // LuaType_Function - LUA_TLIGHTUSERDATA, // LuaType_LightUserdata - LUA_TNIL, // LuaType_Nil - LUA_TNUMBER, // LuaType_Number - LUA_TNONE, // LuaType_None - LUA_TSTRING, // LuaType_String - LUA_TTABLE, // LuaType_Table - LUA_TTHREAD, // LuaType_Thread - LUA_TUSERDATA // LuaType_Userdata - }; - - static_assert(sizeof(s_types)/sizeof(int) == LuaType_Max+1, "Lua type array is incomplete"); - } - - void LuaState::ArgCheck(bool condition, unsigned int argNum, const char* error) const - { - luaL_argcheck(m_state, condition, argNum, error); - } - - void LuaState::ArgCheck(bool condition, unsigned int argNum, const String& error) const - { - luaL_argcheck(m_state, condition, argNum, error.GetConstBuffer()); - } - - int LuaState::ArgError(unsigned int argNum, const char* error) const - { - return luaL_argerror(m_state, argNum, error); - } - - int LuaState::ArgError(unsigned int argNum, const String& error) const - { - return luaL_argerror(m_state, argNum, error.GetConstBuffer()); - } - - bool LuaState::Call(unsigned int argCount) - { - return Run(argCount, LUA_MULTRET, 0); - } - - bool LuaState::Call(unsigned int argCount, unsigned int resultCount) - { - return Run(argCount, resultCount, 0); - } - - bool LuaState::CallWithHandler(unsigned int argCount, int errorHandler) - { - return Run(argCount, LUA_MULTRET, errorHandler); - } - - bool LuaState::CallWithHandler(unsigned int argCount, unsigned int resultCount, int errorHandler) - { - return Run(argCount, resultCount, errorHandler); - } - - void LuaState::CheckAny(int index) const - { - luaL_checkany(m_state, index); - } - - bool LuaState::CheckBoolean(int index) const - { - if (lua_isnoneornil(m_state, index)) - { - const char* msg = lua_pushfstring(m_state, "%s expected, got %s", lua_typename(m_state, LUA_TBOOLEAN), luaL_typename(m_state, index)); - luaL_argerror(m_state, index, msg); // Lance une exception - return false; - } - - return lua_toboolean(m_state, index) != 0; - } - - bool LuaState::CheckBoolean(int index, bool defValue) const - { - if (lua_isnoneornil(m_state, index)) - return defValue; - - return lua_toboolean(m_state, index) != 0; - } - - long long LuaState::CheckInteger(int index) const - { - return luaL_checkinteger(m_state, index); - } - - long long LuaState::CheckInteger(int index, long long defValue) const - { - return luaL_optinteger(m_state, index, defValue); - } - - double LuaState::CheckNumber(int index) const - { - return luaL_checknumber(m_state, index); - } - - double LuaState::CheckNumber(int index, double defValue) const - { - return luaL_optnumber(m_state, index, defValue); - } - - void LuaState::CheckStack(int space, const char* error) const - { - luaL_checkstack(m_state, space, error); - } - - void LuaState::CheckStack(int space, const String& error) const - { - CheckStack(space, error.GetConstBuffer()); - } - - const char* LuaState::CheckString(int index, std::size_t* length) const - { - return luaL_checklstring(m_state, index, length); - } - - const char* LuaState::CheckString(int index, const char* defValue, std::size_t* length) const - { - return luaL_optlstring(m_state, index, defValue, length); - } - - void LuaState::CheckType(int index, LuaType type) const - { - #ifdef NAZARA_DEBUG - if (type > LuaType_Max) - { - NazaraError("Lua type out of enum"); - return; - } - #endif - - luaL_checktype(m_state, index, s_types[type]); - } - - void* LuaState::CheckUserdata(int index, const char* tname) const - { - return luaL_checkudata(m_state, index, tname); - } - - void* LuaState::CheckUserdata(int index, const String& tname) const - { - return luaL_checkudata(m_state, index, tname.GetConstBuffer()); - } - - bool LuaState::Compare(int index1, int index2, LuaComparison comparison) const - { - #ifdef NAZARA_DEBUG - if (comparison > LuaComparison_Max) - { - NazaraError("Lua comparison out of enum"); - return false; - } - #endif - - return (lua_compare(m_state, index1, index2, s_comparisons[comparison]) != 0); - } - - void LuaState::Compute(LuaOperation operation) const - { - #ifdef NAZARA_DEBUG - if (operation > LuaOperation_Max) - { - NazaraError("Lua operation out of enum"); - return; - } - #endif - - lua_arith(m_state, s_operations[operation]); - } - - void LuaState::Concatenate(int count) const - { - lua_concat(m_state, count); - } - - int LuaState::CreateReference() - { - return luaL_ref(m_state, LUA_REGISTRYINDEX); - } - - void LuaState::DestroyReference(int ref) - { - luaL_unref(m_state, LUA_REGISTRYINDEX, ref); - } - - String LuaState::DumpStack() const - { - StringStream stream; - unsigned int stackTop = GetStackTop(); - stream << stackTop << " entries\n"; - - for (unsigned int i = 1; i <= stackTop; ++i) - { - stream << i << ": "; - switch (GetType(i)) - { - case LuaType_Boolean: - stream << "Boolean(" << ToBoolean(i) << ')'; - break; - - case LuaType_Function: - stream << "Function(" << ToPointer(i) << ')'; - break; - - case LuaType_LightUserdata: - case LuaType_Userdata: - stream << "Userdata(" << ToUserdata(i) << ')'; - break; - - case LuaType_Nil: - stream << "Nil"; - break; - - case LuaType_None: - stream << "None"; - break; - - case LuaType_Number: - stream << "Number(" << ToNumber(i) << ')'; - break; - - case LuaType_String: - stream << "String(" << ToString(i) << ')'; - break; - - case LuaType_Table: - stream << "Table(" << ToPointer(i) << ')'; - break; - - case LuaType_Thread: - stream << "Thread(" << ToPointer(i) << ')'; - break; - - default: - stream << "Unknown(" << ToPointer(i) << ')'; - break; - } - - stream << '\n'; - } - - return stream.ToString(); - } - - void LuaState::Error(const char* message) const - { - luaL_error(m_state, message); - } - - void LuaState::Error(const String& message) const - { - luaL_error(m_state, message.GetConstBuffer()); - } - - bool LuaState::Execute(const String& code, int errorHandler) - { - if (code.IsEmpty()) - return true; - - if (!Load(code)) - return false; - - return CallWithHandler(errorHandler, 0); - } - - bool LuaState::ExecuteFromFile(const std::filesystem::path& filePath, int errorHandler) - { - if (!LoadFromFile(filePath)) - return false; - - return CallWithHandler(errorHandler, 0); - } - - bool LuaState::ExecuteFromMemory(const void* data, std::size_t size, int errorHandler) - { - MemoryView stream(data, size); - return ExecuteFromStream(stream, errorHandler); - } - - bool LuaState::ExecuteFromStream(Stream& stream, int errorHandler) - { - if (!LoadFromStream(stream)) - return false; - - return CallWithHandler(errorHandler, 0); - } - - int LuaState::GetAbsIndex(int index) const - { - return lua_absindex(m_state, index); - } - - LuaType LuaState::GetField(const char* fieldName, int tableIndex) const - { - return FromLuaType(lua_getfield(m_state, tableIndex, fieldName)); - } - - LuaType LuaState::GetField(const String& fieldName, int tableIndex) const - { - return FromLuaType(lua_getfield(m_state, tableIndex, fieldName.GetConstBuffer())); - } - - LuaType LuaState::GetGlobal(const char* name) const - { - return FromLuaType(lua_getglobal(m_state, name)); - } - - LuaType LuaState::GetGlobal(const String& name) const - { - return FromLuaType(lua_getglobal(m_state, name.GetConstBuffer())); - } - - LuaType LuaState::GetMetatable(const char* tname) const - { - return FromLuaType(luaL_getmetatable(m_state, tname)); - } - - LuaType LuaState::GetMetatable(const String& tname) const - { - return FromLuaType(luaL_getmetatable(m_state, tname.GetConstBuffer())); - } - - bool LuaState::GetMetatable(int index) const - { - return lua_getmetatable(m_state, index) != 0; - } - - unsigned int LuaState::GetStackTop() const - { - return static_cast(lua_gettop(m_state)); - } - - LuaType LuaState::GetTable(int index) const - { - return FromLuaType(lua_gettable(m_state, index)); - } - - LuaType LuaState::GetTableRaw(int index) const - { - return FromLuaType(lua_rawget(m_state, index)); - } - - LuaType LuaState::GetType(int index) const - { - return FromLuaType(lua_type(m_state, index)); - } - - const char* LuaState::GetTypeName(LuaType type) const - { - #ifdef NAZARA_DEBUG - if (type > LuaType_Max) - { - NazaraError("Lua type out of enum"); - return nullptr; - } - #endif - - return lua_typename(m_state, s_types[type]); - } - - void LuaState::Insert(int index) const - { - lua_insert(m_state, index); - } - - bool LuaState::IsOfType(int index, LuaType type) const - { - switch (type) - { - case LuaType_Boolean: - return lua_isboolean(m_state, index) != 0; - - case LuaType_Function: - return lua_isfunction(m_state, index) != 0; - - case LuaType_LightUserdata: - return lua_islightuserdata(m_state, index) != 0; - - case LuaType_Nil: - return lua_isnil(m_state, index) != 0; - - case LuaType_None: - return lua_isnone(m_state, index) != 0; - - case LuaType_Number: - return lua_isnumber(m_state, index) != 0; - - case LuaType_String: - return lua_isstring(m_state, index) != 0; - - case LuaType_Table: - return lua_istable(m_state, index) != 0; - - case LuaType_Thread: - return lua_isthread(m_state, index) != 0; - - case LuaType_Userdata: - return lua_isuserdata(m_state, index) != 0; - } - - NazaraError("Lua type not handled (0x" + String::Number(type, 16) + ')'); - return false; - } - - bool LuaState::IsOfType(int index, const char* tname) const - { - void* ud = luaL_testudata(m_state, index, tname); - return ud != nullptr; - } - - bool LuaState::IsOfType(int index, const String& tname) const - { - return IsOfType(index, tname.GetConstBuffer()); - } - - bool LuaState::IsValid(int index) const - { - return lua_isnoneornil(m_state, index) == 0; - } - - bool LuaState::Load(const String& code) - { - if (luaL_loadstring(m_state, code.GetConstBuffer()) != 0) - { - m_lastError = lua_tostring(m_state, -1); - lua_pop(m_state, 1); - - return false; - } - - return true; - } - - bool LuaState::LoadFromFile(const std::filesystem::path& filePath) - { - File file(filePath); - if (!file.Open(OpenMode_ReadOnly | OpenMode_Text)) - { - NazaraError("Failed to open file"); - return false; - } - - std::size_t length = static_cast(file.GetSize()); - - String source(length, '\0'); - - if (file.Read(&source[0], length) != length) - { - NazaraError("Failed to read file"); - return false; - } - - file.Close(); - - return Load(source); - } - - bool LuaState::LoadFromMemory(const void* data, std::size_t size) - { - MemoryView stream(data, size); - return LoadFromStream(stream); - } - - bool LuaState::LoadFromStream(Stream& stream) - { - StreamData data; - data.stream = &stream; - - if (lua_load(m_state, StreamReader, &data, "C++", nullptr) != 0) - { - m_lastError = lua_tostring(m_state, -1); - lua_pop(m_state, 1); - - return false; - } - - return true; - } - - long long LuaState::Length(int index) const - { - return luaL_len(m_state, index); - } - - std::size_t LuaState::LengthRaw(int index) const - { - return lua_rawlen(m_state, index); - } - - void LuaState::MoveTo(LuaState* instance, int n) const - { - lua_xmove(m_state, instance->m_state, n); - } - - LuaCoroutine LuaState::NewCoroutine() - { - lua_State* thread = lua_newthread(m_state); - int ref = luaL_ref(m_state, LUA_REGISTRYINDEX); - - return LuaCoroutine(thread, ref); - } - - bool LuaState::NewMetatable(const char* str) - { - return luaL_newmetatable(m_state, str) != 0; - } - - bool LuaState::NewMetatable(const String& str) - { - return luaL_newmetatable(m_state, str.GetConstBuffer()) != 0; - } - - bool LuaState::Next(int index) const - { - return lua_next(m_state, index) != 0; - } - - void LuaState::Pop(unsigned int n) const - { - lua_pop(m_state, static_cast(n)); - } - - void LuaState::PushBoolean(bool value) const - { - lua_pushboolean(m_state, (value) ? 1 : 0); - } - - void LuaState::PushCFunction(LuaCFunction func, unsigned int upvalueCount) const - { - lua_pushcclosure(m_state, func, upvalueCount); - } - - void LuaState::PushFunction(LuaFunction func) const - { - LuaFunction* luaFunc = static_cast(lua_newuserdata(m_state, sizeof(LuaFunction))); - PlacementNew(luaFunc, std::move(func)); - - lua_pushcclosure(m_state, ProxyFunc, 1); - } - - void LuaState::PushInteger(long long value) const - { - lua_pushinteger(m_state, value); - } - - void LuaState::PushLightUserdata(void* value) const - { - lua_pushlightuserdata(m_state, value); - } - - void LuaState::PushMetatable(const char* str) const - { - luaL_getmetatable(m_state, str); - } - - void LuaState::PushMetatable(const String& str) const - { - luaL_getmetatable(m_state, str.GetConstBuffer()); - } - - void LuaState::PushNil() const - { - lua_pushnil(m_state); - } - - void LuaState::PushNumber(double value) const - { - lua_pushnumber(m_state, value); - } - - void LuaState::PushReference(int ref) const - { - lua_rawgeti(m_state, LUA_REGISTRYINDEX, ref); - } - - void LuaState::PushString(const char* str) const - { - lua_pushstring(m_state, str); - } - - void LuaState::PushString(const char* str, std::size_t size) const - { - lua_pushlstring(m_state, str, size); - } - - void LuaState::PushString(const String& str) const - { - lua_pushlstring(m_state, str.GetConstBuffer(), str.GetSize()); - } - - void LuaState::PushTable(std::size_t sequenceElementCount, std::size_t arrayElementCount) const - { - constexpr std::size_t maxInt = std::numeric_limits::max(); - lua_createtable(m_state, static_cast(std::min(sequenceElementCount, maxInt)), static_cast(std::min(arrayElementCount, maxInt))); - } - - void* LuaState::PushUserdata(std::size_t size) const - { - return lua_newuserdata(m_state, size); - } - - void LuaState::PushValue(int index) const - { - lua_pushvalue(m_state, index); - } - - bool LuaState::RawEqual(int index1, int index2) const - { - return lua_rawequal(m_state, index1, index2); - } - - void LuaState::Remove(int index) const - { - lua_remove(m_state, index); - } - - void LuaState::Replace(int index) const - { - lua_replace(m_state, index); - } - - void LuaState::SetField(const char* name, int tableIndex) const - { - lua_setfield(m_state, tableIndex, name); - } - - void LuaState::SetField(const String& name, int tableIndex) const - { - lua_setfield(m_state, tableIndex, name.GetConstBuffer()); - } - - void LuaState::SetGlobal(const char* name) - { - lua_setglobal(m_state, name); - } - - void LuaState::SetGlobal(const String& name) - { - lua_setglobal(m_state, name.GetConstBuffer()); - } - - void LuaState::SetMetatable(const char* tname) const - { - luaL_setmetatable(m_state, tname); - } - - void LuaState::SetMetatable(const String& tname) const - { - luaL_setmetatable(m_state, tname.GetConstBuffer()); - } - - void LuaState::SetMetatable(int index) const - { - lua_setmetatable(m_state, index); - } - - void LuaState::SetTable(int index) const - { - lua_settable(m_state, index); - } - - void LuaState::SetTableRaw(int index) const - { - lua_rawset(m_state, index); - } - - bool LuaState::ToBoolean(int index) const - { - return lua_toboolean(m_state, index) != 0; - } - - long long LuaState::ToInteger(int index, bool* succeeded) const - { - int success; - long long result = lua_tointegerx(m_state, index, &success); - - if (succeeded) - *succeeded = (success != 0); - - return result; - } - - double LuaState::ToNumber(int index, bool* succeeded) const - { - int success; - double result = lua_tonumberx(m_state, index, &success); - - if (succeeded) - *succeeded = (success != 0); - - return result; - } - - const void* LuaState::ToPointer(int index) const - { - return lua_topointer(m_state, index); - } - - const char* LuaState::ToString(int index, std::size_t* length) const - { - return lua_tolstring(m_state, index, length); - } - - void* LuaState::ToUserdata(int index) const - { - return lua_touserdata(m_state, index); - } - - void* LuaState::ToUserdata(int index, const char* tname) const - { - return luaL_testudata(m_state, index, tname); - } - - void* LuaState::ToUserdata(int index, const String& tname) const - { - return luaL_testudata(m_state, index, tname.GetConstBuffer()); - } - - void LuaState::Traceback(const char* message, int level) - { - luaL_traceback(m_state, m_state, message, level); - } - - bool LuaState::Run(int argCount, int resultCount, int errHandler) - { - LuaInstance& instance = GetInstance(m_state); - - if (instance.m_level++ == 0) - instance.m_clock.Restart(); - - int status = lua_pcall(m_state, argCount, resultCount, errHandler); - - instance.m_level--; - - if (status != 0) - { - m_lastError = lua_tostring(m_state, -1); - lua_pop(m_state, 1); - - return false; - } - - return true; - } - - int LuaState::GetIndexOfUpValue(int upValue) - { - return lua_upvalueindex(upValue); - } - - LuaInstance& LuaState::GetInstance(lua_State* internalState) - { - LuaInstance* instance; - lua_getallocf(internalState, reinterpret_cast(&instance)); - - return *instance; - } - - int LuaState::ProxyFunc(lua_State* internalState) - { - LuaFunction& func = *static_cast(lua_touserdata(internalState, lua_upvalueindex(1))); - LuaState state = GetState(internalState); - - return func(state); - } - -} diff --git a/src/Nazara/Noise/Debug/NewOverload.cpp b/src/Nazara/Noise/Debug/NewOverload.cpp deleted file mode 100644 index d761e94b8..000000000 --- a/src/Nazara/Noise/Debug/NewOverload.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2017 Jérôme Leclercq -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#if NAZARA_NOISE_MANAGE_MEMORY - -#include -#include // Nécessaire ? - -void* operator new(std::size_t size) -{ - return Nz::MemoryManager::Allocate(size, false); -} - -void* operator new[](std::size_t size) -{ - return Nz::MemoryManager::Allocate(size, true); -} - -void operator delete(void* pointer) noexcept -{ - Nz::MemoryManager::Free(pointer, false); -} - -void operator delete[](void* pointer) noexcept -{ - Nz::MemoryManager::Free(pointer, true); -} - -#endif // NAZARA_NOISE_MANAGE_MEMORY diff --git a/src/Nazara/Noise/FBM.cpp b/src/Nazara/Noise/FBM.cpp deleted file mode 100644 index 95d79c2cd..000000000 --- a/src/Nazara/Noise/FBM.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - FBM::FBM(const NoiseBase & source): m_source(source) - { - } - - ///TODO: Handle with variadic templates - float FBM::Get(float x, float y, float scale) const - { - float value = 0.f; - for(int i = 0; i < m_octaves; ++i) - { - value += m_source.Get(x, y, scale) * m_exponent_array.at(i); - scale *= m_lacunarity; - } - - float remainder = m_octaves - static_cast(m_octaves); - if(std::fabs(remainder) > 0.01f) - value += remainder * m_source.Get(x, y, scale) * m_exponent_array.at(static_cast(m_octaves-1)); - - return value / m_sum; - } - - float FBM::Get(float x, float y, float z, float scale) const - { - float value = 0.f; - for(int i = 0; i < m_octaves; ++i) - { - value += m_source.Get(x, y, z, scale) * m_exponent_array.at(i); - scale *= m_lacunarity; - } - - float remainder = m_octaves - static_cast(m_octaves); - if(std::fabs(remainder) > 0.01f) - value += remainder * m_source.Get(x, y, z, scale) * m_exponent_array.at(static_cast(m_octaves-1)); - - return value / m_sum; - } - - float FBM::Get(float x, float y, float z, float w, float scale) const - { - float value = 0.f; - for(int i = 0; i < m_octaves; ++i) - { - value += m_source.Get(x, y, z, w, scale) * m_exponent_array.at(i); - scale *= m_lacunarity; - } - - float remainder = m_octaves - static_cast(m_octaves); - if(std::fabs(remainder) > 0.01f) - value += remainder * m_source.Get(x, y, z, w, scale) * m_exponent_array.at(static_cast(m_octaves-1)); - - return value / m_sum; - } -} diff --git a/src/Nazara/Noise/HybridMultiFractal.cpp b/src/Nazara/Noise/HybridMultiFractal.cpp deleted file mode 100644 index 86ae2e9cd..000000000 --- a/src/Nazara/Noise/HybridMultiFractal.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - HybridMultiFractal::HybridMultiFractal(const NoiseBase & source) : - m_source(source) - { - } - - float HybridMultiFractal::Get(float x, float y, float scale) const - { - float offset = 1.0f; - float value = (m_source.Get(x, y, scale) + offset) * m_exponent_array.at(0); - float weight = value; - float signal = 0.f; - - scale *= m_lacunarity; - - for(int i(1) ; i < m_octaves; ++i) - { - if (weight > 1.f) - weight = 1.f; - - signal = (m_source.Get(x, y, scale) + offset) * m_exponent_array.at(i); - value += weight * signal; - weight *= signal; - scale *= m_lacunarity; - } - - float remainder = m_octaves - static_cast(m_octaves); - - if (remainder > 0.f) - value += remainder * m_source.Get(x, y, scale) * m_exponent_array.at(static_cast(m_octaves-1)); - - return value / m_sum - offset; - } - - float HybridMultiFractal::Get(float x, float y, float z, float scale) const - { - float offset = 1.0f; - float value = (m_source.Get(x, y, z, scale) + offset) * m_exponent_array.at(0); - float weight = value; - float signal = 0.f; - - scale *= m_lacunarity; - - for(int i(1) ; i < m_octaves; ++i) - { - if (weight > 1.f) - weight = 1.f; - - signal = (m_source.Get(x, y, z, scale) + offset) * m_exponent_array.at(i); - value += weight * signal; - weight *= signal; - scale *= m_lacunarity; - } - - float remainder = m_octaves - static_cast(m_octaves); - - if (remainder > 0.f) - value += remainder * m_source.Get(x, y, z, scale) * m_exponent_array.at(static_cast(m_octaves-1)); - - return value / m_sum - offset; - } - - float HybridMultiFractal::Get(float x, float y, float z, float w, float scale) const - { - float offset = 1.0f; - float value = (m_source.Get(x, y, z, w, scale) + offset) * m_exponent_array.at(0); - float weight = value; - float signal = 0.f; - - scale *= m_lacunarity; - - for(int i(1) ; i < m_octaves; ++i) - { - if (weight > 1.f) - weight = 1.f; - - signal = (m_source.Get(x, y, z, w, scale) + offset) * m_exponent_array.at(i); - value += weight * signal; - weight *= signal; - scale *= m_lacunarity; - } - - float remainder = m_octaves - static_cast(m_octaves); - - if (remainder > 0.f) - value += remainder * m_source.Get(x, y, z, w, scale) * m_exponent_array.at(static_cast(m_octaves-1)); - - return value / m_sum - offset; - } -} diff --git a/src/Nazara/Noise/MixerBase.cpp b/src/Nazara/Noise/MixerBase.cpp deleted file mode 100644 index f3fbc0f8a..000000000 --- a/src/Nazara/Noise/MixerBase.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - MixerBase::MixerBase() : - m_hurst(1.2f), - m_lacunarity(5.f), - m_octaves(3.f) - { - Recompute(); - } - - float MixerBase::GetHurstParameter() const - { - return m_hurst; - } - - float MixerBase::GetLacunarity() const - { - return m_lacunarity; - } - - float MixerBase::GetOctaveNumber() const - { - return m_octaves; - } - - void MixerBase::SetParameters(float hurst, float lacunarity, float octaves) - { - m_hurst = hurst; - m_lacunarity = lacunarity; - m_octaves = octaves; - - Recompute(); - } - - void MixerBase::Recompute() - { - float frequency = 1.0; - m_sum = 0.f; - m_exponent_array.clear(); - - for (int i(0) ; i < static_cast(m_octaves) ; ++i) - { - m_exponent_array.push_back(std::pow( frequency, -m_hurst )); - frequency *= m_lacunarity; - m_sum += m_exponent_array.at(i); - } - } -} diff --git a/src/Nazara/Noise/Noise.cpp b/src/Nazara/Noise/Noise.cpp deleted file mode 100644 index 880527834..000000000 --- a/src/Nazara/Noise/Noise.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - bool Noise::Initialize() - { - if (s_moduleReferenceCounter > 0) - { - s_moduleReferenceCounter++; - return true; // Déjà initialisé - } - - // Initialisation des dépendances - if (!Core::Initialize()) - { - NazaraError("Failed to initialize core module"); - Uninitialize(); - - return false; - } - - s_moduleReferenceCounter++; - - // Initialisation du module - - NazaraNotice("Initialized: Noise module"); - return true; - } - - bool Noise::IsInitialized() - { - return s_moduleReferenceCounter != 0; - } - - void Noise::Uninitialize() - { - if (s_moduleReferenceCounter != 1) - { - // Le module est soit encore utilisé, soit pas initialisé - if (s_moduleReferenceCounter > 1) - s_moduleReferenceCounter--; - - return; - } - - // Libération du module - s_moduleReferenceCounter = 0; - - NazaraNotice("Uninitialized: Noise module"); - - // Libération des dépendances - Core::Uninitialize(); - } - - unsigned int Noise::s_moduleReferenceCounter = 0; -} diff --git a/src/Nazara/Noise/NoiseBase.cpp b/src/Nazara/Noise/NoiseBase.cpp deleted file mode 100644 index 0a4f09505..000000000 --- a/src/Nazara/Noise/NoiseBase.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - NoiseBase::NoiseBase(unsigned int seed) : - m_scale(0.05f) - { - SetSeed(seed); - - // Fill permutations with initial values - std::iota(m_permutations.begin(), m_permutations.begin() + 256, 0); - } - - float NoiseBase::GetScale() - { - return m_scale; - } - - void NoiseBase::SetScale(float scale) - { - m_scale = scale; - } - - void NoiseBase::SetSeed(unsigned int seed) - { - m_randomEngine.seed(seed); - } - - void NoiseBase::Shuffle() - { - std::shuffle(m_permutations.begin(), m_permutations.begin() + 256, m_randomEngine); - - for(std::size_t i = 1; i < (m_permutations.size() / 256); ++i) - std::copy(m_permutations.begin(), m_permutations.begin() + 256, m_permutations.begin() + 256 * i); - } - - std::array NoiseBase::s_gradients2 = - { - { - {1.f, 1.f}, {-1.f, 1.f}, {1.f, -1.f}, {-1.f, -1.f}, - {1.f, 0.f}, {-1.f, 0.f}, {0.f, 1.f}, { 0.f, -1.f} - } - }; - - std::array NoiseBase::s_gradients3 = - { - { - {1.f,1.f,0.f}, {-1.f, 1.f, 0.f}, {1.f, -1.f, 0.f}, {-1.f, -1.f, 0.f}, - {1.f,0.f,1.f}, {-1.f, 0.f, 1.f}, {1.f, 0.f, -1.f}, {-1.f, 0.f, -1.f}, - {0.f,1.f,1.f}, { 0.f, -1.f, 1.f}, {0.f, 1.f, -1.f}, {0.f, -1.f, -1.f}, - {1.f,1.f,0.f}, {-1.f, 1.f, 0.f}, {0.f, -1.f, 1.f}, {0.f, -1.f, -1.f} - } - }; - - std::array NoiseBase::s_gradients4 = - { - { - {0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1}, - {0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1}, - {1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1}, - {-1,0,1,1},{-1,0,1,-1},{-1,0,-1,1},{-1,0,-1,-1}, - {1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1}, - {-1,1,0,1},{-1,1,0,-1},{-1,-1,0,1},{-1,-1,0,-1}, - {1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0}, - {-1,1,1,0},{-1,1,-1,0},{-1,-1,1,0},{-1,-1,-1,0} - } - }; -} diff --git a/src/Nazara/Noise/NoiseTools.cpp b/src/Nazara/Noise/NoiseTools.cpp deleted file mode 100644 index 5f6274357..000000000 --- a/src/Nazara/Noise/NoiseTools.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include - -namespace Nz -{ - int fastfloor(float n) - { - return (n >= 0) ? static_cast(n) : static_cast(n-1); - } - - int JenkinsHash(int a, int b, int c) - { - a = a-b; a = a - c; a = a^(static_cast(c) >> 13); - b = b-c; b = b - a; b = b^(a << 8); - c = c-a; c = c - b; c = c^(static_cast(b) >> 13); - a = a-b; a = a - c; a = a^(static_cast(c) >> 12); - b = b-c; b = b - a; b = b^(a << 16); - c = c-a; c = c - b; c = c^(static_cast(b) >> 5); - a = a-b; a = a - c; a = a^(static_cast(c) >> 3); - b = b-c; b = b - a; b = b^(a << 10); - c = c-a; c = c - b; c = c^(static_cast(b) >> 15); - return c; - } -} diff --git a/src/Nazara/Noise/Perlin.cpp b/src/Nazara/Noise/Perlin.cpp deleted file mode 100644 index d80bf7c84..000000000 --- a/src/Nazara/Noise/Perlin.cpp +++ /dev/null @@ -1,274 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - Perlin::Perlin(unsigned int seed) : - Perlin() - { - SetSeed(seed); - Shuffle(); - } - - float Perlin::Get(float x, float y, float scale) const - { - float xc, yc; - int x0, y0; - int gi0,gi1,gi2,gi3; - int ii, jj; - - float s,t,u,v; - float Cx,Cy; - float Li1, Li2; - float tempx,tempy; - - xc = x * scale; - yc = y * scale; - - x0 = fastfloor(xc); - y0 = fastfloor(yc); - - ii = x0 & 255; - jj = y0 & 255; - - gi0 = m_permutations[ii + m_permutations[jj]] & 7; - gi1 = m_permutations[ii + 1 + m_permutations[jj]] & 7; - gi2 = m_permutations[ii + m_permutations[jj + 1]] & 7; - gi3 = m_permutations[ii + 1 + m_permutations[jj + 1]] & 7; - - tempx = xc - x0; - tempy = yc - y0; - - Cx = tempx * tempx * tempx * (tempx * (tempx * 6 - 15) + 10); - Cy = tempy * tempy * tempy * (tempy * (tempy * 6 - 15) + 10); - - s = s_gradients2[gi0][0]*tempx + s_gradients2[gi0][1]*tempy; - - tempx = xc - (x0 + 1); - t = s_gradients2[gi1][0]*tempx + s_gradients2[gi1][1]*tempy; - - tempy = yc - (y0 + 1); - v = s_gradients2[gi3][0]*tempx + s_gradients2[gi3][1]*tempy; - - tempx = xc - x0; - u = s_gradients2[gi2][0]*tempx + s_gradients2[gi2][1]*tempy; - - Li1 = s + Cx*(t-s); - Li2 = u + Cx*(v-u); - - return Li1 + Cy*(Li2-Li1); - } - - float Perlin::Get(float x, float y, float z, float scale) const - { - float xc, yc, zc; - int x0, y0, z0; - int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7; - int ii, jj, kk; - - float Li1,Li2,Li3,Li4,Li5,Li6; - float s[2],t[2],u[2],v[2]; - float Cx,Cy,Cz; - float tempx,tempy,tempz; - - xc = x * scale; - yc = y * scale; - zc = z * scale; - - x0 = fastfloor(xc); - y0 = fastfloor(yc); - z0 = fastfloor(zc); - - ii = x0 & 255; - jj = y0 & 255; - kk = z0 & 255; - - gi0 = m_permutations[ii + m_permutations[jj + m_permutations[kk]]] & 15; - gi1 = m_permutations[ii + 1 + m_permutations[jj + m_permutations[kk]]] & 15; - gi2 = m_permutations[ii + m_permutations[jj + 1 + m_permutations[kk]]] & 15; - gi3 = m_permutations[ii + 1 + m_permutations[jj + 1 + m_permutations[kk]]] & 15; - - gi4 = m_permutations[ii + m_permutations[jj + m_permutations[kk + 1]]] & 15; - gi5 = m_permutations[ii + 1 + m_permutations[jj + m_permutations[kk + 1]]] & 15; - gi6 = m_permutations[ii + m_permutations[jj + 1 + m_permutations[kk + 1]]] & 15; - gi7 = m_permutations[ii + 1 + m_permutations[jj + 1 + m_permutations[kk + 1]]] & 15; - - tempx = xc - x0; - tempy = yc - y0; - tempz = zc - z0; - - Cx = tempx * tempx * tempx * (tempx * (tempx * 6 - 15) + 10); - Cy = tempy * tempy * tempy * (tempy * (tempy * 6 - 15) + 10); - Cz = tempz * tempz * tempz * (tempz * (tempz * 6 - 15) + 10); - - s[0] = s_gradients3[gi0][0]*tempx + s_gradients3[gi0][1]*tempy + s_gradients3[gi0][2]*tempz; - - tempx = xc - (x0 + 1); - t[0] = s_gradients3[gi1][0]*tempx + s_gradients3[gi1][1]*tempy + s_gradients3[gi1][2]*tempz; - - tempy = yc - (y0 + 1); - v[0] = s_gradients3[gi3][0]*tempx + s_gradients3[gi3][1]*tempy + s_gradients3[gi3][2]*tempz; - - tempx = xc - x0; - u[0] = s_gradients3[gi2][0]*tempx + s_gradients3[gi2][1]*tempy + s_gradients3[gi2][2]*tempz; - - tempy = yc - y0; - tempz = zc - (z0 + 1); - s[1] = s_gradients3[gi4][0]*tempx + s_gradients3[gi4][1]*tempy + s_gradients3[gi4][2]*tempz; - - tempx = xc - (x0 + 1); - t[1] = s_gradients3[gi5][0]*tempx + s_gradients3[gi5][1]*tempy + s_gradients3[gi5][2]*tempz; - - tempy = yc - (y0 + 1); - v[1] = s_gradients3[gi7][0]*tempx + s_gradients3[gi7][1]*tempy + s_gradients3[gi7][2]*tempz; - - tempx = xc - x0; - u[1] = s_gradients3[gi6][0]*tempx + s_gradients3[gi6][1]*tempy + s_gradients3[gi6][2]*tempz; - - Li1 = s[0] + Cx*(t[0]-s[0]); - Li2 = u[0] + Cx*(v[0]-u[0]); - Li3 = s[1] + Cx*(t[1]-s[1]); - Li4 = u[1] + Cx*(v[1]-u[1]); - - Li5 = Li1 + Cy * (Li2-Li1); - Li6 = Li3 + Cy * (Li4-Li3); - - return Li5 + Cz * (Li6-Li5); - } - - float Perlin::Get(float x, float y, float z, float w, float scale) const - { - float xc,yc,zc,wc; - int x0,y0,z0,w0; - int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; - int ii,jj,kk,ll; - - float Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14; - float s[4],t[4],u[4],v[4]; - float Cx,Cy,Cz,Cw; - - float tempx,tempy,tempz,tempw; - - xc = x * scale; - yc = y * scale; - zc = z * scale; - wc = w * scale; - - x0 = fastfloor(xc); - y0 = fastfloor(yc); - z0 = fastfloor(zc); - w0 = fastfloor(wc); - - ii = x0 & 255; - jj = y0 & 255; - kk = z0 & 255; - ll = w0 & 255; - - gi0 = m_permutations[ii + m_permutations[jj + m_permutations[kk + m_permutations[ll]]]] & 31; - gi1 = m_permutations[ii + 1 + m_permutations[jj + m_permutations[kk + m_permutations[ll]]]] & 31; - gi2 = m_permutations[ii + m_permutations[jj + 1 + m_permutations[kk + m_permutations[ll]]]] & 31; - gi3 = m_permutations[ii + 1 + m_permutations[jj + 1 + m_permutations[kk + m_permutations[ll]]]] & 31; - - gi4 = m_permutations[ii + m_permutations[jj + + m_permutations[kk + 1 + m_permutations[ll]]]] & 31; - gi5 = m_permutations[ii + 1 + m_permutations[jj + + m_permutations[kk + 1 + m_permutations[ll]]]] & 31; - gi6 = m_permutations[ii + m_permutations[jj + 1 + m_permutations[kk + 1 + m_permutations[ll]]]] & 31; - gi7 = m_permutations[ii + 1 + m_permutations[jj + 1 + m_permutations[kk + 1 + m_permutations[ll]]]] & 31; - - gi8 = m_permutations[ii + m_permutations[jj + m_permutations[kk + m_permutations[ll + 1]]]] & 31; - gi9 = m_permutations[ii + 1 + m_permutations[jj + m_permutations[kk + m_permutations[ll + 1]]]] & 31; - gi10 = m_permutations[ii + m_permutations[jj + 1 + m_permutations[kk + m_permutations[ll + 1]]]] & 31; - gi11 = m_permutations[ii + 1 + m_permutations[jj + 1 + m_permutations[kk + m_permutations[ll + 1]]]] & 31; - - gi12 = m_permutations[ii + m_permutations[jj + m_permutations[kk + 1 + m_permutations[ll + 1]]]] & 31; - gi13 = m_permutations[ii + 1 + m_permutations[jj + m_permutations[kk + 1 + m_permutations[ll + 1]]]] & 31; - gi14 = m_permutations[ii + m_permutations[jj + 1 + m_permutations[kk + 1 + m_permutations[ll + 1]]]] & 31; - gi15 = m_permutations[ii + 1 + m_permutations[jj + 1 + m_permutations[kk + 1 + m_permutations[ll + 1]]]] & 31; - - tempx = xc - x0; - tempy = yc - y0; - tempz = zc - z0; - tempw = wc - w0; - - Cx = tempx * tempx * tempx * (tempx * (tempx * 6 - 15) + 10); - Cy = tempy * tempy * tempy * (tempy * (tempy * 6 - 15) + 10); - Cz = tempz * tempz * tempz * (tempz * (tempz * 6 - 15) + 10); - Cw = tempw * tempw * tempw * (tempw * (tempw * 6 - 15) + 10); - - s[0] = s_gradients4[gi0][0]*tempx + s_gradients4[gi0][1]*tempy + s_gradients4[gi0][2]*tempz + s_gradients4[gi0][3]*tempw; - - tempx = xc - (x0+1); - t[0] = s_gradients4[gi1][0]*tempx + s_gradients4[gi1][1]*tempy + s_gradients4[gi1][2]*tempz + s_gradients4[gi1][3]*tempw; - - tempy = yc - (y0+1); - v[0] = s_gradients4[gi3][0]*tempx + s_gradients4[gi3][1]*tempy + s_gradients4[gi3][2]*tempz + s_gradients4[gi3][3]*tempw; - - tempx = xc - x0; - u[0] = s_gradients4[gi2][0]*tempx + s_gradients4[gi2][1]*tempy + s_gradients4[gi2][2]*tempz + s_gradients4[gi2][3]*tempw; - - tempy = yc - y0; - tempz = zc - (z0+1); - s[1] = s_gradients4[gi4][0]*tempx + s_gradients4[gi4][1]*tempy + s_gradients4[gi4][2]*tempz + s_gradients4[gi4][3]*tempw; - - tempx = xc - (x0+1); - t[1] = s_gradients4[gi5][0]*tempx + s_gradients4[gi5][1]*tempy + s_gradients4[gi5][2]*tempz + s_gradients4[gi5][3]*tempw; - - tempy = yc - (y0+1); - v[1] = s_gradients4[gi7][0]*tempx + s_gradients4[gi7][1]*tempy + s_gradients4[gi7][2]*tempz + s_gradients4[gi7][3]*tempw; - - tempx = xc - x0; - u[1] = s_gradients4[gi6][0]*tempx + s_gradients4[gi6][1]*tempy + s_gradients4[gi6][2]*tempz + s_gradients4[gi6][3]*tempw; - - - tempy = yc - y0; - tempz = zc - z0; - tempw = wc - (w0+1); - s[2] = s_gradients4[gi8][0]*tempx + s_gradients4[gi8][1]*tempy + s_gradients4[gi8][2]*tempz + s_gradients4[gi8][3]*tempw; - - tempx = xc - (x0+1); - t[2] = s_gradients4[gi9][0]*tempx + s_gradients4[gi9][1]*tempy + s_gradients4[gi9][2]*tempz + s_gradients4[gi9][3]*tempw; - - tempy = yc - (y0+1); - v[2] = s_gradients4[gi11][0]*tempx + s_gradients4[gi11][1]*tempy + s_gradients4[gi11][2]*tempz + s_gradients4[gi11][3]*tempw; - - tempx = xc - x0; - u[2] = s_gradients4[gi10][0]*tempx + s_gradients4[gi10][1]*tempy + s_gradients4[gi10][2]*tempz + s_gradients4[gi10][3]*tempw; - - - tempy = yc - y0; - tempz = zc - (z0+1); - s[3] = s_gradients4[gi12][0]*tempx + s_gradients4[gi12][1]*tempy + s_gradients4[gi12][2]*tempz + s_gradients4[gi12][3]*tempw; - - tempx = xc - (x0+1); - t[3] = s_gradients4[gi13][0]*tempx + s_gradients4[gi13][1]*tempy + s_gradients4[gi13][2]*tempz + s_gradients4[gi13][3]*tempw; - - tempy = yc - (y0+1); - v[3] = s_gradients4[gi15][0]*tempx + s_gradients4[gi15][1]*tempy + s_gradients4[gi15][2]*tempz + s_gradients4[gi15][3]*tempw; - - tempx = xc - x0; - u[3] = s_gradients4[gi14][0]*tempx + s_gradients4[gi14][1]*tempy + s_gradients4[gi14][2]*tempz + s_gradients4[gi14][3]*tempw; - - Li1 = s[0] + Cx*(t[0]-s[0]); - Li2 = u[0] + Cx*(v[0]-u[0]); - Li3 = s[1] + Cx*(t[1]-s[1]); - Li4 = u[1] + Cx*(v[1]-u[1]); - Li5 = s[2] + Cx*(t[2]-s[2]); - Li6 = u[2] + Cx*(v[2]-u[2]); - Li7 = s[3] + Cx*(t[3]-s[3]); - Li8 = u[3] + Cx*(v[3]-u[3]); - - Li9 = Li1 + Cy*(Li2-Li1); - Li10 = Li3 + Cy*(Li4-Li3); - Li11 = Li5 + Cy*(Li6-Li5); - Li12 = Li7 + Cy*(Li8-Li7); - - Li13 = Li9 + Cz*(Li10-Li9); - Li14 = Li11 + Cz*(Li12-Li11); - - return Li13 + Cw*(Li14-Li13); - } -} diff --git a/src/Nazara/Noise/Simplex.cpp b/src/Nazara/Noise/Simplex.cpp deleted file mode 100644 index b9e6ba957..000000000 --- a/src/Nazara/Noise/Simplex.cpp +++ /dev/null @@ -1,374 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - namespace - { - constexpr float s_SkewCoeff2D = 0.5f * (float(M_SQRT3) - 1.f); - constexpr float s_UnskewCoeff2D = (3.f - float(M_SQRT3))/6.f; - constexpr float s_SkewCoeff3D = 1.f / 3.f; - constexpr float s_UnskewCoeff3D = 1.f / 6.f; - constexpr float s_SkewCoeff4D = (float(M_SQRT5) - 1.f)/4.f; - constexpr float s_UnskewCoeff4D = (5.f - float(M_SQRT5))/20.f; - } - - Simplex::Simplex(unsigned int seed) - { - SetSeed(seed); - Shuffle(); - } - - float Simplex::Get(float x, float y, float scale) const - { - float xc = x * scale; - float yc = y * scale; - - float sum = (xc + yc) * s_SkewCoeff2D; - Vector2i skewedCubeOrigin(fastfloor(xc + sum), fastfloor(yc + sum)); - - sum = (skewedCubeOrigin.x + skewedCubeOrigin.y) * s_UnskewCoeff2D; - Vector2f unskewedCubeOrigin(skewedCubeOrigin.x - sum, skewedCubeOrigin.y - sum); - - Vector2f unskewedDistToOrigin(xc - unskewedCubeOrigin.x, yc - unskewedCubeOrigin.y); - - Vector2ui off1; - if(unskewedDistToOrigin.x > unskewedDistToOrigin.y) - off1.Set(1, 0); - else - off1.Set(0, 1); - - std::array d; - d[0] = -unskewedDistToOrigin; - d[1] = d[0] + Vector2f(off1) - Vector2f(s_UnskewCoeff2D); - d[2] = d[0] + Vector2f(1.f - 2.f * s_UnskewCoeff2D); - - Vector2i offset(skewedCubeOrigin.x & 255, skewedCubeOrigin.y & 255); - std::array gi = { - { - m_permutations[offset.x + m_permutations[offset.y]] & 7, - m_permutations[offset.x + off1.x + m_permutations[offset.y + off1.y]] & 7, - m_permutations[offset.x + 1 + m_permutations[offset.y + 1]] & 7 - } - }; - - float n = 0.f; - for (unsigned int i = 0; i < 3; ++i) - { - float c = 0.5f - d[i].x * d[i].x - d[i].y *d[i].y; - if (c > 0.f) - n += c * c * c * c * (s_gradients2[gi[i]].x * d[i].x + s_gradients2[gi[i]].y * d[i].y); - } - - return n*70.f; - } - - float Simplex::Get(float x, float y, float z, float scale) const - { - float xc, yc, zc; - int ii,jj,kk; - int gi0,gi1,gi2,gi3; - int skewedCubeOriginx,skewedCubeOriginy,skewedCubeOriginz; - - int off1x,off1y,off1z; - int off2x,off2y,off2z; - float n1,n2,n3,n4; - float c1,c2,c3,c4; - - float sum; - float unskewedCubeOriginx,unskewedCubeOriginy,unskewedCubeOriginz; - float unskewedDistToOriginx,unskewedDistToOriginy,unskewedDistToOriginz; - float d1x,d1y,d1z; - float d2x,d2y,d2z; - float d3x,d3y,d3z; - float d4x,d4y,d4z; - - xc = x * scale; - yc = y * scale; - zc = z * scale; - - sum = (xc + yc + zc) * s_SkewCoeff3D; - skewedCubeOriginx = fastfloor(xc + sum); - skewedCubeOriginy = fastfloor(yc + sum); - skewedCubeOriginz = fastfloor(zc + sum); - - sum = (skewedCubeOriginx + skewedCubeOriginy + skewedCubeOriginz) * s_UnskewCoeff3D; - unskewedCubeOriginx = skewedCubeOriginx - sum; - unskewedCubeOriginy = skewedCubeOriginy - sum; - unskewedCubeOriginz = skewedCubeOriginz - sum; - - unskewedDistToOriginx = xc - unskewedCubeOriginx; - unskewedDistToOriginy = yc - unskewedCubeOriginy; - unskewedDistToOriginz = zc - unskewedCubeOriginz; - - if(unskewedDistToOriginx >= unskewedDistToOriginy) - { - if(unskewedDistToOriginy >= unskewedDistToOriginz) - { - off1x = 1; - off1y = 0; - off1z = 0; - off2x = 1; - off2y = 1; - off2z = 0; - } - else if(unskewedDistToOriginx >= unskewedDistToOriginz) - { - off1x = 1; - off1y = 0; - off1z = 0; - off2x = 1; - off2y = 0; - off2z = 1; - } - else - { - off1x = 0; - off1y = 0; - off1z = 1; - off2x = 1; - off2y = 0; - off2z = 1; - } - } - else - { - if(unskewedDistToOriginy < unskewedDistToOriginz) - { - off1x = 0; - off1y = 0; - off1z = 1; - off2x = 0; - off2y = 1; - off2z = 1; - } - else if(unskewedDistToOriginx < unskewedDistToOriginz) - { - off1x = 0; - off1y = 1; - off1z = 0; - off2x = 0; - off2y = 1; - off2z = 1; - } - else - { - off1x = 0; - off1y = 1; - off1z = 0; - off2x = 1; - off2y = 1; - off2z = 0; - } - } - - d1x = unskewedDistToOriginx; - d1y = unskewedDistToOriginy; - d1z = unskewedDistToOriginz; - - d2x = d1x - off1x + s_UnskewCoeff3D; - d2y = d1y - off1y + s_UnskewCoeff3D; - d2z = d1z - off1z + s_UnskewCoeff3D; - - d3x = d1x - off2x + 2.f*s_UnskewCoeff3D; - d3y = d1y - off2y + 2.f*s_UnskewCoeff3D; - d3z = d1z - off2z + 2.f*s_UnskewCoeff3D; - - d4x = d1x - 1.f + 3.f*s_UnskewCoeff3D; - d4y = d1y - 1.f + 3.f*s_UnskewCoeff3D; - d4z = d1z - 1.f + 3.f*s_UnskewCoeff3D; - - ii = skewedCubeOriginx & 255; - jj = skewedCubeOriginy & 255; - kk = skewedCubeOriginz & 255; - - gi0 = m_permutations[ii + m_permutations[jj + m_permutations[kk ]]] % 12; - gi1 = m_permutations[ii + off1x + m_permutations[jj + off1y + m_permutations[kk + off1z ]]] % 12; - gi2 = m_permutations[ii + off2x + m_permutations[jj + off2y + m_permutations[kk + off2z ]]] % 12; - gi3 = m_permutations[ii + 1 + m_permutations[jj + 1 + m_permutations[kk + 1 ]]] % 12; - - c1 = 0.6f - d1x * d1x - d1y * d1y - d1z * d1z; - c2 = 0.6f - d2x * d2x - d2y * d2y - d2z * d2z; - c3 = 0.6f - d3x * d3x - d3y * d3y - d3z * d3z; - c4 = 0.6f - d4x * d4x - d4y * d4y - d4z * d4z; - - if(c1 < 0) - n1 = 0; - else - n1 = c1*c1*c1*c1*(s_gradients3[gi0][0] * d1x + s_gradients3[gi0][1] * d1y + s_gradients3[gi0][2] * d1z); - - if(c2 < 0) - n2 = 0; - else - n2 = c2*c2*c2*c2*(s_gradients3[gi1][0] * d2x + s_gradients3[gi1][1] * d2y + s_gradients3[gi1][2] * d2z); - - if(c3 < 0) - n3 = 0; - else - n3 = c3*c3*c3*c3*(s_gradients3[gi2][0] * d3x + s_gradients3[gi2][1] * d3y + s_gradients3[gi2][2] * d3z); - - if(c4 < 0) - n4 = 0; - else - n4 = c4*c4*c4*c4*(s_gradients3[gi3][0] * d4x + s_gradients3[gi3][1] * d4y + s_gradients3[gi3][2] * d4z); - - return (n1+n2+n3+n4)*32; - } - - float Simplex::Get(float x, float y, float z, float w, float scale) const - { - static std::array lookupTable = - { - { - {0,1,2,3}, {0,1,3,2}, {0,0,0,0}, {0,2,3,1}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {1,2,3,0}, - {0,2,1,3}, {0,0,0,0}, {0,3,1,2}, {0,3,2,1}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {1,3,2,0}, - {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, - {1,2,0,3}, {0,0,0,0}, {1,3,0,2}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,3,0,1}, {2,3,1,0}, - {1,0,2,3}, {1,0,3,2}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {2,0,3,1}, {0,0,0,0}, {2,1,3,0}, - {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, - {2,0,1,3}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {3,0,1,2}, {3,0,2,1}, {0,0,0,0}, {3,1,2,0}, - {2,1,0,3}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {3,1,0,2}, {0,0,0,0}, {3,2,0,1}, {3,2,1,0} - } - }; - - float xc,yc,zc,wc; - int ii,jj,kk,ll; - int gi0,gi1,gi2,gi3,gi4; - int skewedCubeOriginx,skewedCubeOriginy,skewedCubeOriginz,skewedCubeOriginw; - - int off1x,off1y,off1z,off1w; - int off2x,off2y,off2z,off2w; - int off3x,off3y,off3z,off3w; - - int c; - float n1,n2,n3,n4,n5; - float c1,c2,c3,c4,c5; - - float sum; - float unskewedCubeOriginx,unskewedCubeOriginy,unskewedCubeOriginz,unskewedCubeOriginw; - float unskewedDistToOriginx,unskewedDistToOriginy,unskewedDistToOriginz,unskewedDistToOriginw; - float d1x,d2x,d3x,d4x,d5x; - float d1y,d2y,d3y,d4y,d5y; - float d1z,d2z,d3z,d4z,d5z; - float d1w,d2w,d3w,d4w,d5w; - - xc = x * scale; - yc = y * scale; - zc = z * scale; - wc = w * scale; - - sum = (xc + yc + zc + wc) * s_SkewCoeff4D; - skewedCubeOriginx = fastfloor(xc + sum); - skewedCubeOriginy = fastfloor(yc + sum); - skewedCubeOriginz = fastfloor(zc + sum); - skewedCubeOriginw = fastfloor(wc + sum); - - sum = (skewedCubeOriginx + skewedCubeOriginy + skewedCubeOriginz + skewedCubeOriginw) * s_UnskewCoeff4D; - unskewedCubeOriginx = skewedCubeOriginx - sum; - unskewedCubeOriginy = skewedCubeOriginy - sum; - unskewedCubeOriginz = skewedCubeOriginz - sum; - unskewedCubeOriginw = skewedCubeOriginw - sum; - - unskewedDistToOriginx = xc - unskewedCubeOriginx; - unskewedDistToOriginy = yc - unskewedCubeOriginy; - unskewedDistToOriginz = zc - unskewedCubeOriginz; - unskewedDistToOriginw = wc - unskewedCubeOriginw; - - c = 0; - c += (unskewedDistToOriginx > unskewedDistToOriginy) ? 32 : 0; - c += (unskewedDistToOriginx > unskewedDistToOriginz) ? 16 : 0; - c += (unskewedDistToOriginy > unskewedDistToOriginz) ? 8 : 0; - c += (unskewedDistToOriginx > unskewedDistToOriginw) ? 4 : 0; - c += (unskewedDistToOriginy > unskewedDistToOriginw) ? 2 : 0; - c += (unskewedDistToOriginz > unskewedDistToOriginw) ? 1 : 0; - - off1x = lookupTable[c][0] >= 3 ? 1 : 0; - off1y = lookupTable[c][1] >= 3 ? 1 : 0; - off1z = lookupTable[c][2] >= 3 ? 1 : 0; - off1w = lookupTable[c][3] >= 3 ? 1 : 0; - - off2x = lookupTable[c][0] >= 2 ? 1 : 0; - off2y = lookupTable[c][1] >= 2 ? 1 : 0; - off2z = lookupTable[c][2] >= 2 ? 1 : 0; - off2w = lookupTable[c][3] >= 2 ? 1 : 0; - - off3x = lookupTable[c][0] >= 1 ? 1 : 0; - off3y = lookupTable[c][1] >= 1 ? 1 : 0; - off3z = lookupTable[c][2] >= 1 ? 1 : 0; - off3w = lookupTable[c][3] >= 1 ? 1 : 0; - - d1x = unskewedDistToOriginx; - d1y = unskewedDistToOriginy; - d1z = unskewedDistToOriginz; - d1w = unskewedDistToOriginw; - - d2x = d1x - off1x + s_UnskewCoeff4D; - d2y = d1y - off1y + s_UnskewCoeff4D; - d2z = d1z - off1z + s_UnskewCoeff4D; - d2w = d1w - off1w + s_UnskewCoeff4D; - - d3x = d1x - off2x + 2.f*s_UnskewCoeff4D; - d3y = d1y - off2y + 2.f*s_UnskewCoeff4D; - d3z = d1z - off2z + 2.f*s_UnskewCoeff4D; - d3w = d1w - off2w + 2.f*s_UnskewCoeff4D; - - d4x = d1x - off3x + 3.f*s_UnskewCoeff4D; - d4y = d1y - off3y + 3.f*s_UnskewCoeff4D; - d4z = d1z - off3z + 3.f*s_UnskewCoeff4D; - d4w = d1w - off3w + 3.f*s_UnskewCoeff4D; - - d5x = d1x - 1.f + 4*s_UnskewCoeff4D; - d5y = d1y - 1.f + 4*s_UnskewCoeff4D; - d5z = d1z - 1.f + 4*s_UnskewCoeff4D; - d5w = d1w - 1.f + 4*s_UnskewCoeff4D; - - ii = skewedCubeOriginx & 255; - jj = skewedCubeOriginy & 255; - kk = skewedCubeOriginz & 255; - ll = skewedCubeOriginw & 255; - - gi0 = m_permutations[ii + m_permutations[jj + m_permutations[kk + m_permutations[ll ]]]] & 31; - gi1 = m_permutations[ii + off1x + m_permutations[jj + off1y + m_permutations[kk + off1z + m_permutations[ll + off1w]]]] & 31; - gi2 = m_permutations[ii + off2x + m_permutations[jj + off2y + m_permutations[kk + off2z + m_permutations[ll + off2w]]]] & 31; - gi3 = m_permutations[ii + off3x + m_permutations[jj + off3y + m_permutations[kk + off3z + m_permutations[ll + off3w]]]] & 31; - gi4 = m_permutations[ii + 1 + m_permutations[jj + 1 + m_permutations[kk + 1 + m_permutations[ll + 1 ]]]] % 32; - - c1 = 0.6f - d1x*d1x - d1y*d1y - d1z*d1z - d1w*d1w; - c2 = 0.6f - d2x*d2x - d2y*d2y - d2z*d2z - d2w*d2w; - c3 = 0.6f - d3x*d3x - d3y*d3y - d3z*d3z - d3w*d3w; - c4 = 0.6f - d4x*d4x - d4y*d4y - d4z*d4z - d4w*d4w; - c5 = 0.6f - d5x*d5x - d5y*d5y - d5z*d5z - d5w*d5w; - - if(c1 < 0) - n1 = 0; - else - n1 = c1*c1*c1*c1*(s_gradients4[gi0][0]*d1x + s_gradients4[gi0][1]*d1y + s_gradients4[gi0][2]*d1z + s_gradients4[gi0][3]*d1w); - - if(c2 < 0) - n2 = 0; - else - n2 = c2*c2*c2*c2*(s_gradients4[gi1][0]*d2x + s_gradients4[gi1][1]*d2y + s_gradients4[gi1][2]*d2z + s_gradients4[gi1][3]*d2w); - - if(c3 < 0) - n3 = 0; - else - n3 = c3*c3*c3*c3*(s_gradients4[gi2][0]*d3x + s_gradients4[gi2][1]*d3y + s_gradients4[gi2][2]*d3z + s_gradients4[gi2][3]*d3w); - - if(c4 < 0) - n4 = 0; - else - n4 = c4*c4*c4*c4*(s_gradients4[gi3][0]*d4x + s_gradients4[gi3][1]*d4y + s_gradients4[gi3][2]*d4z + s_gradients4[gi3][3]*d4w); - - if(c5 < 0) - n5 = 0; - else - n5 = c5*c5*c5*c5*(s_gradients4[gi4][0]*d5x + s_gradients4[gi4][1]*d5y + s_gradients4[gi4][2]*d5z + s_gradients4[gi4][3]*d5w); - - return (n1+n2+n3+n4+n5)*27.f; - } -} diff --git a/src/Nazara/Noise/Worley.cpp b/src/Nazara/Noise/Worley.cpp deleted file mode 100644 index 82366234b..000000000 --- a/src/Nazara/Noise/Worley.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (C) 2017 Rémi Bèges -// This file is part of the "Nazara Engine - Noise module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include - -namespace Nz -{ - namespace - { - static constexpr std::array m_functionScales = { - { - 1.f / float(M_SQRT2), - 0.5f / float(M_SQRT2), - 0.5f / float(M_SQRT2), - 0.5f / float(M_SQRT2) - } - }; - } - Worley::Worley() : - m_function(WorleyFunction_F1) - { - } - - Worley::Worley(unsigned int seed) : - Worley() - { - SetSeed(seed); - Shuffle(); - } - - float Worley::Get(float x, float y, float scale) const - { - std::map featurePoints; - - float xc, yc; - int x0, y0; - float fractx, fracty; - - xc = x * scale; - yc = y * scale; - - x0 = fastfloor(xc); - y0 = fastfloor(yc); - - fractx = xc - static_cast(x0); - fracty = yc - static_cast(y0); - - featurePoints.clear(); - - SquareTest(x0,y0,xc,yc,featurePoints); - - std::size_t functionIndex = static_cast(m_function); - - auto it = featurePoints.begin(); - std::advance(it, functionIndex); - - if(fractx < it->first) - SquareTest(x0 - 1,y0,xc,yc,featurePoints); - - it = featurePoints.begin(); - std::advance(it, functionIndex); - - if(1.f - fractx < it->first) - SquareTest(x0 + 1,y0,xc,yc,featurePoints); - - it = featurePoints.begin(); - std::advance(it, functionIndex); - - if(fracty < it->first) - SquareTest(x0,y0 - 1,xc,yc,featurePoints); - - it = featurePoints.begin(); - std::advance(it, functionIndex); - - if (1.f - fracty < it->first) - SquareTest(x0,y0 + 1,xc,yc,featurePoints); - - it = featurePoints.begin(); - std::advance(it, functionIndex); - - if (fractx < it->first && fracty < it->first) - SquareTest(x0 - 1, y0 - 1,xc,yc,featurePoints); - - it = featurePoints.begin(); - std::advance(it, functionIndex); - - if (1.f - fractx < it->first && fracty < it->first) - SquareTest(x0 + 1, y0 - 1,xc,yc,featurePoints); - - it = featurePoints.begin(); - std::advance(it, functionIndex); - - if (fractx < it->first && 1.f - fracty < it->first) - SquareTest(x0 - 1, y0 + 1,xc,yc,featurePoints); - - it = featurePoints.begin(); - std::advance(it, functionIndex); - - if(1.f - fractx < it->first && 1.f - fracty < it->first) - SquareTest(x0 + 1, y0 + 1,xc,yc,featurePoints); - - it = featurePoints.begin(); - std::advance(it, functionIndex); - - return it->first * m_functionScales[functionIndex]; - } - - float Worley::Get(float /*x*/, float /*y*/, float /*z*/, float /*scale*/) const - { - throw std::runtime_error("Worley 3D not available yet."); - } - - float Worley::Get(float /*x*/, float /*y*/, float /*z*/, float /*w*/, float /*scale*/) const - { - throw std::runtime_error("Worley 4D not available yet."); - } - - void Worley::Set(WorleyFunction func) - { - m_function = func; - } - - void Worley::SquareTest(int xi, int yi, float x, float y, std::map& featurePoints) const - { - int ii = xi & 255; - int jj = yi & 255; - - std::size_t seed = m_permutations[ii + m_permutations[jj]]; - - //On initialise notre rng avec seed - std::minstd_rand0 randomNumberGenerator(static_cast(seed)); - - //On prend un nombre de points à déterminer dans le cube, compris entre 1 et 8 - std::size_t m = (seed & 7) + 1; - - //On calcule les emplacements des différents points - for(std::size_t i(0) ; i < m; ++i) - { - Nz::Vector2f featurePoint; - featurePoint.x = (randomNumberGenerator() & 1023) / 1023.f + static_cast(xi); - featurePoint.y = (randomNumberGenerator() & 1023) / 1023.f + static_cast(yi); - - // TODO : Check order is correct - float distance = std::sqrt((featurePoint.x - x) * (featurePoint.x - x) + - (featurePoint.y - y) * (featurePoint.y - y)); - - //Insertion dans la liste triée - featurePoints[distance] = featurePoint; - } - } -} diff --git a/tests/Engine/Lua/LuaClass.cpp b/tests/Engine/Lua/LuaClass.cpp deleted file mode 100644 index 5cddb3cb1..000000000 --- a/tests/Engine/Lua/LuaClass.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#include -#include -#include -#include - -class LuaClass_Test -{ - public: - LuaClass_Test() = default; - LuaClass_Test(const LuaClass_Test& other) = default; - LuaClass_Test& operator=(const LuaClass_Test& other) = default; - virtual ~LuaClass_Test() = default; - - LuaClass_Test(int i, bool j = false) : - m_i(i), - m_j(j) - { - } - - virtual int GetI() const - { - return m_i; - } - - bool GetJ() const - { - return m_j; - } - - int GetDefault(int defaultValue = 0) - { - return defaultValue; - } - - static int StaticMethodWithArguments(int a, int b) - { - return a + b; - } - - private: - int m_i; - bool m_j; -}; - -class LuaClass_InheritTest : public LuaClass_Test -{ - public: - LuaClass_InheritTest() : - LuaClass_Test(5, true) - { - } - - int GetI() const override - { - return LuaClass_Test::GetI() + 3; - } -}; - -class LuaClass_TestWithHandle : public Nz::HandledObject -{ - public: - int GetI() const - { - return m_i; - } - - int GetDefault(int defaultValue = 0) - { - return defaultValue; - } - - private: - int m_i = 8; -}; - -inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, LuaClass_Test* arg, Nz::TypeTag) -{ - REQUIRE(instance.IsOfType(index, "Test")); - *arg = *static_cast(instance.ToUserdata(index)); - return 1; -} - -inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, Nz::ObjectHandle* arg, Nz::TypeTag>) -{ - REQUIRE(instance.IsOfType(index, "TestWithHandle")); - *arg = *static_cast*>(instance.ToUserdata(index)); - return 1; -} - -inline unsigned int LuaImplQueryArg(const Nz::LuaState& instance, int index, LuaClass_InheritTest* arg, Nz::TypeTag) -{ - REQUIRE(instance.IsOfType(index, "InheritTest")); - *arg = *static_cast(instance.ToUserdata(index)); - return 1; -} - -SCENARIO("LuaClass", "[LUA][LUACLASS]") -{ - GIVEN("One lua class for our Test class") - { - Nz::LuaInstance luaInstance; - Nz::LuaClass test; - Nz::LuaClass inheritTest; - using TestHandle = Nz::ObjectHandle; - Nz::LuaClass testHandle; - - WHEN("We bind the methods") - { - test.Reset("Test"); - - test.BindDefaultConstructor(); - - test.SetConstructor([] (Nz::LuaState& lua, LuaClass_Test* instance, std::size_t argumentCount) - { - std::size_t argCount = std::min(argumentCount, 2U); - - int argIndex = 1; - switch (argCount) - { - case 1: - { - int iValue = lua.Check(&argIndex, 0); - - Nz::PlacementNew(instance, iValue); - return true; - } - - case 2: - { - int iValue = lua.Check(&argIndex, 0); - bool j = lua.Check(&argIndex, false); - - Nz::PlacementNew(instance, iValue, j); - return true; - } - } - - lua.Error("No matching overload for Test constructor"); - return false; - }); - - test.BindMethod("GetI", &LuaClass_Test::GetI); - test.BindMethod("GetJ", &LuaClass_Test::GetJ); - test.BindMethod("GetDefault", &LuaClass_Test::GetDefault, 0); - - test.BindStaticMethod("StaticMethodWithArguments", [] (Nz::LuaState& state) -> int - { - int argIndex = 1; - int result = LuaClass_Test::StaticMethodWithArguments(state.Check(&argIndex), state.Check(&argIndex)); - - state.Push(result); - return 1; - }); - - test.Register(luaInstance); - - THEN("We should be able to call them") - { - int value = 1; - int staticResult = value + value; - - luaInstance.PushFunction([=](Nz::LuaState& state) -> int - { - int argIndex = 1; - LuaClass_Test result = state.Check(&argIndex); - CHECK(result.GetI() == value); - CHECK_FALSE(result.GetJ()); - return 1; - }); - luaInstance.SetGlobal("CheckTest"); - - luaInstance.PushFunction([=](Nz::LuaState& state) -> int - { - int argIndex = 1; - int result = state.Check(&argIndex); - CHECK(result == staticResult); - return 1; - }); - luaInstance.SetGlobal("CheckStatic"); - - luaInstance.PushFunction([=](Nz::LuaState& state) -> int - { - int argIndex = 1; - LuaClass_Test result = state.Check(&argIndex); - CHECK(result.GetI() == staticResult); - CHECK(result.GetJ()); - return 1; - }); - luaInstance.SetGlobal("CheckFinalTest"); - - REQUIRE(luaInstance.ExecuteFromFile("resources/Engine/Lua/LuaClass.lua")); - REQUIRE(luaInstance.GetGlobal("test_Test") == Nz::LuaType_Function); - luaInstance.Call(0); - } - - AND_THEN("With a subclass") - { - inheritTest.Reset("InheritTest"); - - inheritTest.Inherit(test); - inheritTest.BindDefaultConstructor(); - - inheritTest.Register(luaInstance); - - luaInstance.PushFunction([=](Nz::LuaState& state) -> int - { - int argIndex = 1; - LuaClass_InheritTest result = state.Check(&argIndex); - CHECK(result.GetI() == 8); - CHECK(result.GetJ()); - return 1; - }); - luaInstance.SetGlobal("CheckInheritTest"); - - REQUIRE(luaInstance.ExecuteFromFile("resources/Engine/Lua/LuaClass.lua")); - REQUIRE(luaInstance.GetGlobal("test_InheritTest") == Nz::LuaType_Function); - luaInstance.Call(0); - } - } - - WHEN("We bind the object with Handle") - { - int defaultValue = 5; - - testHandle.Reset("TestHandle"); - testHandle.BindMethod("IsValid", &TestHandle::IsValid); - testHandle.BindMethod("GetI", &LuaClass_TestWithHandle::GetI); - testHandle.BindMethod("GetDefault", &LuaClass_TestWithHandle::GetDefault, defaultValue); - testHandle.Register(luaInstance); - - THEN("We can ensure the following properties") - { - luaInstance.PushFunction([=](Nz::LuaState& state) -> int - { - int argIndex = 1; - TestHandle result = state.Check(&argIndex); - CHECK(result->GetI() == 8); - CHECK(result->GetDefault() == defaultValue); - return 1; - }); - luaInstance.SetGlobal("CheckTestHandle"); - - REQUIRE(luaInstance.ExecuteFromFile("resources/Engine/Lua/LuaClass.lua")); - REQUIRE(luaInstance.GetGlobal("test_TestHandle") == Nz::LuaType_Function); - luaInstance.Call(0); - } - } - } -} diff --git a/tests/Engine/Lua/LuaCoroutine.cpp b/tests/Engine/Lua/LuaCoroutine.cpp deleted file mode 100644 index 3ab42d6b9..000000000 --- a/tests/Engine/Lua/LuaCoroutine.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -SCENARIO("LuaCoroutine", "[LUA][LUACOROUTINE]") -{ - GIVEN("One lua with coroutine") - { - Nz::LuaInstance luaInstance; - luaInstance.LoadLibraries(Nz::LuaLib_Coroutine); - - REQUIRE(luaInstance.ExecuteFromFile("resources/Engine/Lua/LuaCoroutine.lua")); - - Nz::LuaCoroutine coroutine = luaInstance.NewCoroutine(); - REQUIRE(coroutine.GetGlobal("infinite") == Nz::LuaType_Function); - coroutine.PushInteger(4); - CHECK(coroutine.Call(1)); - - coroutine.Resume(); - CHECK(coroutine.CheckInteger(1) == 1); - coroutine.Resume(); - CHECK(coroutine.CheckInteger(1) == -1); - coroutine.Resume(); - CHECK(coroutine.CheckInteger(1) == 0); - coroutine.Resume(); - CHECK(coroutine.CheckInteger(1) == 1); - - coroutine.Resume(); - CHECK_FALSE(coroutine.CanResume()); - } -} diff --git a/tests/Engine/Lua/LuaInstance.cpp b/tests/Engine/Lua/LuaInstance.cpp deleted file mode 100644 index 6042704bf..000000000 --- a/tests/Engine/Lua/LuaInstance.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -#include - -SCENARIO("LuaInstance", "[LUA][LUAINSTANCE]") -{ - GIVEN("One lua instance") - { - Nz::LuaInstance luaInstance; - - WHEN("We set memory constraint") - { - luaInstance.SetMemoryLimit(1'000); - - THEN("If we excess memory, it should crash") - { - REQUIRE_THROWS_WITH(luaInstance.Execute(R"( - global t = {} - for 1,10000000 do - t[i] = i - end - )"), Catch::Matchers::Contains("memory")); - } - } - - WHEN("We set time constraint") - { - luaInstance.SetTimeLimit(10); - - THEN("If we excess time, it should produce an error") - { - CHECK(!luaInstance.Execute(R"( - function ack(M,N) - if M == 0 then return N + 1 end - if N == 0 then return ack(M-1,1) end - return ack(M-1,ack(M, N-1)) - end - ack(100, 100) - )")); - - REQUIRE_THAT(luaInstance.GetLastError().ToStdString(), Catch::Matchers::Contains("time")); - } - } - } - - GIVEN("Two instances") - { - Nz::LuaInstance luaInstance; - - int memoryLimit = 10'000; - int timeLimit = 1'000; - luaInstance.SetMemoryLimit(memoryLimit); - luaInstance.SetTimeLimit(timeLimit); - - int value = 5; - luaInstance.PushInteger(value); - - WHEN("We use move constructor") - { - Nz::LuaInstance movedInstance(std::move(luaInstance)); - - THEN("We should be able to retrieve the value") - { - CHECK(movedInstance.CheckInteger(1) == value); - CHECK(movedInstance.GetMemoryLimit() == memoryLimit); - CHECK(movedInstance.GetTimeLimit() == timeLimit); - } - } - - WHEN("We use move assignment") - { - Nz::LuaInstance movedInstance; - movedInstance.PushInteger(value + 1); - movedInstance = std::move(luaInstance); - - THEN("We should be able to retrieve the value") - { - CHECK(movedInstance.CheckInteger(1) == value); - CHECK(movedInstance.GetMemoryLimit() == memoryLimit); - CHECK(movedInstance.GetTimeLimit() == timeLimit); - } - } - } -} diff --git a/tests/Engine/Lua/LuaState.cpp b/tests/Engine/Lua/LuaState.cpp deleted file mode 100644 index 430927d98..000000000 --- a/tests/Engine/Lua/LuaState.cpp +++ /dev/null @@ -1,216 +0,0 @@ -#include -#include - -static int counter(lua_State* L) -{ - Nz::LuaInstance& luaInstance = Nz::LuaInstance::GetInstance(L); - double val = luaInstance.ToNumber(luaInstance.GetIndexOfUpValue(1)); - luaInstance.PushNumber(++val); - luaInstance.PushValue(-1); - luaInstance.Replace(luaInstance.GetIndexOfUpValue(1)); - return 1; -} - -struct TestLuaState -{ - int a = 3; - float b = 5.f; -}; - -struct TestMetaTable -{ - float x = 1.f; - float y = 2.f; -}; - -inline int LuaImplReplyVal(const Nz::LuaState& state, TestLuaState&& val, Nz::TypeTag) -{ - state.PushTable(); - state.PushField("a", val.a); - state.PushField("b", val.b); - - return 1; -} - -inline unsigned int LuaImplQueryArg(const Nz::LuaState& state, int index, TestLuaState* arg, Nz::TypeTag) -{ - state.CheckType(index, Nz::LuaType_Table); - - arg->a = state.CheckField("a", index); - arg->b = state.CheckField("b", index); - - return 1; -} - -SCENARIO("LuaState", "[LUA][LUASTATE]") -{ - GIVEN("One lua instance") - { - Nz::LuaInstance luaInstance; - luaInstance.LoadLibraries(Nz::LuaLib_Math); - - WHEN("We push different primitive types") - { - bool booleanValue = true; - long long integerValue = 5LL; - double doubleValue = -55.0; - const char* stringValue = "test"; - Nz::String nazaraValue = "Nazara"; - luaInstance.PushBoolean(booleanValue); - luaInstance.PushInteger(integerValue); - luaInstance.PushNil(); - luaInstance.PushNumber(doubleValue); - luaInstance.PushString(stringValue); - luaInstance.PushString(nazaraValue); - - THEN("We should be able to retrieve them") - { - CHECK(luaInstance.CheckBoolean(1) == booleanValue); - CHECK(luaInstance.CheckInteger(2) == integerValue); - bool succeeded = false; - CHECK(luaInstance.ToInteger(2, &succeeded) == integerValue); - CHECK(succeeded); - CHECK(luaInstance.ToPointer(3) == nullptr); - CHECK(luaInstance.CheckNumber(4) == Approx(doubleValue)); - succeeded = false; - CHECK(luaInstance.ToNumber(4, &succeeded) == Approx(doubleValue)); - CHECK(succeeded); - CHECK(luaInstance.CheckString(5) == std::string(stringValue)); - CHECK(luaInstance.CheckString(6) == nazaraValue); - std::size_t length = 0; - CHECK(luaInstance.ToString(6, &length) == nazaraValue); - CHECK(length == nazaraValue.GetSize()); - } - } - - WHEN("We use basic operations") - { - luaInstance.PushInteger(1); - luaInstance.PushInteger(2); - - THEN("We should behave normally") - { - CHECK(luaInstance.Compare(1, 2, Nz::LuaComparison_Less)); - luaInstance.Compute(Nz::LuaOperation_Substraction); - CHECK(luaInstance.ToInteger(1) == -1); - } - } - - WHEN("We manipulate the stack") - { - Nz::String stringValue = "hello"; - luaInstance.PushBoolean(true); - luaInstance.PushNumber(10.0); - luaInstance.PushNil(); - luaInstance.PushString(stringValue); - /* true 10.0 nil hello */ - - THEN("These effects are expected") - { - luaInstance.PushValue(-4); - /* true 10.0 nil hello true */ - CHECK(luaInstance.CheckBoolean(5)); - - luaInstance.Replace(3); - /* true 10.0 true hello */ - CHECK(luaInstance.CheckBoolean(3)); - - luaInstance.Remove(-2); - /* true 10.0 hello */ - CHECK(luaInstance.CheckString(3) == stringValue); - - luaInstance.Pop(2); - /* true */ - CHECK_FALSE(luaInstance.IsValid(2)); - } - } - - WHEN("We try the CFunction") - { - double counterValue = 55.0; - luaInstance.PushFunction([=](Nz::LuaState& s) -> int { - s.PushNumber(counterValue); - s.PushCFunction(&counter, 1); - return 1; - }); - - THEN("We can call them") - { - luaInstance.Call(0); // We call our counter creator - luaInstance.Call(0); // We call our counter, which increments the value - CHECK(luaInstance.ToNumber(0) == Approx(counterValue + 1.0)); - } - } - - WHEN("We push our user type locally") - { - luaInstance.Push(TestLuaState()); - - THEN("We can retrieve it") - { - int index = 1; - TestLuaState popped = luaInstance.Check(&index); - CHECK(popped.a == 3); - CHECK(popped.b == Approx(5.0)); - } - } - - WHEN("We push our user type globally") - { - luaInstance.PushGlobal("TestLuaState", TestLuaState()); - - THEN("We can retrieve it") - { - TestLuaState popped = luaInstance.CheckGlobal("TestLuaState"); - CHECK(popped.a == 3); - CHECK(popped.b == Approx(5.0)); - } - } - - WHEN("We define a lua function") - { - luaInstance.Execute(R"( - function f (x, y) - return (x^2 * math.sin(y))/(1 - x) - end - )"); - - THEN("We can call it from the code") - { - REQUIRE(luaInstance.GetGlobal("f") == Nz::LuaType_Function); - luaInstance.Push(3.0, 2.0); - luaInstance.Call(2, 1); - CHECK(luaInstance.ToNumber(1) == Approx(-4.09).margin(0.1)); - } - } - - WHEN("We push a std::vector locally") - { - std::vector vec { 1, 5, -8, 6, -4 }; - luaInstance.Push(std::vector { vec }); - - THEN("We can retrieve it with correct values") - { - int index = 1; - std::vector otherVec = luaInstance.Check>(&index); - - for (std::size_t i {}; i < otherVec.size(); ++i) - CHECK(otherVec[i] == vec[i]); - } - } - - WHEN("We push a std::vector globally") - { - std::vector vec { 1, 5, -8, 6, -4 }; - luaInstance.PushGlobal("vector", std::vector { vec }); - - THEN("We can retrieve it with correct values") - { - std::vector otherVec = luaInstance.CheckGlobal>("vector"); - - for (std::size_t i {}; i < otherVec.size(); ++i) - CHECK(otherVec[i] == vec[i]); - } - } - } -}