Merge remote-tracking branch 'refs/remotes/origin/master' into gui

This commit is contained in:
Lynix
2016-10-27 18:36:47 +02:00
179 changed files with 5443 additions and 2071 deletions

View File

@@ -374,8 +374,8 @@ namespace Ndk
}
inline Application::WindowInfo::WindowInfo(std::unique_ptr<Nz::Window>&& window) :
window(std::move(window)),
renderTarget(nullptr)
renderTarget(nullptr),
window(std::move(window))
{
}
#endif

View File

@@ -15,8 +15,8 @@ namespace Ndk
*/
inline BaseSystem::BaseSystem(SystemIndex systemId) :
m_updateEnabled(true),
m_systemIndex(systemId)
m_systemIndex(systemId),
m_updateEnabled(true)
{
SetUpdateRate(30);
}

View File

@@ -6,14 +6,14 @@
#define NDK_COMPONENTS_GLOBAL_HPP
#include <NDK/Components/CameraComponent.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/ListenerComponent.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/ParticleEmitterComponent.hpp>
#include <NDK/Components/ParticleGroupComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Components/VelocityComponent.hpp>
#endif // NDK_COMPONENTS_GLOBAL_HPP

View File

@@ -7,53 +7,53 @@
#ifndef NDK_COMPONENTS_COLLISIONCOMPONENT_HPP
#define NDK_COMPONENTS_COLLISIONCOMPONENT_HPP
#include <Nazara/Physics/Geom.hpp>
#include <Nazara/Physics3D/Collider3D.hpp>
#include <NDK/Component.hpp>
#include <memory>
namespace Nz
{
class PhysObject;
class RigidBody3D;
}
namespace Ndk
{
class Entity;
class NDK_API CollisionComponent : public Component<CollisionComponent>
class NDK_API CollisionComponent3D : public Component<CollisionComponent3D>
{
friend class PhysicsSystem;
friend class PhysicsSystem3D;
friend class StaticCollisionSystem;
public:
CollisionComponent(Nz::PhysGeomRef geom = Nz::PhysGeomRef());
CollisionComponent(const CollisionComponent& collision);
~CollisionComponent() = default;
CollisionComponent3D(Nz::Collider3DRef geom = Nz::Collider3DRef());
CollisionComponent3D(const CollisionComponent3D& collision);
~CollisionComponent3D() = default;
const Nz::PhysGeomRef& GetGeom() const;
const Nz::Collider3DRef& GetGeom() const;
void SetGeom(Nz::PhysGeomRef geom);
void SetGeom(Nz::Collider3DRef geom);
CollisionComponent& operator=(Nz::PhysGeomRef geom);
CollisionComponent& operator=(CollisionComponent&& collision) = default;
CollisionComponent3D& operator=(Nz::Collider3DRef geom);
CollisionComponent3D& operator=(CollisionComponent3D&& collision) = default;
static ComponentIndex componentIndex;
private:
void InitializeStaticBody();
Nz::PhysObject* GetStaticBody();
Nz::RigidBody3D* GetStaticBody();
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
std::unique_ptr<Nz::PhysObject> m_staticBody;
Nz::PhysGeomRef m_geom;
std::unique_ptr<Nz::RigidBody3D> m_staticBody;
Nz::Collider3DRef m_geom;
bool m_bodyUpdated;
};
}
#include <NDK/Components/CollisionComponent.inl>
#include <NDK/Components/CollisionComponent3D.inl>
#endif // NDK_COMPONENTS_COLLISIONCOMPONENT_HPP

View File

@@ -4,30 +4,30 @@
#include <NDK/Entity.hpp>
#include <NDK/World.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
namespace Ndk
{
/*!
* \brief Constructs a CollisionComponent object with a geometry
* \brief Constructs a CollisionComponent3D object with a geometry
*
* \param geom Reference to a geometry symbolizing the entity
*/
inline CollisionComponent::CollisionComponent(Nz::PhysGeomRef geom) :
inline CollisionComponent3D::CollisionComponent3D(Nz::Collider3DRef geom) :
m_geom(std::move(geom)),
m_bodyUpdated(false)
{
}
/*!
* \brief Constructs a CollisionComponent object by copy semantic
* \brief Constructs a CollisionComponent3D object by copy semantic
*
* \param collision CollisionComponent to copy
* \param collision CollisionComponent3D to copy
*/
inline CollisionComponent::CollisionComponent(const CollisionComponent& collision) :
inline CollisionComponent3D::CollisionComponent3D(const CollisionComponent3D& collision) :
m_geom(collision.m_geom),
m_bodyUpdated(false)
{
@@ -38,7 +38,7 @@ namespace Ndk
* \return A constant reference to the physics geometry
*/
inline const Nz::PhysGeomRef& CollisionComponent::GetGeom() const
inline const Nz::Collider3DRef& CollisionComponent3D::GetGeom() const
{
return m_geom;
}
@@ -50,7 +50,7 @@ namespace Ndk
* \param geom Reference to a geometry symbolizing the entity
*/
inline CollisionComponent& CollisionComponent::operator=(Nz::PhysGeomRef geom)
inline CollisionComponent3D& CollisionComponent3D::operator=(Nz::Collider3DRef geom)
{
SetGeom(geom);
@@ -62,7 +62,7 @@ namespace Ndk
* \return A pointer to the entity
*/
inline Nz::PhysObject* CollisionComponent::GetStaticBody()
inline Nz::RigidBody3D* CollisionComponent3D::GetStaticBody()
{
return m_staticBody.get();
}

View File

@@ -74,11 +74,11 @@ namespace Ndk
}
Renderable(Renderable&& renderable) noexcept :
renderableInvalidationSlot(std::move(renderable.renderableInvalidationSlot)),
renderableReleaseSlot(std::move(renderable.renderableReleaseSlot)),
data(std::move(renderable.data)),
renderable(std::move(renderable.renderable)),
dataUpdated(renderable.dataUpdated),
renderableInvalidationSlot(std::move(renderable.renderableInvalidationSlot)),
renderableReleaseSlot(std::move(renderable.renderableReleaseSlot))
dataUpdated(renderable.dataUpdated)
{
}

View File

@@ -4,10 +4,10 @@
#pragma once
#ifndef NDK_COMPONENTS_PHYSICSCOMPONENT_HPP
#define NDK_COMPONENTS_PHYSICSCOMPONENT_HPP
#ifndef NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP
#define NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP
#include <Nazara/Physics/PhysObject.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NDK/Component.hpp>
#include <memory>
@@ -15,15 +15,15 @@ namespace Ndk
{
class Entity;
class NDK_API PhysicsComponent : public Component<PhysicsComponent>
class NDK_API PhysicsComponent3D : public Component<PhysicsComponent3D>
{
friend class CollisionComponent;
friend class PhysicsSystem;
friend class CollisionComponent3D;
friend class PhysicsSystem3D;
public:
PhysicsComponent() = default;
PhysicsComponent(const PhysicsComponent& physics);
~PhysicsComponent() = default;
PhysicsComponent3D() = default;
PhysicsComponent3D(const PhysicsComponent3D& physics);
~PhysicsComponent3D() = default;
void AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
@@ -56,17 +56,17 @@ namespace Ndk
static ComponentIndex componentIndex;
private:
Nz::PhysObject& GetPhysObject();
Nz::RigidBody3D& GetPhysObject();
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
std::unique_ptr<Nz::PhysObject> m_object;
std::unique_ptr<Nz::RigidBody3D> m_object;
};
}
#include <NDK/Components/PhysicsComponent.inl>
#include <NDK/Components/PhysicsComponent3D.inl>
#endif // NDK_COMPONENTS_PHYSICSCOMPONENT_HPP
#endif // NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP

View File

@@ -7,12 +7,12 @@
namespace Ndk
{
/*!
* \brief Constructs a PhysicsComponent object by copy semantic
* \brief Constructs a PhysicsComponent3D object by copy semantic
*
* \param physics PhysicsComponent to copy
* \param physics PhysicsComponent3D to copy
*/
inline PhysicsComponent::PhysicsComponent(const PhysicsComponent& physics)
inline PhysicsComponent3D::PhysicsComponent3D(const PhysicsComponent3D& physics)
{
// No copy of physical object (because we only create it when attached to an entity)
NazaraUnused(physics);
@@ -27,7 +27,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys)
inline void PhysicsComponent3D::AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -44,7 +44,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys)
inline void PhysicsComponent3D::AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -60,7 +60,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys)
inline void PhysicsComponent3D::AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -75,7 +75,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::EnableAutoSleep(bool autoSleep)
inline void PhysicsComponent3D::EnableAutoSleep(bool autoSleep)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -89,7 +89,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Boxf PhysicsComponent::GetAABB() const
inline Nz::Boxf PhysicsComponent3D::GetAABB() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -103,7 +103,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent::GetAngularVelocity() const
inline Nz::Vector3f PhysicsComponent3D::GetAngularVelocity() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -117,7 +117,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent::GetGravityFactor() const
inline float PhysicsComponent3D::GetGravityFactor() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -131,7 +131,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent::GetMass() const
inline float PhysicsComponent3D::GetMass() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -147,7 +147,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent::GetMassCenter(Nz::CoordSys coordSys) const
inline Nz::Vector3f PhysicsComponent3D::GetMassCenter(Nz::CoordSys coordSys) const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -161,7 +161,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline const Nz::Matrix4f& PhysicsComponent::GetMatrix() const
inline const Nz::Matrix4f& PhysicsComponent3D::GetMatrix() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -175,7 +175,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent::GetPosition() const
inline Nz::Vector3f PhysicsComponent3D::GetPosition() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -189,7 +189,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Quaternionf PhysicsComponent::GetRotation() const
inline Nz::Quaternionf PhysicsComponent3D::GetRotation() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -203,7 +203,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent::GetVelocity() const
inline Nz::Vector3f PhysicsComponent3D::GetVelocity() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -217,7 +217,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline bool PhysicsComponent::IsAutoSleepEnabled() const
inline bool PhysicsComponent3D::IsAutoSleepEnabled() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -231,7 +231,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline bool PhysicsComponent::IsSleeping() const
inline bool PhysicsComponent3D::IsSleeping() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -246,7 +246,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetAngularVelocity(const Nz::Vector3f& angularVelocity)
inline void PhysicsComponent3D::SetAngularVelocity(const Nz::Vector3f& angularVelocity)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -261,7 +261,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetGravityFactor(float gravityFactor)
inline void PhysicsComponent3D::SetGravityFactor(float gravityFactor)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -277,7 +277,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the mass is negative
*/
inline void PhysicsComponent::SetMass(float mass)
inline void PhysicsComponent3D::SetMass(float mass)
{
NazaraAssert(m_object, "Invalid physics object");
NazaraAssert(mass > 0.f, "Mass should be positive");
@@ -293,7 +293,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetMassCenter(const Nz::Vector3f& center)
inline void PhysicsComponent3D::SetMassCenter(const Nz::Vector3f& center)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -308,7 +308,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetPosition(const Nz::Vector3f& position)
inline void PhysicsComponent3D::SetPosition(const Nz::Vector3f& position)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -323,7 +323,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetRotation(const Nz::Quaternionf& rotation)
inline void PhysicsComponent3D::SetRotation(const Nz::Quaternionf& rotation)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -338,7 +338,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetVelocity(const Nz::Vector3f& velocity)
inline void PhysicsComponent3D::SetVelocity(const Nz::Vector3f& velocity)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -350,7 +350,7 @@ namespace Ndk
* \return A reference to the physics object
*/
inline Nz::PhysObject& PhysicsComponent::GetPhysObject()
inline Nz::RigidBody3D& PhysicsComponent3D::GetPhysObject()
{
return *m_object.get();
}

View File

@@ -12,7 +12,6 @@
namespace Ndk
{
class Entity;
class VelocityComponent;
using VelocityComponentHandle = Nz::ObjectHandle<VelocityComponent>;

View File

@@ -24,7 +24,7 @@ namespace Ndk
LuaAPI() = delete;
~LuaAPI() = delete;
static inline LuaBinding* GetBinding();
static LuaBinding* GetBinding();
static bool Initialize();

View File

@@ -10,6 +10,7 @@
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Network/IpAddress.hpp>
#include <Nazara/Utility/Font.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <NDK/Application.hpp>
#include <NDK/Components.hpp>
@@ -21,22 +22,10 @@
#include <Nazara/Audio/Music.hpp>
#include <Nazara/Audio/SoundBuffer.hpp>
#include <Nazara/Graphics/Model.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <NDK/Console.hpp>
#endif
namespace Ndk
{
/*!
* \brief Gets the internal binding for Lua
* \return A pointer to the binding
*/
inline LuaBinding* LuaAPI::GetBinding()
{
return s_binding;
}
}
namespace Nz
{
/*!
@@ -143,6 +132,104 @@ namespace Nz
return 1;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param params Resulting parameters for an image
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, ImageParams* params, TypeTag<ImageParams>)
{
instance.CheckType(index, Nz::LuaType_Table);
params->levelCount = instance.CheckField<Nz::UInt8>("LevelCount");
params->loadFormat = instance.CheckField<Nz::PixelFormatType>("LoadFormat");
return 1;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param address Resulting IP address
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag<IpAddress>)
{
switch (instance.GetType(index))
{
case Nz::LuaType_String:
address->BuildFromAddress(instance.CheckString(index));
return 1;
default:
*address = *static_cast<IpAddress*>(instance.CheckUserdata(index, "IpAddress"));
return 1;
}
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param quat Resulting quaternion
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Matrix4d* mat, TypeTag<Matrix4d>)
{
switch (instance.GetType(index))
{
case Nz::LuaType_Table:
{
double values[16];
for (std::size_t i = 0; i < 16; ++i)
{
instance.PushInteger(i + 1);
instance.GetTable();
values[i] = instance.CheckNumber(-1);
instance.Pop();
}
mat->Set(values);
return 1;
}
default:
{
if (instance.IsOfType(index, "Matrix4"))
mat->Set(*static_cast<Matrix4d*>(instance.ToUserdata(index)));
return 1;
}
}
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param quat Resulting quaternion
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Matrix4f* mat, TypeTag<Matrix4f>)
{
Matrix4d matDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &matDouble, TypeTag<Matrix4d>());
mat->Set(matDouble);
return ret;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
@@ -156,15 +243,62 @@ namespace Nz
{
instance.CheckType(index, Nz::LuaType_Table);
params->animated = instance.CheckField<bool>("Animated", params->animated);
params->center = instance.CheckField<bool>("Center", params->center);
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
//params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
params->animated = instance.CheckField<bool>("Animated", params->animated);
params->center = instance.CheckField<bool>("Center", params->center);
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
return 1;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param quat Resulting quaternion
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
{
switch (instance.GetType(index))
{
case Nz::LuaType_Table:
quat->Set(instance.CheckField<double>("w", index), instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", index));
return 1;
default:
{
if (instance.IsOfType(index, "EulerAngles"))
quat->Set(*static_cast<EulerAnglesd*>(instance.ToUserdata(index)));
else
quat->Set(*static_cast<Quaterniond*>(instance.CheckUserdata(index, "Quaternion")));
return 1;
}
}
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param quat Resulting quaternion
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag<Quaternionf>)
{
Quaterniond quatDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag<Quaterniond>());
quat->Set(quatDouble);
return ret;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
@@ -222,76 +356,6 @@ namespace Nz
return ret;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param quat Resulting quaternion
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
{
switch (instance.GetType(index))
{
case Nz::LuaType_Table:
quat->Set(instance.CheckField<double>("w", index), instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", index));
return 1;
default:
{
if (instance.IsOfType(index, "EulerAngles"))
quat->Set(*static_cast<EulerAnglesd*>(instance.ToUserdata(index)));
else
quat->Set(*static_cast<Quaterniond*>(instance.CheckUserdata(index, "Quaternion")));
return 1;
}
}
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param quat Resulting quaternion
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag<Quaternionf>)
{
Quaterniond quatDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag<Quaterniond>());
quat->Set(quatDouble);
return ret;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param address Resulting IP address
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag<IpAddress>)
{
switch (instance.GetType(index))
{
case Nz::LuaType_String:
address->BuildFromAddress(instance.CheckString(index));
return 1;
default:
*address = *static_cast<IpAddress*>(instance.CheckUserdata(index, "IpAddress"));
return 1;
}
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
@@ -469,10 +533,31 @@ namespace Nz
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, InstancedRenderableRef* renderable, TypeTag<InstancedRenderableRef>)
{
if (instance.IsOfType(index, "InstancedRenderable"))
*renderable = *static_cast<InstancedRenderableRef*>(instance.CheckUserdata(index, "InstancedRenderable"));
if (instance.IsOfType(index, "InstancedRenderable") ||
instance.IsOfType(index, "Model") ||
instance.IsOfType(index, "Sprite"))
{
*renderable = *static_cast<InstancedRenderableRef*>(instance.ToUserdata(index));
}
else
*renderable = *static_cast<InstancedRenderableRef*>(instance.CheckUserdata(index, "Model"));
instance.ArgError(index, "is not a InstancedRenderable instance");
return 1;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param renderable Resulting reference to a material
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MaterialRef* materialRef, TypeTag<MaterialRef>)
{
*materialRef = *static_cast<MaterialRef*>(instance.CheckUserdata(index, "Material"));
return 1;
}
@@ -495,6 +580,7 @@ namespace Nz
params->loadHeightMap = instance.CheckField<bool>("LoadHeightMap", params->loadHeightMap);
params->loadNormalMap = instance.CheckField<bool>("LoadNormalMap", params->loadNormalMap);
params->loadSpecularMap = instance.CheckField<bool>("LoadSpecularMap", params->loadSpecularMap);
params->shaderName = instance.CheckField<String>("ShaderName", params->shaderName);
return 1;
}
@@ -556,8 +642,59 @@ namespace Nz
return 1;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param renderable Resulting reference to a sprite
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SpriteRef* spriteRef, TypeTag<SpriteRef>)
{
*spriteRef = *static_cast<SpriteRef*>(instance.CheckUserdata(index, "Sprite"));
return 1;
}
/*!
* \brief Queries arguments for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param index Index type
* \param fontRef Resulting reference to a font
*/
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, TextureRef* textureRef, TypeTag<TextureRef>)
{
*textureRef = *static_cast<TextureRef*>(instance.CheckUserdata(index, "Texture"));
return 1;
}
#endif
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param val Resulting color
*/
inline int LuaImplReplyVal(const LuaInstance& instance, Color&& val, TypeTag<Color>)
{
instance.PushTable();
instance.PushField("r", val.r);
instance.PushField("g", val.g);
instance.PushField("b", val.b);
instance.PushField("a", val.a);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
@@ -619,6 +756,65 @@ namespace Nz
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param val Resulting ImageParams
*/
inline int LuaImplReplyVal(const LuaInstance& instance, ImageParams&& val, TypeTag<ImageParams>)
{
instance.PushTable(0, 2);
instance.PushField("LevelCount", val.levelCount);
instance.PushField("LoadFormat", val.loadFormat);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param val Resulting IP address
*/
inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress&& val, TypeTag<IpAddress>)
{
instance.PushInstance<IpAddress>("IpAddress", val);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param val Resulting rectangle
*/
inline int LuaImplReplyVal(const LuaInstance& instance, Matrix4d&& val, TypeTag<Matrix4d>)
{
instance.PushInstance<Matrix4d>("Matrix4", val);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param val Resulting rectangle
*/
inline int LuaImplReplyVal(const LuaInstance& instance, Matrix4f&& val, TypeTag<Matrix4f>)
{
instance.PushInstance<Matrix4d>("Matrix4", val);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
@@ -647,20 +843,6 @@ namespace Nz
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param val Resulting IP address
*/
inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress&& val, TypeTag<IpAddress>)
{
instance.PushInstance<IpAddress>("IpAddress", val);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
@@ -669,7 +851,7 @@ namespace Nz
* \param val Resulting rectangle
*/
inline int LuaImplReplyVal(const LuaInstance& instance, Rectd&& val, TypeTag<Rectf>)
inline int LuaImplReplyVal(const LuaInstance& instance, Rectd&& val, TypeTag<Rectd>)
{
instance.PushInstance<Rectd>("Rect", val);
return 1;
@@ -887,6 +1069,62 @@ namespace Nz
#ifndef NDK_SERVER
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param handle Resulting material
*/
inline int LuaImplReplyVal(const LuaInstance& instance, MaterialRef&& handle, TypeTag<MaterialRef>)
{
instance.PushInstance<MaterialRef>("Material", handle);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param val Resulting sound buffer
*/
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
{
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param handle Resulting sprite
*/
inline int LuaImplReplyVal(const LuaInstance& instance, SpriteRef&& handle, TypeTag<SpriteRef>)
{
instance.PushInstance<SpriteRef>("Sprite", handle);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param handle Resulting texture
*/
inline int LuaImplReplyVal(const LuaInstance& instance, TextureRef&& handle, TypeTag<TextureRef>)
{
instance.PushInstance<TextureRef>("Texture", handle);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
@@ -914,21 +1152,6 @@ namespace Nz
instance.PushInstance<Ndk::GraphicsComponentHandle>("GraphicsComponent", handle);
return 1;
}
/*!
* \brief Replies by value for Lua
* \return 1 in case of success
*
* \param instance Lua instance to interact with
* \param val Resulting sound buffer
*/
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
{
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
return 1;
}
#endif
}

View File

@@ -38,47 +38,56 @@ namespace Ndk
void RegisterClasses(Nz::LuaInstance& instance);
// Core
Nz::LuaClass<Nz::Clock> clockClass;
Nz::LuaClass<Nz::Directory> directoryClass;
Nz::LuaClass<Nz::File> fileClass;
Nz::LuaClass<Nz::Stream> streamClass;
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> eulerAnglesClass;
Nz::LuaClass<Nz::Quaterniond> quaternionClass;
Nz::LuaClass<Nz::Rectd> rectClass;
Nz::LuaClass<Nz::Vector2d> vector2dClass;
Nz::LuaClass<Nz::Vector3d> vector3dClass;
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> abstractSocketClass;
Nz::LuaClass<Nz::IpAddress> ipAddressClass;
Nz::LuaClass<Nz::AbstractSocket> abstractSocket;
Nz::LuaClass<Nz::IpAddress> ipAddress;
// Utility
Nz::LuaClass<Nz::AbstractImage*> abstractImage;
Nz::LuaClass<Nz::FontRef> fontClass;
Nz::LuaClass<Nz::Node> nodeClass;
Nz::LuaClass<Nz::AbstractImageRef> abstractImage;
Nz::LuaClass<Nz::FontRef> font;
Nz::LuaClass<Nz::Node> node;
// SDK
Nz::LuaClass<Application*> application;
Nz::LuaClass<EntityHandle> entityClass;
Nz::LuaClass<EntityHandle> entity;
Nz::LuaClass<NodeComponentHandle> nodeComponent;
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
Nz::LuaClass<WorldHandle> worldClass;
Nz::LuaClass<WorldHandle> world;
#ifndef NDK_SERVER
// Audio
Nz::LuaClass<Nz::Music> musicClass;
Nz::LuaClass<Nz::Sound> soundClass;
Nz::LuaClass<Nz::Music> music;
Nz::LuaClass<Nz::Sound> sound;
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
// Graphics
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
Nz::LuaClass<Nz::ModelRef> modelClass;
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<ConsoleHandle> consoleClass;
Nz::LuaClass<ConsoleHandle> console;
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
#endif
@@ -117,7 +126,7 @@ namespace Ndk
Nz::String name;
};
ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 1);
ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 2);
std::vector<ComponentBinding> m_componentBinding;
std::unordered_map<Nz::String, ComponentIndex> m_componentBindingByName;

View File

@@ -7,7 +7,7 @@
#include <NDK/Systems/ListenerSystem.hpp>
#include <NDK/Systems/ParticleSystem.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
#include <NDK/Systems/RenderSystem.hpp>
#include <NDK/Systems/VelocitySystem.hpp>

View File

@@ -1,40 +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_SYSTEMS_PHYSICSSYSTEM_HPP
#define NDK_SYSTEMS_PHYSICSSYSTEM_HPP
#include <Nazara/Physics/PhysWorld.hpp>
#include <NDK/EntityList.hpp>
#include <NDK/System.hpp>
namespace Ndk
{
class NDK_API PhysicsSystem : public System<PhysicsSystem>
{
public:
PhysicsSystem();
PhysicsSystem(const PhysicsSystem& system);
~PhysicsSystem() = default;
Nz::PhysWorld& GetWorld();
const Nz::PhysWorld& GetWorld() const;
static SystemIndex systemIndex;
private:
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
EntityList m_dynamicObjects;
EntityList m_staticObjects;
Nz::PhysWorld m_world;
};
}
#include <NDK/Systems/PhysicsSystem.inl>
#endif // NDK_SYSTEMS_PHYSICSSYSTEM_HPP

View File

@@ -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_SYSTEMS_PHYSICSSYSTEM3D_HPP
#define NDK_SYSTEMS_PHYSICSSYSTEM3D_HPP
#include <Nazara/Physics3D/PhysWorld3D.hpp>
#include <NDK/EntityList.hpp>
#include <NDK/System.hpp>
#include <memory>
namespace Ndk
{
class NDK_API PhysicsSystem3D : public System<PhysicsSystem3D>
{
public:
PhysicsSystem3D();
PhysicsSystem3D(const PhysicsSystem3D& system);
~PhysicsSystem3D() = default;
Nz::PhysWorld3D& GetWorld();
const Nz::PhysWorld3D& GetWorld() const;
static SystemIndex systemIndex;
private:
void CreatePhysWorld() const;
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
EntityList m_dynamicObjects;
EntityList m_staticObjects;
mutable std::unique_ptr<Nz::PhysWorld3D> m_world; ///TODO: std::optional (Should I make a Nz::Optional class?)
};
}
#include <NDK/Systems/PhysicsSystem3D.inl>
#endif // NDK_SYSTEMS_PHYSICSSYSTEM3D_HPP

View File

@@ -9,9 +9,12 @@ namespace Ndk
* \return A reference to the physical world
*/
inline Nz::PhysWorld& PhysicsSystem::GetWorld()
inline Nz::PhysWorld3D& PhysicsSystem3D::GetWorld()
{
return m_world;
if (!m_world)
CreatePhysWorld();
return *m_world;
}
/*!
@@ -19,8 +22,11 @@ namespace Ndk
* \return A constant reference to the physical world
*/
inline const Nz::PhysWorld& PhysicsSystem::GetWorld() const
inline const Nz::PhysWorld3D& PhysicsSystem3D::GetWorld() const
{
return m_world;
if (!m_world)
CreatePhysWorld();
return *m_world;
}
}

View File

@@ -98,9 +98,7 @@ namespace Ndk
++it;
}
#endif
#ifndef NDK_SERVER
if (m_exitOnClosedWindows && !hasAtLeastOneActiveWindow)
return false;
#endif

View File

@@ -2,18 +2,18 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/CollisionComponent.hpp>
#include <Nazara/Physics/PhysObject.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NDK/Algorithm.hpp>
#include <NDK/World.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::CollisionComponent
* \class Ndk::CollisionComponent3D
* \brief NDK class that represents the component for collision (meant for static objects)
*/
@@ -25,14 +25,14 @@ namespace Ndk
* \remark Produces a NazaraAssert if the entity has no physics component and has no static body
*/
void CollisionComponent::SetGeom(Nz::PhysGeomRef geom)
void CollisionComponent3D::SetGeom(Nz::Collider3DRef geom)
{
m_geom = std::move(geom);
if (m_entity->HasComponent<PhysicsComponent>())
if (m_entity->HasComponent<PhysicsComponent3D>())
{
// We update the geometry of the PhysiscsObject linked to the PhysicsComponent
PhysicsComponent& physComponent = m_entity->GetComponent<PhysicsComponent>();
// We update the geometry of the PhysiscsObject linked to the PhysicsComponent3D
PhysicsComponent3D& physComponent = m_entity->GetComponent<PhysicsComponent3D>();
physComponent.GetPhysObject().SetGeom(m_geom);
}
else
@@ -49,16 +49,16 @@ namespace Ndk
* \remark Produces a NazaraAssert if entity is not linked to a world, or the world has no physics system
*/
void CollisionComponent::InitializeStaticBody()
void CollisionComponent3D::InitializeStaticBody()
{
NazaraAssert(m_entity, "Invalid entity");
World* entityWorld = m_entity->GetWorld();
NazaraAssert(entityWorld, "Entity must have world");
NazaraAssert(entityWorld->HasSystem<PhysicsSystem>(), "World must have a physics system");
Nz::PhysWorld& physWorld = entityWorld->GetSystem<PhysicsSystem>().GetWorld();
NazaraAssert(entityWorld->HasSystem<PhysicsSystem3D>(), "World must have a physics system");
Nz::PhysWorld3D& physWorld = entityWorld->GetSystem<PhysicsSystem3D>().GetWorld();
m_staticBody.reset(new Nz::PhysObject(&physWorld, m_geom));
m_staticBody.reset(new Nz::RigidBody3D(&physWorld, m_geom));
m_staticBody->EnableAutoSleep(false);
}
@@ -66,9 +66,9 @@ namespace Ndk
* \brief Operation to perform when component is attached to an entity
*/
void CollisionComponent::OnAttached()
void CollisionComponent3D::OnAttached()
{
if (!m_entity->HasComponent<PhysicsComponent>())
if (!m_entity->HasComponent<PhysicsComponent3D>())
InitializeStaticBody();
}
@@ -78,9 +78,9 @@ namespace Ndk
* \param component Component being attached
*/
void CollisionComponent::OnComponentAttached(BaseComponent& component)
void CollisionComponent3D::OnComponentAttached(BaseComponent& component)
{
if (IsComponent<PhysicsComponent>(component))
if (IsComponent<PhysicsComponent3D>(component))
m_staticBody.reset();
}
@@ -90,9 +90,9 @@ namespace Ndk
* \param component Component being detached
*/
void CollisionComponent::OnComponentDetached(BaseComponent& component)
void CollisionComponent3D::OnComponentDetached(BaseComponent& component)
{
if (IsComponent<PhysicsComponent>(component))
if (IsComponent<PhysicsComponent3D>(component))
InitializeStaticBody();
}
@@ -100,10 +100,10 @@ namespace Ndk
* \brief Operation to perform when component is detached from an entity
*/
void CollisionComponent::OnDetached()
void CollisionComponent3D::OnDetached()
{
m_staticBody.reset();
}
ComponentIndex CollisionComponent::componentIndex;
ComponentIndex CollisionComponent3D::componentIndex;
}

View File

@@ -131,8 +131,6 @@ namespace Ndk
{
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "GraphicsComponent requires NodeComponent");
Ndk::RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem<Ndk::RenderSystem>();
m_transformMatrix = m_entity->GetComponent<NodeComponent>().GetTransformMatrix();
m_transformMatrixUpdated = true;
}

View File

@@ -2,19 +2,19 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/PhysicsComponent.hpp>
#include <Nazara/Physics/PhysObject.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NDK/Algorithm.hpp>
#include <NDK/World.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::PhysicsComponent
* \class Ndk::PhysicsComponent3D
* \brief NDK class that represents the component for physics (meant for dynamic objects)
*/
@@ -24,16 +24,16 @@ namespace Ndk
* \remark Produces a NazaraAssert if the world does not have a physics system
*/
void PhysicsComponent::OnAttached()
void PhysicsComponent3D::OnAttached()
{
World* entityWorld = m_entity->GetWorld();
NazaraAssert(entityWorld->HasSystem<PhysicsSystem>(), "World must have a physics system");
NazaraAssert(entityWorld->HasSystem<PhysicsSystem3D>(), "World must have a physics system");
Nz::PhysWorld& world = entityWorld->GetSystem<PhysicsSystem>().GetWorld();
Nz::PhysWorld3D& world = entityWorld->GetSystem<PhysicsSystem3D>().GetWorld();
Nz::PhysGeomRef geom;
if (m_entity->HasComponent<CollisionComponent>())
geom = m_entity->GetComponent<CollisionComponent>().GetGeom();
Nz::Collider3DRef geom;
if (m_entity->HasComponent<CollisionComponent3D>())
geom = m_entity->GetComponent<CollisionComponent3D>().GetGeom();
Nz::Matrix4f matrix;
if (m_entity->HasComponent<NodeComponent>())
@@ -41,7 +41,7 @@ namespace Ndk
else
matrix.MakeIdentity();
m_object.reset(new Nz::PhysObject(&world, geom, matrix));
m_object.reset(new Nz::RigidBody3D(&world, geom, matrix));
m_object->SetMass(1.f);
}
@@ -53,12 +53,12 @@ namespace Ndk
* \remark Produces a NazaraAssert if physical object is invalid
*/
void PhysicsComponent::OnComponentAttached(BaseComponent& component)
void PhysicsComponent3D::OnComponentAttached(BaseComponent& component)
{
if (IsComponent<CollisionComponent>(component))
if (IsComponent<CollisionComponent3D>(component))
{
NazaraAssert(m_object, "Invalid object");
m_object->SetGeom(static_cast<CollisionComponent&>(component).GetGeom());
m_object->SetGeom(static_cast<CollisionComponent3D&>(component).GetGeom());
}
}
@@ -70,12 +70,12 @@ namespace Ndk
* \remark Produces a NazaraAssert if physical object is invalid
*/
void PhysicsComponent::OnComponentDetached(BaseComponent& component)
void PhysicsComponent3D::OnComponentDetached(BaseComponent& component)
{
if (IsComponent<CollisionComponent>(component))
if (IsComponent<CollisionComponent3D>(component))
{
NazaraAssert(m_object, "Invalid object");
m_object->SetGeom(Nz::NullGeom::New());
m_object->SetGeom(Nz::NullCollider3D::New());
}
}
@@ -83,10 +83,10 @@ namespace Ndk
* \brief Operation to perform when component is detached from an entity
*/
void PhysicsComponent::OnDetached()
void PhysicsComponent3D::OnDetached()
{
m_object.reset();
}
ComponentIndex PhysicsComponent::componentIndex;
ComponentIndex PhysicsComponent3D::componentIndex;
}

View File

@@ -1,6 +1,7 @@
// This file was automatically generated on 26 May 2014 at 01:05:31
#include <NDK/LuaAPI.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <NDK/LuaBinding.hpp>
namespace Ndk
@@ -11,6 +12,21 @@ namespace Ndk
* \brief NDK class that represents the api used for Lua
*/
/*!
* \brief Gets the internal binding for Lua
* \return A pointer to the binding
*/
LuaBinding* LuaAPI::GetBinding()
{
if (!s_binding && !Initialize())
{
NazaraError("Failed to initialize binding");
return nullptr;
}
return s_binding;
}
/*!
* \brief Initializes the LuaAPI module
* \return true if initialization is successful
@@ -30,13 +46,8 @@ namespace Ndk
void LuaAPI::RegisterClasses(Nz::LuaInstance& instance)
{
if (!s_binding && !Initialize())
{
NazaraError("Failed to initialize binding");
return;
}
s_binding->RegisterClasses(instance);
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
GetBinding()->RegisterClasses(instance);
}
/*!

View File

@@ -16,49 +16,58 @@ namespace Ndk
LuaBinding::LuaBinding() :
// Core
clockClass("Clock"),
directoryClass("Directory"),
fileClass("File"),
streamClass("Stream"),
clock("Clock"),
directory("Directory"),
file("File"),
stream("Stream"),
// Math
eulerAnglesClass("EulerAngles"),
quaternionClass("Quaternion"),
rectClass("Rect"),
vector2dClass("Vector2"),
vector3dClass("Vector3"),
eulerAngles("EulerAngles"),
matrix4d("Matrix4"),
quaternion("Quaternion"),
rect("Rect"),
vector2d("Vector2"),
vector3d("Vector3"),
// Network
abstractSocketClass("AbstractSocket"),
ipAddressClass("IpAddress"),
abstractSocket("AbstractSocket"),
ipAddress("IpAddress"),
// Utility
abstractImage("AbstractImage"),
fontClass("Font"),
nodeClass("Node"),
font("Font"),
node("Node"),
// SDK
application("Application"),
entityClass("Entity"),
entity("Entity"),
nodeComponent("NodeComponent"),
velocityComponent("VelocityComponent"),
worldClass("World")
world("World")
#ifndef NDK_SERVER
,
// Audio
musicClass("Music"),
soundClass("Sound"),
music("Music"),
sound("Sound"),
soundBuffer("SoundBuffer"),
soundEmitter("SoundEmitter"),
// Graphics
instancedRenderable("InstancedRenderable"),
modelClass("Model"),
material("Material"),
model("Model"),
sprite("Sprite"),
spriteLibrary("SpriteLibrary"),
textureLibrary("TextureLibrary"),
textureManager("TextureManager"),
// Renderer
texture("Texture"),
// SDK
consoleClass("Console"),
console("Console"),
graphicsComponent("GraphicsComponent")
#endif
{

View File

@@ -13,35 +13,35 @@ namespace Ndk
void LuaBinding::BindAudio()
{
/*********************************** Nz::Music **********************************/
musicClass.Inherit(soundEmitter);
music.Inherit(soundEmitter);
musicClass.BindDefaultConstructor();
music.BindDefaultConstructor();
//musicClass.SetMethod("Create", &Nz::Music::Create);
//musicClass.SetMethod("Destroy", &Nz::Music::Destroy);
musicClass.BindMethod("EnableLooping", &Nz::Music::EnableLooping);
music.BindMethod("EnableLooping", &Nz::Music::EnableLooping);
musicClass.BindMethod("GetDuration", &Nz::Music::GetDuration);
musicClass.BindMethod("GetFormat", &Nz::Music::GetFormat);
musicClass.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset);
musicClass.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount);
musicClass.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate);
musicClass.BindMethod("GetStatus", &Nz::Music::GetStatus);
music.BindMethod("GetDuration", &Nz::Music::GetDuration);
music.BindMethod("GetFormat", &Nz::Music::GetFormat);
music.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset);
music.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount);
music.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate);
music.BindMethod("GetStatus", &Nz::Music::GetStatus);
musicClass.BindMethod("IsLooping", &Nz::Music::IsLooping);
music.BindMethod("IsLooping", &Nz::Music::IsLooping);
musicClass.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams());
music.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams());
musicClass.BindMethod("Pause", &Nz::Music::Pause);
musicClass.BindMethod("Play", &Nz::Music::Play);
music.BindMethod("Pause", &Nz::Music::Pause);
music.BindMethod("Play", &Nz::Music::Play);
musicClass.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset);
music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset);
musicClass.BindMethod("Stop", &Nz::Music::Stop);
music.BindMethod("Stop", &Nz::Music::Stop);
// Manual
musicClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music) -> int
music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music, std::size_t /*argumentCount*/) -> int
{
Nz::StringStream stream("Music(");
stream << music.GetFilePath() << ')';
@@ -51,21 +51,21 @@ namespace Ndk
});
/*********************************** Nz::Sound **********************************/
soundClass.Inherit(soundEmitter);
sound.Inherit(soundEmitter);
soundClass.BindDefaultConstructor();
sound.BindDefaultConstructor();
soundClass.BindMethod("GetBuffer", &Nz::Sound::GetBuffer);
sound.BindMethod("GetBuffer", &Nz::Sound::GetBuffer);
soundClass.BindMethod("IsPlayable", &Nz::Sound::IsPlayable);
soundClass.BindMethod("IsPlaying", &Nz::Sound::IsPlaying);
sound.BindMethod("IsPlayable", &Nz::Sound::IsPlayable);
sound.BindMethod("IsPlaying", &Nz::Sound::IsPlaying);
soundClass.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
sound.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
soundClass.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);
sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);
// Manual
soundClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int
sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound, std::size_t /*argumentCount*/) -> int
{
Nz::StringStream stream("Sound(");
if (const Nz::SoundBuffer* buffer = sound.GetBuffer())
@@ -101,9 +101,9 @@ namespace Ndk
soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported);
// Manual
soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
{
int index = 1;
int index = 2;
Nz::AudioFormat format = lua.Check<Nz::AudioFormat>(&index);
unsigned int sampleCount = lua.Check<unsigned int>(&index);
unsigned int sampleRate = lua.Check<unsigned int>(&index);
@@ -116,13 +116,13 @@ namespace Ndk
return 1;
});
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
{
lua.PushString(reinterpret_cast<const char*>(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16));
return 1;
});
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
{
Nz::StringStream stream("SoundBuffer(");
if (instance->IsValid())
@@ -177,8 +177,8 @@ namespace Ndk
void LuaBinding::RegisterAudio(Nz::LuaInstance& instance)
{
musicClass.Register(instance);
soundClass.Register(instance);
music.Register(instance);
sound.Register(instance);
soundBuffer.Register(instance);
soundEmitter.Register(instance);
}

View File

@@ -13,9 +13,9 @@ namespace Ndk
void LuaBinding::BindCore()
{
/*********************************** Nz::Clock **********************************/
clockClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock, std::size_t argumentCount)
clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock, std::size_t /*argumentCount*/)
{
int argIndex = 1;
int argIndex = 2;
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
bool paused = lua.Check<bool>(&argIndex, false);
@@ -23,16 +23,16 @@ namespace Ndk
return true;
});
clockClass.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds);
clockClass.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds);
clockClass.BindMethod("GetSeconds", &Nz::Clock::GetSeconds);
clockClass.BindMethod("IsPaused", &Nz::Clock::IsPaused);
clockClass.BindMethod("Pause", &Nz::Clock::Pause);
clockClass.BindMethod("Restart", &Nz::Clock::Restart);
clockClass.BindMethod("Unpause", &Nz::Clock::Unpause);
clock.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds);
clock.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds);
clock.BindMethod("GetSeconds", &Nz::Clock::GetSeconds);
clock.BindMethod("IsPaused", &Nz::Clock::IsPaused);
clock.BindMethod("Pause", &Nz::Clock::Pause);
clock.BindMethod("Restart", &Nz::Clock::Restart);
clock.BindMethod("Unpause", &Nz::Clock::Unpause);
// Manual
clockClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int {
clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock, std::size_t /*argumentCount*/) -> int {
Nz::StringStream stream("Clock(Elapsed: ");
stream << clock.GetSeconds();
stream << "s, Paused: ";
@@ -44,11 +44,11 @@ namespace Ndk
});
/********************************* Nz::Directory ********************************/
directoryClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* directory, std::size_t argumentCount)
directory.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* directory, std::size_t argumentCount)
{
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
int argIndex = 1;
int argIndex = 2;
switch (argCount)
{
case 0:
@@ -63,29 +63,29 @@ namespace Ndk
return false;
});
directoryClass.BindMethod("Close", &Nz::Directory::Close);
directoryClass.BindMethod("Exists", &Nz::Directory::Exists);
directoryClass.BindMethod("GetPath", &Nz::Directory::GetPath);
directoryClass.BindMethod("GetPattern", &Nz::Directory::GetPattern);
directoryClass.BindMethod("GetResultName", &Nz::Directory::GetResultName);
directoryClass.BindMethod("GetResultPath", &Nz::Directory::GetResultPath);
directoryClass.BindMethod("GetResultSize", &Nz::Directory::GetResultSize);
directoryClass.BindMethod("IsOpen", &Nz::Directory::IsOpen);
directoryClass.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory);
directoryClass.BindMethod("NextResult", &Nz::Directory::NextResult, true);
directoryClass.BindMethod("Open", &Nz::Directory::Open);
directoryClass.BindMethod("SetPath", &Nz::Directory::SetPath);
directoryClass.BindMethod("SetPattern", &Nz::Directory::SetPattern);
directory.BindMethod("Close", &Nz::Directory::Close);
directory.BindMethod("Exists", &Nz::Directory::Exists);
directory.BindMethod("GetPath", &Nz::Directory::GetPath);
directory.BindMethod("GetPattern", &Nz::Directory::GetPattern);
directory.BindMethod("GetResultName", &Nz::Directory::GetResultName);
directory.BindMethod("GetResultPath", &Nz::Directory::GetResultPath);
directory.BindMethod("GetResultSize", &Nz::Directory::GetResultSize);
directory.BindMethod("IsOpen", &Nz::Directory::IsOpen);
directory.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory);
directory.BindMethod("NextResult", &Nz::Directory::NextResult, true);
directory.BindMethod("Open", &Nz::Directory::Open);
directory.BindMethod("SetPath", &Nz::Directory::SetPath);
directory.BindMethod("SetPattern", &Nz::Directory::SetPattern);
directoryClass.BindStaticMethod("Copy", Nz::Directory::Copy);
directoryClass.BindStaticMethod("Create", Nz::Directory::Create);
directoryClass.BindStaticMethod("Exists", Nz::Directory::Exists);
directoryClass.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent);
directoryClass.BindStaticMethod("Remove", Nz::Directory::Remove);
directoryClass.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
directory.BindStaticMethod("Copy", Nz::Directory::Copy);
directory.BindStaticMethod("Create", Nz::Directory::Create);
directory.BindStaticMethod("Exists", Nz::Directory::Exists);
directory.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent);
directory.BindStaticMethod("Remove", Nz::Directory::Remove);
directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
// Manual
directoryClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int {
directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory, std::size_t /*argumentCount*/) -> int {
Nz::StringStream stream("Directory(");
stream << directory.GetPath();
stream << ')';
@@ -95,23 +95,23 @@ namespace Ndk
});
/*********************************** Nz::Stream ***********************************/
streamClass.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode);
streamClass.BindMethod("Flush", &Nz::Stream::Flush);
streamClass.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos);
streamClass.BindMethod("GetDirectory", &Nz::Stream::GetDirectory);
streamClass.BindMethod("GetPath", &Nz::Stream::GetPath);
streamClass.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode);
streamClass.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions);
streamClass.BindMethod("GetSize", &Nz::Stream::GetSize);
streamClass.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U);
streamClass.BindMethod("IsReadable", &Nz::Stream::IsReadable);
streamClass.BindMethod("IsSequential", &Nz::Stream::IsSequential);
streamClass.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled);
streamClass.BindMethod("IsWritable", &Nz::Stream::IsWritable);
streamClass.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos);
stream.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode);
stream.BindMethod("Flush", &Nz::Stream::Flush);
stream.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos);
stream.BindMethod("GetDirectory", &Nz::Stream::GetDirectory);
stream.BindMethod("GetPath", &Nz::Stream::GetPath);
stream.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode);
stream.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions);
stream.BindMethod("GetSize", &Nz::Stream::GetSize);
stream.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U);
stream.BindMethod("IsReadable", &Nz::Stream::IsReadable);
stream.BindMethod("IsSequential", &Nz::Stream::IsSequential);
stream.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled);
stream.BindMethod("IsWritable", &Nz::Stream::IsWritable);
stream.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos);
streamClass.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
int argIndex = 1;
stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream, std::size_t /*argumentCount*/) -> int {
int argIndex = 2;
std::size_t length = lua.Check<std::size_t>(&argIndex);
@@ -122,8 +122,8 @@ namespace Ndk
return 1;
});
streamClass.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
int argIndex = 1;
stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream, std::size_t /*argumentCount*/) -> int {
int argIndex = 2;
std::size_t bufferSize = 0;
const char* buffer = lua.CheckString(argIndex, &bufferSize);
@@ -136,13 +136,13 @@ namespace Ndk
});
/*********************************** Nz::File ***********************************/
fileClass.Inherit(streamClass);
file.Inherit(stream);
fileClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* file, std::size_t argumentCount)
file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* file, std::size_t argumentCount)
{
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
int argIndex = 1;
int argIndex = 2;
switch (argCount)
{
case 0:
@@ -171,41 +171,41 @@ namespace Ndk
return false;
});
fileClass.BindMethod("Close", &Nz::File::Close);
fileClass.BindMethod("Copy", &Nz::File::Copy);
fileClass.BindMethod("Delete", &Nz::File::Delete);
fileClass.BindMethod("EndOfFile", &Nz::File::EndOfFile);
fileClass.BindMethod("Exists", &Nz::File::Exists);
fileClass.BindMethod("GetCreationTime", &Nz::File::GetCreationTime);
fileClass.BindMethod("GetFileName", &Nz::File::GetFileName);
fileClass.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
fileClass.BindMethod("IsOpen", &Nz::File::IsOpen);
fileClass.BindMethod("Rename", &Nz::File::GetLastWriteTime);
fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
fileClass.BindMethod("SetFile", &Nz::File::GetLastWriteTime);
file.BindMethod("Close", &Nz::File::Close);
file.BindMethod("Copy", &Nz::File::Copy);
file.BindMethod("Delete", &Nz::File::Delete);
file.BindMethod("EndOfFile", &Nz::File::EndOfFile);
file.BindMethod("Exists", &Nz::File::Exists);
file.BindMethod("GetCreationTime", &Nz::File::GetCreationTime);
file.BindMethod("GetFileName", &Nz::File::GetFileName);
file.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
file.BindMethod("IsOpen", &Nz::File::IsOpen);
file.BindMethod("Rename", &Nz::File::GetLastWriteTime);
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
file.BindMethod("SetFile", &Nz::File::GetLastWriteTime);
fileClass.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath);
fileClass.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash);
fileClass.BindStaticMethod("Copy", &Nz::File::Copy);
fileClass.BindStaticMethod("Delete", &Nz::File::Delete);
fileClass.BindStaticMethod("Exists", &Nz::File::Exists);
file.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath);
file.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash);
file.BindStaticMethod("Copy", &Nz::File::Copy);
file.BindStaticMethod("Delete", &Nz::File::Delete);
file.BindStaticMethod("Exists", &Nz::File::Exists);
//fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime);
fileClass.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory);
file.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory);
//fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
//fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
fileClass.BindStaticMethod("GetSize", &Nz::File::GetSize);
fileClass.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute);
fileClass.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath);
fileClass.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators);
fileClass.BindStaticMethod("Rename", &Nz::File::Rename);
file.BindStaticMethod("GetSize", &Nz::File::GetSize);
file.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute);
file.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath);
file.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators);
file.BindStaticMethod("Rename", &Nz::File::Rename);
// Manual
fileClass.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file, std::size_t argumentCount) -> int
{
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
int argIndex = 1;
int argIndex = 2;
switch (argCount)
{
case 0:
@@ -224,11 +224,11 @@ namespace Ndk
return 0;
});
fileClass.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file, std::size_t argumentCount) -> int
{
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
int argIndex = 1;
int argIndex = 2;
switch (argCount)
{
case 1:
@@ -246,7 +246,7 @@ namespace Ndk
return 0;
});
fileClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int {
file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file, std::size_t /*argumentCount*/) -> int {
Nz::StringStream stream("File(");
if (file.IsOpen())
stream << "Path: " << file.GetPath();
@@ -267,10 +267,10 @@ namespace Ndk
void LuaBinding::RegisterCore(Nz::LuaInstance& instance)
{
// Classes
clockClass.Register(instance);
directoryClass.Register(instance);
fileClass.Register(instance);
streamClass.Register(instance);
clock.Register(instance);
directory.Register(instance);
file.Register(instance);
stream.Register(instance);
// Enums

View File

@@ -14,36 +14,305 @@ namespace Ndk
{
/*********************************** Nz::InstancedRenderable ***********************************/
/*********************************** Nz::Material ***********************************/
material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount)
{
switch (argumentCount)
{
case 0:
Nz::PlacementNew(instance, Nz::Material::New());
return true;
case 1:
{
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);
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 ***********************************/
modelClass.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef*
model.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* model) -> Nz::InstancedRenderableRef*
{
return reinterpret_cast<Nz::InstancedRenderableRef*>(model); //TODO: Make a ObjectRefCast
});
modelClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::ModelRef* model, std::size_t argumentCount)
model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* model, std::size_t /*argumentCount*/)
{
NazaraUnused(argumentCount);
Nz::PlacementNew(model, Nz::Model::New());
return true;
});
//modelClass.SetMethod("GetMaterial", &Nz::Model::GetMaterial);
modelClass.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
//model.BindMethod("GetMaterial", &Nz::Model::GetMaterial);
model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
modelClass.BindMethod("GetSkin", &Nz::Model::GetSkin);
modelClass.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
model.BindMethod("GetSkin", &Nz::Model::GetSkin);
model.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
modelClass.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
modelClass.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
model.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
model.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
modelClass.BindMethod("Reset", &Nz::Model::Reset);
model.BindMethod("Reset", &Nz::Model::Reset);
//modelClass.SetMethod("SetMaterial", &Nz::Model::SetMaterial);
//model.BindMethod("SetMaterial", &Nz::Model::SetMaterial);
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
modelClass.BindMethod("SetSkin", &Nz::Model::SetSkin);
modelClass.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
model.BindMethod("SetSkin", &Nz::Model::SetSkin);
model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
/*********************************** Nz::Sprite ***********************************/
sprite.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::SpriteRef* sprite) -> Nz::InstancedRenderableRef*
{
return reinterpret_cast<Nz::InstancedRenderableRef*>(sprite); //TODO: Make a ObjectRefCast
});
sprite.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* sprite, std::size_t /*argumentCount*/)
{
Nz::PlacementNew(sprite, 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("SetMaterial", &Nz::Sprite::SetMaterial, true);
sprite.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin);
sprite.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize);
sprite.BindMethod("SetTexture", &Nz::Sprite::SetTexture, true);
sprite.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords);
sprite.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect);
/*********************************** Nz::SpriteLibrary ***********************************/
spriteLibrary.BindStaticMethod("Get", &Nz::SpriteLibrary::Get);
spriteLibrary.BindStaticMethod("Has", &Nz::SpriteLibrary::Has);
spriteLibrary.BindStaticMethod("Register", &Nz::SpriteLibrary::Register);
spriteLibrary.BindStaticMethod("Query", &Nz::SpriteLibrary::Query);
spriteLibrary.BindStaticMethod("Unregister", &Nz::SpriteLibrary::Unregister);
/*********************************** 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);
}
/*!
@@ -55,6 +324,11 @@ namespace Ndk
void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance)
{
instancedRenderable.Register(instance);
modelClass.Register(instance);
material.Register(instance);
model.Register(instance);
sprite.Register(instance);
spriteLibrary.Register(instance);
textureLibrary.Register(instance);
textureManager.Register(instance);
}
}
}

View File

@@ -14,7 +14,7 @@ namespace Ndk
void LuaBinding::BindMath()
{
/*********************************** Nz::EulerAngles **********************************/
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* angles, std::size_t argumentCount)
eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* angles, std::size_t argumentCount)
{
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
@@ -37,12 +37,12 @@ namespace Ndk
return false;
});
eulerAnglesClass.BindMethod("__tostring", &Nz::EulerAnglesd::ToString);
eulerAngles.BindMethod("__tostring", &Nz::EulerAnglesd::ToString);
eulerAnglesClass.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
eulerAngles.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
{
std::size_t length;
const char* ypr = lua.CheckString(1, &length);
const char* ypr = lua.CheckString(2, &length);
switch (length)
{
@@ -96,11 +96,11 @@ namespace Ndk
return false;
});
eulerAnglesClass.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
eulerAngles.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
{
std::size_t length;
const char* ypr = lua.CheckString(1, &length);
double value = lua.CheckNumber(2);
const char* ypr = lua.CheckString(2, &length);
double value = lua.CheckNumber(3);
switch (length)
{
@@ -154,8 +154,213 @@ namespace Ndk
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 (std::size_t i = 0; i < 16; ++i)
values[i] = lua.CheckNumber(i);
Nz::PlacementNew(matrix, values);
return true;
}
}
lua.Error("No matching overload for constructor");
return false;
});
matrix4d.BindMethod("ApplyRotation", &Nz::Matrix4d::ApplyRotation);
matrix4d.BindMethod("ApplyScale", &Nz::Matrix4d::ApplyScale);
matrix4d.BindMethod("ApplyTranslation", &Nz::Matrix4d::ApplyTranslation);
matrix4d.BindMethod("Concatenate", &Nz::Matrix4d::Concatenate);
matrix4d.BindMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine);
//matrix4d.BindMethod("GetColumn", &Nz::Matrix4d::GetColumn);
matrix4d.BindMethod("GetDeterminant", &Nz::Matrix4d::GetDeterminant);
matrix4d.BindMethod("GetDeterminantAffine", &Nz::Matrix4d::GetDeterminantAffine);
matrix4d.BindMethod("GetInverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
{
Nz::Matrix4d result;
if (instance.GetInverse(&result))
return lua.Push(true, result);
else
return lua.Push(false);
});
matrix4d.BindMethod("GetInverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
{
Nz::Matrix4d result;
if (instance.GetInverseAffine(&result))
return lua.Push(true, result);
else
return lua.Push(false);
});
matrix4d.BindMethod("GetRotation", &Nz::Matrix4d::GetRotation);
//matrix4d.BindMethod("GetRow", &Nz::Matrix4d::GetRow);
matrix4d.BindMethod("GetScale", &Nz::Matrix4d::GetScale);
matrix4d.BindMethod("GetSquaredScale", &Nz::Matrix4d::GetSquaredScale);
matrix4d.BindMethod("GetTranslation", &Nz::Matrix4d::GetTranslation);
matrix4d.BindMethod("GetTransposed", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
{
Nz::Matrix4d result;
instance.GetTransposed(&result);
return lua.Push(result);
});
matrix4d.BindMethod("HasNegativeScale", &Nz::Matrix4d::HasNegativeScale);
matrix4d.BindMethod("HasScale", &Nz::Matrix4d::HasScale);
matrix4d.BindMethod("Inverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
{
bool succeeded;
instance.Inverse(&succeeded);
return lua.Push(succeeded);
});
matrix4d.BindMethod("InverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
{
bool succeeded;
instance.InverseAffine(&succeeded);
return lua.Push(succeeded);
});
matrix4d.BindMethod("IsAffine", &Nz::Matrix4d::IsAffine);
matrix4d.BindMethod("IsIdentity", &Nz::Matrix4d::IsIdentity);
matrix4d.BindMethod("MakeIdentity", &Nz::Matrix4d::MakeIdentity);
matrix4d.BindMethod("MakeLookAt", &Nz::Matrix4d::MakeLookAt, Nz::Vector3d::Up());
matrix4d.BindMethod("MakeOrtho", &Nz::Matrix4d::MakeOrtho, -1.0, 1.0);
matrix4d.BindMethod("MakePerspective", &Nz::Matrix4d::MakePerspective);
matrix4d.BindMethod("MakeRotation", &Nz::Matrix4d::MakeRotation);
matrix4d.BindMethod("MakeScale", &Nz::Matrix4d::MakeScale);
matrix4d.BindMethod("MakeTranslation", &Nz::Matrix4d::MakeTranslation);
matrix4d.BindMethod("MakeTransform", (Nz::Matrix4d&(Nz::Matrix4d::*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::MakeTransform, Nz::Vector3d::Unit());
matrix4d.BindMethod("MakeViewMatrix", &Nz::Matrix4d::MakeViewMatrix);
matrix4d.BindMethod("MakeZero", &Nz::Matrix4d::MakeZero);
matrix4d.BindMethod("Set", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t argumentCount) -> int
{
std::size_t argCount = std::min<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 **********************************/
rectClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect, std::size_t argumentCount)
rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* rect, std::size_t argumentCount)
{
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
@@ -203,15 +408,15 @@ namespace Ndk
return false;
});
rectClass.BindMethod("__tostring", &Nz::Rectd::ToString);
rect.BindMethod("__tostring", &Nz::Rectd::ToString);
rectClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
rect.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
{
switch (lua.GetType(1))
switch (lua.GetType(2))
{
case Nz::LuaType_Number:
{
auto index = lua.CheckBoundInteger<std::size_t>(1);
auto index = lua.CheckBoundInteger<std::size_t>(2);
if (index < 1 || index > 4)
return false;
@@ -222,7 +427,7 @@ namespace Ndk
case Nz::LuaType_String:
{
std::size_t length;
const char* xywh = lua.CheckString(1, &length);
const char* xywh = lua.CheckString(2, &length);
if (length != 1)
break;
@@ -258,13 +463,13 @@ namespace Ndk
return false;
});
rectClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
rect.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
{
switch (lua.GetType(1))
switch (lua.GetType(2))
{
case Nz::LuaType_Number:
{
auto index = lua.CheckBoundInteger<std::size_t>(1);
auto index = lua.CheckBoundInteger<std::size_t>(2);
if (index < 1 || index > 4)
return false;
@@ -275,12 +480,12 @@ namespace Ndk
case Nz::LuaType_String:
{
std::size_t length;
const char* xywh = lua.CheckString(1, &length);
const char* xywh = lua.CheckString(2, &length);
if (length != 1)
break;
double value = lua.CheckNumber(2);
double value = lua.CheckNumber(3);
switch (xywh[0])
{
@@ -311,7 +516,7 @@ namespace Ndk
});
/*********************************** Nz::Quaternion **********************************/
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion, std::size_t argumentCount)
quaternion.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* quaternion, std::size_t argumentCount)
{
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
@@ -349,12 +554,12 @@ namespace Ndk
return false;
});
quaternionClass.BindMethod("__tostring", &Nz::Quaterniond::ToString);
quaternion.BindMethod("__tostring", &Nz::Quaterniond::ToString);
quaternionClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
quaternion.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
{
std::size_t length;
const char* wxyz = lua.CheckString(1, &length);
const char* wxyz = lua.CheckString(2, &length);
if (length != 1)
return false;
@@ -381,15 +586,15 @@ namespace Ndk
return false;
});
quaternionClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
{
std::size_t length;
const char* wxyz = lua.CheckString(1, &length);
const char* wxyz = lua.CheckString(2, &length);
if (length != 1)
return false;
double value = lua.CheckNumber(2);
double value = lua.CheckNumber(3);
switch (wxyz[0])
{
@@ -417,7 +622,7 @@ namespace Ndk
});
/*********************************** Nz::Vector2 **********************************/
vector2dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount)
vector2d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount)
{
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
@@ -445,15 +650,15 @@ namespace Ndk
return false;
});
vector2dClass.BindMethod("__tostring", &Nz::Vector2d::ToString);
vector2d.BindMethod("__tostring", &Nz::Vector2d::ToString);
vector2dClass.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
vector2d.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
{
switch (lua.GetType(1))
switch (lua.GetType(2))
{
case Nz::LuaType_Number:
{
long long index = lua.CheckInteger(1);
long long index = lua.CheckInteger(2);
if (index < 1 || index > 2)
return false;
@@ -464,7 +669,7 @@ namespace Ndk
case Nz::LuaType_String:
{
std::size_t length;
const char* xy = lua.CheckString(1, &length);
const char* xy = lua.CheckString(2, &length);
if (length != 1)
break;
@@ -492,29 +697,29 @@ namespace Ndk
return false;
});
vector2dClass.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
vector2d.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
{
switch (lua.GetType(1))
switch (lua.GetType(2))
{
case Nz::LuaType_Number:
{
long long index = lua.CheckInteger(1);
long long index = lua.CheckInteger(2);
if (index < 1 || index > 2)
return false;
instance[index - 1] = lua.CheckNumber(2);
instance[index - 1] = lua.CheckNumber(3);
return true;
}
case Nz::LuaType_String:
{
std::size_t length;
const char* xy = lua.CheckString(1, &length);
const char* xy = lua.CheckString(2, &length);
if (length != 1)
break;
double value = lua.CheckNumber(2);
double value = lua.CheckNumber(3);
switch (xy[0])
{
@@ -540,7 +745,7 @@ namespace Ndk
});
/*********************************** Nz::Vector3 **********************************/
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount)
vector3d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount)
{
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
@@ -582,15 +787,15 @@ namespace Ndk
return false;
});
vector3dClass.BindMethod("__tostring", &Nz::Vector3d::ToString);
vector3d.BindMethod("__tostring", &Nz::Vector3d::ToString);
vector3dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
vector3d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
{
switch (lua.GetType(1))
switch (lua.GetType(2))
{
case Nz::LuaType_Number:
{
long long index = lua.CheckInteger(1);
long long index = lua.CheckInteger(2);
if (index < 1 || index > 3)
return false;
@@ -601,7 +806,7 @@ namespace Ndk
case Nz::LuaType_String:
{
std::size_t length;
const char* xyz = lua.CheckString(1, &length);
const char* xyz = lua.CheckString(2, &length);
if (length != 1)
break;
@@ -633,29 +838,29 @@ namespace Ndk
return false;
});
vector3dClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
vector3d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
{
switch (lua.GetType(1))
switch (lua.GetType(2))
{
case Nz::LuaType_Number:
{
long long index = lua.CheckInteger(1);
long long index = lua.CheckInteger(2);
if (index < 1 || index > 3)
return false;
instance[index - 1] = lua.CheckNumber(2);
instance[index - 1] = lua.CheckNumber(3);
return true;
}
case Nz::LuaType_String:
{
std::size_t length;
const char* xyz = lua.CheckString(1, &length);
const char* xyz = lua.CheckString(2, &length);
if (length != 1)
break;
double value = lua.CheckNumber(2);
double value = lua.CheckNumber(3);
switch (xyz[0])
{
@@ -693,10 +898,11 @@ namespace Ndk
void LuaBinding::RegisterMath(Nz::LuaInstance& instance)
{
eulerAnglesClass.Register(instance);
quaternionClass.Register(instance);
rectClass.Register(instance);
vector2dClass.Register(instance);
vector3dClass.Register(instance);
eulerAngles.Register(instance);
matrix4d.Register(instance);
quaternion.Register(instance);
rect.Register(instance);
vector2d.Register(instance);
vector3d.Register(instance);
}
}

View File

@@ -12,20 +12,20 @@ namespace Ndk
void LuaBinding::BindNetwork()
{
/*********************************** Nz::AbstractSocket **********************************/
abstractSocketClass.BindMethod("Close", &Nz::AbstractSocket::Close);
abstractSocketClass.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
abstractSocketClass.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
abstractSocketClass.BindMethod("GetState", &Nz::AbstractSocket::GetState);
abstractSocketClass.BindMethod("GetType", &Nz::AbstractSocket::GetType);
abstractSocketClass.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
abstractSocketClass.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
abstractSocket.BindMethod("Close", &Nz::AbstractSocket::Close);
abstractSocket.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
abstractSocket.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
abstractSocket.BindMethod("GetState", &Nz::AbstractSocket::GetState);
abstractSocket.BindMethod("GetType", &Nz::AbstractSocket::GetType);
abstractSocket.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
abstractSocket.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
/*********************************** Nz::IpAddress **********************************/
ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* address, std::size_t argumentCount)
ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* address, std::size_t argumentCount)
{
std::size_t argCount = std::min<std::size_t>(argumentCount, 9U);
int argIndex = 1;
int argIndex = 2;
switch (argCount)
{
case 0:
@@ -71,19 +71,19 @@ namespace Ndk
return false;
});
ipAddressClass.BindMethod("GetPort", &Nz::IpAddress::GetPort);
ipAddressClass.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol);
ipAddressClass.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback);
ipAddressClass.BindMethod("IsValid", &Nz::IpAddress::IsValid);
ipAddressClass.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32);
ipAddressClass.BindMethod("__tostring", &Nz::IpAddress::ToString);
ipAddress.BindMethod("GetPort", &Nz::IpAddress::GetPort);
ipAddress.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol);
ipAddress.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback);
ipAddress.BindMethod("IsValid", &Nz::IpAddress::IsValid);
ipAddress.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32);
ipAddress.BindMethod("__tostring", &Nz::IpAddress::ToString);
ipAddressClass.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int
ipAddress.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int
{
Nz::String service;
Nz::ResolveError error = Nz::ResolveError_Unknown;
int argIndex = 1;
int argIndex = 2;
Nz::String hostName = Nz::IpAddress::ResolveAddress(instance.Check<Nz::IpAddress>(&argIndex), &service, &error);
if (error == Nz::ResolveError_NoError)
@@ -100,11 +100,11 @@ namespace Ndk
}
});
ipAddressClass.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int
ipAddress.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int
{
Nz::ResolveError error = Nz::ResolveError_Unknown;
int argIndex = 1;
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");
@@ -145,8 +145,8 @@ namespace Ndk
void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance)
{
// Classes
abstractSocketClass.Register(instance);
ipAddressClass.Register(instance);
abstractSocket.Register(instance);
ipAddress.Register(instance);
// Enums

View File

@@ -10,9 +10,58 @@ namespace Ndk
/*!
* \brief Binds Renderer module to Lua
*/
void LuaBinding::BindRenderer()
{
/*********************************** Nz::Texture ***********************************/
texture.Inherit<Nz::AbstractImageRef>(abstractImage, [] (Nz::TextureRef* texture) -> Nz::AbstractImageRef*
{
return reinterpret_cast<Nz::AbstractImageRef*>(texture); //TODO: Make a ObjectRefCast
});
texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* texture, std::size_t /*argumentCount*/)
{
Nz::PlacementNew(texture, Nz::Texture::New());
return true;
});
texture.BindMethod("Create", &Nz::Texture::Create, static_cast<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);
}
/*!
@@ -20,8 +69,8 @@ namespace Ndk
*
* \param instance Lua instance that will interact with the Renderer classes
*/
void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance)
{
texture.Register(instance);
}
}

View File

@@ -25,7 +25,7 @@ namespace Ndk
application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled);
#endif
application.BindMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application) -> int
application.BindMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application, std::size_t /*argumentCount*/) -> int
{
instance.Push(application->AddWorld().CreateHandle());
return 1;
@@ -36,58 +36,58 @@ namespace Ndk
/*********************************** Ndk::Console **********************************/
#ifndef NDK_SERVER
consoleClass.Inherit<Nz::Node>(nodeClass, [] (ConsoleHandle* handle) -> Nz::Node*
console.Inherit<Nz::Node>(node, [] (ConsoleHandle* handle) -> Nz::Node*
{
return handle->GetObject();
});
consoleClass.BindMethod("AddLine", &Console::AddLine, Nz::Color::White);
consoleClass.BindMethod("Clear", &Console::Clear);
consoleClass.BindMethod("GetCharacterSize", &Console::GetCharacterSize);
consoleClass.BindMethod("GetHistory", &Console::GetHistory);
consoleClass.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground);
consoleClass.BindMethod("GetInput", &Console::GetInput);
consoleClass.BindMethod("GetInputBackground", &Console::GetInputBackground);
consoleClass.BindMethod("GetSize", &Console::GetSize);
consoleClass.BindMethod("GetTextFont", &Console::GetTextFont);
console.BindMethod("AddLine", &Console::AddLine, Nz::Color::White);
console.BindMethod("Clear", &Console::Clear);
console.BindMethod("GetCharacterSize", &Console::GetCharacterSize);
console.BindMethod("GetHistory", &Console::GetHistory);
console.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground);
console.BindMethod("GetInput", &Console::GetInput);
console.BindMethod("GetInputBackground", &Console::GetInputBackground);
console.BindMethod("GetSize", &Console::GetSize);
console.BindMethod("GetTextFont", &Console::GetTextFont);
consoleClass.BindMethod("IsVisible", &Console::IsVisible);
console.BindMethod("IsVisible", &Console::IsVisible);
consoleClass.BindMethod("SendCharacter", &Console::SendCharacter);
console.BindMethod("SendCharacter", &Console::SendCharacter);
//consoleClass.SetMethod("SendEvent", &Console::SendEvent);
consoleClass.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
consoleClass.BindMethod("SetSize", &Console::SetSize);
consoleClass.BindMethod("SetTextFont", &Console::SetTextFont);
console.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
console.BindMethod("SetSize", &Console::SetSize);
console.BindMethod("SetTextFont", &Console::SetTextFont);
consoleClass.BindMethod("Show", &Console::Show, true);
console.BindMethod("Show", &Console::Show, true);
#endif
/*********************************** Ndk::Entity **********************************/
entityClass.BindMethod("Enable", &Entity::Enable, true);
entityClass.BindMethod("GetId", &Entity::GetId);
entityClass.BindMethod("GetWorld", &Entity::GetWorld);
entityClass.BindMethod("Kill", &Entity::Kill);
entityClass.BindMethod("IsEnabled", &Entity::IsEnabled);
entityClass.BindMethod("IsValid", &Entity::IsValid);
entityClass.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
entityClass.BindMethod("__tostring", &EntityHandle::ToString);
entity.BindMethod("Enable", &Entity::Enable, true);
entity.BindMethod("GetId", &Entity::GetId);
entity.BindMethod("GetWorld", &Entity::GetWorld);
entity.BindMethod("Kill", &Entity::Kill);
entity.BindMethod("IsEnabled", &Entity::IsEnabled);
entity.BindMethod("IsValid", &Entity::IsValid);
entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
entity.BindMethod("__tostring", &EntityHandle::ToString);
entityClass.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int
entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
{
ComponentBinding* binding = QueryComponentIndex(instance);
return binding->adder(instance, handle);
});
entityClass.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int
entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
{
ComponentBinding* binding = QueryComponentIndex(instance);
return binding->getter(instance, handle->GetComponent(binding->index));
});
entityClass.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle) -> int
entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
{
ComponentBinding* binding = QueryComponentIndex(instance);
@@ -96,7 +96,7 @@ namespace Ndk
});
/*********************************** Ndk::NodeComponent **********************************/
nodeComponent.Inherit<Nz::Node>(nodeClass, [] (NodeComponentHandle* handle) -> Nz::Node*
nodeComponent.Inherit<Nz::Node>(node, [] (NodeComponentHandle* handle) -> Nz::Node*
{
return handle->GetObject();
});
@@ -105,7 +105,7 @@ namespace Ndk
velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
{
std::size_t length;
const char* member = lua.CheckString(1, &length);
const char* member = lua.CheckString(2, &length);
if (std::strcmp(member, "Linear") == 0)
{
@@ -119,9 +119,9 @@ namespace Ndk
velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
{
std::size_t length;
const char* member = lua.CheckString(1, &length);
const char* member = lua.CheckString(2, &length);
int argIndex = 2;
int argIndex = 3;
if (std::strcmp(member, "Linear") == 0)
{
instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
@@ -132,14 +132,69 @@ namespace Ndk
});
/*********************************** Ndk::World **********************************/
worldClass.BindMethod("CreateEntity", &World::CreateEntity);
worldClass.BindMethod("CreateEntities", &World::CreateEntities);
worldClass.BindMethod("Clear", &World::Clear);
world.BindMethod("CreateEntity", &World::CreateEntity);
world.BindMethod("CreateEntities", &World::CreateEntities);
world.BindMethod("Clear", &World::Clear);
#ifndef NDK_SERVER
/*********************************** Ndk::GraphicsComponent **********************************/
graphicsComponent.BindMethod("Attach", (void(Ndk::GraphicsComponent::*)(Nz::InstancedRenderableRef, int)) &GraphicsComponent::Attach, 0);
graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent *gfxComponent, std::size_t argumentCount) -> int
{
/*
void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
*/
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
switch (argCount)
{
case 1:
{
int argIndex = 2;
gfxComponent->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);
gfxComponent->Attach(renderable, renderOrder);
}
else if (lua.IsOfType(argIndex, "Matrix4"))
{
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
gfxComponent->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);
gfxComponent->Attach(renderable, localMatrix, renderOrder);
return 0;
}
}
lua.Error("No matching overload for method GetMemoryUsage");
return 0;
});
#endif
@@ -164,13 +219,13 @@ namespace Ndk
{
// Classes
application.Register(instance);
entityClass.Register(instance);
entity.Register(instance);
nodeComponent.Register(instance);
velocityComponent.Register(instance);
worldClass.Register(instance);
world.Register(instance);
#ifndef NDK_SERVER
consoleClass.Register(instance);
console.Register(instance);
graphicsComponent.Register(instance);
#endif

View File

@@ -25,9 +25,9 @@ namespace Ndk
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage, std::size_t argumentCount) -> int
{
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
switch (argCount)
{
case 0:
@@ -35,8 +35,8 @@ namespace Ndk
case 1:
{
int index = 1;
Nz::UInt8 level(lua.Check<Nz::UInt8>(&index));
int argIndex = 2;
Nz::UInt8 level(lua.Check<Nz::UInt8>(&argIndex));
return lua.Push(abstractImage->GetMemoryUsage(level));
}
@@ -46,10 +46,10 @@ namespace Ndk
return 0;
});
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage, std::size_t argumentCount) -> int
{
unsigned int argCount = std::min(lua.GetStackTop(), 6U);
int argIndex = 1;
std::size_t argCount = std::min<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));
@@ -93,25 +93,23 @@ namespace Ndk
});
/*********************************** Nz::Font **********************************/
fontClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::FontRef* font, std::size_t argumentCount)
font.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* font, std::size_t /*argumentCount*/)
{
NazaraUnused(argumentCount);
Nz::PlacementNew(font, Nz::Font::New());
return true;
});
fontClass.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache);
fontClass.BindMethod("ClearKerningCache", &Nz::Font::ClearKerningCache);
fontClass.BindMethod("ClearSizeInfoCache", &Nz::Font::ClearSizeInfoCache);
font.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache);
font.BindMethod("ClearKerningCache", &Nz::Font::ClearKerningCache);
font.BindMethod("ClearSizeInfoCache", &Nz::Font::ClearSizeInfoCache);
fontClass.BindMethod("Destroy", &Nz::Font::Destroy);
font.BindMethod("Destroy", &Nz::Font::Destroy);
fontClass.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance) -> int
font.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance, std::size_t argumentCount) -> int
{
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
int argIndex = 1;
int argIndex = 2;
switch (argCount)
{
case 0:
@@ -132,78 +130,78 @@ namespace Ndk
return 0;
});
fontClass.BindMethod("GetFamilyName", &Nz::Font::GetFamilyName);
fontClass.BindMethod("GetKerning", &Nz::Font::GetKerning);
fontClass.BindMethod("GetGlyphBorder", &Nz::Font::GetGlyphBorder);
fontClass.BindMethod("GetMinimumStepSize", &Nz::Font::GetMinimumStepSize);
fontClass.BindMethod("GetSizeInfo", &Nz::Font::GetSizeInfo);
fontClass.BindMethod("GetStyleName", &Nz::Font::GetStyleName);
font.BindMethod("GetFamilyName", &Nz::Font::GetFamilyName);
font.BindMethod("GetKerning", &Nz::Font::GetKerning);
font.BindMethod("GetGlyphBorder", &Nz::Font::GetGlyphBorder);
font.BindMethod("GetMinimumStepSize", &Nz::Font::GetMinimumStepSize);
font.BindMethod("GetSizeInfo", &Nz::Font::GetSizeInfo);
font.BindMethod("GetStyleName", &Nz::Font::GetStyleName);
fontClass.BindMethod("IsValid", &Nz::Font::IsValid);
font.BindMethod("IsValid", &Nz::Font::IsValid);
fontClass.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::UInt32, const Nz::String&) const) &Nz::Font::Precache);
font.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::UInt32, const Nz::String&) const) &Nz::Font::Precache);
fontClass.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams());
font.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams());
fontClass.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder);
fontClass.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize);
font.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder);
font.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize);
fontClass.BindStaticMethod("GetDefault", &Nz::Font::GetDefault);
fontClass.BindStaticMethod("GetDefaultGlyphBorder", &Nz::Font::GetDefaultGlyphBorder);
fontClass.BindStaticMethod("GetDefaultMinimumStepSize", &Nz::Font::GetDefaultMinimumStepSize);
font.BindStaticMethod("GetDefault", &Nz::Font::GetDefault);
font.BindStaticMethod("GetDefaultGlyphBorder", &Nz::Font::GetDefaultGlyphBorder);
font.BindStaticMethod("GetDefaultMinimumStepSize", &Nz::Font::GetDefaultMinimumStepSize);
fontClass.BindStaticMethod("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder);
fontClass.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize);
font.BindStaticMethod("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder);
font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize);
/*********************************** Nz::Node **********************************/
nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward);
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
//nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds);
nodeClass.BindMethod("GetDown", &Nz::Node::GetDown);
nodeClass.BindMethod("GetForward", &Nz::Node::GetForward);
nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
node.BindMethod("GetDown", &Nz::Node::GetDown);
node.BindMethod("GetForward", &Nz::Node::GetForward);
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
//nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft);
nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
//nodeClass.SetMethod("GetParent", &Nz::Node::GetParent);
nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
nodeClass.BindMethod("GetRight", &Nz::Node::GetRight);
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
node.BindMethod("GetRight", &Nz::Node::GetRight);
//nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
//nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix);
nodeClass.BindMethod("GetUp", &Nz::Node::GetUp);
node.BindMethod("GetUp", &Nz::Node::GetUp);
nodeClass.BindMethod("HasChilds", &Nz::Node::HasChilds);
node.BindMethod("HasChilds", &Nz::Node::HasChilds);
nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward);
nodeClass.BindMethod("GetDown", &Nz::Node::GetDown);
nodeClass.BindMethod("GetForward", &Nz::Node::GetForward);
nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
nodeClass.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft);
nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
nodeClass.BindMethod("GetRight", &Nz::Node::GetRight);
nodeClass.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
nodeClass.BindMethod("GetUp", &Nz::Node::GetUp);
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
node.BindMethod("GetDown", &Nz::Node::GetDown);
node.BindMethod("GetForward", &Nz::Node::GetForward);
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
node.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
node.BindMethod("GetRight", &Nz::Node::GetRight);
node.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
node.BindMethod("GetUp", &Nz::Node::GetUp);
nodeClass.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
nodeClass.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation);
node.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
node.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation);
nodeClass.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
nodeClass.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
node.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
node.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
nodeClass.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t /*argumentCount*/) -> int
{
int argIndex = 1;
int argIndex = 2;
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
@@ -212,9 +210,9 @@ namespace Ndk
return 0;
});
nodeClass.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t /*argumentCount*/) -> int
{
int argIndex = 1;
int argIndex = 2;
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
@@ -223,11 +221,11 @@ namespace Ndk
return 0;
});
nodeClass.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t argumentCount) -> int
{
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
int argIndex = 1;
int argIndex = 2;
switch (argCount)
{
case 1:
@@ -249,11 +247,11 @@ namespace Ndk
return 0;
});
nodeClass.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t argumentCount) -> int
{
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
int argIndex = 1;
int argIndex = 2;
switch (argCount)
{
case 1:
@@ -286,11 +284,11 @@ namespace Ndk
return 0;
});
nodeClass.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node, std::size_t argumentCount) -> int
{
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
int argIndex = 1;
int argIndex = 2;
switch (argCount)
{
case 1:
@@ -323,7 +321,7 @@ namespace Ndk
void LuaBinding::RegisterUtility(Nz::LuaInstance& instance)
{
abstractImage.Register(instance);
fontClass.Register(instance);
nodeClass.Register(instance);
font.Register(instance);
node.Register(instance);
}
}

View File

@@ -9,15 +9,15 @@
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Lua/Lua.hpp>
#include <Nazara/Noise/Noise.hpp>
#include <Nazara/Physics/Physics.hpp>
#include <Nazara/Physics3D/Physics3D.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <NDK/Algorithm.hpp>
#include <NDK/BaseSystem.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Components/VelocityComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
#include <NDK/Systems/VelocitySystem.hpp>
#ifndef NDK_SERVER
@@ -68,7 +68,7 @@ namespace Ndk
Nz::Lua::Initialize();
Nz::Noise::Initialize();
Nz::Physics::Initialize();
Nz::Physics3D::Initialize();
Nz::Utility::Initialize();
#ifndef NDK_SERVER
@@ -83,9 +83,9 @@ namespace Ndk
BaseComponent::Initialize();
// Shared components
InitializeComponent<CollisionComponent>("NdkColli");
InitializeComponent<CollisionComponent3D>("NdkColli");
InitializeComponent<NodeComponent>("NdkNode");
InitializeComponent<PhysicsComponent>("NdkPhys");
InitializeComponent<PhysicsComponent3D>("NdkPhys");
InitializeComponent<VelocityComponent>("NdkVeloc");
#ifndef NDK_SERVER
@@ -103,7 +103,7 @@ namespace Ndk
BaseSystem::Initialize();
// Shared systems
InitializeSystem<PhysicsSystem>();
InitializeSystem<PhysicsSystem3D>();
InitializeSystem<VelocitySystem>();
#ifndef NDK_SERVER
@@ -161,7 +161,7 @@ namespace Ndk
// Shared modules
Nz::Lua::Uninitialize();
Nz::Noise::Uninitialize();
Nz::Physics::Uninitialize();
Nz::Physics3D::Uninitialize();
Nz::Utility::Uninitialize();
NazaraNotice("Uninitialized: SDK");

View File

@@ -2,11 +2,11 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Systems/PhysicsSystem.hpp>
#include <Nazara/Physics/PhysObject.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
namespace Ndk
{
@@ -15,7 +15,7 @@ namespace Ndk
* \class Ndk::PhysicsSystem
* \brief NDK class that represents the physics system
*
* \remark This system is enabled if the entity has the trait: NodeComponent and any of these two: CollisionComponent or PhysicsComponent
* \remark This system is enabled if the entity has the trait: NodeComponent and any of these two: CollisionComponent3D or PhysicsComponent3D
* \remark Static objects do not have a velocity specified by the physical engine
*/
@@ -23,10 +23,10 @@ namespace Ndk
* \brief Constructs an PhysicsSystem object by default
*/
PhysicsSystem::PhysicsSystem()
PhysicsSystem3D::PhysicsSystem3D()
{
Requires<NodeComponent>();
RequiresAny<CollisionComponent, PhysicsComponent>();
RequiresAny<CollisionComponent3D, PhysicsComponent3D>();
}
/*!
@@ -35,12 +35,19 @@ namespace Ndk
* \param system PhysicsSystem to copy
*/
PhysicsSystem::PhysicsSystem(const PhysicsSystem& system) :
PhysicsSystem3D::PhysicsSystem3D(const PhysicsSystem3D& system) :
System(system),
m_world()
{
}
void PhysicsSystem3D::CreatePhysWorld() const
{
NazaraAssert(!m_world, "Physics world should not be created twice");
m_world = std::make_unique<Nz::PhysWorld3D>();
}
/*!
* \brief Operation to perform when entity is validated for the system
*
@@ -48,18 +55,21 @@ namespace Ndk
* \param justAdded Is the entity newly added
*/
void PhysicsSystem::OnEntityValidation(Entity* entity, bool justAdded)
void PhysicsSystem3D::OnEntityValidation(Entity* entity, bool justAdded)
{
// If entity has not been just added to the system, it is possible that it does not own to the right array
// It's possible our entity got revalidated because of the addition/removal of a PhysicsComponent3D
if (!justAdded)
{
// We take the inverted array from which the entity should belong to
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_staticObjects : m_dynamicObjects;
// We take the opposite array from which the entity should belong to
auto& entities = (entity->HasComponent<PhysicsComponent3D>()) ? m_staticObjects : m_dynamicObjects;
entities.Remove(entity);
}
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_dynamicObjects : m_staticObjects;
auto& entities = (entity->HasComponent<PhysicsComponent3D>()) ? m_dynamicObjects : m_staticObjects;
entities.Insert(entity);
if (!m_world)
CreatePhysWorld();
}
/*!
@@ -68,16 +78,19 @@ namespace Ndk
* \param elapsedTime Delta time used for the update
*/
void PhysicsSystem::OnUpdate(float elapsedTime)
void PhysicsSystem3D::OnUpdate(float elapsedTime)
{
m_world.Step(elapsedTime);
if (!m_world)
return;
m_world->Step(elapsedTime);
for (const Ndk::EntityHandle& entity : m_dynamicObjects)
{
NodeComponent& node = entity->GetComponent<NodeComponent>();
PhysicsComponent& phys = entity->GetComponent<PhysicsComponent>();
PhysicsComponent3D& phys = entity->GetComponent<PhysicsComponent3D>();
Nz::PhysObject& physObj = phys.GetPhysObject();
Nz::RigidBody3D& physObj = phys.GetPhysObject();
node.SetRotation(physObj.GetRotation(), Nz::CoordSys_Global);
node.SetPosition(physObj.GetPosition(), Nz::CoordSys_Global);
}
@@ -85,10 +98,10 @@ namespace Ndk
float invElapsedTime = 1.f / elapsedTime;
for (const Ndk::EntityHandle& entity : m_staticObjects)
{
CollisionComponent& collision = entity->GetComponent<CollisionComponent>();
CollisionComponent3D& collision = entity->GetComponent<CollisionComponent3D>();
NodeComponent& node = entity->GetComponent<NodeComponent>();
Nz::PhysObject* physObj = collision.GetStaticBody();
Nz::RigidBody3D* physObj = collision.GetStaticBody();
Nz::Quaternionf oldRotation = physObj->GetRotation();
Nz::Vector3f oldPosition = physObj->GetPosition();
@@ -121,5 +134,5 @@ namespace Ndk
}
}
SystemIndex PhysicsSystem::systemIndex;
SystemIndex PhysicsSystem3D::systemIndex;
}

View File

@@ -147,7 +147,6 @@ namespace Ndk
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}
@@ -186,7 +185,7 @@ namespace Ndk
* \param viewer Viewer of the scene
*/
void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer)
void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& /*viewer*/)
{
if (!m_shadowRT.IsValid())
m_shadowRT.Create();
@@ -217,7 +216,6 @@ namespace Ndk
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}
@@ -290,7 +288,6 @@ namespace Ndk
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}
@@ -318,7 +315,6 @@ namespace Ndk
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}

View File

@@ -4,7 +4,7 @@
#include <NDK/Systems/VelocitySystem.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Components/VelocityComponent.hpp>
namespace Ndk
@@ -15,7 +15,7 @@ namespace Ndk
* \brief NDK class that represents the velocity system
*
* \remark This system is enabled if the entity owns the trait: NodeComponent and VelocityComponent
* but it's disabled with the trait: PhysicsComponent
* but it's disabled with the trait: PhysicsComponent3D
*/
/*!
@@ -25,7 +25,7 @@ namespace Ndk
VelocitySystem::VelocitySystem()
{
Requires<NodeComponent, VelocityComponent>();
Excludes<PhysicsComponent>();
Excludes<PhysicsComponent3D>();
}
/*!

View File

@@ -5,7 +5,7 @@
#include <NDK/World.hpp>
#include <Nazara/Core/Error.hpp>
#include <NDK/BaseComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
#include <NDK/Systems/VelocitySystem.hpp>
#ifndef NDK_SERVER
@@ -40,7 +40,7 @@ namespace Ndk
void World::AddDefaultSystems()
{
AddSystem<PhysicsSystem>();
AddSystem<PhysicsSystem3D>();
AddSystem<VelocitySystem>();
#ifndef NDK_SERVER