Merge remote-tracking branch 'refs/remotes/origin/master' into culling
This commit is contained in:
commit
3c5594c206
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
#ifndef NDK_CONSOLE_HPP
|
#ifndef NDK_CONSOLE_HPP
|
||||||
#define NDK_CONSOLE_HPP
|
#define NDK_CONSOLE_HPP
|
||||||
|
|
||||||
|
|
@ -99,3 +100,4 @@ namespace Ndk
|
||||||
#include <NDK/Console.inl>
|
#include <NDK/Console.inl>
|
||||||
|
|
||||||
#endif // NDK_CONSOLE_HPP
|
#endif // NDK_CONSOLE_HPP
|
||||||
|
#endif // NDK_SERVER
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_HPP
|
||||||
|
#define NDK_LUABINDING_HPP
|
||||||
|
|
||||||
|
#include <NDK/BaseComponent.hpp>
|
||||||
|
#include <NDK/Entity.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding
|
||||||
|
{
|
||||||
|
friend class LuaBinding_SDK;
|
||||||
|
|
||||||
|
public:
|
||||||
|
LuaBinding();
|
||||||
|
~LuaBinding() = default;
|
||||||
|
|
||||||
|
template<typename T> void BindComponent(const Nz::String& name);
|
||||||
|
|
||||||
|
void RegisterClasses(Nz::LuaInstance& instance);
|
||||||
|
|
||||||
|
std::unique_ptr<LuaBinding_Base> core;
|
||||||
|
std::unique_ptr<LuaBinding_Base> math;
|
||||||
|
std::unique_ptr<LuaBinding_Base> network;
|
||||||
|
std::unique_ptr<LuaBinding_Base> sdk;
|
||||||
|
std::unique_ptr<LuaBinding_Base> utility;
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
std::unique_ptr<LuaBinding_Base> audio;
|
||||||
|
std::unique_ptr<LuaBinding_Base> graphics;
|
||||||
|
std::unique_ptr<LuaBinding_Base> renderer;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename T>
|
||||||
|
static int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component);
|
||||||
|
|
||||||
|
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
||||||
|
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
||||||
|
|
||||||
|
struct ComponentBinding
|
||||||
|
{
|
||||||
|
AddComponentFunc adder;
|
||||||
|
ComponentIndex index;
|
||||||
|
GetComponentFunc getter;
|
||||||
|
Nz::String name;
|
||||||
|
};
|
||||||
|
|
||||||
|
ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 2);
|
||||||
|
|
||||||
|
std::vector<ComponentBinding> m_componentBinding;
|
||||||
|
std::unordered_map<Nz::String, ComponentIndex> m_componentBindingByName;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding.inl>
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_HPP
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// This file is part of the "Nazara Development Kit"
|
// This file is part of the "Nazara Development Kit"
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
|
|
@ -32,18 +32,8 @@ namespace Ndk
|
||||||
m_componentBindingByName[name] = T::componentIndex;
|
m_componentBindingByName[name] = T::componentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Adds a component to an entity
|
|
||||||
* \return 1 in case of success
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the component
|
|
||||||
* \param handle Entity which component will be added to
|
|
||||||
*
|
|
||||||
* \remark T must be a subtype of BaseComponent
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
int LuaBinding::AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||||
{
|
{
|
||||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||||
|
|
||||||
|
|
@ -52,18 +42,8 @@ namespace Ndk
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Pushes a component
|
|
||||||
* \return 1 in case of success
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the component
|
|
||||||
* \param component Component that will be pushed
|
|
||||||
*
|
|
||||||
* \remark T must be a subtype of BaseComponent
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
int LuaBinding::PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||||
{
|
{
|
||||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||||
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_AUDIO_HPP
|
||||||
|
#define NDK_LUABINDING_AUDIO_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Audio/Music.hpp>
|
||||||
|
#include <Nazara/Audio/Sound.hpp>
|
||||||
|
#include <Nazara/Audio/SoundBuffer.hpp>
|
||||||
|
#include <Nazara/Audio/SoundEmitter.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Audio : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Audio(LuaBinding& binding);
|
||||||
|
~LuaBinding_Audio() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::Music> music;
|
||||||
|
Nz::LuaClass<Nz::Sound> sound;
|
||||||
|
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
||||||
|
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_CORE_HPP
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_BASE_HPP
|
||||||
|
#define NDK_LUABINDING_BASE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Lua/LuaClass.hpp>
|
||||||
|
#include <Nazara/Lua/LuaInstance.hpp>
|
||||||
|
#include <NDK/Prerequesites.hpp>
|
||||||
|
|
||||||
|
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 NDK_API LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Base(LuaBinding& binding);
|
||||||
|
virtual ~LuaBinding_Base();
|
||||||
|
|
||||||
|
virtual void Register(Nz::LuaInstance& instance) = 0;
|
||||||
|
|
||||||
|
// Implementation lies in the respective .cpp files (still searching for a cleaner way..)
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindCore(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindMath(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindNetwork(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindSDK(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindUtility(LuaBinding& binding);
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindAudio(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindGraphics(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindRenderer(LuaBinding& binding);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
LuaBinding& m_binding;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_BASE_HPP
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_CORE_HPP
|
||||||
|
#define NDK_LUABINDING_CORE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Clock.hpp>
|
||||||
|
#include <Nazara/Core/Directory.hpp>
|
||||||
|
#include <Nazara/Core/File.hpp>
|
||||||
|
#include <Nazara/Core/Stream.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Core : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Core(LuaBinding& binding);
|
||||||
|
~LuaBinding_Core() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::Clock> clock;
|
||||||
|
Nz::LuaClass<Nz::Directory> directory;
|
||||||
|
Nz::LuaClass<Nz::File> file;
|
||||||
|
Nz::LuaClass<Nz::Stream> stream;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_CORE_HPP
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_GRAPHICS_HPP
|
||||||
|
#define NDK_LUABINDING_GRAPHICS_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||||
|
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Graphics : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Graphics(LuaBinding& binding);
|
||||||
|
~LuaBinding_Graphics() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::AbstractViewer> abstractViewer;
|
||||||
|
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
||||||
|
Nz::LuaClass<Nz::MaterialRef> material;
|
||||||
|
Nz::LuaClass<Nz::ModelRef> model;
|
||||||
|
Nz::LuaClass<Nz::SpriteRef> sprite;
|
||||||
|
Nz::LuaClass<Nz::SpriteLibrary> spriteLibrary;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_GRAPHICS_HPP
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_MATH_HPP
|
||||||
|
#define NDK_LUABINDING_MATH_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Math/EulerAngles.hpp>
|
||||||
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
|
#include <Nazara/Math/Quaternion.hpp>
|
||||||
|
#include <Nazara/Math/Rect.hpp>
|
||||||
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Math : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Math(LuaBinding& binding);
|
||||||
|
~LuaBinding_Math() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::EulerAnglesd> eulerAngles;
|
||||||
|
Nz::LuaClass<Nz::Matrix4d> matrix4d;
|
||||||
|
Nz::LuaClass<Nz::Quaterniond> quaternion;
|
||||||
|
Nz::LuaClass<Nz::Rectd> rect;
|
||||||
|
Nz::LuaClass<Nz::Vector2d> vector2d;
|
||||||
|
Nz::LuaClass<Nz::Vector3d> vector3d;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_MATH_HPP
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_NETWORK_HPP
|
||||||
|
#define NDK_LUABINDING_NETWORK_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Network/AbstractSocket.hpp>
|
||||||
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Network : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Network(LuaBinding& binding);
|
||||||
|
~LuaBinding_Network() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::AbstractSocket> abstractSocket;
|
||||||
|
Nz::LuaClass<Nz::IpAddress> ipAddress;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_NETWORK_HPP
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_RENDERER_HPP
|
||||||
|
#define NDK_LUABINDING_RENDERER_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Renderer : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Renderer(LuaBinding& binding);
|
||||||
|
~LuaBinding_Renderer() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::TextureRef> texture;
|
||||||
|
Nz::LuaClass<Nz::TextureLibrary> textureLibrary;
|
||||||
|
Nz::LuaClass<Nz::TextureManager> textureManager;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_RENDERER_HPP
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_SDK_HPP
|
||||||
|
#define NDK_LUABINDING_SDK_HPP
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/Console.hpp>
|
||||||
|
#include <NDK/Entity.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class Application;
|
||||||
|
|
||||||
|
class NDK_API LuaBinding_SDK : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_SDK(LuaBinding& binding);
|
||||||
|
~LuaBinding_SDK() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Application*> application;
|
||||||
|
Nz::LuaClass<EntityHandle> entity;
|
||||||
|
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
||||||
|
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
||||||
|
Nz::LuaClass<WorldHandle> world;
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
Nz::LuaClass<CameraComponentHandle> cameraComponent;
|
||||||
|
Nz::LuaClass<ConsoleHandle> console;
|
||||||
|
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_SDK_HPP
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_UTILITY_HPP
|
||||||
|
#define NDK_LUABINDING_UTILITY_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Utility/AbstractImage.hpp>
|
||||||
|
#include <Nazara/Utility/Font.hpp>
|
||||||
|
#include <Nazara/Utility/Keyboard.hpp>
|
||||||
|
#include <Nazara/Utility/Node.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Utility : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Utility(LuaBinding& binding);
|
||||||
|
~LuaBinding_Utility() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
// Utility
|
||||||
|
Nz::LuaClass<Nz::AbstractImageRef> abstractImage;
|
||||||
|
Nz::LuaClass<Nz::FontRef> font;
|
||||||
|
Nz::LuaClass<Nz::Keyboard> keyboard;
|
||||||
|
Nz::LuaClass<Nz::Node> node;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_UTILITY_HPP
|
||||||
|
|
@ -156,9 +156,10 @@ namespace Nz
|
||||||
|
|
||||||
params->animated = instance.CheckField<bool>("Animated", params->animated);
|
params->animated = instance.CheckField<bool>("Animated", params->animated);
|
||||||
params->center = instance.CheckField<bool>("Center", params->center);
|
params->center = instance.CheckField<bool>("Center", params->center);
|
||||||
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
|
|
||||||
params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
|
params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
|
||||||
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
|
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
|
||||||
|
params->texCoordOffset = instance.CheckField<Vector2f>("TexCoordOffset", params->texCoordOffset);
|
||||||
|
params->texCoordScale = instance.CheckField<Vector2f>("TexCoordScale", params->texCoordScale);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,147 +0,0 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Development Kit"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NDK_LUABINDING_HPP
|
|
||||||
#define NDK_LUABINDING_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Core.hpp>
|
|
||||||
#include <Nazara/Lua.hpp>
|
|
||||||
#include <Nazara/Math.hpp>
|
|
||||||
#include <Nazara/Network.hpp>
|
|
||||||
#include <Nazara/Utility.hpp>
|
|
||||||
#include <NDK/Application.hpp>
|
|
||||||
#include <NDK/Components.hpp>
|
|
||||||
#include <NDK/Entity.hpp>
|
|
||||||
#include <NDK/Systems.hpp>
|
|
||||||
#include <NDK/World.hpp>
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
#include <Nazara/Audio.hpp>
|
|
||||||
#include <Nazara/Graphics.hpp>
|
|
||||||
#include <Nazara/Renderer.hpp>
|
|
||||||
#include <NDK/Console.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
class NDK_API LuaBinding
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LuaBinding();
|
|
||||||
~LuaBinding() = default;
|
|
||||||
|
|
||||||
template<typename T> void BindComponent(const Nz::String& name);
|
|
||||||
|
|
||||||
void RegisterClasses(Nz::LuaInstance& instance);
|
|
||||||
|
|
||||||
// Core
|
|
||||||
Nz::LuaClass<Nz::Clock> clock;
|
|
||||||
Nz::LuaClass<Nz::Directory> directory;
|
|
||||||
Nz::LuaClass<Nz::File> file;
|
|
||||||
Nz::LuaClass<Nz::Stream> stream;
|
|
||||||
|
|
||||||
// Math
|
|
||||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAngles;
|
|
||||||
Nz::LuaClass<Nz::Matrix4d> matrix4d;
|
|
||||||
Nz::LuaClass<Nz::Quaterniond> quaternion;
|
|
||||||
Nz::LuaClass<Nz::Rectd> rect;
|
|
||||||
Nz::LuaClass<Nz::Vector2d> vector2d;
|
|
||||||
Nz::LuaClass<Nz::Vector3d> vector3d;
|
|
||||||
|
|
||||||
// Network
|
|
||||||
Nz::LuaClass<Nz::AbstractSocket> abstractSocket;
|
|
||||||
Nz::LuaClass<Nz::IpAddress> ipAddress;
|
|
||||||
|
|
||||||
// Utility
|
|
||||||
Nz::LuaClass<Nz::AbstractImageRef> abstractImage;
|
|
||||||
Nz::LuaClass<Nz::FontRef> font;
|
|
||||||
Nz::LuaClass<Nz::Keyboard> keyboard;
|
|
||||||
Nz::LuaClass<Nz::Node> node;
|
|
||||||
|
|
||||||
// SDK
|
|
||||||
Nz::LuaClass<Application*> application;
|
|
||||||
Nz::LuaClass<EntityHandle> entity;
|
|
||||||
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
|
||||||
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
|
||||||
Nz::LuaClass<WorldHandle> world;
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
// Audio
|
|
||||||
Nz::LuaClass<Nz::Music> music;
|
|
||||||
Nz::LuaClass<Nz::Sound> sound;
|
|
||||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
|
||||||
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
|
||||||
|
|
||||||
// Graphics
|
|
||||||
Nz::LuaClass<Nz::AbstractViewer> abstractViewer;
|
|
||||||
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
|
||||||
Nz::LuaClass<Nz::MaterialRef> material;
|
|
||||||
Nz::LuaClass<Nz::ModelRef> model;
|
|
||||||
Nz::LuaClass<Nz::SpriteRef> sprite;
|
|
||||||
Nz::LuaClass<Nz::SpriteLibrary> spriteLibrary;
|
|
||||||
Nz::LuaClass<Nz::TextureLibrary> textureLibrary;
|
|
||||||
Nz::LuaClass<Nz::TextureManager> textureManager;
|
|
||||||
|
|
||||||
// Renderer
|
|
||||||
Nz::LuaClass<Nz::TextureRef> texture;
|
|
||||||
|
|
||||||
// SDK
|
|
||||||
Nz::LuaClass<CameraComponentHandle> cameraComponent;
|
|
||||||
Nz::LuaClass<ConsoleHandle> console;
|
|
||||||
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
void BindCore();
|
|
||||||
void BindMath();
|
|
||||||
void BindNetwork();
|
|
||||||
void BindSDK();
|
|
||||||
void BindUtility();
|
|
||||||
|
|
||||||
void RegisterCore(Nz::LuaInstance& instance);
|
|
||||||
void RegisterMath(Nz::LuaInstance& instance);
|
|
||||||
void RegisterNetwork(Nz::LuaInstance& instance);
|
|
||||||
void RegisterSDK(Nz::LuaInstance& instance);
|
|
||||||
void RegisterUtility(Nz::LuaInstance& instance);
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
void BindAudio();
|
|
||||||
void BindGraphics();
|
|
||||||
void BindRenderer();
|
|
||||||
|
|
||||||
void RegisterAudio(Nz::LuaInstance& instance);
|
|
||||||
void RegisterGraphics(Nz::LuaInstance& instance);
|
|
||||||
void RegisterRenderer(Nz::LuaInstance& instance);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
|
||||||
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
|
||||||
|
|
||||||
struct ComponentBinding
|
|
||||||
{
|
|
||||||
AddComponentFunc adder;
|
|
||||||
ComponentIndex index;
|
|
||||||
GetComponentFunc getter;
|
|
||||||
Nz::String name;
|
|
||||||
};
|
|
||||||
|
|
||||||
ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 2);
|
|
||||||
|
|
||||||
std::vector<ComponentBinding> m_componentBinding;
|
|
||||||
std::unordered_map<Nz::String, ComponentIndex> m_componentBindingByName;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component);
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.inl>
|
|
||||||
|
|
||||||
#endif // NDK_LUABINDING_HPP
|
|
||||||
|
|
@ -152,7 +152,7 @@ namespace Ndk
|
||||||
windowDimensions.MakeZero();
|
windowDimensions.MakeZero();
|
||||||
|
|
||||||
overlay->console = std::make_unique<Console>(*info.overlayWorld, Nz::Vector2f(windowDimensions), overlay->lua);
|
overlay->console = std::make_unique<Console>(*info.overlayWorld, Nz::Vector2f(windowDimensions), overlay->lua);
|
||||||
|
|
||||||
Console& consoleRef = *overlay->console;
|
Console& consoleRef = *overlay->console;
|
||||||
|
|
||||||
// Redirect logs toward the console
|
// Redirect logs toward the console
|
||||||
|
|
@ -248,4 +248,4 @@ namespace Ndk
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Application* Application::s_application = nullptr;
|
Application* Application::s_application = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
|
||||||
|
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);
|
||||||
|
#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::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
core->Register(instance);
|
||||||
|
math->Register(instance);
|
||||||
|
network->Register(instance);
|
||||||
|
sdk->Register(instance);
|
||||||
|
utility->Register(instance);
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
audio->Register(instance);
|
||||||
|
graphics->Register(instance);
|
||||||
|
renderer->Register(instance);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ComponentType (fake enumeration to expose component indexes)
|
||||||
|
instance.PushTable(0, m_componentBinding.size());
|
||||||
|
{
|
||||||
|
for (const ComponentBinding& entry : m_componentBinding)
|
||||||
|
{
|
||||||
|
if (entry.name.IsEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
instance.PushField(entry.name, entry.index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
instance.SetGlobal("ComponentType");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,198 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Audio.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindAudio(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Audio>(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::MusicParams());
|
||||||
|
|
||||||
|
music.BindMethod("Pause", &Nz::Music::Pause);
|
||||||
|
music.BindMethod("Play", &Nz::Music::Play);
|
||||||
|
|
||||||
|
music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset);
|
||||||
|
|
||||||
|
music.BindMethod("Stop", &Nz::Music::Stop);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::StringStream ss("Music(");
|
||||||
|
ss << instance.GetFilePath() << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Sound **********************************/
|
||||||
|
sound.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::LuaInstance& lua, Nz::Sound& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::StringStream ss("Sound(");
|
||||||
|
if (const Nz::SoundBuffer* buffer = instance.GetBuffer())
|
||||||
|
ss << buffer;
|
||||||
|
|
||||||
|
ss << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::SoundBuffer **********************************/
|
||||||
|
soundBuffer.Reset("SoundBuffer");
|
||||||
|
{
|
||||||
|
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
NazaraUnused(lua);
|
||||||
|
NazaraUnused(argumentCount);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, Nz::SoundBuffer::New());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy);
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration);
|
||||||
|
soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat);
|
||||||
|
soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount);
|
||||||
|
soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate);
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid);
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams());
|
||||||
|
|
||||||
|
soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int index = 2;
|
||||||
|
Nz::AudioFormat format = lua.Check<Nz::AudioFormat>(&index);
|
||||||
|
unsigned int sampleCount = lua.Check<unsigned int>(&index);
|
||||||
|
unsigned int sampleRate = lua.Check<unsigned int>(&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<const Nz::Int16*>(buffer)));
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
lua.PushString(reinterpret_cast<const char*>(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16));
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::StringStream ss("SoundBuffer(");
|
||||||
|
if (instance->IsValid())
|
||||||
|
{
|
||||||
|
Nz::String filePath = instance->GetFilePath();
|
||||||
|
if (!filePath.IsEmpty())
|
||||||
|
ss << "File: " << filePath << ", ";
|
||||||
|
|
||||||
|
ss << "Duration: " << instance->GetDuration() / 1000.f << "s";
|
||||||
|
}
|
||||||
|
ss << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \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::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
music.Register(instance);
|
||||||
|
sound.Register(instance);
|
||||||
|
soundBuffer.Register(instance);
|
||||||
|
soundEmitter.Register(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
LuaBinding_Base::LuaBinding_Base(LuaBinding& binding) :
|
||||||
|
m_binding(binding)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Base::~LuaBinding_Base() = default;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,354 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Core.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindCore(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Core>(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::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
std::size_t length = lua.Check<std::size_t>(&argIndex);
|
||||||
|
|
||||||
|
std::unique_ptr<char[]> 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::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
std::size_t bufferSize = 0;
|
||||||
|
const char* buffer = lua.CheckString(argIndex, &bufferSize);
|
||||||
|
|
||||||
|
if (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::LuaInstance& lua, Nz::Clock* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, startingValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
||||||
|
bool paused = lua.Check<bool>(&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::LuaInstance& lua, Nz::Clock& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
Nz::StringStream ss("Clock(Elapsed: ");
|
||||||
|
ss << instance.GetSeconds();
|
||||||
|
ss << "s, Paused: ";
|
||||||
|
ss << instance.IsPaused();
|
||||||
|
ss << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************* Nz::Directory ********************************/
|
||||||
|
directory.Reset("Directory");
|
||||||
|
{
|
||||||
|
directory.SetConstructor([] (Nz::LuaInstance& lua, Nz::Directory* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
Nz::PlacementNew(instance, lua.Check<Nz::String>(&argIndex));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
directory.BindMethod("Close", &Nz::Directory::Close);
|
||||||
|
directory.BindMethod("Exists", &Nz::Directory::Exists);
|
||||||
|
directory.BindMethod("GetPath", &Nz::Directory::GetPath);
|
||||||
|
directory.BindMethod("GetPattern", &Nz::Directory::GetPattern);
|
||||||
|
directory.BindMethod("GetResultName", &Nz::Directory::GetResultName);
|
||||||
|
directory.BindMethod("GetResultPath", &Nz::Directory::GetResultPath);
|
||||||
|
directory.BindMethod("GetResultSize", &Nz::Directory::GetResultSize);
|
||||||
|
directory.BindMethod("IsOpen", &Nz::Directory::IsOpen);
|
||||||
|
directory.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory);
|
||||||
|
directory.BindMethod("NextResult", &Nz::Directory::NextResult, true);
|
||||||
|
directory.BindMethod("Open", &Nz::Directory::Open);
|
||||||
|
directory.BindMethod("SetPath", &Nz::Directory::SetPath);
|
||||||
|
directory.BindMethod("SetPattern", &Nz::Directory::SetPattern);
|
||||||
|
|
||||||
|
directory.BindStaticMethod("Copy", Nz::Directory::Copy);
|
||||||
|
directory.BindStaticMethod("Create", Nz::Directory::Create);
|
||||||
|
directory.BindStaticMethod("Exists", Nz::Directory::Exists);
|
||||||
|
directory.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent);
|
||||||
|
directory.BindStaticMethod("Remove", Nz::Directory::Remove);
|
||||||
|
directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
Nz::StringStream ss("Directory(");
|
||||||
|
ss << instance.GetPath();
|
||||||
|
ss << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::File ***********************************/
|
||||||
|
file.Reset("Stream");
|
||||||
|
{
|
||||||
|
file.Inherit(stream);
|
||||||
|
|
||||||
|
file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, filePath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||||
|
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&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("GetCreationTime", &Nz::File::GetCreationTime);
|
||||||
|
file.BindMethod("GetFileName", &Nz::File::GetFileName);
|
||||||
|
file.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
||||||
|
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||||
|
file.BindMethod("IsOpen", &Nz::File::IsOpen);
|
||||||
|
file.BindMethod("Rename", &Nz::File::GetLastWriteTime);
|
||||||
|
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||||
|
file.BindMethod("SetFile", &Nz::File::GetLastWriteTime);
|
||||||
|
|
||||||
|
file.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath);
|
||||||
|
file.BindStaticMethod("ComputeHash", (Nz::ByteArray(*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash);
|
||||||
|
file.BindStaticMethod("Copy", &Nz::File::Copy);
|
||||||
|
file.BindStaticMethod("Delete", &Nz::File::Delete);
|
||||||
|
file.BindStaticMethod("Exists", &Nz::File::Exists);
|
||||||
|
//fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
||||||
|
file.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory);
|
||||||
|
//fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
||||||
|
//fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||||
|
file.BindStaticMethod("GetSize", &Nz::File::GetSize);
|
||||||
|
file.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute);
|
||||||
|
file.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath);
|
||||||
|
file.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators);
|
||||||
|
file.BindStaticMethod("Rename", &Nz::File::Rename);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
return lua.Push(instance.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||||
|
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&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::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
return lua.Push(instance.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Nz::CursorPosition curPos = lua.Check<Nz::CursorPosition>(&argIndex);
|
||||||
|
Nz::Int64 offset = lua.Check<Nz::Int64>(&argIndex);
|
||||||
|
return lua.Push(instance.SetCursorPos(curPos, offset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method SetCursorPos");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
Nz::StringStream ss("File(");
|
||||||
|
if (instance.IsOpen())
|
||||||
|
ss << "Path: " << instance.GetPath();
|
||||||
|
|
||||||
|
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::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
// Classes
|
||||||
|
clock.Register(instance);
|
||||||
|
directory.Register(instance);
|
||||||
|
file.Register(instance);
|
||||||
|
stream.Register(instance);
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
|
||||||
|
// Nz::CursorPosition
|
||||||
|
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
||||||
|
instance.PushTable(0, 3);
|
||||||
|
{
|
||||||
|
instance.PushField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||||
|
instance.PushField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||||
|
instance.PushField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||||
|
}
|
||||||
|
instance.SetGlobal("CursorPosition");
|
||||||
|
|
||||||
|
// Nz::HashType
|
||||||
|
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||||
|
instance.PushTable(0, 9);
|
||||||
|
{
|
||||||
|
instance.PushField("CRC32", Nz::HashType_CRC32);
|
||||||
|
instance.PushField("Fletcher16", Nz::HashType_Fletcher16);
|
||||||
|
instance.PushField("MD5", Nz::HashType_MD5);
|
||||||
|
instance.PushField("SHA1", Nz::HashType_SHA1);
|
||||||
|
instance.PushField("SHA224", Nz::HashType_SHA224);
|
||||||
|
instance.PushField("SHA256", Nz::HashType_SHA256);
|
||||||
|
instance.PushField("SHA384", Nz::HashType_SHA384);
|
||||||
|
instance.PushField("SHA512", Nz::HashType_SHA512);
|
||||||
|
instance.PushField("Whirlpool", Nz::HashType_Whirlpool);
|
||||||
|
}
|
||||||
|
instance.SetGlobal("HashType");
|
||||||
|
|
||||||
|
// Nz::OpenMode
|
||||||
|
static_assert(Nz::OpenMode_Max + 1 == 8, "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
||||||
|
instance.PushTable(0, Nz::OpenMode_Max + 1);
|
||||||
|
{
|
||||||
|
instance.PushField("Append", Nz::OpenMode_Append);
|
||||||
|
instance.PushField("NotOpen", Nz::OpenMode_NotOpen);
|
||||||
|
instance.PushField("Lock", Nz::OpenMode_Lock);
|
||||||
|
instance.PushField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||||
|
instance.PushField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||||
|
instance.PushField("Text", Nz::OpenMode_Text);
|
||||||
|
instance.PushField("Truncate", Nz::OpenMode_Truncate);
|
||||||
|
instance.PushField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||||
|
}
|
||||||
|
instance.SetGlobal("OpenMode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,370 @@
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Graphics.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindGraphics(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Graphics>(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");
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Material ***********************************/
|
||||||
|
material.Reset("Material");
|
||||||
|
{
|
||||||
|
material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
switch (argumentCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance, Nz::Material::New());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
int argIndex = 1;
|
||||||
|
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Material::New(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (lua.IsOfType(argIndex, "Material"))
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Material::New(**static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Material::New(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("Configure", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
||||||
|
{
|
||||||
|
instance->Configure(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua.Push(instance->Configure(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("EnableAlphaTest", &Nz::Material::EnableAlphaTest);
|
||||||
|
material.BindMethod("EnableBlending", &Nz::Material::EnableBlending);
|
||||||
|
material.BindMethod("EnableColorWrite", &Nz::Material::EnableColorWrite);
|
||||||
|
material.BindMethod("EnableDepthBuffer", &Nz::Material::EnableDepthBuffer);
|
||||||
|
material.BindMethod("EnableDepthSorting", &Nz::Material::EnableDepthSorting);
|
||||||
|
material.BindMethod("EnableDepthWrite", &Nz::Material::EnableDepthWrite);
|
||||||
|
material.BindMethod("EnableFaceCulling", &Nz::Material::EnableFaceCulling);
|
||||||
|
material.BindMethod("EnableScissorTest", &Nz::Material::EnableScissorTest);
|
||||||
|
material.BindMethod("EnableShadowCasting", &Nz::Material::EnableShadowCasting);
|
||||||
|
material.BindMethod("EnableShadowReceive", &Nz::Material::EnableShadowReceive);
|
||||||
|
material.BindMethod("EnableStencilTest", &Nz::Material::EnableStencilTest);
|
||||||
|
|
||||||
|
material.BindMethod("EnsurePipelineUpdate", &Nz::Material::EnsurePipelineUpdate);
|
||||||
|
|
||||||
|
material.BindMethod("GetAlphaMap", &Nz::Material::GetAlphaMap);
|
||||||
|
material.BindMethod("GetAlphaThreshold", &Nz::Material::GetAlphaThreshold);
|
||||||
|
material.BindMethod("GetAmbientColor", &Nz::Material::GetAmbientColor);
|
||||||
|
material.BindMethod("GetDepthFunc", &Nz::Material::GetDepthFunc);
|
||||||
|
material.BindMethod("GetDepthMaterial", &Nz::Material::GetDepthMaterial);
|
||||||
|
material.BindMethod("GetDiffuseColor", &Nz::Material::GetDiffuseColor);
|
||||||
|
material.BindMethod("GetDiffuseMap", &Nz::Material::GetDiffuseMap);
|
||||||
|
//material.BindMethod("GetDiffuseSampler", &Nz::Material::GetDiffuseSampler);
|
||||||
|
material.BindMethod("GetDstBlend", &Nz::Material::GetDstBlend);
|
||||||
|
material.BindMethod("GetEmissiveMap", &Nz::Material::GetEmissiveMap);
|
||||||
|
material.BindMethod("GetFaceCulling", &Nz::Material::GetFaceCulling);
|
||||||
|
material.BindMethod("GetFaceFilling", &Nz::Material::GetFaceFilling);
|
||||||
|
material.BindMethod("GetHeightMap", &Nz::Material::GetHeightMap);
|
||||||
|
material.BindMethod("GetLineWidth", &Nz::Material::GetLineWidth);
|
||||||
|
material.BindMethod("GetNormalMap", &Nz::Material::GetNormalMap);
|
||||||
|
//material.BindMethod("GetPipeline", &Nz::Material::GetPipeline);
|
||||||
|
//material.BindMethod("GetPipelineInfo", &Nz::Material::GetPipelineInfo);
|
||||||
|
material.BindMethod("GetPointSize", &Nz::Material::GetPointSize);
|
||||||
|
//material.BindMethod("GetShader", &Nz::Material::GetShader);
|
||||||
|
material.BindMethod("GetShininess", &Nz::Material::GetShininess);
|
||||||
|
material.BindMethod("GetSpecularColor", &Nz::Material::GetSpecularColor);
|
||||||
|
material.BindMethod("GetSpecularMap", &Nz::Material::GetSpecularMap);
|
||||||
|
//material.BindMethod("GetSpecularSampler", &Nz::Material::GetSpecularSampler);
|
||||||
|
material.BindMethod("GetSrcBlend", &Nz::Material::GetSrcBlend);
|
||||||
|
|
||||||
|
material.BindMethod("HasAlphaMap", &Nz::Material::HasAlphaMap);
|
||||||
|
material.BindMethod("HasDepthMaterial", &Nz::Material::HasDepthMaterial);
|
||||||
|
material.BindMethod("HasDiffuseMap", &Nz::Material::HasDiffuseMap);
|
||||||
|
material.BindMethod("HasEmissiveMap", &Nz::Material::HasEmissiveMap);
|
||||||
|
material.BindMethod("HasHeightMap", &Nz::Material::HasHeightMap);
|
||||||
|
material.BindMethod("HasNormalMap", &Nz::Material::HasNormalMap);
|
||||||
|
material.BindMethod("HasSpecularMap", &Nz::Material::HasSpecularMap);
|
||||||
|
|
||||||
|
material.BindMethod("IsAlphaTestEnabled", &Nz::Material::IsAlphaTestEnabled);
|
||||||
|
material.BindMethod("IsBlendingEnabled", &Nz::Material::IsBlendingEnabled);
|
||||||
|
material.BindMethod("IsColorWriteEnabled", &Nz::Material::IsColorWriteEnabled);
|
||||||
|
material.BindMethod("IsDepthBufferEnabled", &Nz::Material::IsDepthBufferEnabled);
|
||||||
|
material.BindMethod("IsDepthSortingEnabled", &Nz::Material::IsDepthSortingEnabled);
|
||||||
|
material.BindMethod("IsDepthWriteEnabled", &Nz::Material::IsDepthWriteEnabled);
|
||||||
|
material.BindMethod("IsFaceCullingEnabled", &Nz::Material::IsFaceCullingEnabled);
|
||||||
|
material.BindMethod("IsScissorTestEnabled", &Nz::Material::IsScissorTestEnabled);
|
||||||
|
material.BindMethod("IsStencilTestEnabled", &Nz::Material::IsStencilTestEnabled);
|
||||||
|
material.BindMethod("IsShadowCastingEnabled", &Nz::Material::IsShadowCastingEnabled);
|
||||||
|
material.BindMethod("IsShadowReceiveEnabled", &Nz::Material::IsShadowReceiveEnabled);
|
||||||
|
|
||||||
|
material.BindMethod("LoadFromFile", &Nz::Material::LoadFromFile, Nz::MaterialParams());
|
||||||
|
|
||||||
|
material.BindMethod("Reset", &Nz::Material::Reset);
|
||||||
|
|
||||||
|
material.BindMethod("SetAlphaThreshold", &Nz::Material::SetAlphaThreshold);
|
||||||
|
material.BindMethod("SetAmbientColor", &Nz::Material::SetAmbientColor);
|
||||||
|
material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc);
|
||||||
|
material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc);
|
||||||
|
material.BindMethod("SetDepthMaterial", &Nz::Material::SetDepthMaterial);
|
||||||
|
material.BindMethod("SetDiffuseColor", &Nz::Material::SetDiffuseColor);
|
||||||
|
//material.BindMethod("SetDiffuseSampler", &Nz::Material::SetDiffuseSampler);
|
||||||
|
material.BindMethod("SetDstBlend", &Nz::Material::SetDstBlend);
|
||||||
|
material.BindMethod("SetFaceCulling", &Nz::Material::SetFaceCulling);
|
||||||
|
material.BindMethod("SetFaceFilling", &Nz::Material::SetFaceFilling);
|
||||||
|
material.BindMethod("SetLineWidth", &Nz::Material::SetLineWidth);
|
||||||
|
material.BindMethod("SetPointSize", &Nz::Material::SetPointSize);
|
||||||
|
material.BindMethod("SetShininess", &Nz::Material::SetShininess);
|
||||||
|
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
||||||
|
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
||||||
|
//material.BindMethod("SetSpecularSampler", &Nz::Material::SetSpecularSampler);
|
||||||
|
material.BindMethod("SetSrcBlend", &Nz::Material::SetSrcBlend);
|
||||||
|
|
||||||
|
material.BindStaticMethod("GetDefault", &Nz::Material::GetDefault);
|
||||||
|
|
||||||
|
material.BindMethod("SetAlphaMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetAlphaMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetAlphaMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetDiffuseMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetDiffuseMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetEmissiveMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetEmissiveMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetHeightMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetHeightMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetNormalMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetNormalMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "UberShader"))
|
||||||
|
{
|
||||||
|
instance->SetShader(*static_cast<Nz::UberShaderRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetShader(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetSpecularMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetSpecularMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Model ***********************************/
|
||||||
|
model.Reset("Model");
|
||||||
|
{
|
||||||
|
model.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef*
|
||||||
|
{
|
||||||
|
return reinterpret_cast<Nz::InstancedRenderableRef*>(modelRef); //TODO: Make a ObjectRefCast
|
||||||
|
});
|
||||||
|
|
||||||
|
model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* instance, std::size_t /*argumentCount*/)
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Model::New());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
//model.BindMethod("GetMaterial", &Nz::Model::GetMaterial);
|
||||||
|
model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
|
||||||
|
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
|
||||||
|
model.BindMethod("GetSkin", &Nz::Model::GetSkin);
|
||||||
|
model.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
|
||||||
|
|
||||||
|
model.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
|
||||||
|
model.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
|
||||||
|
|
||||||
|
model.BindMethod("Reset", &Nz::Model::Reset);
|
||||||
|
|
||||||
|
//model.BindMethod("SetMaterial", &Nz::Model::SetMaterial);
|
||||||
|
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
|
||||||
|
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
||||||
|
model.BindMethod("SetSkin", &Nz::Model::SetSkin);
|
||||||
|
model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Sprite ***********************************/
|
||||||
|
sprite.Reset("Sprite");
|
||||||
|
{
|
||||||
|
sprite.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef*
|
||||||
|
{
|
||||||
|
return reinterpret_cast<Nz::InstancedRenderableRef*>(spriteRef); //TODO: Make a ObjectRefCast
|
||||||
|
});
|
||||||
|
|
||||||
|
sprite.SetConstructor([] (Nz::LuaInstance& /*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("GetMaterial", &Nz::Sprite::GetMaterial);
|
||||||
|
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::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||||
|
|
||||||
|
if (lua.IsOfType(argIndex, "Material"))
|
||||||
|
instance->SetMaterial(*static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||||
|
else
|
||||||
|
instance->SetMaterial(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
sprite.BindMethod("SetTexture", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||||
|
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
instance->SetTexture(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||||
|
else
|
||||||
|
instance->SetTexture(lua.Check<Nz::String>(&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::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
abstractViewer.Register(instance);
|
||||||
|
instancedRenderable.Register(instance);
|
||||||
|
material.Register(instance);
|
||||||
|
model.Register(instance);
|
||||||
|
sprite.Register(instance);
|
||||||
|
spriteLibrary.Register(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,986 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Math.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindMath(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Math>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Math::LuaBinding_Math(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
/*********************************** Nz::EulerAngles **********************************/
|
||||||
|
eulerAngles.Reset("EulerAngles");
|
||||||
|
{
|
||||||
|
eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||||
|
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
Nz::PlacementNew(instance, *static_cast<Nz::EulerAnglesd*>(lua.CheckUserdata(1, "EulerAngles")));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for EulerAngles constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
eulerAngles.BindMethod("Normalize", &Nz::EulerAnglesd::Normalize);
|
||||||
|
eulerAngles.BindMethod("ToQuaternion", &Nz::EulerAnglesd::ToQuaternion);
|
||||||
|
|
||||||
|
eulerAngles.BindMethod("__tostring", &Nz::EulerAnglesd::ToString);
|
||||||
|
|
||||||
|
eulerAngles.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* ypr = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
switch (length)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
switch (ypr[0])
|
||||||
|
{
|
||||||
|
case 'p':
|
||||||
|
lua.Push(instance.pitch);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.yaw);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
lua.Push(instance.roll);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lua.Push(instance.yaw);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lua.Push(instance.roll);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lua.Push(instance.pitch);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
eulerAngles.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* ypr = lua.CheckString(2, &length);
|
||||||
|
double value = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
switch (length)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
switch (ypr[0])
|
||||||
|
{
|
||||||
|
case 'p':
|
||||||
|
instance.pitch = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.yaw = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
instance.roll = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
instance.yaw = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
instance.roll = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
instance.pitch = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Matrix4 **********************************/
|
||||||
|
matrix4d.Reset("Matrix4");
|
||||||
|
{
|
||||||
|
matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(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<Nz::Matrix4d*>(lua.ToUserdata(1)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
{
|
||||||
|
double values[16];
|
||||||
|
for (int i = 0; i < 16; ++i)
|
||||||
|
values[i] = lua.CheckNumber(i);
|
||||||
|
|
||||||
|
Nz::PlacementNew(matrix, values);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("ApplyRotation", &Nz::Matrix4d::ApplyRotation);
|
||||||
|
matrix4d.BindMethod("ApplyScale", &Nz::Matrix4d::ApplyScale);
|
||||||
|
matrix4d.BindMethod("ApplyTranslation", &Nz::Matrix4d::ApplyTranslation);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Concatenate", &Nz::Matrix4d::Concatenate);
|
||||||
|
matrix4d.BindMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine);
|
||||||
|
|
||||||
|
//matrix4d.BindMethod("GetColumn", &Nz::Matrix4d::GetColumn);
|
||||||
|
matrix4d.BindMethod("GetDeterminant", &Nz::Matrix4d::GetDeterminant);
|
||||||
|
matrix4d.BindMethod("GetDeterminantAffine", &Nz::Matrix4d::GetDeterminantAffine);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("GetInverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::Matrix4d result;
|
||||||
|
if (instance.GetInverse(&result))
|
||||||
|
return lua.Push(true, result);
|
||||||
|
else
|
||||||
|
return lua.Push(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("GetInverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::Matrix4d result;
|
||||||
|
if (instance.GetInverseAffine(&result))
|
||||||
|
return lua.Push(true, result);
|
||||||
|
else
|
||||||
|
return lua.Push(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("GetRotation", &Nz::Matrix4d::GetRotation);
|
||||||
|
|
||||||
|
//matrix4d.BindMethod("GetRow", &Nz::Matrix4d::GetRow);
|
||||||
|
matrix4d.BindMethod("GetScale", &Nz::Matrix4d::GetScale);
|
||||||
|
matrix4d.BindMethod("GetSquaredScale", &Nz::Matrix4d::GetSquaredScale);
|
||||||
|
matrix4d.BindMethod("GetTranslation", &Nz::Matrix4d::GetTranslation);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("GetTransposed", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::Matrix4d result;
|
||||||
|
instance.GetTransposed(&result);
|
||||||
|
|
||||||
|
return lua.Push(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("HasNegativeScale", &Nz::Matrix4d::HasNegativeScale);
|
||||||
|
matrix4d.BindMethod("HasScale", &Nz::Matrix4d::HasScale);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Inverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
bool succeeded;
|
||||||
|
instance.Inverse(&succeeded);
|
||||||
|
|
||||||
|
return lua.Push(succeeded);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("InverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
bool succeeded;
|
||||||
|
instance.InverseAffine(&succeeded);
|
||||||
|
|
||||||
|
return lua.Push(succeeded);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("IsAffine", &Nz::Matrix4d::IsAffine);
|
||||||
|
matrix4d.BindMethod("IsIdentity", &Nz::Matrix4d::IsIdentity);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("MakeIdentity", &Nz::Matrix4d::MakeIdentity);
|
||||||
|
matrix4d.BindMethod("MakeLookAt", &Nz::Matrix4d::MakeLookAt, Nz::Vector3d::Up());
|
||||||
|
matrix4d.BindMethod("MakeOrtho", &Nz::Matrix4d::MakeOrtho, -1.0, 1.0);
|
||||||
|
matrix4d.BindMethod("MakePerspective", &Nz::Matrix4d::MakePerspective);
|
||||||
|
matrix4d.BindMethod("MakeRotation", &Nz::Matrix4d::MakeRotation);
|
||||||
|
matrix4d.BindMethod("MakeScale", &Nz::Matrix4d::MakeScale);
|
||||||
|
matrix4d.BindMethod("MakeTranslation", &Nz::Matrix4d::MakeTranslation);
|
||||||
|
matrix4d.BindMethod("MakeTransform", (Nz::Matrix4d&(Nz::Matrix4d::*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::MakeTransform, Nz::Vector3d::Unit());
|
||||||
|
matrix4d.BindMethod("MakeViewMatrix", &Nz::Matrix4d::MakeViewMatrix);
|
||||||
|
matrix4d.BindMethod("MakeZero", &Nz::Matrix4d::MakeZero);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Set", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
if (lua.IsOfType(argIndex, "Matrix4"))
|
||||||
|
instance.Set(*static_cast<Nz::Matrix4d*>(lua.ToUserdata(argIndex)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
{
|
||||||
|
double values[16];
|
||||||
|
for (std::size_t i = 0; i < 16; ++i)
|
||||||
|
values[i] = lua.CheckNumber(argIndex++);
|
||||||
|
|
||||||
|
instance.Set(values);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method Set");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("SetRotation", &Nz::Matrix4d::SetRotation);
|
||||||
|
matrix4d.BindMethod("SetScale", &Nz::Matrix4d::SetScale);
|
||||||
|
matrix4d.BindMethod("SetTranslation", &Nz::Matrix4d::SetTranslation);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Transform", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Vector2"))
|
||||||
|
{
|
||||||
|
double z(lua.CheckNumber(argIndex + 1, 0.0));
|
||||||
|
double w(lua.CheckNumber(argIndex + 2, 1.0));
|
||||||
|
|
||||||
|
return lua.Push(instance.Transform(*static_cast<Nz::Vector2d*>(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<Nz::Vector3d*>(lua.ToUserdata(argIndex)), w));
|
||||||
|
}
|
||||||
|
//else if (lua.IsOfType(2, "Vector4"))
|
||||||
|
// return lua.Push(instance.Transform(*static_cast<Nz::Vector4d*>(lua.ToUserdata(1))));
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method Transform");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Transpose", &Nz::Matrix4d::Transpose);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("__tostring", &Nz::Matrix4d::ToString);
|
||||||
|
|
||||||
|
matrix4d.BindStaticMethod("Concatenate", &Nz::Matrix4d::Concatenate);
|
||||||
|
matrix4d.BindStaticMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine);
|
||||||
|
matrix4d.BindStaticMethod("Identity", &Nz::Matrix4d::Identity);
|
||||||
|
matrix4d.BindStaticMethod("LookAt", &Nz::Matrix4d::LookAt, Nz::Vector3d::Up());
|
||||||
|
matrix4d.BindStaticMethod("Ortho", &Nz::Matrix4d::Ortho, -1.0, 1.0);
|
||||||
|
matrix4d.BindStaticMethod("Perspective", &Nz::Matrix4d::Perspective);
|
||||||
|
matrix4d.BindStaticMethod("Rotate", &Nz::Matrix4d::Rotate);
|
||||||
|
matrix4d.BindStaticMethod("Scale", &Nz::Matrix4d::Scale);
|
||||||
|
matrix4d.BindStaticMethod("Translate", &Nz::Matrix4d::Translate);
|
||||||
|
matrix4d.BindStaticMethod("Transform", (Nz::Matrix4d(*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::Transform, Nz::Vector3d::Unit());
|
||||||
|
matrix4d.BindStaticMethod("ViewMatrix", &Nz::Matrix4d::ViewMatrix);
|
||||||
|
matrix4d.BindStaticMethod("Zero", &Nz::Matrix4d::Zero);
|
||||||
|
|
||||||
|
matrix4d.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance)
|
||||||
|
{
|
||||||
|
bool succeeded = false;
|
||||||
|
std::size_t index = static_cast<std::size_t>(lua.ToInteger(2, &succeeded));
|
||||||
|
if (!succeeded || index < 1 || index > 16)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance)
|
||||||
|
{
|
||||||
|
bool succeeded = false;
|
||||||
|
std::size_t index = static_cast<std::size_t>(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::LuaInstance& lua, Nz::Rectd* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(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<Nz::Rectd*>(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<double>("x", 1),
|
||||||
|
lua.CheckField<double>("y", 1),
|
||||||
|
lua.CheckField<double>("width", 1),
|
||||||
|
lua.CheckField<double>("height", 1));
|
||||||
|
}
|
||||||
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
|
PlacementNew(instance, *static_cast<Nz::Vector2d*>(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<Nz::Vector2d*>(lua.ToUserdata(1)), *static_cast<Nz::Vector2d*>(lua.ToUserdata(2)));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for Rect constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
rect.BindMethod("__tostring", &Nz::Rectd::ToString);
|
||||||
|
|
||||||
|
rect.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
auto index = lua.CheckBoundInteger<std::size_t>(2);
|
||||||
|
if (index < 1 || index > 4)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xywh = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (xywh[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
lua.Push(instance.x);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'w':
|
||||||
|
lua.Push(instance.width);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'h':
|
||||||
|
lua.Push(instance.height);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
rect.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
auto index = lua.CheckBoundInteger<std::size_t>(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::LuaInstance& lua, Nz::Quaterniond* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(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<Nz::EulerAnglesd*>(lua.ToUserdata(1)));
|
||||||
|
else if (lua.IsOfType(1, "Quaternion"))
|
||||||
|
Nz::PlacementNew(instance, *static_cast<Nz::Quaterniond*>(lua.ToUserdata(1)));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast<Nz::Vector3d*>(lua.CheckUserdata(2, "Vector3")));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for Quaternion constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.BindMethod("ComputeW", &Nz::Quaterniond::ComputeW);
|
||||||
|
quaternion.BindMethod("Conjugate", &Nz::Quaterniond::Conjugate);
|
||||||
|
quaternion.BindMethod("DotProduct", &Nz::Quaterniond::DotProduct);
|
||||||
|
quaternion.BindMethod("GetConjugate", &Nz::Quaterniond::GetConjugate);
|
||||||
|
quaternion.BindMethod("GetInverse", &Nz::Quaterniond::GetInverse);
|
||||||
|
|
||||||
|
quaternion.BindMethod("Inverse", &Nz::Quaterniond::Inverse);
|
||||||
|
quaternion.BindMethod("Magnitude", &Nz::Quaterniond::Magnitude);
|
||||||
|
|
||||||
|
quaternion.BindMethod("SquaredMagnitude", &Nz::Quaterniond::SquaredMagnitude);
|
||||||
|
quaternion.BindMethod("ToEulerAngles", &Nz::Quaterniond::ToEulerAngles);
|
||||||
|
|
||||||
|
quaternion.BindMethod("__tostring", &Nz::Quaterniond::ToString);
|
||||||
|
|
||||||
|
quaternion.BindStaticMethod("Lerp", &Nz::Quaterniond::Lerp);
|
||||||
|
quaternion.BindStaticMethod("RotationBetween", &Nz::Quaterniond::RotationBetween);
|
||||||
|
quaternion.BindStaticMethod("Slerp", &Nz::Quaterniond::Slerp);
|
||||||
|
|
||||||
|
quaternion.BindMethod("GetNormal", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
double length;
|
||||||
|
|
||||||
|
lua.Push(instance.GetNormal(&length));
|
||||||
|
lua.Push(length);
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.BindMethod("Normalize", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
double length;
|
||||||
|
|
||||||
|
instance.Normalize(&length);
|
||||||
|
lua.Push(1); //< instance
|
||||||
|
lua.Push(length);
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.BindStaticMethod("Normalize", [] (Nz::LuaInstance& instance) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 1;
|
||||||
|
Nz::Quaterniond quat = instance.Check<Nz::Quaterniond>(&argIndex);
|
||||||
|
|
||||||
|
double length;
|
||||||
|
|
||||||
|
instance.Push(Nz::Quaterniond::Normalize(quat, &length));
|
||||||
|
instance.Push(length);
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* wxyz = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
switch (wxyz[0])
|
||||||
|
{
|
||||||
|
case 'w':
|
||||||
|
lua.Push(instance.w);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'x':
|
||||||
|
lua.Push(instance.x);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
lua.Push(instance.z);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* wxyz = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
double value = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
switch (wxyz[0])
|
||||||
|
{
|
||||||
|
case 'w':
|
||||||
|
instance.w = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'x':
|
||||||
|
instance.x = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.y = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
instance.z = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Vector2 **********************************/
|
||||||
|
vector2d.Reset("Vector2");
|
||||||
|
{
|
||||||
|
vector2d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(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<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for Vector2 constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
vector2d.BindMethod("__tostring", &Nz::Vector2d::ToString);
|
||||||
|
|
||||||
|
vector2d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
long long index = lua.CheckInteger(2);
|
||||||
|
if (index < 1 || index > 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xy = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (xy[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
lua.Push(instance.x);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
vector2d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
long long index = lua.CheckInteger(2);
|
||||||
|
if (index < 1 || index > 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
instance[index - 1] = lua.CheckNumber(3);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xy = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
double value = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
switch (xy[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
instance.x = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.y = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Vector3 **********************************/
|
||||||
|
vector3d.Reset("Vector3");
|
||||||
|
{
|
||||||
|
vector3d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(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<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||||
|
else if (lua.IsOfType(1, "Vector3"))
|
||||||
|
Nz::PlacementNew(vector, *static_cast<Nz::Vector3d*>(lua.ToUserdata(1)));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||||
|
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(2, "Vector2")));
|
||||||
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
|
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)), lua.CheckNumber(2));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
vector3d.BindMethod("__tostring", &Nz::Vector3d::ToString);
|
||||||
|
|
||||||
|
vector3d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
long long index = lua.CheckInteger(2);
|
||||||
|
if (index < 1 || index > 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xyz = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (xyz[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
lua.Push(instance.x);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
lua.Push(instance.z);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
vector3d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
long long index = lua.CheckInteger(2);
|
||||||
|
if (index < 1 || index > 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
instance[index - 1] = lua.CheckNumber(3);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xyz = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
double value = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
switch (xyz[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
instance.x = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.y = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
instance.z = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the Math classes
|
||||||
|
*/
|
||||||
|
void LuaBinding_Math::Register(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
eulerAngles.Register(instance);
|
||||||
|
matrix4d.Register(instance);
|
||||||
|
quaternion.Register(instance);
|
||||||
|
rect.Register(instance);
|
||||||
|
vector2d.Register(instance);
|
||||||
|
vector3d.Register(instance);
|
||||||
|
|
||||||
|
quaternion.PushGlobalTable(instance);
|
||||||
|
{
|
||||||
|
instance.PushField("Identity", Nz::Quaterniond::Identity());
|
||||||
|
instance.PushField("Zero", Nz::Quaterniond::Zero());
|
||||||
|
}
|
||||||
|
instance.Pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,139 +1,147 @@
|
||||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
#include <NDK/Lua/LuaBinding_Network.hpp>
|
||||||
#include <NDK/LuaAPI.hpp>
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
/*!
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindNetwork(LuaBinding& binding)
|
||||||
* \brief Binds Network module to Lua
|
{
|
||||||
*/
|
return std::make_unique<LuaBinding_Network>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
void LuaBinding::BindNetwork()
|
LuaBinding_Network::LuaBinding_Network(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
{
|
{
|
||||||
/*********************************** Nz::AbstractSocket **********************************/
|
/*********************************** Nz::AbstractSocket **********************************/
|
||||||
abstractSocket.BindMethod("Close", &Nz::AbstractSocket::Close);
|
abstractSocket.Reset("AbstractSocket");
|
||||||
abstractSocket.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
|
{
|
||||||
abstractSocket.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
|
abstractSocket.BindMethod("Close", &Nz::AbstractSocket::Close);
|
||||||
abstractSocket.BindMethod("GetState", &Nz::AbstractSocket::GetState);
|
abstractSocket.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
|
||||||
abstractSocket.BindMethod("GetType", &Nz::AbstractSocket::GetType);
|
abstractSocket.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
|
||||||
abstractSocket.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
|
abstractSocket.BindMethod("GetState", &Nz::AbstractSocket::GetState);
|
||||||
abstractSocket.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
|
abstractSocket.BindMethod("GetType", &Nz::AbstractSocket::GetType);
|
||||||
|
abstractSocket.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
|
||||||
|
abstractSocket.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************** Nz::IpAddress **********************************/
|
/*********************************** Nz::IpAddress **********************************/
|
||||||
ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* instance, std::size_t argumentCount)
|
ipAddress.Reset("IpAddress");
|
||||||
{
|
{
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 9U);
|
ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* instance, std::size_t argumentCount)
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
{
|
||||||
case 0:
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 9U);
|
||||||
Nz::PlacementNew(instance);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
int argIndex = 2;
|
||||||
Nz::PlacementNew(instance, lua.CheckString(argIndex));
|
switch (argCount)
|
||||||
return true;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
{
|
{
|
||||||
Nz::UInt8 a = lua.Check<Nz::UInt8>(&argIndex);
|
case 0:
|
||||||
Nz::UInt8 b = lua.Check<Nz::UInt8>(&argIndex);
|
Nz::PlacementNew(instance);
|
||||||
Nz::UInt8 c = lua.Check<Nz::UInt8>(&argIndex);
|
return true;
|
||||||
Nz::UInt8 d = lua.Check<Nz::UInt8>(&argIndex);
|
|
||||||
Nz::UInt16 port = lua.Check<Nz::UInt16>(&argIndex, 0);
|
|
||||||
|
|
||||||
Nz::PlacementNew(instance, a, b, c, d, port);
|
case 1:
|
||||||
return true;
|
Nz::PlacementNew(instance, lua.CheckString(argIndex));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
Nz::UInt8 a = lua.Check<Nz::UInt8>(&argIndex);
|
||||||
|
Nz::UInt8 b = lua.Check<Nz::UInt8>(&argIndex);
|
||||||
|
Nz::UInt8 c = lua.Check<Nz::UInt8>(&argIndex);
|
||||||
|
Nz::UInt8 d = lua.Check<Nz::UInt8>(&argIndex);
|
||||||
|
Nz::UInt16 port = lua.Check<Nz::UInt16>(&argIndex, 0);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, a, b, c, d, port);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
case 9:
|
||||||
|
{
|
||||||
|
Nz::UInt16 a = lua.Check<Nz::UInt16>(&argIndex);
|
||||||
|
Nz::UInt16 b = lua.Check<Nz::UInt16>(&argIndex);
|
||||||
|
Nz::UInt16 c = lua.Check<Nz::UInt16>(&argIndex);
|
||||||
|
Nz::UInt16 d = lua.Check<Nz::UInt16>(&argIndex);
|
||||||
|
Nz::UInt16 e = lua.Check<Nz::UInt16>(&argIndex);
|
||||||
|
Nz::UInt16 f = lua.Check<Nz::UInt16>(&argIndex);
|
||||||
|
Nz::UInt16 g = lua.Check<Nz::UInt16>(&argIndex);
|
||||||
|
Nz::UInt16 h = lua.Check<Nz::UInt16>(&argIndex);
|
||||||
|
Nz::UInt16 port = lua.Check<Nz::UInt16>(&argIndex, 0);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, a, b, c, d, e, f, g, h, port);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case 8:
|
lua.Error("No matching overload for constructor");
|
||||||
case 9:
|
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::LuaInstance& instance) -> int
|
||||||
|
{
|
||||||
|
Nz::String service;
|
||||||
|
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
Nz::String hostName = Nz::IpAddress::ResolveAddress(instance.Check<Nz::IpAddress>(&argIndex), &service, &error);
|
||||||
|
|
||||||
|
if (error == Nz::ResolveError_NoError)
|
||||||
{
|
{
|
||||||
Nz::UInt16 a = lua.Check<Nz::UInt16>(&argIndex);
|
instance.Push(hostName);
|
||||||
Nz::UInt16 b = lua.Check<Nz::UInt16>(&argIndex);
|
instance.Push(service);
|
||||||
Nz::UInt16 c = lua.Check<Nz::UInt16>(&argIndex);
|
return 2;
|
||||||
Nz::UInt16 d = lua.Check<Nz::UInt16>(&argIndex);
|
|
||||||
Nz::UInt16 e = lua.Check<Nz::UInt16>(&argIndex);
|
|
||||||
Nz::UInt16 f = lua.Check<Nz::UInt16>(&argIndex);
|
|
||||||
Nz::UInt16 g = lua.Check<Nz::UInt16>(&argIndex);
|
|
||||||
Nz::UInt16 h = lua.Check<Nz::UInt16>(&argIndex);
|
|
||||||
Nz::UInt16 port = lua.Check<Nz::UInt16>(&argIndex, 0);
|
|
||||||
|
|
||||||
Nz::PlacementNew(instance, a, b, c, d, e, f, g, h, port);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
|
||||||
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::LuaInstance& instance) -> int
|
|
||||||
{
|
|
||||||
Nz::String service;
|
|
||||||
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
Nz::String hostName = Nz::IpAddress::ResolveAddress(instance.Check<Nz::IpAddress>(&argIndex), &service, &error);
|
|
||||||
|
|
||||||
if (error == Nz::ResolveError_NoError)
|
|
||||||
{
|
|
||||||
instance.Push(hostName);
|
|
||||||
instance.Push(service);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
instance.PushBoolean(false);
|
|
||||||
instance.Push(error);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ipAddress.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int
|
|
||||||
{
|
|
||||||
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
Nz::NetProtocol protocol = instance.Check<Nz::NetProtocol>(&argIndex);
|
|
||||||
Nz::String hostname = instance.Check<Nz::String>(&argIndex);
|
|
||||||
Nz::String service = instance.Check<Nz::String>(&argIndex, "http");
|
|
||||||
|
|
||||||
std::vector<Nz::HostnameInfo> addresses = Nz::IpAddress::ResolveHostname(protocol, hostname, service, &error);
|
|
||||||
if (error == Nz::ResolveError_NoError)
|
|
||||||
{
|
|
||||||
int index = 1;
|
|
||||||
instance.PushTable(addresses.size());
|
|
||||||
for (Nz::HostnameInfo& info : addresses)
|
|
||||||
{
|
{
|
||||||
instance.PushInteger(index++);
|
instance.PushBoolean(false);
|
||||||
instance.PushTable(0, 4);
|
instance.Push(error);
|
||||||
instance.PushField("Address", std::move(info.address));
|
return 2;
|
||||||
instance.PushField("CanonicalName", std::move(info.canonicalName));
|
|
||||||
instance.PushField("Protocol", std::move(info.protocol));
|
|
||||||
instance.PushField("SocketType", std::move(info.socketType));
|
|
||||||
instance.SetTable();
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return 1;
|
ipAddress.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
instance.PushBoolean(false);
|
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
||||||
instance.Push(error);
|
|
||||||
return 2;
|
int argIndex = 2;
|
||||||
}
|
Nz::NetProtocol protocol = instance.Check<Nz::NetProtocol>(&argIndex);
|
||||||
});
|
Nz::String hostname = instance.Check<Nz::String>(&argIndex);
|
||||||
|
Nz::String service = instance.Check<Nz::String>(&argIndex, "http");
|
||||||
|
|
||||||
|
std::vector<Nz::HostnameInfo> addresses = Nz::IpAddress::ResolveHostname(protocol, hostname, service, &error);
|
||||||
|
if (error == Nz::ResolveError_NoError)
|
||||||
|
{
|
||||||
|
int index = 1;
|
||||||
|
instance.PushTable(addresses.size());
|
||||||
|
for (Nz::HostnameInfo& info : addresses)
|
||||||
|
{
|
||||||
|
instance.PushInteger(index++);
|
||||||
|
instance.PushTable(0, 4);
|
||||||
|
instance.PushField("Address", std::move(info.address));
|
||||||
|
instance.PushField("CanonicalName", std::move(info.canonicalName));
|
||||||
|
instance.PushField("Protocol", std::move(info.protocol));
|
||||||
|
instance.PushField("SocketType", std::move(info.socketType));
|
||||||
|
instance.SetTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
instance.PushBoolean(false);
|
||||||
|
instance.Push(error);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -141,8 +149,7 @@ namespace Ndk
|
||||||
*
|
*
|
||||||
* \param instance Lua instance that will interact with the Network classes
|
* \param instance Lua instance that will interact with the Network classes
|
||||||
*/
|
*/
|
||||||
|
void LuaBinding_Network::Register(Nz::LuaInstance& instance)
|
||||||
void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance)
|
|
||||||
{
|
{
|
||||||
// Classes
|
// Classes
|
||||||
abstractSocket.Register(instance);
|
abstractSocket.Register(instance);
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Renderer.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Utility.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindRenderer(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Renderer>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Renderer::LuaBinding_Renderer(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
LuaBinding_Utility& utility = static_cast<LuaBinding_Utility&>(*m_binding.utility);
|
||||||
|
|
||||||
|
/*********************************** Nz::Texture ***********************************/
|
||||||
|
texture.Reset("Texture");
|
||||||
|
{
|
||||||
|
texture.Inherit<Nz::AbstractImageRef>(utility.abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef*
|
||||||
|
{
|
||||||
|
return reinterpret_cast<Nz::AbstractImageRef*>(textureRef); //TODO: Make a ObjectRefCast
|
||||||
|
});
|
||||||
|
|
||||||
|
texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* instance, std::size_t /*argumentCount*/)
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Texture::New());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
texture.BindMethod("Create", &Nz::Texture::Create, static_cast<Nz::UInt8>(1), 1U);
|
||||||
|
texture.BindMethod("Destroy", &Nz::Texture::Destroy);
|
||||||
|
|
||||||
|
//texture.BindMethod("Download", &Nz::Texture::Download);
|
||||||
|
|
||||||
|
texture.BindMethod("EnableMipmapping", &Nz::Texture::EnableMipmapping);
|
||||||
|
texture.BindMethod("EnsureMipmapsUpdate", &Nz::Texture::EnsureMipmapsUpdate);
|
||||||
|
texture.BindMethod("HasMipmaps", &Nz::Texture::HasMipmaps);
|
||||||
|
texture.BindMethod("InvalidateMipmaps", &Nz::Texture::InvalidateMipmaps);
|
||||||
|
texture.BindMethod("IsValid", &Nz::Texture::IsValid);
|
||||||
|
|
||||||
|
texture.BindMethod("LoadFromFile", &Nz::Texture::LoadFromFile, true, Nz::ImageParams());
|
||||||
|
//bool LoadFromImage(const Image& image, bool generateMipmaps = true);
|
||||||
|
//bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||||
|
//bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||||
|
|
||||||
|
texture.BindMethod("LoadArrayFromFile", &Nz::Texture::LoadArrayFromFile, Nz::Vector2ui(2, 2), true, Nz::ImageParams());
|
||||||
|
//bool LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
//bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
//bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
|
||||||
|
//bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||||
|
//bool LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams());
|
||||||
|
//bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||||
|
//bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||||
|
|
||||||
|
texture.BindMethod("LoadFaceFromFile", &Nz::Texture::LoadFaceFromFile, Nz::ImageParams());
|
||||||
|
//bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||||
|
//bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams());
|
||||||
|
|
||||||
|
texture.BindMethod("SaveToFile", &Nz::Texture::SaveToFile, Nz::ImageParams());
|
||||||
|
//bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams());
|
||||||
|
|
||||||
|
texture.BindMethod("SetMipmapRange", &Nz::Texture::SetMipmapRange);
|
||||||
|
|
||||||
|
texture.BindStaticMethod("IsFormatSupported", &Nz::Texture::IsFormatSupported);
|
||||||
|
texture.BindStaticMethod("IsMipmappingSupported", &Nz::Texture::IsMipmappingSupported);
|
||||||
|
texture.BindStaticMethod("IsTypeSupported", &Nz::Texture::IsTypeSupported);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** 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::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
texture.Register(instance);
|
||||||
|
textureLibrary.Register(instance);
|
||||||
|
textureManager.Register(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,338 @@
|
||||||
|
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_SDK.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Utility.hpp>
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
#include <NDK/Lua/LuaBinding_Graphics.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindSDK(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_SDK>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_SDK::LuaBinding_SDK(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
LuaBinding_Graphics& graphics = static_cast<LuaBinding_Graphics&>(*m_binding.graphics);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LuaBinding_Utility& utility = static_cast<LuaBinding_Utility&>(*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::LuaInstance& lua, Application* instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
lua.Push(instance->AddWorld().CreateHandle());
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
application.BindMethod("GetUpdateTime", &Application::GetUpdateTime);
|
||||||
|
application.BindMethod("Quit", &Application::Quit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Ndk::Console **********************************/
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
console.Reset("Console");
|
||||||
|
{
|
||||||
|
console.Inherit<Nz::Node>(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("GetHistoryBackground", &Console::GetHistoryBackground);
|
||||||
|
console.BindMethod("GetInput", &Console::GetInput);
|
||||||
|
console.BindMethod("GetInputBackground", &Console::GetInputBackground);
|
||||||
|
console.BindMethod("GetSize", &Console::GetSize);
|
||||||
|
console.BindMethod("GetTextFont", &Console::GetTextFont);
|
||||||
|
|
||||||
|
console.BindMethod("IsVisible", &Console::IsVisible);
|
||||||
|
|
||||||
|
console.BindMethod("SendCharacter", &Console::SendCharacter);
|
||||||
|
//consoleClass.SetMethod("SendEvent", &Console::SendEvent);
|
||||||
|
|
||||||
|
console.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
|
||||||
|
console.BindMethod("SetSize", &Console::SetSize);
|
||||||
|
console.BindMethod("SetTextFont", &Console::SetTextFont);
|
||||||
|
|
||||||
|
console.BindMethod("Show", &Console::Show, true);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*********************************** Ndk::Entity **********************************/
|
||||||
|
entity.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("RemoveAllComponents", &Entity::RemoveAllComponents);
|
||||||
|
entity.BindMethod("__tostring", &EntityHandle::ToString);
|
||||||
|
|
||||||
|
entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
||||||
|
|
||||||
|
return binding->adder(instance, handle);
|
||||||
|
});
|
||||||
|
|
||||||
|
entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
||||||
|
|
||||||
|
return binding->getter(instance, handle->GetComponent(binding->index));
|
||||||
|
});
|
||||||
|
|
||||||
|
entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
||||||
|
|
||||||
|
handle->RemoveComponent(binding->index);
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Ndk::NodeComponent **********************************/
|
||||||
|
nodeComponent.Reset("NodeComponent");
|
||||||
|
{
|
||||||
|
nodeComponent.Inherit<Nz::Node>(utility.node, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||||
|
{
|
||||||
|
return handle->GetObject();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Ndk::VelocityComponent **********************************/
|
||||||
|
velocityComponent.Reset("VelocityComponent");
|
||||||
|
{
|
||||||
|
velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* member = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (std::strcmp(member, "Linear") == 0)
|
||||||
|
{
|
||||||
|
lua.Push(instance->linearVelocity);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* member = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
int argIndex = 3;
|
||||||
|
if (std::strcmp(member, "Linear") == 0)
|
||||||
|
{
|
||||||
|
instance->linearVelocity = lua.Check<Nz::Vector3f>(&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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
/*********************************** Ndk::CameraComponent **********************************/
|
||||||
|
cameraComponent.Reset("CameraComponent");
|
||||||
|
{
|
||||||
|
cameraComponent.Inherit<Nz::AbstractViewer>(graphics.abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer*
|
||||||
|
{
|
||||||
|
return handle->GetObject();
|
||||||
|
});
|
||||||
|
|
||||||
|
cameraComponent.BindMethod("GetFOV", &Ndk::CameraComponent::GetFOV);
|
||||||
|
cameraComponent.BindMethod("GetLayer", &Ndk::CameraComponent::GetLayer);
|
||||||
|
|
||||||
|
cameraComponent.BindMethod("SetFOV", &Ndk::CameraComponent::SetFOV);
|
||||||
|
cameraComponent.BindMethod("SetLayer", &Ndk::CameraComponent::SetLayer);
|
||||||
|
cameraComponent.BindMethod("SetProjectionType", &Ndk::CameraComponent::SetProjectionType);
|
||||||
|
cameraComponent.BindMethod("SetSize", (void(Ndk::CameraComponent::*)(const Nz::Vector2f&)) &Ndk::CameraComponent::SetSize);
|
||||||
|
//cameraComponent.BindMethod("SetTarget", &Ndk::CameraComponent::SetTarget);
|
||||||
|
cameraComponent.BindMethod("SetTargetRegion", &Ndk::CameraComponent::SetTargetRegion);
|
||||||
|
cameraComponent.BindMethod("SetViewport", &Ndk::CameraComponent::SetViewport);
|
||||||
|
cameraComponent.BindMethod("SetZFar", &Ndk::CameraComponent::SetZFar);
|
||||||
|
cameraComponent.BindMethod("SetZNear", &Ndk::CameraComponent::SetZNear);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Ndk::GraphicsComponent **********************************/
|
||||||
|
graphicsComponent.Reset("GraphicsComponent");
|
||||||
|
{
|
||||||
|
graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||||
|
void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||||
|
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
instance->Attach(lua.Check<Nz::InstancedRenderableRef>(&argIndex));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
||||||
|
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
{
|
||||||
|
int renderOrder = lua.Check<int>(&argIndex);
|
||||||
|
|
||||||
|
instance->Attach(renderable, renderOrder);
|
||||||
|
}
|
||||||
|
else if (lua.IsOfType(argIndex, "Matrix4"))
|
||||||
|
{
|
||||||
|
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
||||||
|
|
||||||
|
instance->Attach(renderable, localMatrix);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
||||||
|
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
||||||
|
int renderOrder = lua.Check<int>(&argIndex);
|
||||||
|
|
||||||
|
instance->Attach(renderable, localMatrix, renderOrder);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method GetMemoryUsage");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Components functions
|
||||||
|
m_binding.BindComponent<NodeComponent>("Node");
|
||||||
|
m_binding.BindComponent<VelocityComponent>("Velocity");
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
m_binding.BindComponent<CameraComponent>("Camera");
|
||||||
|
m_binding.BindComponent<GraphicsComponent>("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::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
// Classes
|
||||||
|
application.Register(instance);
|
||||||
|
entity.Register(instance);
|
||||||
|
nodeComponent.Register(instance);
|
||||||
|
velocityComponent.Register(instance);
|
||||||
|
world.Register(instance);
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
cameraComponent.Register(instance);
|
||||||
|
console.Register(instance);
|
||||||
|
graphicsComponent.Register(instance);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the index of the component
|
||||||
|
* \return A pointer to the binding linked to a component
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the component
|
||||||
|
* \param argIndex Index of the component
|
||||||
|
*/
|
||||||
|
LuaBinding::ComponentBinding* LuaBinding::QueryComponentIndex(Nz::LuaInstance& instance, int argIndex)
|
||||||
|
{
|
||||||
|
switch (instance.GetType(argIndex))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
ComponentIndex componentIndex = instance.Check<ComponentIndex>(&argIndex);
|
||||||
|
if (componentIndex > m_componentBinding.size())
|
||||||
|
{
|
||||||
|
instance.Error("Invalid component index");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||||
|
if (binding.name.IsEmpty())
|
||||||
|
{
|
||||||
|
instance.Error("Invalid component index");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &binding;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
const char* key = instance.CheckString(argIndex);
|
||||||
|
auto it = m_componentBindingByName.find(key);
|
||||||
|
if (it == m_componentBindingByName.end())
|
||||||
|
{
|
||||||
|
instance.Error("Invalid component name");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &m_componentBinding[it->second];
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.Error("Invalid component index at #" + Nz::String::Number(argIndex));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,446 @@
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Utility.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindUtility(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Utility>(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<Nz::UInt8>(0));
|
||||||
|
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||||
|
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||||
|
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||||
|
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||||
|
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||||
|
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
|
||||||
|
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||||
|
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||||
|
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||||
|
|
||||||
|
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return lua.Push(instance->GetMemoryUsage());
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
Nz::UInt8 level(lua.Check<Nz::UInt8>(&argIndex));
|
||||||
|
|
||||||
|
return lua.Push(instance->GetMemoryUsage(level));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method GetMemoryUsage");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 6U);
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
std::size_t bufferSize = 0;
|
||||||
|
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(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<unsigned int>(&argIndex, 0);
|
||||||
|
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
Nz::UInt8 level = lua.Check<Nz::UInt8>(&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<Nz::Boxui>(&argIndex);
|
||||||
|
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
Nz::UInt8 level = lua.Check<Nz::UInt8>(&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<Nz::Rectui>(&argIndex);
|
||||||
|
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
Nz::UInt8 level = lua.Check<Nz::UInt8>(&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::LuaInstance& /*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::LuaInstance& lua, Nz::FontRef& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
lua.Push(instance->GetCachedGlyphCount());
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
unsigned int characterSize = lua.Check<unsigned int>(&argIndex);
|
||||||
|
Nz::UInt32 style = lua.Check<Nz::UInt32>(&argIndex);
|
||||||
|
|
||||||
|
lua.Push(instance->GetCachedGlyphCount(characterSize, style));
|
||||||
|
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::UInt32, const Nz::String&) const) &Nz::Font::Precache);
|
||||||
|
|
||||||
|
font.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams());
|
||||||
|
|
||||||
|
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("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder);
|
||||||
|
font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Keyboard **********************************/
|
||||||
|
keyboard.Reset("Keyboard");
|
||||||
|
{
|
||||||
|
keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName);
|
||||||
|
keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** 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::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
instance.Move(offset, coordSys);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
instance.Rotate(rotation, coordSys);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
instance.Scale(lua.Check<float>(&argIndex));
|
||||||
|
else
|
||||||
|
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method Scale");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
{
|
||||||
|
float scale = lua.Check<float>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
instance.SetScale(scale, coordSys);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
instance.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
|
||||||
|
instance.SetScale(scale, coordSys);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method SetScale");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
instance.SetInitialScale(lua.Check<float>(&argIndex));
|
||||||
|
else
|
||||||
|
instance.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
instance.SetInitialScale(lua.Check<Nz::Vector3f>(&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::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
abstractImage.Register(instance);
|
||||||
|
font.Register(instance);
|
||||||
|
keyboard.Register(instance);
|
||||||
|
node.Register(instance);
|
||||||
|
|
||||||
|
keyboard.PushGlobalTable(instance);
|
||||||
|
{
|
||||||
|
static_assert(Nz::Keyboard::Count == 121, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding");
|
||||||
|
|
||||||
|
instance.PushField("Undefined", Nz::Keyboard::Undefined);
|
||||||
|
|
||||||
|
// A-Z
|
||||||
|
for (std::size_t i = 0; i < 26; ++i)
|
||||||
|
instance.PushField(Nz::String('A' + char(i)), Nz::Keyboard::A + i);
|
||||||
|
|
||||||
|
// Numerical
|
||||||
|
for (std::size_t i = 0; i < 10; ++i)
|
||||||
|
{
|
||||||
|
instance.PushField("Num" + Nz::String::Number(i), Nz::Keyboard::Num0 + i);
|
||||||
|
instance.PushField("Numpad" + Nz::String::Number(i), Nz::Keyboard::Numpad0 + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// F1-F15
|
||||||
|
for (std::size_t i = 0; i < 15; ++i)
|
||||||
|
instance.PushField('F' + Nz::String::Number(i+1), Nz::Keyboard::F1 + i);
|
||||||
|
|
||||||
|
// And all the others...
|
||||||
|
instance.PushField("Down", Nz::Keyboard::Down);
|
||||||
|
instance.PushField("Left", Nz::Keyboard::Left);
|
||||||
|
instance.PushField("Right", Nz::Keyboard::Right);
|
||||||
|
instance.PushField("Up", Nz::Keyboard::Up);
|
||||||
|
|
||||||
|
instance.PushField("Add", Nz::Keyboard::Add);
|
||||||
|
instance.PushField("Decimal", Nz::Keyboard::Decimal);
|
||||||
|
instance.PushField("Divide", Nz::Keyboard::Divide);
|
||||||
|
instance.PushField("Multiply", Nz::Keyboard::Multiply);
|
||||||
|
instance.PushField("Subtract", Nz::Keyboard::Subtract);
|
||||||
|
|
||||||
|
instance.PushField("Backslash", Nz::Keyboard::Backslash);
|
||||||
|
instance.PushField("Backspace", Nz::Keyboard::Backspace);
|
||||||
|
instance.PushField("Clear", Nz::Keyboard::Clear);
|
||||||
|
instance.PushField("Comma", Nz::Keyboard::Comma);
|
||||||
|
instance.PushField("Dash", Nz::Keyboard::Dash);
|
||||||
|
instance.PushField("Delete", Nz::Keyboard::Delete);
|
||||||
|
instance.PushField("End", Nz::Keyboard::End);
|
||||||
|
instance.PushField("Equal", Nz::Keyboard::Equal);
|
||||||
|
instance.PushField("Escape", Nz::Keyboard::Escape);
|
||||||
|
instance.PushField("Home", Nz::Keyboard::Home);
|
||||||
|
instance.PushField("Insert", Nz::Keyboard::Insert);
|
||||||
|
instance.PushField("LAlt", Nz::Keyboard::LAlt);
|
||||||
|
instance.PushField("LBracket", Nz::Keyboard::LBracket);
|
||||||
|
instance.PushField("LControl", Nz::Keyboard::LControl);
|
||||||
|
instance.PushField("LShift", Nz::Keyboard::LShift);
|
||||||
|
instance.PushField("LSystem", Nz::Keyboard::LSystem);
|
||||||
|
instance.PushField("PageDown", Nz::Keyboard::PageDown);
|
||||||
|
instance.PushField("PageUp", Nz::Keyboard::PageUp);
|
||||||
|
instance.PushField("Pause", Nz::Keyboard::Pause);
|
||||||
|
instance.PushField("Period", Nz::Keyboard::Period);
|
||||||
|
instance.PushField("Print", Nz::Keyboard::Print);
|
||||||
|
instance.PushField("PrintScreen", Nz::Keyboard::PrintScreen);
|
||||||
|
instance.PushField("Quote", Nz::Keyboard::Quote);
|
||||||
|
instance.PushField("RAlt", Nz::Keyboard::RAlt);
|
||||||
|
instance.PushField("RBracket", Nz::Keyboard::RBracket);
|
||||||
|
instance.PushField("RControl", Nz::Keyboard::RControl);
|
||||||
|
instance.PushField("Return", Nz::Keyboard::Return);
|
||||||
|
instance.PushField("RShift", Nz::Keyboard::RShift);
|
||||||
|
instance.PushField("RSystem", Nz::Keyboard::RSystem);
|
||||||
|
instance.PushField("Semicolon", Nz::Keyboard::Semicolon);
|
||||||
|
instance.PushField("Slash", Nz::Keyboard::Slash);
|
||||||
|
instance.PushField("Space", Nz::Keyboard::Space);
|
||||||
|
instance.PushField("Tab", Nz::Keyboard::Tab);
|
||||||
|
instance.PushField("Tilde", Nz::Keyboard::Tilde);
|
||||||
|
instance.PushField("Browser_Back", Nz::Keyboard::Browser_Back);
|
||||||
|
instance.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites);
|
||||||
|
instance.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward);
|
||||||
|
instance.PushField("Browser_Home", Nz::Keyboard::Browser_Home);
|
||||||
|
instance.PushField("Browser_Refresh", Nz::Keyboard::Browser_Refresh);
|
||||||
|
instance.PushField("Browser_Search", Nz::Keyboard::Browser_Search);
|
||||||
|
instance.PushField("Browser_Stop", Nz::Keyboard::Browser_Stop);
|
||||||
|
instance.PushField("Media_Next", Nz::Keyboard::Media_Next);
|
||||||
|
instance.PushField("Media_Play", Nz::Keyboard::Media_Play);
|
||||||
|
instance.PushField("Media_Previous", Nz::Keyboard::Media_Previous);
|
||||||
|
instance.PushField("Media_Stop", Nz::Keyboard::Media_Stop);
|
||||||
|
instance.PushField("Volume_Down", Nz::Keyboard::Volume_Down);
|
||||||
|
instance.PushField("Volume_Mute", Nz::Keyboard::Volume_Mute);
|
||||||
|
instance.PushField("Volume_Up", Nz::Keyboard::Volume_Up);
|
||||||
|
instance.PushField("CapsLock", Nz::Keyboard::CapsLock);
|
||||||
|
instance.PushField("NumLock", Nz::Keyboard::NumLock);
|
||||||
|
instance.PushField("ScrollLock", Nz::Keyboard::ScrollLock);
|
||||||
|
}
|
||||||
|
instance.Pop();
|
||||||
|
|
||||||
|
static_assert(Nz::WindowStyle_Max + 1 == 6, "Nz::WindowStyle has been updated but change was not reflected to Lua binding");
|
||||||
|
instance.PushTable(0, Nz::WindowStyle_Max + 1);
|
||||||
|
{
|
||||||
|
instance.PushField("None", Nz::WindowStyle_None);
|
||||||
|
instance.PushField("Fullscreen", Nz::WindowStyle_Fullscreen);
|
||||||
|
instance.PushField("Closable", Nz::WindowStyle_Closable);
|
||||||
|
instance.PushField("Resizable", Nz::WindowStyle_Resizable);
|
||||||
|
instance.PushField("Titlebar", Nz::WindowStyle_Titlebar);
|
||||||
|
instance.PushField("Threaded", Nz::WindowStyle_Threaded);
|
||||||
|
}
|
||||||
|
instance.SetGlobal("WindowStyle");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
#include <NDK/LuaAPI.hpp>
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
#include <NDK/LuaBinding.hpp>
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,110 +0,0 @@
|
||||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \ingroup NDK
|
|
||||||
* \class Ndk::LuaBinding
|
|
||||||
* \brief NDK class that represents the binding between the engine & the SDK with the Lua scripting
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Binds modules to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
LuaBinding::LuaBinding() :
|
|
||||||
// Core
|
|
||||||
clock("Clock"),
|
|
||||||
directory("Directory"),
|
|
||||||
file("File"),
|
|
||||||
stream("Stream"),
|
|
||||||
|
|
||||||
// Math
|
|
||||||
eulerAngles("EulerAngles"),
|
|
||||||
matrix4d("Matrix4"),
|
|
||||||
quaternion("Quaternion"),
|
|
||||||
rect("Rect"),
|
|
||||||
vector2d("Vector2"),
|
|
||||||
vector3d("Vector3"),
|
|
||||||
|
|
||||||
// Network
|
|
||||||
abstractSocket("AbstractSocket"),
|
|
||||||
ipAddress("IpAddress"),
|
|
||||||
|
|
||||||
// Utility
|
|
||||||
abstractImage("AbstractImage"),
|
|
||||||
font("Font"),
|
|
||||||
keyboard("Keyboard"),
|
|
||||||
node("Node"),
|
|
||||||
|
|
||||||
// SDK
|
|
||||||
application("Application"),
|
|
||||||
entity("Entity"),
|
|
||||||
nodeComponent("NodeComponent"),
|
|
||||||
velocityComponent("VelocityComponent"),
|
|
||||||
world("World")
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
,
|
|
||||||
|
|
||||||
// Audio
|
|
||||||
music("Music"),
|
|
||||||
sound("Sound"),
|
|
||||||
soundBuffer("SoundBuffer"),
|
|
||||||
soundEmitter("SoundEmitter"),
|
|
||||||
|
|
||||||
// Graphics
|
|
||||||
abstractViewer("AbstractViewer"),
|
|
||||||
instancedRenderable("InstancedRenderable"),
|
|
||||||
material("Material"),
|
|
||||||
model("Model"),
|
|
||||||
sprite("Sprite"),
|
|
||||||
spriteLibrary("SpriteLibrary"),
|
|
||||||
textureLibrary("TextureLibrary"),
|
|
||||||
textureManager("TextureManager"),
|
|
||||||
|
|
||||||
// Renderer
|
|
||||||
texture("Texture"),
|
|
||||||
|
|
||||||
// SDK
|
|
||||||
cameraComponent("CameraComponent"),
|
|
||||||
console("Console"),
|
|
||||||
graphicsComponent("GraphicsComponent")
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
BindCore();
|
|
||||||
BindMath();
|
|
||||||
BindNetwork();
|
|
||||||
BindSDK();
|
|
||||||
BindUtility();
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
BindAudio();
|
|
||||||
BindGraphics();
|
|
||||||
BindRenderer();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Registers the classes that will be used by the Lua instance
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the engine & SDK
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::RegisterClasses(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
RegisterCore(instance);
|
|
||||||
RegisterMath(instance);
|
|
||||||
RegisterNetwork(instance);
|
|
||||||
RegisterSDK(instance);
|
|
||||||
RegisterUtility(instance);
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
RegisterAudio(instance);
|
|
||||||
RegisterGraphics(instance);
|
|
||||||
RegisterRenderer(instance);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,185 +0,0 @@
|
||||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <Nazara/Core/MemoryHelper.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds Audio module to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::BindAudio()
|
|
||||||
{
|
|
||||||
/*********************************** Nz::Music **********************************/
|
|
||||||
music.Inherit(soundEmitter);
|
|
||||||
|
|
||||||
music.BindDefaultConstructor();
|
|
||||||
|
|
||||||
//musicClass.SetMethod("Create", &Nz::Music::Create);
|
|
||||||
//musicClass.SetMethod("Destroy", &Nz::Music::Destroy);
|
|
||||||
|
|
||||||
music.BindMethod("EnableLooping", &Nz::Music::EnableLooping);
|
|
||||||
|
|
||||||
music.BindMethod("GetDuration", &Nz::Music::GetDuration);
|
|
||||||
music.BindMethod("GetFormat", &Nz::Music::GetFormat);
|
|
||||||
music.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset);
|
|
||||||
music.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount);
|
|
||||||
music.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate);
|
|
||||||
music.BindMethod("GetStatus", &Nz::Music::GetStatus);
|
|
||||||
|
|
||||||
music.BindMethod("IsLooping", &Nz::Music::IsLooping);
|
|
||||||
|
|
||||||
music.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams());
|
|
||||||
|
|
||||||
music.BindMethod("Pause", &Nz::Music::Pause);
|
|
||||||
music.BindMethod("Play", &Nz::Music::Play);
|
|
||||||
|
|
||||||
music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset);
|
|
||||||
|
|
||||||
music.BindMethod("Stop", &Nz::Music::Stop);
|
|
||||||
|
|
||||||
// Manual
|
|
||||||
music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
Nz::StringStream ss("Music(");
|
|
||||||
ss << instance.GetFilePath() << ')';
|
|
||||||
|
|
||||||
lua.PushString(ss);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::Sound **********************************/
|
|
||||||
sound.Inherit(soundEmitter);
|
|
||||||
|
|
||||||
sound.BindDefaultConstructor();
|
|
||||||
|
|
||||||
sound.BindMethod("GetBuffer", &Nz::Sound::GetBuffer);
|
|
||||||
|
|
||||||
sound.BindMethod("IsPlayable", &Nz::Sound::IsPlayable);
|
|
||||||
sound.BindMethod("IsPlaying", &Nz::Sound::IsPlaying);
|
|
||||||
|
|
||||||
sound.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
|
|
||||||
|
|
||||||
sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);
|
|
||||||
|
|
||||||
// Manual
|
|
||||||
sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
Nz::StringStream ss("Sound(");
|
|
||||||
if (const Nz::SoundBuffer* buffer = instance.GetBuffer())
|
|
||||||
ss << buffer;
|
|
||||||
|
|
||||||
ss << ')';
|
|
||||||
|
|
||||||
lua.PushString(ss);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::SoundBuffer **********************************/
|
|
||||||
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
NazaraUnused(lua);
|
|
||||||
NazaraUnused(argumentCount);
|
|
||||||
|
|
||||||
Nz::PlacementNew(instance, Nz::SoundBuffer::New());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy);
|
|
||||||
|
|
||||||
soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration);
|
|
||||||
soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat);
|
|
||||||
soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount);
|
|
||||||
soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate);
|
|
||||||
|
|
||||||
soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid);
|
|
||||||
|
|
||||||
soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams());
|
|
||||||
|
|
||||||
soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported);
|
|
||||||
|
|
||||||
// Manual
|
|
||||||
soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int index = 2;
|
|
||||||
Nz::AudioFormat format = lua.Check<Nz::AudioFormat>(&index);
|
|
||||||
unsigned int sampleCount = lua.Check<unsigned int>(&index);
|
|
||||||
unsigned int sampleRate = lua.Check<unsigned int>(&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<const Nz::Int16*>(buffer)));
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
lua.PushString(reinterpret_cast<const char*>(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16));
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
Nz::StringStream ss("SoundBuffer(");
|
|
||||||
if (instance->IsValid())
|
|
||||||
{
|
|
||||||
Nz::String filePath = instance->GetFilePath();
|
|
||||||
if (!filePath.IsEmpty())
|
|
||||||
ss << "File: " << filePath << ", ";
|
|
||||||
|
|
||||||
ss << "Duration: " << instance->GetDuration() / 1000.f << "s";
|
|
||||||
}
|
|
||||||
ss << ')';
|
|
||||||
|
|
||||||
lua.PushString(ss);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::SoundEmitter **********************************/
|
|
||||||
soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping);
|
|
||||||
soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization);
|
|
||||||
|
|
||||||
soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation);
|
|
||||||
soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration);
|
|
||||||
soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance);
|
|
||||||
soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch);
|
|
||||||
soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset);
|
|
||||||
soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition);
|
|
||||||
soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus);
|
|
||||||
soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity);
|
|
||||||
soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume);
|
|
||||||
|
|
||||||
soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping);
|
|
||||||
soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);
|
|
||||||
|
|
||||||
soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause);
|
|
||||||
soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play);
|
|
||||||
|
|
||||||
soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation);
|
|
||||||
soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance);
|
|
||||||
soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch);
|
|
||||||
soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition);
|
|
||||||
soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity);
|
|
||||||
soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume);
|
|
||||||
|
|
||||||
soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Registers the classes that will be used by the Lua instance
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the Audio classes
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::RegisterAudio(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
music.Register(instance);
|
|
||||||
sound.Register(instance);
|
|
||||||
soundBuffer.Register(instance);
|
|
||||||
soundEmitter.Register(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,341 +0,0 @@
|
||||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <Nazara/Core/MemoryHelper.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds Core module to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::BindCore()
|
|
||||||
{
|
|
||||||
/*********************************** Nz::Clock **********************************/
|
|
||||||
clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Nz::PlacementNew(instance);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
|
||||||
|
|
||||||
Nz::PlacementNew(instance, startingValue);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
|
||||||
bool paused = lua.Check<bool>(&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::LuaInstance& lua, Nz::Clock& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
Nz::StringStream ss("Clock(Elapsed: ");
|
|
||||||
ss << instance.GetSeconds();
|
|
||||||
ss << "s, Paused: ";
|
|
||||||
ss << instance.IsPaused();
|
|
||||||
ss << ')';
|
|
||||||
|
|
||||||
lua.PushString(ss);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
/********************************* Nz::Directory ********************************/
|
|
||||||
directory.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Nz::PlacementNew(instance);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
Nz::PlacementNew(instance, lua.Check<Nz::String>(&argIndex));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
directory.BindMethod("Close", &Nz::Directory::Close);
|
|
||||||
directory.BindMethod("Exists", &Nz::Directory::Exists);
|
|
||||||
directory.BindMethod("GetPath", &Nz::Directory::GetPath);
|
|
||||||
directory.BindMethod("GetPattern", &Nz::Directory::GetPattern);
|
|
||||||
directory.BindMethod("GetResultName", &Nz::Directory::GetResultName);
|
|
||||||
directory.BindMethod("GetResultPath", &Nz::Directory::GetResultPath);
|
|
||||||
directory.BindMethod("GetResultSize", &Nz::Directory::GetResultSize);
|
|
||||||
directory.BindMethod("IsOpen", &Nz::Directory::IsOpen);
|
|
||||||
directory.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory);
|
|
||||||
directory.BindMethod("NextResult", &Nz::Directory::NextResult, true);
|
|
||||||
directory.BindMethod("Open", &Nz::Directory::Open);
|
|
||||||
directory.BindMethod("SetPath", &Nz::Directory::SetPath);
|
|
||||||
directory.BindMethod("SetPattern", &Nz::Directory::SetPattern);
|
|
||||||
|
|
||||||
directory.BindStaticMethod("Copy", Nz::Directory::Copy);
|
|
||||||
directory.BindStaticMethod("Create", Nz::Directory::Create);
|
|
||||||
directory.BindStaticMethod("Exists", Nz::Directory::Exists);
|
|
||||||
directory.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent);
|
|
||||||
directory.BindStaticMethod("Remove", Nz::Directory::Remove);
|
|
||||||
directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
|
|
||||||
|
|
||||||
// Manual
|
|
||||||
directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
Nz::StringStream ss("Directory(");
|
|
||||||
ss << instance.GetPath();
|
|
||||||
ss << ')';
|
|
||||||
|
|
||||||
lua.PushString(ss);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::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::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
std::size_t length = lua.Check<std::size_t>(&argIndex);
|
|
||||||
|
|
||||||
std::unique_ptr<char[]> 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::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
std::size_t bufferSize = 0;
|
|
||||||
const char* buffer = lua.CheckString(argIndex, &bufferSize);
|
|
||||||
|
|
||||||
if (instance.IsTextModeEnabled())
|
|
||||||
lua.Push(instance.Write(Nz::String(buffer, bufferSize)));
|
|
||||||
else
|
|
||||||
lua.Push(instance.Write(buffer, bufferSize));
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::File ***********************************/
|
|
||||||
file.Inherit(stream);
|
|
||||||
|
|
||||||
file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Nz::PlacementNew(instance);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
|
||||||
|
|
||||||
Nz::PlacementNew(instance, filePath);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
|
||||||
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&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("GetCreationTime", &Nz::File::GetCreationTime);
|
|
||||||
file.BindMethod("GetFileName", &Nz::File::GetFileName);
|
|
||||||
file.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
|
||||||
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
|
||||||
file.BindMethod("IsOpen", &Nz::File::IsOpen);
|
|
||||||
file.BindMethod("Rename", &Nz::File::GetLastWriteTime);
|
|
||||||
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
|
||||||
file.BindMethod("SetFile", &Nz::File::GetLastWriteTime);
|
|
||||||
|
|
||||||
file.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath);
|
|
||||||
file.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash);
|
|
||||||
file.BindStaticMethod("Copy", &Nz::File::Copy);
|
|
||||||
file.BindStaticMethod("Delete", &Nz::File::Delete);
|
|
||||||
file.BindStaticMethod("Exists", &Nz::File::Exists);
|
|
||||||
//fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
|
||||||
file.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory);
|
|
||||||
//fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
|
||||||
//fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
|
||||||
file.BindStaticMethod("GetSize", &Nz::File::GetSize);
|
|
||||||
file.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute);
|
|
||||||
file.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath);
|
|
||||||
file.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators);
|
|
||||||
file.BindStaticMethod("Rename", &Nz::File::Rename);
|
|
||||||
|
|
||||||
// Manual
|
|
||||||
file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
case 1:
|
|
||||||
return lua.Push(instance.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
|
||||||
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&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::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
return lua.Push(instance.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
Nz::CursorPosition curPos = lua.Check<Nz::CursorPosition>(&argIndex);
|
|
||||||
Nz::Int64 offset = lua.Check<Nz::Int64>(&argIndex);
|
|
||||||
return lua.Push(instance.SetCursorPos(curPos, offset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method SetCursorPos");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
Nz::StringStream ss("File(");
|
|
||||||
if (instance.IsOpen())
|
|
||||||
ss << "Path: " << instance.GetPath();
|
|
||||||
|
|
||||||
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::RegisterCore(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
// Classes
|
|
||||||
clock.Register(instance);
|
|
||||||
directory.Register(instance);
|
|
||||||
file.Register(instance);
|
|
||||||
stream.Register(instance);
|
|
||||||
|
|
||||||
// Enums
|
|
||||||
|
|
||||||
// Nz::CursorPosition
|
|
||||||
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
|
||||||
instance.PushTable(0, 3);
|
|
||||||
{
|
|
||||||
instance.PushField("AtBegin", Nz::CursorPosition_AtBegin);
|
|
||||||
instance.PushField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
|
||||||
instance.PushField("AtEnd", Nz::CursorPosition_AtEnd);
|
|
||||||
}
|
|
||||||
instance.SetGlobal("CursorPosition");
|
|
||||||
|
|
||||||
// Nz::HashType
|
|
||||||
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
|
||||||
instance.PushTable(0, 9);
|
|
||||||
{
|
|
||||||
instance.PushField("CRC32", Nz::HashType_CRC32);
|
|
||||||
instance.PushField("Fletcher16", Nz::HashType_Fletcher16);
|
|
||||||
instance.PushField("MD5", Nz::HashType_MD5);
|
|
||||||
instance.PushField("SHA1", Nz::HashType_SHA1);
|
|
||||||
instance.PushField("SHA224", Nz::HashType_SHA224);
|
|
||||||
instance.PushField("SHA256", Nz::HashType_SHA256);
|
|
||||||
instance.PushField("SHA384", Nz::HashType_SHA384);
|
|
||||||
instance.PushField("SHA512", Nz::HashType_SHA512);
|
|
||||||
instance.PushField("Whirlpool", Nz::HashType_Whirlpool);
|
|
||||||
}
|
|
||||||
instance.SetGlobal("HashType");
|
|
||||||
|
|
||||||
// Nz::OpenMode
|
|
||||||
static_assert(Nz::OpenMode_Max + 1 == 2 * (64), "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
|
||||||
instance.PushTable(0, 8);
|
|
||||||
{
|
|
||||||
instance.PushField("Append", Nz::OpenMode_Append);
|
|
||||||
instance.PushField("NotOpen", Nz::OpenMode_NotOpen);
|
|
||||||
instance.PushField("Lock", Nz::OpenMode_Lock);
|
|
||||||
instance.PushField("ReadOnly", Nz::OpenMode_ReadOnly);
|
|
||||||
instance.PushField("ReadWrite", Nz::OpenMode_ReadWrite);
|
|
||||||
instance.PushField("Text", Nz::OpenMode_Text);
|
|
||||||
instance.PushField("Truncate", Nz::OpenMode_Truncate);
|
|
||||||
instance.PushField("WriteOnly", Nz::OpenMode_WriteOnly);
|
|
||||||
}
|
|
||||||
instance.SetGlobal("OpenMode");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,371 +0,0 @@
|
||||||
// This file is part of the "Nazara Development Kit"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds Graphics module to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::BindGraphics()
|
|
||||||
{
|
|
||||||
/*********************************** Nz::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 ***********************************/
|
|
||||||
|
|
||||||
/*********************************** Nz::Material ***********************************/
|
|
||||||
material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
switch (argumentCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Nz::PlacementNew(instance, Nz::Material::New());
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
int argIndex = 1;
|
|
||||||
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Material::New(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex))));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (lua.IsOfType(argIndex, "Material"))
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Material::New(**static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex))));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Material::New(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("Configure", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
|
||||||
{
|
|
||||||
instance->Configure(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lua.Push(instance->Configure(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("EnableAlphaTest", &Nz::Material::EnableAlphaTest);
|
|
||||||
material.BindMethod("EnableBlending", &Nz::Material::EnableBlending);
|
|
||||||
material.BindMethod("EnableColorWrite", &Nz::Material::EnableColorWrite);
|
|
||||||
material.BindMethod("EnableDepthBuffer", &Nz::Material::EnableDepthBuffer);
|
|
||||||
material.BindMethod("EnableDepthSorting", &Nz::Material::EnableDepthSorting);
|
|
||||||
material.BindMethod("EnableDepthWrite", &Nz::Material::EnableDepthWrite);
|
|
||||||
material.BindMethod("EnableFaceCulling", &Nz::Material::EnableFaceCulling);
|
|
||||||
material.BindMethod("EnableScissorTest", &Nz::Material::EnableScissorTest);
|
|
||||||
material.BindMethod("EnableShadowCasting", &Nz::Material::EnableShadowCasting);
|
|
||||||
material.BindMethod("EnableShadowReceive", &Nz::Material::EnableShadowReceive);
|
|
||||||
material.BindMethod("EnableStencilTest", &Nz::Material::EnableStencilTest);
|
|
||||||
|
|
||||||
material.BindMethod("EnsurePipelineUpdate", &Nz::Material::EnsurePipelineUpdate);
|
|
||||||
|
|
||||||
material.BindMethod("GetAlphaMap", &Nz::Material::GetAlphaMap);
|
|
||||||
material.BindMethod("GetAlphaThreshold", &Nz::Material::GetAlphaThreshold);
|
|
||||||
material.BindMethod("GetAmbientColor", &Nz::Material::GetAmbientColor);
|
|
||||||
material.BindMethod("GetDepthFunc", &Nz::Material::GetDepthFunc);
|
|
||||||
material.BindMethod("GetDepthMaterial", &Nz::Material::GetDepthMaterial);
|
|
||||||
material.BindMethod("GetDiffuseColor", &Nz::Material::GetDiffuseColor);
|
|
||||||
material.BindMethod("GetDiffuseMap", &Nz::Material::GetDiffuseMap);
|
|
||||||
//material.BindMethod("GetDiffuseSampler", &Nz::Material::GetDiffuseSampler);
|
|
||||||
material.BindMethod("GetDstBlend", &Nz::Material::GetDstBlend);
|
|
||||||
material.BindMethod("GetEmissiveMap", &Nz::Material::GetEmissiveMap);
|
|
||||||
material.BindMethod("GetFaceCulling", &Nz::Material::GetFaceCulling);
|
|
||||||
material.BindMethod("GetFaceFilling", &Nz::Material::GetFaceFilling);
|
|
||||||
material.BindMethod("GetHeightMap", &Nz::Material::GetHeightMap);
|
|
||||||
material.BindMethod("GetLineWidth", &Nz::Material::GetLineWidth);
|
|
||||||
material.BindMethod("GetNormalMap", &Nz::Material::GetNormalMap);
|
|
||||||
//material.BindMethod("GetPipeline", &Nz::Material::GetPipeline);
|
|
||||||
//material.BindMethod("GetPipelineInfo", &Nz::Material::GetPipelineInfo);
|
|
||||||
material.BindMethod("GetPointSize", &Nz::Material::GetPointSize);
|
|
||||||
//material.BindMethod("GetShader", &Nz::Material::GetShader);
|
|
||||||
material.BindMethod("GetShininess", &Nz::Material::GetShininess);
|
|
||||||
material.BindMethod("GetSpecularColor", &Nz::Material::GetSpecularColor);
|
|
||||||
material.BindMethod("GetSpecularMap", &Nz::Material::GetSpecularMap);
|
|
||||||
//material.BindMethod("GetSpecularSampler", &Nz::Material::GetSpecularSampler);
|
|
||||||
material.BindMethod("GetSrcBlend", &Nz::Material::GetSrcBlend);
|
|
||||||
|
|
||||||
material.BindMethod("HasAlphaMap", &Nz::Material::HasAlphaMap);
|
|
||||||
material.BindMethod("HasDepthMaterial", &Nz::Material::HasDepthMaterial);
|
|
||||||
material.BindMethod("HasDiffuseMap", &Nz::Material::HasDiffuseMap);
|
|
||||||
material.BindMethod("HasEmissiveMap", &Nz::Material::HasEmissiveMap);
|
|
||||||
material.BindMethod("HasHeightMap", &Nz::Material::HasHeightMap);
|
|
||||||
material.BindMethod("HasNormalMap", &Nz::Material::HasNormalMap);
|
|
||||||
material.BindMethod("HasSpecularMap", &Nz::Material::HasSpecularMap);
|
|
||||||
|
|
||||||
material.BindMethod("IsAlphaTestEnabled", &Nz::Material::IsAlphaTestEnabled);
|
|
||||||
material.BindMethod("IsBlendingEnabled", &Nz::Material::IsBlendingEnabled);
|
|
||||||
material.BindMethod("IsColorWriteEnabled", &Nz::Material::IsColorWriteEnabled);
|
|
||||||
material.BindMethod("IsDepthBufferEnabled", &Nz::Material::IsDepthBufferEnabled);
|
|
||||||
material.BindMethod("IsDepthSortingEnabled", &Nz::Material::IsDepthSortingEnabled);
|
|
||||||
material.BindMethod("IsDepthWriteEnabled", &Nz::Material::IsDepthWriteEnabled);
|
|
||||||
material.BindMethod("IsFaceCullingEnabled", &Nz::Material::IsFaceCullingEnabled);
|
|
||||||
material.BindMethod("IsScissorTestEnabled", &Nz::Material::IsScissorTestEnabled);
|
|
||||||
material.BindMethod("IsStencilTestEnabled", &Nz::Material::IsStencilTestEnabled);
|
|
||||||
material.BindMethod("IsShadowCastingEnabled", &Nz::Material::IsShadowCastingEnabled);
|
|
||||||
material.BindMethod("IsShadowReceiveEnabled", &Nz::Material::IsShadowReceiveEnabled);
|
|
||||||
|
|
||||||
material.BindMethod("LoadFromFile", &Nz::Material::LoadFromFile, Nz::MaterialParams());
|
|
||||||
|
|
||||||
material.BindMethod("Reset", &Nz::Material::Reset);
|
|
||||||
|
|
||||||
material.BindMethod("SetAlphaThreshold", &Nz::Material::SetAlphaThreshold);
|
|
||||||
material.BindMethod("SetAmbientColor", &Nz::Material::SetAmbientColor);
|
|
||||||
material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc);
|
|
||||||
material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc);
|
|
||||||
material.BindMethod("SetDepthMaterial", &Nz::Material::SetDepthMaterial);
|
|
||||||
material.BindMethod("SetDiffuseColor", &Nz::Material::SetDiffuseColor);
|
|
||||||
//material.BindMethod("SetDiffuseSampler", &Nz::Material::SetDiffuseSampler);
|
|
||||||
material.BindMethod("SetDstBlend", &Nz::Material::SetDstBlend);
|
|
||||||
material.BindMethod("SetFaceCulling", &Nz::Material::SetFaceCulling);
|
|
||||||
material.BindMethod("SetFaceFilling", &Nz::Material::SetFaceFilling);
|
|
||||||
material.BindMethod("SetLineWidth", &Nz::Material::SetLineWidth);
|
|
||||||
material.BindMethod("SetPointSize", &Nz::Material::SetPointSize);
|
|
||||||
material.BindMethod("SetShininess", &Nz::Material::SetShininess);
|
|
||||||
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
|
||||||
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
|
||||||
//material.BindMethod("SetSpecularSampler", &Nz::Material::SetSpecularSampler);
|
|
||||||
material.BindMethod("SetSrcBlend", &Nz::Material::SetSrcBlend);
|
|
||||||
|
|
||||||
material.BindStaticMethod("GetDefault", &Nz::Material::GetDefault);
|
|
||||||
|
|
||||||
material.BindMethod("SetAlphaMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetAlphaMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetAlphaMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetDiffuseMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetDiffuseMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetEmissiveMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetEmissiveMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetHeightMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetHeightMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetNormalMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetNormalMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "UberShader"))
|
|
||||||
{
|
|
||||||
instance->SetShader(*static_cast<Nz::UberShaderRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetShader(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetSpecularMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetSpecularMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::Model ***********************************/
|
|
||||||
model.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef*
|
|
||||||
{
|
|
||||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(modelRef); //TODO: Make a ObjectRefCast
|
|
||||||
});
|
|
||||||
|
|
||||||
model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* instance, std::size_t /*argumentCount*/)
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Model::New());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
//model.BindMethod("GetMaterial", &Nz::Model::GetMaterial);
|
|
||||||
model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
|
|
||||||
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
|
|
||||||
model.BindMethod("GetSkin", &Nz::Model::GetSkin);
|
|
||||||
model.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
|
|
||||||
|
|
||||||
model.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
|
|
||||||
model.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
|
|
||||||
|
|
||||||
model.BindMethod("Reset", &Nz::Model::Reset);
|
|
||||||
|
|
||||||
//model.BindMethod("SetMaterial", &Nz::Model::SetMaterial);
|
|
||||||
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
|
|
||||||
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
|
||||||
model.BindMethod("SetSkin", &Nz::Model::SetSkin);
|
|
||||||
model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
|
||||||
|
|
||||||
/*********************************** Nz::Sprite ***********************************/
|
|
||||||
sprite.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef*
|
|
||||||
{
|
|
||||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(spriteRef); //TODO: Make a ObjectRefCast
|
|
||||||
});
|
|
||||||
|
|
||||||
sprite.SetConstructor([] (Nz::LuaInstance& /*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("GetMaterial", &Nz::Sprite::GetMaterial);
|
|
||||||
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::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
|
||||||
|
|
||||||
if (lua.IsOfType(argIndex, "Material"))
|
|
||||||
instance->SetMaterial(*static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
|
||||||
else
|
|
||||||
instance->SetMaterial(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
sprite.BindMethod("SetTexture", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
|
||||||
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
instance->SetTexture(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
|
||||||
else
|
|
||||||
instance->SetTexture(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::SpriteLibrary ***********************************/
|
|
||||||
|
|
||||||
spriteLibrary.BindStaticMethod("Get", &Nz::SpriteLibrary::Get);
|
|
||||||
spriteLibrary.BindStaticMethod("Has", &Nz::SpriteLibrary::Has);
|
|
||||||
spriteLibrary.BindStaticMethod("Register", &Nz::SpriteLibrary::Register);
|
|
||||||
spriteLibrary.BindStaticMethod("Query", &Nz::SpriteLibrary::Query);
|
|
||||||
spriteLibrary.BindStaticMethod("Unregister", &Nz::SpriteLibrary::Unregister);
|
|
||||||
|
|
||||||
/*********************************** Nz::TextureLibrary ***********************************/
|
|
||||||
|
|
||||||
textureLibrary.BindStaticMethod("Get", &Nz::TextureLibrary::Get);
|
|
||||||
textureLibrary.BindStaticMethod("Has", &Nz::TextureLibrary::Has);
|
|
||||||
textureLibrary.BindStaticMethod("Register", &Nz::TextureLibrary::Register);
|
|
||||||
textureLibrary.BindStaticMethod("Query", &Nz::TextureLibrary::Query);
|
|
||||||
textureLibrary.BindStaticMethod("Unregister", &Nz::TextureLibrary::Unregister);
|
|
||||||
|
|
||||||
/*********************************** Nz::TextureManager ***********************************/
|
|
||||||
|
|
||||||
textureManager.BindStaticMethod("Clear", &Nz::TextureManager::Clear);
|
|
||||||
textureManager.BindStaticMethod("Get", &Nz::TextureManager::Get);
|
|
||||||
textureManager.BindStaticMethod("GetDefaultParameters", &Nz::TextureManager::GetDefaultParameters);
|
|
||||||
textureManager.BindStaticMethod("Purge", &Nz::TextureManager::Purge);
|
|
||||||
textureManager.BindStaticMethod("Register", &Nz::TextureManager::Register);
|
|
||||||
textureManager.BindStaticMethod("SetDefaultParameters", &Nz::TextureManager::SetDefaultParameters);
|
|
||||||
textureManager.BindStaticMethod("Unregister", &Nz::TextureManager::Unregister);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \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::RegisterGraphics(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
abstractViewer.Register(instance);
|
|
||||||
instancedRenderable.Register(instance);
|
|
||||||
material.Register(instance);
|
|
||||||
model.Register(instance);
|
|
||||||
sprite.Register(instance);
|
|
||||||
spriteLibrary.Register(instance);
|
|
||||||
textureLibrary.Register(instance);
|
|
||||||
textureManager.Register(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,968 +0,0 @@
|
||||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <Nazara/Core/MemoryHelper.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds Math module to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::BindMath()
|
|
||||||
{
|
|
||||||
/*********************************** Nz::EulerAngles **********************************/
|
|
||||||
eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
|
||||||
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero());
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
Nz::PlacementNew(instance, *static_cast<Nz::EulerAnglesd*>(lua.CheckUserdata(1, "EulerAngles")));
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for EulerAngles constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
eulerAngles.BindMethod("Normalize", &Nz::EulerAnglesd::Normalize);
|
|
||||||
eulerAngles.BindMethod("ToQuaternion", &Nz::EulerAnglesd::ToQuaternion);
|
|
||||||
|
|
||||||
eulerAngles.BindMethod("__tostring", &Nz::EulerAnglesd::ToString);
|
|
||||||
|
|
||||||
eulerAngles.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* ypr = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
switch (length)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
switch (ypr[0])
|
|
||||||
{
|
|
||||||
case 'p':
|
|
||||||
lua.Push(instance.pitch);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
lua.Push(instance.yaw);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'r':
|
|
||||||
lua.Push(instance.roll);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
{
|
|
||||||
if (std::memcmp(ypr, "yaw", 3) != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
lua.Push(instance.yaw);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
{
|
|
||||||
if (std::memcmp(ypr, "roll", 4) != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
lua.Push(instance.roll);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 5:
|
|
||||||
{
|
|
||||||
if (std::memcmp(ypr, "pitch", 5) != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
lua.Push(instance.pitch);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
eulerAngles.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* ypr = lua.CheckString(2, &length);
|
|
||||||
double value = lua.CheckNumber(3);
|
|
||||||
|
|
||||||
switch (length)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
switch (ypr[0])
|
|
||||||
{
|
|
||||||
case 'p':
|
|
||||||
instance.pitch = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
instance.yaw = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'r':
|
|
||||||
instance.roll = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
{
|
|
||||||
if (std::memcmp(ypr, "yaw", 3) != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
instance.yaw = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
{
|
|
||||||
if (std::memcmp(ypr, "roll", 4) != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
instance.roll = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 5:
|
|
||||||
{
|
|
||||||
if (std::memcmp(ypr, "pitch", 5) != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
instance.pitch = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************** Nz::Matrix4 **********************************/
|
|
||||||
matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(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<Nz::Matrix4d*>(lua.ToUserdata(1)));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 16:
|
|
||||||
{
|
|
||||||
double values[16];
|
|
||||||
for (int i = 0; i < 16; ++i)
|
|
||||||
values[i] = lua.CheckNumber(i);
|
|
||||||
|
|
||||||
Nz::PlacementNew(matrix, values);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
matrix4d.BindMethod("ApplyRotation", &Nz::Matrix4d::ApplyRotation);
|
|
||||||
matrix4d.BindMethod("ApplyScale", &Nz::Matrix4d::ApplyScale);
|
|
||||||
matrix4d.BindMethod("ApplyTranslation", &Nz::Matrix4d::ApplyTranslation);
|
|
||||||
|
|
||||||
matrix4d.BindMethod("Concatenate", &Nz::Matrix4d::Concatenate);
|
|
||||||
matrix4d.BindMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine);
|
|
||||||
|
|
||||||
//matrix4d.BindMethod("GetColumn", &Nz::Matrix4d::GetColumn);
|
|
||||||
matrix4d.BindMethod("GetDeterminant", &Nz::Matrix4d::GetDeterminant);
|
|
||||||
matrix4d.BindMethod("GetDeterminantAffine", &Nz::Matrix4d::GetDeterminantAffine);
|
|
||||||
|
|
||||||
matrix4d.BindMethod("GetInverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
Nz::Matrix4d result;
|
|
||||||
if (instance.GetInverse(&result))
|
|
||||||
return lua.Push(true, result);
|
|
||||||
else
|
|
||||||
return lua.Push(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
matrix4d.BindMethod("GetInverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
Nz::Matrix4d result;
|
|
||||||
if (instance.GetInverseAffine(&result))
|
|
||||||
return lua.Push(true, result);
|
|
||||||
else
|
|
||||||
return lua.Push(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
matrix4d.BindMethod("GetRotation", &Nz::Matrix4d::GetRotation);
|
|
||||||
|
|
||||||
//matrix4d.BindMethod("GetRow", &Nz::Matrix4d::GetRow);
|
|
||||||
matrix4d.BindMethod("GetScale", &Nz::Matrix4d::GetScale);
|
|
||||||
matrix4d.BindMethod("GetSquaredScale", &Nz::Matrix4d::GetSquaredScale);
|
|
||||||
matrix4d.BindMethod("GetTranslation", &Nz::Matrix4d::GetTranslation);
|
|
||||||
|
|
||||||
matrix4d.BindMethod("GetTransposed", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
Nz::Matrix4d result;
|
|
||||||
instance.GetTransposed(&result);
|
|
||||||
|
|
||||||
return lua.Push(result);
|
|
||||||
});
|
|
||||||
|
|
||||||
matrix4d.BindMethod("HasNegativeScale", &Nz::Matrix4d::HasNegativeScale);
|
|
||||||
matrix4d.BindMethod("HasScale", &Nz::Matrix4d::HasScale);
|
|
||||||
|
|
||||||
matrix4d.BindMethod("Inverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
bool succeeded;
|
|
||||||
instance.Inverse(&succeeded);
|
|
||||||
|
|
||||||
return lua.Push(succeeded);
|
|
||||||
});
|
|
||||||
|
|
||||||
matrix4d.BindMethod("InverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
bool succeeded;
|
|
||||||
instance.InverseAffine(&succeeded);
|
|
||||||
|
|
||||||
return lua.Push(succeeded);
|
|
||||||
});
|
|
||||||
|
|
||||||
matrix4d.BindMethod("IsAffine", &Nz::Matrix4d::IsAffine);
|
|
||||||
matrix4d.BindMethod("IsIdentity", &Nz::Matrix4d::IsIdentity);
|
|
||||||
|
|
||||||
matrix4d.BindMethod("MakeIdentity", &Nz::Matrix4d::MakeIdentity);
|
|
||||||
matrix4d.BindMethod("MakeLookAt", &Nz::Matrix4d::MakeLookAt, Nz::Vector3d::Up());
|
|
||||||
matrix4d.BindMethod("MakeOrtho", &Nz::Matrix4d::MakeOrtho, -1.0, 1.0);
|
|
||||||
matrix4d.BindMethod("MakePerspective", &Nz::Matrix4d::MakePerspective);
|
|
||||||
matrix4d.BindMethod("MakeRotation", &Nz::Matrix4d::MakeRotation);
|
|
||||||
matrix4d.BindMethod("MakeScale", &Nz::Matrix4d::MakeScale);
|
|
||||||
matrix4d.BindMethod("MakeTranslation", &Nz::Matrix4d::MakeTranslation);
|
|
||||||
matrix4d.BindMethod("MakeTransform", (Nz::Matrix4d&(Nz::Matrix4d::*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::MakeTransform, Nz::Vector3d::Unit());
|
|
||||||
matrix4d.BindMethod("MakeViewMatrix", &Nz::Matrix4d::MakeViewMatrix);
|
|
||||||
matrix4d.BindMethod("MakeZero", &Nz::Matrix4d::MakeZero);
|
|
||||||
|
|
||||||
matrix4d.BindMethod("Set", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
if (lua.IsOfType(argIndex, "Matrix4"))
|
|
||||||
instance.Set(*static_cast<Nz::Matrix4d*>(lua.ToUserdata(argIndex)));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 16:
|
|
||||||
{
|
|
||||||
double values[16];
|
|
||||||
for (std::size_t i = 0; i < 16; ++i)
|
|
||||||
values[i] = lua.CheckNumber(argIndex++);
|
|
||||||
|
|
||||||
instance.Set(values);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method Set");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
matrix4d.BindMethod("SetRotation", &Nz::Matrix4d::SetRotation);
|
|
||||||
matrix4d.BindMethod("SetScale", &Nz::Matrix4d::SetScale);
|
|
||||||
matrix4d.BindMethod("SetTranslation", &Nz::Matrix4d::SetTranslation);
|
|
||||||
|
|
||||||
matrix4d.BindMethod("Transform", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Vector2"))
|
|
||||||
{
|
|
||||||
double z(lua.CheckNumber(argIndex+1, 0.0));
|
|
||||||
double w(lua.CheckNumber(argIndex+2, 1.0));
|
|
||||||
|
|
||||||
return lua.Push(instance.Transform(*static_cast<Nz::Vector2d*>(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<Nz::Vector3d*>(lua.ToUserdata(argIndex)), w));
|
|
||||||
}
|
|
||||||
//else if (lua.IsOfType(2, "Vector4"))
|
|
||||||
// return lua.Push(instance.Transform(*static_cast<Nz::Vector4d*>(lua.ToUserdata(1))));
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method Transform");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
matrix4d.BindMethod("Transpose", &Nz::Matrix4d::Transpose);
|
|
||||||
|
|
||||||
matrix4d.BindMethod("__tostring", &Nz::Matrix4d::ToString);
|
|
||||||
|
|
||||||
matrix4d.BindStaticMethod("Concatenate", &Nz::Matrix4d::Concatenate);
|
|
||||||
matrix4d.BindStaticMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine);
|
|
||||||
matrix4d.BindStaticMethod("Identity", &Nz::Matrix4d::Identity);
|
|
||||||
matrix4d.BindStaticMethod("LookAt", &Nz::Matrix4d::LookAt, Nz::Vector3d::Up());
|
|
||||||
matrix4d.BindStaticMethod("Ortho", &Nz::Matrix4d::Ortho, -1.0, 1.0);
|
|
||||||
matrix4d.BindStaticMethod("Perspective", &Nz::Matrix4d::Perspective);
|
|
||||||
matrix4d.BindStaticMethod("Rotate", &Nz::Matrix4d::Rotate);
|
|
||||||
matrix4d.BindStaticMethod("Scale", &Nz::Matrix4d::Scale);
|
|
||||||
matrix4d.BindStaticMethod("Translate", &Nz::Matrix4d::Translate);
|
|
||||||
matrix4d.BindStaticMethod("Transform", (Nz::Matrix4d(*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::Transform, Nz::Vector3d::Unit());
|
|
||||||
matrix4d.BindStaticMethod("ViewMatrix", &Nz::Matrix4d::ViewMatrix);
|
|
||||||
matrix4d.BindStaticMethod("Zero", &Nz::Matrix4d::Zero);
|
|
||||||
|
|
||||||
matrix4d.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance)
|
|
||||||
{
|
|
||||||
bool succeeded = false;
|
|
||||||
std::size_t index = static_cast<std::size_t>(lua.ToInteger(2, &succeeded));
|
|
||||||
if (!succeeded || index < 1 || index > 16)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
lua.Push(instance[index - 1]);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
matrix4d.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance)
|
|
||||||
{
|
|
||||||
bool succeeded = false;
|
|
||||||
std::size_t index = static_cast<std::size_t>(lua.ToInteger(2, &succeeded));
|
|
||||||
if (!succeeded || index < 1 || index > 16)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
instance[index - 1] = lua.CheckNumber(3);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::Rect **********************************/
|
|
||||||
rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(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<Nz::Rectd*>(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<double>("x", 1),
|
|
||||||
lua.CheckField<double>("y", 1),
|
|
||||||
lua.CheckField<double>("width", 1),
|
|
||||||
lua.CheckField<double>("height", 1));
|
|
||||||
}
|
|
||||||
else if (lua.IsOfType(1, "Vector2"))
|
|
||||||
PlacementNew(instance, *static_cast<Nz::Vector2d*>(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<Nz::Vector2d*>(lua.ToUserdata(1)), *static_cast<Nz::Vector2d*>(lua.ToUserdata(2)));
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for Rect constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
rect.BindMethod("__tostring", &Nz::Rectd::ToString);
|
|
||||||
|
|
||||||
rect.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
|
|
||||||
{
|
|
||||||
switch (lua.GetType(2))
|
|
||||||
{
|
|
||||||
case Nz::LuaType_Number:
|
|
||||||
{
|
|
||||||
auto index = lua.CheckBoundInteger<std::size_t>(2);
|
|
||||||
if (index < 1 || index > 4)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
lua.Push(instance[index - 1]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Nz::LuaType_String:
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* xywh = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
if (length != 1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
switch (xywh[0])
|
|
||||||
{
|
|
||||||
case 'x':
|
|
||||||
lua.Push(instance.x);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
lua.Push(instance.y);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'w':
|
|
||||||
lua.Push(instance.width);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'h':
|
|
||||||
lua.Push(instance.height);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
rect.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
|
|
||||||
{
|
|
||||||
switch (lua.GetType(2))
|
|
||||||
{
|
|
||||||
case Nz::LuaType_Number:
|
|
||||||
{
|
|
||||||
auto index = lua.CheckBoundInteger<std::size_t>(2);
|
|
||||||
if (index < 1 || index > 4)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
instance[index - 1] = lua.CheckNumber(2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Nz::LuaType_String:
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* xywh = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
if (length != 1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
double value = lua.CheckNumber(3);
|
|
||||||
|
|
||||||
switch (xywh[0])
|
|
||||||
{
|
|
||||||
case 'x':
|
|
||||||
instance.x = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
instance.y = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'w':
|
|
||||||
instance.width = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'h':
|
|
||||||
instance.height = value;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::Quaternion **********************************/
|
|
||||||
quaternion.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(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<Nz::EulerAnglesd*>(lua.ToUserdata(1)));
|
|
||||||
else if (lua.IsOfType(1, "Quaternion"))
|
|
||||||
Nz::PlacementNew(instance, *static_cast<Nz::Quaterniond*>(lua.ToUserdata(1)));
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast<Nz::Vector3d*>(lua.CheckUserdata(2, "Vector3")));
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for Quaternion constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
quaternion.BindMethod("ComputeW", &Nz::Quaterniond::ComputeW);
|
|
||||||
quaternion.BindMethod("Conjugate", &Nz::Quaterniond::Conjugate);
|
|
||||||
quaternion.BindMethod("DotProduct", &Nz::Quaterniond::DotProduct);
|
|
||||||
quaternion.BindMethod("GetConjugate", &Nz::Quaterniond::GetConjugate);
|
|
||||||
quaternion.BindMethod("GetInverse", &Nz::Quaterniond::GetInverse);
|
|
||||||
|
|
||||||
quaternion.BindMethod("Inverse", &Nz::Quaterniond::Inverse);
|
|
||||||
quaternion.BindMethod("Magnitude", &Nz::Quaterniond::Magnitude);
|
|
||||||
|
|
||||||
quaternion.BindMethod("SquaredMagnitude", &Nz::Quaterniond::SquaredMagnitude);
|
|
||||||
quaternion.BindMethod("ToEulerAngles", &Nz::Quaterniond::ToEulerAngles);
|
|
||||||
|
|
||||||
quaternion.BindMethod("__tostring", &Nz::Quaterniond::ToString);
|
|
||||||
|
|
||||||
quaternion.BindStaticMethod("Lerp", &Nz::Quaterniond::Lerp);
|
|
||||||
quaternion.BindStaticMethod("RotationBetween", &Nz::Quaterniond::RotationBetween);
|
|
||||||
quaternion.BindStaticMethod("Slerp", &Nz::Quaterniond::Slerp);
|
|
||||||
|
|
||||||
quaternion.BindMethod("GetNormal", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
double length;
|
|
||||||
|
|
||||||
lua.Push(instance.GetNormal(&length));
|
|
||||||
lua.Push(length);
|
|
||||||
|
|
||||||
return 2;
|
|
||||||
});
|
|
||||||
|
|
||||||
quaternion.BindMethod("Normalize", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
double length;
|
|
||||||
|
|
||||||
instance.Normalize(&length);
|
|
||||||
lua.Push(1); //< instance
|
|
||||||
lua.Push(length);
|
|
||||||
|
|
||||||
return 2;
|
|
||||||
});
|
|
||||||
|
|
||||||
quaternion.BindStaticMethod("Normalize", [] (Nz::LuaInstance& instance) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 1;
|
|
||||||
Nz::Quaterniond quat = instance.Check<Nz::Quaterniond>(&argIndex);
|
|
||||||
|
|
||||||
double length;
|
|
||||||
|
|
||||||
instance.Push(Nz::Quaterniond::Normalize(quat, &length));
|
|
||||||
instance.Push(length);
|
|
||||||
|
|
||||||
return 2;
|
|
||||||
});
|
|
||||||
|
|
||||||
quaternion.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* wxyz = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
if (length != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
switch (wxyz[0])
|
|
||||||
{
|
|
||||||
case 'w':
|
|
||||||
lua.Push(instance.w);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'x':
|
|
||||||
lua.Push(instance.x);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
lua.Push(instance.y);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'z':
|
|
||||||
lua.Push(instance.z);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* wxyz = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
if (length != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
double value = lua.CheckNumber(3);
|
|
||||||
|
|
||||||
switch (wxyz[0])
|
|
||||||
{
|
|
||||||
case 'w':
|
|
||||||
instance.w = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'x':
|
|
||||||
instance.x = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
instance.y = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'z':
|
|
||||||
instance.z = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::Vector2 **********************************/
|
|
||||||
vector2d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(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<Nz::Vector2d*>(lua.ToUserdata(1)));
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for Vector2 constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
vector2d.BindMethod("__tostring", &Nz::Vector2d::ToString);
|
|
||||||
|
|
||||||
vector2d.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
|
||||||
{
|
|
||||||
switch (lua.GetType(2))
|
|
||||||
{
|
|
||||||
case Nz::LuaType_Number:
|
|
||||||
{
|
|
||||||
long long index = lua.CheckInteger(2);
|
|
||||||
if (index < 1 || index > 2)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
lua.Push(instance[index - 1]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Nz::LuaType_String:
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* xy = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
if (length != 1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
switch (xy[0])
|
|
||||||
{
|
|
||||||
case 'x':
|
|
||||||
lua.Push(instance.x);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
lua.Push(instance.y);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
vector2d.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
|
||||||
{
|
|
||||||
switch (lua.GetType(2))
|
|
||||||
{
|
|
||||||
case Nz::LuaType_Number:
|
|
||||||
{
|
|
||||||
long long index = lua.CheckInteger(2);
|
|
||||||
if (index < 1 || index > 2)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
instance[index - 1] = lua.CheckNumber(3);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Nz::LuaType_String:
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* xy = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
if (length != 1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
double value = lua.CheckNumber(3);
|
|
||||||
|
|
||||||
switch (xy[0])
|
|
||||||
{
|
|
||||||
case 'x':
|
|
||||||
instance.x = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
instance.y = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::Vector3 **********************************/
|
|
||||||
vector3d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(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<Nz::Vector2d*>(lua.ToUserdata(1)));
|
|
||||||
else if (lua.IsOfType(1, "Vector3"))
|
|
||||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector3d*>(lua.ToUserdata(1)));
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
|
||||||
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(2, "Vector2")));
|
|
||||||
else if (lua.IsOfType(1, "Vector2"))
|
|
||||||
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)), lua.CheckNumber(2));
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
vector3d.BindMethod("__tostring", &Nz::Vector3d::ToString);
|
|
||||||
|
|
||||||
vector3d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
|
||||||
{
|
|
||||||
switch (lua.GetType(2))
|
|
||||||
{
|
|
||||||
case Nz::LuaType_Number:
|
|
||||||
{
|
|
||||||
long long index = lua.CheckInteger(2);
|
|
||||||
if (index < 1 || index > 3)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
lua.Push(instance[index - 1]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Nz::LuaType_String:
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* xyz = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
if (length != 1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
switch (xyz[0])
|
|
||||||
{
|
|
||||||
case 'x':
|
|
||||||
lua.Push(instance.x);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
lua.Push(instance.y);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'z':
|
|
||||||
lua.Push(instance.z);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
vector3d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
|
||||||
{
|
|
||||||
switch (lua.GetType(2))
|
|
||||||
{
|
|
||||||
case Nz::LuaType_Number:
|
|
||||||
{
|
|
||||||
long long index = lua.CheckInteger(2);
|
|
||||||
if (index < 1 || index > 3)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
instance[index - 1] = lua.CheckNumber(3);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Nz::LuaType_String:
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* xyz = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
if (length != 1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
double value = lua.CheckNumber(3);
|
|
||||||
|
|
||||||
switch (xyz[0])
|
|
||||||
{
|
|
||||||
case 'x':
|
|
||||||
instance.x = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'y':
|
|
||||||
instance.y = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'z':
|
|
||||||
instance.z = value;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Registers the classes that will be used by the Lua instance
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the Math classes
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::RegisterMath(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
eulerAngles.Register(instance);
|
|
||||||
matrix4d.Register(instance);
|
|
||||||
quaternion.Register(instance);
|
|
||||||
rect.Register(instance);
|
|
||||||
vector2d.Register(instance);
|
|
||||||
vector3d.Register(instance);
|
|
||||||
|
|
||||||
quaternion.PushGlobalTable(instance);
|
|
||||||
{
|
|
||||||
instance.PushField("Identity", Nz::Quaterniond::Identity());
|
|
||||||
instance.PushField("Zero", Nz::Quaterniond::Zero());
|
|
||||||
}
|
|
||||||
instance.Pop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
|
||||||
// This file is part of the "Nazara Development Kit"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds Renderer module to Lua
|
|
||||||
*/
|
|
||||||
void LuaBinding::BindRenderer()
|
|
||||||
{
|
|
||||||
/*********************************** Nz::Texture ***********************************/
|
|
||||||
texture.Inherit<Nz::AbstractImageRef>(abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef*
|
|
||||||
{
|
|
||||||
return reinterpret_cast<Nz::AbstractImageRef*>(textureRef); //TODO: Make a ObjectRefCast
|
|
||||||
});
|
|
||||||
|
|
||||||
texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* instance, std::size_t /*argumentCount*/)
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Texture::New());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
texture.BindMethod("Create", &Nz::Texture::Create, static_cast<Nz::UInt8>(1), 1U);
|
|
||||||
texture.BindMethod("Destroy", &Nz::Texture::Destroy);
|
|
||||||
|
|
||||||
//texture.BindMethod("Download", &Nz::Texture::Download);
|
|
||||||
|
|
||||||
texture.BindMethod("EnableMipmapping", &Nz::Texture::EnableMipmapping);
|
|
||||||
texture.BindMethod("EnsureMipmapsUpdate", &Nz::Texture::EnsureMipmapsUpdate);
|
|
||||||
texture.BindMethod("HasMipmaps", &Nz::Texture::HasMipmaps);
|
|
||||||
texture.BindMethod("InvalidateMipmaps", &Nz::Texture::InvalidateMipmaps);
|
|
||||||
texture.BindMethod("IsValid", &Nz::Texture::IsValid);
|
|
||||||
|
|
||||||
texture.BindMethod("LoadFromFile", &Nz::Texture::LoadFromFile, true, Nz::ImageParams());
|
|
||||||
//bool LoadFromImage(const Image& image, bool generateMipmaps = true);
|
|
||||||
//bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
|
||||||
//bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
|
||||||
|
|
||||||
texture.BindMethod("LoadArrayFromFile", &Nz::Texture::LoadArrayFromFile, Nz::Vector2ui(2, 2), true, Nz::ImageParams());
|
|
||||||
//bool LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
|
||||||
//bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
|
||||||
//bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
|
||||||
|
|
||||||
//bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
|
||||||
//bool LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams());
|
|
||||||
//bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
|
||||||
//bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
|
||||||
|
|
||||||
texture.BindMethod("LoadFaceFromFile", &Nz::Texture::LoadFaceFromFile, Nz::ImageParams());
|
|
||||||
//bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
|
||||||
//bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams());
|
|
||||||
|
|
||||||
texture.BindMethod("SaveToFile", &Nz::Texture::SaveToFile, Nz::ImageParams());
|
|
||||||
//bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams());
|
|
||||||
|
|
||||||
texture.BindMethod("SetMipmapRange", &Nz::Texture::SetMipmapRange);
|
|
||||||
|
|
||||||
texture.BindStaticMethod("IsFormatSupported", &Nz::Texture::IsFormatSupported);
|
|
||||||
texture.BindStaticMethod("IsMipmappingSupported", &Nz::Texture::IsMipmappingSupported);
|
|
||||||
texture.BindStaticMethod("IsTypeSupported", &Nz::Texture::IsTypeSupported);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Registers the classes that will be used by the Lua instance
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the Renderer classes
|
|
||||||
*/
|
|
||||||
void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
texture.Register(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,320 +0,0 @@
|
||||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
|
||||||
// This file is part of the "Nazara Development Kit"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds SDK module to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::BindSDK()
|
|
||||||
{
|
|
||||||
/*********************************** Ndk::Application **********************************/
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
//application.SetMethod("AddWindow", &Application::AddWindow);
|
|
||||||
|
|
||||||
application.BindMethod("EnableConsole", &Application::EnableConsole);
|
|
||||||
application.BindMethod("EnableFPSCounter", &Application::EnableFPSCounter);
|
|
||||||
|
|
||||||
application.BindMethod("IsConsoleEnabled", &Application::IsConsoleEnabled);
|
|
||||||
application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
application.BindMethod("AddWorld", [] (Nz::LuaInstance& lua, Application* instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
lua.Push(instance->AddWorld().CreateHandle());
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
application.BindMethod("GetUpdateTime", &Application::GetUpdateTime);
|
|
||||||
application.BindMethod("Quit", &Application::Quit);
|
|
||||||
|
|
||||||
/*********************************** Ndk::Console **********************************/
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
console.Inherit<Nz::Node>(node, [] (ConsoleHandle* handle) -> Nz::Node*
|
|
||||||
{
|
|
||||||
return handle->GetObject();
|
|
||||||
});
|
|
||||||
|
|
||||||
console.BindMethod("AddLine", &Console::AddLine, Nz::Color::White);
|
|
||||||
console.BindMethod("Clear", &Console::Clear);
|
|
||||||
console.BindMethod("GetCharacterSize", &Console::GetCharacterSize);
|
|
||||||
console.BindMethod("GetHistory", &Console::GetHistory);
|
|
||||||
console.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground);
|
|
||||||
console.BindMethod("GetInput", &Console::GetInput);
|
|
||||||
console.BindMethod("GetInputBackground", &Console::GetInputBackground);
|
|
||||||
console.BindMethod("GetSize", &Console::GetSize);
|
|
||||||
console.BindMethod("GetTextFont", &Console::GetTextFont);
|
|
||||||
|
|
||||||
console.BindMethod("IsVisible", &Console::IsVisible);
|
|
||||||
|
|
||||||
console.BindMethod("SendCharacter", &Console::SendCharacter);
|
|
||||||
//consoleClass.SetMethod("SendEvent", &Console::SendEvent);
|
|
||||||
|
|
||||||
console.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
|
|
||||||
console.BindMethod("SetSize", &Console::SetSize);
|
|
||||||
console.BindMethod("SetTextFont", &Console::SetTextFont);
|
|
||||||
|
|
||||||
console.BindMethod("Show", &Console::Show, true);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*********************************** Ndk::Entity **********************************/
|
|
||||||
entity.BindMethod("Enable", &Entity::Enable, true);
|
|
||||||
entity.BindMethod("GetId", &Entity::GetId);
|
|
||||||
entity.BindMethod("GetWorld", &Entity::GetWorld);
|
|
||||||
entity.BindMethod("Kill", &Entity::Kill);
|
|
||||||
entity.BindMethod("IsEnabled", &Entity::IsEnabled);
|
|
||||||
entity.BindMethod("IsValid", &Entity::IsValid);
|
|
||||||
entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
|
|
||||||
entity.BindMethod("__tostring", &EntityHandle::ToString);
|
|
||||||
|
|
||||||
entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
ComponentBinding* binding = QueryComponentIndex(instance);
|
|
||||||
|
|
||||||
return binding->adder(instance, handle);
|
|
||||||
});
|
|
||||||
|
|
||||||
entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
ComponentBinding* binding = QueryComponentIndex(instance);
|
|
||||||
|
|
||||||
return binding->getter(instance, handle->GetComponent(binding->index));
|
|
||||||
});
|
|
||||||
|
|
||||||
entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
ComponentBinding* binding = QueryComponentIndex(instance);
|
|
||||||
|
|
||||||
handle->RemoveComponent(binding->index);
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Ndk::NodeComponent **********************************/
|
|
||||||
nodeComponent.Inherit<Nz::Node>(node, [] (NodeComponentHandle* handle) -> Nz::Node*
|
|
||||||
{
|
|
||||||
return handle->GetObject();
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Ndk::VelocityComponent **********************************/
|
|
||||||
velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* member = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
if (std::strcmp(member, "Linear") == 0)
|
|
||||||
{
|
|
||||||
lua.Push(instance->linearVelocity);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
|
||||||
{
|
|
||||||
std::size_t length;
|
|
||||||
const char* member = lua.CheckString(2, &length);
|
|
||||||
|
|
||||||
int argIndex = 3;
|
|
||||||
if (std::strcmp(member, "Linear") == 0)
|
|
||||||
{
|
|
||||||
instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Ndk::World **********************************/
|
|
||||||
world.BindMethod("CreateEntity", &World::CreateEntity);
|
|
||||||
world.BindMethod("CreateEntities", &World::CreateEntities);
|
|
||||||
world.BindMethod("Clear", &World::Clear);
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
/*********************************** Ndk::CameraComponent **********************************/
|
|
||||||
cameraComponent.Inherit<Nz::AbstractViewer>(abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer*
|
|
||||||
{
|
|
||||||
return handle->GetObject();
|
|
||||||
});
|
|
||||||
|
|
||||||
cameraComponent.BindMethod("GetFOV", &Ndk::CameraComponent::GetFOV);
|
|
||||||
cameraComponent.BindMethod("GetLayer", &Ndk::CameraComponent::GetLayer);
|
|
||||||
|
|
||||||
cameraComponent.BindMethod("SetFOV", &Ndk::CameraComponent::SetFOV);
|
|
||||||
cameraComponent.BindMethod("SetLayer", &Ndk::CameraComponent::SetLayer);
|
|
||||||
cameraComponent.BindMethod("SetProjectionType", &Ndk::CameraComponent::SetProjectionType);
|
|
||||||
cameraComponent.BindMethod("SetSize", (void(Ndk::CameraComponent::*)(const Nz::Vector2f&)) &Ndk::CameraComponent::SetSize);
|
|
||||||
//cameraComponent.BindMethod("SetTarget", &Ndk::CameraComponent::SetTarget);
|
|
||||||
cameraComponent.BindMethod("SetTargetRegion", &Ndk::CameraComponent::SetTargetRegion);
|
|
||||||
cameraComponent.BindMethod("SetViewport", &Ndk::CameraComponent::SetViewport);
|
|
||||||
cameraComponent.BindMethod("SetZFar", &Ndk::CameraComponent::SetZFar);
|
|
||||||
cameraComponent.BindMethod("SetZNear", &Ndk::CameraComponent::SetZNear);
|
|
||||||
|
|
||||||
/*********************************** Ndk::GraphicsComponent **********************************/
|
|
||||||
graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
|
||||||
void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
|
|
||||||
*/
|
|
||||||
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
|
||||||
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
instance->Attach(lua.Check<Nz::InstancedRenderableRef>(&argIndex));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
|
||||||
|
|
||||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
|
||||||
{
|
|
||||||
int renderOrder = lua.Check<int>(&argIndex);
|
|
||||||
|
|
||||||
instance->Attach(renderable, renderOrder);
|
|
||||||
}
|
|
||||||
else if (lua.IsOfType(argIndex, "Matrix4"))
|
|
||||||
{
|
|
||||||
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
|
||||||
|
|
||||||
instance->Attach(renderable, localMatrix);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
|
||||||
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
|
||||||
int renderOrder = lua.Check<int>(&argIndex);
|
|
||||||
|
|
||||||
instance->Attach(renderable, localMatrix, renderOrder);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method GetMemoryUsage");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// Components functions
|
|
||||||
m_componentBinding.resize(BaseComponent::GetMaxComponentIndex());
|
|
||||||
|
|
||||||
BindComponent<NodeComponent>("Node");
|
|
||||||
BindComponent<VelocityComponent>("Velocity");
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
BindComponent<CameraComponent>("Camera");
|
|
||||||
BindComponent<GraphicsComponent>("Graphics");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Registers the classes that will be used by the Lua instance
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the SDK classes
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::RegisterSDK(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
// Classes
|
|
||||||
application.Register(instance);
|
|
||||||
entity.Register(instance);
|
|
||||||
nodeComponent.Register(instance);
|
|
||||||
velocityComponent.Register(instance);
|
|
||||||
world.Register(instance);
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
cameraComponent.Register(instance);
|
|
||||||
console.Register(instance);
|
|
||||||
graphicsComponent.Register(instance);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Enums
|
|
||||||
|
|
||||||
// ComponentType (fake enumeration to expose component indexes)
|
|
||||||
instance.PushTable(0, m_componentBinding.size());
|
|
||||||
{
|
|
||||||
for (const ComponentBinding& entry : m_componentBinding)
|
|
||||||
{
|
|
||||||
if (entry.name.IsEmpty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
instance.PushField(entry.name, entry.index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
instance.SetGlobal("ComponentType");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Gets the index of the component
|
|
||||||
* \return A pointer to the binding linked to a component
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the component
|
|
||||||
* \param argIndex Index of the component
|
|
||||||
*/
|
|
||||||
|
|
||||||
LuaBinding::ComponentBinding* LuaBinding::QueryComponentIndex(Nz::LuaInstance& instance, int argIndex)
|
|
||||||
{
|
|
||||||
switch (instance.GetType(argIndex))
|
|
||||||
{
|
|
||||||
case Nz::LuaType_Number:
|
|
||||||
{
|
|
||||||
ComponentIndex componentIndex = instance.Check<ComponentIndex>(&argIndex);
|
|
||||||
if (componentIndex > m_componentBinding.size())
|
|
||||||
{
|
|
||||||
instance.Error("Invalid component index");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
|
||||||
if (binding.name.IsEmpty())
|
|
||||||
{
|
|
||||||
instance.Error("Invalid component index");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return &binding;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Nz::LuaType_String:
|
|
||||||
{
|
|
||||||
const char* key = instance.CheckString(argIndex);
|
|
||||||
auto it = m_componentBindingByName.find(key);
|
|
||||||
if (it == m_componentBindingByName.end())
|
|
||||||
{
|
|
||||||
instance.Error("Invalid component name");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return &m_componentBinding[it->second];
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.Error("Invalid component index at #" + Nz::String::Number(argIndex));
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,417 +0,0 @@
|
||||||
// This file is part of the "Nazara Development Kit"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds Utility module to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::BindUtility()
|
|
||||||
{
|
|
||||||
/*********************************** Nz::AbstractImage **********************************/
|
|
||||||
abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
|
||||||
abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
|
||||||
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
|
||||||
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
|
||||||
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
|
||||||
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
|
||||||
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
|
||||||
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
|
|
||||||
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
|
||||||
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
|
||||||
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
|
||||||
|
|
||||||
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
return lua.Push(instance->GetMemoryUsage());
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&argIndex));
|
|
||||||
|
|
||||||
return lua.Push(instance->GetMemoryUsage(level));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method GetMemoryUsage");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 6U);
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
std::size_t bufferSize = 0;
|
|
||||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(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<unsigned int>(&argIndex, 0);
|
|
||||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&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<Nz::Boxui>(&argIndex);
|
|
||||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&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<Nz::Rectui>(&argIndex);
|
|
||||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&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.SetConstructor([] (Nz::LuaInstance& /*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::LuaInstance& lua, Nz::FontRef& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
lua.Push(instance->GetCachedGlyphCount());
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
unsigned int characterSize = lua.Check<unsigned int>(&argIndex);
|
|
||||||
Nz::UInt32 style = lua.Check<Nz::UInt32>(&argIndex);
|
|
||||||
|
|
||||||
lua.Push(instance->GetCachedGlyphCount(characterSize, style));
|
|
||||||
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::UInt32, const Nz::String&) const) &Nz::Font::Precache);
|
|
||||||
|
|
||||||
font.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams());
|
|
||||||
|
|
||||||
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("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder);
|
|
||||||
font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize);
|
|
||||||
|
|
||||||
/*********************************** Nz::Keyboard **********************************/
|
|
||||||
keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName);
|
|
||||||
keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed);
|
|
||||||
|
|
||||||
/*********************************** Nz::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::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
|
||||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
|
||||||
instance.Move(offset, coordSys);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
|
||||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
|
||||||
instance.Rotate(rotation, coordSys);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
|
||||||
instance.Scale(lua.Check<float>(&argIndex));
|
|
||||||
else
|
|
||||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method Scale");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
|
||||||
{
|
|
||||||
float scale = lua.Check<float>(&argIndex);
|
|
||||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
|
||||||
instance.SetScale(scale, coordSys);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
instance.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
{
|
|
||||||
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
|
||||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
|
||||||
|
|
||||||
instance.SetScale(scale, coordSys);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method SetScale");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
|
||||||
instance.SetInitialScale(lua.Check<float>(&argIndex));
|
|
||||||
else
|
|
||||||
instance.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
instance.SetInitialScale(lua.Check<Nz::Vector3f>(&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::RegisterUtility(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
abstractImage.Register(instance);
|
|
||||||
font.Register(instance);
|
|
||||||
keyboard.Register(instance);
|
|
||||||
node.Register(instance);
|
|
||||||
|
|
||||||
keyboard.PushGlobalTable(instance);
|
|
||||||
{
|
|
||||||
instance.PushField("Undefined", Nz::Keyboard::Undefined);
|
|
||||||
|
|
||||||
// A-Z
|
|
||||||
for (std::size_t i = 0; i < 26; ++i)
|
|
||||||
instance.PushField(Nz::String('A' + char(i)), Nz::Keyboard::A + i);
|
|
||||||
|
|
||||||
// Numerical
|
|
||||||
for (std::size_t i = 0; i < 10; ++i)
|
|
||||||
{
|
|
||||||
instance.PushField("Num" + Nz::String::Number(i), Nz::Keyboard::Num0 + i);
|
|
||||||
instance.PushField("Numpad" + Nz::String::Number(i), Nz::Keyboard::Numpad0 + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// F1-F15
|
|
||||||
for (std::size_t i = 0; i < 15; ++i)
|
|
||||||
instance.PushField('F' + Nz::String::Number(i+1), Nz::Keyboard::F1 + i);
|
|
||||||
|
|
||||||
// And all the others...
|
|
||||||
instance.PushField("Down", Nz::Keyboard::Down);
|
|
||||||
instance.PushField("Left", Nz::Keyboard::Left);
|
|
||||||
instance.PushField("Right", Nz::Keyboard::Right);
|
|
||||||
instance.PushField("Up", Nz::Keyboard::Up);
|
|
||||||
|
|
||||||
instance.PushField("Add", Nz::Keyboard::Add);
|
|
||||||
instance.PushField("Decimal", Nz::Keyboard::Decimal);
|
|
||||||
instance.PushField("Divide", Nz::Keyboard::Divide);
|
|
||||||
instance.PushField("Multiply", Nz::Keyboard::Multiply);
|
|
||||||
instance.PushField("Subtract", Nz::Keyboard::Subtract);
|
|
||||||
|
|
||||||
instance.PushField("Backslash", Nz::Keyboard::Backslash);
|
|
||||||
instance.PushField("Backspace", Nz::Keyboard::Backspace);
|
|
||||||
instance.PushField("Clear", Nz::Keyboard::Clear);
|
|
||||||
instance.PushField("Comma", Nz::Keyboard::Comma);
|
|
||||||
instance.PushField("Dash", Nz::Keyboard::Dash);
|
|
||||||
instance.PushField("Delete", Nz::Keyboard::Delete);
|
|
||||||
instance.PushField("End", Nz::Keyboard::End);
|
|
||||||
instance.PushField("Equal", Nz::Keyboard::Equal);
|
|
||||||
instance.PushField("Escape", Nz::Keyboard::Escape);
|
|
||||||
instance.PushField("Home", Nz::Keyboard::Home);
|
|
||||||
instance.PushField("Insert", Nz::Keyboard::Insert);
|
|
||||||
instance.PushField("LAlt", Nz::Keyboard::LAlt);
|
|
||||||
instance.PushField("LBracket", Nz::Keyboard::LBracket);
|
|
||||||
instance.PushField("LControl", Nz::Keyboard::LControl);
|
|
||||||
instance.PushField("LShift", Nz::Keyboard::LShift);
|
|
||||||
instance.PushField("LSystem", Nz::Keyboard::LSystem);
|
|
||||||
instance.PushField("PageDown", Nz::Keyboard::PageDown);
|
|
||||||
instance.PushField("PageUp", Nz::Keyboard::PageUp);
|
|
||||||
instance.PushField("Pause", Nz::Keyboard::Pause);
|
|
||||||
instance.PushField("Period", Nz::Keyboard::Period);
|
|
||||||
instance.PushField("Print", Nz::Keyboard::Print);
|
|
||||||
instance.PushField("PrintScreen", Nz::Keyboard::PrintScreen);
|
|
||||||
instance.PushField("Quote", Nz::Keyboard::Quote);
|
|
||||||
instance.PushField("RAlt", Nz::Keyboard::RAlt);
|
|
||||||
instance.PushField("RBracket", Nz::Keyboard::RBracket);
|
|
||||||
instance.PushField("RControl", Nz::Keyboard::RControl);
|
|
||||||
instance.PushField("Return", Nz::Keyboard::Return);
|
|
||||||
instance.PushField("RShift", Nz::Keyboard::RShift);
|
|
||||||
instance.PushField("RSystem", Nz::Keyboard::RSystem);
|
|
||||||
instance.PushField("Semicolon", Nz::Keyboard::Semicolon);
|
|
||||||
instance.PushField("Slash", Nz::Keyboard::Slash);
|
|
||||||
instance.PushField("Space", Nz::Keyboard::Space);
|
|
||||||
instance.PushField("Tab", Nz::Keyboard::Tab);
|
|
||||||
instance.PushField("Tilde", Nz::Keyboard::Tilde);
|
|
||||||
instance.PushField("Browser_Back", Nz::Keyboard::Browser_Back);
|
|
||||||
instance.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites);
|
|
||||||
instance.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward);
|
|
||||||
instance.PushField("Browser_Home", Nz::Keyboard::Browser_Home);
|
|
||||||
instance.PushField("Browser_Refresh", Nz::Keyboard::Browser_Refresh);
|
|
||||||
instance.PushField("Browser_Search", Nz::Keyboard::Browser_Search);
|
|
||||||
instance.PushField("Browser_Stop", Nz::Keyboard::Browser_Stop);
|
|
||||||
instance.PushField("Media_Next", Nz::Keyboard::Media_Next);
|
|
||||||
instance.PushField("Media_Play", Nz::Keyboard::Media_Play);
|
|
||||||
instance.PushField("Media_Previous", Nz::Keyboard::Media_Previous);
|
|
||||||
instance.PushField("Media_Stop", Nz::Keyboard::Media_Stop);
|
|
||||||
instance.PushField("Volume_Down", Nz::Keyboard::Volume_Down);
|
|
||||||
instance.PushField("Volume_Mute", Nz::Keyboard::Volume_Mute);
|
|
||||||
instance.PushField("Volume_Up", Nz::Keyboard::Volume_Up);
|
|
||||||
instance.PushField("CapsLock", Nz::Keyboard::CapsLock);
|
|
||||||
instance.PushField("NumLock", Nz::Keyboard::NumLock);
|
|
||||||
instance.PushField("ScrollLock", Nz::Keyboard::ScrollLock);
|
|
||||||
}
|
|
||||||
instance.Pop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -96,7 +96,7 @@ int main()
|
||||||
|
|
||||||
// Les UVs de ce fichier sont retournées (repère OpenGL, origine coin bas-gauche) par rapport à ce que le moteur attend (haut-gauche)
|
// Les UVs de ce fichier sont retournées (repère OpenGL, origine coin bas-gauche) par rapport à ce que le moteur attend (haut-gauche)
|
||||||
// Nous devons donc indiquer au moteur de les retourner lors du chargement
|
// Nous devons donc indiquer au moteur de les retourner lors du chargement
|
||||||
params.mesh.flipUVs = true;
|
params.mesh.texCoordScale.Set(1.f, -1.f);
|
||||||
|
|
||||||
// Nazara va par défaut optimiser les modèles pour un rendu plus rapide, cela peut prendre du temps et n'est pas nécessaire ici
|
// Nazara va par défaut optimiser les modèles pour un rendu plus rapide, cela peut prendre du temps et n'est pas nécessaire ici
|
||||||
params.mesh.optimizeIndexBuffers = false;
|
params.mesh.optimizeIndexBuffers = false;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
#include "Common.hpp"
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||||
|
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||||
|
#include <NDK/Systems/RenderSystem.hpp>
|
||||||
|
|
||||||
|
ParticleDemo::ParticleDemo(const Nz::String& name, const ExampleShared& exampleShared) :
|
||||||
|
m_shared(exampleShared),
|
||||||
|
m_index(s_demoIndex++),
|
||||||
|
m_name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleDemo::Enter(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
m_shared.demoName->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_index+1) + " - " + m_name, 48));
|
||||||
|
m_fpsCounter = 0;
|
||||||
|
m_updateClock.Restart();
|
||||||
|
|
||||||
|
Ndk::RenderSystem& renderSystem2D = m_shared.world2D->GetSystem<Ndk::RenderSystem>();
|
||||||
|
Ndk::RenderSystem& renderSystem3D = m_shared.world3D->GetSystem<Ndk::RenderSystem>();
|
||||||
|
m_oldBackground2D = renderSystem2D.GetDefaultBackground();
|
||||||
|
m_oldBackground3D = renderSystem3D.GetDefaultBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleDemo::Leave(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
m_shared.world2D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(m_oldBackground2D);
|
||||||
|
m_shared.world3D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(m_oldBackground3D);
|
||||||
|
|
||||||
|
m_entities.clear();
|
||||||
|
m_particleGroups.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParticleDemo::Update(Ndk::StateMachine& fsm, float elapsedTime)
|
||||||
|
{
|
||||||
|
m_fpsCounter++;
|
||||||
|
if (m_updateClock.GetMilliseconds() > 1000)
|
||||||
|
{
|
||||||
|
m_updateClock.Restart();
|
||||||
|
|
||||||
|
m_shared.fpsCount->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_fpsCounter) + " FPS", 24));
|
||||||
|
m_fpsCounter = 0;
|
||||||
|
|
||||||
|
unsigned int particleCount = 0;
|
||||||
|
for (const Ndk::EntityHandle& entity : m_particleGroups)
|
||||||
|
{
|
||||||
|
const Ndk::ParticleGroupComponent& group = entity->GetComponent<Ndk::ParticleGroupComponent>();
|
||||||
|
particleCount += group.GetParticleCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_shared.particleCount->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(particleCount) + " particles", 36));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleDemo::RegisterEntity(const Ndk::EntityHandle& entity)
|
||||||
|
{
|
||||||
|
m_entities.emplace_back(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleDemo::RegisterParticleGroup(const Ndk::EntityHandle& entity)
|
||||||
|
{
|
||||||
|
NazaraAssert(entity->HasComponent<Ndk::ParticleGroupComponent>(), "Must have particle group component");
|
||||||
|
|
||||||
|
m_particleGroups.emplace_back(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t ParticleDemo::s_demoIndex = 0;
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_EXAMPLES_PARTICLES_COMMON_HPP
|
||||||
|
#define NAZARA_EXAMPLES_PARTICLES_COMMON_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Clock.hpp>
|
||||||
|
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||||
|
#include <Nazara/Graphics/TextSprite.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||||
|
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||||
|
#include <NDK/EntityOwner.hpp>
|
||||||
|
#include <NDK/StateMachine.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <random>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class ParticleDemo;
|
||||||
|
|
||||||
|
struct ExampleShared
|
||||||
|
{
|
||||||
|
mutable std::mt19937 randomGen;
|
||||||
|
std::vector<std::shared_ptr<ParticleDemo>> demos;
|
||||||
|
Nz::RenderWindow* target;
|
||||||
|
Nz::TextSpriteRef demoName;
|
||||||
|
Nz::TextSpriteRef fpsCount;
|
||||||
|
Nz::TextSpriteRef particleCount;
|
||||||
|
Ndk::EntityHandle viewer2D;
|
||||||
|
Ndk::EntityHandle viewer3D;
|
||||||
|
Ndk::WorldHandle world2D;
|
||||||
|
Ndk::WorldHandle world3D;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ParticleDemo : public Ndk::State
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ParticleDemo(const Nz::String& name, const ExampleShared& exampleShared);
|
||||||
|
~ParticleDemo() = default;
|
||||||
|
|
||||||
|
void Enter(Ndk::StateMachine& fsm) override;
|
||||||
|
void Leave(Ndk::StateMachine& fsm) override;
|
||||||
|
|
||||||
|
bool Update(Ndk::StateMachine& fsm, float elapsedTime) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const ExampleShared& m_shared;
|
||||||
|
|
||||||
|
void RegisterEntity(const Ndk::EntityHandle& entity);
|
||||||
|
void RegisterParticleGroup(const Ndk::EntityHandle& entity);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::size_t m_index;
|
||||||
|
std::vector<Ndk::EntityOwner> m_entities;
|
||||||
|
std::vector<Ndk::EntityOwner> m_particleGroups;
|
||||||
|
Nz::BackgroundRef m_oldBackground2D;
|
||||||
|
Nz::BackgroundRef m_oldBackground3D;
|
||||||
|
Nz::Clock m_updateClock;
|
||||||
|
Nz::String m_name;
|
||||||
|
unsigned int m_fpsCounter;
|
||||||
|
|
||||||
|
static std::size_t s_demoIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_EXAMPLES_PARTICLES_COMMON_HPP
|
||||||
|
|
@ -0,0 +1,170 @@
|
||||||
|
#include "LogoDemo.hpp"
|
||||||
|
#include <Nazara/Graphics.hpp>
|
||||||
|
#include <Nazara/Utility.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/Systems.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const float duration = 10.f;
|
||||||
|
const float maxVel = 50.f;
|
||||||
|
const float pauseTime = 3.f;
|
||||||
|
const float startTime = 2.f;
|
||||||
|
const float speed = 3.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SpriteController : public Nz::ParticleController
|
||||||
|
{
|
||||||
|
void Apply(Nz::ParticleGroup& system, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) override
|
||||||
|
{
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto posPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto velPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
posPtr[i] += velPtr[i] * elapsedTime * factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool enabled = false;
|
||||||
|
float factor = 1.f;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class SpriteRenderer : public Nz::ParticleRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SpriteRenderer(Nz::MaterialRef mat) :
|
||||||
|
m_material(mat)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Render(const Nz::ParticleGroup& system, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||||
|
{
|
||||||
|
Nz::Vector2f size(1.f, 1.f);
|
||||||
|
Nz::SparsePtr<const Nz::Vector2f> sizePtr(&size, 0);
|
||||||
|
Nz::SparsePtr<const Nz::Vector2f> sinCosPtr(nullptr, 0);
|
||||||
|
|
||||||
|
renderQueue->AddBillboards(0, m_material, endId - startId + 1, mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position), sizePtr, sinCosPtr, mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Nz::MaterialRef m_material;
|
||||||
|
};
|
||||||
|
|
||||||
|
LogoExample::LogoExample(ExampleShared& sharedData) :
|
||||||
|
ParticleDemo("Logo", sharedData)
|
||||||
|
{
|
||||||
|
Nz::ImageParams params;
|
||||||
|
params.loadFormat = Nz::PixelFormatType_RGBA8;
|
||||||
|
|
||||||
|
if (!m_logo.LoadFromFile("resources/Logo.png", params))
|
||||||
|
NazaraError("Failed to load logo!");
|
||||||
|
|
||||||
|
unsigned int width = m_logo.GetWidth();
|
||||||
|
unsigned int height = m_logo.GetHeight();
|
||||||
|
m_pixels.reserve(width * height);
|
||||||
|
|
||||||
|
for (unsigned int y = 0; y < height; ++y)
|
||||||
|
{
|
||||||
|
for (unsigned int x = 0; x < width; ++x)
|
||||||
|
{
|
||||||
|
Nz::Color color = m_logo.GetPixelColor(x, y);
|
||||||
|
if (color.a == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PixelData data;
|
||||||
|
data.pos.Set(x, y);
|
||||||
|
data.color = color;
|
||||||
|
|
||||||
|
m_pixels.push_back(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Nz::MaterialRef material = Nz::Material::New();
|
||||||
|
material->EnableBlending(true);
|
||||||
|
material->EnableDepthWrite(false);
|
||||||
|
material->EnableFaceCulling(false);
|
||||||
|
material->SetDstBlend(Nz::BlendFunc_InvSrcAlpha);
|
||||||
|
material->SetSrcBlend(Nz::BlendFunc_SrcAlpha);
|
||||||
|
|
||||||
|
m_controller = new SpriteController;
|
||||||
|
m_renderer = new SpriteRenderer(std::move(material));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogoExample::Enter(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
ParticleDemo::Enter(fsm);
|
||||||
|
|
||||||
|
m_shared.world3D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(nullptr);
|
||||||
|
|
||||||
|
Nz::TextureRef backgroundTexture = Nz::Texture::New();
|
||||||
|
if (backgroundTexture->LoadFromFile("resources/stars-background.jpg"))
|
||||||
|
m_shared.world2D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::TextureBackground::New(std::move(backgroundTexture)));
|
||||||
|
|
||||||
|
Ndk::EntityHandle particleGroupEntity = m_shared.world2D->CreateEntity();
|
||||||
|
Ndk::ParticleGroupComponent& particleGroup = particleGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(m_pixels.size(), Nz::ParticleLayout_Sprite);
|
||||||
|
RegisterParticleGroup(particleGroupEntity);
|
||||||
|
|
||||||
|
particleGroup.AddController(m_controller);
|
||||||
|
particleGroup.SetRenderer(m_renderer);
|
||||||
|
|
||||||
|
m_particles = static_cast<Nz::ParticleStruct_Sprite*>(particleGroup.CreateParticles(m_pixels.size()));
|
||||||
|
ResetParticles(-duration * (speed / 2.f));
|
||||||
|
|
||||||
|
m_accumulator = pauseTime + duration;
|
||||||
|
m_totalAccumulator = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogoExample::Leave(Ndk::StateMachine & fsm)
|
||||||
|
{
|
||||||
|
ParticleDemo::Leave(fsm);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LogoExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
|
||||||
|
{
|
||||||
|
if (!ParticleDemo::Update(fsm, elapsedTime))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_totalAccumulator += elapsedTime;
|
||||||
|
if (m_totalAccumulator <= startTime)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
m_accumulator += elapsedTime;
|
||||||
|
|
||||||
|
SpriteController* controller = static_cast<SpriteController*>(m_controller.Get());
|
||||||
|
if (m_accumulator > pauseTime + 2.f * duration)
|
||||||
|
{
|
||||||
|
ResetParticles(0.f);
|
||||||
|
m_accumulator = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
controller->enabled = (m_accumulator > pauseTime);
|
||||||
|
controller->factor = -speed + speed * (m_accumulator - pauseTime) / (duration);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogoExample::ResetParticles(float elapsed)
|
||||||
|
{
|
||||||
|
Nz::Vector2f center = {m_shared.target->GetWidth() / 2.f, m_shared.target->GetHeight() / 2.f};
|
||||||
|
Nz::Vector2f offset = center - Nz::Vector2f(Nz::Vector2ui(m_logo.GetSize()) / 2);
|
||||||
|
|
||||||
|
float ratio = float(m_shared.target->GetWidth()) / m_shared.target->GetHeight();
|
||||||
|
std::uniform_real_distribution<float> disX(-maxVel * ratio, maxVel * ratio);
|
||||||
|
std::uniform_real_distribution<float> disY(-maxVel, maxVel);
|
||||||
|
|
||||||
|
Nz::ParticleStruct_Sprite* sprite = m_particles;
|
||||||
|
for (PixelData& data : m_pixels)
|
||||||
|
{
|
||||||
|
sprite->color = data.color;
|
||||||
|
sprite->position = offset + Nz::Vector2f(data.pos);
|
||||||
|
sprite->rotation = 0.f;
|
||||||
|
sprite->velocity.Set(disX(m_shared.randomGen), disY(m_shared.randomGen), 0.f);
|
||||||
|
sprite->position += sprite->velocity * elapsed;
|
||||||
|
sprite++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_EXAMPLES_PARTICLES_LOGO_HPP
|
||||||
|
#define NAZARA_EXAMPLES_PARTICLES_LOGO_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
|
#include <Nazara/Graphics/ParticleStruct.hpp>
|
||||||
|
#include <NDK/State.hpp>
|
||||||
|
#include <vector>
|
||||||
|
#include "Common.hpp"
|
||||||
|
|
||||||
|
class LogoExample : public ParticleDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LogoExample(ExampleShared& sharedData);
|
||||||
|
~LogoExample() = default;
|
||||||
|
|
||||||
|
void Enter(Ndk::StateMachine& fsm) override;
|
||||||
|
void Leave(Ndk::StateMachine& fsm) override;
|
||||||
|
bool Update(Ndk::StateMachine& fsm, float elapsedTime) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ResetParticles(float elapsed);
|
||||||
|
|
||||||
|
struct PixelData
|
||||||
|
{
|
||||||
|
Nz::Vector2ui pos;
|
||||||
|
Nz::Color color;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<PixelData> m_pixels;
|
||||||
|
Nz::BackgroundRef m_oldBackground;
|
||||||
|
Nz::ParticleStruct_Sprite* m_particles;
|
||||||
|
Nz::Image m_logo;
|
||||||
|
Nz::ParticleControllerRef m_controller;
|
||||||
|
Nz::ParticleRendererRef m_renderer;
|
||||||
|
float m_accumulator;
|
||||||
|
float m_totalAccumulator;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_EXAMPLES_PARTICLES_LOGO_HPP
|
||||||
|
|
@ -0,0 +1,826 @@
|
||||||
|
#include "SpacebattleDemo.hpp"
|
||||||
|
#include <Nazara/Audio/Sound.hpp>
|
||||||
|
#include <Nazara/Core/OffsetOf.hpp>
|
||||||
|
#include <Nazara/Graphics.hpp>
|
||||||
|
#include <Nazara/Utility.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/Systems.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const float maxLaserLife = 15.f;
|
||||||
|
const float maxSmokeLife = 20.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SpaceshipComponent : public Ndk::Component<SpaceshipComponent>
|
||||||
|
{
|
||||||
|
SpaceshipComponent()
|
||||||
|
{
|
||||||
|
engineSound.SetBuffer(Nz::SoundBufferManager::Get("resources/spaceship_loop.wav"));
|
||||||
|
engineSound.EnableSpatialization(true);
|
||||||
|
engineSound.SetMinDistance(10.f);
|
||||||
|
engineSound.SetPitch(1.5f);
|
||||||
|
|
||||||
|
hitSound.SetBuffer(Nz::SoundBufferManager::Get("resources/explosion.wav"));
|
||||||
|
hitSound.EnableSpatialization(true);
|
||||||
|
hitSound.SetMinDistance(150.f);
|
||||||
|
|
||||||
|
laserSound.SetBuffer(Nz::SoundBufferManager::Get("resources/laser.wav"));
|
||||||
|
laserSound.EnableSpatialization(true);
|
||||||
|
laserSound.SetMinDistance(150.f);
|
||||||
|
laserSound.SetVolume(60.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::array<Nz::SpriteRef, 2> laserBeamSprites;
|
||||||
|
Nz::Sound engineSound;
|
||||||
|
Nz::Sound hitSound;
|
||||||
|
Nz::Sound laserSound;
|
||||||
|
Nz::UInt64 hitTime = 0;
|
||||||
|
Nz::Vector3f targetPos = Nz::Vector3f::Zero();
|
||||||
|
bool attacking = true;
|
||||||
|
|
||||||
|
static Ndk::ComponentIndex componentIndex;
|
||||||
|
};
|
||||||
|
Ndk::ComponentIndex SpaceshipComponent::componentIndex;
|
||||||
|
|
||||||
|
struct LaserBeamComponent : public Ndk::Component<LaserBeamComponent>
|
||||||
|
{
|
||||||
|
LaserBeamComponent()
|
||||||
|
{
|
||||||
|
Nz::MaterialRef laserBeamMaterial = Nz::MaterialLibrary::Get("LaserBeam");
|
||||||
|
for (Nz::Sprite& sprite : sprites)
|
||||||
|
{
|
||||||
|
sprite.SetMaterial(laserBeamMaterial);
|
||||||
|
sprite.SetOrigin(Nz::Vector2f(0.f, 0.5f));
|
||||||
|
sprite.SetTextureCoords(Nz::Rectf(0.f, 0.f, 50.f, 1.f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnAttached() override
|
||||||
|
{
|
||||||
|
auto& spaceshipCom = m_entity->GetComponent<SpaceshipComponent>();
|
||||||
|
spaceshipCom.laserSound.Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::array<Nz::Sprite, 2> sprites;
|
||||||
|
Nz::Vector3f origin = Nz::Vector3f::Zero();
|
||||||
|
float length = 1500.f;
|
||||||
|
float life = 2.f;
|
||||||
|
float width = 2.f;
|
||||||
|
|
||||||
|
static Ndk::ComponentIndex componentIndex;
|
||||||
|
};
|
||||||
|
Ndk::ComponentIndex LaserBeamComponent::componentIndex;
|
||||||
|
|
||||||
|
class LaserBeamSystem : public Ndk::System<LaserBeamSystem>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LaserBeamSystem(const ExampleShared& sharedData) :
|
||||||
|
m_sharedData(sharedData)
|
||||||
|
{
|
||||||
|
Requires<Ndk::GraphicsComponent, LaserBeamComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnEntityAdded(Ndk::Entity* entity) override
|
||||||
|
{
|
||||||
|
auto& laserComponent = entity->GetComponent<LaserBeamComponent>();
|
||||||
|
auto& gfxComponent = entity->GetComponent<Ndk::GraphicsComponent>();
|
||||||
|
|
||||||
|
for (Nz::Sprite& sprite : laserComponent.sprites)
|
||||||
|
sprite.SetSize({laserComponent.length, laserComponent.width});
|
||||||
|
|
||||||
|
gfxComponent.Attach(&laserComponent.sprites[0], Nz::Matrix4f::Transform(laserComponent.origin, Nz::EulerAnglesf(0.f, 90.f, 0.f)));
|
||||||
|
gfxComponent.Attach(&laserComponent.sprites[1], Nz::Matrix4f::Transform(laserComponent.origin, Nz::EulerAnglesf(90.f, 90.f, 0.f)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUpdate(float elapsedTime) override
|
||||||
|
{
|
||||||
|
const float scrollSpeed = 2.f;
|
||||||
|
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||||
|
{
|
||||||
|
auto& laserComponent = entity->GetComponent<LaserBeamComponent>();
|
||||||
|
for (Nz::Sprite& sprite : laserComponent.sprites)
|
||||||
|
{
|
||||||
|
Nz::Rectf rect = sprite.GetTextureCoords();
|
||||||
|
rect.x = std::fmod(rect.x - elapsedTime * scrollSpeed, rect.width);
|
||||||
|
|
||||||
|
sprite.SetTextureCoords(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Ndk::SystemIndex systemIndex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const ExampleShared& m_sharedData;
|
||||||
|
};
|
||||||
|
Ndk::SystemIndex LaserBeamSystem::systemIndex;
|
||||||
|
|
||||||
|
class SpaceshipSystem : public Ndk::System<SpaceshipSystem>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SpaceshipSystem(const ExampleShared& sharedData) :
|
||||||
|
m_sharedData(sharedData)
|
||||||
|
{
|
||||||
|
Requires<Ndk::NodeComponent, Ndk::VelocityComponent, SpaceshipComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnEntityAdded(Ndk::Entity* entity) override
|
||||||
|
{
|
||||||
|
std::uniform_real_distribution<float> pitchDis(0.8f, 1.5f);
|
||||||
|
|
||||||
|
auto& nodeComponent = entity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
auto& spaceshipComponent = entity->GetComponent<SpaceshipComponent>();
|
||||||
|
|
||||||
|
spaceshipComponent.engineSound.SetPosition(nodeComponent.GetPosition());
|
||||||
|
spaceshipComponent.engineSound.Play();
|
||||||
|
spaceshipComponent.engineSound.EnableLooping(true);
|
||||||
|
|
||||||
|
spaceshipComponent.laserSound.SetPitch(pitchDis(m_sharedData.randomGen));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUpdate(float elapsedTime) override
|
||||||
|
{
|
||||||
|
const float escapeMaxDist = 50.f;
|
||||||
|
const float speed = 200.f;
|
||||||
|
|
||||||
|
Nz::UInt64 curTime = Nz::GetElapsedMilliseconds();
|
||||||
|
std::uniform_real_distribution<float> dis(-escapeMaxDist, escapeMaxDist);
|
||||||
|
|
||||||
|
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||||
|
{
|
||||||
|
auto& nodeComponent = entity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
auto& spaceshipComponent = entity->GetComponent<SpaceshipComponent>();
|
||||||
|
auto& velocityComponent = entity->GetComponent<Ndk::VelocityComponent>();
|
||||||
|
|
||||||
|
//< I agree, I need some kind of SoundEmitterComponent
|
||||||
|
spaceshipComponent.engineSound.SetPosition(nodeComponent.GetPosition());
|
||||||
|
spaceshipComponent.engineSound.SetVelocity(velocityComponent.linearVelocity);
|
||||||
|
|
||||||
|
spaceshipComponent.hitSound.SetPosition(nodeComponent.GetPosition());
|
||||||
|
spaceshipComponent.hitSound.SetVelocity(velocityComponent.linearVelocity);
|
||||||
|
|
||||||
|
spaceshipComponent.laserSound.SetPosition(nodeComponent.GetPosition());
|
||||||
|
spaceshipComponent.laserSound.SetVelocity(velocityComponent.linearVelocity);
|
||||||
|
|
||||||
|
Nz::Vector3f targetDir = spaceshipComponent.targetPos - nodeComponent.GetPosition();
|
||||||
|
targetDir.Normalize();
|
||||||
|
|
||||||
|
Nz::Quaternionf targetRotation = Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), targetDir);
|
||||||
|
|
||||||
|
nodeComponent.SetRotation(Nz::Quaternionf::Slerp(nodeComponent.GetRotation(), targetRotation, elapsedTime * 1.5f));
|
||||||
|
|
||||||
|
Nz::Vector3f actualDir = nodeComponent.GetForward();
|
||||||
|
float sqDistance = spaceshipComponent.targetPos.SquaredDistance(nodeComponent.GetPosition());
|
||||||
|
|
||||||
|
if (spaceshipComponent.attacking)
|
||||||
|
{
|
||||||
|
float dotProduct = targetDir.DotProduct(actualDir);
|
||||||
|
if (dotProduct > 0.9f && sqDistance < (150.f * 150.f) && !entity->HasComponent<LaserBeamComponent>())
|
||||||
|
{
|
||||||
|
auto& laserBeam = entity->AddComponent<LaserBeamComponent>();
|
||||||
|
laserBeam.origin = Nz::Vector3f::Forward() * 12.f + Nz::Vector3f::Down() * 2.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sqDistance < (100.f * 100.f))
|
||||||
|
{
|
||||||
|
entity->RemoveComponent<LaserBeamComponent>();
|
||||||
|
|
||||||
|
spaceshipComponent.targetPos -= Nz::Vector3f(dis(m_sharedData.randomGen), dis(m_sharedData.randomGen), dis(m_sharedData.randomGen)) * -actualDir * escapeMaxDist / 2.f;
|
||||||
|
spaceshipComponent.attacking = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sqDistance < (50.f * 50.f) && spaceshipComponent.hitTime == 0)
|
||||||
|
{
|
||||||
|
spaceshipComponent.targetPos = Nz::Vector3f::Zero();
|
||||||
|
spaceshipComponent.attacking = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spaceshipComponent.hitTime == 0 || curTime - spaceshipComponent.hitTime <= 1000)
|
||||||
|
velocityComponent.linearVelocity = actualDir * speed;
|
||||||
|
else if (curTime - spaceshipComponent.hitTime > 10000)
|
||||||
|
entity->Kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Ndk::SystemIndex systemIndex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const ExampleShared& m_sharedData;
|
||||||
|
};
|
||||||
|
Ndk::SystemIndex SpaceshipSystem::systemIndex;
|
||||||
|
|
||||||
|
struct TorpedoParticle
|
||||||
|
{
|
||||||
|
Nz::Color color;
|
||||||
|
Nz::Vector2f size;
|
||||||
|
Nz::Vector3f position;
|
||||||
|
Nz::Vector3f velocity;
|
||||||
|
float rotation;
|
||||||
|
float life;
|
||||||
|
};
|
||||||
|
|
||||||
|
SpacebattleExample::SpacebattleExample(ExampleShared& sharedData) :
|
||||||
|
ParticleDemo("Space battle", sharedData)
|
||||||
|
{
|
||||||
|
Ndk::InitializeComponent<LaserBeamComponent>("Lasrbeam");
|
||||||
|
Ndk::InitializeComponent<SpaceshipComponent>("Spceship");
|
||||||
|
Ndk::InitializeSystem<LaserBeamSystem>();
|
||||||
|
Ndk::InitializeSystem<SpaceshipSystem>();
|
||||||
|
|
||||||
|
Nz::ModelParameters parameters;
|
||||||
|
parameters.mesh.optimizeIndexBuffers = false;
|
||||||
|
|
||||||
|
Nz::Color grey(100, 100, 100);
|
||||||
|
|
||||||
|
if (!m_turret.baseModel.LoadFromFile("resources/Turret/base.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load base.obj");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < m_turret.baseModel.GetMaterialCount(); ++i)
|
||||||
|
m_turret.baseModel.GetMaterial(i)->SetDiffuseColor(grey);
|
||||||
|
|
||||||
|
if (!m_turret.rotatingBaseModel.LoadFromFile("resources/Turret/rotating_base.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load rotating_base.obj");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < m_turret.rotatingBaseModel.GetMaterialCount(); ++i)
|
||||||
|
m_turret.rotatingBaseModel.GetMaterial(i)->SetDiffuseColor(grey);
|
||||||
|
|
||||||
|
if (!m_turret.cannonBaseModel.LoadFromFile("resources/Turret/cannon_base.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load cannon_base.obj");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < m_turret.cannonBaseModel.GetMaterialCount(); ++i)
|
||||||
|
m_turret.cannonBaseModel.GetMaterial(i)->SetDiffuseColor(grey);
|
||||||
|
|
||||||
|
parameters.mesh.texCoordScale.Set(40.f, 40.f);
|
||||||
|
parameters.mesh.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 180.f, 0.f));
|
||||||
|
if (!m_turret.cannonModel.LoadFromFile("resources/Turret/cannon.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load cannon.obj");
|
||||||
|
|
||||||
|
// Since OBJ don't support normal maps..
|
||||||
|
m_turret.cannonModel.GetMaterial(0)->SetNormalMap("resources/Turret/198_norm.jpg");
|
||||||
|
|
||||||
|
parameters.mesh.matrix.MakeIdentity();
|
||||||
|
parameters.mesh.texCoordScale.Set(1.f, 1.f);
|
||||||
|
|
||||||
|
parameters.mesh.center = true;
|
||||||
|
if (!m_spacestationModel.LoadFromFile("resources/SpaceStation/space_station.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load space_station.obj");
|
||||||
|
|
||||||
|
parameters.mesh.texCoordScale.Set(1.f, -1.f);
|
||||||
|
parameters.mesh.matrix.MakeRotation(Nz::EulerAnglesf(0.f, -90.f, 0.f));
|
||||||
|
|
||||||
|
if (!m_spaceshipModel.LoadFromFile("resources/space_frigate_6/space_frigate_6.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load space_frigate_6.obj");
|
||||||
|
|
||||||
|
// Since OBJ don't support normal maps..
|
||||||
|
for (unsigned int i = 0; i < m_spaceshipModel.GetMaterialCount(); ++i)
|
||||||
|
{
|
||||||
|
m_spaceshipModel.GetMaterial(i)->SetEmissiveMap("resources/space_frigate_6/space_frigate_6_illumination.jpg");
|
||||||
|
m_spaceshipModel.GetMaterial(i)->SetNormalMap("resources/space_frigate_6/space_frigate_6_normal.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
Nz::TextureRef skyboxCubemap = Nz::Texture::New();
|
||||||
|
if (skyboxCubemap->Create(Nz::ImageType_Cubemap, Nz::PixelFormatType_RGBA8, 2048, 2048))
|
||||||
|
{
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_PositiveX, "resources/purple_nebula_skybox/purple_nebula_skybox_right1.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_PositiveY, "resources/purple_nebula_skybox/purple_nebula_skybox_top3.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_PositiveZ, "resources/purple_nebula_skybox/purple_nebula_skybox_front5.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_NegativeX, "resources/purple_nebula_skybox/purple_nebula_skybox_left2.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_NegativeY, "resources/purple_nebula_skybox/purple_nebula_skybox_bottom4.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_NegativeZ, "resources/purple_nebula_skybox/purple_nebula_skybox_back6.png");
|
||||||
|
|
||||||
|
m_skybox.SetTexture(std::move(skyboxCubemap));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_torpedoDeclaration = Nz::ParticleDeclaration::New();
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Color, Nz::ComponentType_Color, NazaraOffsetOf(TorpedoParticle, color));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Position, Nz::ComponentType_Float3, NazaraOffsetOf(TorpedoParticle, position));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Rotation, Nz::ComponentType_Float1, NazaraOffsetOf(TorpedoParticle, rotation));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Size, Nz::ComponentType_Float2, NazaraOffsetOf(TorpedoParticle, size));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Life, Nz::ComponentType_Float1, NazaraOffsetOf(TorpedoParticle, life));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Velocity, Nz::ComponentType_Float3, NazaraOffsetOf(TorpedoParticle, velocity));
|
||||||
|
|
||||||
|
Nz::TextureSampler diffuseSampler;
|
||||||
|
diffuseSampler.SetWrapMode(Nz::SamplerWrap_Repeat);
|
||||||
|
|
||||||
|
Nz::MaterialRef material = Nz::Material::New("Translucent3D");
|
||||||
|
material->SetDiffuseMap("resources/LaserBeam.png");
|
||||||
|
material->SetDiffuseSampler(diffuseSampler);
|
||||||
|
|
||||||
|
Nz::MaterialLibrary::Register("LaserBeam", std::move(material));
|
||||||
|
|
||||||
|
Nz::MaterialRef sparkleMat1 = Nz::Material::New("Translucent3D");
|
||||||
|
|
||||||
|
sparkleMat1->SetDiffuseMap("resources/flare1.png");
|
||||||
|
Nz::MaterialLibrary::Register("TorpedoFlare1", std::move(sparkleMat1));
|
||||||
|
|
||||||
|
m_spaceshipTemplate = m_shared.world3D->CreateEntity();
|
||||||
|
m_spaceshipTemplate->Enable(false);
|
||||||
|
|
||||||
|
auto& gfxComponent = m_spaceshipTemplate->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
auto& nodeComponent = m_spaceshipTemplate->AddComponent<Ndk::NodeComponent>();
|
||||||
|
auto& velocityComponent = m_spaceshipTemplate->AddComponent<Ndk::VelocityComponent>();
|
||||||
|
auto& spaceshipComponent = m_spaceshipTemplate->AddComponent<SpaceshipComponent>();
|
||||||
|
gfxComponent.Attach(&m_spaceshipModel);
|
||||||
|
|
||||||
|
m_ambientMusic.OpenFromFile("resources/ambience.ogg");
|
||||||
|
m_ambientMusic.SetVolume(60.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
ParticleDemo::Enter(fsm);
|
||||||
|
|
||||||
|
m_shared.world3D->AddSystem<LaserBeamSystem>(m_shared);
|
||||||
|
m_shared.world3D->AddSystem<SpaceshipSystem>(m_shared);
|
||||||
|
|
||||||
|
Ndk::RenderSystem& renderSystem2D = m_shared.world2D->GetSystem<Ndk::RenderSystem>();
|
||||||
|
Ndk::RenderSystem& renderSystem3D = m_shared.world3D->GetSystem<Ndk::RenderSystem>();
|
||||||
|
renderSystem2D.SetDefaultBackground(nullptr);
|
||||||
|
renderSystem3D.SetDefaultBackground(&m_skybox);
|
||||||
|
|
||||||
|
CreateSpaceShip();
|
||||||
|
CreateTurret();
|
||||||
|
|
||||||
|
Ndk::EntityHandle light = m_shared.world3D->CreateEntity();
|
||||||
|
Ndk::NodeComponent& lightNode = light->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::LightComponent& lightComp = light->AddComponent<Ndk::LightComponent>(Nz::LightType_Directional);
|
||||||
|
lightNode.SetRotation(Nz::EulerAnglesf(-30.f, 0.f, 0.f));
|
||||||
|
RegisterEntity(light);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cameraNode = m_shared.viewer3D->GetComponent<Ndk::NodeComponent>();
|
||||||
|
cameraNode.SetParent(m_turret.cannonAnchorEntity);
|
||||||
|
cameraNode.SetPosition(Nz::Vector3f::Up() * 4.f - Nz::Vector3f::Backward() * 6.f);
|
||||||
|
cameraNode.SetRotation(Nz::EulerAnglesf(0.f, 180.f, 0.f));
|
||||||
|
|
||||||
|
m_introTimer = 10.f;
|
||||||
|
m_spaceshipSpawnCounter = -5.f;
|
||||||
|
m_turretBaseRotation = 0.f;
|
||||||
|
m_turretCannonBaseRotation = 0.f;
|
||||||
|
m_turretShootTimer = 0.f;
|
||||||
|
|
||||||
|
Ndk::EntityHandle torpedoGroupEntity = m_shared.world3D->CreateEntity();
|
||||||
|
m_torpedoGroup = torpedoGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(200, m_torpedoDeclaration).CreateHandle();
|
||||||
|
RegisterParticleGroup(torpedoGroupEntity);
|
||||||
|
|
||||||
|
m_torpedoGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||||
|
auto rotationPtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
rotationPtr[i] += elapsedTime * 90.f;
|
||||||
|
positionPtr[i] += velocityPtr[i] * elapsedTime;
|
||||||
|
|
||||||
|
lifePtr[i] -= elapsedTime;
|
||||||
|
if (lifePtr[i] < 0.f)
|
||||||
|
group.KillParticle(i);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
m_torpedoGroup->AddController(Nz::ParticleFunctionController::New([this] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto rotationPtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
auto velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
auto& spaceshipSystem = m_shared.world3D->GetSystem<SpaceshipSystem>();
|
||||||
|
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
Nz::Spheref torpedoSphere(positionPtr[i], std::max(sizePtr[i].x, sizePtr[i].y) * 0.1f);
|
||||||
|
|
||||||
|
for (const Ndk::EntityHandle& entity : spaceshipSystem.GetEntities())
|
||||||
|
{
|
||||||
|
auto& spaceshipNode = entity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Nz::Spheref spaceshipSphere(spaceshipNode.GetPosition(), 10.f);
|
||||||
|
if (torpedoSphere.Intersect(spaceshipSphere))
|
||||||
|
{
|
||||||
|
entity->RemoveComponent<LaserBeamComponent>();
|
||||||
|
|
||||||
|
group.KillParticle(i);
|
||||||
|
|
||||||
|
const float hitMaxDist = 500.f;
|
||||||
|
|
||||||
|
std::uniform_real_distribution<float> dis(-hitMaxDist, hitMaxDist);
|
||||||
|
|
||||||
|
auto& spaceshipComponent = entity->GetComponent<SpaceshipComponent>();
|
||||||
|
spaceshipComponent.attacking = false;
|
||||||
|
spaceshipComponent.engineSound.Stop();
|
||||||
|
spaceshipComponent.hitSound.Play();
|
||||||
|
spaceshipComponent.hitTime = Nz::GetElapsedMilliseconds();
|
||||||
|
spaceshipComponent.targetPos = Nz::Vector3f(dis(m_shared.randomGen), dis(m_shared.randomGen), dis(m_shared.randomGen));
|
||||||
|
|
||||||
|
auto& emitter = entity->AddComponent<Ndk::ParticleEmitterComponent>();
|
||||||
|
emitter.SetEmissionCount(2);
|
||||||
|
emitter.SetEmissionRate(200.f);
|
||||||
|
|
||||||
|
emitter.SetSetupFunc([this] (const Ndk::EntityHandle& entity, Nz::ParticleMapper& mapper, unsigned int count)
|
||||||
|
{
|
||||||
|
auto& gen = m_shared.randomGen;
|
||||||
|
|
||||||
|
const float maxFireVel = 15.f;
|
||||||
|
std::uniform_real_distribution<float> lifeDis(-0.5f, 0.5f);
|
||||||
|
std::uniform_real_distribution<float> normalDis(-1.f, 1.f);
|
||||||
|
std::uniform_real_distribution<float> posDis(-0.1f, 0.1f);
|
||||||
|
std::uniform_real_distribution<float> rotDis(-180.f, 180.f);
|
||||||
|
std::uniform_real_distribution<float> sizeDis(1.0f, 4.f);
|
||||||
|
std::uniform_real_distribution<float> velDis(-maxFireVel, maxFireVel);
|
||||||
|
|
||||||
|
Nz::Vector3f pos = entity->GetComponent<Ndk::NodeComponent>().GetPosition();
|
||||||
|
|
||||||
|
Nz::ParticleStruct_Billboard* billboards = static_cast<Nz::ParticleStruct_Billboard*>(mapper.GetPointer());
|
||||||
|
Nz::ParticleStruct_Billboard* smokeParticles = static_cast<Nz::ParticleStruct_Billboard*>(m_smokeGroup->CreateParticles(count));
|
||||||
|
for (unsigned int i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
billboards[i].color = Nz::Color::White;
|
||||||
|
billboards[i].life = 1.f + lifeDis(gen);
|
||||||
|
billboards[i].position = pos + Nz::Vector3f(posDis(gen), posDis(gen), posDis(gen));
|
||||||
|
billboards[i].rotation = rotDis(gen);
|
||||||
|
billboards[i].size = {1.28f, 1.28f};
|
||||||
|
billboards[i].size *= sizeDis(gen);
|
||||||
|
billboards[i].velocity.Set(normalDis(gen), normalDis(gen), normalDis(gen));
|
||||||
|
billboards[i].velocity.Normalize();
|
||||||
|
billboards[i].velocity *= velDis(gen);
|
||||||
|
|
||||||
|
smokeParticles[i].color = Nz::Color(128, 128, 128, 0);
|
||||||
|
smokeParticles[i].life = maxSmokeLife;
|
||||||
|
smokeParticles[i].position = billboards[i].position;
|
||||||
|
smokeParticles[i].rotation = billboards[i].rotation;
|
||||||
|
smokeParticles[i].size = {2.56f, 2.56f};
|
||||||
|
smokeParticles[i].size *= sizeDis(gen);
|
||||||
|
smokeParticles[i].velocity = billboards[i].velocity / 2.f;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
m_fireGroup->AddEmitter(entity);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
m_torpedoGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([sparkleMat1 = Nz::MaterialLibrary::Get("TorpedoFlare1")] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||||
|
{
|
||||||
|
auto positionPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto rotationPtr = mapper.GetComponentPtr<const float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<const Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
auto velocityPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
renderQueue->AddBillboards(0, sparkleMat1, endId - startId + 1, positionPtr, sizePtr, rotationPtr);
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
Nz::AbstractRenderQueue::PointLight pointLight;
|
||||||
|
pointLight.ambientFactor = 0.f;
|
||||||
|
pointLight.attenuation = 0.9f;
|
||||||
|
pointLight.color = Nz::Color::Cyan;
|
||||||
|
pointLight.diffuseFactor = 1.f;
|
||||||
|
pointLight.position = positionPtr[i];
|
||||||
|
pointLight.radius = std::max(sizePtr[i].x, sizePtr[i].y) * 2.f;
|
||||||
|
pointLight.invRadius = 1.f / pointLight.radius;
|
||||||
|
pointLight.shadowMap = nullptr;
|
||||||
|
|
||||||
|
renderQueue->AddPointLight(pointLight);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Ndk::EntityHandle fireGroupEntity = m_shared.world3D->CreateEntity();
|
||||||
|
m_fireGroup = fireGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(40000, Nz::ParticleDeclaration::Get(Nz::ParticleLayout_Billboard)).CreateHandle();
|
||||||
|
RegisterParticleGroup(fireGroupEntity);
|
||||||
|
|
||||||
|
Ndk::EntityHandle smokeGroupEntity = m_shared.world3D->CreateEntity();
|
||||||
|
m_smokeGroup = smokeGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(40000, Nz::ParticleDeclaration::Get(Nz::ParticleLayout_Billboard)).CreateHandle();
|
||||||
|
RegisterParticleGroup(smokeGroupEntity);
|
||||||
|
|
||||||
|
auto movementController = Nz::ParticleFunctionController::New([this] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||||
|
auto posPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
auto velPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
auto& spaceshipSystem = m_shared.world3D->GetSystem<SpaceshipSystem>();
|
||||||
|
|
||||||
|
const Nz::Vector2f sizeGrowth(0.5f);
|
||||||
|
|
||||||
|
float velFactor = std::pow(0.9f, elapsedTime * 15.f);
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
float& remainingLife = lifePtr[i];
|
||||||
|
|
||||||
|
remainingLife -= elapsedTime;
|
||||||
|
if (remainingLife <= 0.f)
|
||||||
|
{
|
||||||
|
group.KillParticle(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Nz::Vector3f& position = posPtr[i];
|
||||||
|
Nz::Vector2f& size = sizePtr[i];
|
||||||
|
Nz::Vector3f& velocity = velPtr[i];
|
||||||
|
|
||||||
|
position += velPtr[i] * elapsedTime;
|
||||||
|
size += sizeGrowth * elapsedTime;
|
||||||
|
velocity *= (velocity.GetSquaredLength() >= 1.f) ? velFactor : 1.f;
|
||||||
|
|
||||||
|
if (remainingLife <= 18.f)
|
||||||
|
{
|
||||||
|
for (const Ndk::EntityHandle& entity : spaceshipSystem.GetEntities())
|
||||||
|
{
|
||||||
|
auto& spaceshipNode = entity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Nz::Spheref spaceshipSphere(spaceshipNode.GetPosition(), 5.f);
|
||||||
|
if (spaceshipSphere.Contains(position))
|
||||||
|
{
|
||||||
|
auto& spaceshipVel = entity->GetComponent<Ndk::VelocityComponent>();
|
||||||
|
|
||||||
|
Nz::Vector3f force = spaceshipVel.linearVelocity * 2.f + (position - spaceshipSphere.GetPosition()) * 10.f;
|
||||||
|
velocity += force * elapsedTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TorpedoParticle* torpedos = static_cast<TorpedoParticle*>(m_torpedoGroup->GetBuffer());
|
||||||
|
std::size_t torpedoCount = m_torpedoGroup->GetParticleCount();
|
||||||
|
for (std::size_t j = 0; j < torpedoCount; ++j)
|
||||||
|
{
|
||||||
|
Nz::Spheref tordedoSphere(torpedos[j].position, 5.f);
|
||||||
|
|
||||||
|
if (tordedoSphere.Contains(position))
|
||||||
|
{
|
||||||
|
Nz::Spheref tordedoCenter(torpedos[j].position, 2.f);
|
||||||
|
if (tordedoCenter.Contains(position))
|
||||||
|
{
|
||||||
|
group.KillParticle(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Nz::Vector3f dir = (torpedos[j].position - position);
|
||||||
|
float length;
|
||||||
|
dir.Normalize(&length);
|
||||||
|
|
||||||
|
remainingLife -= 100.f * elapsedTime / length;
|
||||||
|
size -= 100.f * sizeGrowth * elapsedTime / length;
|
||||||
|
velocity += 500.f * dir * elapsedTime / length;
|
||||||
|
velocity += torpedos[j].velocity * elapsedTime;
|
||||||
|
|
||||||
|
break; //< There's no way a particle would be in multiple torpedo at once
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
m_fireGroup->AddController(movementController);
|
||||||
|
m_fireGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
|
||||||
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||||
|
|
||||||
|
float velFactor = std::pow(0.9f, elapsedTime / 0.1f);
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
colorPtr[i].a = static_cast<Nz::UInt8>(Nz::Clamp(lifePtr[i] * 255.f, 0.f, 255.f));
|
||||||
|
}));
|
||||||
|
|
||||||
|
m_smokeGroup->AddController(movementController);
|
||||||
|
m_smokeGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
|
||||||
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||||
|
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
float alpha = std::min((maxSmokeLife - lifePtr[i]) * 255.f / 5.f, 255.f);
|
||||||
|
alpha -= std::max((maxSmokeLife - lifePtr[i]) / maxSmokeLife * 255.f, 0.f);
|
||||||
|
|
||||||
|
colorPtr[i].a = static_cast<Nz::UInt8>(Nz::Clamp(alpha, 0.f, 255.f));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
Nz::MaterialRef fireMat = Nz::Material::New("Translucent3D");
|
||||||
|
fireMat->EnableFaceCulling(true);
|
||||||
|
fireMat->SetDiffuseMap("resources/fire_particle.png");
|
||||||
|
// Additive blending for fire
|
||||||
|
fireMat->SetDstBlend(Nz::BlendFunc_One);
|
||||||
|
fireMat->SetSrcBlend(Nz::BlendFunc_SrcAlpha);
|
||||||
|
|
||||||
|
Nz::MaterialRef smokeMat = Nz::Material::New("Translucent3D");
|
||||||
|
smokeMat->EnableFaceCulling(true);
|
||||||
|
smokeMat->SetDiffuseColor(Nz::Color(128, 128, 128));
|
||||||
|
smokeMat->SetDiffuseMap("resources/smoke.png");
|
||||||
|
|
||||||
|
m_fireGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([fireMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||||
|
{
|
||||||
|
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
|
||||||
|
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto rotPtr = mapper.GetComponentPtr<const float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<const Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
|
||||||
|
renderQueue->AddBillboards(0, fireMat, endId - startId + 1, posPtr, sizePtr, rotPtr, colorPtr);
|
||||||
|
}));
|
||||||
|
|
||||||
|
m_smokeGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([smokeMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||||
|
{
|
||||||
|
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
|
||||||
|
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto rotPtr = mapper.GetComponentPtr<const float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<const Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
|
||||||
|
renderQueue->AddBillboards(0, smokeMat, endId - startId + 1, posPtr, sizePtr, rotPtr, colorPtr);
|
||||||
|
}));
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
m_ambientMusic.Play();
|
||||||
|
m_turretFireSound.LoadFromFile("resources/turretFire.wav");
|
||||||
|
m_turretReloadSound.LoadFromFile("resources/turretReload.wav");
|
||||||
|
|
||||||
|
//m_onMouseMoved.Connect(m_shared.target->GetEventHandler().OnMouseMoved, this, &SpacebattleExample::OnMouseMoved);
|
||||||
|
//m_shared.target->SetCursor(Nz::WindowCursor_None);
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Nz::TextSpriteRef introText = Nz::TextSprite::New();
|
||||||
|
introText->Update(Nz::SimpleTextDrawer::Draw("--Tourelle de défense du secteur A407M2--\nLes contrôles ont été adaptés à vos contrôleurs:\nZQSD pour orienter la tourelle, espace pour tirer.\n", 72));
|
||||||
|
introText->SetScale(0.5f);
|
||||||
|
|
||||||
|
m_introText = m_shared.world3D->CreateEntity();
|
||||||
|
Ndk::NodeComponent& introNode = m_introText->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::GraphicsComponent& introGfx = m_introText->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
introGfx.Attach(introText, 1);
|
||||||
|
RegisterEntity(m_introText);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonNode = m_turret.cannonEntity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Nz::Boxf introAABB = introGfx.GetBoundingVolume().aabb;
|
||||||
|
introNode.SetPosition(cannonNode.GetForward() * 500.f + introNode.GetLeft() * introAABB.width / 2.f + introNode.GetUp() * introAABB.height / 2.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::Leave(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
m_ambientMusic.Stop();
|
||||||
|
m_shared.world3D->RemoveSystem<LaserBeamSystem>();
|
||||||
|
m_shared.world3D->RemoveSystem<SpaceshipSystem>();
|
||||||
|
m_turretFireSound.Stop();
|
||||||
|
m_turretReloadSound.Stop();
|
||||||
|
|
||||||
|
ParticleDemo::Leave(fsm);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SpacebattleExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
|
||||||
|
{
|
||||||
|
if (!ParticleDemo::Update(fsm, elapsedTime))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const float speed = 100.f;
|
||||||
|
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Z))
|
||||||
|
m_turretCannonBaseRotation = std::max(m_turretCannonBaseRotation - speed * elapsedTime, -65.f);
|
||||||
|
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::S))
|
||||||
|
m_turretCannonBaseRotation = std::min(m_turretCannonBaseRotation + speed * elapsedTime, 40.f);
|
||||||
|
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Q))
|
||||||
|
m_turretBaseRotation += speed * elapsedTime;
|
||||||
|
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::D))
|
||||||
|
m_turretBaseRotation -= speed * elapsedTime;
|
||||||
|
|
||||||
|
m_turret.cannonBaseEntity->GetComponent<Ndk::NodeComponent>().SetRotation(Nz::EulerAnglesf(m_turretCannonBaseRotation, 0.f, 0.f));
|
||||||
|
m_turret.rotatingBaseEntity->GetComponent<Ndk::NodeComponent>().SetRotation(Nz::EulerAnglesf(0.f, m_turretBaseRotation, 0.f));
|
||||||
|
|
||||||
|
bool discharged = m_turretShootTimer < 1.f;
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Space) && !discharged)
|
||||||
|
{
|
||||||
|
m_turretFireSound.Play();
|
||||||
|
|
||||||
|
m_turretShootTimer = -1.f;
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonNode = m_turret.cannonEntity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
TorpedoParticle* particle = static_cast<TorpedoParticle*>(m_torpedoGroup->CreateParticle());
|
||||||
|
particle->color = Nz::Color::White;
|
||||||
|
particle->position = cannonNode.ToGlobalPosition(Nz::Vector3f::Forward() * 10.f);
|
||||||
|
particle->rotation = 0.f;
|
||||||
|
particle->life = 15.f;
|
||||||
|
particle->size.Set(13.34f, 7.41f);
|
||||||
|
particle->size *= 2.f;
|
||||||
|
particle->velocity = cannonNode.GetForward() * 100.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_turretShootTimer += elapsedTime * 2.f;
|
||||||
|
if (discharged && m_turretShootTimer >= 1.f)
|
||||||
|
m_turretReloadSound.Play();
|
||||||
|
|
||||||
|
m_turret.cannonEntity->GetComponent<Ndk::NodeComponent>().SetPosition(Nz::Vector3f::Backward() * std::sin(std::min(m_turretShootTimer, 0.f) * float(M_PI)) * 3.f);
|
||||||
|
|
||||||
|
m_spaceshipSpawnCounter += elapsedTime;
|
||||||
|
if (m_spaceshipSpawnCounter >= 10.f)
|
||||||
|
{
|
||||||
|
m_spaceshipSpawnCounter -= 10.f;
|
||||||
|
|
||||||
|
auto& spacestationNode = m_spacestationEntity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Ndk::EntityHandle spaceship = m_spaceshipTemplate->Clone();
|
||||||
|
RegisterEntity(spaceship);
|
||||||
|
auto& nodeComponent = spaceship->GetComponent<Ndk::NodeComponent>();
|
||||||
|
auto& spaceshipComponent = spaceship->GetComponent<SpaceshipComponent>();
|
||||||
|
|
||||||
|
spaceshipComponent.targetPos = m_shared.viewer3D->GetComponent<Ndk::NodeComponent>().GetPosition();
|
||||||
|
nodeComponent.SetPosition(spacestationNode.GetPosition());
|
||||||
|
nodeComponent.SetRotation(Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), spacestationNode.GetRight()));
|
||||||
|
nodeComponent.Move(Nz::Vector3f::Forward() * 15.f + Nz::Vector3f::Down() * 5.f, Nz::CoordSys_Local);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_introTimer -= elapsedTime;
|
||||||
|
if (m_introTimer <= 0.f && m_introText)
|
||||||
|
m_introText->Kill();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::CreateSpaceShip()
|
||||||
|
{
|
||||||
|
m_spacestationEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_spacestationEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& spacestationNode = m_spacestationEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
spacestationNode.SetPosition(Nz::Vector3f::Forward() * 500.f + Nz::Vector3f::Up() * 200.f + Nz::Vector3f::Right() * 250.f);
|
||||||
|
spacestationNode.SetRotation(Nz::EulerAnglesf(0.f, 15.f, 0.f));
|
||||||
|
spacestationNode.SetScale(0.1f);
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& spacestationGfx = m_spacestationEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
spacestationGfx.Attach(&m_spacestationModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::CreateTurret()
|
||||||
|
{
|
||||||
|
// Fixed base
|
||||||
|
m_turret.baseEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.baseEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& baseNode = m_turret.baseEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
//baseNode.SetParent(m_spacestationEntity);
|
||||||
|
baseNode.SetRotation(Nz::EulerAnglesf(0.f, 180.f, 0.f));
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& baseGfx = m_turret.baseEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
baseGfx.Attach(&m_turret.baseModel);
|
||||||
|
|
||||||
|
// Rotating base
|
||||||
|
m_turret.rotatingBaseEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.rotatingBaseEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& rotatingBaseNode = m_turret.rotatingBaseEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
rotatingBaseNode.SetParent(m_turret.baseEntity);
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& rotatingBaseGfx = m_turret.rotatingBaseEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
rotatingBaseGfx.Attach(&m_turret.rotatingBaseModel);
|
||||||
|
|
||||||
|
// Cannon base
|
||||||
|
m_turret.cannonBaseEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.cannonBaseEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonBaseNode = m_turret.cannonBaseEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
cannonBaseNode.SetPosition({0.f, 3.39623547f, 0.f});
|
||||||
|
cannonBaseNode.SetParent(m_turret.rotatingBaseEntity);
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& cannonBaseGfx = m_turret.cannonBaseEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
cannonBaseGfx.Attach(&m_turret.cannonBaseModel);
|
||||||
|
|
||||||
|
// Cannon anchor
|
||||||
|
m_turret.cannonAnchorEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.cannonAnchorEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonAnchorNode = m_turret.cannonAnchorEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
cannonAnchorNode.SetPosition({0.f, 2.96482944f, 3.20705462f});
|
||||||
|
cannonAnchorNode.SetParent(m_turret.cannonBaseEntity);
|
||||||
|
|
||||||
|
// Cannon
|
||||||
|
m_turret.cannonEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.cannonEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonNode = m_turret.cannonEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
cannonNode.SetParent(m_turret.cannonAnchorEntity);
|
||||||
|
cannonNode.SetRotation(Nz::EulerAnglesf(0.f, 180.f, 0.f));
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& cannonGfx = m_turret.cannonEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
cannonGfx.Attach(&m_turret.cannonModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||||
|
{
|
||||||
|
const float speed = 0.1f;
|
||||||
|
|
||||||
|
m_turretCannonBaseRotation = Nz::Clamp(m_turretCannonBaseRotation + speed * event.deltaY, -65.f, 40.f);
|
||||||
|
m_turretBaseRotation -= event.deltaX * speed;
|
||||||
|
|
||||||
|
Nz::Mouse::SetPosition(m_shared.target->GetWidth() / 2, m_shared.target->GetHeight() / 2, *m_shared.target);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_EXAMPLES_PARTICLES_SPACEBATTLE_HPP
|
||||||
|
#define NAZARA_EXAMPLES_PARTICLES_SPACEBATTLE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Audio/Music.hpp>
|
||||||
|
#include <Nazara/Audio/Sound.hpp>
|
||||||
|
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||||
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
|
#include <Nazara/Graphics/ParticleStruct.hpp>
|
||||||
|
#include <Nazara/Graphics/SkyboxBackground.hpp>
|
||||||
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
|
#include <Nazara/Utility/EventHandler.hpp>
|
||||||
|
#include <NDK/Entity.hpp>
|
||||||
|
#include <NDK/State.hpp>
|
||||||
|
#include <vector>
|
||||||
|
#include "Common.hpp"
|
||||||
|
|
||||||
|
class SpacebattleExample : public ParticleDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SpacebattleExample(ExampleShared& sharedData);
|
||||||
|
~SpacebattleExample() = default;
|
||||||
|
|
||||||
|
void Enter(Ndk::StateMachine& fsm) override;
|
||||||
|
void Leave(Ndk::StateMachine& fsm) override;
|
||||||
|
bool Update(Ndk::StateMachine& fsm, float elapsedTime) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CreateSpaceShip();
|
||||||
|
void CreateTurret();
|
||||||
|
void OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
|
||||||
|
|
||||||
|
struct Turret
|
||||||
|
{
|
||||||
|
Nz::Model baseModel;
|
||||||
|
Nz::Model cannonModel;
|
||||||
|
Nz::Model cannonBaseModel;
|
||||||
|
Nz::Model rotatingBaseModel;
|
||||||
|
Ndk::EntityHandle baseEntity;
|
||||||
|
Ndk::EntityHandle cannonAnchorEntity;
|
||||||
|
Ndk::EntityHandle cannonEntity;
|
||||||
|
Ndk::EntityHandle cannonBaseEntity;
|
||||||
|
Ndk::EntityHandle rotatingBaseEntity;
|
||||||
|
};
|
||||||
|
|
||||||
|
Turret m_turret;
|
||||||
|
float m_introTimer;
|
||||||
|
float m_spaceshipSpawnCounter;
|
||||||
|
float m_turretBaseRotation;
|
||||||
|
float m_turretCannonBaseRotation;
|
||||||
|
float m_turretShootTimer;
|
||||||
|
Nz::Model m_spaceshipModel;
|
||||||
|
Nz::Model m_spacestationModel;
|
||||||
|
Nz::Music m_ambientMusic;
|
||||||
|
Nz::ParticleDeclarationRef m_torpedoDeclaration;
|
||||||
|
Nz::ParticleRendererRef m_laserBeamRenderer;
|
||||||
|
Nz::Sound m_turretFireSound;
|
||||||
|
Nz::Sound m_turretReloadSound;
|
||||||
|
Nz::SkyboxBackground m_skybox;
|
||||||
|
Ndk::EntityHandle m_introText;
|
||||||
|
Ndk::EntityHandle m_spaceshipTemplate;
|
||||||
|
Ndk::EntityHandle m_spacestationEntity;
|
||||||
|
Ndk::ParticleGroupComponentHandle m_fireGroup;
|
||||||
|
Ndk::ParticleGroupComponentHandle m_smokeGroup;
|
||||||
|
Ndk::ParticleGroupComponentHandle m_torpedoGroup;
|
||||||
|
|
||||||
|
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_onMouseMoved);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_EXAMPLES_PARTICLES_SPACEBATTLE_HPP
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
EXAMPLE.Name = "Particles"
|
||||||
|
|
||||||
|
EXAMPLE.EnableConsole = true
|
||||||
|
|
||||||
|
EXAMPLE.Files = {
|
||||||
|
"*.hpp",
|
||||||
|
"*.inl",
|
||||||
|
"*.cpp"
|
||||||
|
}
|
||||||
|
|
||||||
|
EXAMPLE.Libraries = {
|
||||||
|
"NazaraSDK"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,202 @@
|
||||||
|
#include <Nazara/Audio.hpp>
|
||||||
|
#include <Nazara/Core.hpp>
|
||||||
|
#include <Nazara/Graphics.hpp>
|
||||||
|
#include <Nazara/Lua.hpp>
|
||||||
|
#include <Nazara/Network.hpp>
|
||||||
|
#include <Nazara/Noise.hpp>
|
||||||
|
#include <Nazara/Physics3D.hpp>
|
||||||
|
#include <Nazara/Renderer.hpp>
|
||||||
|
#include <Nazara/Utility.hpp>
|
||||||
|
#include <NDK/Application.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/Systems.hpp>
|
||||||
|
#include <NDK/StateMachine.hpp>
|
||||||
|
#include "LogoDemo.hpp"
|
||||||
|
#include "SpacebattleDemo.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Nz::ContextParameters::defaultCompatibilityProfile = true;
|
||||||
|
|
||||||
|
Ndk::Application app;
|
||||||
|
|
||||||
|
// Mix all sounds in mono (in order to give them 3D position)
|
||||||
|
Nz::SoundBufferParams soundParams;
|
||||||
|
soundParams.forceMono = true;
|
||||||
|
|
||||||
|
Nz::SoundBufferManager::SetDefaultParameters(soundParams);
|
||||||
|
|
||||||
|
// Pour commencer le mode vidéo, celui-ci va définir la taille de la zone de rendu et le nombre de bits par pixels
|
||||||
|
Nz::VideoMode mode = Nz::VideoMode::GetDesktopMode(); // Nous récupérons le mode vidéo du bureau
|
||||||
|
|
||||||
|
// Nous allons prendre les trois quarts de la résolution du bureau pour notre fenêtre
|
||||||
|
mode.width = 3 * mode.width / 4;
|
||||||
|
mode.height = 3 * mode.height / 4;
|
||||||
|
|
||||||
|
Nz::ContextParameters targetParams;
|
||||||
|
targetParams.antialiasingLevel = 0;
|
||||||
|
|
||||||
|
Nz::RenderWindow& window = app.AddWindow<Nz::RenderWindow>(mode, "Nazara demo - Particles", Nz::WindowStyle_Closable, targetParams);
|
||||||
|
//Nz::RenderWindow& window = app.AddWindow<Nz::RenderWindow>(Nz::VideoMode(1920, 1080), "Nazara demo - Particles", Nz::WindowStyle_Fullscreen, targetParams);
|
||||||
|
|
||||||
|
Ndk::World& world3D = app.AddWorld();
|
||||||
|
Ndk::World& world2D = app.AddWorld();
|
||||||
|
|
||||||
|
std::random_device randomDevice;
|
||||||
|
|
||||||
|
ExampleShared shared;
|
||||||
|
shared.randomGen.seed(randomDevice());
|
||||||
|
shared.target = &window;
|
||||||
|
shared.world2D = &world2D;
|
||||||
|
shared.world3D = &world3D;
|
||||||
|
|
||||||
|
shared.demoName = Nz::TextSprite::New();
|
||||||
|
shared.demoName->Update(Nz::SimpleTextDrawer::Draw("XX - DemoName", 48));
|
||||||
|
|
||||||
|
shared.fpsCount = Nz::TextSprite::New();
|
||||||
|
shared.fpsCount->Update(Nz::SimpleTextDrawer::Draw("XXXXX FPS", 24));
|
||||||
|
|
||||||
|
shared.particleCount = Nz::TextSprite::New();
|
||||||
|
shared.particleCount->Update(Nz::SimpleTextDrawer::Draw("XXXXX particles", 36));
|
||||||
|
|
||||||
|
world2D.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
|
||||||
|
world3D.GetSystem<Ndk::RenderSystem>().ChangeRenderTechnique<Nz::DeferredRenderTechnique>();
|
||||||
|
|
||||||
|
|
||||||
|
Ndk::EntityHandle viewEntity = world2D.CreateEntity();
|
||||||
|
viewEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
|
||||||
|
viewer.SetTarget(&window);
|
||||||
|
viewer.SetProjectionType(Nz::ProjectionType_Orthogonal);
|
||||||
|
|
||||||
|
shared.viewer2D = viewEntity;
|
||||||
|
|
||||||
|
Ndk::EntityHandle cameraEntity = world3D.CreateEntity();
|
||||||
|
cameraEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
cameraEntity->AddComponent<Ndk::ListenerComponent>();
|
||||||
|
|
||||||
|
Ndk::CameraComponent& camera = cameraEntity->AddComponent<Ndk::CameraComponent>();
|
||||||
|
camera.SetTarget(&window);
|
||||||
|
camera.SetZFar(10000.f);
|
||||||
|
|
||||||
|
shared.viewer3D = cameraEntity;
|
||||||
|
|
||||||
|
Ndk::EntityHandle demoNameEntity = world2D.CreateEntity();
|
||||||
|
Ndk::NodeComponent& demoNameNode = demoNameEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::GraphicsComponent& demoNameGfx = demoNameEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
demoNameGfx.Attach(shared.demoName, 1);
|
||||||
|
|
||||||
|
Ndk::EntityHandle fpsCountEntity = world2D.CreateEntity();
|
||||||
|
Ndk::NodeComponent& fpsNode = fpsCountEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::GraphicsComponent& fpsGfx = fpsCountEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
fpsGfx.Attach(shared.fpsCount, 1);
|
||||||
|
|
||||||
|
Ndk::EntityHandle particleCountEntity = world2D.CreateEntity();
|
||||||
|
Ndk::NodeComponent& particleCountNode = particleCountEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::GraphicsComponent& particleCountGfx = particleCountEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
particleCountGfx.Attach(shared.particleCount, 1);
|
||||||
|
|
||||||
|
|
||||||
|
Nz::Boxf fpsCountBox = fpsGfx.GetBoundingVolume().aabb;
|
||||||
|
Nz::Boxf particleCountBox = particleCountGfx.GetBoundingVolume().aabb;
|
||||||
|
|
||||||
|
demoNameNode.SetPosition(5.f, 5.f);
|
||||||
|
particleCountNode.SetPosition(5.f, window.GetHeight() - particleCountBox.height - 5.f);
|
||||||
|
fpsNode.SetPosition(5.f, window.GetHeight() - fpsCountBox.height - particleCountBox.height - 5.f);
|
||||||
|
|
||||||
|
|
||||||
|
//shared.demos.push_back(std::make_shared<LogoExample>(shared));
|
||||||
|
shared.demos.push_back(std::make_shared<SpacebattleExample>(shared));
|
||||||
|
|
||||||
|
std::size_t demoIndex = 0;
|
||||||
|
Ndk::StateMachine stateMachine(shared.demos[demoIndex]);
|
||||||
|
|
||||||
|
window.EnableEventPolling(true);
|
||||||
|
|
||||||
|
while (app.Run())
|
||||||
|
{
|
||||||
|
Nz::WindowEvent event;
|
||||||
|
while (window.PollEvent(&event))
|
||||||
|
{
|
||||||
|
switch (event.type)
|
||||||
|
{
|
||||||
|
case Nz::WindowEventType_KeyPressed:
|
||||||
|
{
|
||||||
|
switch (event.key.code)
|
||||||
|
{
|
||||||
|
case Nz::Keyboard::Backspace:
|
||||||
|
stateMachine.ChangeState(stateMachine.GetCurrentState());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Nz::Keyboard::Escape:
|
||||||
|
app.Quit();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Nz::Keyboard::Left:
|
||||||
|
{
|
||||||
|
if (shared.demos.size() <= 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (demoIndex == 0)
|
||||||
|
demoIndex = shared.demos.size();
|
||||||
|
|
||||||
|
demoIndex--;
|
||||||
|
stateMachine.ChangeState(shared.demos[demoIndex]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::Keyboard::Right:
|
||||||
|
{
|
||||||
|
if (shared.demos.size() <= 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
demoIndex++;
|
||||||
|
if (demoIndex == shared.demos.size())
|
||||||
|
demoIndex = 0;
|
||||||
|
|
||||||
|
stateMachine.ChangeState(shared.demos[demoIndex]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::Keyboard::Pause:
|
||||||
|
{
|
||||||
|
auto& velocitySystem = shared.world3D->GetSystem<Ndk::VelocitySystem>();
|
||||||
|
velocitySystem.Enable(!velocitySystem.IsEnabled());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::Keyboard::F5:
|
||||||
|
{
|
||||||
|
Nz::Image screenshot;
|
||||||
|
screenshot.Create(Nz::ImageType_2D, Nz::PixelFormatType_RGBA8, 1920, 1080);
|
||||||
|
window.CopyToImage(&screenshot);
|
||||||
|
|
||||||
|
static unsigned int counter = 1;
|
||||||
|
screenshot.SaveToFile("screenshot_" + Nz::String::Number(counter++) + ".png");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::WindowEventType_Quit:
|
||||||
|
window.Close();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stateMachine.Update(app.GetUpdateTime());
|
||||||
|
|
||||||
|
window.Display();
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -73,6 +73,7 @@ namespace Nz
|
||||||
|
|
||||||
bool FillAndQueueBuffer(unsigned int buffer);
|
bool FillAndQueueBuffer(unsigned int buffer);
|
||||||
void MusicThread();
|
void MusicThread();
|
||||||
|
void StopThread();
|
||||||
|
|
||||||
static MusicLoader::LoaderList s_loaders;
|
static MusicLoader::LoaderList s_loaders;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline ByteStream(Stream* stream = nullptr);
|
inline ByteStream(Stream* stream = nullptr);
|
||||||
ByteStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
ByteStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
|
||||||
ByteStream(void* ptr, Nz::UInt64 size);
|
ByteStream(void* ptr, Nz::UInt64 size);
|
||||||
ByteStream(const void* ptr, Nz::UInt64 size);
|
ByteStream(const void* ptr, Nz::UInt64 size);
|
||||||
ByteStream(const ByteStream&) = delete;
|
ByteStream(const ByteStream&) = delete;
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Nz
|
||||||
|
|
||||||
inline void SetDataEndianness(Endianness endiannes);
|
inline void SetDataEndianness(Endianness endiannes);
|
||||||
inline void SetStream(Stream* stream);
|
inline void SetStream(Stream* stream);
|
||||||
void SetStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
void SetStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
|
||||||
void SetStream(void* ptr, Nz::UInt64 size);
|
void SetStream(void* ptr, Nz::UInt64 size);
|
||||||
void SetStream(const void* ptr, Nz::UInt64 size);
|
void SetStream(const void* ptr, Nz::UInt64 size);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#ifndef NAZARA_ENUMS_CORE_HPP
|
#ifndef NAZARA_ENUMS_CORE_HPP
|
||||||
#define NAZARA_ENUMS_CORE_HPP
|
#define NAZARA_ENUMS_CORE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Flags.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
enum CoordSys
|
enum CoordSys
|
||||||
|
|
@ -73,23 +75,31 @@ namespace Nz
|
||||||
HashType_Max = HashType_Whirlpool
|
HashType_Max = HashType_Whirlpool
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OpenModeFlags
|
enum OpenMode
|
||||||
{
|
{
|
||||||
OpenMode_NotOpen = 0x00, // Use the current mod of opening
|
OpenMode_NotOpen, // Use the current mod of opening
|
||||||
|
|
||||||
OpenMode_Append = 0x01, // Disable writing on existing parts and put the cursor at the end
|
OpenMode_Append, // Disable writing on existing parts and put the cursor at the end
|
||||||
OpenMode_Lock = 0x02, // Disable modifying the file before it is open
|
OpenMode_Lock, // Disable modifying the file before it is open
|
||||||
OpenMode_MustExit = 0x04, // Fail if the file doesn't exists, even if opened in write mode
|
OpenMode_MustExist, // Fail if the file doesn't exists, even if opened in write mode
|
||||||
OpenMode_ReadOnly = 0x08, // Open in read only
|
OpenMode_ReadOnly, // Open in read only
|
||||||
OpenMode_Text = 0x10, // Open in text mod
|
OpenMode_Text, // Open in text mod
|
||||||
OpenMode_Truncate = 0x20, // Create the file if it doesn't exist and empty it if it exists
|
OpenMode_Truncate, // Create the file if it doesn't exist and empty it if it exists
|
||||||
OpenMode_WriteOnly = 0x40, // Open in write only, create the file if it doesn't exist
|
OpenMode_WriteOnly, // Open in write only, create the file if it doesn't exist
|
||||||
|
|
||||||
OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly, // Open in read and write
|
OpenMode_Max = OpenMode_WriteOnly
|
||||||
|
|
||||||
OpenMode_Max = OpenMode_WriteOnly * 2 - 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct EnableFlagsOperators<OpenMode>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
using OpenModeFlags = Flags<OpenMode>;
|
||||||
|
|
||||||
|
constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly;
|
||||||
|
|
||||||
enum ParameterType
|
enum ParameterType
|
||||||
{
|
{
|
||||||
ParameterType_Boolean,
|
ParameterType_Boolean,
|
||||||
|
|
@ -173,16 +183,24 @@ namespace Nz
|
||||||
SphereType_Max = SphereType_UV
|
SphereType_Max = SphereType_UV
|
||||||
};
|
};
|
||||||
|
|
||||||
enum StreamOptionFlags
|
enum StreamOption
|
||||||
{
|
{
|
||||||
StreamOption_None = 0,
|
StreamOption_None,
|
||||||
|
|
||||||
StreamOption_Sequential = 0x1,
|
StreamOption_Sequential,
|
||||||
StreamOption_Text = 0x2,
|
StreamOption_Text,
|
||||||
|
|
||||||
StreamOption_Max = StreamOption_Text * 2 - 1
|
StreamOption_Max = StreamOption_Text
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct EnableFlagsOperators<StreamOption>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
using StreamOptionFlags = Flags<StreamOption>;
|
||||||
|
|
||||||
enum Ternary
|
enum Ternary
|
||||||
{
|
{
|
||||||
Ternary_False,
|
Ternary_False,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
File();
|
File();
|
||||||
File(const String& filePath);
|
File(const String& filePath);
|
||||||
File(const String& filePath, UInt32 openMode);
|
File(const String& filePath, OpenModeFlags openMode);
|
||||||
File(const File&) = delete;
|
File(const File&) = delete;
|
||||||
File(File&& file) noexcept;
|
File(File&& file) noexcept;
|
||||||
~File();
|
~File();
|
||||||
|
|
@ -57,8 +57,8 @@ namespace Nz
|
||||||
|
|
||||||
bool IsOpen() const;
|
bool IsOpen() const;
|
||||||
|
|
||||||
bool Open(unsigned int openMode = OpenMode_NotOpen);
|
bool Open(OpenModeFlags openMode = OpenMode_NotOpen);
|
||||||
bool Open(const String& filePath, unsigned int openMode = OpenMode_NotOpen);
|
bool Open(const String& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
|
||||||
|
|
||||||
bool Rename(const String& newFilePath);
|
bool Rename(const String& newFilePath);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
// Copyright (C) 2016 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_FLAGS_HPP
|
||||||
|
#define NAZARA_FLAGS_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template<typename E>
|
||||||
|
class Flags
|
||||||
|
{
|
||||||
|
static_assert(std::is_enum<E>::value, "Type must be an enumeration");
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr Flags(UInt32 value);
|
||||||
|
constexpr Flags(E enumVal);
|
||||||
|
|
||||||
|
explicit constexpr operator bool() const;
|
||||||
|
explicit constexpr operator UInt32() const;
|
||||||
|
|
||||||
|
constexpr Flags operator~() const;
|
||||||
|
constexpr Flags operator&(Flags rhs) const;
|
||||||
|
constexpr Flags operator|(Flags rhs) const;
|
||||||
|
constexpr Flags operator^(Flags rhs) const;
|
||||||
|
|
||||||
|
constexpr bool operator==(Flags rhs) const;
|
||||||
|
constexpr bool operator!=(Flags rhs) const;
|
||||||
|
|
||||||
|
/*constexpr*/ Flags& operator|=(Flags rhs);
|
||||||
|
/*constexpr*/ Flags& operator&=(Flags rhs);
|
||||||
|
/*constexpr*/ Flags& operator^=(Flags rhs);
|
||||||
|
|
||||||
|
static constexpr UInt32 GetFlagValue(E enumValue);
|
||||||
|
|
||||||
|
private:
|
||||||
|
UInt32 m_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
// From: https://www.justsoftwaresolutions.co.uk/cplusplus/using-enum-classes-as-bitfields.html
|
||||||
|
template<typename E>
|
||||||
|
struct EnableFlagsOperators
|
||||||
|
{
|
||||||
|
static constexpr bool value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator~(E lhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator|(E lhs, E rhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator&(E lhs, E rhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator^(E lhs, E rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/Flags.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_FLAGS_HPP
|
||||||
|
|
@ -0,0 +1,134 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/Flags.hpp>
|
||||||
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* \ingroup core
|
||||||
|
* \class Nz::Flags
|
||||||
|
* \brief Core class that represents a set of bits
|
||||||
|
*
|
||||||
|
* This class meets the requirements of Container, AllocatorAwareContainer, SequenceContainer
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E>::Flags(UInt32 value) :
|
||||||
|
m_value(value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E>::Flags(E enumVal) :
|
||||||
|
Flags(GetFlagValue(enumVal))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E>::operator bool() const
|
||||||
|
{
|
||||||
|
return m_value != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E>::operator UInt32() const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E> Flags<E>::operator~() const
|
||||||
|
{
|
||||||
|
return Flags(~m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E> Flags<E>::operator&(Flags rhs) const
|
||||||
|
{
|
||||||
|
return Flags(m_value & rhs.m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E> Flags<E>::operator|(Flags rhs) const
|
||||||
|
{
|
||||||
|
return Flags(m_value | rhs.m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E> Flags<E>::operator^(Flags rhs) const
|
||||||
|
{
|
||||||
|
return Flags(m_value ^ rhs.m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr bool Flags<E>::operator==(Flags rhs) const
|
||||||
|
{
|
||||||
|
return m_value == rhs.m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr bool Flags<E>::operator!=(Flags rhs) const
|
||||||
|
{
|
||||||
|
return !operator==(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
/*constexpr*/ Flags<E>& Flags<E>::operator|=(Flags rhs)
|
||||||
|
{
|
||||||
|
m_value |= rhs.m_value;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
/*constexpr*/ Flags<E>& Flags<E>::operator&=(Flags rhs)
|
||||||
|
{
|
||||||
|
m_value &= rhs.m_value;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
/*constexpr*/ Flags<E>& Flags<E>::operator^=(Flags rhs)
|
||||||
|
{
|
||||||
|
m_value ^= rhs.m_value;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr UInt32 Flags<E>::GetFlagValue(E enumValue)
|
||||||
|
{
|
||||||
|
return 1U << static_cast<UInt32>(enumValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator~(E lhs)
|
||||||
|
{
|
||||||
|
return ~Flags<E>(lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator|(E lhs, E rhs)
|
||||||
|
{
|
||||||
|
return Flags<E>(lhs) | rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator&(E lhs, E rhs)
|
||||||
|
{
|
||||||
|
return Flags<E>(lhs) & rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator^(E lhs, E rhs)
|
||||||
|
{
|
||||||
|
return Flags<E>(lhs) ^ rhs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline MemoryStream();
|
inline MemoryStream();
|
||||||
inline MemoryStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
inline MemoryStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
|
||||||
MemoryStream(const MemoryStream&) = default;
|
MemoryStream(const MemoryStream&) = default;
|
||||||
MemoryStream(MemoryStream&&) = default;
|
MemoryStream(MemoryStream&&) = default;
|
||||||
~MemoryStream() = default;
|
~MemoryStream() = default;
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Nz
|
||||||
UInt64 GetCursorPos() const override;
|
UInt64 GetCursorPos() const override;
|
||||||
UInt64 GetSize() const override;
|
UInt64 GetSize() const override;
|
||||||
|
|
||||||
void SetBuffer(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
void SetBuffer(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
|
||||||
bool SetCursorPos(UInt64 offset) override;
|
bool SetCursorPos(UInt64 offset) override;
|
||||||
|
|
||||||
MemoryStream& operator=(const MemoryStream&) = default;
|
MemoryStream& operator=(const MemoryStream&) = default;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Nz
|
||||||
* \param byteArray Bytes to stream
|
* \param byteArray Bytes to stream
|
||||||
* \param openMode Reading/writing mode for the stream
|
* \param openMode Reading/writing mode for the stream
|
||||||
*/
|
*/
|
||||||
inline MemoryStream::MemoryStream(ByteArray* byteArray, UInt32 openMode) :
|
inline MemoryStream::MemoryStream(ByteArray* byteArray, OpenModeFlags openMode) :
|
||||||
MemoryStream()
|
MemoryStream()
|
||||||
{
|
{
|
||||||
SetBuffer(byteArray, openMode);
|
SetBuffer(byteArray, openMode);
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ namespace Nz
|
||||||
virtual UInt64 GetCursorPos() const = 0;
|
virtual UInt64 GetCursorPos() const = 0;
|
||||||
virtual String GetDirectory() const;
|
virtual String GetDirectory() const;
|
||||||
virtual String GetPath() const;
|
virtual String GetPath() const;
|
||||||
inline UInt32 GetOpenMode() const;
|
inline OpenModeFlags GetOpenMode() const;
|
||||||
inline UInt32 GetStreamOptions() const;
|
inline StreamOptionFlags GetStreamOptions() const;
|
||||||
|
|
||||||
virtual UInt64 GetSize() const = 0;
|
virtual UInt64 GetSize() const = 0;
|
||||||
|
|
||||||
|
|
@ -55,14 +55,14 @@ namespace Nz
|
||||||
Stream& operator=(Stream&&) = default;
|
Stream& operator=(Stream&&) = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
inline Stream(UInt32 streamOptions = StreamOption_None, UInt32 openMode = OpenMode_NotOpen);
|
inline Stream(StreamOptionFlags streamOptions = StreamOption_None, OpenModeFlags openMode = OpenMode_NotOpen);
|
||||||
|
|
||||||
virtual void FlushStream() = 0;
|
virtual void FlushStream() = 0;
|
||||||
virtual std::size_t ReadBlock(void* buffer, std::size_t size) = 0;
|
virtual std::size_t ReadBlock(void* buffer, std::size_t size) = 0;
|
||||||
virtual std::size_t WriteBlock(const void* buffer, std::size_t size) = 0;
|
virtual std::size_t WriteBlock(const void* buffer, std::size_t size) = 0;
|
||||||
|
|
||||||
UInt32 m_openMode;
|
OpenModeFlags m_openMode;
|
||||||
UInt32 m_streamOptions;
|
StreamOptionFlags m_streamOptions;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Nz
|
||||||
* \param openMode Reading/writing mode for the stream
|
* \param openMode Reading/writing mode for the stream
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline Stream::Stream(UInt32 streamOptions, UInt32 openMode) :
|
inline Stream::Stream(StreamOptionFlags streamOptions, OpenModeFlags openMode) :
|
||||||
m_openMode(openMode),
|
m_openMode(openMode),
|
||||||
m_streamOptions(streamOptions)
|
m_streamOptions(streamOptions)
|
||||||
{
|
{
|
||||||
|
|
@ -53,7 +53,7 @@ namespace Nz
|
||||||
* \return Reading/writing mode for the stream
|
* \return Reading/writing mode for the stream
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline UInt32 Stream::GetOpenMode() const
|
inline OpenModeFlags Stream::GetOpenMode() const
|
||||||
{
|
{
|
||||||
return m_openMode;
|
return m_openMode;
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +63,7 @@ namespace Nz
|
||||||
* \return Options of the stream
|
* \return Options of the stream
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline UInt32 Stream::GetStreamOptions() const
|
inline StreamOptionFlags Stream::GetStreamOptions() const
|
||||||
{
|
{
|
||||||
return m_streamOptions;
|
return m_streamOptions;
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +116,7 @@ namespace Nz
|
||||||
* \param size Size meant to be read
|
* \param size Size meant to be read
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraAssert if stream is not readable
|
* \remark Produces a NazaraAssert if stream is not readable
|
||||||
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
|
* \remark If preallocated space of buffer is less than the size, the behavior is undefined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline std::size_t Stream::Read(void* buffer, std::size_t size)
|
inline std::size_t Stream::Read(void* buffer, std::size_t size)
|
||||||
|
|
@ -134,7 +134,7 @@ namespace Nz
|
||||||
* \param size Size meant to be written
|
* \param size Size meant to be written
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraAssert if stream is not writable
|
* \remark Produces a NazaraAssert if stream is not writable
|
||||||
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
|
* \remark If preallocated space of buffer is less than the size, the behavior is undefined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline std::size_t Stream::Write(const void* buffer, std::size_t size)
|
inline std::size_t Stream::Write(const void* buffer, std::size_t size)
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
m_scale = scale;
|
m_scale = scale;
|
||||||
|
|
||||||
|
InvalidateBoundingVolume();
|
||||||
InvalidateVertices();
|
InvalidateVertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <Nazara/Lua/LuaInstance.hpp>
|
#include <Nazara/Lua/LuaInstance.hpp>
|
||||||
#include <Nazara/Core/Algorithm.hpp>
|
#include <Nazara/Core/Algorithm.hpp>
|
||||||
|
#include <Nazara/Core/Flags.hpp>
|
||||||
#include <Nazara/Core/MemoryHelper.hpp>
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
#include <Nazara/Core/StringStream.hpp>
|
#include <Nazara/Core/StringStream.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
@ -99,19 +100,50 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
std::enable_if_t<std::is_enum<T>::value && !EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
||||||
{
|
{
|
||||||
using UnderlyingT = std::underlying_type_t<T>;
|
using UnderlyingT = std::underlying_type_t<T>;
|
||||||
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), TypeTag<UnderlyingT>());
|
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), TypeTag<UnderlyingT>());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
|
std::enable_if_t<std::is_enum<T>::value && !EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
|
||||||
{
|
{
|
||||||
using UnderlyingT = std::underlying_type_t<T>;
|
using UnderlyingT = std::underlying_type_t<T>;
|
||||||
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
|
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::enable_if_t<std::is_enum<T>::value && EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
||||||
|
{
|
||||||
|
using UnderlyingT = std::underlying_type_t<T>;
|
||||||
|
|
||||||
|
UnderlyingT pot2Val;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, TypeTag<UnderlyingT>());
|
||||||
|
|
||||||
|
*arg = static_cast<T>(IntegralLog2Pot(pot2Val));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::enable_if_t<std::is_enum<T>::value && EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
|
||||||
|
{
|
||||||
|
using UnderlyingT = std::underlying_type_t<T>;
|
||||||
|
|
||||||
|
UnderlyingT pot2Val;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, 1U << static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
|
||||||
|
|
||||||
|
*arg = static_cast<T>(IntegralLog2Pot(pot2Val));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Flags<E>* arg, TypeTag<Flags<E>>)
|
||||||
|
{
|
||||||
|
*arg = Flags<E>(instance.CheckBoundInteger<UInt32>(index));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
||||||
{
|
{
|
||||||
|
|
@ -184,12 +216,26 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_enum<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
std::enable_if_t<std::is_enum<T>::value && !EnableFlagsOperators<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
||||||
{
|
{
|
||||||
using EnumT = typename std::underlying_type<T>::type;
|
using EnumT = typename std::underlying_type<T>::type;
|
||||||
return LuaImplReplyVal(instance, static_cast<EnumT>(val), TypeTag<EnumT>());
|
return LuaImplReplyVal(instance, static_cast<EnumT>(val), TypeTag<EnumT>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::enable_if_t<std::is_enum<T>::value && EnableFlagsOperators<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
||||||
|
{
|
||||||
|
Flags<T> flags(val);
|
||||||
|
return LuaImplReplyVal(instance, flags, TypeTag<decltype(flags)>());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
int LuaImplReplyVal(const LuaInstance& instance, Flags<E> val, TypeTag<Flags<E>>)
|
||||||
|
{
|
||||||
|
instance.PushInteger(UInt32(val));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_integral<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
std::enable_if_t<std::is_integral<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ namespace Nz
|
||||||
void OnEmptyStream() override;
|
void OnEmptyStream() override;
|
||||||
|
|
||||||
void FreeStream();
|
void FreeStream();
|
||||||
void InitStream(std::size_t minCapacity, UInt64 cursorPos, UInt32 openMode);
|
void InitStream(std::size_t minCapacity, UInt64 cursorPos, OpenModeFlags openMode);
|
||||||
|
|
||||||
static bool Initialize();
|
static bool Initialize();
|
||||||
static void Uninitialize();
|
static void Uninitialize();
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RenderWindow() = default;
|
RenderWindow() = default;
|
||||||
RenderWindow(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
|
RenderWindow(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
|
||||||
RenderWindow(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
|
RenderWindow(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
|
||||||
RenderWindow(const RenderWindow&) = delete;
|
RenderWindow(const RenderWindow&) = delete;
|
||||||
RenderWindow(RenderWindow&&) = delete; ///TODO
|
RenderWindow(RenderWindow&&) = delete; ///TODO
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Nz
|
||||||
bool CopyToImage(AbstractImage* image, const Vector3ui& dstPos = Vector3ui(0U)) const;
|
bool CopyToImage(AbstractImage* image, const Vector3ui& dstPos = Vector3ui(0U)) const;
|
||||||
bool CopyToImage(AbstractImage* image, const Rectui& rect, const Vector3ui& dstPos = Vector3ui(0U)) const;
|
bool CopyToImage(AbstractImage* image, const Rectui& rect, const Vector3ui& dstPos = Vector3ui(0U)) const;
|
||||||
|
|
||||||
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
|
bool Create(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
|
||||||
bool Create(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
|
bool Create(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
|
||||||
|
|
||||||
void Display();
|
void Display();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#ifndef NAZARA_ENUMS_UTILITY_HPP
|
#ifndef NAZARA_ENUMS_UTILITY_HPP
|
||||||
#define NAZARA_ENUMS_UTILITY_HPP
|
#define NAZARA_ENUMS_UTILITY_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Flags.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
enum AnimationType
|
enum AnimationType
|
||||||
|
|
@ -430,20 +432,29 @@ namespace Nz
|
||||||
WindowEventType_Max = WindowEventType_TextEntered
|
WindowEventType_Max = WindowEventType_TextEntered
|
||||||
};
|
};
|
||||||
|
|
||||||
enum WindowStyleFlags
|
enum WindowStyle
|
||||||
{
|
{
|
||||||
WindowStyle_None = 0x0, ///< Window has no border nor titlebar.
|
WindowStyle_None, ///< Window has no border nor titlebar.
|
||||||
WindowStyle_Fullscreen = 0x1, ///< At the window creation, the OS tries to set it in fullscreen.
|
WindowStyle_Fullscreen, ///< At the window creation, the OS tries to set it in fullscreen.
|
||||||
|
|
||||||
WindowStyle_Closable = 0x2, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
|
WindowStyle_Closable, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
|
||||||
WindowStyle_Resizable = 0x4, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
|
WindowStyle_Resizable, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
|
||||||
WindowStyle_Titlebar = 0x8, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
|
WindowStyle_Titlebar, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
|
||||||
|
|
||||||
WindowStyle_Threaded = 0x10, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
|
WindowStyle_Threaded, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
|
||||||
|
|
||||||
WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar,
|
WindowStyle_Max = WindowStyle_Threaded
|
||||||
WindowStyle_Max = WindowStyle_Threaded*2-1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct EnableFlagsOperators<WindowStyle>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
using WindowStyleFlags = Flags<WindowStyle>;
|
||||||
|
|
||||||
|
constexpr WindowStyleFlags WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NAZARA_ENUMS_UTILITY_HPP
|
#endif // NAZARA_ENUMS_UTILITY_HPP
|
||||||
|
|
|
||||||
|
|
@ -28,25 +28,15 @@ namespace Nz
|
||||||
{
|
{
|
||||||
struct NAZARA_UTILITY_API MeshParams : ResourceParameters
|
struct NAZARA_UTILITY_API MeshParams : ResourceParameters
|
||||||
{
|
{
|
||||||
MeshParams(); // Vérifie que le storage par défaut est supporté (software autrement)
|
MeshParams();
|
||||||
|
|
||||||
// La transformation appliquée à tous les sommets du mesh
|
Matrix4f matrix = Matrix4f::Identity(); ///< A matrix which will transform every vertex position
|
||||||
Matrix4f matrix = Matrix4f::Identity();
|
UInt32 storage = DataStorage_Hardware; ///< The place where the buffers will be allocated
|
||||||
|
Vector2f texCoordOffset = {0.f, 0.f}; ///< Offset to apply on the texture coordinates (not scaled)
|
||||||
// Si ceci sera le stockage utilisé par les buffers
|
Vector2f texCoordScale = {1.f, 1.f}; ///< Scale to apply on the texture coordinates
|
||||||
UInt32 storage = DataStorage_Hardware;
|
bool animated = true; ///< If true, will load an animated version of the model if possible
|
||||||
|
bool center = false; ///< If true, will center the mesh vertices around the origin
|
||||||
// Charger une version animée du mesh si possible ?
|
bool optimizeIndexBuffers = true; ///< Optimize the index buffers after loading, improve cache locality (and thus rendering speed) but increase loading time.
|
||||||
bool animated = true;
|
|
||||||
|
|
||||||
// Faut-il centrer le mesh autour de l'origine ?
|
|
||||||
bool center = false;
|
|
||||||
|
|
||||||
// Faut-il retourner les UV ?
|
|
||||||
bool flipUVs = false;
|
|
||||||
|
|
||||||
// Faut-il optimiser les index buffers ? (Rendu plus rapide, mais le chargement dure plus longtemps)
|
|
||||||
bool optimizeIndexBuffers = true;
|
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Nz
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Window();
|
inline Window();
|
||||||
inline Window(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
|
||||||
inline Window(WindowHandle handle);
|
inline Window(WindowHandle handle);
|
||||||
Window(const Window&) = delete;
|
Window(const Window&) = delete;
|
||||||
inline Window(Window&& window) noexcept;
|
inline Window(Window&& window) noexcept;
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Nz
|
||||||
|
|
||||||
inline void Close();
|
inline void Close();
|
||||||
|
|
||||||
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
bool Create(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
|
||||||
bool Create(WindowHandle handle);
|
bool Create(WindowHandle handle);
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Nz
|
||||||
unsigned int GetHeight() const;
|
unsigned int GetHeight() const;
|
||||||
Vector2i GetPosition() const;
|
Vector2i GetPosition() const;
|
||||||
Vector2ui GetSize() const;
|
Vector2ui GetSize() const;
|
||||||
UInt32 GetStyle() const;
|
WindowStyleFlags GetStyle() const;
|
||||||
String GetTitle() const;
|
String GetTitle() const;
|
||||||
unsigned int GetWidth() const;
|
unsigned int GetWidth() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Window::Window(VideoMode mode, const String& title, UInt32 style) :
|
inline Window::Window(VideoMode mode, const String& title, WindowStyleFlags style) :
|
||||||
Window()
|
Window()
|
||||||
{
|
{
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ size_t StreamWrite(aiFile* file, const char* buffer, size_t size, size_t count)
|
||||||
|
|
||||||
aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMode)
|
aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMode)
|
||||||
{
|
{
|
||||||
FileIOUserdata* fileIOUserdata = reinterpret_cast<FileIOUserdata*>(fileIO->UserData);
|
FileIOUserdata* fileIOUserdata = reinterpret_cast<FileIOUserdata*>(fileIO->UserData);
|
||||||
|
|
||||||
bool isOriginalStream = (std::strcmp(filePath, fileIOUserdata->originalFilePath) == 0);
|
bool isOriginalStream = (std::strcmp(filePath, fileIOUserdata->originalFilePath) == 0);
|
||||||
if (!isOriginalStream && strstr(filePath, StreamPath) != 0)
|
if (!isOriginalStream && strstr(filePath, StreamPath) != 0)
|
||||||
|
|
@ -83,13 +83,13 @@ aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMod
|
||||||
ErrorFlags errFlags(ErrorFlag_ThrowExceptionDisabled, true);
|
ErrorFlags errFlags(ErrorFlag_ThrowExceptionDisabled, true);
|
||||||
|
|
||||||
///TODO: Move to File::DecodeOpenMode
|
///TODO: Move to File::DecodeOpenMode
|
||||||
UInt32 openModeEnum = 0;
|
OpenModeFlags openModeEnum = 0;
|
||||||
|
|
||||||
if (std::strchr(openMode, 'r'))
|
if (std::strchr(openMode, 'r'))
|
||||||
{
|
{
|
||||||
openModeEnum |= OpenMode_ReadOnly;
|
openModeEnum |= OpenMode_ReadOnly;
|
||||||
if (std::strchr(openMode, '+'))
|
if (std::strchr(openMode, '+'))
|
||||||
openModeEnum |= OpenMode_ReadWrite | OpenMode_MustExit;
|
openModeEnum |= OpenMode_ReadWrite | OpenMode_MustExist;
|
||||||
}
|
}
|
||||||
else if (std::strchr(openMode, 'w'))
|
else if (std::strchr(openMode, 'w'))
|
||||||
{
|
{
|
||||||
|
|
@ -133,10 +133,10 @@ aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMod
|
||||||
|
|
||||||
void StreamCloser(aiFileIO* fileIO, aiFile* file)
|
void StreamCloser(aiFileIO* fileIO, aiFile* file)
|
||||||
{
|
{
|
||||||
FileIOUserdata* fileIOUserdata = reinterpret_cast<FileIOUserdata*>(fileIO->UserData);
|
FileIOUserdata* fileIOUserdata = reinterpret_cast<FileIOUserdata*>(fileIO->UserData);
|
||||||
Stream* fileUserdata = reinterpret_cast<Stream*>(file->UserData);
|
Stream* fileUserdata = reinterpret_cast<Stream*>(file->UserData);
|
||||||
|
|
||||||
if (fileUserdata != fileIOUserdata->originalStream)
|
if (fileUserdata != fileIOUserdata->originalStream)
|
||||||
delete reinterpret_cast<File*>(file->UserData);
|
delete reinterpret_cast<File*>(file->UserData);
|
||||||
|
|
||||||
delete file;
|
delete file;
|
||||||
|
|
|
||||||
|
|
@ -97,17 +97,14 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters)
|
||||||
unsigned int postProcess = aiProcess_CalcTangentSpace | aiProcess_JoinIdenticalVertices
|
unsigned int postProcess = aiProcess_CalcTangentSpace | aiProcess_JoinIdenticalVertices
|
||||||
| aiProcess_MakeLeftHanded | aiProcess_Triangulate
|
| aiProcess_MakeLeftHanded | aiProcess_Triangulate
|
||||||
| aiProcess_RemoveComponent | aiProcess_GenSmoothNormals
|
| aiProcess_RemoveComponent | aiProcess_GenSmoothNormals
|
||||||
| aiProcess_SplitLargeMeshes | aiProcess_LimitBoneWeights
|
| aiProcess_SplitLargeMeshes | aiProcess_LimitBoneWeights
|
||||||
| aiProcess_ImproveCacheLocality | aiProcess_RemoveRedundantMaterials
|
| aiProcess_ImproveCacheLocality | aiProcess_RemoveRedundantMaterials
|
||||||
| aiProcess_FixInfacingNormals | aiProcess_SortByPType
|
| aiProcess_FixInfacingNormals | aiProcess_SortByPType
|
||||||
| aiProcess_FindInvalidData | aiProcess_GenUVCoords
|
| aiProcess_FindInvalidData | aiProcess_GenUVCoords
|
||||||
| aiProcess_TransformUVCoords | aiProcess_OptimizeMeshes
|
| aiProcess_TransformUVCoords | aiProcess_OptimizeMeshes
|
||||||
| aiProcess_OptimizeGraph | aiProcess_FlipWindingOrder
|
| aiProcess_OptimizeGraph | aiProcess_FlipWindingOrder
|
||||||
| aiProcess_Debone;
|
| aiProcess_Debone;
|
||||||
|
|
||||||
if (parameters.flipUVs)
|
|
||||||
postProcess |= aiProcess_FlipUVs;
|
|
||||||
|
|
||||||
if (parameters.optimizeIndexBuffers)
|
if (parameters.optimizeIndexBuffers)
|
||||||
postProcess |= aiProcess_ImproveCacheLocality;
|
postProcess |= aiProcess_ImproveCacheLocality;
|
||||||
|
|
||||||
|
|
@ -157,7 +154,7 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters)
|
||||||
if (animatedMesh)
|
if (animatedMesh)
|
||||||
{
|
{
|
||||||
mesh->CreateSkeletal(joints.size());
|
mesh->CreateSkeletal(joints.size());
|
||||||
|
|
||||||
Skeleton* skeleton = mesh->GetSkeleton();
|
Skeleton* skeleton = mesh->GetSkeleton();
|
||||||
|
|
||||||
// First, assign names
|
// First, assign names
|
||||||
|
|
@ -172,9 +169,9 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mesh->CreateStatic();
|
mesh->CreateStatic();
|
||||||
|
|
||||||
// aiMaterial index in scene => Material index and data in Mesh
|
// aiMaterial index in scene => Material index and data in Mesh
|
||||||
std::unordered_map<unsigned int, std::pair<unsigned int, ParameterList>> materials;
|
std::unordered_map<unsigned int, std::pair<std::size_t, ParameterList>> materials;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < scene->mNumMeshes; ++i)
|
for (unsigned int i = 0; i < scene->mNumMeshes; ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -219,7 +216,7 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters)
|
||||||
vertex->position = parameters.matrix * Vector3f(position.x, position.y, position.z);
|
vertex->position = parameters.matrix * Vector3f(position.x, position.y, position.z);
|
||||||
vertex->normal.Set(normal.x, normal.y, normal.z);
|
vertex->normal.Set(normal.x, normal.y, normal.z);
|
||||||
vertex->tangent.Set(tangent.x, tangent.y, tangent.z);
|
vertex->tangent.Set(tangent.x, tangent.y, tangent.z);
|
||||||
vertex->uv.Set(uv.x, uv.y);
|
vertex->uv.Set(parameters.texCoordOffset + Vector2f(uv.x, uv.y) * parameters.texCoordScale);
|
||||||
vertex++;
|
vertex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,7 +308,7 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters)
|
||||||
mesh->AddSubMesh(subMesh);
|
mesh->AddSubMesh(subMesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh->SetMaterialCount(std::max<unsigned int>(materials.size(), 1));
|
mesh->SetMaterialCount(std::max<UInt32>(materials.size(), 1));
|
||||||
for (const auto& pair : materials)
|
for (const auto& pair : materials)
|
||||||
mesh->SetMaterialData(pair.second.first, pair.second.second);
|
mesh->SetMaterialData(pair.second.first, pair.second.second);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
if (m_impl)
|
if (m_impl)
|
||||||
{
|
{
|
||||||
Stop();
|
StopThread();
|
||||||
|
|
||||||
delete m_impl;
|
delete m_impl;
|
||||||
m_impl = nullptr;
|
m_impl = nullptr;
|
||||||
|
|
@ -339,11 +339,8 @@ namespace Nz
|
||||||
{
|
{
|
||||||
NazaraAssert(m_impl, "Music not created");
|
NazaraAssert(m_impl, "Music not created");
|
||||||
|
|
||||||
if (m_impl->streaming)
|
StopThread();
|
||||||
{
|
SetPlayingOffset(0);
|
||||||
m_impl->streaming = false;
|
|
||||||
m_impl->thread.Join();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Music::FillAndQueueBuffer(unsigned int buffer)
|
bool Music::FillAndQueueBuffer(unsigned int buffer)
|
||||||
|
|
@ -442,5 +439,14 @@ namespace Nz
|
||||||
alDeleteBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers);
|
alDeleteBuffers(NAZARA_AUDIO_STREAMED_BUFFER_COUNT, buffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Music::StopThread()
|
||||||
|
{
|
||||||
|
if (m_impl->streaming)
|
||||||
|
{
|
||||||
|
m_impl->streaming = false;
|
||||||
|
m_impl->thread.Join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MusicLoader::LoaderList Music::s_loaders;
|
MusicLoader::LoaderList Music::s_loaders;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Nz
|
||||||
* \param openMode Reading/writing mode for the stream
|
* \param openMode Reading/writing mode for the stream
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ByteStream::ByteStream(ByteArray* byteArray, UInt32 openMode) :
|
ByteStream::ByteStream(ByteArray* byteArray, OpenModeFlags openMode) :
|
||||||
ByteStream()
|
ByteStream()
|
||||||
{
|
{
|
||||||
SetStream(byteArray, openMode);
|
SetStream(byteArray, openMode);
|
||||||
|
|
@ -67,7 +67,7 @@ namespace Nz
|
||||||
* \param openMode Reading/writing mode for the stream
|
* \param openMode Reading/writing mode for the stream
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ByteStream::SetStream(ByteArray* byteArray, UInt32 openMode)
|
void ByteStream::SetStream(ByteArray* byteArray, OpenModeFlags openMode)
|
||||||
{
|
{
|
||||||
std::unique_ptr<Stream> stream(new MemoryStream(byteArray, openMode));
|
std::unique_ptr<Stream> stream(new MemoryStream(byteArray, openMode));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Nz
|
||||||
* \param openMode Flag of the file
|
* \param openMode Flag of the file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
File::File(const String& filePath, UInt32 openMode) :
|
File::File(const String& filePath, OpenModeFlags openMode) :
|
||||||
File()
|
File()
|
||||||
{
|
{
|
||||||
Open(filePath, openMode);
|
Open(filePath, openMode);
|
||||||
|
|
@ -311,7 +311,7 @@ namespace Nz
|
||||||
* \remark Produces a NazaraError if OS error to open a file
|
* \remark Produces a NazaraError if OS error to open a file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool File::Open(unsigned int openMode)
|
bool File::Open(OpenModeFlags openMode)
|
||||||
{
|
{
|
||||||
NazaraLock(m_mutex)
|
NazaraLock(m_mutex)
|
||||||
|
|
||||||
|
|
@ -352,7 +352,7 @@ namespace Nz
|
||||||
* \remark Produces a NazaraError if OS error to open a file
|
* \remark Produces a NazaraError if OS error to open a file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool File::Open(const String& filePath, unsigned int openMode)
|
bool File::Open(const String& filePath, OpenModeFlags openMode)
|
||||||
{
|
{
|
||||||
NazaraLock(m_mutex)
|
NazaraLock(m_mutex)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace Nz
|
||||||
* \remark Produces a NazaraAssert if byteArray is nullptr
|
* \remark Produces a NazaraAssert if byteArray is nullptr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void MemoryStream::SetBuffer(ByteArray* byteArray, UInt32 openMode)
|
void MemoryStream::SetBuffer(ByteArray* byteArray, OpenModeFlags openMode)
|
||||||
{
|
{
|
||||||
NazaraAssert(byteArray, "Invalid ByteArray");
|
NazaraAssert(byteArray, "Invalid ByteArray");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Nz
|
||||||
return static_cast<UInt64>(position);
|
return static_cast<UInt64>(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileImpl::Open(const String& filePath, UInt32 mode)
|
bool FileImpl::Open(const String& filePath, OpenModeFlags mode)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||||
|
|
@ -66,6 +66,9 @@ namespace Nz
|
||||||
if (mode & OpenMode_Append)
|
if (mode & OpenMode_Append)
|
||||||
flags |= O_APPEND;
|
flags |= O_APPEND;
|
||||||
|
|
||||||
|
if (mode & OpenMode_MustExist)
|
||||||
|
flags &= ~O_CREAT;
|
||||||
|
|
||||||
if (mode & OpenMode_Truncate)
|
if (mode & OpenMode_Truncate)
|
||||||
flags |= O_TRUNC;
|
flags |= O_TRUNC;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Nz
|
||||||
bool EndOfFile() const;
|
bool EndOfFile() const;
|
||||||
void Flush();
|
void Flush();
|
||||||
UInt64 GetCursorPos() const;
|
UInt64 GetCursorPos() const;
|
||||||
bool Open(const String& filePath, UInt32 mode);
|
bool Open(const String& filePath, OpenModeFlags mode);
|
||||||
std::size_t Read(void* buffer, std::size_t size);
|
std::size_t Read(void* buffer, std::size_t size);
|
||||||
bool SetCursorPos(CursorPosition pos, Int64 offset);
|
bool SetCursorPos(CursorPosition pos, Int64 offset);
|
||||||
bool SetSize(UInt64 size);
|
bool SetSize(UInt64 size);
|
||||||
|
|
|
||||||
|
|
@ -55,20 +55,20 @@ namespace Nz
|
||||||
return position.QuadPart;
|
return position.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileImpl::Open(const String& filePath, UInt32 mode)
|
bool FileImpl::Open(const String& filePath, OpenModeFlags mode)
|
||||||
{
|
{
|
||||||
DWORD access = 0;
|
DWORD access = 0;
|
||||||
DWORD shareMode = FILE_SHARE_READ;
|
DWORD shareMode = FILE_SHARE_READ;
|
||||||
DWORD openMode = 0;
|
DWORD openMode = 0;
|
||||||
|
|
||||||
if (mode & OpenMode_ReadOnly)
|
if (mode & OpenMode_ReadOnly)
|
||||||
{
|
{
|
||||||
access |= GENERIC_READ;
|
access |= GENERIC_READ;
|
||||||
|
|
||||||
if (mode & OpenMode_MustExit || (mode & OpenMode_WriteOnly) == 0)
|
if (mode & OpenMode_MustExist || (mode & OpenMode_WriteOnly) == 0)
|
||||||
openMode |= OPEN_EXISTING;
|
openMode |= OPEN_EXISTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode & OpenMode_WriteOnly)
|
if (mode & OpenMode_WriteOnly)
|
||||||
{
|
{
|
||||||
if (mode & OpenMode_Append)
|
if (mode & OpenMode_Append)
|
||||||
|
|
@ -78,7 +78,7 @@ namespace Nz
|
||||||
|
|
||||||
if (mode & OpenMode_Truncate)
|
if (mode & OpenMode_Truncate)
|
||||||
openMode |= CREATE_ALWAYS;
|
openMode |= CREATE_ALWAYS;
|
||||||
else if (mode & OpenMode_MustExit)
|
else if (mode & OpenMode_MustExist)
|
||||||
openMode |= OPEN_EXISTING;
|
openMode |= OPEN_EXISTING;
|
||||||
else
|
else
|
||||||
openMode |= OPEN_ALWAYS;
|
openMode |= OPEN_ALWAYS;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
||||||
bool EndOfFile() const;
|
bool EndOfFile() const;
|
||||||
void Flush();
|
void Flush();
|
||||||
UInt64 GetCursorPos() const;
|
UInt64 GetCursorPos() const;
|
||||||
bool Open(const String& filePath, UInt32 mode);
|
bool Open(const String& filePath, OpenModeFlags mode);
|
||||||
std::size_t Read(void* buffer, std::size_t size);
|
std::size_t Read(void* buffer, std::size_t size);
|
||||||
bool SetCursorPos(CursorPosition pos, Int64 offset);
|
bool SetCursorPos(CursorPosition pos, Int64 offset);
|
||||||
bool SetSize(UInt64 size);
|
bool SetSize(UInt64 size);
|
||||||
|
|
|
||||||
|
|
@ -200,8 +200,8 @@ namespace Nz
|
||||||
void TextSprite::MakeBoundingVolume() const
|
void TextSprite::MakeBoundingVolume() const
|
||||||
{
|
{
|
||||||
Rectf bounds(m_localBounds);
|
Rectf bounds(m_localBounds);
|
||||||
Vector2f max = bounds.GetMaximum();
|
Vector2f max = m_scale * bounds.GetMaximum();
|
||||||
Vector2f min = bounds.GetMinimum();
|
Vector2f min = m_scale * bounds.GetMinimum();
|
||||||
|
|
||||||
m_boundingVolume.Set(min.x * Vector3f::Right() + min.y * Vector3f::Down(), max.x * Vector3f::Right() + max.y * Vector3f::Down());
|
m_boundingVolume.Set(min.x * Vector3f::Right() + min.y * Vector3f::Down(), max.x * Vector3f::Right() + max.y * Vector3f::Down());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ namespace Nz
|
||||||
* \remark Produces a NazaraAssert if cursor position is greather than the capacity
|
* \remark Produces a NazaraAssert if cursor position is greather than the capacity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void NetPacket::InitStream(std::size_t minCapacity, UInt64 cursorPos, UInt32 openMode)
|
void NetPacket::InitStream(std::size_t minCapacity, UInt64 cursorPos, OpenModeFlags openMode)
|
||||||
{
|
{
|
||||||
NazaraAssert(minCapacity >= cursorPos, "Cannot init stream with a smaller capacity than wanted cursor pos");
|
NazaraAssert(minCapacity >= cursorPos, "Cannot init stream with a smaller capacity than wanted cursor pos");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
RenderWindow::RenderWindow(VideoMode mode, const String& title, UInt32 style, const ContextParameters& parameters) :
|
RenderWindow::RenderWindow(VideoMode mode, const String& title, WindowStyleFlags style, const ContextParameters& parameters) :
|
||||||
RenderTarget(), Window()
|
RenderTarget(), Window()
|
||||||
{
|
{
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||||
|
|
@ -121,7 +121,7 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderWindow::Create(VideoMode mode, const String& title, UInt32 style, const ContextParameters& parameters)
|
bool RenderWindow::Create(VideoMode mode, const String& title, WindowStyleFlags style, const ContextParameters& parameters)
|
||||||
{
|
{
|
||||||
m_parameters = parameters;
|
m_parameters = parameters;
|
||||||
return Window::Create(mode, title, style);
|
return Window::Create(mode, title, style);
|
||||||
|
|
|
||||||
|
|
@ -81,15 +81,14 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Création du mesh
|
// Since the engine no longer supports keyframe animations, let's make a static mesh
|
||||||
// Le moteur ne supporte plus les animations image-clé, nous ne pouvons charger qu'en statique
|
if (!mesh->CreateStatic())
|
||||||
if (!mesh->CreateStatic()) // Ne devrait jamais échouer
|
|
||||||
{
|
{
|
||||||
NazaraInternalError("Failed to create mesh");
|
NazaraInternalError("Failed to create mesh");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Chargement des skins
|
// Extract skins (texture name)
|
||||||
if (header.num_skins > 0)
|
if (header.num_skins > 0)
|
||||||
{
|
{
|
||||||
mesh->SetMaterialCount(header.num_skins);
|
mesh->SetMaterialCount(header.num_skins);
|
||||||
|
|
@ -109,16 +108,15 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Chargement des submesh
|
|
||||||
// Actuellement le loader ne charge qu'un submesh
|
|
||||||
IndexBufferRef indexBuffer = IndexBuffer::New(false, header.num_tris*3, parameters.storage, BufferUsage_Static);
|
IndexBufferRef indexBuffer = IndexBuffer::New(false, header.num_tris*3, parameters.storage, BufferUsage_Static);
|
||||||
|
|
||||||
/// Lecture des triangles
|
// Extract triangles data
|
||||||
std::vector<MD2_Triangle> triangles(header.num_tris);
|
std::vector<MD2_Triangle> triangles(header.num_tris);
|
||||||
|
|
||||||
stream.SetCursorPos(header.offset_tris);
|
stream.SetCursorPos(header.offset_tris);
|
||||||
stream.Read(&triangles[0], header.num_tris*sizeof(MD2_Triangle));
|
stream.Read(&triangles[0], header.num_tris*sizeof(MD2_Triangle));
|
||||||
|
|
||||||
|
// And convert them into an index buffer
|
||||||
BufferMapper<IndexBuffer> indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
|
BufferMapper<IndexBuffer> indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
|
||||||
UInt16* index = static_cast<UInt16*>(indexMapper.GetPointer());
|
UInt16* index = static_cast<UInt16*>(indexMapper.GetPointer());
|
||||||
|
|
||||||
|
|
@ -135,7 +133,7 @@ namespace Nz
|
||||||
SwapBytes(&triangles[i].texCoords[2], sizeof(UInt16));
|
SwapBytes(&triangles[i].texCoords[2], sizeof(UInt16));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// On respécifie le triangle dans l'ordre attendu
|
// Reverse winding order
|
||||||
*index++ = triangles[i].vertices[0];
|
*index++ = triangles[i].vertices[0];
|
||||||
*index++ = triangles[i].vertices[2];
|
*index++ = triangles[i].vertices[2];
|
||||||
*index++ = triangles[i].vertices[1];
|
*index++ = triangles[i].vertices[1];
|
||||||
|
|
@ -143,10 +141,11 @@ namespace Nz
|
||||||
|
|
||||||
indexMapper.Unmap();
|
indexMapper.Unmap();
|
||||||
|
|
||||||
|
// Optimize if requested (improves cache locality)
|
||||||
if (parameters.optimizeIndexBuffers)
|
if (parameters.optimizeIndexBuffers)
|
||||||
indexBuffer->Optimize();
|
indexBuffer->Optimize();
|
||||||
|
|
||||||
/// Lecture des coordonnées de texture
|
// Extracting texture coordinates
|
||||||
std::vector<MD2_TexCoord> texCoords(header.num_st);
|
std::vector<MD2_TexCoord> texCoords(header.num_st);
|
||||||
|
|
||||||
stream.SetCursorPos(header.offset_st);
|
stream.SetCursorPos(header.offset_st);
|
||||||
|
|
@ -168,15 +167,15 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Chargement des vertices
|
// Extracting vertices
|
||||||
stream.SetCursorPos(header.offset_frames);
|
stream.SetCursorPos(header.offset_frames);
|
||||||
|
|
||||||
std::unique_ptr<MD2_Vertex[]> vertices(new MD2_Vertex[header.num_vertices]);
|
std::vector<MD2_Vertex> vertices(header.num_vertices);
|
||||||
Vector3f scale, translate;
|
Vector3f scale, translate;
|
||||||
stream.Read(scale, sizeof(Vector3f));
|
stream.Read(scale, sizeof(Vector3f));
|
||||||
stream.Read(translate, sizeof(Vector3f));
|
stream.Read(translate, sizeof(Vector3f));
|
||||||
stream.Read(nullptr, 16*sizeof(char)); // Nom de la frame, inutile ici
|
stream.Read(nullptr, 16*sizeof(char)); //< Frame name, unused
|
||||||
stream.Read(vertices.get(), header.num_vertices*sizeof(MD2_Vertex));
|
stream.Read(vertices.data(), header.num_vertices*sizeof(MD2_Vertex));
|
||||||
|
|
||||||
#ifdef NAZARA_BIG_ENDIAN
|
#ifdef NAZARA_BIG_ENDIAN
|
||||||
SwapBytes(&scale.x, sizeof(float));
|
SwapBytes(&scale.x, sizeof(float));
|
||||||
|
|
@ -196,23 +195,26 @@ namespace Nz
|
||||||
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite);
|
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite);
|
||||||
MeshVertex* vertex = static_cast<MeshVertex*>(vertexMapper.GetPointer());
|
MeshVertex* vertex = static_cast<MeshVertex*>(vertexMapper.GetPointer());
|
||||||
|
|
||||||
/// Chargement des coordonnées de texture
|
// Loading texture coordinates
|
||||||
const unsigned int indexFix[3] = {0, 2, 1}; // Pour respécifier les indices dans le bon ordre
|
const unsigned int indexFix[3] = {0, 2, 1};
|
||||||
|
Vector2f invSkinSize(1.f / header.skinwidth, 1.f / header.skinheight);
|
||||||
for (unsigned int i = 0; i < header.num_tris; ++i)
|
for (unsigned int i = 0; i < header.num_tris; ++i)
|
||||||
{
|
{
|
||||||
for (unsigned int j = 0; j < 3; ++j)
|
for (unsigned int j = 0; j < 3; ++j)
|
||||||
{
|
{
|
||||||
const unsigned int fixedIndex = indexFix[j];
|
const unsigned int fixedIndex = indexFix[j]; //< Reverse winding order
|
||||||
const MD2_TexCoord& texC = texCoords[triangles[i].texCoords[fixedIndex]];
|
|
||||||
float u = static_cast<float>(texC.u) / header.skinwidth;
|
|
||||||
float v = static_cast<float>(texC.v) / header.skinheight;
|
|
||||||
|
|
||||||
vertex[triangles[i].vertices[fixedIndex]].uv.Set(u, (parameters.flipUVs) ? 1.f - v : v);
|
const MD2_TexCoord& texC = texCoords[triangles[i].texCoords[fixedIndex]];
|
||||||
|
Vector2f uv(texC.u, texC.v);
|
||||||
|
uv *= invSkinSize;
|
||||||
|
|
||||||
|
vertex[triangles[i].vertices[fixedIndex]].uv.Set(parameters.texCoordOffset + uv * parameters.texCoordScale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Chargement des positions
|
// Loading vertex position
|
||||||
// Pour que le modèle soit correctement aligné, on génère un quaternion que nous appliquerons à chacune des vertices
|
|
||||||
|
// Align the model to our coordinates system
|
||||||
Quaternionf rotationQuat = EulerAnglesf(-90.f, 90.f, 0.f);
|
Quaternionf rotationQuat = EulerAnglesf(-90.f, 90.f, 0.f);
|
||||||
Nz::Matrix4f matrix = Matrix4f::Transform(translate, rotationQuat, scale);
|
Nz::Matrix4f matrix = Matrix4f::Transform(translate, rotationQuat, scale);
|
||||||
matrix *= parameters.matrix;
|
matrix *= parameters.matrix;
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices->position = finalPos;
|
vertices->position = finalPos;
|
||||||
vertices->uv.Set(vertex.uv.x, (parameters.flipUVs) ? 1.f - vertex.uv.y : vertex.uv.y); // Inversion des UV si demandé
|
vertices->uv.Set(parameters.texCoordOffset + vertex.uv * parameters.texCoordScale);
|
||||||
vertices++;
|
vertices++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,7 +254,7 @@ namespace Nz
|
||||||
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage);
|
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage);
|
||||||
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
|
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
|
||||||
|
|
||||||
MeshVertex* vertex = static_cast<MeshVertex*>(vertexMapper.GetPointer());
|
MeshVertex* vertices = static_cast<MeshVertex*>(vertexMapper.GetPointer());
|
||||||
for (const MD5MeshParser::Vertex& md5Vertex : md5Mesh.vertices)
|
for (const MD5MeshParser::Vertex& md5Vertex : md5Mesh.vertices)
|
||||||
{
|
{
|
||||||
// Skinning MD5 (Formule d'Id Tech)
|
// Skinning MD5 (Formule d'Id Tech)
|
||||||
|
|
@ -268,9 +268,9 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
// On retourne le modèle dans le bon sens
|
// On retourne le modèle dans le bon sens
|
||||||
vertex->position = matrix * finalPos;
|
vertices->position = matrix * finalPos;
|
||||||
vertex->uv.Set(md5Vertex.uv.x, (parameters.flipUVs) ? 1.f - md5Vertex.uv.y : md5Vertex.uv.y); // Inversion des UV si demandé
|
vertices->uv.Set(parameters.texCoordOffset + md5Vertex.uv * parameters.texCoordScale);
|
||||||
vertex++;
|
vertices++;
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexMapper.Unmap();
|
vertexMapper.Unmap();
|
||||||
|
|
|
||||||
|
|
@ -265,8 +265,8 @@ namespace Nz
|
||||||
|
|
||||||
if (vertexIndices.texCoord > 0)
|
if (vertexIndices.texCoord > 0)
|
||||||
{
|
{
|
||||||
const Vector3f& uvw = texCoords[vertexIndices.texCoord-1];
|
Vector2f uv = Vector2f(texCoords[vertexIndices.texCoord - 1]);
|
||||||
vertex.uv.Set(uvw.x, (parameters.flipUVs) ? 1.f - uvw.y : uvw.y); // Inversion des UVs si demandé
|
vertex.uv.Set(parameters.texCoordOffset + uv * parameters.texCoordScale);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hasTexCoords = false;
|
hasTexCoords = false;
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowImpl::Create(const VideoMode& mode, const String& title, UInt32 style)
|
bool WindowImpl::Create(const VideoMode& mode, const String& title, WindowStyleFlags style)
|
||||||
{
|
{
|
||||||
bool async = (style & WindowStyle_Threaded) != 0;
|
bool async = (style & WindowStyle_Threaded) != 0;
|
||||||
bool fullscreen = (style & WindowStyle_Fullscreen) != 0;
|
bool fullscreen = (style & WindowStyle_Fullscreen) != 0;
|
||||||
|
|
@ -259,7 +259,7 @@ namespace Nz
|
||||||
return m_size;
|
return m_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 WindowImpl::GetStyle() const
|
WindowStyleFlags WindowImpl::GetStyle() const
|
||||||
{
|
{
|
||||||
return m_style;
|
return m_style;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ namespace Nz
|
||||||
WindowImpl(WindowImpl&&) = delete; ///TODO?
|
WindowImpl(WindowImpl&&) = delete; ///TODO?
|
||||||
~WindowImpl() = default;
|
~WindowImpl() = default;
|
||||||
|
|
||||||
bool Create(const VideoMode& mode, const String& title, UInt32 style);
|
bool Create(const VideoMode& mode, const String& title, WindowStyleFlags style);
|
||||||
bool Create(WindowHandle handle);
|
bool Create(WindowHandle handle);
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Nz
|
||||||
unsigned int GetHeight() const;
|
unsigned int GetHeight() const;
|
||||||
Vector2i GetPosition() const;
|
Vector2i GetPosition() const;
|
||||||
Vector2ui GetSize() const;
|
Vector2ui GetSize() const;
|
||||||
UInt32 GetStyle() const;
|
WindowStyleFlags GetStyle() const;
|
||||||
String GetTitle() const;
|
String GetTitle() const;
|
||||||
unsigned int GetWidth() const;
|
unsigned int GetWidth() const;
|
||||||
|
|
||||||
|
|
@ -93,7 +93,7 @@ namespace Nz
|
||||||
HCURSOR m_cursor;
|
HCURSOR m_cursor;
|
||||||
HWND m_handle;
|
HWND m_handle;
|
||||||
LONG_PTR m_callback;
|
LONG_PTR m_callback;
|
||||||
UInt32 m_style;
|
WindowStyleFlags m_style;
|
||||||
Vector2i m_maxSize;
|
Vector2i m_maxSize;
|
||||||
Vector2i m_minSize;
|
Vector2i m_minSize;
|
||||||
Vector2i m_mousePos;
|
Vector2i m_mousePos;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ namespace Nz
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::Create(VideoMode mode, const String& title, UInt32 style)
|
bool Window::Create(VideoMode mode, const String& title, WindowStyleFlags style)
|
||||||
{
|
{
|
||||||
// Si la fenêtre est déjà ouverte, nous conservons sa position
|
// Si la fenêtre est déjà ouverte, nous conservons sa position
|
||||||
bool opened = IsOpen();
|
bool opened = IsOpen();
|
||||||
|
|
@ -228,7 +228,7 @@ namespace Nz
|
||||||
return m_impl->GetSize();
|
return m_impl->GetSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 Window::GetStyle() const
|
WindowStyleFlags Window::GetStyle() const
|
||||||
{
|
{
|
||||||
#if NAZARA_UTILITY_SAFE
|
#if NAZARA_UTILITY_SAFE
|
||||||
if (!m_impl)
|
if (!m_impl)
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ namespace Nz
|
||||||
UpdateEventQueue(nullptr);
|
UpdateEventQueue(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WindowImpl::Create(const VideoMode& mode, const String& title, UInt32 style)
|
bool WindowImpl::Create(const VideoMode& mode, const String& title, WindowStyleFlags style)
|
||||||
{
|
{
|
||||||
bool fullscreen = (style & Nz::WindowStyle_Fullscreen) != 0;
|
bool fullscreen = (style & Nz::WindowStyle_Fullscreen) != 0;
|
||||||
m_eventListener = true;
|
m_eventListener = true;
|
||||||
|
|
@ -336,7 +336,7 @@ namespace Nz
|
||||||
return Vector2ui(m_size_hints.width, m_size_hints.height);
|
return Vector2ui(m_size_hints.width, m_size_hints.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 WindowImpl::GetStyle() const
|
WindowStyleFlags WindowImpl::GetStyle() const
|
||||||
{
|
{
|
||||||
return m_style;
|
return m_style;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Nz
|
||||||
WindowImpl(WindowImpl&&) = delete; ///TODO?
|
WindowImpl(WindowImpl&&) = delete; ///TODO?
|
||||||
~WindowImpl();
|
~WindowImpl();
|
||||||
|
|
||||||
bool Create(const VideoMode& mode, const String& title, UInt32 style);
|
bool Create(const VideoMode& mode, const String& title, WindowStyleFlags style);
|
||||||
bool Create(WindowHandle handle);
|
bool Create(WindowHandle handle);
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
@ -47,7 +47,7 @@ namespace Nz
|
||||||
unsigned int GetHeight() const;
|
unsigned int GetHeight() const;
|
||||||
Vector2i GetPosition() const;
|
Vector2i GetPosition() const;
|
||||||
Vector2ui GetSize() const;
|
Vector2ui GetSize() const;
|
||||||
UInt32 GetStyle() const;
|
WindowStyleFlags GetStyle() const;
|
||||||
String GetTitle() const;
|
String GetTitle() const;
|
||||||
unsigned int GetWidth() const;
|
unsigned int GetWidth() const;
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ namespace Nz
|
||||||
xcb_randr_get_screen_info_reply_t m_oldVideoMode;
|
xcb_randr_get_screen_info_reply_t m_oldVideoMode;
|
||||||
xcb_size_hints_t m_size_hints;
|
xcb_size_hints_t m_size_hints;
|
||||||
Thread m_thread;
|
Thread m_thread;
|
||||||
UInt32 m_style;
|
WindowStyleFlags m_style;
|
||||||
Window* m_parent;
|
Window* m_parent;
|
||||||
bool m_eventListener;
|
bool m_eventListener;
|
||||||
bool m_ownsWindow;
|
bool m_ownsWindow;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue