Merge branch 'master' into NDK-ShadowMapping
Former-commit-id: e2be28b65207dfbb81efe58f31ca31548afecee7
This commit is contained in:
@@ -20,6 +20,6 @@ namespace Ndk
|
||||
template<typename SystemType, typename S> bool IsSystem(S& system);
|
||||
}
|
||||
|
||||
#include <Ndk/Algorithm.inl>
|
||||
#include <NDK/Algorithm.inl>
|
||||
|
||||
#endif // NDK_ALGORITHM_HPP
|
||||
|
||||
@@ -8,14 +8,51 @@
|
||||
#define NDK_APPLICATION_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API Application
|
||||
{
|
||||
public:
|
||||
Application();
|
||||
~Application();
|
||||
inline Application();
|
||||
Application(const Application&) = delete;
|
||||
Application(Application&&) = delete;
|
||||
inline ~Application();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
template<typename T, typename... Args> T& AddWindow(Args&&... args);
|
||||
#endif
|
||||
template<typename... Args> World& AddWorld(Args&&... args);
|
||||
|
||||
inline float GetUpdateTime() const;
|
||||
|
||||
bool Run();
|
||||
|
||||
inline void Quit();
|
||||
|
||||
Application& operator=(const Application&) = delete;
|
||||
Application& operator=(Application&&) = delete;
|
||||
|
||||
inline static Application* Instance();
|
||||
|
||||
private:
|
||||
#ifndef NDK_SERVER
|
||||
std::vector<std::unique_ptr<Nz::Window>> m_windows;
|
||||
#endif
|
||||
std::list<World> m_worlds;
|
||||
Nz::Clock m_updateClock;
|
||||
#ifndef NDK_SERVER
|
||||
bool m_exitOnClosedWindows;
|
||||
#endif
|
||||
bool m_shouldQuit;
|
||||
float m_updateTime;
|
||||
|
||||
static Application* s_application;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,21 @@
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <type_traits>
|
||||
#include <NDK/Sdk.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline Application::Application()
|
||||
inline Application::Application() :
|
||||
#ifndef NDK_SERVER
|
||||
m_exitOnClosedWindows(true),
|
||||
#endif
|
||||
m_shouldQuit(false),
|
||||
m_updateTime(0.f)
|
||||
{
|
||||
NazaraAssert(s_application == nullptr, "You can create only one application instance per program");
|
||||
s_application = this;
|
||||
|
||||
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
|
||||
|
||||
// Initialisation du SDK
|
||||
@@ -17,9 +26,48 @@ namespace Ndk
|
||||
|
||||
inline Application::~Application()
|
||||
{
|
||||
m_worlds.clear();
|
||||
#ifndef NDK_SERVER
|
||||
m_windows.clear();
|
||||
#endif
|
||||
|
||||
// Libération du SDK
|
||||
Sdk::Uninitialize();
|
||||
|
||||
// Libération automatique des modules
|
||||
s_application = nullptr;
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
template<typename T, typename... Args>
|
||||
T& Application::AddWindow(Args&&... args)
|
||||
{
|
||||
static_assert(std::is_base_of<Nz::Window, T>::value, "Type must inherit Window");
|
||||
|
||||
m_windows.emplace_back(new T(std::forward<Args>(args)...));
|
||||
return static_cast<T&>(*m_windows.back().get());
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename... Args>
|
||||
World& Application::AddWorld(Args&&... args)
|
||||
{
|
||||
m_worlds.emplace_back(std::forward<Args>(args)...);
|
||||
return m_worlds.back();
|
||||
}
|
||||
|
||||
inline float Application::GetUpdateTime() const
|
||||
{
|
||||
return m_updateTime;
|
||||
}
|
||||
|
||||
inline void Application::Quit()
|
||||
{
|
||||
m_shouldQuit = true;
|
||||
}
|
||||
|
||||
inline Application* Application::Instance()
|
||||
{
|
||||
return s_application;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#ifndef NDK_BASECOMPONENT_HPP
|
||||
#define NDK_BASECOMPONENT_HPP
|
||||
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
@@ -31,6 +31,8 @@ namespace Ndk
|
||||
|
||||
ComponentIndex GetIndex() const;
|
||||
|
||||
inline static ComponentIndex GetMaxComponentIndex();
|
||||
|
||||
BaseComponent& operator=(const BaseComponent&) = default;
|
||||
BaseComponent& operator=(BaseComponent&&) = default;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
namespace Ndk
|
||||
@@ -17,6 +18,11 @@ namespace Ndk
|
||||
return m_componentIndex;
|
||||
}
|
||||
|
||||
inline ComponentIndex BaseComponent::GetMaxComponentIndex()
|
||||
{
|
||||
return static_cast<ComponentIndex>(s_entries.size());
|
||||
}
|
||||
|
||||
inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc)
|
||||
{
|
||||
// Nous allons rajouter notre composant à la fin
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define NDK_BASESYSTEM_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
@@ -71,7 +71,7 @@ namespace Ndk
|
||||
|
||||
inline void RemoveEntity(Entity* entity);
|
||||
|
||||
inline void SetWorld(World& world);
|
||||
inline void SetWorld(World* world) noexcept;
|
||||
|
||||
inline void ValidateEntity(Entity* entity, bool justAdded);
|
||||
|
||||
|
||||
@@ -60,14 +60,16 @@ namespace Ndk
|
||||
{
|
||||
if (m_updateRate > 0.f)
|
||||
{
|
||||
m_updateCounter -= elapsedTime;
|
||||
if (m_updateCounter >= 0.f)
|
||||
return;
|
||||
m_updateCounter += elapsedTime;
|
||||
|
||||
m_updateCounter += m_updateRate;
|
||||
while (m_updateCounter >= m_updateRate)
|
||||
{
|
||||
OnUpdate(m_updateRate);
|
||||
m_updateCounter -= m_updateRate;
|
||||
}
|
||||
}
|
||||
|
||||
OnUpdate(elapsedTime);
|
||||
else
|
||||
OnUpdate(elapsedTime);
|
||||
}
|
||||
|
||||
template<typename ComponentType>
|
||||
@@ -172,9 +174,9 @@ namespace Ndk
|
||||
OnEntityValidation(entity, justAdded);
|
||||
}
|
||||
|
||||
inline void BaseSystem::SetWorld(World& world)
|
||||
inline void BaseSystem::SetWorld(World* world) noexcept
|
||||
{
|
||||
m_world = &world;
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
inline bool BaseSystem::Initialize()
|
||||
@@ -186,6 +188,6 @@ namespace Ndk
|
||||
|
||||
inline void BaseSystem::Uninitialize()
|
||||
{
|
||||
// Rien à faire
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Ndk/Algorithm.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Ndk
|
||||
|
||||
20
SDK/include/NDK/Components.hpp
Normal file
20
SDK/include/NDK/Components.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// This file was automatically generated on 03 Mar 2016 at 14:09:12
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_COMPONENTS_GLOBAL_HPP
|
||||
#define NDK_COMPONENTS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Components/CollisionComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#endif
|
||||
|
||||
#endif // NDK_COMPONENTS_GLOBAL_HPP
|
||||
@@ -33,24 +33,27 @@ namespace Ndk
|
||||
inline void EnsureViewMatrixUpdate() const;
|
||||
inline void EnsureViewportUpdate() const;
|
||||
|
||||
inline float GetAspectRatio() const;
|
||||
inline Nz::Vector3f GetEyePosition() const;
|
||||
inline Nz::Vector3f GetForward() const;
|
||||
inline float GetAspectRatio() const override;
|
||||
inline Nz::Vector3f GetEyePosition() const override;
|
||||
inline Nz::Vector3f GetForward() const override;
|
||||
inline float GetFOV() const;
|
||||
inline const Nz::Frustumf& GetFrustum() const;
|
||||
inline const Nz::Frustumf& GetFrustum() const override;
|
||||
inline unsigned int GetLayer() const;
|
||||
inline const Nz::Matrix4f& GetProjectionMatrix() const;
|
||||
inline const Nz::Matrix4f& GetProjectionMatrix() const override;
|
||||
inline Nz::ProjectionType GetProjectionType() const;
|
||||
inline const Nz::RenderTarget* GetTarget() const;
|
||||
inline const Nz::Vector2f& GetSize() const;
|
||||
inline const Nz::RenderTarget* GetTarget() const override;
|
||||
inline const Nz::Rectf& GetTargetRegion() const;
|
||||
inline const Nz::Matrix4f& GetViewMatrix() const;
|
||||
inline const Nz::Recti& GetViewport() const;
|
||||
inline float GetZFar() const;
|
||||
inline float GetZNear() const;
|
||||
inline const Nz::Matrix4f& GetViewMatrix() const override;
|
||||
inline const Nz::Recti& GetViewport() const override;
|
||||
inline float GetZFar() const override;
|
||||
inline float GetZNear() const override;
|
||||
|
||||
inline void SetFOV(float fov);
|
||||
inline void SetLayer(unsigned int layer);
|
||||
inline void SetProjectionType(Nz::ProjectionType projection);
|
||||
inline void SetSize(const Nz::Vector2f& size);
|
||||
inline void SetSize(float width, float height);
|
||||
inline void SetTarget(const Nz::RenderTarget* renderTarget);
|
||||
inline void SetTargetRegion(const Nz::Rectf& region);
|
||||
inline void SetViewport(const Nz::Recti& viewport);
|
||||
@@ -89,6 +92,7 @@ namespace Ndk
|
||||
Nz::Rectf m_targetRegion;
|
||||
mutable Nz::Recti m_viewport;
|
||||
const Nz::RenderTarget* m_target;
|
||||
Nz::Vector2f m_size;
|
||||
mutable bool m_frustumUpdated;
|
||||
mutable bool m_projectionMatrixUpdated;
|
||||
mutable bool m_viewMatrixUpdated;
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include "CameraComponent.hpp"
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline CameraComponent::CameraComponent() :
|
||||
m_projectionType(Nz::ProjectionType_Perspective),
|
||||
m_targetRegion(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(0.f),
|
||||
m_target(nullptr),
|
||||
m_frustumUpdated(false),
|
||||
m_projectionMatrixUpdated(false),
|
||||
@@ -28,6 +30,7 @@ namespace Ndk
|
||||
AbstractViewer(camera),
|
||||
m_projectionType(camera.m_projectionType),
|
||||
m_targetRegion(camera.m_targetRegion),
|
||||
m_size(camera.m_size),
|
||||
m_target(nullptr),
|
||||
m_frustumUpdated(false),
|
||||
m_projectionMatrixUpdated(false),
|
||||
@@ -102,6 +105,11 @@ namespace Ndk
|
||||
return m_projectionType;
|
||||
}
|
||||
|
||||
inline const Nz::Vector2f & CameraComponent::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline const Nz::RenderTarget* CameraComponent::GetTarget() const
|
||||
{
|
||||
return m_target;
|
||||
@@ -151,6 +159,18 @@ namespace Ndk
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetSize(const Nz::Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetSize(float width, float height)
|
||||
{
|
||||
SetSize({width, height});
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetTarget(const Nz::RenderTarget* renderTarget)
|
||||
{
|
||||
m_target = renderTarget;
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API GraphicsComponent : public Component<GraphicsComponent>
|
||||
class GraphicsComponent;
|
||||
|
||||
using GraphicsComponentHandle = Nz::ObjectHandle<GraphicsComponent>;
|
||||
|
||||
class NDK_API GraphicsComponent : public Component<GraphicsComponent>, public Nz::HandledObject<GraphicsComponent>
|
||||
{
|
||||
friend class RenderSystem;
|
||||
|
||||
@@ -26,11 +30,15 @@ namespace Ndk
|
||||
|
||||
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||
|
||||
inline void EnsureBoundingVolumeUpdate() const;
|
||||
inline void EnsureTransformMatrixUpdate() const;
|
||||
|
||||
inline const Nz::BoundingVolumef& GetBoundingVolume() const;
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
inline void InvalidateBoundingVolume();
|
||||
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index);
|
||||
inline void InvalidateRenderables();
|
||||
inline void InvalidateTransformMatrix();
|
||||
@@ -41,6 +49,7 @@ namespace Ndk
|
||||
void OnDetached() override;
|
||||
void OnNodeInvalidated(const Nz::Node* node);
|
||||
|
||||
void UpdateBoundingVolume() const;
|
||||
void UpdateTransformMatrix() const;
|
||||
|
||||
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
|
||||
@@ -61,7 +70,9 @@ namespace Ndk
|
||||
};
|
||||
|
||||
std::vector<Renderable> m_renderables;
|
||||
mutable Nz::BoundingVolumef m_boundingVolume;
|
||||
mutable Nz::Matrix4f m_transformMatrix;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
mutable bool m_transformMatrixUpdated;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ namespace Ndk
|
||||
{
|
||||
inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) :
|
||||
Component(graphicsComponent),
|
||||
m_boundingVolume(graphicsComponent.m_boundingVolume),
|
||||
m_transformMatrix(graphicsComponent.m_transformMatrix),
|
||||
m_boundingVolumeUpdated(graphicsComponent.m_boundingVolumeUpdated),
|
||||
m_transformMatrixUpdated(graphicsComponent.m_transformMatrixUpdated)
|
||||
{
|
||||
m_renderables.reserve(graphicsComponent.m_renderables.size());
|
||||
@@ -39,6 +41,14 @@ namespace Ndk
|
||||
r.data.renderOrder = renderOrder;
|
||||
r.renderable = std::move(renderable);
|
||||
r.renderableInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::EnsureBoundingVolumeUpdate() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::EnsureTransformMatrixUpdate() const
|
||||
@@ -47,6 +57,18 @@ namespace Ndk
|
||||
UpdateTransformMatrix();
|
||||
}
|
||||
|
||||
inline const Nz::BoundingVolumef& GraphicsComponent::GetBoundingVolume() const
|
||||
{
|
||||
EnsureBoundingVolumeUpdate();
|
||||
|
||||
return m_boundingVolume;
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::InvalidateBoundingVolume()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::InvalidateRenderables()
|
||||
{
|
||||
for (Renderable& r : m_renderables)
|
||||
@@ -55,6 +77,7 @@ namespace Ndk
|
||||
|
||||
inline void GraphicsComponent::InvalidateTransformMatrix()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
m_transformMatrixUpdated = false;
|
||||
|
||||
InvalidateRenderables();
|
||||
|
||||
@@ -13,8 +13,11 @@
|
||||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
class NodeComponent;
|
||||
|
||||
class NDK_API NodeComponent : public Component<NodeComponent>, public Nz::Node
|
||||
using NodeComponentHandle = Nz::ObjectHandle<NodeComponent>;
|
||||
|
||||
class NDK_API NodeComponent : public Component<NodeComponent>, public Nz::Node, public Nz::HandledObject<NodeComponent>
|
||||
{
|
||||
public:
|
||||
NodeComponent() = default;
|
||||
|
||||
@@ -13,8 +13,11 @@
|
||||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
class VelocityComponent;
|
||||
|
||||
class NDK_API VelocityComponent : public Component<VelocityComponent>
|
||||
using VelocityComponentHandle = Nz::ObjectHandle<VelocityComponent>;
|
||||
|
||||
class NDK_API VelocityComponent : public Component<VelocityComponent>, public Nz::HandledObject<VelocityComponent>
|
||||
{
|
||||
public:
|
||||
VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero());
|
||||
|
||||
101
SDK/include/NDK/Console.hpp
Normal file
101
SDK/include/NDK/Console.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
// 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_CONSOLE_HPP
|
||||
#define NDK_CONSOLE_HPP
|
||||
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Utility/Event.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <NDK/EntityOwner.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class LuaInstance;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class Console;
|
||||
class Entity;
|
||||
|
||||
using ConsoleHandle = Nz::ObjectHandle<Console>;
|
||||
|
||||
class NDK_API Console : public Nz::Node, public Nz::HandledObject<Console>
|
||||
{
|
||||
public:
|
||||
Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance);
|
||||
Console(const Console& console) = delete;
|
||||
Console(Console&& console) = default;
|
||||
~Console() = default;
|
||||
|
||||
void AddLine(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
|
||||
|
||||
void Clear();
|
||||
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const EntityHandle& GetHistory() const;
|
||||
inline const EntityHandle& GetHistoryBackground() const;
|
||||
inline const EntityHandle& GetInput() const;
|
||||
inline const EntityHandle& GetInputBackground() const;
|
||||
inline const Nz::Vector2f& GetSize() const;
|
||||
inline const Nz::FontRef& GetTextFont() const;
|
||||
|
||||
inline bool IsVisible() const;
|
||||
|
||||
void SendCharacter(char32_t character);
|
||||
void SendEvent(Nz::WindowEvent event);
|
||||
|
||||
void SetCharacterSize(unsigned int size);
|
||||
void SetSize(const Nz::Vector2f& size);
|
||||
void SetTextFont(Nz::FontRef font);
|
||||
|
||||
void Show(bool show = true);
|
||||
|
||||
Console& operator=(const Console& console) = delete;
|
||||
Console& operator=(Console&& console) = default;
|
||||
|
||||
private:
|
||||
void AddLineInternal(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
|
||||
void ExecuteInput();
|
||||
void Layout();
|
||||
void RefreshHistory();
|
||||
|
||||
struct Line
|
||||
{
|
||||
Nz::Color color;
|
||||
Nz::String text;
|
||||
};
|
||||
|
||||
std::size_t m_historyPosition;
|
||||
std::vector<Nz::String> m_commandHistory;
|
||||
std::vector<Line> m_historyLines;
|
||||
EntityOwner m_historyBackground;
|
||||
EntityOwner m_history;
|
||||
EntityOwner m_input;
|
||||
EntityOwner m_inputBackground;
|
||||
Nz::FontRef m_defaultFont;
|
||||
Nz::LuaInstance& m_instance;
|
||||
Nz::SpriteRef m_historyBackgroundSprite;
|
||||
Nz::SpriteRef m_inputBackgroundSprite;
|
||||
Nz::SimpleTextDrawer m_historyDrawer;
|
||||
Nz::SimpleTextDrawer m_inputDrawer;
|
||||
Nz::TextSpriteRef m_historyTextSprite;
|
||||
Nz::TextSpriteRef m_inputTextSprite;
|
||||
Nz::Vector2f m_size;
|
||||
bool m_opened;
|
||||
unsigned int m_characterSize;
|
||||
unsigned int m_maxHistoryLines;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Console.inl>
|
||||
|
||||
#endif // NDK_CONSOLE_HPP
|
||||
49
SDK/include/NDK/Console.inl
Normal file
49
SDK/include/NDK/Console.inl
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include "Console.hpp"
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline unsigned int Console::GetCharacterSize() const
|
||||
{
|
||||
return m_characterSize;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetHistory() const
|
||||
{
|
||||
return m_history;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetHistoryBackground() const
|
||||
{
|
||||
return m_historyBackground;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetInput() const
|
||||
{
|
||||
return m_input;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetInputBackground() const
|
||||
{
|
||||
return m_inputBackground;
|
||||
}
|
||||
|
||||
inline const Nz::Vector2f& Console::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline const Nz::FontRef& Console::GetTextFont() const
|
||||
{
|
||||
return m_defaultFont;
|
||||
}
|
||||
|
||||
inline bool Console::IsVisible() const
|
||||
{
|
||||
return m_opened;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NDK_ENTITY_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@@ -15,13 +16,14 @@
|
||||
namespace Ndk
|
||||
{
|
||||
class BaseComponent;
|
||||
class EntityHandle;
|
||||
class Entity;
|
||||
class World;
|
||||
|
||||
class NDK_API Entity
|
||||
using EntityHandle = Nz::ObjectHandle<Entity>;
|
||||
|
||||
class NDK_API Entity : public Nz::HandledObject<Entity>
|
||||
{
|
||||
friend class BaseSystem;
|
||||
friend EntityHandle;
|
||||
friend World;
|
||||
|
||||
public:
|
||||
@@ -32,7 +34,7 @@ namespace Ndk
|
||||
BaseComponent& AddComponent(std::unique_ptr<BaseComponent>&& component);
|
||||
template<typename ComponentType, typename... Args> ComponentType& AddComponent(Args&&... args);
|
||||
|
||||
EntityHandle CreateHandle();
|
||||
inline void Enable(bool enable);
|
||||
|
||||
inline BaseComponent& GetComponent(ComponentIndex index);
|
||||
template<typename ComponentType> ComponentType& GetComponent();
|
||||
@@ -47,32 +49,36 @@ namespace Ndk
|
||||
void Kill();
|
||||
|
||||
void Invalidate();
|
||||
inline bool IsEnabled() const;
|
||||
inline bool IsValid() const;
|
||||
|
||||
void RemoveAllComponents();
|
||||
void RemoveComponent(ComponentIndex index);
|
||||
template<typename ComponentType> void RemoveComponent();
|
||||
|
||||
inline Nz::String ToString() const;
|
||||
|
||||
Entity& operator=(const Entity&) = delete;
|
||||
Entity& operator=(Entity&&) = delete;
|
||||
|
||||
private:
|
||||
Entity(World& world, EntityId id);
|
||||
Entity(World* world, EntityId id);
|
||||
|
||||
void Create();
|
||||
void Destroy();
|
||||
|
||||
inline void RegisterHandle(EntityHandle* handle);
|
||||
inline void RegisterSystem(SystemIndex index);
|
||||
inline void UnregisterHandle(EntityHandle* handle);
|
||||
|
||||
inline void SetWorld(World* world) noexcept;
|
||||
|
||||
inline void UnregisterSystem(SystemIndex index);
|
||||
|
||||
std::vector<std::unique_ptr<BaseComponent>> m_components;
|
||||
std::vector<EntityHandle*> m_handles;
|
||||
Nz::Bitset<> m_componentBits;
|
||||
Nz::Bitset<> m_systemBits;
|
||||
EntityId m_id;
|
||||
World* m_world;
|
||||
bool m_enabled;
|
||||
bool m_valid;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@@ -19,6 +20,15 @@ namespace Ndk
|
||||
return static_cast<ComponentType&>(AddComponent(std::move(ptr)));
|
||||
}
|
||||
|
||||
inline void Entity::Enable(bool enable)
|
||||
{
|
||||
if (m_enabled != enable)
|
||||
{
|
||||
m_enabled = enable;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
inline BaseComponent& Entity::GetComponent(ComponentIndex index)
|
||||
{
|
||||
///DOC: Le component doit être présent
|
||||
@@ -74,6 +84,11 @@ namespace Ndk
|
||||
return HasComponent(index);
|
||||
}
|
||||
|
||||
inline bool Entity::IsEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
inline bool Entity::IsValid() const
|
||||
{
|
||||
return m_valid;
|
||||
@@ -88,10 +103,10 @@ namespace Ndk
|
||||
RemoveComponent(index);
|
||||
}
|
||||
|
||||
inline void Entity::RegisterHandle(EntityHandle* handle)
|
||||
inline Nz::String Entity::ToString() const
|
||||
{
|
||||
///DOC: Un handle ne doit être enregistré qu'une fois, des erreurs se produisent s'il l'est plus d'une fois
|
||||
m_handles.push_back(handle);
|
||||
Nz::StringStream ss;
|
||||
return ss << "Entity(" << GetId() << ')';
|
||||
}
|
||||
|
||||
inline void Entity::RegisterSystem(SystemIndex index)
|
||||
@@ -99,14 +114,11 @@ namespace Ndk
|
||||
m_systemBits.UnboundedSet(index);
|
||||
}
|
||||
|
||||
inline void Entity::UnregisterHandle(EntityHandle* handle)
|
||||
inline void Entity::SetWorld(World* world) noexcept
|
||||
{
|
||||
///DOC: Un handle ne doit être libéré qu'une fois, et doit faire partie de la liste, sous peine de crash
|
||||
auto it = std::find(m_handles.begin(), m_handles.end(), handle);
|
||||
NazaraAssert(world, "An entity must be attached to a world at any time");
|
||||
|
||||
// On échange cet élément avec le dernier, et on diminue la taille du vector de 1
|
||||
std::swap(*it, m_handles.back());
|
||||
m_handles.pop_back();
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
inline void Entity::UnregisterSystem(SystemIndex index)
|
||||
@@ -114,3 +126,19 @@ namespace Ndk
|
||||
m_systemBits.UnboundedReset(index);
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Ndk::EntityHandle>
|
||||
{
|
||||
size_t operator()(const Ndk::EntityHandle& handle) const
|
||||
{
|
||||
// Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée
|
||||
// pour cette raison, nous devons hasher l'ID de l'entité (qui reste constante)
|
||||
Ndk::EntityId id = (handle.IsValid()) ? handle->GetId() : std::numeric_limits<Ndk::EntityId>::max();
|
||||
|
||||
return hash<Ndk::EntityId>()(id);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,89 +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_ENTITYHANDLE_HPP
|
||||
#define NDK_ENTITYHANDLE_HPP
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class EntityHandle
|
||||
{
|
||||
friend Entity;
|
||||
|
||||
public:
|
||||
EntityHandle();
|
||||
explicit EntityHandle(Entity* entity);
|
||||
EntityHandle(const EntityHandle& handle);
|
||||
EntityHandle(EntityHandle&& handle);
|
||||
~EntityHandle();
|
||||
|
||||
Entity* GetEntity() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void Reset(Entity* entity = nullptr);
|
||||
void Reset(const EntityHandle& handle);
|
||||
void Reset(EntityHandle&& handle);
|
||||
|
||||
EntityHandle& Swap(EntityHandle& handle);
|
||||
|
||||
Nz::String ToString() const;
|
||||
|
||||
operator bool() const;
|
||||
operator Entity*() const;
|
||||
Entity* operator->() const;
|
||||
|
||||
EntityHandle& operator=(Entity* entity);
|
||||
EntityHandle& operator=(const EntityHandle& handle);
|
||||
EntityHandle& operator=(EntityHandle&& handle);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const EntityHandle& handle);
|
||||
|
||||
friend bool operator==(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator==(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator==(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator!=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator!=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator!=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator<(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator<=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator>(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator>=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
static const EntityHandle InvalidHandle;
|
||||
|
||||
private:
|
||||
void OnEntityDestroyed();
|
||||
void OnEntityMoved(Entity* newEntity);
|
||||
|
||||
Entity* m_entity;
|
||||
};
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
void swap(Ndk::EntityHandle& lhs, Ndk::EntityHandle& rhs);
|
||||
}
|
||||
|
||||
#include <NDK/EntityHandle.inl>
|
||||
|
||||
#endif // NDK_ENTITYHANDLE_HPP
|
||||
@@ -1,280 +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
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline EntityHandle::EntityHandle() :
|
||||
m_entity(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline EntityHandle::EntityHandle(Entity* entity) :
|
||||
EntityHandle()
|
||||
{
|
||||
Reset(entity);
|
||||
}
|
||||
|
||||
inline EntityHandle::EntityHandle(const EntityHandle& handle) :
|
||||
EntityHandle()
|
||||
{
|
||||
Reset(handle);
|
||||
}
|
||||
|
||||
inline EntityHandle::EntityHandle(EntityHandle&& handle) :
|
||||
EntityHandle()
|
||||
{
|
||||
Reset(handle);
|
||||
}
|
||||
|
||||
inline EntityHandle::~EntityHandle()
|
||||
{
|
||||
Reset(nullptr);
|
||||
}
|
||||
|
||||
inline Entity* EntityHandle::GetEntity() const
|
||||
{
|
||||
return m_entity;
|
||||
}
|
||||
|
||||
inline bool EntityHandle::IsValid() const
|
||||
{
|
||||
return m_entity != nullptr;
|
||||
}
|
||||
|
||||
inline void EntityHandle::Reset(Entity* entity)
|
||||
{
|
||||
// Si nous avions déjà une entité, nous devons l'informer que nous ne pointons plus sur elle
|
||||
if (m_entity)
|
||||
m_entity->UnregisterHandle(this);
|
||||
|
||||
m_entity = entity;
|
||||
if (m_entity)
|
||||
// On informe la nouvelle entité que nous pointons sur elle
|
||||
m_entity->RegisterHandle(this);
|
||||
}
|
||||
|
||||
inline void EntityHandle::Reset(const EntityHandle& handle)
|
||||
{
|
||||
Reset(handle.GetEntity());
|
||||
}
|
||||
|
||||
inline void EntityHandle::Reset(EntityHandle&& handle)
|
||||
{
|
||||
Reset(handle.GetEntity());
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::Swap(EntityHandle& handle)
|
||||
{
|
||||
// Comme nous inversons les handles, nous devons prévenir les entités
|
||||
// La version par défaut de swap (à base de move) aurait fonctionné,
|
||||
// mais en enregistrant les handles une fois de plus que nécessaire (à cause de la copie temporaire).
|
||||
if (m_entity)
|
||||
{
|
||||
m_entity->UnregisterHandle(this);
|
||||
m_entity->RegisterHandle(&handle);
|
||||
}
|
||||
|
||||
if (handle.m_entity)
|
||||
{
|
||||
handle.m_entity->UnregisterHandle(&handle);
|
||||
handle.m_entity->RegisterHandle(this);
|
||||
}
|
||||
|
||||
// On effectue l'échange
|
||||
std::swap(m_entity, handle.m_entity);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Nz::String EntityHandle::ToString() const
|
||||
{
|
||||
Nz::StringStream ss;
|
||||
ss << "EntityHandle(";
|
||||
if (IsValid())
|
||||
ss << "Entity(" << m_entity->GetId() << ')';
|
||||
else
|
||||
ss << "Null entity";
|
||||
|
||||
ss << ')';
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline EntityHandle::operator bool() const
|
||||
{
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
inline EntityHandle::operator Entity*() const
|
||||
{
|
||||
return m_entity;
|
||||
}
|
||||
|
||||
inline Entity* EntityHandle::operator->() const
|
||||
{
|
||||
return m_entity;
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::operator=(Entity* entity)
|
||||
{
|
||||
Reset(entity);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::operator=(const EntityHandle& handle)
|
||||
{
|
||||
Reset(handle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::operator=(EntityHandle&& handle)
|
||||
{
|
||||
Reset(handle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void EntityHandle::OnEntityDestroyed()
|
||||
{
|
||||
// Un raccourci, un appel à Reset nous enlèverait de la liste des handles que nous ne pouvons pas modifier
|
||||
// maintenant car elle est actuellement parcourue
|
||||
m_entity = nullptr;
|
||||
}
|
||||
|
||||
inline void EntityHandle::OnEntityMoved(Entity* newEntity)
|
||||
{
|
||||
// L'entité a été déplacée (peut arriver lors d'un changement de taille du conteneur du monde)
|
||||
// nous mettons à jour notre pointeur
|
||||
m_entity = newEntity;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const EntityHandle& handle)
|
||||
{
|
||||
out << "EntityHandle(";
|
||||
if (handle.IsValid())
|
||||
out << "Entity(" << handle->GetId() << ')';
|
||||
else
|
||||
out << "Null entity";
|
||||
|
||||
out << ')';
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
inline bool operator==(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return lhs.m_entity == rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator==(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return &lhs == rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator==(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return lhs.m_entity == &rhs;
|
||||
}
|
||||
|
||||
inline bool operator!=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return lhs.m_entity < rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator<(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return &lhs < rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator<(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return lhs.m_entity < &rhs;
|
||||
}
|
||||
|
||||
inline bool operator<=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator>(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Ndk::EntityHandle>
|
||||
{
|
||||
size_t operator()(const Ndk::EntityHandle& handle) const
|
||||
{
|
||||
// Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée
|
||||
// pour cette raison, nous devons hasher l'ID de l'entité (qui reste constante)
|
||||
Ndk::EntityId id = (handle.IsValid()) ? handle->GetId() : std::numeric_limits<Ndk::EntityId>::max();
|
||||
|
||||
return hash<Ndk::EntityId>()(id);
|
||||
}
|
||||
};
|
||||
|
||||
inline void swap(Ndk::EntityHandle& lhs, Ndk::EntityHandle& rhs)
|
||||
{
|
||||
lhs.Swap(rhs);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace Ndk
|
||||
|
||||
std::swap(*it, m_entities.back());
|
||||
m_entities.pop_back(); // On le sort du vector
|
||||
m_entityBits.UnboundedSet(entity->GetId(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
34
SDK/include/NDK/EntityOwner.hpp
Normal file
34
SDK/include/NDK/EntityOwner.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_ENTITYOWNER_HPP
|
||||
#define NDK_ENTITYOWNER_HPP
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class EntityOwner : public EntityHandle
|
||||
{
|
||||
public:
|
||||
EntityOwner() = default;
|
||||
explicit EntityOwner(Entity* entity);
|
||||
EntityOwner(const EntityOwner& handle) = delete;
|
||||
EntityOwner(EntityOwner&& handle);
|
||||
~EntityOwner();
|
||||
|
||||
void Reset(Entity* entity = nullptr);
|
||||
void Reset(EntityOwner&& handle);
|
||||
|
||||
EntityOwner& operator=(Entity* entity);
|
||||
EntityOwner& operator=(const EntityOwner& handle) = delete;
|
||||
EntityOwner& operator=(EntityOwner&& handle);
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/EntityOwner.inl>
|
||||
|
||||
#endif // NDK_ENTITYOwner_HPP
|
||||
62
SDK/include/NDK/EntityOwner.inl
Normal file
62
SDK/include/NDK/EntityOwner.inl
Normal file
@@ -0,0 +1,62 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline EntityOwner::EntityOwner(Entity* entity) :
|
||||
EntityOwner()
|
||||
{
|
||||
Reset(entity);
|
||||
}
|
||||
|
||||
inline EntityOwner::EntityOwner(EntityOwner&& handle) :
|
||||
EntityHandle(std::move(handle))
|
||||
{
|
||||
}
|
||||
|
||||
inline EntityOwner::~EntityOwner()
|
||||
{
|
||||
Reset(nullptr);
|
||||
}
|
||||
|
||||
inline void EntityOwner::Reset(Entity* entity)
|
||||
{
|
||||
if (m_object)
|
||||
m_object->Kill();
|
||||
|
||||
EntityHandle::Reset(entity);
|
||||
}
|
||||
|
||||
inline void EntityOwner::Reset(EntityOwner&& handle)
|
||||
{
|
||||
Reset(handle.GetObject());
|
||||
handle.m_object = nullptr;
|
||||
}
|
||||
|
||||
inline EntityOwner& EntityOwner::operator=(Entity* entity)
|
||||
{
|
||||
Reset(entity);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline EntityOwner& EntityOwner::operator=(EntityOwner&& handle)
|
||||
{
|
||||
Reset(std::move(handle));
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Ndk::EntityOwner> : public hash<Ndk::EntityHandle>
|
||||
{
|
||||
};
|
||||
}
|
||||
40
SDK/include/NDK/LuaAPI.hpp
Normal file
40
SDK/include/NDK/LuaAPI.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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_LUAINTERFACE_HPP
|
||||
#define NDK_LUAINTERFACE_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class LuaInstance;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class LuaBinding;
|
||||
|
||||
class NDK_API LuaAPI
|
||||
{
|
||||
public:
|
||||
LuaAPI() = delete;
|
||||
~LuaAPI() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static LuaBinding* s_binding;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/LuaAPI.inl>
|
||||
|
||||
#endif // NDK_LUAINTERFACE_HPP
|
||||
385
SDK/include/NDK/LuaAPI.inl
Normal file
385
SDK/include/NDK/LuaAPI.inl
Normal file
@@ -0,0 +1,385 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <NDK/Application.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio/Music.hpp>
|
||||
#include <Nazara/Audio/SoundBuffer.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <NDK/Console.hpp>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Color* color, TypeTag<Color>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
color->r = instance.CheckField<UInt8>("r", index);
|
||||
color->g = instance.CheckField<UInt8>("g", index);
|
||||
color->b = instance.CheckField<UInt8>("b", index);
|
||||
color->a = instance.CheckField<UInt8>("a", 255, index);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesd* angles, TypeTag<EulerAnglesd>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Table:
|
||||
angles->Set(instance.CheckField<double>("pitch", index), instance.CheckField<double>("yaw", index), instance.CheckField<double>("roll", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
{
|
||||
if (instance.IsOfType(index, "EulerAngles"))
|
||||
angles->Set(*(*static_cast<EulerAnglesd**>(instance.ToUserdata(index))));
|
||||
else
|
||||
angles->Set(*(*static_cast<Quaterniond**>(instance.CheckUserdata(index, "Quaternion"))));
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesf* angles, TypeTag<EulerAnglesf>)
|
||||
{
|
||||
EulerAnglesd anglesDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &anglesDouble, TypeTag<EulerAnglesd>());
|
||||
|
||||
angles->Set(anglesDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2d* vec, TypeTag<Vector2d>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
if (index < 0 && index > -2)
|
||||
instance.Error("Vector2 expected, two numbers are required to convert it");
|
||||
|
||||
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1));
|
||||
return 2;
|
||||
|
||||
case Nz::LuaType_Table:
|
||||
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
vec->Set(*(*static_cast<Vector2d**>(instance.CheckUserdata(index, "Vector2"))));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2f* vec, TypeTag<Vector2f>)
|
||||
{
|
||||
Vector2d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2ui* vec, TypeTag<Vector2ui>)
|
||||
{
|
||||
Vector2d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3d* vec, TypeTag<Vector3d>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
if (index < 0 && index > -3)
|
||||
instance.Error("Vector3 expected, three numbers are required to convert it");
|
||||
|
||||
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1), instance.CheckNumber(index + 2, 0.0));
|
||||
return 3;
|
||||
|
||||
case Nz::LuaType_Table:
|
||||
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", 0.0, index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
vec->Set(*(*static_cast<Vector3d**>(instance.CheckUserdata(index, "Vector3"))));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3f* vec, TypeTag<Vector3f>)
|
||||
{
|
||||
Vector3d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3ui* vec, TypeTag<Vector3ui>)
|
||||
{
|
||||
Vector3d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
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")));
|
||||
else
|
||||
*renderable = *(*static_cast<InstancedRenderableRef**>(instance.CheckUserdata(index, "Model")));
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MaterialParams* params, TypeTag<MaterialParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->loadAlphaMap = instance.CheckField<bool>("LoadAlphaMap", params->loadAlphaMap);
|
||||
params->loadDiffuseMap = instance.CheckField<bool>("LoadDiffuseMap", params->loadDiffuseMap);
|
||||
params->loadEmissiveMap = instance.CheckField<bool>("LoadEmissiveMap", params->loadEmissiveMap);
|
||||
params->loadHeightMap = instance.CheckField<bool>("LoadHeightMap", params->loadHeightMap);
|
||||
params->loadNormalMap = instance.CheckField<bool>("LoadNormalMap", params->loadNormalMap);
|
||||
params->loadSpecularMap = instance.CheckField<bool>("LoadSpecularMap", params->loadSpecularMap);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MeshParams* params, TypeTag<MeshParams>)
|
||||
{
|
||||
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->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
|
||||
params->scale = instance.CheckField<Vector3f>("Scale", params->scale);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, ModelParameters* params, TypeTag<ModelParameters>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->loadMaterials = instance.CheckField<bool>("LoadMaterials", params->loadMaterials);
|
||||
|
||||
LuaImplQueryArg(instance, -1, ¶ms->material, TypeTag<MaterialParams>());
|
||||
LuaImplQueryArg(instance, -1, ¶ms->mesh, TypeTag<MeshParams>());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MusicParams* params, TypeTag<MusicParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->forceMono = instance.CheckField<bool>("ForceMono", params->forceMono);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SoundBufferParams* params, TypeTag<SoundBufferParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->forceMono = instance.CheckField<bool>("ForceMono", params->forceMono);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesd val, TypeTag<EulerAnglesd>)
|
||||
{
|
||||
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesf val, TypeTag<EulerAnglesf>)
|
||||
{
|
||||
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Quaterniond val, TypeTag<Quaterniond>)
|
||||
{
|
||||
instance.PushInstance<Quaterniond>("Quaternion", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Quaternionf val, TypeTag<Quaternionf>)
|
||||
{
|
||||
instance.PushInstance<Quaterniond>("Quaternion", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress val, TypeTag<IpAddress>)
|
||||
{
|
||||
instance.PushInstance<IpAddress>("IpAddress", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2d val, TypeTag<Vector2d>)
|
||||
{
|
||||
instance.PushInstance<Vector2d>("Vector2", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2f val, TypeTag<Vector2f>)
|
||||
{
|
||||
instance.PushInstance<Vector2d>("Vector2", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2ui val, TypeTag<Vector2ui>)
|
||||
{
|
||||
instance.PushInstance<Vector2d>("Vector2", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3d val, TypeTag<Vector3d>)
|
||||
{
|
||||
instance.PushInstance<Vector3d>("Vector3", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3f val, TypeTag<Vector3f>)
|
||||
{
|
||||
instance.PushInstance<Vector3d>("Vector3", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3ui val, TypeTag<Vector3ui>)
|
||||
{
|
||||
instance.PushInstance<Vector3d>("Vector3", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Entity* ptr, TypeTag<Ndk::Entity*>)
|
||||
{
|
||||
instance.PushInstance<Ndk::EntityHandle>("Entity", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Application* ptr, TypeTag<Ndk::Application*>)
|
||||
{
|
||||
instance.PushInstance<Ndk::Application*>("Application", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::EntityHandle handle, TypeTag<Ndk::EntityHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::EntityHandle>("Entity", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::NodeComponentHandle handle, TypeTag<Ndk::NodeComponentHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::NodeComponentHandle>("NodeComponent", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::VelocityComponentHandle handle, TypeTag<Ndk::VelocityComponentHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::VelocityComponentHandle>("VelocityComponent", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::World* ptr, TypeTag<Ndk::World*>)
|
||||
{
|
||||
instance.PushInstance<Ndk::WorldHandle>("World", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::WorldHandle handle, TypeTag<Ndk::WorldHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::WorldHandle>("World", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::ConsoleHandle handle, TypeTag<Ndk::ConsoleHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::ConsoleHandle>("Console", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::GraphicsComponentHandle handle, TypeTag<Ndk::GraphicsComponentHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::GraphicsComponentHandle>("GraphicsComponent", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
|
||||
{
|
||||
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
28
SDK/include/NDK/State.hpp
Normal file
28
SDK/include/NDK/State.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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_STATE_HPP
|
||||
#define NDK_STATE_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class StateMachine;
|
||||
|
||||
class State
|
||||
{
|
||||
public:
|
||||
State();
|
||||
~State();
|
||||
|
||||
virtual void Enter(StateMachine& fsm) = 0;
|
||||
virtual void Leave(StateMachine& fsm) = 0;
|
||||
virtual bool Update(StateMachine& fsm, float elapsedTime) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_STATE_HPP
|
||||
39
SDK/include/NDK/StateMachine.hpp
Normal file
39
SDK/include/NDK/StateMachine.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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_STATEMACHINE_HPP
|
||||
#define NDK_STATEMACHINE_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/State.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class StateMachine
|
||||
{
|
||||
public:
|
||||
inline StateMachine(std::shared_ptr<State> originalState);
|
||||
StateMachine(const StateMachine&) = delete;
|
||||
inline StateMachine(StateMachine&& fsm) = default;
|
||||
inline ~StateMachine();
|
||||
|
||||
inline void ChangeState(std::shared_ptr<State> state);
|
||||
|
||||
inline bool Update(float elapsedTime);
|
||||
|
||||
inline StateMachine& operator=(StateMachine&& fsm) = default;
|
||||
StateMachine& operator=(const StateMachine&) = delete;
|
||||
|
||||
private:
|
||||
std::shared_ptr<State> m_currentState;
|
||||
std::shared_ptr<State> m_nextState;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/StateMachine.inl>
|
||||
|
||||
#endif // NDK_STATEMACHINE_HPP
|
||||
40
SDK/include/NDK/StateMachine.inl
Normal file
40
SDK/include/NDK/StateMachine.inl
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/StateMachine.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline StateMachine::StateMachine(std::shared_ptr<State> originalState) :
|
||||
m_currentState(std::move(originalState))
|
||||
{
|
||||
NazaraAssert(m_currentState, "StateMachine must have a state to begin with");
|
||||
m_currentState->Enter(*this);
|
||||
}
|
||||
|
||||
inline StateMachine::~StateMachine()
|
||||
{
|
||||
m_currentState->Leave(*this);
|
||||
}
|
||||
|
||||
|
||||
inline void StateMachine::ChangeState(std::shared_ptr<State> state)
|
||||
{
|
||||
m_nextState = std::move(state);
|
||||
}
|
||||
|
||||
inline bool StateMachine::Update(float elapsedTime)
|
||||
{
|
||||
if (m_nextState)
|
||||
{
|
||||
m_currentState->Leave(*this);
|
||||
m_currentState = std::move(m_nextState);
|
||||
m_currentState->Enter(*this);
|
||||
}
|
||||
|
||||
return m_currentState->Update(*this, elapsedTime);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Ndk/Algorithm.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Ndk
|
||||
|
||||
16
SDK/include/NDK/Systems.hpp
Normal file
16
SDK/include/NDK/Systems.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// This file was automatically generated on 03 Mar 2016 at 14:09:12
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SYSTEMS_GLOBAL_HPP
|
||||
#define NDK_SYSTEMS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
#endif // NDK_SYSTEMS_GLOBAL_HPP
|
||||
@@ -27,11 +27,15 @@ namespace Ndk
|
||||
inline RenderSystem(const RenderSystem& renderSystem);
|
||||
~RenderSystem() = default;
|
||||
|
||||
template<typename T> void ChangeRenderTechnique();
|
||||
inline void ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique);
|
||||
|
||||
inline const Nz::BackgroundRef& GetDefaultBackground() const;
|
||||
inline const Nz::Matrix4f& GetCoordinateSystemMatrix() const;
|
||||
inline Nz::Vector3f GetGlobalForward() const;
|
||||
inline Nz::Vector3f GetGlobalRight() const;
|
||||
inline Nz::Vector3f GetGlobalUp() const;
|
||||
inline Nz::AbstractRenderTechnique& GetRenderTechnique() const;
|
||||
|
||||
inline void SetDefaultBackground(Nz::BackgroundRef background);
|
||||
inline void SetGlobalForward(const Nz::Vector3f& direction);
|
||||
@@ -49,6 +53,7 @@ namespace Ndk
|
||||
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
|
||||
void UpdatePointSpotShadowMaps();
|
||||
|
||||
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
|
||||
EntityList m_cameras;
|
||||
EntityList m_drawables;
|
||||
EntityList m_directionalLights;
|
||||
@@ -56,7 +61,6 @@ namespace Ndk
|
||||
EntityList m_pointSpotLights;
|
||||
Nz::BackgroundRef m_background;
|
||||
Nz::DepthRenderTechnique m_shadowTechnique;
|
||||
Nz::ForwardRenderTechnique m_renderTechnique;
|
||||
Nz::Matrix4f m_coordinateSystemMatrix;
|
||||
Nz::RenderTexture m_shadowRT;
|
||||
bool m_coordinateSystemInvalidated;
|
||||
|
||||
@@ -9,6 +9,17 @@ namespace Ndk
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void RenderSystem::ChangeRenderTechnique()
|
||||
{
|
||||
ChangeRenderTechnique(std::make_unique<T>());
|
||||
}
|
||||
|
||||
inline void RenderSystem::ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique)
|
||||
{
|
||||
m_renderTechnique = std::move(renderTechnique);
|
||||
}
|
||||
|
||||
inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const
|
||||
{
|
||||
return m_background;
|
||||
@@ -34,6 +45,11 @@ namespace Ndk
|
||||
return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32);
|
||||
}
|
||||
|
||||
inline Nz::AbstractRenderTechnique& RenderSystem::GetRenderTechnique() const
|
||||
{
|
||||
return *m_renderTechnique.get();
|
||||
}
|
||||
|
||||
inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background)
|
||||
{
|
||||
m_background = std::move(background);
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#define NDK_WORLD_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/System.hpp>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
@@ -18,7 +18,11 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API World
|
||||
class World;
|
||||
|
||||
using WorldHandle = Nz::ObjectHandle<World>;
|
||||
|
||||
class NDK_API World : public Nz::HandledObject<World>
|
||||
{
|
||||
friend Entity;
|
||||
|
||||
@@ -27,8 +31,8 @@ namespace Ndk
|
||||
|
||||
inline World(bool addDefaultSystems = true);
|
||||
World(const World&) = delete;
|
||||
World(World&&) = delete; ///TODO
|
||||
~World();
|
||||
inline World(World&& world) noexcept;
|
||||
~World() noexcept;
|
||||
|
||||
void AddDefaultSystems();
|
||||
|
||||
@@ -38,7 +42,7 @@ namespace Ndk
|
||||
const EntityHandle& CreateEntity();
|
||||
inline EntityList CreateEntities(unsigned int count);
|
||||
|
||||
void Clear();
|
||||
void Clear() noexcept;
|
||||
|
||||
const EntityHandle& GetEntity(EntityId id);
|
||||
inline const EntityList& GetEntities();
|
||||
@@ -62,7 +66,7 @@ namespace Ndk
|
||||
inline void Update(float elapsedTime);
|
||||
|
||||
World& operator=(const World&) = delete;
|
||||
World& operator=(World&&) = delete; ///TODO
|
||||
inline World& operator=(World&& world) noexcept;
|
||||
|
||||
private:
|
||||
inline void Invalidate();
|
||||
|
||||
@@ -13,6 +13,12 @@ namespace Ndk
|
||||
AddDefaultSystems();
|
||||
}
|
||||
|
||||
inline World::World(World&& world) noexcept :
|
||||
HandledObject(std::move(world))
|
||||
{
|
||||
operator=(std::move(world));
|
||||
}
|
||||
|
||||
inline BaseSystem& World::AddSystem(std::unique_ptr<BaseSystem>&& system)
|
||||
{
|
||||
NazaraAssert(system, "System must be valid");
|
||||
@@ -25,7 +31,7 @@ namespace Ndk
|
||||
|
||||
// Affectation et retour du système
|
||||
m_systems[index] = std::move(system);
|
||||
m_systems[index]->SetWorld(*this);
|
||||
m_systems[index]->SetWorld(this);
|
||||
|
||||
Invalidate(); // On force une mise à jour de toutes les entités
|
||||
|
||||
@@ -152,4 +158,22 @@ namespace Ndk
|
||||
{
|
||||
m_dirtyEntities.UnboundedSet(id, true);
|
||||
}
|
||||
|
||||
inline World& World::operator=(World&& world) noexcept
|
||||
{
|
||||
m_aliveEntities = std::move(world.m_aliveEntities);
|
||||
m_dirtyEntities = std::move(world.m_dirtyEntities);
|
||||
m_freeIdList = std::move(world.m_freeIdList);
|
||||
m_killedEntities = std::move(world.m_killedEntities);
|
||||
|
||||
m_entities = std::move(world.m_entities);
|
||||
for (EntityBlock& block : m_entities)
|
||||
block.entity.SetWorld(this);
|
||||
|
||||
m_systems = std::move(world.m_systems);
|
||||
for (const auto& systemPtr : m_systems)
|
||||
systemPtr->SetWorld(this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,3 +3,47 @@
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Application.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool Application::Run()
|
||||
{
|
||||
#ifndef NDK_SERVER
|
||||
bool hasAtLeastOneActiveWindow = false;
|
||||
|
||||
auto it = m_windows.begin();
|
||||
while (it != m_windows.end())
|
||||
{
|
||||
Nz::Window& window = **it;
|
||||
|
||||
if (!window.IsOpen(true))
|
||||
{
|
||||
it = m_windows.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
hasAtLeastOneActiveWindow = true;
|
||||
|
||||
++it;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
if (m_exitOnClosedWindows && !hasAtLeastOneActiveWindow)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if (m_shouldQuit)
|
||||
return false;
|
||||
|
||||
m_updateTime = m_updateClock.GetSeconds();
|
||||
m_updateClock.Restart();
|
||||
|
||||
for (World& world : m_worlds)
|
||||
world.Update(m_updateTime);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Application* Application::s_application = nullptr;
|
||||
}
|
||||
@@ -119,9 +119,14 @@ namespace Ndk
|
||||
switch (m_projectionType)
|
||||
{
|
||||
case Nz::ProjectionType_Orthogonal:
|
||||
EnsureViewportUpdate();
|
||||
if (m_size.x <= 0.f || m_size.y <= 0.f)
|
||||
{
|
||||
EnsureViewportUpdate();
|
||||
|
||||
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
|
||||
m_projectionMatrix.MakeOrtho(0.f, static_cast<float>(m_viewport.width), 0.f, static_cast<float>(m_viewport.height), m_zNear, m_zFar);
|
||||
}
|
||||
else
|
||||
m_projectionMatrix.MakeOrtho(0.f, m_size.x, 0.f, m_size.y, m_zNear, m_zFar);
|
||||
break;
|
||||
|
||||
case Nz::ProjectionType_Perspective:
|
||||
|
||||
@@ -63,6 +63,18 @@ namespace Ndk
|
||||
InvalidateTransformMatrix();
|
||||
}
|
||||
|
||||
void GraphicsComponent::UpdateBoundingVolume() const
|
||||
{
|
||||
EnsureTransformMatrixUpdate();
|
||||
|
||||
m_boundingVolume.MakeNull();
|
||||
for (const Renderable& r : m_renderables)
|
||||
m_boundingVolume.ExtendTo(r.renderable->GetBoundingVolume());
|
||||
|
||||
m_boundingVolume.Update(m_transformMatrix);
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
|
||||
void GraphicsComponent::UpdateTransformMatrix() const
|
||||
{
|
||||
NazaraAssert(m_entity && m_entity->HasComponent<NodeComponent>(), "GraphicsComponent requires NodeComponent");
|
||||
|
||||
272
SDK/src/NDK/Console.cpp
Normal file
272
SDK/src/NDK/Console.cpp
Normal file
@@ -0,0 +1,272 @@
|
||||
// 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
|
||||
|
||||
#include <NDK/Console.hpp>
|
||||
#include <Nazara/Core/Unicode.hpp>
|
||||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
///TODO: For now is unable to display different color in the history, it needs a RichTextDrawer to do so
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const char s_inputPrefix[] = "> ";
|
||||
constexpr std::size_t s_inputPrefixSize = Nz::CountOf(s_inputPrefix) - 1;
|
||||
}
|
||||
|
||||
Console::Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance) :
|
||||
m_historyPosition(0),
|
||||
m_defaultFont(Nz::Font::GetDefault()),
|
||||
m_instance(instance),
|
||||
m_size(size),
|
||||
m_opened(false),
|
||||
m_characterSize(24)
|
||||
{
|
||||
Nz::MaterialRef backgroundMaterial = Nz::Material::New();
|
||||
backgroundMaterial->Enable(Nz::RendererParameter_Blend, true);
|
||||
backgroundMaterial->Enable(Nz::RendererParameter_DepthBuffer, false);
|
||||
backgroundMaterial->SetDstBlend(Nz::BlendFunc_InvSrcAlpha);
|
||||
backgroundMaterial->SetSrcBlend(Nz::BlendFunc_SrcAlpha);
|
||||
|
||||
// History bakckground
|
||||
m_historyBackgroundSprite = Nz::Sprite::New();
|
||||
m_historyBackgroundSprite->SetColor(Nz::Color(80, 80, 160, 128));
|
||||
m_historyBackgroundSprite->SetMaterial(backgroundMaterial);
|
||||
|
||||
m_historyBackground = world.CreateEntity();
|
||||
m_historyBackground->Enable(m_opened);
|
||||
m_historyBackground->AddComponent<Ndk::GraphicsComponent>().Attach(m_historyBackgroundSprite, -1);
|
||||
m_historyBackground->AddComponent<Ndk::NodeComponent>().SetParent(this);
|
||||
|
||||
// History
|
||||
m_historyDrawer.SetCharacterSize(m_characterSize);
|
||||
m_historyDrawer.SetColor(Nz::Color(200, 200, 200));
|
||||
m_historyDrawer.SetFont(m_defaultFont);
|
||||
|
||||
m_historyTextSprite = Nz::TextSprite::New();
|
||||
|
||||
m_history = world.CreateEntity();
|
||||
m_history->Enable(m_opened);
|
||||
m_history->AddComponent<Ndk::GraphicsComponent>().Attach(m_historyTextSprite);
|
||||
|
||||
Ndk::NodeComponent& historyNode = m_history->AddComponent<Ndk::NodeComponent>();
|
||||
historyNode.SetParent(this);
|
||||
|
||||
// Input background
|
||||
m_inputBackgroundSprite = Nz::Sprite::New();
|
||||
m_inputBackgroundSprite->SetColor(Nz::Color(255, 255, 255, 200));
|
||||
m_inputBackgroundSprite->SetMaterial(backgroundMaterial);
|
||||
|
||||
m_inputBackground = world.CreateEntity();
|
||||
m_inputBackground->Enable(m_opened);
|
||||
m_inputBackground->AddComponent<Ndk::GraphicsComponent>().Attach(m_inputBackgroundSprite, -1);
|
||||
m_inputBackground->AddComponent<Ndk::NodeComponent>().SetParent(this);
|
||||
|
||||
// Input
|
||||
m_inputDrawer.SetColor(Nz::Color::Black);
|
||||
m_inputDrawer.SetCharacterSize(m_characterSize);
|
||||
m_inputDrawer.SetFont(m_defaultFont);
|
||||
m_inputDrawer.SetText(s_inputPrefix);
|
||||
|
||||
m_inputTextSprite = Nz::TextSprite::New();
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
|
||||
m_input = world.CreateEntity();
|
||||
m_input->Enable(m_opened);
|
||||
m_input->AddComponent<Ndk::GraphicsComponent>().Attach(m_inputTextSprite);
|
||||
|
||||
Ndk::NodeComponent& inputNode = m_input->AddComponent<Ndk::NodeComponent>();
|
||||
inputNode.SetParent(this);
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::AddLine(const Nz::String& text, const Nz::Color& color)
|
||||
{
|
||||
AddLineInternal(text, color);
|
||||
RefreshHistory();
|
||||
}
|
||||
|
||||
void Console::Clear()
|
||||
{
|
||||
m_historyLines.clear();
|
||||
RefreshHistory();
|
||||
}
|
||||
|
||||
void Console::SendCharacter(char32_t character)
|
||||
{
|
||||
switch (character)
|
||||
{
|
||||
case '\b':
|
||||
{
|
||||
Nz::String input = m_inputDrawer.GetText();
|
||||
if (input.GetLength() <= s_inputPrefixSize) // Prevent removal of the input prefix
|
||||
return; // Ignore if no user character is there
|
||||
|
||||
input.Resize(-1, Nz::String::HandleUtf8);
|
||||
m_inputDrawer.SetText(input);
|
||||
break;
|
||||
}
|
||||
|
||||
case '\r':
|
||||
case '\n':
|
||||
ExecuteInput();
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
if (Nz::Unicode::GetCategory(character) == Nz::Unicode::Category_Other_Control)
|
||||
return;
|
||||
|
||||
m_inputDrawer.AppendText(Nz::String::Unicode(character));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
}
|
||||
|
||||
void Console::SendEvent(Nz::WindowEvent event)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case Nz::WindowEventType_TextEntered:
|
||||
SendCharacter(event.text.character);
|
||||
break;
|
||||
|
||||
case Nz::WindowEventType_KeyPressed:
|
||||
{
|
||||
switch (event.key.code)
|
||||
{
|
||||
case Nz::Keyboard::Down:
|
||||
case Nz::Keyboard::Up:
|
||||
if (event.key.code == Nz::Keyboard::Up)
|
||||
m_historyPosition = std::min<std::size_t>(m_commandHistory.size(), m_historyPosition + 1);
|
||||
else
|
||||
{
|
||||
if (m_historyPosition > 1)
|
||||
m_historyPosition--;
|
||||
else if (m_historyPosition == 0)
|
||||
m_historyPosition = 1;
|
||||
}
|
||||
|
||||
Nz::String text = m_commandHistory[m_commandHistory.size() - m_historyPosition];
|
||||
m_inputDrawer.SetText(s_inputPrefix + text);
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Console::SetCharacterSize(unsigned int size)
|
||||
{
|
||||
m_characterSize = size;
|
||||
|
||||
m_historyDrawer.SetCharacterSize(m_characterSize);
|
||||
m_historyTextSprite->Update(m_historyDrawer);
|
||||
m_inputDrawer.SetCharacterSize(m_characterSize);
|
||||
m_inputTextSprite->Update(m_inputDrawer);
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::SetSize(const Nz::Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
m_historyBackgroundSprite->SetSize(m_size);
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::SetTextFont(Nz::FontRef font)
|
||||
{
|
||||
Layout();
|
||||
}
|
||||
|
||||
void Console::Show(bool show)
|
||||
{
|
||||
if (m_opened != show)
|
||||
{
|
||||
m_historyBackground->Enable(show);
|
||||
m_history->Enable(show);
|
||||
m_input->Enable(show);
|
||||
m_inputBackground->Enable(show);
|
||||
|
||||
m_opened = show;
|
||||
}
|
||||
}
|
||||
|
||||
void Console::AddLineInternal(const Nz::String& text, const Nz::Color& color)
|
||||
{
|
||||
m_historyLines.emplace_back(Line{color, text});
|
||||
}
|
||||
|
||||
void Console::ExecuteInput()
|
||||
{
|
||||
Nz::String input = m_inputDrawer.GetText();
|
||||
Nz::String inputCmd = input.SubString(s_inputPrefixSize);;
|
||||
m_inputDrawer.SetText(s_inputPrefix);
|
||||
|
||||
if (m_commandHistory.empty() || m_commandHistory.back() != inputCmd)
|
||||
m_commandHistory.push_back(inputCmd);
|
||||
|
||||
m_historyPosition = 0;
|
||||
|
||||
AddLineInternal(input); //< With the input prefix
|
||||
|
||||
if (!m_instance.Execute(inputCmd))
|
||||
AddLineInternal(m_instance.GetLastError(), Nz::Color::Red);
|
||||
|
||||
RefreshHistory();
|
||||
}
|
||||
|
||||
void Console::Layout()
|
||||
{
|
||||
unsigned int lineHeight = m_defaultFont->GetSizeInfo(m_characterSize).lineHeight;
|
||||
|
||||
Ndk::NodeComponent& inputNode = m_input->GetComponent<Ndk::NodeComponent>();
|
||||
inputNode.SetPosition(0.f, m_size.y - lineHeight - 5.f);
|
||||
|
||||
float historyHeight = m_size.y - lineHeight - 5.f - 2.f;
|
||||
m_historyBackgroundSprite->SetSize(m_size.x, historyHeight);
|
||||
|
||||
m_maxHistoryLines = static_cast<unsigned int>(std::ceil(historyHeight / lineHeight));
|
||||
|
||||
Ndk::NodeComponent& historyNode = m_history->GetComponent<Ndk::NodeComponent>();
|
||||
historyNode.SetPosition(0.f, historyHeight - m_maxHistoryLines * lineHeight);
|
||||
|
||||
Ndk::NodeComponent& inputBackgroundNode = m_inputBackground->GetComponent<Ndk::NodeComponent>();
|
||||
inputBackgroundNode.SetPosition(0.f, historyHeight + 2.f);
|
||||
|
||||
m_inputBackgroundSprite->SetSize(m_size.x, m_size.y - historyHeight);
|
||||
}
|
||||
|
||||
void Console::RefreshHistory()
|
||||
{
|
||||
m_historyDrawer.Clear();
|
||||
auto it = m_historyLines.end();
|
||||
if (m_historyLines.size() > m_maxHistoryLines)
|
||||
it -= m_maxHistoryLines;
|
||||
else
|
||||
it = m_historyLines.begin();
|
||||
|
||||
for (unsigned int i = 0; i < m_maxHistoryLines; ++i)
|
||||
{
|
||||
if (m_maxHistoryLines - i <= m_historyLines.size() && it != m_historyLines.end())
|
||||
{
|
||||
m_historyDrawer.AppendText(it->text);
|
||||
++it;
|
||||
}
|
||||
|
||||
m_historyDrawer.AppendText(Nz::String('\n'));
|
||||
}
|
||||
|
||||
m_historyTextSprite->Update(m_historyDrawer);
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,25 @@
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
Entity::Entity(Entity&& entity) :
|
||||
HandledObject(std::move(entity)),
|
||||
m_components(std::move(entity.m_components)),
|
||||
m_handles(std::move(entity.m_handles)),
|
||||
m_componentBits(std::move(entity.m_componentBits)),
|
||||
m_systemBits(std::move(entity.m_systemBits)),
|
||||
m_id(entity.m_id),
|
||||
m_world(entity.m_world),
|
||||
m_enabled(entity.m_enabled),
|
||||
m_valid(entity.m_valid)
|
||||
{
|
||||
for (EntityHandle* handle : m_handles)
|
||||
handle->OnEntityMoved(this);
|
||||
}
|
||||
|
||||
Entity::Entity(World& world, EntityId id) :
|
||||
Entity::Entity(World* world, EntityId id) :
|
||||
m_id(id),
|
||||
m_world(&world)
|
||||
m_world(world)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -62,11 +60,6 @@ namespace Ndk
|
||||
return component;
|
||||
}
|
||||
|
||||
EntityHandle Entity::CreateHandle()
|
||||
{
|
||||
return EntityHandle(this);
|
||||
}
|
||||
|
||||
void Entity::Kill()
|
||||
{
|
||||
m_world->KillEntity(this);
|
||||
@@ -114,6 +107,7 @@ namespace Ndk
|
||||
|
||||
void Entity::Create()
|
||||
{
|
||||
m_enabled = true;
|
||||
m_valid = true;
|
||||
}
|
||||
|
||||
@@ -130,11 +124,7 @@ namespace Ndk
|
||||
}
|
||||
m_systemBits.Clear();
|
||||
|
||||
// On informe chaque handle de notre destruction pour éviter qu'il ne continue de pointer sur nous
|
||||
for (EntityHandle* handle : m_handles)
|
||||
handle->OnEntityDestroyed();
|
||||
|
||||
m_handles.clear();
|
||||
UnregisterAllHandles();
|
||||
|
||||
m_valid = false;
|
||||
}
|
||||
|
||||
@@ -1,10 +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
|
||||
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
const EntityHandle EntityHandle::InvalidHandle;
|
||||
}
|
||||
31
SDK/src/NDK/LuaAPI.cpp
Normal file
31
SDK/src/NDK/LuaAPI.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool LuaAPI::Initialize()
|
||||
{
|
||||
s_binding = new LuaBinding;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LuaAPI::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
if (!s_binding && !Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize binding");
|
||||
return;
|
||||
}
|
||||
|
||||
s_binding->RegisterClasses(instance);
|
||||
}
|
||||
|
||||
void LuaAPI::Uninitialize()
|
||||
{
|
||||
delete s_binding;
|
||||
}
|
||||
|
||||
LuaBinding* LuaAPI::s_binding = nullptr;
|
||||
}
|
||||
80
SDK/src/NDK/LuaBinding.cpp
Normal file
80
SDK/src/NDK/LuaBinding.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
LuaBinding::LuaBinding() :
|
||||
// Core
|
||||
clockClass("Clock"),
|
||||
directoryClass("Directory"),
|
||||
fileClass("File"),
|
||||
streamClass("Stream"),
|
||||
|
||||
// Math
|
||||
eulerAnglesClass("EulerAngles"),
|
||||
quaternionClass("Quaternion"),
|
||||
vector2dClass("Vector2"),
|
||||
vector3dClass("Vector3"),
|
||||
|
||||
// Network
|
||||
abstractSocketClass("AbstractSocket"),
|
||||
ipAddressClass("IpAddress"),
|
||||
|
||||
// Utility
|
||||
abstractImage("AbstractImage"),
|
||||
nodeClass("Node"),
|
||||
|
||||
// SDK
|
||||
application("Application"),
|
||||
nodeComponent("NodeComponent"),
|
||||
entityClass("Entity"),
|
||||
velocityComponent("VelocityComponent"),
|
||||
worldClass("World")
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
,
|
||||
|
||||
// Audio
|
||||
musicClass("Music"),
|
||||
soundBuffer("SoundBuffer"),
|
||||
soundEmitter("SoundEmitter"),
|
||||
soundClass("Sound"),
|
||||
|
||||
// Graphics
|
||||
instancedRenderable("InstancedRenderable"),
|
||||
modelClass("Model"),
|
||||
|
||||
// SDK
|
||||
consoleClass("Console"),
|
||||
graphicsComponent("GraphicsComponent")
|
||||
#endif
|
||||
{
|
||||
BindCore();
|
||||
BindMath();
|
||||
BindNetwork();
|
||||
BindSDK();
|
||||
BindUtility();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
BindAudio();
|
||||
BindGraphics();
|
||||
BindRenderer();
|
||||
#endif
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterClasses(Nz::LuaInstance& instance)
|
||||
{
|
||||
RegisterCore(instance);
|
||||
RegisterMath(instance);
|
||||
RegisterNetwork(instance);
|
||||
RegisterSDK(instance);
|
||||
RegisterUtility(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
RegisterAudio(instance);
|
||||
RegisterGraphics(instance);
|
||||
RegisterRenderer(instance);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
120
SDK/src/NDK/LuaBinding.hpp
Normal file
120
SDK/src/NDK/LuaBinding.hpp
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_LUABINDING_HPP
|
||||
#define NDK_LUABINDING_HPP
|
||||
|
||||
#include <Nazara/Core.hpp>
|
||||
#include <Nazara/Lua.hpp>
|
||||
#include <Nazara/Math.hpp>
|
||||
#include <Nazara/Network.hpp>
|
||||
#include <Nazara/Utility.hpp>
|
||||
#include <NDK/Application.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/Systems.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio.hpp>
|
||||
#include <Nazara/Graphics.hpp>
|
||||
#include <Nazara/Renderer.hpp>
|
||||
#include <NDK/Console.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class LuaBinding
|
||||
{
|
||||
public:
|
||||
LuaBinding();
|
||||
~LuaBinding() = default;
|
||||
|
||||
void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
private:
|
||||
void BindCore();
|
||||
void BindMath();
|
||||
void BindNetwork();
|
||||
void BindSDK();
|
||||
void BindUtility();
|
||||
|
||||
template<typename T> void EnableComponentBinding();
|
||||
|
||||
void RegisterCore(Nz::LuaInstance& instance);
|
||||
void RegisterMath(Nz::LuaInstance& instance);
|
||||
void RegisterNetwork(Nz::LuaInstance& instance);
|
||||
void RegisterSDK(Nz::LuaInstance& instance);
|
||||
void RegisterUtility(Nz::LuaInstance& instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
void BindAudio();
|
||||
void BindGraphics();
|
||||
void BindRenderer();
|
||||
|
||||
void RegisterAudio(Nz::LuaInstance& instance);
|
||||
void RegisterGraphics(Nz::LuaInstance& instance);
|
||||
void RegisterRenderer(Nz::LuaInstance& instance);
|
||||
#endif
|
||||
|
||||
// Core
|
||||
Nz::LuaClass<Nz::Clock> clockClass;
|
||||
Nz::LuaClass<Nz::Directory> directoryClass;
|
||||
Nz::LuaClass<Nz::File> fileClass;
|
||||
Nz::LuaClass<Nz::Stream> streamClass;
|
||||
|
||||
// Math
|
||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAnglesClass;
|
||||
Nz::LuaClass<Nz::Quaterniond> quaternionClass;
|
||||
Nz::LuaClass<Nz::Vector2d> vector2dClass;
|
||||
Nz::LuaClass<Nz::Vector3d> vector3dClass;
|
||||
|
||||
// Network
|
||||
Nz::LuaClass<Nz::AbstractSocket> abstractSocketClass;
|
||||
Nz::LuaClass<Nz::IpAddress> ipAddressClass;
|
||||
|
||||
// Utility
|
||||
Nz::LuaClass<Nz::AbstractImage*> abstractImage;
|
||||
Nz::LuaClass<Nz::Node> nodeClass;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<Application*> application;
|
||||
Nz::LuaClass<EntityHandle> entityClass;
|
||||
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
||||
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
||||
Nz::LuaClass<WorldHandle> worldClass;
|
||||
|
||||
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
||||
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
||||
|
||||
struct ComponentBinding
|
||||
{
|
||||
AddComponentFunc adder;
|
||||
GetComponentFunc getter;
|
||||
bool valid = false;
|
||||
};
|
||||
|
||||
std::vector<ComponentBinding> m_componentBinding;
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Audio
|
||||
Nz::LuaClass<Nz::Music> musicClass;
|
||||
Nz::LuaClass<Nz::Sound> soundClass;
|
||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
||||
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
||||
|
||||
// Graphics
|
||||
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
||||
Nz::LuaClass<Nz::ModelRef> modelClass;
|
||||
|
||||
// SDK
|
||||
Nz::LuaClass<ConsoleHandle> consoleClass;
|
||||
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_LUABINDING_HPP
|
||||
176
SDK/src/NDK/LuaBinding_Audio.cpp
Normal file
176
SDK/src/NDK/LuaBinding_Audio.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindAudio()
|
||||
{
|
||||
/*********************************** Nz::Music **********************************/
|
||||
musicClass.Inherit(soundEmitter);
|
||||
|
||||
musicClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Music*
|
||||
{
|
||||
return new Nz::Music;
|
||||
});
|
||||
|
||||
//musicClass.SetMethod("Create", &Nz::Music::Create);
|
||||
//musicClass.SetMethod("Destroy", &Nz::Music::Destroy);
|
||||
|
||||
musicClass.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);
|
||||
|
||||
musicClass.BindMethod("IsLooping", &Nz::Music::IsLooping);
|
||||
|
||||
musicClass.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams());
|
||||
|
||||
musicClass.BindMethod("Pause", &Nz::Music::Pause);
|
||||
musicClass.BindMethod("Play", &Nz::Music::Play);
|
||||
|
||||
musicClass.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset);
|
||||
|
||||
musicClass.BindMethod("Stop", &Nz::Music::Stop);
|
||||
|
||||
// Manual
|
||||
musicClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music) -> int
|
||||
{
|
||||
Nz::StringStream stream("Music(");
|
||||
stream << music.GetFilePath() << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Sound **********************************/
|
||||
soundClass.Inherit(soundEmitter);
|
||||
|
||||
soundClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Sound*
|
||||
{
|
||||
return new Nz::Sound;
|
||||
});
|
||||
|
||||
soundClass.BindMethod("GetBuffer", &Nz::Sound::GetBuffer);
|
||||
|
||||
soundClass.BindMethod("IsPlayable", &Nz::Sound::IsPlayable);
|
||||
soundClass.BindMethod("IsPlaying", &Nz::Sound::IsPlaying);
|
||||
|
||||
soundClass.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
|
||||
|
||||
soundClass.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);
|
||||
|
||||
// Manual
|
||||
soundClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int
|
||||
{
|
||||
Nz::StringStream stream("Sound(");
|
||||
if (const Nz::SoundBuffer* buffer = sound.GetBuffer())
|
||||
stream << buffer;
|
||||
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::SoundBuffer **********************************/
|
||||
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::SoundBufferRef*
|
||||
{
|
||||
return new Nz::SoundBufferRef(new Nz::SoundBuffer);
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy);
|
||||
|
||||
soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration);
|
||||
soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat);
|
||||
soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount);
|
||||
soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate);
|
||||
|
||||
soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid);
|
||||
|
||||
soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams());
|
||||
|
||||
soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported);
|
||||
|
||||
// Manual
|
||||
soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
|
||||
{
|
||||
int index = 1;
|
||||
Nz::AudioFormat format = lua.Check<Nz::AudioFormat>(&index);
|
||||
unsigned int sampleCount = lua.Check<unsigned int>(&index);
|
||||
unsigned int sampleRate = lua.Check<unsigned int>(&index);
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const char* buffer = lua.CheckString(index, &bufferSize);
|
||||
lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer");
|
||||
|
||||
lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast<const Nz::Int16*>(buffer)));
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int
|
||||
{
|
||||
lua.PushString(reinterpret_cast<const char*>(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16));
|
||||
return 1;
|
||||
});
|
||||
|
||||
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int
|
||||
{
|
||||
Nz::StringStream stream("SoundBuffer(");
|
||||
if (soundBuffer->IsValid())
|
||||
{
|
||||
Nz::String filePath = soundBuffer->GetFilePath();
|
||||
if (!filePath.IsEmpty())
|
||||
stream << "File: " << filePath << ", ";
|
||||
|
||||
stream << "Duration: " << soundBuffer->GetDuration() / 1000.f << "s";
|
||||
}
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::SoundEmitter **********************************/
|
||||
soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping);
|
||||
soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization);
|
||||
|
||||
soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation);
|
||||
soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration);
|
||||
soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance);
|
||||
soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch);
|
||||
soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset);
|
||||
soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition);
|
||||
soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus);
|
||||
soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity);
|
||||
soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume);
|
||||
|
||||
soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping);
|
||||
soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);
|
||||
|
||||
soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause);
|
||||
soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play);
|
||||
|
||||
soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation);
|
||||
soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance);
|
||||
soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch);
|
||||
soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition);
|
||||
soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity);
|
||||
soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume);
|
||||
|
||||
soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterAudio(Nz::LuaInstance& instance)
|
||||
{
|
||||
musicClass.Register(instance);
|
||||
soundClass.Register(instance);
|
||||
soundBuffer.Register(instance);
|
||||
soundEmitter.Register(instance);
|
||||
}
|
||||
}
|
||||
280
SDK/src/NDK/LuaBinding_Core.cpp
Normal file
280
SDK/src/NDK/LuaBinding_Core.cpp
Normal file
@@ -0,0 +1,280 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindCore()
|
||||
{
|
||||
/*********************************** Nz::Clock **********************************/
|
||||
clockClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Clock*
|
||||
{
|
||||
int argIndex = 1;
|
||||
return new Nz::Clock(lua.Check<Nz::Int64>(&argIndex, 0), lua.Check<bool>(&argIndex, false));
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
// Manual
|
||||
clockClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int {
|
||||
Nz::StringStream stream("Clock(Elapsed: ");
|
||||
stream << clock.GetSeconds();
|
||||
stream << "s, Paused: ";
|
||||
stream << clock.IsPaused();
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/********************************* Nz::Directory ********************************/
|
||||
directoryClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Directory*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::Directory;
|
||||
|
||||
case 1:
|
||||
return new Nz::Directory(lua.Check<Nz::String>(&argIndex));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
// Manual
|
||||
directoryClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int {
|
||||
Nz::StringStream stream("Directory(");
|
||||
stream << directory.GetPath();
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** 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);
|
||||
|
||||
streamClass.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t length = lua.Check<std::size_t>(&argIndex);
|
||||
|
||||
std::unique_ptr<char[]> buffer(new char[length]);
|
||||
std::size_t readLength = stream.Read(buffer.get(), length);
|
||||
|
||||
lua.PushString(Nz::String(buffer.get(), readLength));
|
||||
return 1;
|
||||
});
|
||||
|
||||
streamClass.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int {
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const char* buffer = lua.CheckString(argIndex, &bufferSize);
|
||||
|
||||
if (stream.IsTextModeEnabled())
|
||||
lua.Push(stream.Write(Nz::String(buffer, bufferSize)));
|
||||
else
|
||||
lua.Push(stream.Write(buffer, bufferSize));
|
||||
return 1;
|
||||
});
|
||||
|
||||
/*********************************** Nz::File ***********************************/
|
||||
fileClass.Inherit(streamClass);
|
||||
|
||||
fileClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::File*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::File;
|
||||
|
||||
case 1:
|
||||
return new Nz::File(lua.Check<Nz::String>(&argIndex));
|
||||
|
||||
case 2:
|
||||
return new Nz::File(lua.Check<Nz::String>(&argIndex), lua.Check<Nz::UInt32>(&argIndex));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
//fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
||||
fileClass.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);
|
||||
|
||||
// Manual
|
||||
fileClass.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return lua.Push(file.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
|
||||
case 2:
|
||||
return lua.Push(file.Open(lua.Check<Nz::String>(&argIndex), lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Open");
|
||||
return 0;
|
||||
});
|
||||
|
||||
fileClass.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
return lua.Push(file.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||
|
||||
case 2:
|
||||
return lua.Push(file.SetCursorPos(lua.Check<Nz::CursorPosition>(&argIndex), lua.Check<Nz::Int64>(&argIndex)));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetCursorPos");
|
||||
return 0;
|
||||
});
|
||||
|
||||
fileClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int {
|
||||
Nz::StringStream stream("File(");
|
||||
if (file.IsOpen())
|
||||
stream << "Path: " << file.GetPath();
|
||||
|
||||
stream << ')';
|
||||
|
||||
lua.PushString(stream);
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterCore(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
clockClass.Register(instance);
|
||||
directoryClass.Register(instance);
|
||||
fileClass.Register(instance);
|
||||
streamClass.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
||||
// Nz::CursorPosition
|
||||
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.SetField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||
instance.SetField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||
instance.SetField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||
}
|
||||
instance.SetGlobal("CursorPosition");
|
||||
|
||||
// Nz::HashType
|
||||
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 9);
|
||||
{
|
||||
instance.SetField("CRC32", Nz::HashType_CRC32);
|
||||
instance.SetField("Fletcher16", Nz::HashType_Fletcher16);
|
||||
instance.SetField("MD5", Nz::HashType_MD5);
|
||||
instance.SetField("SHA1", Nz::HashType_SHA1);
|
||||
instance.SetField("SHA224", Nz::HashType_SHA224);
|
||||
instance.SetField("SHA256", Nz::HashType_SHA256);
|
||||
instance.SetField("SHA384", Nz::HashType_SHA384);
|
||||
instance.SetField("SHA512", Nz::HashType_SHA512);
|
||||
instance.SetField("Whirlpool", Nz::HashType_Whirlpool);
|
||||
}
|
||||
instance.SetGlobal("HashType");
|
||||
|
||||
// Nz::OpenMode
|
||||
static_assert(Nz::OpenMode_Max + 1 == 2 * (64), "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 8);
|
||||
{
|
||||
instance.SetField("Append", Nz::OpenMode_Append);
|
||||
instance.SetField("NotOpen", Nz::OpenMode_NotOpen);
|
||||
instance.SetField("Lock", Nz::OpenMode_Lock);
|
||||
instance.SetField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||
instance.SetField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||
instance.SetField("Text", Nz::OpenMode_Text);
|
||||
instance.SetField("Truncate", Nz::OpenMode_Truncate);
|
||||
instance.SetField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||
}
|
||||
instance.SetGlobal("OpenMode");
|
||||
}
|
||||
}
|
||||
47
SDK/src/NDK/LuaBinding_Graphics.cpp
Normal file
47
SDK/src/NDK/LuaBinding_Graphics.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindGraphics()
|
||||
{
|
||||
/*********************************** Nz::InstancedRenderable ***********************************/
|
||||
|
||||
/*********************************** Nz::Model ***********************************/
|
||||
modelClass.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*
|
||||
{
|
||||
return new Nz::ModelRef(new Nz::Model);
|
||||
});
|
||||
|
||||
//modelClass.SetMethod("GetMaterial", &Nz::Model::GetMaterial);
|
||||
modelClass.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
|
||||
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
|
||||
modelClass.BindMethod("GetSkin", &Nz::Model::GetSkin);
|
||||
modelClass.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
|
||||
|
||||
modelClass.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
|
||||
modelClass.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
|
||||
|
||||
modelClass.BindMethod("Reset", &Nz::Model::Reset);
|
||||
|
||||
//modelClass.SetMethod("SetMaterial", &Nz::Model::SetMaterial);
|
||||
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
|
||||
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
||||
modelClass.BindMethod("SetSkin", &Nz::Model::SetSkin);
|
||||
modelClass.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance)
|
||||
{
|
||||
instancedRenderable.Register(instance);
|
||||
modelClass.Register(instance);
|
||||
}
|
||||
}
|
||||
482
SDK/src/NDK/LuaBinding_Math.cpp
Normal file
482
SDK/src/NDK/LuaBinding_Math.cpp
Normal file
@@ -0,0 +1,482 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
#include <cstring>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindMath()
|
||||
{
|
||||
/*********************************** Nz::EulerAngles **********************************/
|
||||
eulerAnglesClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::EulerAnglesd*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::EulerAnglesd(0.0, 0.0, 0.0);
|
||||
|
||||
case 1:
|
||||
return new Nz::EulerAnglesd(*(*static_cast<Nz::EulerAnglesd**>(lua.CheckUserdata(1, "EulerAngles"))));
|
||||
|
||||
case 3:
|
||||
return new Nz::EulerAnglesd(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for EulerAngles constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
eulerAnglesClass.BindMethod("__tostring", &Nz::EulerAnglesd::ToString);
|
||||
|
||||
eulerAnglesClass.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* ypr = lua.CheckString(1, &length);
|
||||
|
||||
switch (length)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
switch (ypr[0])
|
||||
{
|
||||
case 'p':
|
||||
lua.Push(instance.pitch);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.yaw);
|
||||
return true;
|
||||
|
||||
case 'r':
|
||||
lua.Push(instance.roll);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||
break;
|
||||
|
||||
lua.Push(instance.yaw);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||
break;
|
||||
|
||||
lua.Push(instance.roll);
|
||||
return true;
|
||||
}
|
||||
|
||||
case 5:
|
||||
{
|
||||
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||
break;
|
||||
|
||||
lua.Push(instance.pitch);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
eulerAnglesClass.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* ypr = lua.CheckString(1, &length);
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (length)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
switch (ypr[0])
|
||||
{
|
||||
case 'p':
|
||||
instance.pitch = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.yaw = value;
|
||||
return true;
|
||||
|
||||
case 'r':
|
||||
instance.roll = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||
break;
|
||||
|
||||
instance.yaw = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||
break;
|
||||
|
||||
instance.roll = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
case 5:
|
||||
{
|
||||
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||
break;
|
||||
|
||||
instance.pitch = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Quaternion **********************************/
|
||||
quaternionClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Quaterniond*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::Quaterniond(1.0, 0.0, 0.0, 0.0);
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, "EulerAngles"))
|
||||
return new Nz::Quaterniond(*(*static_cast<Nz::EulerAnglesd**>(lua.ToUserdata(1))));
|
||||
else if (lua.IsOfType(1, "Quaternion"))
|
||||
return new Nz::Quaterniond(*(*static_cast<Nz::Quaterniond**>(lua.ToUserdata(1))));
|
||||
}
|
||||
|
||||
case 2:
|
||||
return new Nz::Quaterniond(lua.CheckNumber(1), *(*static_cast<Nz::Vector3d**>(lua.CheckUserdata(2, "Vector3"))));
|
||||
|
||||
case 4:
|
||||
return new Nz::Quaterniond(lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Quaternion constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
quaternionClass.BindMethod("__tostring", &Nz::Quaterniond::ToString);
|
||||
|
||||
quaternionClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* wxyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
return false;
|
||||
|
||||
switch (wxyz[0])
|
||||
{
|
||||
case 'w':
|
||||
lua.Push(instance.w);
|
||||
return true;
|
||||
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
lua.Push(instance.z);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
quaternionClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* wxyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
return false;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (wxyz[0])
|
||||
{
|
||||
case 'w':
|
||||
instance.w = value;
|
||||
return true;
|
||||
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
instance.z = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Vector2 **********************************/
|
||||
vector2dClass.SetConstructor([](Nz::LuaInstance& lua) -> Nz::Vector2d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 2U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 2:
|
||||
return new Nz::Vector2d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector2d(lua.CheckNumber(1));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector2d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for Vector2 constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
vector2dClass.BindMethod("__tostring", &Nz::Vector2d::ToString);
|
||||
|
||||
vector2dClass.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 2)
|
||||
return false;
|
||||
|
||||
lua.Push(instance[index - 1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
vector2dClass.SetSetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 2)
|
||||
return false;
|
||||
|
||||
instance[index - 1] = lua.CheckNumber(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xy = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (xy[0])
|
||||
{
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Vector3 **********************************/
|
||||
vector3dClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::Vector3d*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 3U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
case 3:
|
||||
return new Nz::Vector3d(lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0));
|
||||
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector3d(lua.CheckNumber(1), *(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))));
|
||||
else if (lua.IsOfType(1, "Vector3"))
|
||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector3d**>(lua.ToUserdata(1))));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||
return new Nz::Vector3d(lua.CheckNumber(1), *(*static_cast<Nz::Vector2d**>(lua.CheckUserdata(1, "Vector2"))));
|
||||
else if (lua.IsOfType(1, "Vector2"))
|
||||
return new Nz::Vector3d(*(*static_cast<Nz::Vector2d**>(lua.ToUserdata(1))), lua.CheckNumber(2));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for constructor");
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
vector3dClass.BindMethod("__tostring", &Nz::Vector3d::ToString);
|
||||
|
||||
vector3dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 3)
|
||||
return false;
|
||||
|
||||
lua.Push(instance[index - 1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
switch (xyz[0])
|
||||
{
|
||||
case 'x':
|
||||
lua.Push(instance.x);
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
lua.Push(instance.y);
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
lua.Push(instance.z);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
vector3dClass.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||
{
|
||||
switch (lua.GetType(1))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
{
|
||||
long long index = lua.CheckInteger(1);
|
||||
if (index < 1 || index > 3)
|
||||
return false;
|
||||
|
||||
instance[index - 1] = lua.CheckNumber(2);
|
||||
return true;
|
||||
}
|
||||
|
||||
case Nz::LuaType_String:
|
||||
{
|
||||
std::size_t length;
|
||||
const char* xyz = lua.CheckString(1, &length);
|
||||
|
||||
if (length != 1)
|
||||
break;
|
||||
|
||||
double value = lua.CheckNumber(2);
|
||||
|
||||
switch (xyz[0])
|
||||
{
|
||||
case 'x':
|
||||
instance.x = value;
|
||||
return true;
|
||||
|
||||
case 'y':
|
||||
instance.y = value;
|
||||
return true;
|
||||
|
||||
case 'z':
|
||||
instance.z = value;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterMath(Nz::LuaInstance& instance)
|
||||
{
|
||||
eulerAnglesClass.Register(instance);
|
||||
quaternionClass.Register(instance);
|
||||
vector2dClass.Register(instance);
|
||||
vector3dClass.Register(instance);
|
||||
}
|
||||
}
|
||||
214
SDK/src/NDK/LuaBinding_Network.cpp
Normal file
214
SDK/src/NDK/LuaBinding_Network.cpp
Normal file
@@ -0,0 +1,214 @@
|
||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
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);
|
||||
|
||||
/*********************************** Nz::IpAddress **********************************/
|
||||
ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::IpAddress*
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 9U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return new Nz::IpAddress;
|
||||
|
||||
case 1:
|
||||
return new Nz::IpAddress(lua.CheckString(argIndex));
|
||||
|
||||
case 4:
|
||||
case 5:
|
||||
return new Nz::IpAddress(lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt8>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
|
||||
|
||||
case 8:
|
||||
case 9:
|
||||
return new Nz::IpAddress(lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex),
|
||||
lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex), lua.Check<Nz::UInt16>(&argIndex, 0));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
ipAddressClass.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int
|
||||
{
|
||||
Nz::String service;
|
||||
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
||||
|
||||
int argIndex = 1;
|
||||
Nz::String hostName = Nz::IpAddress::ResolveAddress(instance.Check<Nz::IpAddress>(&argIndex), &service, &error);
|
||||
|
||||
if (error == Nz::ResolveError_NoError)
|
||||
{
|
||||
instance.Push(hostName);
|
||||
instance.Push(service);
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.PushBoolean(false);
|
||||
instance.Push(error);
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
|
||||
ipAddressClass.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int
|
||||
{
|
||||
Nz::ResolveError error = Nz::ResolveError_Unknown;
|
||||
|
||||
int argIndex = 1;
|
||||
Nz::NetProtocol protocol = instance.Check<Nz::NetProtocol>(&argIndex);
|
||||
Nz::String hostname = instance.Check<Nz::String>(&argIndex);
|
||||
Nz::String service = instance.Check<Nz::String>(&argIndex, "http");
|
||||
|
||||
std::vector<Nz::HostnameInfo> addresses = Nz::IpAddress::ResolveHostname(protocol, hostname, service, &error);
|
||||
if (error == Nz::ResolveError_NoError)
|
||||
{
|
||||
int index = 1;
|
||||
instance.PushTable(addresses.size());
|
||||
for (Nz::HostnameInfo& info : addresses)
|
||||
{
|
||||
instance.PushInteger(index++);
|
||||
instance.PushTable(0, 4);
|
||||
instance.SetField("Address", std::move(info.address));
|
||||
instance.SetField("CanonicalName", std::move(info.canonicalName));
|
||||
instance.SetField("Protocol", std::move(info.protocol));
|
||||
instance.SetField("SocketType", std::move(info.socketType));
|
||||
instance.SetTable();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.PushBoolean(false);
|
||||
instance.Push(error);
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
abstractSocketClass.Register(instance);
|
||||
ipAddressClass.Register(instance);
|
||||
|
||||
// Enums
|
||||
|
||||
// Nz::NetProtocol
|
||||
static_assert(Nz::NetProtocol_Max + 1 == 4, "Nz::NetProtocol has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 4);
|
||||
{
|
||||
instance.SetField("Any", Nz::NetProtocol_Any);
|
||||
instance.SetField("IPv4", Nz::NetProtocol_IPv4);
|
||||
instance.SetField("IPv6", Nz::NetProtocol_IPv6);
|
||||
instance.SetField("Unknown", Nz::NetProtocol_Unknown);
|
||||
}
|
||||
instance.SetGlobal("NetProtocol");
|
||||
|
||||
// Nz::PacketPriority
|
||||
static_assert(Nz::PacketPriority_Max + 1 == 4, "Nz::PacketPriority has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 6);
|
||||
{
|
||||
instance.SetField("High", Nz::PacketPriority_High);
|
||||
instance.SetField("Highest", Nz::PacketPriority_Highest);
|
||||
instance.SetField("Immediate", Nz::PacketPriority_Immediate);
|
||||
instance.SetField("Medium", Nz::PacketPriority_Medium);
|
||||
instance.SetField("Low", Nz::PacketPriority_Low);
|
||||
instance.SetField("Lowest", Nz::PacketPriority_Lowest);
|
||||
}
|
||||
instance.SetGlobal("PacketPriority");
|
||||
|
||||
// Nz::PacketReliability
|
||||
static_assert(Nz::PacketReliability_Max + 1 == 3, "Nz::PacketReliability has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 3);
|
||||
{
|
||||
instance.SetField("Reliable", Nz::PacketReliability_Reliable);
|
||||
instance.SetField("ReliableOrdered", Nz::PacketReliability_ReliableOrdered);
|
||||
instance.SetField("Unreliable", Nz::PacketReliability_Unreliable);
|
||||
}
|
||||
instance.SetGlobal("PacketReliability");
|
||||
|
||||
// Nz::ResolveError
|
||||
static_assert(Nz::ResolveError_Max + 1 == 9, "Nz::ResolveError has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 9);
|
||||
{
|
||||
instance.SetField("Internal", Nz::ResolveError_Internal);
|
||||
instance.SetField("ResourceError", Nz::ResolveError_ResourceError);
|
||||
instance.SetField("NoError", Nz::ResolveError_NoError);
|
||||
instance.SetField("NonRecoverable", Nz::ResolveError_NonRecoverable);
|
||||
instance.SetField("NotFound", Nz::ResolveError_NotFound);
|
||||
instance.SetField("NotInitialized", Nz::ResolveError_NotInitialized);
|
||||
instance.SetField("ProtocolNotSupported", Nz::ResolveError_ProtocolNotSupported);
|
||||
instance.SetField("TemporaryFailure", Nz::ResolveError_TemporaryFailure);
|
||||
instance.SetField("Unknown", Nz::ResolveError_Unknown);
|
||||
}
|
||||
instance.SetGlobal("ResolveError");
|
||||
|
||||
// Nz::SocketError
|
||||
static_assert(Nz::SocketError_Max + 1 == 15, "Nz::ResolveError has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 15);
|
||||
{
|
||||
instance.SetField("AddressNotAvailable", Nz::SocketError_AddressNotAvailable);
|
||||
instance.SetField("ConnectionClosed", Nz::SocketError_ConnectionClosed);
|
||||
instance.SetField("ConnectionRefused", Nz::SocketError_ConnectionRefused);
|
||||
instance.SetField("DatagramSize", Nz::SocketError_DatagramSize);
|
||||
instance.SetField("Internal", Nz::SocketError_Internal);
|
||||
instance.SetField("Packet", Nz::SocketError_Packet);
|
||||
instance.SetField("NetworkError", Nz::SocketError_NetworkError);
|
||||
instance.SetField("NoError", Nz::SocketError_NoError);
|
||||
instance.SetField("NotInitialized", Nz::SocketError_NotInitialized);
|
||||
instance.SetField("NotSupported", Nz::SocketError_NotSupported);
|
||||
instance.SetField("ResolveError", Nz::SocketError_ResolveError);
|
||||
instance.SetField("ResourceError", Nz::SocketError_ResourceError);
|
||||
instance.SetField("TimedOut", Nz::SocketError_TimedOut);
|
||||
instance.SetField("Unknown", Nz::SocketError_Unknown);
|
||||
instance.SetField("UnreachableHost", Nz::SocketError_UnreachableHost);
|
||||
}
|
||||
instance.SetGlobal("SocketError");
|
||||
|
||||
// Nz::SocketState
|
||||
static_assert(Nz::SocketState_Max + 1 == 5, "Nz::SocketState has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 5);
|
||||
{
|
||||
instance.SetField("Bound", Nz::SocketState_Bound);
|
||||
instance.SetField("Connecting", Nz::SocketState_Connecting);
|
||||
instance.SetField("Connected", Nz::SocketState_Connected);
|
||||
instance.SetField("NotConnected", Nz::SocketState_NotConnected);
|
||||
instance.SetField("Resolving", Nz::SocketState_Resolving);
|
||||
}
|
||||
instance.SetGlobal("SocketState");
|
||||
|
||||
// Nz::SocketType
|
||||
static_assert(Nz::SocketType_Max + 1 == 4, "Nz::SocketState has been updated but change was not reflected to Lua binding");
|
||||
instance.PushTable(0, 4);
|
||||
{
|
||||
instance.SetField("Raw", Nz::SocketType_Raw);
|
||||
instance.SetField("TCP", Nz::SocketType_TCP);
|
||||
instance.SetField("UDP", Nz::SocketType_UDP);
|
||||
instance.SetField("Unknown", Nz::SocketType_Unknown);
|
||||
}
|
||||
instance.SetGlobal("SocketType");
|
||||
}
|
||||
}
|
||||
17
SDK/src/NDK/LuaBinding_Renderer.cpp
Normal file
17
SDK/src/NDK/LuaBinding_Renderer.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterRenderer(Nz::LuaInstance& instance)
|
||||
{
|
||||
}
|
||||
}
|
||||
253
SDK/src/NDK/LuaBinding_SDK.cpp
Normal file
253
SDK/src/NDK/LuaBinding_SDK.cpp
Normal file
@@ -0,0 +1,253 @@
|
||||
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
namespace
|
||||
{
|
||||
int AddNilComponent(Nz::LuaInstance& lua, EntityHandle&)
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& component = handle->AddComponent<T>();
|
||||
lua.Push(component.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int PushNilComponent(Nz::LuaInstance& lua, BaseComponent&)
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||
{
|
||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||
|
||||
T& rightComponent = static_cast<T&>(component);
|
||||
lua.Push(rightComponent.CreateHandle());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void LuaBinding::BindSDK()
|
||||
{
|
||||
/*********************************** Ndk::Application **********************************/
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
//application.SetMethod("AddWindow", &Application::AddWindow);
|
||||
#endif
|
||||
application.BindMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application) -> int
|
||||
{
|
||||
instance.Push(application->AddWorld().CreateHandle());
|
||||
return 1;
|
||||
});
|
||||
|
||||
application.BindMethod("GetUpdateTime", &Application::GetUpdateTime);
|
||||
application.BindMethod("Quit", &Application::Quit);
|
||||
|
||||
/*********************************** Ndk::Console **********************************/
|
||||
#ifndef NDK_SERVER
|
||||
consoleClass.Inherit<Nz::Node>(nodeClass, [] (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.SetMethod("GetTextFont", &Console::GetTextFont);
|
||||
|
||||
consoleClass.BindMethod("IsVisible", &Console::IsVisible);
|
||||
|
||||
consoleClass.BindMethod("SendCharacter", &Console::SendCharacter);
|
||||
//consoleClass.SetMethod("SendEvent", &Console::SendEvent);
|
||||
|
||||
consoleClass.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
|
||||
consoleClass.BindMethod("SetSize", &Console::SetSize);
|
||||
//consoleClass.SetMethod("SetTextFont", &Console::SetTextFont);
|
||||
|
||||
consoleClass.BindMethod("Show", &Console::Show, true);
|
||||
#endif
|
||||
|
||||
/*********************************** Ndk::Entity **********************************/
|
||||
entityClass.BindMethod("Enable", &Entity::Enable);
|
||||
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("RemoveComponent", (void(Entity::*)(ComponentIndex)) &Entity::RemoveComponent);
|
||||
entityClass.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
|
||||
entityClass.BindMethod("__tostring", &EntityHandle::ToString);
|
||||
|
||||
entityClass.BindMethod("AddComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (!binding.valid)
|
||||
{
|
||||
lua.Error("This component is not available to the LuaAPI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return binding.adder(lua, handle);
|
||||
});
|
||||
|
||||
entityClass.BindMethod("GetComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int
|
||||
{
|
||||
int index = 1;
|
||||
ComponentIndex componentIndex = lua.Check<ComponentIndex>(&index);
|
||||
|
||||
if (!handle->HasComponent(componentIndex))
|
||||
{
|
||||
lua.PushNil();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (componentIndex > m_componentBinding.size())
|
||||
{
|
||||
lua.Error("Invalid component index");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||
if (!binding.valid)
|
||||
{
|
||||
lua.Error("This component is not available to the LuaAPI");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return binding.getter(lua, handle->GetComponent(componentIndex));
|
||||
});
|
||||
|
||||
/*********************************** Ndk::NodeComponent **********************************/
|
||||
nodeComponent.Inherit<Nz::Node>(nodeClass, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||
{
|
||||
return handle->GetObject();
|
||||
});
|
||||
|
||||
/*********************************** Ndk::VelocityComponent **********************************/
|
||||
velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(1, &length);
|
||||
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
lua.Push(instance->linearVelocity);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||
{
|
||||
std::size_t length;
|
||||
const char* member = lua.CheckString(1, &length);
|
||||
|
||||
int argIndex = 2;
|
||||
if (std::strcmp(member, "Linear") == 0)
|
||||
{
|
||||
instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
/*********************************** Ndk::World **********************************/
|
||||
worldClass.BindMethod("CreateEntity", &World::CreateEntity);
|
||||
worldClass.BindMethod("CreateEntities", &World::CreateEntities);
|
||||
worldClass.BindMethod("Clear", &World::Clear);
|
||||
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
/*********************************** Ndk::GraphicsComponent **********************************/
|
||||
graphicsComponent.BindMethod("Attach", &GraphicsComponent::Attach, 0);
|
||||
#endif
|
||||
|
||||
|
||||
// Components functions
|
||||
m_componentBinding.resize(BaseComponent::GetMaxComponentIndex() + 1);
|
||||
|
||||
EnableComponentBinding<NodeComponent>();
|
||||
EnableComponentBinding<VelocityComponent>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
EnableComponentBinding<GraphicsComponent>();
|
||||
#endif
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void LuaBinding::EnableComponentBinding()
|
||||
{
|
||||
ComponentBinding binding;
|
||||
binding.adder = &AddComponentOfType<T>;
|
||||
binding.getter = &PushComponentOfType<T>;
|
||||
binding.valid = true;
|
||||
|
||||
NazaraAssert(T::componentIndex < m_componentBinding.size(), "Component index is over component binding size");
|
||||
|
||||
m_componentBinding[T::componentIndex] = std::move(binding);
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterSDK(Nz::LuaInstance& instance)
|
||||
{
|
||||
// Classes
|
||||
application.Register(instance);
|
||||
entityClass.Register(instance);
|
||||
nodeComponent.Register(instance);
|
||||
velocityComponent.Register(instance);
|
||||
worldClass.Register(instance);
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
consoleClass.Register(instance);
|
||||
graphicsComponent.Register(instance);
|
||||
#endif
|
||||
|
||||
// Enums
|
||||
|
||||
// ComponentType (fake enumeration to expose component indexes)
|
||||
instance.PushTable();
|
||||
{
|
||||
#ifndef NDK_SERVER
|
||||
instance.PushInteger(GraphicsComponent::componentIndex);
|
||||
instance.SetField("Graphics");
|
||||
#endif
|
||||
|
||||
instance.PushInteger(NodeComponent::componentIndex);
|
||||
instance.SetField("Node");
|
||||
|
||||
instance.PushInteger(VelocityComponent::componentIndex);
|
||||
instance.SetField("Velocity");
|
||||
}
|
||||
instance.SetGlobal("ComponentType");
|
||||
}
|
||||
}
|
||||
255
SDK/src/NDK/LuaBinding_Utility.cpp
Normal file
255
SDK/src/NDK/LuaBinding_Utility.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/LuaBinding.hpp>
|
||||
#include <NDK/LuaAPI.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
void LuaBinding::BindUtility()
|
||||
{
|
||||
/*********************************** Nz::AbstractImage **********************************/
|
||||
abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
||||
abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
|
||||
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||
|
||||
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 1U);
|
||||
switch (argCount)
|
||||
{
|
||||
case 0:
|
||||
return lua.Push(abstractImage->GetMemoryUsage());
|
||||
|
||||
case 1:
|
||||
{
|
||||
int index = 1;
|
||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&index));
|
||||
|
||||
return lua.Push(abstractImage->GetMemoryUsage(level));
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method GetMemoryUsage");
|
||||
return 0;
|
||||
});
|
||||
|
||||
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 6U);
|
||||
int argIndex = 1;
|
||||
|
||||
std::size_t bufferSize = 0;
|
||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
||||
|
||||
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
/* Disabled until Box and Rect have been ported
|
||||
else if (lua.IsOfType(2, "Box"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}
|
||||
else if (lua.IsOfType(2, "Rect"))
|
||||
{
|
||||
// bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||
Nz::Rectui box = lua.Check<Nz::Rectui>(&argIndex);
|
||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||
|
||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||
}*/
|
||||
|
||||
lua.Error("No matching overload for method Update");
|
||||
return 0;
|
||||
});
|
||||
|
||||
/*********************************** Nz::Node **********************************/
|
||||
nodeClass.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);
|
||||
//nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||
nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||
nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||
nodeClass.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);
|
||||
//nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||
nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||
//nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix);
|
||||
nodeClass.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||
|
||||
nodeClass.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);
|
||||
|
||||
nodeClass.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
|
||||
nodeClass.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);
|
||||
|
||||
nodeClass.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
int argIndex = 1;
|
||||
|
||||
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.Move(offset, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
int argIndex = 1;
|
||||
|
||||
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.Rotate(rotation, coordSys);
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
node.Scale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
node.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method Scale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
{
|
||||
float scale = lua.Check<float>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
node.SetScale(scale, coordSys);
|
||||
}
|
||||
else
|
||||
node.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 3:
|
||||
case 4:
|
||||
{
|
||||
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||
|
||||
node.SetScale(scale, coordSys);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetScale");
|
||||
return 0;
|
||||
});
|
||||
|
||||
nodeClass.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int
|
||||
{
|
||||
unsigned int argCount = std::min(lua.GetStackTop(), 4U);
|
||||
|
||||
int argIndex = 1;
|
||||
switch (argCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||
node.SetInitialScale(lua.Check<float>(&argIndex));
|
||||
else
|
||||
node.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
node.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua.Error("No matching overload for method SetInitialScale");
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
void LuaBinding::RegisterUtility(Nz::LuaInstance& instance)
|
||||
{
|
||||
abstractImage.Register(instance);
|
||||
nodeClass.Register(instance);
|
||||
}
|
||||
}
|
||||
@@ -13,64 +13,80 @@
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <NDK/BaseSystem.hpp>
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/CollisionComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
bool Sdk::Initialize()
|
||||
{
|
||||
if (s_referenceCounter++ > 0)
|
||||
return true; // Déjà initialisé
|
||||
return true; // Already initialized
|
||||
|
||||
try
|
||||
{
|
||||
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
|
||||
|
||||
// Initialisation du moteur
|
||||
// Initialize the engine first
|
||||
|
||||
// Modules clients
|
||||
Nz::Audio::Initialize();
|
||||
Nz::Graphics::Initialize();
|
||||
|
||||
// Modules serveurs
|
||||
// Shared modules
|
||||
Nz::Lua::Initialize();
|
||||
Nz::Noise::Initialize();
|
||||
Nz::Physics::Initialize();
|
||||
Nz::Utility::Initialize();
|
||||
|
||||
// Initialisation du SDK
|
||||
#ifndef NDK_SERVER
|
||||
// Client modules
|
||||
Nz::Audio::Initialize();
|
||||
Nz::Graphics::Initialize();
|
||||
#endif
|
||||
|
||||
// Initialisation des composants et systèmes
|
||||
// SDK Initialization
|
||||
|
||||
// Components
|
||||
BaseComponent::Initialize();
|
||||
BaseSystem::Initialize();
|
||||
|
||||
// Composants
|
||||
InitializeComponent<CameraComponent>("NdkCam");
|
||||
// Shared components
|
||||
InitializeComponent<CollisionComponent>("NdkColli");
|
||||
InitializeComponent<LightComponent>("NdkLight");
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<GraphicsComponent>("NdkGfx");
|
||||
InitializeComponent<NodeComponent>("NdkNode");
|
||||
InitializeComponent<PhysicsComponent>("NdkPhys");
|
||||
InitializeComponent<VelocityComponent>("NdkVeloc");
|
||||
|
||||
// Systèmes
|
||||
InitializeSystem<ListenerSystem>();
|
||||
#ifndef NDK_SERVER
|
||||
// Client components
|
||||
InitializeComponent<CameraComponent>("NdkCam");
|
||||
InitializeComponent<LightComponent>("NdkLight");
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<GraphicsComponent>("NdkGfx");
|
||||
#endif
|
||||
|
||||
// Systems
|
||||
|
||||
BaseSystem::Initialize();
|
||||
|
||||
// Shared systems
|
||||
InitializeSystem<PhysicsSystem>();
|
||||
InitializeSystem<RenderSystem>();
|
||||
InitializeSystem<VelocitySystem>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
// Client systems
|
||||
InitializeSystem<ListenerSystem>();
|
||||
InitializeSystem<RenderSystem>();
|
||||
#endif
|
||||
|
||||
NazaraNotice("Initialized: SDK");
|
||||
return true;
|
||||
}
|
||||
@@ -86,23 +102,25 @@ namespace Ndk
|
||||
{
|
||||
if (s_referenceCounter != 1)
|
||||
{
|
||||
// Le module est soit encore utilisé, soit pas initialisé
|
||||
// Either the module is not initialized, either it was initialized multiple times
|
||||
if (s_referenceCounter > 1)
|
||||
s_referenceCounter--;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Libération du SDK
|
||||
// Uninitialize the SDK
|
||||
s_referenceCounter = 0;
|
||||
|
||||
// Libération du moteur
|
||||
// Uninitialize the engine
|
||||
|
||||
// Modules clients
|
||||
#ifndef NDK_SERVER
|
||||
// Client modules
|
||||
Nz::Audio::Uninitialize();
|
||||
Nz::Graphics::Uninitialize();
|
||||
#endif
|
||||
|
||||
// Modules serveurs
|
||||
// Shared modules
|
||||
Nz::Lua::Uninitialize();
|
||||
Nz::Noise::Uninitialize();
|
||||
Nz::Physics::Uninitialize();
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Ndk
|
||||
m_coordinateSystemMatrix(Nz::Matrix4f::Identity()),
|
||||
m_coordinateSystemInvalidated(true)
|
||||
{
|
||||
ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
|
||||
SetDefaultBackground(Nz::ColorBackground::New());
|
||||
SetUpdateRate(0.f);
|
||||
}
|
||||
@@ -95,7 +96,7 @@ namespace Ndk
|
||||
|
||||
//UpdateDirectionalShadowMaps(camComponent);
|
||||
|
||||
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue();
|
||||
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue();
|
||||
renderQueue->Clear();
|
||||
|
||||
//TODO: Culling
|
||||
@@ -123,7 +124,8 @@ namespace Ndk
|
||||
sceneData.background = m_background;
|
||||
sceneData.viewer = &camComponent;
|
||||
|
||||
m_renderTechnique.Draw(sceneData);
|
||||
m_renderTechnique->Clear(sceneData);
|
||||
m_renderTechnique->Draw(sceneData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,17 @@
|
||||
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
World::~World()
|
||||
World::~World() noexcept
|
||||
{
|
||||
// La destruction doit se faire dans un ordre précis
|
||||
Clear();
|
||||
@@ -19,10 +22,13 @@ namespace Ndk
|
||||
|
||||
void World::AddDefaultSystems()
|
||||
{
|
||||
AddSystem<ListenerSystem>();
|
||||
AddSystem<PhysicsSystem>();
|
||||
AddSystem<RenderSystem>();
|
||||
AddSystem<VelocitySystem>();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
AddSystem<ListenerSystem>();
|
||||
AddSystem<RenderSystem>();
|
||||
#endif
|
||||
}
|
||||
|
||||
const EntityHandle& World::CreateEntity()
|
||||
@@ -40,7 +46,7 @@ namespace Ndk
|
||||
id = m_entities.size();
|
||||
|
||||
// Impossible d'utiliser emplace_back à cause de la portée
|
||||
m_entities.push_back(Entity(*this, id));
|
||||
m_entities.push_back(Entity(this, id));
|
||||
}
|
||||
|
||||
// On initialise l'entité et on l'ajoute à la liste des entités vivantes
|
||||
@@ -53,9 +59,9 @@ namespace Ndk
|
||||
return m_aliveEntities.back();
|
||||
}
|
||||
|
||||
void World::Clear()
|
||||
void World::Clear() noexcept
|
||||
{
|
||||
///DOC: Tous les handles sont correctement invalidés
|
||||
///DOC: Tous les handles sont correctement invalidés, les entités sont immédiatement invalidées
|
||||
|
||||
// Destruction des entités d'abord, et des handles ensuite
|
||||
// ceci pour éviter que les handles n'informent les entités inutilement lors de leur destruction
|
||||
@@ -127,33 +133,33 @@ namespace Ndk
|
||||
|
||||
Entity* entity = &m_entities[i].entity;
|
||||
|
||||
// Aucun intérêt de traiter une entité n'existant plus
|
||||
if (entity->IsValid())
|
||||
// Check entity validity (as it could have been reported as dirty and killed during the same iteration)
|
||||
if (!entity->IsValid())
|
||||
continue;
|
||||
|
||||
for (auto& system : m_systems)
|
||||
{
|
||||
for (auto& system : m_systems)
|
||||
// Ignore non-existent systems
|
||||
if (!system)
|
||||
continue;
|
||||
|
||||
// Is our entity already part of this system?
|
||||
bool partOfSystem = system->HasEntity(entity);
|
||||
|
||||
// Should it be part of it?
|
||||
if (entity->IsEnabled() && system->Filters(entity))
|
||||
{
|
||||
// Ignore non-existent systems
|
||||
if (!system)
|
||||
continue;
|
||||
// Yes it should, add it to the system if not already done and validate it (again)
|
||||
if (!partOfSystem)
|
||||
system->AddEntity(entity);
|
||||
|
||||
// L'entité est-elle enregistrée comme faisant partie du système ?
|
||||
bool partOfSystem = system->HasEntity(entity);
|
||||
|
||||
// Doit-elle en faire partie ?
|
||||
if (system->Filters(entity))
|
||||
{
|
||||
// L'entité doit faire partie du système, revalidons-là (événement système) ou ajoutons-la au système
|
||||
if (!partOfSystem)
|
||||
system->AddEntity(entity);
|
||||
|
||||
system->ValidateEntity(entity, !partOfSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Elle ne doit pas en faire partie, si elle en faisait partie nous devons la retirer
|
||||
if (partOfSystem)
|
||||
system->RemoveEntity(entity);
|
||||
}
|
||||
system->ValidateEntity(entity, !partOfSystem);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, it shouldn't, remove it if it's part of the system
|
||||
if (partOfSystem)
|
||||
system->RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user