Merge branch 'master' into vulkan
This commit is contained in:
commit
2217cf9661
|
|
@ -0,0 +1,104 @@
|
||||||
|
// 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_BASEWIDGET_HPP
|
||||||
|
#define NDK_BASEWIDGET_HPP
|
||||||
|
|
||||||
|
#include <NDK/Prerequesites.hpp>
|
||||||
|
#include <NDK/Entity.hpp>
|
||||||
|
#include <NDK/EntityOwner.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
|
#include <Nazara/Utility/Event.hpp>
|
||||||
|
#include <Nazara/Utility/Mouse.hpp>
|
||||||
|
#include <Nazara/Utility/Node.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class Canvas;
|
||||||
|
|
||||||
|
class NDK_API BaseWidget : public Nz::Node
|
||||||
|
{
|
||||||
|
friend Canvas;
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct Padding;
|
||||||
|
|
||||||
|
BaseWidget(BaseWidget* parent);
|
||||||
|
BaseWidget(const BaseWidget&) = delete;
|
||||||
|
BaseWidget(BaseWidget&&) = default;
|
||||||
|
virtual ~BaseWidget();
|
||||||
|
|
||||||
|
template<typename T, typename... Args> T& Add(Args&&... args);
|
||||||
|
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
|
||||||
|
|
||||||
|
inline void Center();
|
||||||
|
|
||||||
|
void EnableBackground(bool enable);
|
||||||
|
|
||||||
|
//virtual BaseWidget* Clone() const = 0;
|
||||||
|
|
||||||
|
inline Canvas* GetCanvas();
|
||||||
|
inline const Padding& GetPadding() const;
|
||||||
|
inline const Nz::Vector2f& GetContentSize() const;
|
||||||
|
inline Nz::Vector2f GetSize() const;
|
||||||
|
|
||||||
|
void GrabKeyboard();
|
||||||
|
|
||||||
|
virtual void ResizeToContent() = 0;
|
||||||
|
|
||||||
|
inline void SetContentSize(const Nz::Vector2f& size);
|
||||||
|
inline void SetPadding(float left, float top, float right, float bottom);
|
||||||
|
void SetSize(const Nz::Vector2f& size);
|
||||||
|
|
||||||
|
BaseWidget& operator=(const BaseWidget&) = delete;
|
||||||
|
BaseWidget& operator=(BaseWidget&&) = default;
|
||||||
|
|
||||||
|
struct Padding
|
||||||
|
{
|
||||||
|
float left;
|
||||||
|
float top;
|
||||||
|
float right;
|
||||||
|
float bottom;
|
||||||
|
};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
EntityHandle CreateEntity();
|
||||||
|
void DestroyEntity(Entity* entity);
|
||||||
|
virtual void Layout();
|
||||||
|
void InvalidateNode() override;
|
||||||
|
|
||||||
|
virtual void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key);
|
||||||
|
virtual void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key);
|
||||||
|
virtual void OnMouseEnter();
|
||||||
|
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
|
||||||
|
virtual void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button);
|
||||||
|
virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button);
|
||||||
|
virtual void OnMouseExit();
|
||||||
|
virtual void OnTextEntered(char32_t character, bool repeated);
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline BaseWidget();
|
||||||
|
|
||||||
|
inline void UpdateCanvasIndex(std::size_t index);
|
||||||
|
|
||||||
|
std::size_t m_canvasIndex;
|
||||||
|
std::vector<EntityOwner> m_entities;
|
||||||
|
std::vector<std::unique_ptr<BaseWidget>> m_children;
|
||||||
|
Canvas* m_canvas;
|
||||||
|
EntityOwner m_backgroundEntity;
|
||||||
|
Padding m_padding;
|
||||||
|
WorldHandle m_world;
|
||||||
|
Nz::Color m_backgroundColor;
|
||||||
|
Nz::SpriteRef m_backgroundSprite;
|
||||||
|
Nz::Vector2f m_contentSize;
|
||||||
|
BaseWidget* m_widgetParent;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <NDK/BaseWidget.inl>
|
||||||
|
|
||||||
|
#endif // NDK_BASEWIDGET_HPP
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
// 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/BaseWidget.hpp>
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <Nazara/Math/Algorithm.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
inline BaseWidget::BaseWidget() :
|
||||||
|
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
|
||||||
|
m_canvas(nullptr),
|
||||||
|
m_contentSize(50.f, 50.f),
|
||||||
|
m_widgetParent(nullptr)
|
||||||
|
{
|
||||||
|
SetPadding(5.f, 5.f, 5.f, 5.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
inline T& BaseWidget::Add(Args&&... args)
|
||||||
|
{
|
||||||
|
std::unique_ptr<T> widget = std::make_unique<T>(this, std::forward<Args>(args)...);
|
||||||
|
T& widgetRef = *widget;
|
||||||
|
AddChild(std::move(widget));
|
||||||
|
|
||||||
|
return widgetRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)
|
||||||
|
{
|
||||||
|
m_children.emplace_back(std::move(widget));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void BaseWidget::Center()
|
||||||
|
{
|
||||||
|
NazaraAssert(m_widgetParent, "Widget has no parent");
|
||||||
|
|
||||||
|
Nz::Vector2f parentSize = m_widgetParent->GetSize();
|
||||||
|
Nz::Vector2f mySize = GetSize();
|
||||||
|
SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Canvas* BaseWidget::GetCanvas()
|
||||||
|
{
|
||||||
|
return m_canvas;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const BaseWidget::Padding& BaseWidget::GetPadding() const
|
||||||
|
{
|
||||||
|
return m_padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Nz::Vector2f& BaseWidget::GetContentSize() const
|
||||||
|
{
|
||||||
|
return m_contentSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Nz::Vector2f BaseWidget::GetSize() const
|
||||||
|
{
|
||||||
|
return Nz::Vector2f(m_contentSize.x + m_padding.left + m_padding.right, m_contentSize.y + m_padding.top + m_padding.bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void BaseWidget::SetContentSize(const Nz::Vector2f& size)
|
||||||
|
{
|
||||||
|
m_contentSize = size;
|
||||||
|
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void BaseWidget::SetPadding(float left, float top, float right, float bottom)
|
||||||
|
{
|
||||||
|
m_padding.left = left;
|
||||||
|
m_padding.top = top;
|
||||||
|
m_padding.bottom = bottom;
|
||||||
|
m_padding.right = right;
|
||||||
|
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void BaseWidget::UpdateCanvasIndex(std::size_t index)
|
||||||
|
{
|
||||||
|
m_canvasIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
// 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_CANVAS_HPP
|
||||||
|
#define NDK_CANVAS_HPP
|
||||||
|
|
||||||
|
#include <NDK/Prerequesites.hpp>
|
||||||
|
#include <NDK/BaseWidget.hpp>
|
||||||
|
#include <Nazara/Utility/EventHandler.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API Canvas : public BaseWidget
|
||||||
|
{
|
||||||
|
friend BaseWidget;
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct Padding;
|
||||||
|
|
||||||
|
inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler);
|
||||||
|
Canvas(const Canvas&) = delete;
|
||||||
|
Canvas(Canvas&&) = delete;
|
||||||
|
~Canvas() = default;
|
||||||
|
|
||||||
|
inline const WorldHandle& GetWorld() const;
|
||||||
|
|
||||||
|
void ResizeToContent() override;
|
||||||
|
|
||||||
|
Canvas& operator=(const Canvas&) = delete;
|
||||||
|
Canvas& operator=(Canvas&&) = delete;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void Layout() override;
|
||||||
|
|
||||||
|
void NotifyWidgetUpdate(std::size_t index);
|
||||||
|
|
||||||
|
std::size_t RegisterWidget(BaseWidget* widget);
|
||||||
|
|
||||||
|
inline void SetKeyboardOwner(BaseWidget* widget);
|
||||||
|
|
||||||
|
void UnregisterWidget(std::size_t index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void OnMouseButtonPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||||
|
void OnMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
|
||||||
|
void OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
|
||||||
|
void OnMouseLeft(const Nz::EventHandler* eventHandler);
|
||||||
|
void OnKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||||
|
void OnKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
|
||||||
|
void OnTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
|
||||||
|
|
||||||
|
struct WidgetBox
|
||||||
|
{
|
||||||
|
BaseWidget* widget;
|
||||||
|
Nz::Boxf box;
|
||||||
|
};
|
||||||
|
|
||||||
|
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
|
||||||
|
NazaraSlot(Nz::EventHandler, OnKeyReleased, m_keyReleasedSlot);
|
||||||
|
NazaraSlot(Nz::EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot);
|
||||||
|
NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
|
||||||
|
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot);
|
||||||
|
NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot);
|
||||||
|
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
|
||||||
|
|
||||||
|
std::vector<WidgetBox> m_widgetBoxes;
|
||||||
|
const WidgetBox* m_hoveredWidget;
|
||||||
|
BaseWidget* m_keyboardOwner;
|
||||||
|
WorldHandle m_world;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <NDK/Canvas.inl>
|
||||||
|
|
||||||
|
#endif // NDK_CANVAS_HPP
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Canvas.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler) :
|
||||||
|
m_hoveredWidget(nullptr),
|
||||||
|
m_keyboardOwner(nullptr),
|
||||||
|
m_world(std::move(world))
|
||||||
|
{
|
||||||
|
m_canvas = this;
|
||||||
|
|
||||||
|
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, this, &Canvas::OnKeyPressed);
|
||||||
|
m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, this, &Canvas::OnKeyReleased);
|
||||||
|
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, this, &Canvas::OnMouseButtonPressed);
|
||||||
|
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnMouseButtonRelease);
|
||||||
|
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnMouseMoved);
|
||||||
|
m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnMouseLeft);
|
||||||
|
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnTextEntered);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const WorldHandle& Canvas::GetWorld() const
|
||||||
|
{
|
||||||
|
return m_world;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Ndk::Canvas::SetKeyboardOwner(BaseWidget* widget)
|
||||||
|
{
|
||||||
|
m_keyboardOwner = widget;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -64,6 +64,8 @@ namespace Ndk
|
||||||
inline void SetZFar(float zFar);
|
inline void SetZFar(float zFar);
|
||||||
inline void SetZNear(float zNear);
|
inline void SetZNear(float zNear);
|
||||||
|
|
||||||
|
inline bool UpdateVisibility(std::size_t visibilityHash);
|
||||||
|
|
||||||
static ComponentIndex componentIndex;
|
static ComponentIndex componentIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -89,6 +91,7 @@ namespace Ndk
|
||||||
NazaraSlot(Nz::RenderTarget, OnRenderTargetRelease, m_targetReleaseSlot);
|
NazaraSlot(Nz::RenderTarget, OnRenderTargetRelease, m_targetReleaseSlot);
|
||||||
NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot);
|
NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot);
|
||||||
|
|
||||||
|
std::size_t m_visibilityHash;
|
||||||
Nz::ProjectionType m_projectionType;
|
Nz::ProjectionType m_projectionType;
|
||||||
mutable Nz::Frustumf m_frustum;
|
mutable Nz::Frustumf m_frustum;
|
||||||
mutable Nz::Matrix4f m_projectionMatrix;
|
mutable Nz::Matrix4f m_projectionMatrix;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ namespace Ndk
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline CameraComponent::CameraComponent() :
|
inline CameraComponent::CameraComponent() :
|
||||||
|
m_visibilityHash(0U),
|
||||||
m_projectionType(Nz::ProjectionType_Perspective),
|
m_projectionType(Nz::ProjectionType_Perspective),
|
||||||
m_targetRegion(0.f, 0.f, 1.f, 1.f),
|
m_targetRegion(0.f, 0.f, 1.f, 1.f),
|
||||||
m_target(nullptr),
|
m_target(nullptr),
|
||||||
|
|
@ -38,6 +39,7 @@ namespace Ndk
|
||||||
inline CameraComponent::CameraComponent(const CameraComponent& camera) :
|
inline CameraComponent::CameraComponent(const CameraComponent& camera) :
|
||||||
Component(camera),
|
Component(camera),
|
||||||
AbstractViewer(camera),
|
AbstractViewer(camera),
|
||||||
|
m_visibilityHash(camera.m_visibilityHash),
|
||||||
m_projectionType(camera.m_projectionType),
|
m_projectionType(camera.m_projectionType),
|
||||||
m_targetRegion(camera.m_targetRegion),
|
m_targetRegion(camera.m_targetRegion),
|
||||||
m_target(nullptr),
|
m_target(nullptr),
|
||||||
|
|
@ -280,6 +282,26 @@ namespace Ndk
|
||||||
InvalidateProjectionMatrix();
|
InvalidateProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Update the camera component visibility hash
|
||||||
|
*
|
||||||
|
* This is used with CullingList (which produce a visibility hash)
|
||||||
|
*
|
||||||
|
* \param visibilityHash New visibility hash
|
||||||
|
*
|
||||||
|
* \return True if the visibility hash is not the same as before
|
||||||
|
*/
|
||||||
|
inline bool CameraComponent::UpdateVisibility(std::size_t visibilityHash)
|
||||||
|
{
|
||||||
|
if (m_visibilityHash != visibilityHash)
|
||||||
|
{
|
||||||
|
m_visibilityHash = visibilityHash;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Invalidates the frustum
|
* \brief Invalidates the frustum
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||||
#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/CullingList.hpp>
|
||||||
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||||
#include <Nazara/Utility/Node.hpp>
|
#include <Nazara/Utility/Node.hpp>
|
||||||
#include <NDK/Component.hpp>
|
#include <NDK/Component.hpp>
|
||||||
|
|
@ -16,6 +17,7 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
class GraphicsComponent;
|
class GraphicsComponent;
|
||||||
|
|
||||||
|
using GraphicsComponentCullingList = Nz::CullingList<GraphicsComponent>;
|
||||||
using GraphicsComponentHandle = Nz::ObjectHandle<GraphicsComponent>;
|
using GraphicsComponentHandle = Nz::ObjectHandle<GraphicsComponent>;
|
||||||
|
|
||||||
class NDK_API GraphicsComponent : public Component<GraphicsComponent>, public Nz::HandledObject<GraphicsComponent>
|
class NDK_API GraphicsComponent : public Component<GraphicsComponent>, public Nz::HandledObject<GraphicsComponent>
|
||||||
|
|
@ -29,10 +31,11 @@ namespace Ndk
|
||||||
inline GraphicsComponent(const GraphicsComponent& graphicsComponent);
|
inline GraphicsComponent(const GraphicsComponent& graphicsComponent);
|
||||||
~GraphicsComponent() = default;
|
~GraphicsComponent() = default;
|
||||||
|
|
||||||
inline void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const;
|
inline void AddToCullingList(GraphicsComponentCullingList* cullingList) const;
|
||||||
|
void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const;
|
||||||
|
|
||||||
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||||
inline void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
|
void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
|
||||||
|
|
||||||
inline void Clear();
|
inline void Clear();
|
||||||
|
|
||||||
|
|
@ -46,10 +49,12 @@ namespace Ndk
|
||||||
|
|
||||||
inline const Nz::BoundingVolumef& GetBoundingVolume() const;
|
inline const Nz::BoundingVolumef& GetBoundingVolume() const;
|
||||||
|
|
||||||
|
inline void RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const;
|
||||||
|
|
||||||
static ComponentIndex componentIndex;
|
static ComponentIndex componentIndex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void InvalidateBoundingVolume();
|
inline void InvalidateBoundingVolume() const;
|
||||||
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index);
|
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index);
|
||||||
inline void InvalidateRenderables();
|
inline void InvalidateRenderables();
|
||||||
inline void InvalidateTransformMatrix();
|
inline void InvalidateTransformMatrix();
|
||||||
|
|
@ -74,7 +79,8 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable(Renderable&& rhs) noexcept :
|
Renderable(Renderable&& rhs) noexcept :
|
||||||
renderableInvalidationSlot(std::move(rhs.renderableInvalidationSlot)),
|
renderableBoundingVolumeInvalidationSlot(std::move(rhs.renderableBoundingVolumeInvalidationSlot)),
|
||||||
|
renderableDataInvalidationSlot(std::move(rhs.renderableDataInvalidationSlot)),
|
||||||
renderableReleaseSlot(std::move(rhs.renderableReleaseSlot)),
|
renderableReleaseSlot(std::move(rhs.renderableReleaseSlot)),
|
||||||
data(std::move(rhs.data)),
|
data(std::move(rhs.data)),
|
||||||
renderable(std::move(rhs.renderable)),
|
renderable(std::move(rhs.renderable)),
|
||||||
|
|
@ -93,13 +99,15 @@ namespace Ndk
|
||||||
data = std::move(r.data);
|
data = std::move(r.data);
|
||||||
dataUpdated = r.dataUpdated;
|
dataUpdated = r.dataUpdated;
|
||||||
renderable = std::move(r.renderable);
|
renderable = std::move(r.renderable);
|
||||||
renderableInvalidationSlot = std::move(r.renderableInvalidationSlot);
|
renderableBoundingVolumeInvalidationSlot = std::move(r.renderableBoundingVolumeInvalidationSlot);
|
||||||
|
renderableDataInvalidationSlot = std::move(r.renderableDataInvalidationSlot);
|
||||||
renderableReleaseSlot = std::move(r.renderableReleaseSlot);
|
renderableReleaseSlot = std::move(r.renderableReleaseSlot);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateData, renderableInvalidationSlot);
|
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateBoundingVolume, renderableBoundingVolumeInvalidationSlot);
|
||||||
|
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateData, renderableDataInvalidationSlot);
|
||||||
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableRelease, renderableReleaseSlot);
|
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableRelease, renderableReleaseSlot);
|
||||||
|
|
||||||
mutable Nz::InstancedRenderable::InstanceData data;
|
mutable Nz::InstancedRenderable::InstanceData data;
|
||||||
|
|
@ -107,6 +115,16 @@ namespace Ndk
|
||||||
mutable bool dataUpdated;
|
mutable bool dataUpdated;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using VolumeCullingListEntry = GraphicsComponentCullingList::VolumeEntry;
|
||||||
|
|
||||||
|
struct VolumeCullingEntry
|
||||||
|
{
|
||||||
|
VolumeCullingListEntry listEntry;
|
||||||
|
|
||||||
|
NazaraSlot(GraphicsComponentCullingList, OnCullingListRelease, cullingListReleaseSlot);
|
||||||
|
};
|
||||||
|
|
||||||
|
mutable std::vector<VolumeCullingEntry> m_volumeCullingEntries;
|
||||||
std::vector<Renderable> m_renderables;
|
std::vector<Renderable> m_renderables;
|
||||||
mutable Nz::BoundingVolumef m_boundingVolume;
|
mutable Nz::BoundingVolumef m_boundingVolume;
|
||||||
mutable Nz::Matrix4f m_transformMatrix;
|
mutable Nz::Matrix4f m_transformMatrix;
|
||||||
|
|
|
||||||
|
|
@ -28,52 +28,12 @@ namespace Ndk
|
||||||
Attach(r.renderable, r.data.renderOrder);
|
Attach(r.renderable, r.data.renderOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
inline void GraphicsComponent::AddToCullingList(GraphicsComponentCullingList* cullingList) const
|
||||||
* \brief Adds the renderable elements to the render queue
|
|
||||||
*
|
|
||||||
* \param renderQueue Queue to be added
|
|
||||||
*/
|
|
||||||
|
|
||||||
inline void GraphicsComponent::AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const
|
|
||||||
{
|
{
|
||||||
EnsureTransformMatrixUpdate();
|
m_volumeCullingEntries.emplace_back(VolumeCullingEntry{});
|
||||||
|
VolumeCullingEntry& entry = m_volumeCullingEntries.back();
|
||||||
Ndk::RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem<Ndk::RenderSystem>();
|
entry.cullingListReleaseSlot.Connect(cullingList->OnCullingListRelease, this, &GraphicsComponent::RemoveFromCullingList);
|
||||||
|
entry.listEntry = cullingList->RegisterVolumeTest(this);
|
||||||
for (const Renderable& object : m_renderables)
|
|
||||||
{
|
|
||||||
if (!object.dataUpdated)
|
|
||||||
{
|
|
||||||
object.data.transformMatrix = Nz::Matrix4f::ConcatenateAffine(renderSystem.GetCoordinateSystemMatrix(), Nz::Matrix4f::ConcatenateAffine(object.data.localMatrix, m_transformMatrix));
|
|
||||||
object.renderable->UpdateData(&object.data);
|
|
||||||
object.dataUpdated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
object.renderable->AddToRenderQueue(renderQueue, object.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Attaches a renderable to the entity
|
|
||||||
*
|
|
||||||
* \param renderable Reference to a renderable element
|
|
||||||
* \param renderOrder Render order of the element
|
|
||||||
*/
|
|
||||||
|
|
||||||
inline void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, int renderOrder)
|
|
||||||
{
|
|
||||||
return Attach(renderable, Nz::Matrix4f::Identity(), renderOrder);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder)
|
|
||||||
{
|
|
||||||
m_renderables.emplace_back(m_transformMatrix);
|
|
||||||
Renderable& r = m_renderables.back();
|
|
||||||
r.data.localMatrix = localMatrix;
|
|
||||||
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));
|
|
||||||
r.renderableReleaseSlot.Connect(r.renderable->OnInstancedRenderableRelease, this, &GraphicsComponent::Detach);
|
|
||||||
|
|
||||||
InvalidateBoundingVolume();
|
InvalidateBoundingVolume();
|
||||||
}
|
}
|
||||||
|
|
@ -167,11 +127,26 @@ namespace Ndk
|
||||||
return m_boundingVolume;
|
return m_boundingVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void GraphicsComponent::RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const
|
||||||
|
{
|
||||||
|
for (auto it = m_volumeCullingEntries.begin(); it != m_volumeCullingEntries.end(); ++it)
|
||||||
|
{
|
||||||
|
if (it->listEntry.GetParent() == cullingList)
|
||||||
|
{
|
||||||
|
if (m_volumeCullingEntries.size() > 1)
|
||||||
|
*it = std::move(m_volumeCullingEntries.back());
|
||||||
|
|
||||||
|
m_volumeCullingEntries.pop_back();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Invalidates the bounding volume
|
* \brief Invalidates the bounding volume
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline void GraphicsComponent::InvalidateBoundingVolume()
|
inline void GraphicsComponent::InvalidateBoundingVolume() const
|
||||||
{
|
{
|
||||||
m_boundingVolumeUpdated = false;
|
m_boundingVolumeUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
@ -192,9 +167,9 @@ namespace Ndk
|
||||||
|
|
||||||
inline void GraphicsComponent::InvalidateTransformMatrix()
|
inline void GraphicsComponent::InvalidateTransformMatrix()
|
||||||
{
|
{
|
||||||
m_boundingVolumeUpdated = false;
|
|
||||||
m_transformMatrixUpdated = false;
|
m_transformMatrixUpdated = false;
|
||||||
|
|
||||||
|
InvalidateBoundingVolume();
|
||||||
InvalidateRenderables();
|
InvalidateRenderables();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
#ifndef NDK_CONSOLE_HPP
|
#ifndef NDK_CONSOLE_HPP
|
||||||
#define NDK_CONSOLE_HPP
|
#define NDK_CONSOLE_HPP
|
||||||
|
|
||||||
|
|
@ -99,3 +100,4 @@ namespace Ndk
|
||||||
#include <NDK/Console.inl>
|
#include <NDK/Console.inl>
|
||||||
|
|
||||||
#endif // NDK_CONSOLE_HPP
|
#endif // NDK_CONSOLE_HPP
|
||||||
|
#endif // NDK_SERVER
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_HPP
|
||||||
|
#define NDK_LUABINDING_HPP
|
||||||
|
|
||||||
|
#include <NDK/BaseComponent.hpp>
|
||||||
|
#include <NDK/Entity.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding
|
||||||
|
{
|
||||||
|
friend class LuaBinding_SDK;
|
||||||
|
|
||||||
|
public:
|
||||||
|
LuaBinding();
|
||||||
|
~LuaBinding() = default;
|
||||||
|
|
||||||
|
template<typename T> void BindComponent(const Nz::String& name);
|
||||||
|
|
||||||
|
void RegisterClasses(Nz::LuaInstance& instance);
|
||||||
|
|
||||||
|
std::unique_ptr<LuaBinding_Base> core;
|
||||||
|
std::unique_ptr<LuaBinding_Base> math;
|
||||||
|
std::unique_ptr<LuaBinding_Base> network;
|
||||||
|
std::unique_ptr<LuaBinding_Base> sdk;
|
||||||
|
std::unique_ptr<LuaBinding_Base> utility;
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
std::unique_ptr<LuaBinding_Base> audio;
|
||||||
|
std::unique_ptr<LuaBinding_Base> graphics;
|
||||||
|
std::unique_ptr<LuaBinding_Base> renderer;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename T>
|
||||||
|
static int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component);
|
||||||
|
|
||||||
|
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
||||||
|
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
||||||
|
|
||||||
|
struct ComponentBinding
|
||||||
|
{
|
||||||
|
AddComponentFunc adder;
|
||||||
|
ComponentIndex index;
|
||||||
|
GetComponentFunc getter;
|
||||||
|
Nz::String name;
|
||||||
|
};
|
||||||
|
|
||||||
|
ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 2);
|
||||||
|
|
||||||
|
std::vector<ComponentBinding> m_componentBinding;
|
||||||
|
std::unordered_map<Nz::String, ComponentIndex> m_componentBindingByName;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding.inl>
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_HPP
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// This file is part of the "Nazara Development Kit"
|
// This file is part of the "Nazara Development Kit"
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
|
|
@ -32,18 +32,8 @@ namespace Ndk
|
||||||
m_componentBindingByName[name] = T::componentIndex;
|
m_componentBindingByName[name] = T::componentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Adds a component to an entity
|
|
||||||
* \return 1 in case of success
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the component
|
|
||||||
* \param handle Entity which component will be added to
|
|
||||||
*
|
|
||||||
* \remark T must be a subtype of BaseComponent
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
int LuaBinding::AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
|
||||||
{
|
{
|
||||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||||
|
|
||||||
|
|
@ -52,18 +42,8 @@ namespace Ndk
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Pushes a component
|
|
||||||
* \return 1 in case of success
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the component
|
|
||||||
* \param component Component that will be pushed
|
|
||||||
*
|
|
||||||
* \remark T must be a subtype of BaseComponent
|
|
||||||
*/
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
int LuaBinding::PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
|
||||||
{
|
{
|
||||||
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
|
||||||
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_AUDIO_HPP
|
||||||
|
#define NDK_LUABINDING_AUDIO_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Audio/Music.hpp>
|
||||||
|
#include <Nazara/Audio/Sound.hpp>
|
||||||
|
#include <Nazara/Audio/SoundBuffer.hpp>
|
||||||
|
#include <Nazara/Audio/SoundEmitter.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Audio : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Audio(LuaBinding& binding);
|
||||||
|
~LuaBinding_Audio() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::Music> music;
|
||||||
|
Nz::LuaClass<Nz::Sound> sound;
|
||||||
|
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
||||||
|
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_CORE_HPP
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_BASE_HPP
|
||||||
|
#define NDK_LUABINDING_BASE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Lua/LuaClass.hpp>
|
||||||
|
#include <Nazara/Lua/LuaInstance.hpp>
|
||||||
|
#include <NDK/Prerequesites.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class LuaBinding;
|
||||||
|
|
||||||
|
class LuaBinding_Audio;
|
||||||
|
class LuaBinding_Core;
|
||||||
|
class LuaBinding_Graphics;
|
||||||
|
class LuaBinding_Math;
|
||||||
|
class LuaBinding_Network;
|
||||||
|
class LuaBinding_Renderer;
|
||||||
|
class LuaBinding_SDK;
|
||||||
|
class LuaBinding_Utility;
|
||||||
|
|
||||||
|
class NDK_API LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Base(LuaBinding& binding);
|
||||||
|
virtual ~LuaBinding_Base();
|
||||||
|
|
||||||
|
virtual void Register(Nz::LuaInstance& instance) = 0;
|
||||||
|
|
||||||
|
// Implementation lies in the respective .cpp files (still searching for a cleaner way..)
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindCore(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindMath(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindNetwork(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindSDK(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindUtility(LuaBinding& binding);
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindAudio(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindGraphics(LuaBinding& binding);
|
||||||
|
static std::unique_ptr<LuaBinding_Base> BindRenderer(LuaBinding& binding);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
LuaBinding& m_binding;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_BASE_HPP
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_CORE_HPP
|
||||||
|
#define NDK_LUABINDING_CORE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Clock.hpp>
|
||||||
|
#include <Nazara/Core/Directory.hpp>
|
||||||
|
#include <Nazara/Core/File.hpp>
|
||||||
|
#include <Nazara/Core/Stream.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Core : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Core(LuaBinding& binding);
|
||||||
|
~LuaBinding_Core() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::Clock> clock;
|
||||||
|
Nz::LuaClass<Nz::Directory> directory;
|
||||||
|
Nz::LuaClass<Nz::File> file;
|
||||||
|
Nz::LuaClass<Nz::Stream> stream;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_CORE_HPP
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_GRAPHICS_HPP
|
||||||
|
#define NDK_LUABINDING_GRAPHICS_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||||
|
#include <Nazara/Graphics/InstancedRenderable.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Graphics : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Graphics(LuaBinding& binding);
|
||||||
|
~LuaBinding_Graphics() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::AbstractViewer> abstractViewer;
|
||||||
|
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
||||||
|
Nz::LuaClass<Nz::MaterialRef> material;
|
||||||
|
Nz::LuaClass<Nz::ModelRef> model;
|
||||||
|
Nz::LuaClass<Nz::SpriteRef> sprite;
|
||||||
|
Nz::LuaClass<Nz::SpriteLibrary> spriteLibrary;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_GRAPHICS_HPP
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_MATH_HPP
|
||||||
|
#define NDK_LUABINDING_MATH_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Math/EulerAngles.hpp>
|
||||||
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
|
#include <Nazara/Math/Quaternion.hpp>
|
||||||
|
#include <Nazara/Math/Rect.hpp>
|
||||||
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
|
#include <Nazara/Math/Vector3.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Math : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Math(LuaBinding& binding);
|
||||||
|
~LuaBinding_Math() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::EulerAnglesd> eulerAngles;
|
||||||
|
Nz::LuaClass<Nz::Matrix4d> matrix4d;
|
||||||
|
Nz::LuaClass<Nz::Quaterniond> quaternion;
|
||||||
|
Nz::LuaClass<Nz::Rectd> rect;
|
||||||
|
Nz::LuaClass<Nz::Vector2d> vector2d;
|
||||||
|
Nz::LuaClass<Nz::Vector3d> vector3d;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_MATH_HPP
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_NETWORK_HPP
|
||||||
|
#define NDK_LUABINDING_NETWORK_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Network/AbstractSocket.hpp>
|
||||||
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Network : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Network(LuaBinding& binding);
|
||||||
|
~LuaBinding_Network() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::AbstractSocket> abstractSocket;
|
||||||
|
Nz::LuaClass<Nz::IpAddress> ipAddress;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_NETWORK_HPP
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_RENDERER_HPP
|
||||||
|
#define NDK_LUABINDING_RENDERER_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/Texture.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Renderer : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Renderer(LuaBinding& binding);
|
||||||
|
~LuaBinding_Renderer() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Nz::TextureRef> texture;
|
||||||
|
Nz::LuaClass<Nz::TextureLibrary> textureLibrary;
|
||||||
|
Nz::LuaClass<Nz::TextureManager> textureManager;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_RENDERER_HPP
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_SDK_HPP
|
||||||
|
#define NDK_LUABINDING_SDK_HPP
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/Console.hpp>
|
||||||
|
#include <NDK/Entity.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class Application;
|
||||||
|
|
||||||
|
class NDK_API LuaBinding_SDK : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_SDK(LuaBinding& binding);
|
||||||
|
~LuaBinding_SDK() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
Nz::LuaClass<Application*> application;
|
||||||
|
Nz::LuaClass<EntityHandle> entity;
|
||||||
|
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
||||||
|
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
||||||
|
Nz::LuaClass<WorldHandle> world;
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
Nz::LuaClass<CameraComponentHandle> cameraComponent;
|
||||||
|
Nz::LuaClass<ConsoleHandle> console;
|
||||||
|
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_SDK_HPP
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_LUABINDING_UTILITY_HPP
|
||||||
|
#define NDK_LUABINDING_UTILITY_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Utility/AbstractImage.hpp>
|
||||||
|
#include <Nazara/Utility/Font.hpp>
|
||||||
|
#include <Nazara/Utility/Keyboard.hpp>
|
||||||
|
#include <Nazara/Utility/Node.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class NDK_API LuaBinding_Utility : public LuaBinding_Base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LuaBinding_Utility(LuaBinding& binding);
|
||||||
|
~LuaBinding_Utility() = default;
|
||||||
|
|
||||||
|
void Register(Nz::LuaInstance& instance) override;
|
||||||
|
|
||||||
|
// Utility
|
||||||
|
Nz::LuaClass<Nz::AbstractImageRef> abstractImage;
|
||||||
|
Nz::LuaClass<Nz::FontRef> font;
|
||||||
|
Nz::LuaClass<Nz::Keyboard> keyboard;
|
||||||
|
Nz::LuaClass<Nz::Node> node;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NDK_LUABINDING_UTILITY_HPP
|
||||||
|
|
@ -156,9 +156,10 @@ namespace Nz
|
||||||
|
|
||||||
params->animated = instance.CheckField<bool>("Animated", params->animated);
|
params->animated = instance.CheckField<bool>("Animated", params->animated);
|
||||||
params->center = instance.CheckField<bool>("Center", params->center);
|
params->center = instance.CheckField<bool>("Center", params->center);
|
||||||
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
|
|
||||||
params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
|
params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
|
||||||
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
|
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
|
||||||
|
params->texCoordOffset = instance.CheckField<Vector2f>("TexCoordOffset", params->texCoordOffset);
|
||||||
|
params->texCoordScale = instance.CheckField<Vector2f>("TexCoordScale", params->texCoordScale);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -403,7 +404,6 @@ namespace Nz
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline int LuaImplReplyVal(const LuaInstance& instance, Color&& val, TypeTag<Color>)
|
inline int LuaImplReplyVal(const LuaInstance& instance, Color&& val, TypeTag<Color>)
|
||||||
|
|
|
||||||
|
|
@ -1,147 +0,0 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
|
||||||
// This file is part of the "Nazara Development Kit"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef NDK_LUABINDING_HPP
|
|
||||||
#define NDK_LUABINDING_HPP
|
|
||||||
|
|
||||||
#include <Nazara/Core.hpp>
|
|
||||||
#include <Nazara/Lua.hpp>
|
|
||||||
#include <Nazara/Math.hpp>
|
|
||||||
#include <Nazara/Network.hpp>
|
|
||||||
#include <Nazara/Utility.hpp>
|
|
||||||
#include <NDK/Application.hpp>
|
|
||||||
#include <NDK/Components.hpp>
|
|
||||||
#include <NDK/Entity.hpp>
|
|
||||||
#include <NDK/Systems.hpp>
|
|
||||||
#include <NDK/World.hpp>
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
#include <Nazara/Audio.hpp>
|
|
||||||
#include <Nazara/Graphics.hpp>
|
|
||||||
#include <Nazara/Renderer.hpp>
|
|
||||||
#include <NDK/Console.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
class NDK_API LuaBinding
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LuaBinding();
|
|
||||||
~LuaBinding() = default;
|
|
||||||
|
|
||||||
template<typename T> void BindComponent(const Nz::String& name);
|
|
||||||
|
|
||||||
void RegisterClasses(Nz::LuaInstance& instance);
|
|
||||||
|
|
||||||
// Core
|
|
||||||
Nz::LuaClass<Nz::Clock> clock;
|
|
||||||
Nz::LuaClass<Nz::Directory> directory;
|
|
||||||
Nz::LuaClass<Nz::File> file;
|
|
||||||
Nz::LuaClass<Nz::Stream> stream;
|
|
||||||
|
|
||||||
// Math
|
|
||||||
Nz::LuaClass<Nz::EulerAnglesd> eulerAngles;
|
|
||||||
Nz::LuaClass<Nz::Matrix4d> matrix4d;
|
|
||||||
Nz::LuaClass<Nz::Quaterniond> quaternion;
|
|
||||||
Nz::LuaClass<Nz::Rectd> rect;
|
|
||||||
Nz::LuaClass<Nz::Vector2d> vector2d;
|
|
||||||
Nz::LuaClass<Nz::Vector3d> vector3d;
|
|
||||||
|
|
||||||
// Network
|
|
||||||
Nz::LuaClass<Nz::AbstractSocket> abstractSocket;
|
|
||||||
Nz::LuaClass<Nz::IpAddress> ipAddress;
|
|
||||||
|
|
||||||
// Utility
|
|
||||||
Nz::LuaClass<Nz::AbstractImageRef> abstractImage;
|
|
||||||
Nz::LuaClass<Nz::FontRef> font;
|
|
||||||
Nz::LuaClass<Nz::Keyboard> keyboard;
|
|
||||||
Nz::LuaClass<Nz::Node> node;
|
|
||||||
|
|
||||||
// SDK
|
|
||||||
Nz::LuaClass<Application*> application;
|
|
||||||
Nz::LuaClass<EntityHandle> entity;
|
|
||||||
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
|
||||||
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
|
||||||
Nz::LuaClass<WorldHandle> world;
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
// Audio
|
|
||||||
Nz::LuaClass<Nz::Music> music;
|
|
||||||
Nz::LuaClass<Nz::Sound> sound;
|
|
||||||
Nz::LuaClass<Nz::SoundBufferRef> soundBuffer;
|
|
||||||
Nz::LuaClass<Nz::SoundEmitter> soundEmitter;
|
|
||||||
|
|
||||||
// Graphics
|
|
||||||
Nz::LuaClass<Nz::AbstractViewer> abstractViewer;
|
|
||||||
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;
|
|
||||||
Nz::LuaClass<Nz::MaterialRef> material;
|
|
||||||
Nz::LuaClass<Nz::ModelRef> model;
|
|
||||||
Nz::LuaClass<Nz::SpriteRef> sprite;
|
|
||||||
Nz::LuaClass<Nz::SpriteLibrary> spriteLibrary;
|
|
||||||
Nz::LuaClass<Nz::TextureLibrary> textureLibrary;
|
|
||||||
Nz::LuaClass<Nz::TextureManager> textureManager;
|
|
||||||
|
|
||||||
// Renderer
|
|
||||||
Nz::LuaClass<Nz::TextureRef> texture;
|
|
||||||
|
|
||||||
// SDK
|
|
||||||
Nz::LuaClass<CameraComponentHandle> cameraComponent;
|
|
||||||
Nz::LuaClass<ConsoleHandle> console;
|
|
||||||
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
void BindCore();
|
|
||||||
void BindMath();
|
|
||||||
void BindNetwork();
|
|
||||||
void BindSDK();
|
|
||||||
void BindUtility();
|
|
||||||
|
|
||||||
void RegisterCore(Nz::LuaInstance& instance);
|
|
||||||
void RegisterMath(Nz::LuaInstance& instance);
|
|
||||||
void RegisterNetwork(Nz::LuaInstance& instance);
|
|
||||||
void RegisterSDK(Nz::LuaInstance& instance);
|
|
||||||
void RegisterUtility(Nz::LuaInstance& instance);
|
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
|
||||||
void BindAudio();
|
|
||||||
void BindGraphics();
|
|
||||||
void BindRenderer();
|
|
||||||
|
|
||||||
void RegisterAudio(Nz::LuaInstance& instance);
|
|
||||||
void RegisterGraphics(Nz::LuaInstance& instance);
|
|
||||||
void RegisterRenderer(Nz::LuaInstance& instance);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
|
||||||
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
|
|
||||||
|
|
||||||
struct ComponentBinding
|
|
||||||
{
|
|
||||||
AddComponentFunc adder;
|
|
||||||
ComponentIndex index;
|
|
||||||
GetComponentFunc getter;
|
|
||||||
Nz::String name;
|
|
||||||
};
|
|
||||||
|
|
||||||
ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 2);
|
|
||||||
|
|
||||||
std::vector<ComponentBinding> m_componentBinding;
|
|
||||||
std::unordered_map<Nz::String, ComponentIndex> m_componentBindingByName;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component);
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.inl>
|
|
||||||
|
|
||||||
#endif // NDK_LUABINDING_HPP
|
|
||||||
|
|
@ -9,9 +9,11 @@
|
||||||
#define NDK_SYSTEMS_RENDERSYSTEM_HPP
|
#define NDK_SYSTEMS_RENDERSYSTEM_HPP
|
||||||
|
|
||||||
#include <Nazara/Graphics/AbstractBackground.hpp>
|
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||||
|
#include <Nazara/Graphics/CullingList.hpp>
|
||||||
#include <Nazara/Graphics/DepthRenderTechnique.hpp>
|
#include <Nazara/Graphics/DepthRenderTechnique.hpp>
|
||||||
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
|
||||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||||
|
#include <NDK/Components/GraphicsComponent.hpp>
|
||||||
#include <NDK/EntityList.hpp>
|
#include <NDK/EntityList.hpp>
|
||||||
#include <NDK/System.hpp>
|
#include <NDK/System.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
@ -19,8 +21,6 @@
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
class GraphicsComponent;
|
|
||||||
|
|
||||||
class NDK_API RenderSystem : public System<RenderSystem>
|
class NDK_API RenderSystem : public System<RenderSystem>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -51,21 +51,25 @@ namespace Ndk
|
||||||
void OnEntityRemoved(Entity* entity) override;
|
void OnEntityRemoved(Entity* entity) override;
|
||||||
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
void OnEntityValidation(Entity* entity, bool justAdded) override;
|
||||||
void OnUpdate(float elapsedTime) override;
|
void OnUpdate(float elapsedTime) override;
|
||||||
|
|
||||||
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
|
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
|
||||||
void UpdatePointSpotShadowMaps();
|
void UpdatePointSpotShadowMaps();
|
||||||
|
|
||||||
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
|
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
|
||||||
|
std::vector<GraphicsComponentCullingList::VolumeEntry> m_volumeEntries;
|
||||||
EntityList m_cameras;
|
EntityList m_cameras;
|
||||||
EntityList m_drawables;
|
EntityList m_drawables;
|
||||||
EntityList m_directionalLights;
|
EntityList m_directionalLights;
|
||||||
EntityList m_lights;
|
EntityList m_lights;
|
||||||
EntityList m_pointSpotLights;
|
EntityList m_pointSpotLights;
|
||||||
EntityList m_particleGroups;
|
EntityList m_particleGroups;
|
||||||
|
GraphicsComponentCullingList m_drawableCulling;
|
||||||
Nz::BackgroundRef m_background;
|
Nz::BackgroundRef m_background;
|
||||||
Nz::DepthRenderTechnique m_shadowTechnique;
|
Nz::DepthRenderTechnique m_shadowTechnique;
|
||||||
Nz::Matrix4f m_coordinateSystemMatrix;
|
Nz::Matrix4f m_coordinateSystemMatrix;
|
||||||
Nz::RenderTexture m_shadowRT;
|
Nz::RenderTexture m_shadowRT;
|
||||||
bool m_coordinateSystemInvalidated;
|
bool m_coordinateSystemInvalidated;
|
||||||
|
bool m_forceRenderQueueInvalidation;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
// This file was automatically generated
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NDK_WIDGETS_GLOBAL_HPP
|
||||||
|
#define NDK_WIDGETS_GLOBAL_HPP
|
||||||
|
|
||||||
|
#include <NDK/Widgets/ButtonWidget.hpp>
|
||||||
|
#include <NDK/Widgets/LabelWidget.hpp>
|
||||||
|
#include <NDK/Widgets/TextAreaWidget.hpp>
|
||||||
|
|
||||||
|
#endif // NDK_WIDGETS_GLOBAL_HPP
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
// 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_WIDGETS_BUTTONWIDGET_HPP
|
||||||
|
#define NDK_WIDGETS_BUTTONWIDGET_HPP
|
||||||
|
|
||||||
|
#include <NDK/Prerequesites.hpp>
|
||||||
|
#include <NDK/BaseWidget.hpp>
|
||||||
|
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||||
|
#include <Nazara/Graphics/Sprite.hpp>
|
||||||
|
#include <Nazara/Graphics/TextSprite.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class World;
|
||||||
|
|
||||||
|
class NDK_API ButtonWidget : public BaseWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ButtonWidget(BaseWidget* parent = nullptr);
|
||||||
|
ButtonWidget(const ButtonWidget&) = delete;
|
||||||
|
ButtonWidget(ButtonWidget&&) = default;
|
||||||
|
~ButtonWidget() = default;
|
||||||
|
|
||||||
|
//virtual ButtonWidget* Clone() const = 0;
|
||||||
|
|
||||||
|
void ResizeToContent();
|
||||||
|
|
||||||
|
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
||||||
|
|
||||||
|
ButtonWidget& operator=(const ButtonWidget&) = delete;
|
||||||
|
ButtonWidget& operator=(ButtonWidget&&) = default;
|
||||||
|
|
||||||
|
NazaraSignal(OnButtonTrigger, const ButtonWidget* /*button*/);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Layout() override;
|
||||||
|
|
||||||
|
void OnMouseEnter() override;
|
||||||
|
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
||||||
|
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
|
||||||
|
void OnMouseExit() override;
|
||||||
|
|
||||||
|
EntityHandle m_textEntity;
|
||||||
|
EntityHandle m_gradientEntity;
|
||||||
|
Nz::SpriteRef m_gradientSprite;
|
||||||
|
Nz::TextSpriteRef m_textSprite;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <NDK/Widgets/ButtonWidget.inl>
|
||||||
|
|
||||||
|
#endif // NDK_WIDGETS_BUTTONWIDGET_HPP
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
// 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/Widgets/ButtonWidget.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
inline void ButtonWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
|
||||||
|
{
|
||||||
|
m_textSprite->Update(drawer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
// 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_WIDGETS_LABELWIDGET_HPP
|
||||||
|
#define NDK_WIDGETS_LABELWIDGET_HPP
|
||||||
|
|
||||||
|
#include <NDK/Prerequesites.hpp>
|
||||||
|
#include <NDK/BaseWidget.hpp>
|
||||||
|
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||||
|
#include <Nazara/Graphics/TextSprite.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class World;
|
||||||
|
|
||||||
|
class NDK_API LabelWidget : public BaseWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LabelWidget(BaseWidget* parent = nullptr);
|
||||||
|
LabelWidget(const LabelWidget&) = delete;
|
||||||
|
LabelWidget(LabelWidget&&) = default;
|
||||||
|
~LabelWidget() = default;
|
||||||
|
|
||||||
|
//virtual LabelWidget* Clone() const = 0;
|
||||||
|
|
||||||
|
void ResizeToContent();
|
||||||
|
|
||||||
|
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
||||||
|
|
||||||
|
LabelWidget& operator=(const LabelWidget&) = delete;
|
||||||
|
LabelWidget& operator=(LabelWidget&&) = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
EntityHandle m_textEntity;
|
||||||
|
Nz::TextSpriteRef m_textSprite;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <NDK/Widgets/LabelWidget.inl>
|
||||||
|
|
||||||
|
#endif // NDK_WIDGETS_LABELWIDGET_HPP
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
// 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/Widgets/LabelWidget.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
inline void LabelWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
|
||||||
|
{
|
||||||
|
m_textSprite->Update(drawer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
// 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_WIDGETS_TEXTAREAWIDGET_HPP
|
||||||
|
#define NDK_WIDGETS_TEXTAREAWIDGET_HPP
|
||||||
|
|
||||||
|
#include <NDK/Prerequesites.hpp>
|
||||||
|
#include <NDK/BaseWidget.hpp>
|
||||||
|
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||||
|
#include <Nazara/Graphics/TextSprite.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
class World;
|
||||||
|
|
||||||
|
class NDK_API TextAreaWidget : public BaseWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextAreaWidget(BaseWidget* parent = nullptr);
|
||||||
|
TextAreaWidget(const TextAreaWidget&) = delete;
|
||||||
|
TextAreaWidget(TextAreaWidget&&) = default;
|
||||||
|
~TextAreaWidget() = default;
|
||||||
|
|
||||||
|
void AppendText(const Nz::String& text);
|
||||||
|
|
||||||
|
inline void Clear();
|
||||||
|
|
||||||
|
//virtual TextAreaWidget* Clone() const = 0;
|
||||||
|
|
||||||
|
inline void EnableMultiline(bool enable = true);
|
||||||
|
|
||||||
|
inline std::size_t GetCursorPosition() const;
|
||||||
|
inline std::size_t GetLineCount() const;
|
||||||
|
inline const Nz::String& GetText() const;
|
||||||
|
|
||||||
|
std::size_t GetHoveredGlyph(float x, float y) const;
|
||||||
|
|
||||||
|
inline bool IsMultilineEnabled() const;
|
||||||
|
inline bool IsReadOnly() const;
|
||||||
|
|
||||||
|
inline void MoveCursor(int offset);
|
||||||
|
|
||||||
|
void ResizeToContent() override;
|
||||||
|
|
||||||
|
inline void SetCursorPosition(std::size_t cursorPosition);
|
||||||
|
inline void SetReadOnly(bool readOnly = true);
|
||||||
|
void SetText(const Nz::String& text);
|
||||||
|
|
||||||
|
void Write(const Nz::String& text);
|
||||||
|
|
||||||
|
TextAreaWidget& operator=(const TextAreaWidget&) = delete;
|
||||||
|
TextAreaWidget& operator=(TextAreaWidget&&) = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void RefreshCursor();
|
||||||
|
|
||||||
|
void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
|
||||||
|
void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key) override;
|
||||||
|
void OnMouseEnter() override;
|
||||||
|
void OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button) override;
|
||||||
|
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
||||||
|
void OnMouseExit() override;
|
||||||
|
void OnTextEntered(char32_t character, bool repeated) override;
|
||||||
|
|
||||||
|
EntityHandle m_cursorEntity;
|
||||||
|
EntityHandle m_textEntity;
|
||||||
|
Nz::SimpleTextDrawer m_drawer;
|
||||||
|
Nz::SpriteRef m_cursorSprite;
|
||||||
|
Nz::TextSpriteRef m_textSprite;
|
||||||
|
std::size_t m_cursorPosition;
|
||||||
|
bool m_multiLineEnabled;
|
||||||
|
bool m_readOnly;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <NDK/Widgets/TextAreaWidget.inl>
|
||||||
|
|
||||||
|
#endif // NDK_WIDGETS_TEXTAREAWIDGET_HPP
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
// 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/Widgets/TextAreaWidget.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
inline void TextAreaWidget::Clear()
|
||||||
|
{
|
||||||
|
m_cursorPosition = 0;
|
||||||
|
m_drawer.Clear();
|
||||||
|
m_textSprite->Update(m_drawer);
|
||||||
|
|
||||||
|
RefreshCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void TextAreaWidget::EnableMultiline(bool enable)
|
||||||
|
{
|
||||||
|
m_multiLineEnabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t TextAreaWidget::GetCursorPosition() const
|
||||||
|
{
|
||||||
|
return m_cursorPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::size_t TextAreaWidget::GetLineCount() const
|
||||||
|
{
|
||||||
|
return m_drawer.GetLineCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const Nz::String& TextAreaWidget::GetText() const
|
||||||
|
{
|
||||||
|
return m_drawer.GetText();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Ndk::TextAreaWidget::IsMultilineEnabled() const
|
||||||
|
{
|
||||||
|
return m_multiLineEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool TextAreaWidget::IsReadOnly() const
|
||||||
|
{
|
||||||
|
return m_readOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void TextAreaWidget::MoveCursor(int offset)
|
||||||
|
{
|
||||||
|
if (offset >= 0)
|
||||||
|
SetCursorPosition(m_cursorPosition += static_cast<std::size_t>(offset));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::size_t nOffset = static_cast<std::size_t>(-offset);
|
||||||
|
if (nOffset >= m_cursorPosition)
|
||||||
|
SetCursorPosition(0);
|
||||||
|
else
|
||||||
|
SetCursorPosition(m_cursorPosition - nOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void TextAreaWidget::SetCursorPosition(std::size_t cursorPosition)
|
||||||
|
{
|
||||||
|
m_cursorPosition = std::min(cursorPosition, m_drawer.GetGlyphCount());
|
||||||
|
|
||||||
|
RefreshCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void TextAreaWidget::SetReadOnly(bool readOnly)
|
||||||
|
{
|
||||||
|
m_readOnly = readOnly;
|
||||||
|
|
||||||
|
m_cursorEntity->Enable(!m_readOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,132 @@
|
||||||
|
// 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/BaseWidget.hpp>
|
||||||
|
#include <NDK/Canvas.hpp>
|
||||||
|
#include <NDK/Components/GraphicsComponent.hpp>
|
||||||
|
#include <NDK/Components/NodeComponent.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
BaseWidget::BaseWidget(BaseWidget* parent) :
|
||||||
|
BaseWidget()
|
||||||
|
{
|
||||||
|
NazaraAssert(parent, "Invalid parent");
|
||||||
|
NazaraAssert(parent->GetCanvas(), "Parent has no canvas");
|
||||||
|
|
||||||
|
m_canvas = parent->GetCanvas();
|
||||||
|
m_widgetParent = parent;
|
||||||
|
m_world = m_canvas->GetWorld();
|
||||||
|
|
||||||
|
m_canvasIndex = m_canvas->RegisterWidget(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseWidget::~BaseWidget()
|
||||||
|
{
|
||||||
|
m_canvas->UnregisterWidget(m_canvasIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void BaseWidget::EnableBackground(bool enable)
|
||||||
|
{
|
||||||
|
if (m_backgroundEntity.IsValid() == enable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
m_backgroundSprite = Nz::Sprite::New();
|
||||||
|
m_backgroundSprite->SetColor(m_backgroundColor);
|
||||||
|
m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D"));
|
||||||
|
|
||||||
|
m_backgroundEntity = m_world->CreateEntity();
|
||||||
|
m_backgroundEntity->AddComponent<GraphicsComponent>().Attach(m_backgroundSprite, -1);
|
||||||
|
m_backgroundEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||||
|
|
||||||
|
BaseWidget::Layout(); // Only layout background
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_backgroundEntity->Kill();
|
||||||
|
m_backgroundSprite.Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::SetSize(const Nz::Vector2f& size)
|
||||||
|
{
|
||||||
|
SetContentSize({std::max(size.x - m_padding.left - m_padding.right, 0.f), std::max(size.y - m_padding.top - m_padding.bottom, 0.f)});
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityHandle BaseWidget::CreateEntity()
|
||||||
|
{
|
||||||
|
m_entities.emplace_back(m_world->CreateEntity());
|
||||||
|
return m_entities.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::DestroyEntity(Entity* entity)
|
||||||
|
{
|
||||||
|
auto it = std::find(m_entities.begin(), m_entities.end(), entity);
|
||||||
|
NazaraAssert(it != m_entities.end(), "Entity does not belong to this widget");
|
||||||
|
|
||||||
|
m_entities.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::GrabKeyboard()
|
||||||
|
{
|
||||||
|
m_canvas->SetKeyboardOwner(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::Layout()
|
||||||
|
{
|
||||||
|
if (m_canvas)
|
||||||
|
m_canvas->NotifyWidgetUpdate(m_canvasIndex);
|
||||||
|
|
||||||
|
if (m_backgroundEntity)
|
||||||
|
{
|
||||||
|
NodeComponent& node = m_backgroundEntity->GetComponent<NodeComponent>();
|
||||||
|
node.SetPosition(-m_padding.left, -m_padding.top);
|
||||||
|
|
||||||
|
m_backgroundSprite->SetSize(m_contentSize.x + m_padding.left + m_padding.right, m_contentSize.y + m_padding.top + m_padding.bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::InvalidateNode()
|
||||||
|
{
|
||||||
|
Node::InvalidateNode();
|
||||||
|
|
||||||
|
if (m_canvas)
|
||||||
|
m_canvas->NotifyWidgetUpdate(m_canvasIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnMouseEnter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnMouseButtonPress(int x, int y, Nz::Mouse::Button button)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnMouseExit()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseWidget::OnTextEntered(char32_t character, bool repeated)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,160 @@
|
||||||
|
// 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/Canvas.hpp>
|
||||||
|
#include <NDK/Components/GraphicsComponent.hpp>
|
||||||
|
#include <NDK/Components/NodeComponent.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
void Canvas::ResizeToContent()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::Layout()
|
||||||
|
{
|
||||||
|
if (m_backgroundEntity)
|
||||||
|
{
|
||||||
|
NodeComponent& node = m_backgroundEntity->GetComponent<NodeComponent>();
|
||||||
|
node.SetPosition(-m_padding.left, -m_padding.top);
|
||||||
|
|
||||||
|
m_backgroundSprite->SetSize(m_contentSize.x + m_padding.left + m_padding.right, m_contentSize.y + m_padding.top + m_padding.bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::NotifyWidgetUpdate(std::size_t index)
|
||||||
|
{
|
||||||
|
WidgetBox& entry = m_widgetBoxes[index];
|
||||||
|
|
||||||
|
Nz::Vector3f pos = entry.widget->GetPosition();
|
||||||
|
Nz::Vector2f size = entry.widget->GetContentSize();
|
||||||
|
|
||||||
|
entry.box.Set(pos.x, pos.y, pos.z, size.x, size.y, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t Canvas::RegisterWidget(BaseWidget* widget)
|
||||||
|
{
|
||||||
|
WidgetBox box;
|
||||||
|
box.widget = widget;
|
||||||
|
|
||||||
|
std::size_t index = m_widgetBoxes.size();
|
||||||
|
m_widgetBoxes.emplace_back(box);
|
||||||
|
|
||||||
|
NotifyWidgetUpdate(index);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::UnregisterWidget(std::size_t index)
|
||||||
|
{
|
||||||
|
if (m_widgetBoxes.size() > 1U)
|
||||||
|
{
|
||||||
|
WidgetBox& entry = m_widgetBoxes[index];
|
||||||
|
WidgetBox& lastEntry = m_widgetBoxes.back();
|
||||||
|
|
||||||
|
if (m_hoveredWidget == &entry)
|
||||||
|
m_hoveredWidget = nullptr;
|
||||||
|
|
||||||
|
if (m_keyboardOwner == entry.widget)
|
||||||
|
m_keyboardOwner = nullptr;
|
||||||
|
|
||||||
|
entry = std::move(lastEntry);
|
||||||
|
entry.widget->UpdateCanvasIndex(index);
|
||||||
|
m_widgetBoxes.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::OnMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event)
|
||||||
|
{
|
||||||
|
if (m_hoveredWidget)
|
||||||
|
{
|
||||||
|
int x = static_cast<int>(std::round(event.x - m_hoveredWidget->box.x));
|
||||||
|
int y = static_cast<int>(std::round(event.y - m_hoveredWidget->box.y));
|
||||||
|
|
||||||
|
m_hoveredWidget->widget->OnMouseButtonPress(x, y, event.button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::OnMouseButtonRelease(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent & event)
|
||||||
|
{
|
||||||
|
if (m_hoveredWidget)
|
||||||
|
{
|
||||||
|
int x = static_cast<int>(std::round(event.x - m_hoveredWidget->box.x));
|
||||||
|
int y = static_cast<int>(std::round(event.y - m_hoveredWidget->box.y));
|
||||||
|
|
||||||
|
m_hoveredWidget->widget->OnMouseButtonRelease(x, y, event.button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::OnMouseMoved(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||||
|
{
|
||||||
|
const WidgetBox* bestEntry = nullptr;
|
||||||
|
float bestEntryArea = std::numeric_limits<float>::infinity();
|
||||||
|
|
||||||
|
for (const WidgetBox& entry : m_widgetBoxes)
|
||||||
|
{
|
||||||
|
const Nz::Boxf& box = entry.box;
|
||||||
|
|
||||||
|
if (box.Contains(Nz::Vector3f(event.x, event.y, 0.f)))
|
||||||
|
{
|
||||||
|
float area = box.width * box.height;
|
||||||
|
if (area < bestEntryArea)
|
||||||
|
{
|
||||||
|
bestEntry = &entry;
|
||||||
|
bestEntryArea = area;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bestEntry)
|
||||||
|
{
|
||||||
|
if (m_hoveredWidget != bestEntry)
|
||||||
|
{
|
||||||
|
if (m_hoveredWidget)
|
||||||
|
m_hoveredWidget->widget->OnMouseExit();
|
||||||
|
|
||||||
|
m_hoveredWidget = bestEntry;
|
||||||
|
m_hoveredWidget->widget->OnMouseEnter();
|
||||||
|
}
|
||||||
|
|
||||||
|
int x = static_cast<int>(std::round(event.x - m_hoveredWidget->box.x));
|
||||||
|
int y = static_cast<int>(std::round(event.y - m_hoveredWidget->box.y));
|
||||||
|
|
||||||
|
bestEntry->widget->OnMouseMoved(x, y, event.deltaX, event.deltaY);
|
||||||
|
}
|
||||||
|
else if (m_hoveredWidget)
|
||||||
|
{
|
||||||
|
m_hoveredWidget->widget->OnMouseExit();
|
||||||
|
m_hoveredWidget = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::OnMouseLeft(const Nz::EventHandler* /*eventHandler*/)
|
||||||
|
{
|
||||||
|
if (m_hoveredWidget)
|
||||||
|
{
|
||||||
|
m_hoveredWidget->widget->OnMouseExit();
|
||||||
|
m_hoveredWidget = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::OnKeyPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||||
|
{
|
||||||
|
if (m_keyboardOwner)
|
||||||
|
m_keyboardOwner->OnKeyPressed(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::OnKeyReleased(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& event)
|
||||||
|
{
|
||||||
|
if (m_keyboardOwner)
|
||||||
|
m_keyboardOwner->OnKeyReleased(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::OnTextEntered(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::TextEvent& event)
|
||||||
|
{
|
||||||
|
if (m_keyboardOwner)
|
||||||
|
m_keyboardOwner->OnTextEntered(event.character, event.repeated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -141,6 +141,7 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
return m_zNear;
|
return m_zNear;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Sets the layer of the camera in case of multiples fields
|
* \brief Sets the layer of the camera in case of multiples fields
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,62 @@ namespace Ndk
|
||||||
* \brief NDK class that represents the component for graphics
|
* \brief NDK class that represents the component for graphics
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Adds the renderable elements to the render queue
|
||||||
|
*
|
||||||
|
* \param renderQueue Queue to be added
|
||||||
|
*/
|
||||||
|
void GraphicsComponent::AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const
|
||||||
|
{
|
||||||
|
EnsureTransformMatrixUpdate();
|
||||||
|
|
||||||
|
RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem<RenderSystem>();
|
||||||
|
|
||||||
|
for (const Renderable& object : m_renderables)
|
||||||
|
{
|
||||||
|
if (!object.dataUpdated)
|
||||||
|
{
|
||||||
|
object.data.transformMatrix = Nz::Matrix4f::ConcatenateAffine(renderSystem.GetCoordinateSystemMatrix(), Nz::Matrix4f::ConcatenateAffine(object.data.localMatrix, m_transformMatrix));
|
||||||
|
object.renderable->UpdateData(&object.data);
|
||||||
|
object.dataUpdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
object.renderable->AddToRenderQueue(renderQueue, object.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Attaches a renderable to the entity
|
||||||
|
*
|
||||||
|
* \param renderable Reference to a renderable element
|
||||||
|
* \param renderOrder Render order of the element
|
||||||
|
*/
|
||||||
|
void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, int renderOrder)
|
||||||
|
{
|
||||||
|
return Attach(renderable, Nz::Matrix4f::Identity(), renderOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Attaches a renderable to the entity with a specific matrix
|
||||||
|
*
|
||||||
|
* \param renderable Reference to a renderable element
|
||||||
|
* \param localMatrix Local matrix that will be applied to the instanced renderable
|
||||||
|
* \param renderOrder Render order of the element
|
||||||
|
*/
|
||||||
|
void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder)
|
||||||
|
{
|
||||||
|
m_renderables.emplace_back(m_transformMatrix);
|
||||||
|
Renderable& r = m_renderables.back();
|
||||||
|
r.data.localMatrix = localMatrix;
|
||||||
|
r.data.renderOrder = renderOrder;
|
||||||
|
r.renderable = std::move(renderable);
|
||||||
|
r.renderableBoundingVolumeInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateBoundingVolume, [this] (const Nz::InstancedRenderable*) { InvalidateBoundingVolume(); });
|
||||||
|
r.renderableDataInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size() - 1));
|
||||||
|
r.renderableReleaseSlot.Connect(r.renderable->OnInstancedRenderableRelease, this, &GraphicsComponent::Detach);
|
||||||
|
|
||||||
|
InvalidateBoundingVolume();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Invalidates the data for renderable
|
* \brief Invalidates the data for renderable
|
||||||
*
|
*
|
||||||
|
|
@ -33,6 +89,9 @@ namespace Ndk
|
||||||
Renderable& r = m_renderables[index];
|
Renderable& r = m_renderables[index];
|
||||||
r.dataUpdated = false;
|
r.dataUpdated = false;
|
||||||
r.renderable->InvalidateData(&r.data, flags);
|
r.renderable->InvalidateData(&r.data, flags);
|
||||||
|
|
||||||
|
for (VolumeCullingEntry& entry : m_volumeCullingEntries)
|
||||||
|
entry.listEntry.ForceInvalidation();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -102,7 +161,11 @@ namespace Ndk
|
||||||
NazaraUnused(node);
|
NazaraUnused(node);
|
||||||
|
|
||||||
// Our view matrix depends on NodeComponent position/rotation
|
// Our view matrix depends on NodeComponent position/rotation
|
||||||
|
InvalidateBoundingVolume();
|
||||||
InvalidateTransformMatrix();
|
InvalidateTransformMatrix();
|
||||||
|
|
||||||
|
for (VolumeCullingEntry& entry : m_volumeCullingEntries)
|
||||||
|
entry.listEntry.ForceInvalidation(); //< Force invalidation on movement
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -115,10 +178,29 @@ namespace Ndk
|
||||||
|
|
||||||
m_boundingVolume.MakeNull();
|
m_boundingVolume.MakeNull();
|
||||||
for (const Renderable& r : m_renderables)
|
for (const Renderable& r : m_renderables)
|
||||||
m_boundingVolume.ExtendTo(r.renderable->GetBoundingVolume());
|
{
|
||||||
|
Nz::BoundingVolumef boundingVolume = r.renderable->GetBoundingVolume();
|
||||||
|
|
||||||
m_boundingVolume.Update(m_transformMatrix);
|
// Adjust renderable bounding volume by local matrix
|
||||||
|
if (boundingVolume.IsFinite())
|
||||||
|
{
|
||||||
|
Nz::Boxf localBox = boundingVolume.obb.localBox;
|
||||||
|
Nz::Vector3f newPos = r.data.localMatrix * localBox.GetPosition();
|
||||||
|
Nz::Vector3f newLengths = r.data.localMatrix * localBox.GetLengths();
|
||||||
|
|
||||||
|
boundingVolume.Set(Nz::Boxf(newPos.x, newPos.y, newPos.z, newLengths.x, newLengths.y, newLengths.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_boundingVolume.ExtendTo(r.renderable->GetBoundingVolume());
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderSystem& renderSystem = m_entity->GetWorld()->GetSystem<RenderSystem>();
|
||||||
|
|
||||||
|
m_boundingVolume.Update(Nz::Matrix4f::ConcatenateAffine(renderSystem.GetCoordinateSystemMatrix(), m_transformMatrix));
|
||||||
m_boundingVolumeUpdated = true;
|
m_boundingVolumeUpdated = true;
|
||||||
|
|
||||||
|
for (VolumeCullingEntry& entry : m_volumeCullingEntries)
|
||||||
|
entry.listEntry.UpdateVolume(m_boundingVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,6 @@ namespace Ndk
|
||||||
*
|
*
|
||||||
* \param event Event to be takin into consideration by the console
|
* \param event Event to be takin into consideration by the console
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Console::SendEvent(const Nz::WindowEvent& event)
|
void Console::SendEvent(const Nz::WindowEvent& event)
|
||||||
{
|
{
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* \ingroup NDK
|
||||||
|
* \class Ndk::LuaBinding
|
||||||
|
* \brief NDK class that represents the binding between the engine & the SDK with the Lua scripting
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Binds modules to Lua
|
||||||
|
*/
|
||||||
|
|
||||||
|
LuaBinding::LuaBinding()
|
||||||
|
{
|
||||||
|
core = LuaBinding_Base::BindCore(*this);
|
||||||
|
math = LuaBinding_Base::BindMath(*this);
|
||||||
|
network = LuaBinding_Base::BindNetwork(*this);
|
||||||
|
utility = LuaBinding_Base::BindUtility(*this);
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
audio = LuaBinding_Base::BindAudio(*this);
|
||||||
|
renderer = LuaBinding_Base::BindRenderer(*this);
|
||||||
|
graphics = LuaBinding_Base::BindGraphics(*this);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sdk = LuaBinding_Base::BindSDK(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the engine & SDK
|
||||||
|
*/
|
||||||
|
|
||||||
|
void LuaBinding::RegisterClasses(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
core->Register(instance);
|
||||||
|
math->Register(instance);
|
||||||
|
network->Register(instance);
|
||||||
|
sdk->Register(instance);
|
||||||
|
utility->Register(instance);
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
audio->Register(instance);
|
||||||
|
graphics->Register(instance);
|
||||||
|
renderer->Register(instance);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ComponentType (fake enumeration to expose component indexes)
|
||||||
|
instance.PushTable(0, m_componentBinding.size());
|
||||||
|
{
|
||||||
|
for (const ComponentBinding& entry : m_componentBinding)
|
||||||
|
{
|
||||||
|
if (entry.name.IsEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
instance.PushField(entry.name, entry.index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
instance.SetGlobal("ComponentType");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,198 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Audio.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindAudio(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Audio>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Audio::LuaBinding_Audio(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
/*********************************** Nz::SoundEmitter **********************************/
|
||||||
|
soundEmitter.Reset("SoundEmitter");
|
||||||
|
{
|
||||||
|
soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping);
|
||||||
|
soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization);
|
||||||
|
|
||||||
|
soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation);
|
||||||
|
soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration);
|
||||||
|
soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance);
|
||||||
|
soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch);
|
||||||
|
soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset);
|
||||||
|
soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition);
|
||||||
|
soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus);
|
||||||
|
soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity);
|
||||||
|
soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume);
|
||||||
|
|
||||||
|
soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping);
|
||||||
|
soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized);
|
||||||
|
|
||||||
|
soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause);
|
||||||
|
soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play);
|
||||||
|
|
||||||
|
soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation);
|
||||||
|
soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance);
|
||||||
|
soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch);
|
||||||
|
soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition);
|
||||||
|
soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity);
|
||||||
|
soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume);
|
||||||
|
|
||||||
|
soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Music **********************************/
|
||||||
|
music.Reset("Music");
|
||||||
|
{
|
||||||
|
music.Inherit(soundEmitter);
|
||||||
|
|
||||||
|
music.BindDefaultConstructor();
|
||||||
|
|
||||||
|
//musicClass.SetMethod("Create", &Nz::Music::Create);
|
||||||
|
//musicClass.SetMethod("Destroy", &Nz::Music::Destroy);
|
||||||
|
|
||||||
|
music.BindMethod("EnableLooping", &Nz::Music::EnableLooping);
|
||||||
|
|
||||||
|
music.BindMethod("GetDuration", &Nz::Music::GetDuration);
|
||||||
|
music.BindMethod("GetFormat", &Nz::Music::GetFormat);
|
||||||
|
music.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset);
|
||||||
|
music.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount);
|
||||||
|
music.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate);
|
||||||
|
music.BindMethod("GetStatus", &Nz::Music::GetStatus);
|
||||||
|
|
||||||
|
music.BindMethod("IsLooping", &Nz::Music::IsLooping);
|
||||||
|
|
||||||
|
music.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams());
|
||||||
|
|
||||||
|
music.BindMethod("Pause", &Nz::Music::Pause);
|
||||||
|
music.BindMethod("Play", &Nz::Music::Play);
|
||||||
|
|
||||||
|
music.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset);
|
||||||
|
|
||||||
|
music.BindMethod("Stop", &Nz::Music::Stop);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
music.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::StringStream ss("Music(");
|
||||||
|
ss << instance.GetFilePath() << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Sound **********************************/
|
||||||
|
sound.Reset("Sound");
|
||||||
|
{
|
||||||
|
sound.Inherit(soundEmitter);
|
||||||
|
|
||||||
|
sound.BindDefaultConstructor();
|
||||||
|
|
||||||
|
sound.BindMethod("GetBuffer", &Nz::Sound::GetBuffer);
|
||||||
|
|
||||||
|
sound.BindMethod("IsPlayable", &Nz::Sound::IsPlayable);
|
||||||
|
sound.BindMethod("IsPlaying", &Nz::Sound::IsPlaying);
|
||||||
|
|
||||||
|
sound.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams());
|
||||||
|
|
||||||
|
sound.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
sound.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::StringStream ss("Sound(");
|
||||||
|
if (const Nz::SoundBuffer* buffer = instance.GetBuffer())
|
||||||
|
ss << buffer;
|
||||||
|
|
||||||
|
ss << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::SoundBuffer **********************************/
|
||||||
|
soundBuffer.Reset("SoundBuffer");
|
||||||
|
{
|
||||||
|
soundBuffer.SetConstructor([] (Nz::LuaInstance& lua, Nz::SoundBufferRef* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
NazaraUnused(lua);
|
||||||
|
NazaraUnused(argumentCount);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, Nz::SoundBuffer::New());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy);
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration);
|
||||||
|
soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat);
|
||||||
|
soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount);
|
||||||
|
soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate);
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid);
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams());
|
||||||
|
|
||||||
|
soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int index = 2;
|
||||||
|
Nz::AudioFormat format = lua.Check<Nz::AudioFormat>(&index);
|
||||||
|
unsigned int sampleCount = lua.Check<unsigned int>(&index);
|
||||||
|
unsigned int sampleRate = lua.Check<unsigned int>(&index);
|
||||||
|
|
||||||
|
std::size_t bufferSize = 0;
|
||||||
|
const char* buffer = lua.CheckString(index, &bufferSize);
|
||||||
|
lua.ArgCheck(buffer && bufferSize >= sampleCount * sizeof(Nz::Int16), index, "Invalid buffer");
|
||||||
|
|
||||||
|
lua.PushBoolean(instance->Create(format, sampleCount, sampleRate, reinterpret_cast<const Nz::Int16*>(buffer)));
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
lua.PushString(reinterpret_cast<const char*>(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16));
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::StringStream ss("SoundBuffer(");
|
||||||
|
if (instance->IsValid())
|
||||||
|
{
|
||||||
|
Nz::String filePath = instance->GetFilePath();
|
||||||
|
if (!filePath.IsEmpty())
|
||||||
|
ss << "File: " << filePath << ", ";
|
||||||
|
|
||||||
|
ss << "Duration: " << instance->GetDuration() / 1000.f << "s";
|
||||||
|
}
|
||||||
|
ss << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the Audio classes
|
||||||
|
*/
|
||||||
|
void LuaBinding_Audio::Register(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
music.Register(instance);
|
||||||
|
sound.Register(instance);
|
||||||
|
soundBuffer.Register(instance);
|
||||||
|
soundEmitter.Register(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Base.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
LuaBinding_Base::LuaBinding_Base(LuaBinding& binding) :
|
||||||
|
m_binding(binding)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Base::~LuaBinding_Base() = default;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,354 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Core.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindCore(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Core>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Core::LuaBinding_Core(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
/*********************************** Nz::Stream ***********************************/
|
||||||
|
stream.Reset("Stream");
|
||||||
|
{
|
||||||
|
stream.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode);
|
||||||
|
stream.BindMethod("Flush", &Nz::Stream::Flush);
|
||||||
|
stream.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos);
|
||||||
|
stream.BindMethod("GetDirectory", &Nz::Stream::GetDirectory);
|
||||||
|
stream.BindMethod("GetPath", &Nz::Stream::GetPath);
|
||||||
|
stream.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode);
|
||||||
|
stream.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions);
|
||||||
|
stream.BindMethod("GetSize", &Nz::Stream::GetSize);
|
||||||
|
stream.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U);
|
||||||
|
stream.BindMethod("IsReadable", &Nz::Stream::IsReadable);
|
||||||
|
stream.BindMethod("IsSequential", &Nz::Stream::IsSequential);
|
||||||
|
stream.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled);
|
||||||
|
stream.BindMethod("IsWritable", &Nz::Stream::IsWritable);
|
||||||
|
stream.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos);
|
||||||
|
|
||||||
|
stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
std::size_t length = lua.Check<std::size_t>(&argIndex);
|
||||||
|
|
||||||
|
std::unique_ptr<char[]> buffer(new char[length]);
|
||||||
|
std::size_t readLength = instance.Read(buffer.get(), length);
|
||||||
|
|
||||||
|
lua.PushString(Nz::String(buffer.get(), readLength));
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
std::size_t bufferSize = 0;
|
||||||
|
const char* buffer = lua.CheckString(argIndex, &bufferSize);
|
||||||
|
|
||||||
|
if (instance.IsTextModeEnabled())
|
||||||
|
lua.Push(instance.Write(Nz::String(buffer, bufferSize)));
|
||||||
|
else
|
||||||
|
lua.Push(instance.Write(buffer, bufferSize));
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Clock **********************************/
|
||||||
|
clock.Reset("Clock");
|
||||||
|
{
|
||||||
|
clock.SetConstructor([] (Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, startingValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
||||||
|
bool paused = lua.Check<bool>(&argIndex, false);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, startingValue, paused);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for Clock constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
clock.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds);
|
||||||
|
clock.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds);
|
||||||
|
clock.BindMethod("GetSeconds", &Nz::Clock::GetSeconds);
|
||||||
|
clock.BindMethod("IsPaused", &Nz::Clock::IsPaused);
|
||||||
|
clock.BindMethod("Pause", &Nz::Clock::Pause);
|
||||||
|
clock.BindMethod("Restart", &Nz::Clock::Restart);
|
||||||
|
clock.BindMethod("Unpause", &Nz::Clock::Unpause);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
Nz::StringStream ss("Clock(Elapsed: ");
|
||||||
|
ss << instance.GetSeconds();
|
||||||
|
ss << "s, Paused: ";
|
||||||
|
ss << instance.IsPaused();
|
||||||
|
ss << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************* Nz::Directory ********************************/
|
||||||
|
directory.Reset("Directory");
|
||||||
|
{
|
||||||
|
directory.SetConstructor([] (Nz::LuaInstance& lua, Nz::Directory* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
Nz::PlacementNew(instance, lua.Check<Nz::String>(&argIndex));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
directory.BindMethod("Close", &Nz::Directory::Close);
|
||||||
|
directory.BindMethod("Exists", &Nz::Directory::Exists);
|
||||||
|
directory.BindMethod("GetPath", &Nz::Directory::GetPath);
|
||||||
|
directory.BindMethod("GetPattern", &Nz::Directory::GetPattern);
|
||||||
|
directory.BindMethod("GetResultName", &Nz::Directory::GetResultName);
|
||||||
|
directory.BindMethod("GetResultPath", &Nz::Directory::GetResultPath);
|
||||||
|
directory.BindMethod("GetResultSize", &Nz::Directory::GetResultSize);
|
||||||
|
directory.BindMethod("IsOpen", &Nz::Directory::IsOpen);
|
||||||
|
directory.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory);
|
||||||
|
directory.BindMethod("NextResult", &Nz::Directory::NextResult, true);
|
||||||
|
directory.BindMethod("Open", &Nz::Directory::Open);
|
||||||
|
directory.BindMethod("SetPath", &Nz::Directory::SetPath);
|
||||||
|
directory.BindMethod("SetPattern", &Nz::Directory::SetPattern);
|
||||||
|
|
||||||
|
directory.BindStaticMethod("Copy", Nz::Directory::Copy);
|
||||||
|
directory.BindStaticMethod("Create", Nz::Directory::Create);
|
||||||
|
directory.BindStaticMethod("Exists", Nz::Directory::Exists);
|
||||||
|
directory.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent);
|
||||||
|
directory.BindStaticMethod("Remove", Nz::Directory::Remove);
|
||||||
|
directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
Nz::StringStream ss("Directory(");
|
||||||
|
ss << instance.GetPath();
|
||||||
|
ss << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::File ***********************************/
|
||||||
|
file.Reset("File");
|
||||||
|
{
|
||||||
|
file.Inherit(stream);
|
||||||
|
|
||||||
|
file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, filePath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||||
|
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex);
|
||||||
|
|
||||||
|
Nz::PlacementNew(instance, filePath, openMode);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for File constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
file.BindMethod("Close", &Nz::File::Close);
|
||||||
|
file.BindMethod("Copy", &Nz::File::Copy);
|
||||||
|
file.BindMethod("Delete", &Nz::File::Delete);
|
||||||
|
file.BindMethod("EndOfFile", &Nz::File::EndOfFile);
|
||||||
|
file.BindMethod("Exists", &Nz::File::Exists);
|
||||||
|
file.BindMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
||||||
|
file.BindMethod("GetFileName", &Nz::File::GetFileName);
|
||||||
|
file.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
||||||
|
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||||
|
file.BindMethod("IsOpen", &Nz::File::IsOpen);
|
||||||
|
file.BindMethod("Rename", &Nz::File::GetLastWriteTime);
|
||||||
|
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||||
|
file.BindMethod("SetFile", &Nz::File::GetLastWriteTime);
|
||||||
|
|
||||||
|
file.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath);
|
||||||
|
file.BindStaticMethod("ComputeHash", (Nz::ByteArray(*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash);
|
||||||
|
file.BindStaticMethod("Copy", &Nz::File::Copy);
|
||||||
|
file.BindStaticMethod("Delete", &Nz::File::Delete);
|
||||||
|
file.BindStaticMethod("Exists", &Nz::File::Exists);
|
||||||
|
//fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
||||||
|
file.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory);
|
||||||
|
//fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
||||||
|
//fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
||||||
|
file.BindStaticMethod("GetSize", &Nz::File::GetSize);
|
||||||
|
file.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute);
|
||||||
|
file.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath);
|
||||||
|
file.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators);
|
||||||
|
file.BindStaticMethod("Rename", &Nz::File::Rename);
|
||||||
|
|
||||||
|
// Manual
|
||||||
|
file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
return lua.Push(instance.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
||||||
|
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen);
|
||||||
|
return lua.Push(instance.Open(filePath, openMode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method Open");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
return lua.Push(instance.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Nz::CursorPosition curPos = lua.Check<Nz::CursorPosition>(&argIndex);
|
||||||
|
Nz::Int64 offset = lua.Check<Nz::Int64>(&argIndex);
|
||||||
|
return lua.Push(instance.SetCursorPos(curPos, offset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method SetCursorPos");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t /*argumentCount*/) -> int {
|
||||||
|
Nz::StringStream ss("File(");
|
||||||
|
if (instance.IsOpen())
|
||||||
|
ss << "Path: " << instance.GetPath();
|
||||||
|
|
||||||
|
ss << ')';
|
||||||
|
|
||||||
|
lua.PushString(ss);
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the Core classes
|
||||||
|
*/
|
||||||
|
void LuaBinding_Core::Register(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
// Classes
|
||||||
|
clock.Register(instance);
|
||||||
|
directory.Register(instance);
|
||||||
|
file.Register(instance);
|
||||||
|
stream.Register(instance);
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
|
||||||
|
// Nz::CursorPosition
|
||||||
|
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
||||||
|
instance.PushTable(0, 3);
|
||||||
|
{
|
||||||
|
instance.PushField("AtBegin", Nz::CursorPosition_AtBegin);
|
||||||
|
instance.PushField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
||||||
|
instance.PushField("AtEnd", Nz::CursorPosition_AtEnd);
|
||||||
|
}
|
||||||
|
instance.SetGlobal("CursorPosition");
|
||||||
|
|
||||||
|
// Nz::HashType
|
||||||
|
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
||||||
|
instance.PushTable(0, 9);
|
||||||
|
{
|
||||||
|
instance.PushField("CRC32", Nz::HashType_CRC32);
|
||||||
|
instance.PushField("Fletcher16", Nz::HashType_Fletcher16);
|
||||||
|
instance.PushField("MD5", Nz::HashType_MD5);
|
||||||
|
instance.PushField("SHA1", Nz::HashType_SHA1);
|
||||||
|
instance.PushField("SHA224", Nz::HashType_SHA224);
|
||||||
|
instance.PushField("SHA256", Nz::HashType_SHA256);
|
||||||
|
instance.PushField("SHA384", Nz::HashType_SHA384);
|
||||||
|
instance.PushField("SHA512", Nz::HashType_SHA512);
|
||||||
|
instance.PushField("Whirlpool", Nz::HashType_Whirlpool);
|
||||||
|
}
|
||||||
|
instance.SetGlobal("HashType");
|
||||||
|
|
||||||
|
// Nz::OpenMode
|
||||||
|
static_assert(Nz::OpenMode_Max + 1 == 8, "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
||||||
|
instance.PushTable(0, Nz::OpenMode_Max + 1);
|
||||||
|
{
|
||||||
|
instance.PushField("Append", Nz::OpenMode_Append);
|
||||||
|
instance.PushField("NotOpen", Nz::OpenMode_NotOpen);
|
||||||
|
instance.PushField("Lock", Nz::OpenMode_Lock);
|
||||||
|
instance.PushField("ReadOnly", Nz::OpenMode_ReadOnly);
|
||||||
|
instance.PushField("ReadWrite", Nz::OpenMode_ReadWrite);
|
||||||
|
instance.PushField("Text", Nz::OpenMode_Text);
|
||||||
|
instance.PushField("Truncate", Nz::OpenMode_Truncate);
|
||||||
|
instance.PushField("WriteOnly", Nz::OpenMode_WriteOnly);
|
||||||
|
}
|
||||||
|
instance.SetGlobal("OpenMode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,370 @@
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Graphics.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindGraphics(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Graphics>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Graphics::LuaBinding_Graphics(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
/*********************************** Nz::AbstractViewer ***********************************/
|
||||||
|
abstractViewer.Reset("AbstractViewer");
|
||||||
|
{
|
||||||
|
abstractViewer.BindMethod("GetAspectRatio", &Nz::AbstractViewer::GetAspectRatio);
|
||||||
|
abstractViewer.BindMethod("GetEyePosition", &Nz::AbstractViewer::GetEyePosition);
|
||||||
|
abstractViewer.BindMethod("GetForward", &Nz::AbstractViewer::GetForward);
|
||||||
|
//abstractViewer.BindMethod("GetFrustum", &Nz::AbstractViewer::GetFrustum);
|
||||||
|
abstractViewer.BindMethod("GetProjectionMatrix", &Nz::AbstractViewer::GetProjectionMatrix);
|
||||||
|
//abstractViewer.BindMethod("GetTarget", &Nz::AbstractViewer::GetTarget);
|
||||||
|
abstractViewer.BindMethod("GetViewMatrix", &Nz::AbstractViewer::GetViewMatrix);
|
||||||
|
abstractViewer.BindMethod("GetViewport", &Nz::AbstractViewer::GetViewport);
|
||||||
|
abstractViewer.BindMethod("GetZFar", &Nz::AbstractViewer::GetZFar);
|
||||||
|
abstractViewer.BindMethod("GetZNear", &Nz::AbstractViewer::GetZNear);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::InstancedRenderable ***********************************/
|
||||||
|
instancedRenderable.Reset("InstancedRenderable");
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Material ***********************************/
|
||||||
|
material.Reset("Material");
|
||||||
|
{
|
||||||
|
material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
switch (argumentCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance, Nz::Material::New());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
int argIndex = 1;
|
||||||
|
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Material::New(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (lua.IsOfType(argIndex, "Material"))
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Material::New(**static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex))));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Material::New(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("Configure", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
||||||
|
{
|
||||||
|
instance->Configure(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lua.Push(instance->Configure(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("EnableAlphaTest", &Nz::Material::EnableAlphaTest);
|
||||||
|
material.BindMethod("EnableBlending", &Nz::Material::EnableBlending);
|
||||||
|
material.BindMethod("EnableColorWrite", &Nz::Material::EnableColorWrite);
|
||||||
|
material.BindMethod("EnableDepthBuffer", &Nz::Material::EnableDepthBuffer);
|
||||||
|
material.BindMethod("EnableDepthSorting", &Nz::Material::EnableDepthSorting);
|
||||||
|
material.BindMethod("EnableDepthWrite", &Nz::Material::EnableDepthWrite);
|
||||||
|
material.BindMethod("EnableFaceCulling", &Nz::Material::EnableFaceCulling);
|
||||||
|
material.BindMethod("EnableScissorTest", &Nz::Material::EnableScissorTest);
|
||||||
|
material.BindMethod("EnableShadowCasting", &Nz::Material::EnableShadowCasting);
|
||||||
|
material.BindMethod("EnableShadowReceive", &Nz::Material::EnableShadowReceive);
|
||||||
|
material.BindMethod("EnableStencilTest", &Nz::Material::EnableStencilTest);
|
||||||
|
|
||||||
|
material.BindMethod("EnsurePipelineUpdate", &Nz::Material::EnsurePipelineUpdate);
|
||||||
|
|
||||||
|
material.BindMethod("GetAlphaMap", &Nz::Material::GetAlphaMap);
|
||||||
|
material.BindMethod("GetAlphaThreshold", &Nz::Material::GetAlphaThreshold);
|
||||||
|
material.BindMethod("GetAmbientColor", &Nz::Material::GetAmbientColor);
|
||||||
|
material.BindMethod("GetDepthFunc", &Nz::Material::GetDepthFunc);
|
||||||
|
material.BindMethod("GetDepthMaterial", &Nz::Material::GetDepthMaterial);
|
||||||
|
material.BindMethod("GetDiffuseColor", &Nz::Material::GetDiffuseColor);
|
||||||
|
material.BindMethod("GetDiffuseMap", &Nz::Material::GetDiffuseMap);
|
||||||
|
//material.BindMethod("GetDiffuseSampler", &Nz::Material::GetDiffuseSampler);
|
||||||
|
material.BindMethod("GetDstBlend", &Nz::Material::GetDstBlend);
|
||||||
|
material.BindMethod("GetEmissiveMap", &Nz::Material::GetEmissiveMap);
|
||||||
|
material.BindMethod("GetFaceCulling", &Nz::Material::GetFaceCulling);
|
||||||
|
material.BindMethod("GetFaceFilling", &Nz::Material::GetFaceFilling);
|
||||||
|
material.BindMethod("GetHeightMap", &Nz::Material::GetHeightMap);
|
||||||
|
material.BindMethod("GetLineWidth", &Nz::Material::GetLineWidth);
|
||||||
|
material.BindMethod("GetNormalMap", &Nz::Material::GetNormalMap);
|
||||||
|
//material.BindMethod("GetPipeline", &Nz::Material::GetPipeline);
|
||||||
|
//material.BindMethod("GetPipelineInfo", &Nz::Material::GetPipelineInfo);
|
||||||
|
material.BindMethod("GetPointSize", &Nz::Material::GetPointSize);
|
||||||
|
//material.BindMethod("GetShader", &Nz::Material::GetShader);
|
||||||
|
material.BindMethod("GetShininess", &Nz::Material::GetShininess);
|
||||||
|
material.BindMethod("GetSpecularColor", &Nz::Material::GetSpecularColor);
|
||||||
|
material.BindMethod("GetSpecularMap", &Nz::Material::GetSpecularMap);
|
||||||
|
//material.BindMethod("GetSpecularSampler", &Nz::Material::GetSpecularSampler);
|
||||||
|
material.BindMethod("GetSrcBlend", &Nz::Material::GetSrcBlend);
|
||||||
|
|
||||||
|
material.BindMethod("HasAlphaMap", &Nz::Material::HasAlphaMap);
|
||||||
|
material.BindMethod("HasDepthMaterial", &Nz::Material::HasDepthMaterial);
|
||||||
|
material.BindMethod("HasDiffuseMap", &Nz::Material::HasDiffuseMap);
|
||||||
|
material.BindMethod("HasEmissiveMap", &Nz::Material::HasEmissiveMap);
|
||||||
|
material.BindMethod("HasHeightMap", &Nz::Material::HasHeightMap);
|
||||||
|
material.BindMethod("HasNormalMap", &Nz::Material::HasNormalMap);
|
||||||
|
material.BindMethod("HasSpecularMap", &Nz::Material::HasSpecularMap);
|
||||||
|
|
||||||
|
material.BindMethod("IsAlphaTestEnabled", &Nz::Material::IsAlphaTestEnabled);
|
||||||
|
material.BindMethod("IsBlendingEnabled", &Nz::Material::IsBlendingEnabled);
|
||||||
|
material.BindMethod("IsColorWriteEnabled", &Nz::Material::IsColorWriteEnabled);
|
||||||
|
material.BindMethod("IsDepthBufferEnabled", &Nz::Material::IsDepthBufferEnabled);
|
||||||
|
material.BindMethod("IsDepthSortingEnabled", &Nz::Material::IsDepthSortingEnabled);
|
||||||
|
material.BindMethod("IsDepthWriteEnabled", &Nz::Material::IsDepthWriteEnabled);
|
||||||
|
material.BindMethod("IsFaceCullingEnabled", &Nz::Material::IsFaceCullingEnabled);
|
||||||
|
material.BindMethod("IsScissorTestEnabled", &Nz::Material::IsScissorTestEnabled);
|
||||||
|
material.BindMethod("IsStencilTestEnabled", &Nz::Material::IsStencilTestEnabled);
|
||||||
|
material.BindMethod("IsShadowCastingEnabled", &Nz::Material::IsShadowCastingEnabled);
|
||||||
|
material.BindMethod("IsShadowReceiveEnabled", &Nz::Material::IsShadowReceiveEnabled);
|
||||||
|
|
||||||
|
material.BindMethod("LoadFromFile", &Nz::Material::LoadFromFile, Nz::MaterialParams());
|
||||||
|
|
||||||
|
material.BindMethod("Reset", &Nz::Material::Reset);
|
||||||
|
|
||||||
|
material.BindMethod("SetAlphaThreshold", &Nz::Material::SetAlphaThreshold);
|
||||||
|
material.BindMethod("SetAmbientColor", &Nz::Material::SetAmbientColor);
|
||||||
|
material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc);
|
||||||
|
material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc);
|
||||||
|
material.BindMethod("SetDepthMaterial", &Nz::Material::SetDepthMaterial);
|
||||||
|
material.BindMethod("SetDiffuseColor", &Nz::Material::SetDiffuseColor);
|
||||||
|
//material.BindMethod("SetDiffuseSampler", &Nz::Material::SetDiffuseSampler);
|
||||||
|
material.BindMethod("SetDstBlend", &Nz::Material::SetDstBlend);
|
||||||
|
material.BindMethod("SetFaceCulling", &Nz::Material::SetFaceCulling);
|
||||||
|
material.BindMethod("SetFaceFilling", &Nz::Material::SetFaceFilling);
|
||||||
|
material.BindMethod("SetLineWidth", &Nz::Material::SetLineWidth);
|
||||||
|
material.BindMethod("SetPointSize", &Nz::Material::SetPointSize);
|
||||||
|
material.BindMethod("SetShininess", &Nz::Material::SetShininess);
|
||||||
|
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
||||||
|
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
||||||
|
//material.BindMethod("SetSpecularSampler", &Nz::Material::SetSpecularSampler);
|
||||||
|
material.BindMethod("SetSrcBlend", &Nz::Material::SetSrcBlend);
|
||||||
|
|
||||||
|
material.BindStaticMethod("GetDefault", &Nz::Material::GetDefault);
|
||||||
|
|
||||||
|
material.BindMethod("SetAlphaMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetAlphaMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetAlphaMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetDiffuseMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetDiffuseMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetEmissiveMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetEmissiveMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetHeightMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetHeightMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetNormalMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetNormalMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "UberShader"))
|
||||||
|
{
|
||||||
|
instance->SetShader(*static_cast<Nz::UberShaderRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetShader(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
|
||||||
|
material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
{
|
||||||
|
instance->SetSpecularMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return lua.Push(instance->SetSpecularMap(lua.Check<Nz::String>(&argIndex)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Model ***********************************/
|
||||||
|
model.Reset("Model");
|
||||||
|
{
|
||||||
|
model.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef*
|
||||||
|
{
|
||||||
|
return reinterpret_cast<Nz::InstancedRenderableRef*>(modelRef); //TODO: Make a ObjectRefCast
|
||||||
|
});
|
||||||
|
|
||||||
|
model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* instance, std::size_t /*argumentCount*/)
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Model::New());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
//model.BindMethod("GetMaterial", &Nz::Model::GetMaterial);
|
||||||
|
model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
|
||||||
|
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
|
||||||
|
model.BindMethod("GetSkin", &Nz::Model::GetSkin);
|
||||||
|
model.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
|
||||||
|
|
||||||
|
model.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
|
||||||
|
model.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
|
||||||
|
|
||||||
|
model.BindMethod("Reset", &Nz::Model::Reset);
|
||||||
|
|
||||||
|
//model.BindMethod("SetMaterial", &Nz::Model::SetMaterial);
|
||||||
|
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
|
||||||
|
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
||||||
|
model.BindMethod("SetSkin", &Nz::Model::SetSkin);
|
||||||
|
model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Sprite ***********************************/
|
||||||
|
sprite.Reset("Sprite");
|
||||||
|
{
|
||||||
|
sprite.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef*
|
||||||
|
{
|
||||||
|
return reinterpret_cast<Nz::InstancedRenderableRef*>(spriteRef); //TODO: Make a ObjectRefCast
|
||||||
|
});
|
||||||
|
|
||||||
|
sprite.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* instance, std::size_t /*argumentCount*/)
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Sprite::New());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
sprite.BindMethod("GetColor", &Nz::Sprite::GetColor);
|
||||||
|
sprite.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor);
|
||||||
|
sprite.BindMethod("GetMaterial", &Nz::Sprite::GetMaterial);
|
||||||
|
sprite.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin);
|
||||||
|
sprite.BindMethod("GetSize", &Nz::Sprite::GetSize);
|
||||||
|
sprite.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords);
|
||||||
|
|
||||||
|
sprite.BindMethod("SetColor", &Nz::Sprite::SetColor);
|
||||||
|
sprite.BindMethod("SetCornerColor", &Nz::Sprite::SetCornerColor);
|
||||||
|
sprite.BindMethod("SetDefaultMaterial", &Nz::Sprite::SetDefaultMaterial);
|
||||||
|
sprite.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin);
|
||||||
|
sprite.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize);
|
||||||
|
sprite.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords);
|
||||||
|
sprite.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect);
|
||||||
|
|
||||||
|
sprite.BindMethod("SetMaterial", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||||
|
|
||||||
|
if (lua.IsOfType(argIndex, "Material"))
|
||||||
|
instance->SetMaterial(*static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||||
|
else
|
||||||
|
instance->SetMaterial(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
sprite.BindMethod("SetTexture", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
||||||
|
|
||||||
|
if (lua.IsOfType(argIndex, "Texture"))
|
||||||
|
instance->SetTexture(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
||||||
|
else
|
||||||
|
instance->SetTexture(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::SpriteLibrary ***********************************/
|
||||||
|
spriteLibrary.Reset("SpriteLibrary");
|
||||||
|
{
|
||||||
|
spriteLibrary.BindStaticMethod("Get", &Nz::SpriteLibrary::Get);
|
||||||
|
spriteLibrary.BindStaticMethod("Has", &Nz::SpriteLibrary::Has);
|
||||||
|
spriteLibrary.BindStaticMethod("Register", &Nz::SpriteLibrary::Register);
|
||||||
|
spriteLibrary.BindStaticMethod("Query", &Nz::SpriteLibrary::Query);
|
||||||
|
spriteLibrary.BindStaticMethod("Unregister", &Nz::SpriteLibrary::Unregister);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the Graphics classes
|
||||||
|
*/
|
||||||
|
|
||||||
|
void LuaBinding_Graphics::Register(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
abstractViewer.Register(instance);
|
||||||
|
instancedRenderable.Register(instance);
|
||||||
|
material.Register(instance);
|
||||||
|
model.Register(instance);
|
||||||
|
sprite.Register(instance);
|
||||||
|
spriteLibrary.Register(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,986 @@
|
||||||
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Math.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindMath(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Math>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Math::LuaBinding_Math(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
/*********************************** Nz::EulerAngles **********************************/
|
||||||
|
eulerAngles.Reset("EulerAngles");
|
||||||
|
{
|
||||||
|
eulerAngles.SetConstructor([] (Nz::LuaInstance& lua, Nz::EulerAnglesd* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||||
|
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance, Nz::EulerAnglesd::Zero());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
Nz::PlacementNew(instance, *static_cast<Nz::EulerAnglesd*>(lua.CheckUserdata(1, "EulerAngles")));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for EulerAngles constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
eulerAngles.BindMethod("Normalize", &Nz::EulerAnglesd::Normalize);
|
||||||
|
eulerAngles.BindMethod("ToQuaternion", &Nz::EulerAnglesd::ToQuaternion);
|
||||||
|
|
||||||
|
eulerAngles.BindMethod("__tostring", &Nz::EulerAnglesd::ToString);
|
||||||
|
|
||||||
|
eulerAngles.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* ypr = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
switch (length)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
switch (ypr[0])
|
||||||
|
{
|
||||||
|
case 'p':
|
||||||
|
lua.Push(instance.pitch);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.yaw);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
lua.Push(instance.roll);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lua.Push(instance.yaw);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lua.Push(instance.roll);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
lua.Push(instance.pitch);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
eulerAngles.SetSetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* ypr = lua.CheckString(2, &length);
|
||||||
|
double value = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
switch (length)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
switch (ypr[0])
|
||||||
|
{
|
||||||
|
case 'p':
|
||||||
|
instance.pitch = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.yaw = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'r':
|
||||||
|
instance.roll = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "yaw", 3) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
instance.yaw = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "roll", 4) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
instance.roll = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
{
|
||||||
|
if (std::memcmp(ypr, "pitch", 5) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
instance.pitch = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Matrix4 **********************************/
|
||||||
|
matrix4d.Reset("Matrix4");
|
||||||
|
{
|
||||||
|
matrix4d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Matrix4d* matrix, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||||
|
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(matrix, Nz::Matrix4d::Zero());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
if (lua.IsOfType(1, "Matrix4"))
|
||||||
|
Nz::PlacementNew(matrix, *static_cast<Nz::Matrix4d*>(lua.ToUserdata(1)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
{
|
||||||
|
double values[16];
|
||||||
|
for (int i = 0; i < 16; ++i)
|
||||||
|
values[i] = lua.CheckNumber(i);
|
||||||
|
|
||||||
|
Nz::PlacementNew(matrix, values);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("ApplyRotation", &Nz::Matrix4d::ApplyRotation);
|
||||||
|
matrix4d.BindMethod("ApplyScale", &Nz::Matrix4d::ApplyScale);
|
||||||
|
matrix4d.BindMethod("ApplyTranslation", &Nz::Matrix4d::ApplyTranslation);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Concatenate", &Nz::Matrix4d::Concatenate);
|
||||||
|
matrix4d.BindMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine);
|
||||||
|
|
||||||
|
//matrix4d.BindMethod("GetColumn", &Nz::Matrix4d::GetColumn);
|
||||||
|
matrix4d.BindMethod("GetDeterminant", &Nz::Matrix4d::GetDeterminant);
|
||||||
|
matrix4d.BindMethod("GetDeterminantAffine", &Nz::Matrix4d::GetDeterminantAffine);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("GetInverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::Matrix4d result;
|
||||||
|
if (instance.GetInverse(&result))
|
||||||
|
return lua.Push(true, result);
|
||||||
|
else
|
||||||
|
return lua.Push(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("GetInverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::Matrix4d result;
|
||||||
|
if (instance.GetInverseAffine(&result))
|
||||||
|
return lua.Push(true, result);
|
||||||
|
else
|
||||||
|
return lua.Push(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("GetRotation", &Nz::Matrix4d::GetRotation);
|
||||||
|
|
||||||
|
//matrix4d.BindMethod("GetRow", &Nz::Matrix4d::GetRow);
|
||||||
|
matrix4d.BindMethod("GetScale", &Nz::Matrix4d::GetScale);
|
||||||
|
matrix4d.BindMethod("GetSquaredScale", &Nz::Matrix4d::GetSquaredScale);
|
||||||
|
matrix4d.BindMethod("GetTranslation", &Nz::Matrix4d::GetTranslation);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("GetTransposed", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
Nz::Matrix4d result;
|
||||||
|
instance.GetTransposed(&result);
|
||||||
|
|
||||||
|
return lua.Push(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("HasNegativeScale", &Nz::Matrix4d::HasNegativeScale);
|
||||||
|
matrix4d.BindMethod("HasScale", &Nz::Matrix4d::HasScale);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Inverse", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
bool succeeded;
|
||||||
|
instance.Inverse(&succeeded);
|
||||||
|
|
||||||
|
return lua.Push(succeeded);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("InverseAffine", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
bool succeeded;
|
||||||
|
instance.InverseAffine(&succeeded);
|
||||||
|
|
||||||
|
return lua.Push(succeeded);
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("IsAffine", &Nz::Matrix4d::IsAffine);
|
||||||
|
matrix4d.BindMethod("IsIdentity", &Nz::Matrix4d::IsIdentity);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("MakeIdentity", &Nz::Matrix4d::MakeIdentity);
|
||||||
|
matrix4d.BindMethod("MakeLookAt", &Nz::Matrix4d::MakeLookAt, Nz::Vector3d::Up());
|
||||||
|
matrix4d.BindMethod("MakeOrtho", &Nz::Matrix4d::MakeOrtho, -1.0, 1.0);
|
||||||
|
matrix4d.BindMethod("MakePerspective", &Nz::Matrix4d::MakePerspective);
|
||||||
|
matrix4d.BindMethod("MakeRotation", &Nz::Matrix4d::MakeRotation);
|
||||||
|
matrix4d.BindMethod("MakeScale", &Nz::Matrix4d::MakeScale);
|
||||||
|
matrix4d.BindMethod("MakeTranslation", &Nz::Matrix4d::MakeTranslation);
|
||||||
|
matrix4d.BindMethod("MakeTransform", (Nz::Matrix4d&(Nz::Matrix4d::*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::MakeTransform, Nz::Vector3d::Unit());
|
||||||
|
matrix4d.BindMethod("MakeViewMatrix", &Nz::Matrix4d::MakeViewMatrix);
|
||||||
|
matrix4d.BindMethod("MakeZero", &Nz::Matrix4d::MakeZero);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Set", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
if (lua.IsOfType(argIndex, "Matrix4"))
|
||||||
|
instance.Set(*static_cast<Nz::Matrix4d*>(lua.ToUserdata(argIndex)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
{
|
||||||
|
double values[16];
|
||||||
|
for (std::size_t i = 0; i < 16; ++i)
|
||||||
|
values[i] = lua.CheckNumber(argIndex++);
|
||||||
|
|
||||||
|
instance.Set(values);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method Set");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("SetRotation", &Nz::Matrix4d::SetRotation);
|
||||||
|
matrix4d.BindMethod("SetScale", &Nz::Matrix4d::SetScale);
|
||||||
|
matrix4d.BindMethod("SetTranslation", &Nz::Matrix4d::SetTranslation);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Transform", [] (Nz::LuaInstance& lua, Nz::Matrix4d& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
if (lua.IsOfType(argIndex, "Vector2"))
|
||||||
|
{
|
||||||
|
double z(lua.CheckNumber(argIndex + 1, 0.0));
|
||||||
|
double w(lua.CheckNumber(argIndex + 2, 1.0));
|
||||||
|
|
||||||
|
return lua.Push(instance.Transform(*static_cast<Nz::Vector2d*>(lua.ToUserdata(argIndex)), z, w));
|
||||||
|
}
|
||||||
|
else if (lua.IsOfType(argIndex, "Vector3"))
|
||||||
|
{
|
||||||
|
double w(lua.CheckNumber(argIndex + 1, 1.0));
|
||||||
|
|
||||||
|
return lua.Push(instance.Transform(*static_cast<Nz::Vector3d*>(lua.ToUserdata(argIndex)), w));
|
||||||
|
}
|
||||||
|
//else if (lua.IsOfType(2, "Vector4"))
|
||||||
|
// return lua.Push(instance.Transform(*static_cast<Nz::Vector4d*>(lua.ToUserdata(1))));
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method Transform");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.BindMethod("Transpose", &Nz::Matrix4d::Transpose);
|
||||||
|
|
||||||
|
matrix4d.BindMethod("__tostring", &Nz::Matrix4d::ToString);
|
||||||
|
|
||||||
|
matrix4d.BindStaticMethod("Concatenate", &Nz::Matrix4d::Concatenate);
|
||||||
|
matrix4d.BindStaticMethod("ConcatenateAffine", &Nz::Matrix4d::ConcatenateAffine);
|
||||||
|
matrix4d.BindStaticMethod("Identity", &Nz::Matrix4d::Identity);
|
||||||
|
matrix4d.BindStaticMethod("LookAt", &Nz::Matrix4d::LookAt, Nz::Vector3d::Up());
|
||||||
|
matrix4d.BindStaticMethod("Ortho", &Nz::Matrix4d::Ortho, -1.0, 1.0);
|
||||||
|
matrix4d.BindStaticMethod("Perspective", &Nz::Matrix4d::Perspective);
|
||||||
|
matrix4d.BindStaticMethod("Rotate", &Nz::Matrix4d::Rotate);
|
||||||
|
matrix4d.BindStaticMethod("Scale", &Nz::Matrix4d::Scale);
|
||||||
|
matrix4d.BindStaticMethod("Translate", &Nz::Matrix4d::Translate);
|
||||||
|
matrix4d.BindStaticMethod("Transform", (Nz::Matrix4d(*)(const Nz::Vector3d&, const Nz::Quaterniond&, const Nz::Vector3d&)) &Nz::Matrix4d::Transform, Nz::Vector3d::Unit());
|
||||||
|
matrix4d.BindStaticMethod("ViewMatrix", &Nz::Matrix4d::ViewMatrix);
|
||||||
|
matrix4d.BindStaticMethod("Zero", &Nz::Matrix4d::Zero);
|
||||||
|
|
||||||
|
matrix4d.SetGetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance)
|
||||||
|
{
|
||||||
|
bool succeeded = false;
|
||||||
|
std::size_t index = static_cast<std::size_t>(lua.ToInteger(2, &succeeded));
|
||||||
|
if (!succeeded || index < 1 || index > 16)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
matrix4d.SetSetter([] (Nz::LuaInstance& lua, Nz::Matrix4d& instance)
|
||||||
|
{
|
||||||
|
bool succeeded = false;
|
||||||
|
std::size_t index = static_cast<std::size_t>(lua.ToInteger(2, &succeeded));
|
||||||
|
if (!succeeded || index < 1 || index > 16)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
instance[index - 1] = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Rect **********************************/
|
||||||
|
rect.Reset("Rect");
|
||||||
|
{
|
||||||
|
rect.SetConstructor([] (Nz::LuaInstance& lua, Nz::Rectd* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||||
|
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 4:
|
||||||
|
PlacementNew(instance, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0), lua.CheckNumber(4, 0.0));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(1, "Rect"))
|
||||||
|
PlacementNew(instance, *static_cast<Nz::Rectd*>(lua.ToUserdata(1)));
|
||||||
|
else if (lua.IsOfType(1, Nz::LuaType_Table))
|
||||||
|
{
|
||||||
|
// TODO => Faire sans avoir à mettre de nom dans la table et prendre les éléments un à un pour créer le Rectd
|
||||||
|
PlacementNew(instance, lua.CheckField<double>("x", 1),
|
||||||
|
lua.CheckField<double>("y", 1),
|
||||||
|
lua.CheckField<double>("width", 1),
|
||||||
|
lua.CheckField<double>("height", 1));
|
||||||
|
}
|
||||||
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
|
PlacementNew(instance, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(1, Nz::LuaType_Number) && lua.IsOfType(2, Nz::LuaType_Number))
|
||||||
|
PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2));
|
||||||
|
else if (lua.IsOfType(1, "Vector2") && lua.IsOfType(2, "Vector2"))
|
||||||
|
PlacementNew(instance, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)), *static_cast<Nz::Vector2d*>(lua.ToUserdata(2)));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for Rect constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
rect.BindMethod("__tostring", &Nz::Rectd::ToString);
|
||||||
|
|
||||||
|
rect.SetGetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
auto index = lua.CheckBoundInteger<std::size_t>(2);
|
||||||
|
if (index < 1 || index > 4)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xywh = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (xywh[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
lua.Push(instance.x);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'w':
|
||||||
|
lua.Push(instance.width);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'h':
|
||||||
|
lua.Push(instance.height);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
rect.SetSetter([] (Nz::LuaInstance& lua, Nz::Rectd& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
auto index = lua.CheckBoundInteger<std::size_t>(2);
|
||||||
|
if (index < 1 || index > 4)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
instance[index - 1] = lua.CheckNumber(2);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xywh = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
double value = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
switch (xywh[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
instance.x = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.y = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'w':
|
||||||
|
instance.width = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'h':
|
||||||
|
instance.height = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Quaternion **********************************/
|
||||||
|
quaternion.Reset("Quaternion");
|
||||||
|
{
|
||||||
|
quaternion.SetConstructor([] (Nz::LuaInstance& lua, Nz::Quaterniond* instance, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||||
|
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
Nz::PlacementNew(instance, Nz::Quaterniond::Zero());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(1, "EulerAngles"))
|
||||||
|
Nz::PlacementNew(instance, *static_cast<Nz::EulerAnglesd*>(lua.ToUserdata(1)));
|
||||||
|
else if (lua.IsOfType(1, "Quaternion"))
|
||||||
|
Nz::PlacementNew(instance, *static_cast<Nz::Quaterniond*>(lua.ToUserdata(1)));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
Nz::PlacementNew(instance, lua.CheckNumber(1), *static_cast<Nz::Vector3d*>(lua.CheckUserdata(2, "Vector3")));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
Nz::PlacementNew(instance, lua.CheckNumber(1), lua.CheckNumber(2), lua.CheckNumber(3), lua.CheckNumber(4));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for Quaternion constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.BindMethod("ComputeW", &Nz::Quaterniond::ComputeW);
|
||||||
|
quaternion.BindMethod("Conjugate", &Nz::Quaterniond::Conjugate);
|
||||||
|
quaternion.BindMethod("DotProduct", &Nz::Quaterniond::DotProduct);
|
||||||
|
quaternion.BindMethod("GetConjugate", &Nz::Quaterniond::GetConjugate);
|
||||||
|
quaternion.BindMethod("GetInverse", &Nz::Quaterniond::GetInverse);
|
||||||
|
|
||||||
|
quaternion.BindMethod("Inverse", &Nz::Quaterniond::Inverse);
|
||||||
|
quaternion.BindMethod("Magnitude", &Nz::Quaterniond::Magnitude);
|
||||||
|
|
||||||
|
quaternion.BindMethod("SquaredMagnitude", &Nz::Quaterniond::SquaredMagnitude);
|
||||||
|
quaternion.BindMethod("ToEulerAngles", &Nz::Quaterniond::ToEulerAngles);
|
||||||
|
|
||||||
|
quaternion.BindMethod("__tostring", &Nz::Quaterniond::ToString);
|
||||||
|
|
||||||
|
quaternion.BindStaticMethod("Lerp", &Nz::Quaterniond::Lerp);
|
||||||
|
quaternion.BindStaticMethod("RotationBetween", &Nz::Quaterniond::RotationBetween);
|
||||||
|
quaternion.BindStaticMethod("Slerp", &Nz::Quaterniond::Slerp);
|
||||||
|
|
||||||
|
quaternion.BindMethod("GetNormal", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
double length;
|
||||||
|
|
||||||
|
lua.Push(instance.GetNormal(&length));
|
||||||
|
lua.Push(length);
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.BindMethod("Normalize", [] (Nz::LuaInstance& lua, Nz::Quaterniond& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
double length;
|
||||||
|
|
||||||
|
instance.Normalize(&length);
|
||||||
|
lua.Push(1); //< instance
|
||||||
|
lua.Push(length);
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.BindStaticMethod("Normalize", [] (Nz::LuaInstance& instance) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 1;
|
||||||
|
Nz::Quaterniond quat = instance.Check<Nz::Quaterniond>(&argIndex);
|
||||||
|
|
||||||
|
double length;
|
||||||
|
|
||||||
|
instance.Push(Nz::Quaterniond::Normalize(quat, &length));
|
||||||
|
instance.Push(length);
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* wxyz = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
switch (wxyz[0])
|
||||||
|
{
|
||||||
|
case 'w':
|
||||||
|
lua.Push(instance.w);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'x':
|
||||||
|
lua.Push(instance.x);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
lua.Push(instance.z);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
quaternion.SetSetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* wxyz = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
double value = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
switch (wxyz[0])
|
||||||
|
{
|
||||||
|
case 'w':
|
||||||
|
instance.w = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'x':
|
||||||
|
instance.x = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.y = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
instance.z = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Vector2 **********************************/
|
||||||
|
vector2d.Reset("Vector2");
|
||||||
|
{
|
||||||
|
vector2d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector2d* vector, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||||
|
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||||
|
Nz::PlacementNew(vector, lua.CheckNumber(1));
|
||||||
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
|
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for Vector2 constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
vector2d.BindMethod("__tostring", &Nz::Vector2d::ToString);
|
||||||
|
|
||||||
|
vector2d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
long long index = lua.CheckInteger(2);
|
||||||
|
if (index < 1 || index > 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xy = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (xy[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
lua.Push(instance.x);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
vector2d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector2d& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
long long index = lua.CheckInteger(2);
|
||||||
|
if (index < 1 || index > 2)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
instance[index - 1] = lua.CheckNumber(3);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xy = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
double value = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
switch (xy[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
instance.x = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.y = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Vector3 **********************************/
|
||||||
|
vector3d.Reset("Vector3");
|
||||||
|
{
|
||||||
|
vector3d.SetConstructor([] (Nz::LuaInstance& lua, Nz::Vector3d* vector, std::size_t argumentCount)
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||||
|
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
case 3:
|
||||||
|
Nz::PlacementNew(vector, lua.CheckNumber(1, 0.0), lua.CheckNumber(2, 0.0), lua.CheckNumber(3, 0.0));
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||||
|
Nz::PlacementNew(vector, lua.CheckNumber(1));
|
||||||
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
|
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)));
|
||||||
|
else if (lua.IsOfType(1, "Vector3"))
|
||||||
|
Nz::PlacementNew(vector, *static_cast<Nz::Vector3d*>(lua.ToUserdata(1)));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(1, Nz::LuaType_Number))
|
||||||
|
Nz::PlacementNew(vector, lua.CheckNumber(1), *static_cast<Nz::Vector2d*>(lua.CheckUserdata(2, "Vector2")));
|
||||||
|
else if (lua.IsOfType(1, "Vector2"))
|
||||||
|
Nz::PlacementNew(vector, *static_cast<Nz::Vector2d*>(lua.ToUserdata(1)), lua.CheckNumber(2));
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for constructor");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
vector3d.BindMethod("__tostring", &Nz::Vector3d::ToString);
|
||||||
|
|
||||||
|
vector3d.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
long long index = lua.CheckInteger(2);
|
||||||
|
if (index < 1 || index > 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
lua.Push(instance[index - 1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xyz = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (xyz[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
lua.Push(instance.x);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
lua.Push(instance.y);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
lua.Push(instance.z);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
vector3d.SetSetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance)
|
||||||
|
{
|
||||||
|
switch (lua.GetType(2))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
long long index = lua.CheckInteger(2);
|
||||||
|
if (index < 1 || index > 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
instance[index - 1] = lua.CheckNumber(3);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* xyz = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (length != 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
double value = lua.CheckNumber(3);
|
||||||
|
|
||||||
|
switch (xyz[0])
|
||||||
|
{
|
||||||
|
case 'x':
|
||||||
|
instance.x = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
instance.y = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
instance.z = value;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the Math classes
|
||||||
|
*/
|
||||||
|
void LuaBinding_Math::Register(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
eulerAngles.Register(instance);
|
||||||
|
matrix4d.Register(instance);
|
||||||
|
quaternion.Register(instance);
|
||||||
|
rect.Register(instance);
|
||||||
|
vector2d.Register(instance);
|
||||||
|
vector3d.Register(instance);
|
||||||
|
|
||||||
|
quaternion.PushGlobalTable(instance);
|
||||||
|
{
|
||||||
|
instance.PushField("Identity", Nz::Quaterniond::Identity());
|
||||||
|
instance.PushField("Zero", Nz::Quaterniond::Zero());
|
||||||
|
}
|
||||||
|
instance.Pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,17 +1,21 @@
|
||||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
// This file was automatically generated on 26 May 2014 at 01:05:31
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
#include <NDK/Lua/LuaBinding_Network.hpp>
|
||||||
#include <NDK/LuaAPI.hpp>
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
/*!
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindNetwork(LuaBinding& binding)
|
||||||
* \brief Binds Network module to Lua
|
{
|
||||||
*/
|
return std::make_unique<LuaBinding_Network>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
void LuaBinding::BindNetwork()
|
LuaBinding_Network::LuaBinding_Network(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
{
|
{
|
||||||
/*********************************** Nz::AbstractSocket **********************************/
|
/*********************************** Nz::AbstractSocket **********************************/
|
||||||
|
abstractSocket.Reset("AbstractSocket");
|
||||||
|
{
|
||||||
abstractSocket.BindMethod("Close", &Nz::AbstractSocket::Close);
|
abstractSocket.BindMethod("Close", &Nz::AbstractSocket::Close);
|
||||||
abstractSocket.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
|
abstractSocket.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking);
|
||||||
abstractSocket.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
|
abstractSocket.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError);
|
||||||
|
|
@ -19,8 +23,11 @@ namespace Ndk
|
||||||
abstractSocket.BindMethod("GetType", &Nz::AbstractSocket::GetType);
|
abstractSocket.BindMethod("GetType", &Nz::AbstractSocket::GetType);
|
||||||
abstractSocket.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
|
abstractSocket.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled);
|
||||||
abstractSocket.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
|
abstractSocket.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes);
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************** Nz::IpAddress **********************************/
|
/*********************************** Nz::IpAddress **********************************/
|
||||||
|
ipAddress.Reset("IpAddress");
|
||||||
|
{
|
||||||
ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* instance, std::size_t argumentCount)
|
ipAddress.SetConstructor([] (Nz::LuaInstance& lua, Nz::IpAddress* instance, std::size_t argumentCount)
|
||||||
{
|
{
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 9U);
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 9U);
|
||||||
|
|
@ -135,14 +142,14 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Registers the classes that will be used by the Lua instance
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
*
|
*
|
||||||
* \param instance Lua instance that will interact with the Network classes
|
* \param instance Lua instance that will interact with the Network classes
|
||||||
*/
|
*/
|
||||||
|
void LuaBinding_Network::Register(Nz::LuaInstance& instance)
|
||||||
void LuaBinding::RegisterNetwork(Nz::LuaInstance& instance)
|
|
||||||
{
|
{
|
||||||
// Classes
|
// Classes
|
||||||
abstractSocket.Register(instance);
|
abstractSocket.Register(instance);
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Renderer.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Utility.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindRenderer(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Renderer>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Renderer::LuaBinding_Renderer(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
LuaBinding_Utility& utility = static_cast<LuaBinding_Utility&>(*m_binding.utility);
|
||||||
|
|
||||||
|
/*********************************** Nz::Texture ***********************************/
|
||||||
|
texture.Reset("Texture");
|
||||||
|
{
|
||||||
|
texture.Inherit<Nz::AbstractImageRef>(utility.abstractImage, [] (Nz::TextureRef* textureRef) -> Nz::AbstractImageRef*
|
||||||
|
{
|
||||||
|
return reinterpret_cast<Nz::AbstractImageRef*>(textureRef); //TODO: Make a ObjectRefCast
|
||||||
|
});
|
||||||
|
|
||||||
|
texture.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::TextureRef* instance, std::size_t /*argumentCount*/)
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Texture::New());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
texture.BindMethod("Create", &Nz::Texture::Create, static_cast<Nz::UInt8>(1), 1U);
|
||||||
|
texture.BindMethod("Destroy", &Nz::Texture::Destroy);
|
||||||
|
|
||||||
|
//texture.BindMethod("Download", &Nz::Texture::Download);
|
||||||
|
|
||||||
|
texture.BindMethod("EnableMipmapping", &Nz::Texture::EnableMipmapping);
|
||||||
|
texture.BindMethod("EnsureMipmapsUpdate", &Nz::Texture::EnsureMipmapsUpdate);
|
||||||
|
texture.BindMethod("HasMipmaps", &Nz::Texture::HasMipmaps);
|
||||||
|
texture.BindMethod("InvalidateMipmaps", &Nz::Texture::InvalidateMipmaps);
|
||||||
|
texture.BindMethod("IsValid", &Nz::Texture::IsValid);
|
||||||
|
|
||||||
|
texture.BindMethod("LoadFromFile", &Nz::Texture::LoadFromFile, true, Nz::ImageParams());
|
||||||
|
//bool LoadFromImage(const Image& image, bool generateMipmaps = true);
|
||||||
|
//bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||||
|
//bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||||
|
|
||||||
|
texture.BindMethod("LoadArrayFromFile", &Nz::Texture::LoadArrayFromFile, Nz::Vector2ui(2, 2), true, Nz::ImageParams());
|
||||||
|
//bool LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
//bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
//bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
|
||||||
|
//bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||||
|
//bool LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams());
|
||||||
|
//bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||||
|
//bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||||
|
|
||||||
|
texture.BindMethod("LoadFaceFromFile", &Nz::Texture::LoadFaceFromFile, Nz::ImageParams());
|
||||||
|
//bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||||
|
//bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams());
|
||||||
|
|
||||||
|
texture.BindMethod("SaveToFile", &Nz::Texture::SaveToFile, Nz::ImageParams());
|
||||||
|
//bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams());
|
||||||
|
|
||||||
|
texture.BindMethod("SetMipmapRange", &Nz::Texture::SetMipmapRange);
|
||||||
|
|
||||||
|
texture.BindStaticMethod("IsFormatSupported", &Nz::Texture::IsFormatSupported);
|
||||||
|
texture.BindStaticMethod("IsMipmappingSupported", &Nz::Texture::IsMipmappingSupported);
|
||||||
|
texture.BindStaticMethod("IsTypeSupported", &Nz::Texture::IsTypeSupported);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::TextureLibrary ***********************************/
|
||||||
|
textureLibrary.Reset("TextureLibrary");
|
||||||
|
{
|
||||||
|
textureLibrary.BindStaticMethod("Get", &Nz::TextureLibrary::Get);
|
||||||
|
textureLibrary.BindStaticMethod("Has", &Nz::TextureLibrary::Has);
|
||||||
|
textureLibrary.BindStaticMethod("Register", &Nz::TextureLibrary::Register);
|
||||||
|
textureLibrary.BindStaticMethod("Query", &Nz::TextureLibrary::Query);
|
||||||
|
textureLibrary.BindStaticMethod("Unregister", &Nz::TextureLibrary::Unregister);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::TextureManager ***********************************/
|
||||||
|
textureManager.Reset("textureManager");
|
||||||
|
{
|
||||||
|
textureManager.BindStaticMethod("Clear", &Nz::TextureManager::Clear);
|
||||||
|
textureManager.BindStaticMethod("Get", &Nz::TextureManager::Get);
|
||||||
|
textureManager.BindStaticMethod("GetDefaultParameters", &Nz::TextureManager::GetDefaultParameters);
|
||||||
|
textureManager.BindStaticMethod("Purge", &Nz::TextureManager::Purge);
|
||||||
|
textureManager.BindStaticMethod("Register", &Nz::TextureManager::Register);
|
||||||
|
textureManager.BindStaticMethod("SetDefaultParameters", &Nz::TextureManager::SetDefaultParameters);
|
||||||
|
textureManager.BindStaticMethod("Unregister", &Nz::TextureManager::Unregister);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the Renderer classes
|
||||||
|
*/
|
||||||
|
void LuaBinding_Renderer::Register(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
texture.Register(instance);
|
||||||
|
textureLibrary.Register(instance);
|
||||||
|
textureManager.Register(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,338 @@
|
||||||
|
// Copyright (C) 2016 Jérôme Leclercq, Arnaud Cadot
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_SDK.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
#include <NDK/Lua/LuaBinding_Utility.hpp>
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
#include <NDK/Lua/LuaBinding_Graphics.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindSDK(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_SDK>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_SDK::LuaBinding_SDK(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
LuaBinding_Graphics& graphics = static_cast<LuaBinding_Graphics&>(*m_binding.graphics);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LuaBinding_Utility& utility = static_cast<LuaBinding_Utility&>(*m_binding.utility);
|
||||||
|
|
||||||
|
/*********************************** Ndk::Application **********************************/
|
||||||
|
application.Reset("Application");
|
||||||
|
{
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
//application.SetMethod("AddWindow", &Application::AddWindow);
|
||||||
|
|
||||||
|
application.BindMethod("EnableConsole", &Application::EnableConsole);
|
||||||
|
application.BindMethod("EnableFPSCounter", &Application::EnableFPSCounter);
|
||||||
|
|
||||||
|
application.BindMethod("IsConsoleEnabled", &Application::IsConsoleEnabled);
|
||||||
|
application.BindMethod("IsFPSCounterEnabled", &Application::IsFPSCounterEnabled);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
application.BindMethod("AddWorld", [] (Nz::LuaInstance& lua, Application* instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
lua.Push(instance->AddWorld().CreateHandle());
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
application.BindMethod("GetUpdateTime", &Application::GetUpdateTime);
|
||||||
|
application.BindMethod("Quit", &Application::Quit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Ndk::Console **********************************/
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
console.Reset("Console");
|
||||||
|
{
|
||||||
|
console.Inherit<Nz::Node>(utility.node, [] (ConsoleHandle* handle) -> Nz::Node*
|
||||||
|
{
|
||||||
|
return handle->GetObject();
|
||||||
|
});
|
||||||
|
|
||||||
|
console.BindMethod("AddLine", &Console::AddLine, Nz::Color::White);
|
||||||
|
console.BindMethod("Clear", &Console::Clear);
|
||||||
|
console.BindMethod("GetCharacterSize", &Console::GetCharacterSize);
|
||||||
|
console.BindMethod("GetHistory", &Console::GetHistory);
|
||||||
|
console.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground);
|
||||||
|
console.BindMethod("GetInput", &Console::GetInput);
|
||||||
|
console.BindMethod("GetInputBackground", &Console::GetInputBackground);
|
||||||
|
console.BindMethod("GetSize", &Console::GetSize);
|
||||||
|
console.BindMethod("GetTextFont", &Console::GetTextFont);
|
||||||
|
|
||||||
|
console.BindMethod("IsVisible", &Console::IsVisible);
|
||||||
|
|
||||||
|
console.BindMethod("SendCharacter", &Console::SendCharacter);
|
||||||
|
//consoleClass.SetMethod("SendEvent", &Console::SendEvent);
|
||||||
|
|
||||||
|
console.BindMethod("SetCharacterSize", &Console::SetCharacterSize);
|
||||||
|
console.BindMethod("SetSize", &Console::SetSize);
|
||||||
|
console.BindMethod("SetTextFont", &Console::SetTextFont);
|
||||||
|
|
||||||
|
console.BindMethod("Show", &Console::Show, true);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*********************************** Ndk::Entity **********************************/
|
||||||
|
entity.Reset("Entity");
|
||||||
|
{
|
||||||
|
entity.BindMethod("Enable", &Entity::Enable, true);
|
||||||
|
entity.BindMethod("GetId", &Entity::GetId);
|
||||||
|
entity.BindMethod("GetWorld", &Entity::GetWorld);
|
||||||
|
entity.BindMethod("Kill", &Entity::Kill);
|
||||||
|
entity.BindMethod("IsEnabled", &Entity::IsEnabled);
|
||||||
|
entity.BindMethod("IsValid", &Entity::IsValid);
|
||||||
|
entity.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents);
|
||||||
|
entity.BindMethod("__tostring", &EntityHandle::ToString);
|
||||||
|
|
||||||
|
entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
||||||
|
|
||||||
|
return binding->adder(instance, handle);
|
||||||
|
});
|
||||||
|
|
||||||
|
entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
||||||
|
|
||||||
|
return binding->getter(instance, handle->GetComponent(binding->index));
|
||||||
|
});
|
||||||
|
|
||||||
|
entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
||||||
|
|
||||||
|
handle->RemoveComponent(binding->index);
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Ndk::NodeComponent **********************************/
|
||||||
|
nodeComponent.Reset("NodeComponent");
|
||||||
|
{
|
||||||
|
nodeComponent.Inherit<Nz::Node>(utility.node, [] (NodeComponentHandle* handle) -> Nz::Node*
|
||||||
|
{
|
||||||
|
return handle->GetObject();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Ndk::VelocityComponent **********************************/
|
||||||
|
velocityComponent.Reset("VelocityComponent");
|
||||||
|
{
|
||||||
|
velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* member = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
if (std::strcmp(member, "Linear") == 0)
|
||||||
|
{
|
||||||
|
lua.Push(instance->linearVelocity);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance)
|
||||||
|
{
|
||||||
|
std::size_t length;
|
||||||
|
const char* member = lua.CheckString(2, &length);
|
||||||
|
|
||||||
|
int argIndex = 3;
|
||||||
|
if (std::strcmp(member, "Linear") == 0)
|
||||||
|
{
|
||||||
|
instance->linearVelocity = lua.Check<Nz::Vector3f>(&argIndex);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Ndk::World **********************************/
|
||||||
|
world.Reset("World");
|
||||||
|
{
|
||||||
|
world.BindMethod("CreateEntity", &World::CreateEntity);
|
||||||
|
world.BindMethod("CreateEntities", &World::CreateEntities);
|
||||||
|
world.BindMethod("Clear", &World::Clear);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
/*********************************** Ndk::CameraComponent **********************************/
|
||||||
|
cameraComponent.Reset("CameraComponent");
|
||||||
|
{
|
||||||
|
cameraComponent.Inherit<Nz::AbstractViewer>(graphics.abstractViewer, [] (CameraComponentHandle* handle) -> Nz::AbstractViewer*
|
||||||
|
{
|
||||||
|
return handle->GetObject();
|
||||||
|
});
|
||||||
|
|
||||||
|
cameraComponent.BindMethod("GetFOV", &Ndk::CameraComponent::GetFOV);
|
||||||
|
cameraComponent.BindMethod("GetLayer", &Ndk::CameraComponent::GetLayer);
|
||||||
|
|
||||||
|
cameraComponent.BindMethod("SetFOV", &Ndk::CameraComponent::SetFOV);
|
||||||
|
cameraComponent.BindMethod("SetLayer", &Ndk::CameraComponent::SetLayer);
|
||||||
|
cameraComponent.BindMethod("SetProjectionType", &Ndk::CameraComponent::SetProjectionType);
|
||||||
|
cameraComponent.BindMethod("SetSize", (void(Ndk::CameraComponent::*)(const Nz::Vector2f&)) &Ndk::CameraComponent::SetSize);
|
||||||
|
//cameraComponent.BindMethod("SetTarget", &Ndk::CameraComponent::SetTarget);
|
||||||
|
cameraComponent.BindMethod("SetTargetRegion", &Ndk::CameraComponent::SetTargetRegion);
|
||||||
|
cameraComponent.BindMethod("SetViewport", &Ndk::CameraComponent::SetViewport);
|
||||||
|
cameraComponent.BindMethod("SetZFar", &Ndk::CameraComponent::SetZFar);
|
||||||
|
cameraComponent.BindMethod("SetZNear", &Ndk::CameraComponent::SetZNear);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Ndk::GraphicsComponent **********************************/
|
||||||
|
graphicsComponent.Reset("GraphicsComponent");
|
||||||
|
{
|
||||||
|
graphicsComponent.BindMethod("Attach", [] (Nz::LuaInstance& lua, Ndk::GraphicsComponent* instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||||
|
void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
|
||||||
|
*/
|
||||||
|
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 3U);
|
||||||
|
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
instance->Attach(lua.Check<Nz::InstancedRenderableRef>(&argIndex));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
||||||
|
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
{
|
||||||
|
int renderOrder = lua.Check<int>(&argIndex);
|
||||||
|
|
||||||
|
instance->Attach(renderable, renderOrder);
|
||||||
|
}
|
||||||
|
else if (lua.IsOfType(argIndex, "Matrix4"))
|
||||||
|
{
|
||||||
|
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
||||||
|
|
||||||
|
instance->Attach(renderable, localMatrix);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
Nz::InstancedRenderableRef renderable = lua.Check<Nz::InstancedRenderableRef>(&argIndex);
|
||||||
|
Nz::Matrix4f localMatrix = lua.Check<Nz::Matrix4f>(&argIndex);
|
||||||
|
int renderOrder = lua.Check<int>(&argIndex);
|
||||||
|
|
||||||
|
instance->Attach(renderable, localMatrix, renderOrder);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method GetMemoryUsage");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Components functions
|
||||||
|
m_binding.BindComponent<NodeComponent>("Node");
|
||||||
|
m_binding.BindComponent<VelocityComponent>("Velocity");
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
m_binding.BindComponent<CameraComponent>("Camera");
|
||||||
|
m_binding.BindComponent<GraphicsComponent>("Graphics");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the SDK classes
|
||||||
|
*/
|
||||||
|
void LuaBinding_SDK::Register(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
// Classes
|
||||||
|
application.Register(instance);
|
||||||
|
entity.Register(instance);
|
||||||
|
nodeComponent.Register(instance);
|
||||||
|
velocityComponent.Register(instance);
|
||||||
|
world.Register(instance);
|
||||||
|
|
||||||
|
#ifndef NDK_SERVER
|
||||||
|
cameraComponent.Register(instance);
|
||||||
|
console.Register(instance);
|
||||||
|
graphicsComponent.Register(instance);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets the index of the component
|
||||||
|
* \return A pointer to the binding linked to a component
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the component
|
||||||
|
* \param argIndex Index of the component
|
||||||
|
*/
|
||||||
|
LuaBinding::ComponentBinding* LuaBinding::QueryComponentIndex(Nz::LuaInstance& instance, int argIndex)
|
||||||
|
{
|
||||||
|
switch (instance.GetType(argIndex))
|
||||||
|
{
|
||||||
|
case Nz::LuaType_Number:
|
||||||
|
{
|
||||||
|
ComponentIndex componentIndex = instance.Check<ComponentIndex>(&argIndex);
|
||||||
|
if (componentIndex > m_componentBinding.size())
|
||||||
|
{
|
||||||
|
instance.Error("Invalid component index");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ComponentBinding& binding = m_componentBinding[componentIndex];
|
||||||
|
if (binding.name.IsEmpty())
|
||||||
|
{
|
||||||
|
instance.Error("Invalid component index");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &binding;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::LuaType_String:
|
||||||
|
{
|
||||||
|
const char* key = instance.CheckString(argIndex);
|
||||||
|
auto it = m_componentBindingByName.find(key);
|
||||||
|
if (it == m_componentBindingByName.end())
|
||||||
|
{
|
||||||
|
instance.Error("Invalid component name");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &m_componentBinding[it->second];
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.Error("Invalid component index at #" + Nz::String::Number(argIndex));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,446 @@
|
||||||
|
// This file is part of the "Nazara Development Kit"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||||
|
|
||||||
|
#include <NDK/Lua/LuaBinding_Utility.hpp>
|
||||||
|
#include <NDK/LuaAPI.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
std::unique_ptr<LuaBinding_Base> LuaBinding_Base::BindUtility(LuaBinding& binding)
|
||||||
|
{
|
||||||
|
return std::make_unique<LuaBinding_Utility>(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaBinding_Utility::LuaBinding_Utility(LuaBinding& binding) :
|
||||||
|
LuaBinding_Base(binding)
|
||||||
|
{
|
||||||
|
/*********************************** Nz::AbstractImage **********************************/
|
||||||
|
abstractImage.Reset("AbstractImage");
|
||||||
|
{
|
||||||
|
abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
||||||
|
abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
||||||
|
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
||||||
|
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
||||||
|
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
||||||
|
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
||||||
|
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
||||||
|
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
|
||||||
|
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
||||||
|
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
||||||
|
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
||||||
|
|
||||||
|
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return lua.Push(instance->GetMemoryUsage());
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
Nz::UInt8 level(lua.Check<Nz::UInt8>(&argIndex));
|
||||||
|
|
||||||
|
return lua.Push(instance->GetMemoryUsage(level));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method GetMemoryUsage");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 6U);
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
std::size_t bufferSize = 0;
|
||||||
|
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
||||||
|
|
||||||
|
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
||||||
|
{
|
||||||
|
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||||
|
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||||
|
|
||||||
|
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||||
|
return lua.Push(instance->Update(pixels, srcWidth, srcHeight, level));
|
||||||
|
}
|
||||||
|
/* Disabled until Box and Rect have been ported
|
||||||
|
else if (lua.IsOfType(2, "Box"))
|
||||||
|
{
|
||||||
|
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||||
|
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
||||||
|
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||||
|
|
||||||
|
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||||
|
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||||
|
}
|
||||||
|
else if (lua.IsOfType(2, "Rect"))
|
||||||
|
{
|
||||||
|
// bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
||||||
|
Nz::Rectui box = lua.Check<Nz::Rectui>(&argIndex);
|
||||||
|
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
||||||
|
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
||||||
|
|
||||||
|
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
||||||
|
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method Update");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Font **********************************/
|
||||||
|
font.Reset("Font");
|
||||||
|
{
|
||||||
|
font.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* instance, std::size_t /*argumentCount*/)
|
||||||
|
{
|
||||||
|
Nz::PlacementNew(instance, Nz::Font::New());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
font.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache);
|
||||||
|
font.BindMethod("ClearKerningCache", &Nz::Font::ClearKerningCache);
|
||||||
|
font.BindMethod("ClearSizeInfoCache", &Nz::Font::ClearSizeInfoCache);
|
||||||
|
|
||||||
|
font.BindMethod("Destroy", &Nz::Font::Destroy);
|
||||||
|
|
||||||
|
font.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
lua.Push(instance->GetCachedGlyphCount());
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
unsigned int characterSize = lua.Check<unsigned int>(&argIndex);
|
||||||
|
Nz::UInt32 style = lua.Check<Nz::UInt32>(&argIndex);
|
||||||
|
|
||||||
|
lua.Push(instance->GetCachedGlyphCount(characterSize, style));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method GetCachedGlyphCount");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
font.BindMethod("GetFamilyName", &Nz::Font::GetFamilyName);
|
||||||
|
font.BindMethod("GetKerning", &Nz::Font::GetKerning);
|
||||||
|
font.BindMethod("GetGlyphBorder", &Nz::Font::GetGlyphBorder);
|
||||||
|
font.BindMethod("GetMinimumStepSize", &Nz::Font::GetMinimumStepSize);
|
||||||
|
font.BindMethod("GetSizeInfo", &Nz::Font::GetSizeInfo);
|
||||||
|
font.BindMethod("GetStyleName", &Nz::Font::GetStyleName);
|
||||||
|
|
||||||
|
font.BindMethod("IsValid", &Nz::Font::IsValid);
|
||||||
|
|
||||||
|
font.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::UInt32, const Nz::String&) const) &Nz::Font::Precache);
|
||||||
|
|
||||||
|
font.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams());
|
||||||
|
|
||||||
|
font.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder);
|
||||||
|
font.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize);
|
||||||
|
|
||||||
|
font.BindStaticMethod("GetDefault", &Nz::Font::GetDefault);
|
||||||
|
font.BindStaticMethod("GetDefaultGlyphBorder", &Nz::Font::GetDefaultGlyphBorder);
|
||||||
|
font.BindStaticMethod("GetDefaultMinimumStepSize", &Nz::Font::GetDefaultMinimumStepSize);
|
||||||
|
|
||||||
|
font.BindStaticMethod("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder);
|
||||||
|
font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Keyboard **********************************/
|
||||||
|
keyboard.Reset("Keyboard");
|
||||||
|
{
|
||||||
|
keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName);
|
||||||
|
keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************** Nz::Node **********************************/
|
||||||
|
node.Reset("Node");
|
||||||
|
{
|
||||||
|
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||||
|
//nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds);
|
||||||
|
node.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||||
|
node.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||||
|
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||||
|
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||||
|
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||||
|
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||||
|
//nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||||
|
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||||
|
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||||
|
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||||
|
//nodeClass.SetMethod("GetParent", &Nz::Node::GetParent);
|
||||||
|
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||||
|
node.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||||
|
//nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||||
|
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||||
|
//nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix);
|
||||||
|
node.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||||
|
|
||||||
|
node.BindMethod("HasChilds", &Nz::Node::HasChilds);
|
||||||
|
|
||||||
|
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
||||||
|
node.BindMethod("GetDown", &Nz::Node::GetDown);
|
||||||
|
node.BindMethod("GetForward", &Nz::Node::GetForward);
|
||||||
|
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
||||||
|
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
||||||
|
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
||||||
|
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
||||||
|
node.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
||||||
|
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
||||||
|
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
||||||
|
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
||||||
|
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
||||||
|
node.BindMethod("GetRight", &Nz::Node::GetRight);
|
||||||
|
node.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
||||||
|
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
||||||
|
node.BindMethod("GetUp", &Nz::Node::GetUp);
|
||||||
|
|
||||||
|
node.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
|
||||||
|
node.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation);
|
||||||
|
|
||||||
|
node.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
|
||||||
|
node.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
|
||||||
|
|
||||||
|
node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
instance.Move(offset, coordSys);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
||||||
|
{
|
||||||
|
int argIndex = 2;
|
||||||
|
|
||||||
|
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
instance.Rotate(rotation, coordSys);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
instance.Scale(lua.Check<float>(&argIndex));
|
||||||
|
else
|
||||||
|
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method Scale");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
{
|
||||||
|
float scale = lua.Check<float>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
instance.SetScale(scale, coordSys);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
instance.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
||||||
|
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
||||||
|
|
||||||
|
instance.SetScale(scale, coordSys);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method SetScale");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
||||||
|
{
|
||||||
|
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
||||||
|
|
||||||
|
int argIndex = 2;
|
||||||
|
switch (argCount)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
||||||
|
instance.SetInitialScale(lua.Check<float>(&argIndex));
|
||||||
|
else
|
||||||
|
instance.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
instance.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua.Error("No matching overload for method SetInitialScale");
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Registers the classes that will be used by the Lua instance
|
||||||
|
*
|
||||||
|
* \param instance Lua instance that will interact with the Utility classes
|
||||||
|
*/
|
||||||
|
void LuaBinding_Utility::Register(Nz::LuaInstance& instance)
|
||||||
|
{
|
||||||
|
abstractImage.Register(instance);
|
||||||
|
font.Register(instance);
|
||||||
|
keyboard.Register(instance);
|
||||||
|
node.Register(instance);
|
||||||
|
|
||||||
|
keyboard.PushGlobalTable(instance);
|
||||||
|
{
|
||||||
|
static_assert(Nz::Keyboard::Count == 121, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding");
|
||||||
|
|
||||||
|
instance.PushField("Undefined", Nz::Keyboard::Undefined);
|
||||||
|
|
||||||
|
// A-Z
|
||||||
|
for (std::size_t i = 0; i < 26; ++i)
|
||||||
|
instance.PushField(Nz::String('A' + char(i)), Nz::Keyboard::A + i);
|
||||||
|
|
||||||
|
// Numerical
|
||||||
|
for (std::size_t i = 0; i < 10; ++i)
|
||||||
|
{
|
||||||
|
instance.PushField("Num" + Nz::String::Number(i), Nz::Keyboard::Num0 + i);
|
||||||
|
instance.PushField("Numpad" + Nz::String::Number(i), Nz::Keyboard::Numpad0 + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// F1-F15
|
||||||
|
for (std::size_t i = 0; i < 15; ++i)
|
||||||
|
instance.PushField('F' + Nz::String::Number(i+1), Nz::Keyboard::F1 + i);
|
||||||
|
|
||||||
|
// And all the others...
|
||||||
|
instance.PushField("Down", Nz::Keyboard::Down);
|
||||||
|
instance.PushField("Left", Nz::Keyboard::Left);
|
||||||
|
instance.PushField("Right", Nz::Keyboard::Right);
|
||||||
|
instance.PushField("Up", Nz::Keyboard::Up);
|
||||||
|
|
||||||
|
instance.PushField("Add", Nz::Keyboard::Add);
|
||||||
|
instance.PushField("Decimal", Nz::Keyboard::Decimal);
|
||||||
|
instance.PushField("Divide", Nz::Keyboard::Divide);
|
||||||
|
instance.PushField("Multiply", Nz::Keyboard::Multiply);
|
||||||
|
instance.PushField("Subtract", Nz::Keyboard::Subtract);
|
||||||
|
|
||||||
|
instance.PushField("Backslash", Nz::Keyboard::Backslash);
|
||||||
|
instance.PushField("Backspace", Nz::Keyboard::Backspace);
|
||||||
|
instance.PushField("Clear", Nz::Keyboard::Clear);
|
||||||
|
instance.PushField("Comma", Nz::Keyboard::Comma);
|
||||||
|
instance.PushField("Dash", Nz::Keyboard::Dash);
|
||||||
|
instance.PushField("Delete", Nz::Keyboard::Delete);
|
||||||
|
instance.PushField("End", Nz::Keyboard::End);
|
||||||
|
instance.PushField("Equal", Nz::Keyboard::Equal);
|
||||||
|
instance.PushField("Escape", Nz::Keyboard::Escape);
|
||||||
|
instance.PushField("Home", Nz::Keyboard::Home);
|
||||||
|
instance.PushField("Insert", Nz::Keyboard::Insert);
|
||||||
|
instance.PushField("LAlt", Nz::Keyboard::LAlt);
|
||||||
|
instance.PushField("LBracket", Nz::Keyboard::LBracket);
|
||||||
|
instance.PushField("LControl", Nz::Keyboard::LControl);
|
||||||
|
instance.PushField("LShift", Nz::Keyboard::LShift);
|
||||||
|
instance.PushField("LSystem", Nz::Keyboard::LSystem);
|
||||||
|
instance.PushField("PageDown", Nz::Keyboard::PageDown);
|
||||||
|
instance.PushField("PageUp", Nz::Keyboard::PageUp);
|
||||||
|
instance.PushField("Pause", Nz::Keyboard::Pause);
|
||||||
|
instance.PushField("Period", Nz::Keyboard::Period);
|
||||||
|
instance.PushField("Print", Nz::Keyboard::Print);
|
||||||
|
instance.PushField("PrintScreen", Nz::Keyboard::PrintScreen);
|
||||||
|
instance.PushField("Quote", Nz::Keyboard::Quote);
|
||||||
|
instance.PushField("RAlt", Nz::Keyboard::RAlt);
|
||||||
|
instance.PushField("RBracket", Nz::Keyboard::RBracket);
|
||||||
|
instance.PushField("RControl", Nz::Keyboard::RControl);
|
||||||
|
instance.PushField("Return", Nz::Keyboard::Return);
|
||||||
|
instance.PushField("RShift", Nz::Keyboard::RShift);
|
||||||
|
instance.PushField("RSystem", Nz::Keyboard::RSystem);
|
||||||
|
instance.PushField("Semicolon", Nz::Keyboard::Semicolon);
|
||||||
|
instance.PushField("Slash", Nz::Keyboard::Slash);
|
||||||
|
instance.PushField("Space", Nz::Keyboard::Space);
|
||||||
|
instance.PushField("Tab", Nz::Keyboard::Tab);
|
||||||
|
instance.PushField("Tilde", Nz::Keyboard::Tilde);
|
||||||
|
instance.PushField("Browser_Back", Nz::Keyboard::Browser_Back);
|
||||||
|
instance.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites);
|
||||||
|
instance.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward);
|
||||||
|
instance.PushField("Browser_Home", Nz::Keyboard::Browser_Home);
|
||||||
|
instance.PushField("Browser_Refresh", Nz::Keyboard::Browser_Refresh);
|
||||||
|
instance.PushField("Browser_Search", Nz::Keyboard::Browser_Search);
|
||||||
|
instance.PushField("Browser_Stop", Nz::Keyboard::Browser_Stop);
|
||||||
|
instance.PushField("Media_Next", Nz::Keyboard::Media_Next);
|
||||||
|
instance.PushField("Media_Play", Nz::Keyboard::Media_Play);
|
||||||
|
instance.PushField("Media_Previous", Nz::Keyboard::Media_Previous);
|
||||||
|
instance.PushField("Media_Stop", Nz::Keyboard::Media_Stop);
|
||||||
|
instance.PushField("Volume_Down", Nz::Keyboard::Volume_Down);
|
||||||
|
instance.PushField("Volume_Mute", Nz::Keyboard::Volume_Mute);
|
||||||
|
instance.PushField("Volume_Up", Nz::Keyboard::Volume_Up);
|
||||||
|
instance.PushField("CapsLock", Nz::Keyboard::CapsLock);
|
||||||
|
instance.PushField("NumLock", Nz::Keyboard::NumLock);
|
||||||
|
instance.PushField("ScrollLock", Nz::Keyboard::ScrollLock);
|
||||||
|
}
|
||||||
|
instance.Pop();
|
||||||
|
|
||||||
|
static_assert(Nz::WindowStyle_Max + 1 == 6, "Nz::WindowStyle has been updated but change was not reflected to Lua binding");
|
||||||
|
instance.PushTable(0, Nz::WindowStyle_Max + 1);
|
||||||
|
{
|
||||||
|
instance.PushField("None", Nz::WindowStyle_None);
|
||||||
|
instance.PushField("Fullscreen", Nz::WindowStyle_Fullscreen);
|
||||||
|
instance.PushField("Closable", Nz::WindowStyle_Closable);
|
||||||
|
instance.PushField("Resizable", Nz::WindowStyle_Resizable);
|
||||||
|
instance.PushField("Titlebar", Nz::WindowStyle_Titlebar);
|
||||||
|
instance.PushField("Threaded", Nz::WindowStyle_Threaded);
|
||||||
|
}
|
||||||
|
instance.SetGlobal("WindowStyle");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
#include <NDK/LuaAPI.hpp>
|
||||||
#include <Nazara/Core/ErrorFlags.hpp>
|
#include <Nazara/Core/ErrorFlags.hpp>
|
||||||
#include <NDK/LuaBinding.hpp>
|
#include <NDK/Lua/LuaBinding.hpp>
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,341 +0,0 @@
|
||||||
// This file was automatically generated on 26 May 2014 at 01:05:31
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <Nazara/Core/MemoryHelper.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds Core module to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::BindCore()
|
|
||||||
{
|
|
||||||
/*********************************** Nz::Clock **********************************/
|
|
||||||
clock.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Nz::PlacementNew(instance);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
|
||||||
|
|
||||||
Nz::PlacementNew(instance, startingValue);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);
|
|
||||||
bool paused = lua.Check<bool>(&argIndex, false);
|
|
||||||
|
|
||||||
Nz::PlacementNew(instance, startingValue, paused);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for Clock constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
clock.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds);
|
|
||||||
clock.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds);
|
|
||||||
clock.BindMethod("GetSeconds", &Nz::Clock::GetSeconds);
|
|
||||||
clock.BindMethod("IsPaused", &Nz::Clock::IsPaused);
|
|
||||||
clock.BindMethod("Pause", &Nz::Clock::Pause);
|
|
||||||
clock.BindMethod("Restart", &Nz::Clock::Restart);
|
|
||||||
clock.BindMethod("Unpause", &Nz::Clock::Unpause);
|
|
||||||
|
|
||||||
// Manual
|
|
||||||
clock.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
Nz::StringStream ss("Clock(Elapsed: ");
|
|
||||||
ss << instance.GetSeconds();
|
|
||||||
ss << "s, Paused: ";
|
|
||||||
ss << instance.IsPaused();
|
|
||||||
ss << ')';
|
|
||||||
|
|
||||||
lua.PushString(ss);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
/********************************* Nz::Directory ********************************/
|
|
||||||
directory.SetConstructor([](Nz::LuaInstance& lua, Nz::Directory* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Nz::PlacementNew(instance);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
Nz::PlacementNew(instance, lua.Check<Nz::String>(&argIndex));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
directory.BindMethod("Close", &Nz::Directory::Close);
|
|
||||||
directory.BindMethod("Exists", &Nz::Directory::Exists);
|
|
||||||
directory.BindMethod("GetPath", &Nz::Directory::GetPath);
|
|
||||||
directory.BindMethod("GetPattern", &Nz::Directory::GetPattern);
|
|
||||||
directory.BindMethod("GetResultName", &Nz::Directory::GetResultName);
|
|
||||||
directory.BindMethod("GetResultPath", &Nz::Directory::GetResultPath);
|
|
||||||
directory.BindMethod("GetResultSize", &Nz::Directory::GetResultSize);
|
|
||||||
directory.BindMethod("IsOpen", &Nz::Directory::IsOpen);
|
|
||||||
directory.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory);
|
|
||||||
directory.BindMethod("NextResult", &Nz::Directory::NextResult, true);
|
|
||||||
directory.BindMethod("Open", &Nz::Directory::Open);
|
|
||||||
directory.BindMethod("SetPath", &Nz::Directory::SetPath);
|
|
||||||
directory.BindMethod("SetPattern", &Nz::Directory::SetPattern);
|
|
||||||
|
|
||||||
directory.BindStaticMethod("Copy", Nz::Directory::Copy);
|
|
||||||
directory.BindStaticMethod("Create", Nz::Directory::Create);
|
|
||||||
directory.BindStaticMethod("Exists", Nz::Directory::Exists);
|
|
||||||
directory.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent);
|
|
||||||
directory.BindStaticMethod("Remove", Nz::Directory::Remove);
|
|
||||||
directory.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent);
|
|
||||||
|
|
||||||
// Manual
|
|
||||||
directory.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
Nz::StringStream ss("Directory(");
|
|
||||||
ss << instance.GetPath();
|
|
||||||
ss << ')';
|
|
||||||
|
|
||||||
lua.PushString(ss);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::Stream ***********************************/
|
|
||||||
stream.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode);
|
|
||||||
stream.BindMethod("Flush", &Nz::Stream::Flush);
|
|
||||||
stream.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos);
|
|
||||||
stream.BindMethod("GetDirectory", &Nz::Stream::GetDirectory);
|
|
||||||
stream.BindMethod("GetPath", &Nz::Stream::GetPath);
|
|
||||||
stream.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode);
|
|
||||||
stream.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions);
|
|
||||||
stream.BindMethod("GetSize", &Nz::Stream::GetSize);
|
|
||||||
stream.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U);
|
|
||||||
stream.BindMethod("IsReadable", &Nz::Stream::IsReadable);
|
|
||||||
stream.BindMethod("IsSequential", &Nz::Stream::IsSequential);
|
|
||||||
stream.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled);
|
|
||||||
stream.BindMethod("IsWritable", &Nz::Stream::IsWritable);
|
|
||||||
stream.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos);
|
|
||||||
|
|
||||||
stream.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
std::size_t length = lua.Check<std::size_t>(&argIndex);
|
|
||||||
|
|
||||||
std::unique_ptr<char[]> buffer(new char[length]);
|
|
||||||
std::size_t readLength = instance.Read(buffer.get(), length);
|
|
||||||
|
|
||||||
lua.PushString(Nz::String(buffer.get(), readLength));
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
stream.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
std::size_t bufferSize = 0;
|
|
||||||
const char* buffer = lua.CheckString(argIndex, &bufferSize);
|
|
||||||
|
|
||||||
if (instance.IsTextModeEnabled())
|
|
||||||
lua.Push(instance.Write(Nz::String(buffer, bufferSize)));
|
|
||||||
else
|
|
||||||
lua.Push(instance.Write(buffer, bufferSize));
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::File ***********************************/
|
|
||||||
file.Inherit(stream);
|
|
||||||
|
|
||||||
file.SetConstructor([] (Nz::LuaInstance& lua, Nz::File* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Nz::PlacementNew(instance);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
|
||||||
|
|
||||||
Nz::PlacementNew(instance, filePath);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
|
||||||
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex);
|
|
||||||
|
|
||||||
Nz::PlacementNew(instance, filePath, openMode);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for File constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
file.BindMethod("Close", &Nz::File::Close);
|
|
||||||
file.BindMethod("Copy", &Nz::File::Copy);
|
|
||||||
file.BindMethod("Delete", &Nz::File::Delete);
|
|
||||||
file.BindMethod("EndOfFile", &Nz::File::EndOfFile);
|
|
||||||
file.BindMethod("Exists", &Nz::File::Exists);
|
|
||||||
file.BindMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
|
||||||
file.BindMethod("GetFileName", &Nz::File::GetFileName);
|
|
||||||
file.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
|
||||||
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
|
||||||
file.BindMethod("IsOpen", &Nz::File::IsOpen);
|
|
||||||
file.BindMethod("Rename", &Nz::File::GetLastWriteTime);
|
|
||||||
file.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
|
||||||
file.BindMethod("SetFile", &Nz::File::GetLastWriteTime);
|
|
||||||
|
|
||||||
file.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath);
|
|
||||||
file.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash);
|
|
||||||
file.BindStaticMethod("Copy", &Nz::File::Copy);
|
|
||||||
file.BindStaticMethod("Delete", &Nz::File::Delete);
|
|
||||||
file.BindStaticMethod("Exists", &Nz::File::Exists);
|
|
||||||
//fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime);
|
|
||||||
file.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory);
|
|
||||||
//fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime);
|
|
||||||
//fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime);
|
|
||||||
file.BindStaticMethod("GetSize", &Nz::File::GetSize);
|
|
||||||
file.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute);
|
|
||||||
file.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath);
|
|
||||||
file.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators);
|
|
||||||
file.BindStaticMethod("Rename", &Nz::File::Rename);
|
|
||||||
|
|
||||||
// Manual
|
|
||||||
file.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
case 1:
|
|
||||||
return lua.Push(instance.Open(lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen)));
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
Nz::String filePath = lua.Check<Nz::String>(&argIndex);
|
|
||||||
Nz::UInt32 openMode = lua.Check<Nz::UInt32>(&argIndex, Nz::OpenMode_NotOpen);
|
|
||||||
return lua.Push(instance.Open(filePath, openMode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method Open");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
file.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
return lua.Push(instance.SetCursorPos(lua.Check<Nz::UInt64>(&argIndex)));
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
Nz::CursorPosition curPos = lua.Check<Nz::CursorPosition>(&argIndex);
|
|
||||||
Nz::Int64 offset = lua.Check<Nz::Int64>(&argIndex);
|
|
||||||
return lua.Push(instance.SetCursorPos(curPos, offset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method SetCursorPos");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
file.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& instance, std::size_t /*argumentCount*/) -> int {
|
|
||||||
Nz::StringStream ss("File(");
|
|
||||||
if (instance.IsOpen())
|
|
||||||
ss << "Path: " << instance.GetPath();
|
|
||||||
|
|
||||||
ss << ')';
|
|
||||||
|
|
||||||
lua.PushString(ss);
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Registers the classes that will be used by the Lua instance
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the Core classes
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::RegisterCore(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
// Classes
|
|
||||||
clock.Register(instance);
|
|
||||||
directory.Register(instance);
|
|
||||||
file.Register(instance);
|
|
||||||
stream.Register(instance);
|
|
||||||
|
|
||||||
// Enums
|
|
||||||
|
|
||||||
// Nz::CursorPosition
|
|
||||||
static_assert(Nz::CursorPosition_Max + 1 == 3, "Nz::CursorPosition has been updated but change was not reflected to Lua binding");
|
|
||||||
instance.PushTable(0, 3);
|
|
||||||
{
|
|
||||||
instance.PushField("AtBegin", Nz::CursorPosition_AtBegin);
|
|
||||||
instance.PushField("AtCurrent", Nz::CursorPosition_AtCurrent);
|
|
||||||
instance.PushField("AtEnd", Nz::CursorPosition_AtEnd);
|
|
||||||
}
|
|
||||||
instance.SetGlobal("CursorPosition");
|
|
||||||
|
|
||||||
// Nz::HashType
|
|
||||||
static_assert(Nz::HashType_Max + 1 == 9, "Nz::HashType has been updated but change was not reflected to Lua binding");
|
|
||||||
instance.PushTable(0, 9);
|
|
||||||
{
|
|
||||||
instance.PushField("CRC32", Nz::HashType_CRC32);
|
|
||||||
instance.PushField("Fletcher16", Nz::HashType_Fletcher16);
|
|
||||||
instance.PushField("MD5", Nz::HashType_MD5);
|
|
||||||
instance.PushField("SHA1", Nz::HashType_SHA1);
|
|
||||||
instance.PushField("SHA224", Nz::HashType_SHA224);
|
|
||||||
instance.PushField("SHA256", Nz::HashType_SHA256);
|
|
||||||
instance.PushField("SHA384", Nz::HashType_SHA384);
|
|
||||||
instance.PushField("SHA512", Nz::HashType_SHA512);
|
|
||||||
instance.PushField("Whirlpool", Nz::HashType_Whirlpool);
|
|
||||||
}
|
|
||||||
instance.SetGlobal("HashType");
|
|
||||||
|
|
||||||
// Nz::OpenMode
|
|
||||||
static_assert(Nz::OpenMode_Max + 1 == 2 * (64), "Nz::OpenModeFlags has been updated but change was not reflected to Lua binding");
|
|
||||||
instance.PushTable(0, 8);
|
|
||||||
{
|
|
||||||
instance.PushField("Append", Nz::OpenMode_Append);
|
|
||||||
instance.PushField("NotOpen", Nz::OpenMode_NotOpen);
|
|
||||||
instance.PushField("Lock", Nz::OpenMode_Lock);
|
|
||||||
instance.PushField("ReadOnly", Nz::OpenMode_ReadOnly);
|
|
||||||
instance.PushField("ReadWrite", Nz::OpenMode_ReadWrite);
|
|
||||||
instance.PushField("Text", Nz::OpenMode_Text);
|
|
||||||
instance.PushField("Truncate", Nz::OpenMode_Truncate);
|
|
||||||
instance.PushField("WriteOnly", Nz::OpenMode_WriteOnly);
|
|
||||||
}
|
|
||||||
instance.SetGlobal("OpenMode");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,371 +0,0 @@
|
||||||
// This file is part of the "Nazara Development Kit"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds Graphics module to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::BindGraphics()
|
|
||||||
{
|
|
||||||
/*********************************** Nz::AbstractViewer ***********************************/
|
|
||||||
abstractViewer.BindMethod("GetAspectRatio", &Nz::AbstractViewer::GetAspectRatio);
|
|
||||||
abstractViewer.BindMethod("GetEyePosition", &Nz::AbstractViewer::GetEyePosition);
|
|
||||||
abstractViewer.BindMethod("GetForward", &Nz::AbstractViewer::GetForward);
|
|
||||||
//abstractViewer.BindMethod("GetFrustum", &Nz::AbstractViewer::GetFrustum);
|
|
||||||
abstractViewer.BindMethod("GetProjectionMatrix", &Nz::AbstractViewer::GetProjectionMatrix);
|
|
||||||
//abstractViewer.BindMethod("GetTarget", &Nz::AbstractViewer::GetTarget);
|
|
||||||
abstractViewer.BindMethod("GetViewMatrix", &Nz::AbstractViewer::GetViewMatrix);
|
|
||||||
abstractViewer.BindMethod("GetViewport", &Nz::AbstractViewer::GetViewport);
|
|
||||||
abstractViewer.BindMethod("GetZFar", &Nz::AbstractViewer::GetZFar);
|
|
||||||
abstractViewer.BindMethod("GetZNear", &Nz::AbstractViewer::GetZNear);
|
|
||||||
|
|
||||||
/*********************************** Nz::InstancedRenderable ***********************************/
|
|
||||||
|
|
||||||
/*********************************** Nz::Material ***********************************/
|
|
||||||
material.SetConstructor([] (Nz::LuaInstance& lua, Nz::MaterialRef* instance, std::size_t argumentCount)
|
|
||||||
{
|
|
||||||
switch (argumentCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
Nz::PlacementNew(instance, Nz::Material::New());
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
int argIndex = 1;
|
|
||||||
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Material::New(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex))));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (lua.IsOfType(argIndex, "Material"))
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Material::New(**static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex))));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Material::New(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for constructor");
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("Configure", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "MaterialPipeline"))
|
|
||||||
{
|
|
||||||
instance->Configure(*static_cast<Nz::MaterialPipelineRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lua.Push(instance->Configure(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("EnableAlphaTest", &Nz::Material::EnableAlphaTest);
|
|
||||||
material.BindMethod("EnableBlending", &Nz::Material::EnableBlending);
|
|
||||||
material.BindMethod("EnableColorWrite", &Nz::Material::EnableColorWrite);
|
|
||||||
material.BindMethod("EnableDepthBuffer", &Nz::Material::EnableDepthBuffer);
|
|
||||||
material.BindMethod("EnableDepthSorting", &Nz::Material::EnableDepthSorting);
|
|
||||||
material.BindMethod("EnableDepthWrite", &Nz::Material::EnableDepthWrite);
|
|
||||||
material.BindMethod("EnableFaceCulling", &Nz::Material::EnableFaceCulling);
|
|
||||||
material.BindMethod("EnableScissorTest", &Nz::Material::EnableScissorTest);
|
|
||||||
material.BindMethod("EnableShadowCasting", &Nz::Material::EnableShadowCasting);
|
|
||||||
material.BindMethod("EnableShadowReceive", &Nz::Material::EnableShadowReceive);
|
|
||||||
material.BindMethod("EnableStencilTest", &Nz::Material::EnableStencilTest);
|
|
||||||
|
|
||||||
material.BindMethod("EnsurePipelineUpdate", &Nz::Material::EnsurePipelineUpdate);
|
|
||||||
|
|
||||||
material.BindMethod("GetAlphaMap", &Nz::Material::GetAlphaMap);
|
|
||||||
material.BindMethod("GetAlphaThreshold", &Nz::Material::GetAlphaThreshold);
|
|
||||||
material.BindMethod("GetAmbientColor", &Nz::Material::GetAmbientColor);
|
|
||||||
material.BindMethod("GetDepthFunc", &Nz::Material::GetDepthFunc);
|
|
||||||
material.BindMethod("GetDepthMaterial", &Nz::Material::GetDepthMaterial);
|
|
||||||
material.BindMethod("GetDiffuseColor", &Nz::Material::GetDiffuseColor);
|
|
||||||
material.BindMethod("GetDiffuseMap", &Nz::Material::GetDiffuseMap);
|
|
||||||
//material.BindMethod("GetDiffuseSampler", &Nz::Material::GetDiffuseSampler);
|
|
||||||
material.BindMethod("GetDstBlend", &Nz::Material::GetDstBlend);
|
|
||||||
material.BindMethod("GetEmissiveMap", &Nz::Material::GetEmissiveMap);
|
|
||||||
material.BindMethod("GetFaceCulling", &Nz::Material::GetFaceCulling);
|
|
||||||
material.BindMethod("GetFaceFilling", &Nz::Material::GetFaceFilling);
|
|
||||||
material.BindMethod("GetHeightMap", &Nz::Material::GetHeightMap);
|
|
||||||
material.BindMethod("GetLineWidth", &Nz::Material::GetLineWidth);
|
|
||||||
material.BindMethod("GetNormalMap", &Nz::Material::GetNormalMap);
|
|
||||||
//material.BindMethod("GetPipeline", &Nz::Material::GetPipeline);
|
|
||||||
//material.BindMethod("GetPipelineInfo", &Nz::Material::GetPipelineInfo);
|
|
||||||
material.BindMethod("GetPointSize", &Nz::Material::GetPointSize);
|
|
||||||
//material.BindMethod("GetShader", &Nz::Material::GetShader);
|
|
||||||
material.BindMethod("GetShininess", &Nz::Material::GetShininess);
|
|
||||||
material.BindMethod("GetSpecularColor", &Nz::Material::GetSpecularColor);
|
|
||||||
material.BindMethod("GetSpecularMap", &Nz::Material::GetSpecularMap);
|
|
||||||
//material.BindMethod("GetSpecularSampler", &Nz::Material::GetSpecularSampler);
|
|
||||||
material.BindMethod("GetSrcBlend", &Nz::Material::GetSrcBlend);
|
|
||||||
|
|
||||||
material.BindMethod("HasAlphaMap", &Nz::Material::HasAlphaMap);
|
|
||||||
material.BindMethod("HasDepthMaterial", &Nz::Material::HasDepthMaterial);
|
|
||||||
material.BindMethod("HasDiffuseMap", &Nz::Material::HasDiffuseMap);
|
|
||||||
material.BindMethod("HasEmissiveMap", &Nz::Material::HasEmissiveMap);
|
|
||||||
material.BindMethod("HasHeightMap", &Nz::Material::HasHeightMap);
|
|
||||||
material.BindMethod("HasNormalMap", &Nz::Material::HasNormalMap);
|
|
||||||
material.BindMethod("HasSpecularMap", &Nz::Material::HasSpecularMap);
|
|
||||||
|
|
||||||
material.BindMethod("IsAlphaTestEnabled", &Nz::Material::IsAlphaTestEnabled);
|
|
||||||
material.BindMethod("IsBlendingEnabled", &Nz::Material::IsBlendingEnabled);
|
|
||||||
material.BindMethod("IsColorWriteEnabled", &Nz::Material::IsColorWriteEnabled);
|
|
||||||
material.BindMethod("IsDepthBufferEnabled", &Nz::Material::IsDepthBufferEnabled);
|
|
||||||
material.BindMethod("IsDepthSortingEnabled", &Nz::Material::IsDepthSortingEnabled);
|
|
||||||
material.BindMethod("IsDepthWriteEnabled", &Nz::Material::IsDepthWriteEnabled);
|
|
||||||
material.BindMethod("IsFaceCullingEnabled", &Nz::Material::IsFaceCullingEnabled);
|
|
||||||
material.BindMethod("IsScissorTestEnabled", &Nz::Material::IsScissorTestEnabled);
|
|
||||||
material.BindMethod("IsStencilTestEnabled", &Nz::Material::IsStencilTestEnabled);
|
|
||||||
material.BindMethod("IsShadowCastingEnabled", &Nz::Material::IsShadowCastingEnabled);
|
|
||||||
material.BindMethod("IsShadowReceiveEnabled", &Nz::Material::IsShadowReceiveEnabled);
|
|
||||||
|
|
||||||
material.BindMethod("LoadFromFile", &Nz::Material::LoadFromFile, Nz::MaterialParams());
|
|
||||||
|
|
||||||
material.BindMethod("Reset", &Nz::Material::Reset);
|
|
||||||
|
|
||||||
material.BindMethod("SetAlphaThreshold", &Nz::Material::SetAlphaThreshold);
|
|
||||||
material.BindMethod("SetAmbientColor", &Nz::Material::SetAmbientColor);
|
|
||||||
material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc);
|
|
||||||
material.BindMethod("SetDepthFunc", &Nz::Material::SetDepthFunc);
|
|
||||||
material.BindMethod("SetDepthMaterial", &Nz::Material::SetDepthMaterial);
|
|
||||||
material.BindMethod("SetDiffuseColor", &Nz::Material::SetDiffuseColor);
|
|
||||||
//material.BindMethod("SetDiffuseSampler", &Nz::Material::SetDiffuseSampler);
|
|
||||||
material.BindMethod("SetDstBlend", &Nz::Material::SetDstBlend);
|
|
||||||
material.BindMethod("SetFaceCulling", &Nz::Material::SetFaceCulling);
|
|
||||||
material.BindMethod("SetFaceFilling", &Nz::Material::SetFaceFilling);
|
|
||||||
material.BindMethod("SetLineWidth", &Nz::Material::SetLineWidth);
|
|
||||||
material.BindMethod("SetPointSize", &Nz::Material::SetPointSize);
|
|
||||||
material.BindMethod("SetShininess", &Nz::Material::SetShininess);
|
|
||||||
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
|
||||||
material.BindMethod("SetSpecularColor", &Nz::Material::SetSpecularColor);
|
|
||||||
//material.BindMethod("SetSpecularSampler", &Nz::Material::SetSpecularSampler);
|
|
||||||
material.BindMethod("SetSrcBlend", &Nz::Material::SetSrcBlend);
|
|
||||||
|
|
||||||
material.BindStaticMethod("GetDefault", &Nz::Material::GetDefault);
|
|
||||||
|
|
||||||
material.BindMethod("SetAlphaMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetAlphaMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetAlphaMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetDiffuseMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetDiffuseMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetDiffuseMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetEmissiveMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetEmissiveMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetEmissiveMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetHeightMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetHeightMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetHeightMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetNormalMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetNormalMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetNormalMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetShader", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "UberShader"))
|
|
||||||
{
|
|
||||||
instance->SetShader(*static_cast<Nz::UberShaderRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetShader(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
material.BindMethod("SetSpecularMap", [] (Nz::LuaInstance& lua, Nz::MaterialRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
{
|
|
||||||
instance->SetSpecularMap(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return lua.Push(instance->SetSpecularMap(lua.Check<Nz::String>(&argIndex)));
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::Model ***********************************/
|
|
||||||
model.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::ModelRef* modelRef) -> Nz::InstancedRenderableRef*
|
|
||||||
{
|
|
||||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(modelRef); //TODO: Make a ObjectRefCast
|
|
||||||
});
|
|
||||||
|
|
||||||
model.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* instance, std::size_t /*argumentCount*/)
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Model::New());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
//model.BindMethod("GetMaterial", &Nz::Model::GetMaterial);
|
|
||||||
model.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount);
|
|
||||||
//modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh);
|
|
||||||
model.BindMethod("GetSkin", &Nz::Model::GetSkin);
|
|
||||||
model.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount);
|
|
||||||
|
|
||||||
model.BindMethod("IsAnimated", &Nz::Model::IsAnimated);
|
|
||||||
model.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters());
|
|
||||||
|
|
||||||
model.BindMethod("Reset", &Nz::Model::Reset);
|
|
||||||
|
|
||||||
//model.BindMethod("SetMaterial", &Nz::Model::SetMaterial);
|
|
||||||
//modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh);
|
|
||||||
//modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence);
|
|
||||||
model.BindMethod("SetSkin", &Nz::Model::SetSkin);
|
|
||||||
model.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount);
|
|
||||||
|
|
||||||
/*********************************** Nz::Sprite ***********************************/
|
|
||||||
sprite.Inherit<Nz::InstancedRenderableRef>(instancedRenderable, [] (Nz::SpriteRef* spriteRef) -> Nz::InstancedRenderableRef*
|
|
||||||
{
|
|
||||||
return reinterpret_cast<Nz::InstancedRenderableRef*>(spriteRef); //TODO: Make a ObjectRefCast
|
|
||||||
});
|
|
||||||
|
|
||||||
sprite.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::SpriteRef* instance, std::size_t /*argumentCount*/)
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Sprite::New());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
sprite.BindMethod("GetColor", &Nz::Sprite::GetColor);
|
|
||||||
sprite.BindMethod("GetCornerColor", &Nz::Sprite::GetCornerColor);
|
|
||||||
sprite.BindMethod("GetMaterial", &Nz::Sprite::GetMaterial);
|
|
||||||
sprite.BindMethod("GetOrigin", &Nz::Sprite::GetOrigin);
|
|
||||||
sprite.BindMethod("GetSize", &Nz::Sprite::GetSize);
|
|
||||||
sprite.BindMethod("GetTextureCoords", &Nz::Sprite::GetTextureCoords);
|
|
||||||
|
|
||||||
sprite.BindMethod("SetColor", &Nz::Sprite::SetColor);
|
|
||||||
sprite.BindMethod("SetCornerColor", &Nz::Sprite::SetCornerColor);
|
|
||||||
sprite.BindMethod("SetDefaultMaterial", &Nz::Sprite::SetDefaultMaterial);
|
|
||||||
sprite.BindMethod("SetOrigin", &Nz::Sprite::SetOrigin);
|
|
||||||
sprite.BindMethod("SetSize", (void(Nz::Sprite::*)(const Nz::Vector2f&)) &Nz::Sprite::SetSize);
|
|
||||||
sprite.BindMethod("SetTextureCoords", &Nz::Sprite::SetTextureCoords);
|
|
||||||
sprite.BindMethod("SetTextureRect", &Nz::Sprite::SetTextureRect);
|
|
||||||
|
|
||||||
sprite.BindMethod("SetMaterial", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
|
||||||
|
|
||||||
if (lua.IsOfType(argIndex, "Material"))
|
|
||||||
instance->SetMaterial(*static_cast<Nz::MaterialRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
|
||||||
else
|
|
||||||
instance->SetMaterial(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
sprite.BindMethod("SetTexture", [] (Nz::LuaInstance& lua, Nz::SpriteRef& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
bool resizeSprite = lua.CheckBoolean(argIndex + 1, true);
|
|
||||||
|
|
||||||
if (lua.IsOfType(argIndex, "Texture"))
|
|
||||||
instance->SetTexture(*static_cast<Nz::TextureRef*>(lua.ToUserdata(argIndex)), resizeSprite);
|
|
||||||
else
|
|
||||||
instance->SetTexture(lua.Check<Nz::String>(&argIndex), resizeSprite);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::SpriteLibrary ***********************************/
|
|
||||||
|
|
||||||
spriteLibrary.BindStaticMethod("Get", &Nz::SpriteLibrary::Get);
|
|
||||||
spriteLibrary.BindStaticMethod("Has", &Nz::SpriteLibrary::Has);
|
|
||||||
spriteLibrary.BindStaticMethod("Register", &Nz::SpriteLibrary::Register);
|
|
||||||
spriteLibrary.BindStaticMethod("Query", &Nz::SpriteLibrary::Query);
|
|
||||||
spriteLibrary.BindStaticMethod("Unregister", &Nz::SpriteLibrary::Unregister);
|
|
||||||
|
|
||||||
/*********************************** Nz::TextureLibrary ***********************************/
|
|
||||||
|
|
||||||
textureLibrary.BindStaticMethod("Get", &Nz::TextureLibrary::Get);
|
|
||||||
textureLibrary.BindStaticMethod("Has", &Nz::TextureLibrary::Has);
|
|
||||||
textureLibrary.BindStaticMethod("Register", &Nz::TextureLibrary::Register);
|
|
||||||
textureLibrary.BindStaticMethod("Query", &Nz::TextureLibrary::Query);
|
|
||||||
textureLibrary.BindStaticMethod("Unregister", &Nz::TextureLibrary::Unregister);
|
|
||||||
|
|
||||||
/*********************************** Nz::TextureManager ***********************************/
|
|
||||||
|
|
||||||
textureManager.BindStaticMethod("Clear", &Nz::TextureManager::Clear);
|
|
||||||
textureManager.BindStaticMethod("Get", &Nz::TextureManager::Get);
|
|
||||||
textureManager.BindStaticMethod("GetDefaultParameters", &Nz::TextureManager::GetDefaultParameters);
|
|
||||||
textureManager.BindStaticMethod("Purge", &Nz::TextureManager::Purge);
|
|
||||||
textureManager.BindStaticMethod("Register", &Nz::TextureManager::Register);
|
|
||||||
textureManager.BindStaticMethod("SetDefaultParameters", &Nz::TextureManager::SetDefaultParameters);
|
|
||||||
textureManager.BindStaticMethod("Unregister", &Nz::TextureManager::Unregister);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Registers the classes that will be used by the Lua instance
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the Graphics classes
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
abstractViewer.Register(instance);
|
|
||||||
instancedRenderable.Register(instance);
|
|
||||||
material.Register(instance);
|
|
||||||
model.Register(instance);
|
|
||||||
sprite.Register(instance);
|
|
||||||
spriteLibrary.Register(instance);
|
|
||||||
textureLibrary.Register(instance);
|
|
||||||
textureManager.Register(instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,417 +0,0 @@
|
||||||
// This file is part of the "Nazara Development Kit"
|
|
||||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
|
||||||
|
|
||||||
#include <NDK/LuaBinding.hpp>
|
|
||||||
#include <NDK/LuaAPI.hpp>
|
|
||||||
|
|
||||||
namespace Ndk
|
|
||||||
{
|
|
||||||
/*!
|
|
||||||
* \brief Binds Utility module to Lua
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::BindUtility()
|
|
||||||
{
|
|
||||||
/*********************************** Nz::AbstractImage **********************************/
|
|
||||||
abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel);
|
|
||||||
abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast<Nz::UInt8>(0));
|
|
||||||
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
|
|
||||||
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
|
|
||||||
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
|
|
||||||
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
|
|
||||||
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
|
|
||||||
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
|
|
||||||
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(0));
|
|
||||||
abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed);
|
|
||||||
abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap);
|
|
||||||
|
|
||||||
abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 1U);
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
return lua.Push(instance->GetMemoryUsage());
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
Nz::UInt8 level(lua.Check<Nz::UInt8>(&argIndex));
|
|
||||||
|
|
||||||
return lua.Push(instance->GetMemoryUsage(level));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method GetMemoryUsage");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 6U);
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
std::size_t bufferSize = 0;
|
|
||||||
const Nz::UInt8* pixels = reinterpret_cast<const Nz::UInt8*>(lua.CheckString(argIndex++, &bufferSize));
|
|
||||||
|
|
||||||
if (argCount < 2 || lua.IsOfType(2, Nz::LuaType_Number))
|
|
||||||
{
|
|
||||||
// bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
|
||||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
|
||||||
|
|
||||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
|
||||||
return lua.Push(instance->Update(pixels, srcWidth, srcHeight, level));
|
|
||||||
}
|
|
||||||
/* Disabled until Box and Rect have been ported
|
|
||||||
else if (lua.IsOfType(2, "Box"))
|
|
||||||
{
|
|
||||||
// bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
|
||||||
Nz::Boxui box = lua.Check<Nz::Boxui>(&argIndex);
|
|
||||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
|
||||||
|
|
||||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
|
||||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
|
||||||
}
|
|
||||||
else if (lua.IsOfType(2, "Rect"))
|
|
||||||
{
|
|
||||||
// bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0)
|
|
||||||
Nz::Rectui box = lua.Check<Nz::Rectui>(&argIndex);
|
|
||||||
unsigned int srcWidth = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
unsigned int srcHeight = lua.Check<unsigned int>(&argIndex, 0);
|
|
||||||
Nz::UInt8 level = lua.Check<Nz::UInt8>(&argIndex, 0);
|
|
||||||
|
|
||||||
///TODO: Buffer checks (Nz::ByteBufferView ?)
|
|
||||||
return lua.Push(abstractImage->Update(pixels, srcWidth, srcHeight, level));
|
|
||||||
}*/
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method Update");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
/*********************************** Nz::Font **********************************/
|
|
||||||
font.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* instance, std::size_t /*argumentCount*/)
|
|
||||||
{
|
|
||||||
Nz::PlacementNew(instance, Nz::Font::New());
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
font.BindMethod("ClearGlyphCache", &Nz::Font::ClearGlyphCache);
|
|
||||||
font.BindMethod("ClearKerningCache", &Nz::Font::ClearKerningCache);
|
|
||||||
font.BindMethod("ClearSizeInfoCache", &Nz::Font::ClearSizeInfoCache);
|
|
||||||
|
|
||||||
font.BindMethod("Destroy", &Nz::Font::Destroy);
|
|
||||||
|
|
||||||
font.BindMethod("GetCachedGlyphCount", [] (Nz::LuaInstance& lua, Nz::FontRef& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 2U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
lua.Push(instance->GetCachedGlyphCount());
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
unsigned int characterSize = lua.Check<unsigned int>(&argIndex);
|
|
||||||
Nz::UInt32 style = lua.Check<Nz::UInt32>(&argIndex);
|
|
||||||
|
|
||||||
lua.Push(instance->GetCachedGlyphCount(characterSize, style));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method GetCachedGlyphCount");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
font.BindMethod("GetFamilyName", &Nz::Font::GetFamilyName);
|
|
||||||
font.BindMethod("GetKerning", &Nz::Font::GetKerning);
|
|
||||||
font.BindMethod("GetGlyphBorder", &Nz::Font::GetGlyphBorder);
|
|
||||||
font.BindMethod("GetMinimumStepSize", &Nz::Font::GetMinimumStepSize);
|
|
||||||
font.BindMethod("GetSizeInfo", &Nz::Font::GetSizeInfo);
|
|
||||||
font.BindMethod("GetStyleName", &Nz::Font::GetStyleName);
|
|
||||||
|
|
||||||
font.BindMethod("IsValid", &Nz::Font::IsValid);
|
|
||||||
|
|
||||||
font.BindMethod("Precache", (bool(Nz::Font::*)(unsigned int, Nz::UInt32, const Nz::String&) const) &Nz::Font::Precache);
|
|
||||||
|
|
||||||
font.BindMethod("OpenFromFile", &Nz::Font::OpenFromFile, Nz::FontParams());
|
|
||||||
|
|
||||||
font.BindMethod("SetGlyphBorder", &Nz::Font::SetGlyphBorder);
|
|
||||||
font.BindMethod("SetMinimumStepSize", &Nz::Font::SetMinimumStepSize);
|
|
||||||
|
|
||||||
font.BindStaticMethod("GetDefault", &Nz::Font::GetDefault);
|
|
||||||
font.BindStaticMethod("GetDefaultGlyphBorder", &Nz::Font::GetDefaultGlyphBorder);
|
|
||||||
font.BindStaticMethod("GetDefaultMinimumStepSize", &Nz::Font::GetDefaultMinimumStepSize);
|
|
||||||
|
|
||||||
font.BindStaticMethod("SetDefaultGlyphBorder", &Nz::Font::SetDefaultGlyphBorder);
|
|
||||||
font.BindStaticMethod("SetDefaultMinimumStepSize", &Nz::Font::SetDefaultMinimumStepSize);
|
|
||||||
|
|
||||||
/*********************************** Nz::Keyboard **********************************/
|
|
||||||
keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName);
|
|
||||||
keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed);
|
|
||||||
|
|
||||||
/*********************************** Nz::Node **********************************/
|
|
||||||
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
|
||||||
//nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds);
|
|
||||||
node.BindMethod("GetDown", &Nz::Node::GetDown);
|
|
||||||
node.BindMethod("GetForward", &Nz::Node::GetForward);
|
|
||||||
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
|
||||||
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
|
||||||
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
|
||||||
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
|
||||||
//nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
|
||||||
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
|
||||||
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
|
||||||
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
|
||||||
//nodeClass.SetMethod("GetParent", &Nz::Node::GetParent);
|
|
||||||
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
|
||||||
node.BindMethod("GetRight", &Nz::Node::GetRight);
|
|
||||||
//nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
|
||||||
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
|
||||||
//nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix);
|
|
||||||
node.BindMethod("GetUp", &Nz::Node::GetUp);
|
|
||||||
|
|
||||||
node.BindMethod("HasChilds", &Nz::Node::HasChilds);
|
|
||||||
|
|
||||||
node.BindMethod("GetBackward", &Nz::Node::GetBackward);
|
|
||||||
node.BindMethod("GetDown", &Nz::Node::GetDown);
|
|
||||||
node.BindMethod("GetForward", &Nz::Node::GetForward);
|
|
||||||
node.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition);
|
|
||||||
node.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation);
|
|
||||||
node.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale);
|
|
||||||
node.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition);
|
|
||||||
node.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation);
|
|
||||||
node.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale);
|
|
||||||
node.BindMethod("GetLeft", &Nz::Node::GetLeft);
|
|
||||||
node.BindMethod("GetNodeType", &Nz::Node::GetNodeType);
|
|
||||||
node.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global);
|
|
||||||
node.BindMethod("GetRight", &Nz::Node::GetRight);
|
|
||||||
node.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global);
|
|
||||||
node.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global);
|
|
||||||
node.BindMethod("GetUp", &Nz::Node::GetUp);
|
|
||||||
|
|
||||||
node.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition);
|
|
||||||
node.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation);
|
|
||||||
|
|
||||||
node.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local);
|
|
||||||
node.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local);
|
|
||||||
|
|
||||||
node.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
Nz::Vector3f offset = lua.Check<Nz::Vector3f>(&argIndex);
|
|
||||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
|
||||||
instance.Move(offset, coordSys);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
node.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t /*argumentCount*/) -> int
|
|
||||||
{
|
|
||||||
int argIndex = 2;
|
|
||||||
|
|
||||||
Nz::Quaternionf rotation = lua.Check<Nz::Quaternionf>(&argIndex);
|
|
||||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
|
||||||
instance.Rotate(rotation, coordSys);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
node.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
|
||||||
instance.Scale(lua.Check<float>(&argIndex));
|
|
||||||
else
|
|
||||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
instance.Scale(lua.Check<Nz::Vector3f>(&argIndex));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method Scale");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
node.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
|
||||||
{
|
|
||||||
float scale = lua.Check<float>(&argIndex);
|
|
||||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
|
||||||
instance.SetScale(scale, coordSys);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
instance.SetScale(lua.Check<Nz::Vector3f>(&argIndex));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
{
|
|
||||||
Nz::Vector3f scale = lua.Check<Nz::Vector3f>(&argIndex);
|
|
||||||
Nz::CoordSys coordSys = lua.Check<Nz::CoordSys>(&argIndex, Nz::CoordSys_Local);
|
|
||||||
|
|
||||||
instance.SetScale(scale, coordSys);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method SetScale");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
node.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& instance, std::size_t argumentCount) -> int
|
|
||||||
{
|
|
||||||
std::size_t argCount = std::min<std::size_t>(argumentCount, 4U);
|
|
||||||
|
|
||||||
int argIndex = 2;
|
|
||||||
switch (argCount)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
if (lua.IsOfType(argIndex, Nz::LuaType_Number))
|
|
||||||
instance.SetInitialScale(lua.Check<float>(&argIndex));
|
|
||||||
else
|
|
||||||
instance.SetInitialScale(lua.Check<Nz::Vector2f>(&argIndex));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
instance.SetInitialScale(lua.Check<Nz::Vector3f>(&argIndex));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
lua.Error("No matching overload for method SetInitialScale");
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Registers the classes that will be used by the Lua instance
|
|
||||||
*
|
|
||||||
* \param instance Lua instance that will interact with the Utility classes
|
|
||||||
*/
|
|
||||||
|
|
||||||
void LuaBinding::RegisterUtility(Nz::LuaInstance& instance)
|
|
||||||
{
|
|
||||||
abstractImage.Register(instance);
|
|
||||||
font.Register(instance);
|
|
||||||
keyboard.Register(instance);
|
|
||||||
node.Register(instance);
|
|
||||||
|
|
||||||
keyboard.PushGlobalTable(instance);
|
|
||||||
{
|
|
||||||
instance.PushField("Undefined", Nz::Keyboard::Undefined);
|
|
||||||
|
|
||||||
// A-Z
|
|
||||||
for (std::size_t i = 0; i < 26; ++i)
|
|
||||||
instance.PushField(Nz::String('A' + char(i)), Nz::Keyboard::A + i);
|
|
||||||
|
|
||||||
// Numerical
|
|
||||||
for (std::size_t i = 0; i < 10; ++i)
|
|
||||||
{
|
|
||||||
instance.PushField("Num" + Nz::String::Number(i), Nz::Keyboard::Num0 + i);
|
|
||||||
instance.PushField("Numpad" + Nz::String::Number(i), Nz::Keyboard::Numpad0 + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// F1-F15
|
|
||||||
for (std::size_t i = 0; i < 15; ++i)
|
|
||||||
instance.PushField('F' + Nz::String::Number(i+1), Nz::Keyboard::F1 + i);
|
|
||||||
|
|
||||||
// And all the others...
|
|
||||||
instance.PushField("Down", Nz::Keyboard::Down);
|
|
||||||
instance.PushField("Left", Nz::Keyboard::Left);
|
|
||||||
instance.PushField("Right", Nz::Keyboard::Right);
|
|
||||||
instance.PushField("Up", Nz::Keyboard::Up);
|
|
||||||
|
|
||||||
instance.PushField("Add", Nz::Keyboard::Add);
|
|
||||||
instance.PushField("Decimal", Nz::Keyboard::Decimal);
|
|
||||||
instance.PushField("Divide", Nz::Keyboard::Divide);
|
|
||||||
instance.PushField("Multiply", Nz::Keyboard::Multiply);
|
|
||||||
instance.PushField("Subtract", Nz::Keyboard::Subtract);
|
|
||||||
|
|
||||||
instance.PushField("Backslash", Nz::Keyboard::Backslash);
|
|
||||||
instance.PushField("Backspace", Nz::Keyboard::Backspace);
|
|
||||||
instance.PushField("Clear", Nz::Keyboard::Clear);
|
|
||||||
instance.PushField("Comma", Nz::Keyboard::Comma);
|
|
||||||
instance.PushField("Dash", Nz::Keyboard::Dash);
|
|
||||||
instance.PushField("Delete", Nz::Keyboard::Delete);
|
|
||||||
instance.PushField("End", Nz::Keyboard::End);
|
|
||||||
instance.PushField("Equal", Nz::Keyboard::Equal);
|
|
||||||
instance.PushField("Escape", Nz::Keyboard::Escape);
|
|
||||||
instance.PushField("Home", Nz::Keyboard::Home);
|
|
||||||
instance.PushField("Insert", Nz::Keyboard::Insert);
|
|
||||||
instance.PushField("LAlt", Nz::Keyboard::LAlt);
|
|
||||||
instance.PushField("LBracket", Nz::Keyboard::LBracket);
|
|
||||||
instance.PushField("LControl", Nz::Keyboard::LControl);
|
|
||||||
instance.PushField("LShift", Nz::Keyboard::LShift);
|
|
||||||
instance.PushField("LSystem", Nz::Keyboard::LSystem);
|
|
||||||
instance.PushField("PageDown", Nz::Keyboard::PageDown);
|
|
||||||
instance.PushField("PageUp", Nz::Keyboard::PageUp);
|
|
||||||
instance.PushField("Pause", Nz::Keyboard::Pause);
|
|
||||||
instance.PushField("Period", Nz::Keyboard::Period);
|
|
||||||
instance.PushField("Print", Nz::Keyboard::Print);
|
|
||||||
instance.PushField("PrintScreen", Nz::Keyboard::PrintScreen);
|
|
||||||
instance.PushField("Quote", Nz::Keyboard::Quote);
|
|
||||||
instance.PushField("RAlt", Nz::Keyboard::RAlt);
|
|
||||||
instance.PushField("RBracket", Nz::Keyboard::RBracket);
|
|
||||||
instance.PushField("RControl", Nz::Keyboard::RControl);
|
|
||||||
instance.PushField("Return", Nz::Keyboard::Return);
|
|
||||||
instance.PushField("RShift", Nz::Keyboard::RShift);
|
|
||||||
instance.PushField("RSystem", Nz::Keyboard::RSystem);
|
|
||||||
instance.PushField("Semicolon", Nz::Keyboard::Semicolon);
|
|
||||||
instance.PushField("Slash", Nz::Keyboard::Slash);
|
|
||||||
instance.PushField("Space", Nz::Keyboard::Space);
|
|
||||||
instance.PushField("Tab", Nz::Keyboard::Tab);
|
|
||||||
instance.PushField("Tilde", Nz::Keyboard::Tilde);
|
|
||||||
instance.PushField("Browser_Back", Nz::Keyboard::Browser_Back);
|
|
||||||
instance.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites);
|
|
||||||
instance.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward);
|
|
||||||
instance.PushField("Browser_Home", Nz::Keyboard::Browser_Home);
|
|
||||||
instance.PushField("Browser_Refresh", Nz::Keyboard::Browser_Refresh);
|
|
||||||
instance.PushField("Browser_Search", Nz::Keyboard::Browser_Search);
|
|
||||||
instance.PushField("Browser_Stop", Nz::Keyboard::Browser_Stop);
|
|
||||||
instance.PushField("Media_Next", Nz::Keyboard::Media_Next);
|
|
||||||
instance.PushField("Media_Play", Nz::Keyboard::Media_Play);
|
|
||||||
instance.PushField("Media_Previous", Nz::Keyboard::Media_Previous);
|
|
||||||
instance.PushField("Media_Stop", Nz::Keyboard::Media_Stop);
|
|
||||||
instance.PushField("Volume_Down", Nz::Keyboard::Volume_Down);
|
|
||||||
instance.PushField("Volume_Mute", Nz::Keyboard::Volume_Mute);
|
|
||||||
instance.PushField("Volume_Up", Nz::Keyboard::Volume_Up);
|
|
||||||
instance.PushField("CapsLock", Nz::Keyboard::CapsLock);
|
|
||||||
instance.PushField("NumLock", Nz::Keyboard::NumLock);
|
|
||||||
instance.PushField("ScrollLock", Nz::Keyboard::ScrollLock);
|
|
||||||
}
|
|
||||||
instance.Pop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -28,10 +28,10 @@ namespace Ndk
|
||||||
/*!
|
/*!
|
||||||
* \brief Constructs an RenderSystem object by default
|
* \brief Constructs an RenderSystem object by default
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RenderSystem::RenderSystem() :
|
RenderSystem::RenderSystem() :
|
||||||
m_coordinateSystemMatrix(Nz::Matrix4f::Identity()),
|
m_coordinateSystemMatrix(Nz::Matrix4f::Identity()),
|
||||||
m_coordinateSystemInvalidated(true)
|
m_coordinateSystemInvalidated(true),
|
||||||
|
m_forceRenderQueueInvalidation(false)
|
||||||
{
|
{
|
||||||
ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
|
ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
|
||||||
SetDefaultBackground(Nz::ColorBackground::New());
|
SetDefaultBackground(Nz::ColorBackground::New());
|
||||||
|
|
@ -44,15 +44,22 @@ namespace Ndk
|
||||||
*
|
*
|
||||||
* \param entity Pointer to the entity
|
* \param entity Pointer to the entity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void RenderSystem::OnEntityRemoved(Entity* entity)
|
void RenderSystem::OnEntityRemoved(Entity* entity)
|
||||||
{
|
{
|
||||||
|
m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list
|
||||||
|
|
||||||
m_cameras.Remove(entity);
|
m_cameras.Remove(entity);
|
||||||
m_directionalLights.Remove(entity);
|
m_directionalLights.Remove(entity);
|
||||||
m_drawables.Remove(entity);
|
m_drawables.Remove(entity);
|
||||||
m_lights.Remove(entity);
|
m_lights.Remove(entity);
|
||||||
m_particleGroups.Remove(entity);
|
m_particleGroups.Remove(entity);
|
||||||
m_pointSpotLights.Remove(entity);
|
m_pointSpotLights.Remove(entity);
|
||||||
|
|
||||||
|
if (entity->HasComponent<GraphicsComponent>())
|
||||||
|
{
|
||||||
|
GraphicsComponent& gfxComponent = entity->GetComponent<GraphicsComponent>();
|
||||||
|
gfxComponent.RemoveFromCullingList(&m_drawableCulling);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -61,7 +68,6 @@ namespace Ndk
|
||||||
* \param entity Pointer to the entity
|
* \param entity Pointer to the entity
|
||||||
* \param justAdded Is the entity newly added
|
* \param justAdded Is the entity newly added
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded)
|
||||||
{
|
{
|
||||||
NazaraUnused(justAdded);
|
NazaraUnused(justAdded);
|
||||||
|
|
@ -78,12 +84,30 @@ namespace Ndk
|
||||||
m_cameras.Remove(entity);
|
m_cameras.Remove(entity);
|
||||||
|
|
||||||
if (entity->HasComponent<GraphicsComponent>() && entity->HasComponent<NodeComponent>())
|
if (entity->HasComponent<GraphicsComponent>() && entity->HasComponent<NodeComponent>())
|
||||||
|
{
|
||||||
m_drawables.Insert(entity);
|
m_drawables.Insert(entity);
|
||||||
|
|
||||||
|
if (justAdded)
|
||||||
|
{
|
||||||
|
GraphicsComponent& gfxComponent = entity->GetComponent<GraphicsComponent>();
|
||||||
|
gfxComponent.AddToCullingList(&m_drawableCulling);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
m_drawables.Remove(entity);
|
m_drawables.Remove(entity);
|
||||||
|
|
||||||
|
if (entity->HasComponent<GraphicsComponent>())
|
||||||
|
{
|
||||||
|
GraphicsComponent& gfxComponent = entity->GetComponent<GraphicsComponent>();
|
||||||
|
gfxComponent.RemoveFromCullingList(&m_drawableCulling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
|
if (entity->HasComponent<LightComponent>() && entity->HasComponent<NodeComponent>())
|
||||||
{
|
{
|
||||||
|
m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list
|
||||||
|
|
||||||
LightComponent& lightComponent = entity->GetComponent<LightComponent>();
|
LightComponent& lightComponent = entity->GetComponent<LightComponent>();
|
||||||
if (lightComponent.GetLightType() == Nz::LightType_Directional)
|
if (lightComponent.GetLightType() == Nz::LightType_Directional)
|
||||||
{
|
{
|
||||||
|
|
@ -100,16 +124,26 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list
|
||||||
|
|
||||||
m_directionalLights.Remove(entity);
|
m_directionalLights.Remove(entity);
|
||||||
m_lights.Remove(entity);
|
m_lights.Remove(entity);
|
||||||
m_pointSpotLights.Remove(entity);
|
m_pointSpotLights.Remove(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity->HasComponent<ParticleGroupComponent>())
|
if (entity->HasComponent<ParticleGroupComponent>())
|
||||||
|
{
|
||||||
|
m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list
|
||||||
|
|
||||||
m_particleGroups.Insert(entity);
|
m_particleGroups.Insert(entity);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
m_forceRenderQueueInvalidation = true; //< Hackfix until lights and particles are handled by culling list
|
||||||
|
|
||||||
m_particleGroups.Remove(entity);
|
m_particleGroups.Remove(entity);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Operation to perform when system is updated
|
* \brief Operation to perform when system is updated
|
||||||
|
|
@ -140,16 +174,28 @@ namespace Ndk
|
||||||
//UpdateDirectionalShadowMaps(camComponent);
|
//UpdateDirectionalShadowMaps(camComponent);
|
||||||
|
|
||||||
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue();
|
Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue();
|
||||||
renderQueue->Clear();
|
|
||||||
|
|
||||||
//TODO: Culling
|
// To make sure the bounding volume used by the culling list is updated
|
||||||
for (const Ndk::EntityHandle& drawable : m_drawables)
|
for (const Ndk::EntityHandle& drawable : m_drawables)
|
||||||
{
|
{
|
||||||
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
|
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
|
||||||
|
graphicsComponent.EnsureBoundingVolumeUpdate();
|
||||||
graphicsComponent.AddToRenderQueue(renderQueue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool forceInvalidation = false;
|
||||||
|
|
||||||
|
std::size_t visibilityHash = m_drawableCulling.Cull(camComponent.GetFrustum(), &forceInvalidation);
|
||||||
|
|
||||||
|
// Always regenerate renderqueue if particle groups are present for now (FIXME)
|
||||||
|
if (!m_particleGroups.empty())
|
||||||
|
forceInvalidation = true;
|
||||||
|
|
||||||
|
if (camComponent.UpdateVisibility(visibilityHash) || m_forceRenderQueueInvalidation || forceInvalidation)
|
||||||
|
{
|
||||||
|
renderQueue->Clear();
|
||||||
|
for (const GraphicsComponent* gfxComponent : m_drawableCulling)
|
||||||
|
gfxComponent->AddToRenderQueue(renderQueue);
|
||||||
|
|
||||||
for (const Ndk::EntityHandle& light : m_lights)
|
for (const Ndk::EntityHandle& light : m_lights)
|
||||||
{
|
{
|
||||||
LightComponent& lightComponent = light->GetComponent<LightComponent>();
|
LightComponent& lightComponent = light->GetComponent<LightComponent>();
|
||||||
|
|
@ -163,7 +209,10 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
ParticleGroupComponent& groupComponent = particleGroup->GetComponent<ParticleGroupComponent>();
|
ParticleGroupComponent& groupComponent = particleGroup->GetComponent<ParticleGroupComponent>();
|
||||||
|
|
||||||
groupComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::Identity()); //< ParticleGroup doesn't use Matrix4f
|
groupComponent.AddToRenderQueue(renderQueue, Nz::Matrix4f::Identity()); //< ParticleGroup doesn't use any transform matrix (yet)
|
||||||
|
}
|
||||||
|
|
||||||
|
m_forceRenderQueueInvalidation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
camComponent.ApplyView();
|
camComponent.ApplyView();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <NDK/Systems/VelocitySystem.hpp>
|
#include <NDK/Systems/VelocitySystem.hpp>
|
||||||
#include <NDK/Components/NodeComponent.hpp>
|
#include <NDK/Components/NodeComponent.hpp>
|
||||||
|
#include <NDK/Components/PhysicsComponent2D.hpp>
|
||||||
#include <NDK/Components/PhysicsComponent3D.hpp>
|
#include <NDK/Components/PhysicsComponent3D.hpp>
|
||||||
#include <NDK/Components/VelocityComponent.hpp>
|
#include <NDK/Components/VelocityComponent.hpp>
|
||||||
|
|
||||||
|
|
@ -14,17 +15,16 @@ namespace Ndk
|
||||||
* \class Ndk::VelocitySystem
|
* \class Ndk::VelocitySystem
|
||||||
* \brief NDK class that represents the velocity system
|
* \brief NDK class that represents the velocity system
|
||||||
*
|
*
|
||||||
* \remark This system is enabled if the entity owns the trait: NodeComponent and VelocityComponent
|
* \remark This system is enabled if the entity owns the traits NodeComponent and VelocityComponent
|
||||||
* but it's disabled with the trait: PhysicsComponent3D
|
* but it's disabled with the traits: PhysicsComponent2D, PhysicsComponent3D
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Constructs an VelocitySystem object by default
|
* \brief Constructs an VelocitySystem object by default
|
||||||
*/
|
*/
|
||||||
|
|
||||||
VelocitySystem::VelocitySystem()
|
VelocitySystem::VelocitySystem()
|
||||||
{
|
{
|
||||||
Excludes<PhysicsComponent3D>();
|
Excludes<PhysicsComponent2D, PhysicsComponent3D>();
|
||||||
Requires<NodeComponent, VelocityComponent>();
|
Requires<NodeComponent, VelocityComponent>();
|
||||||
SetUpdateOrder(10); //< Since some systems may want to stop us
|
SetUpdateOrder(10); //< Since some systems may want to stop us
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
// 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/Widgets/ButtonWidget.hpp>
|
||||||
|
#include <NDK/Components/GraphicsComponent.hpp>
|
||||||
|
#include <NDK/Components/NodeComponent.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
ButtonWidget::ButtonWidget(BaseWidget* parent) :
|
||||||
|
BaseWidget(parent)
|
||||||
|
{
|
||||||
|
m_gradientSprite = Nz::Sprite::New();
|
||||||
|
m_gradientSprite->SetColor(Nz::Color(74, 74, 74));
|
||||||
|
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, Nz::Color(180, 180, 180));
|
||||||
|
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, Nz::Color(180, 180, 180));
|
||||||
|
m_gradientSprite->SetMaterial(Nz::Material::New("Basic2D"));
|
||||||
|
|
||||||
|
m_gradientEntity = CreateEntity();
|
||||||
|
m_gradientEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||||
|
m_gradientEntity->AddComponent<GraphicsComponent>().Attach(m_gradientSprite);
|
||||||
|
|
||||||
|
m_textSprite = Nz::TextSprite::New();
|
||||||
|
|
||||||
|
m_textEntity = CreateEntity();
|
||||||
|
m_textEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||||
|
m_textEntity->AddComponent<GraphicsComponent>().Attach(m_textSprite, 1);
|
||||||
|
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ButtonWidget::ResizeToContent()
|
||||||
|
{
|
||||||
|
SetContentSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ButtonWidget::Layout()
|
||||||
|
{
|
||||||
|
BaseWidget::Layout();
|
||||||
|
|
||||||
|
const Nz::Vector2f& contentSize = GetContentSize();
|
||||||
|
|
||||||
|
m_gradientSprite->SetSize(contentSize);
|
||||||
|
|
||||||
|
Nz::Boxf textBox = m_textEntity->GetComponent<GraphicsComponent>().GetBoundingVolume().aabb;
|
||||||
|
m_textEntity->GetComponent<NodeComponent>().SetPosition(contentSize.x / 2 - textBox.width / 2, contentSize.y / 2 - textBox.height / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ButtonWidget::OnMouseButtonRelease(int /*x*/, int /*y*/, Nz::Mouse::Button button)
|
||||||
|
{
|
||||||
|
if (button == Nz::Mouse::Left)
|
||||||
|
OnButtonTrigger(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ButtonWidget::OnMouseEnter()
|
||||||
|
{
|
||||||
|
m_gradientSprite->SetColor(Nz::Color(128, 128, 128));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ButtonWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ButtonWidget::OnMouseExit()
|
||||||
|
{
|
||||||
|
m_gradientSprite->SetColor(Nz::Color(74, 74, 74));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
#include <NDK/Widgets/LabelWidget.hpp>
|
||||||
|
#include <NDK/Components/GraphicsComponent.hpp>
|
||||||
|
#include <NDK/Components/NodeComponent.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
LabelWidget::LabelWidget(BaseWidget* parent) :
|
||||||
|
BaseWidget(parent)
|
||||||
|
{
|
||||||
|
m_textSprite = Nz::TextSprite::New();
|
||||||
|
|
||||||
|
m_textEntity = CreateEntity();
|
||||||
|
m_textEntity->AddComponent<GraphicsComponent>().Attach(m_textSprite);
|
||||||
|
m_textEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||||
|
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LabelWidget::ResizeToContent()
|
||||||
|
{
|
||||||
|
SetContentSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,232 @@
|
||||||
|
// 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/Widgets/TextAreaWidget.hpp>
|
||||||
|
#include <Nazara/Core/Unicode.hpp>
|
||||||
|
#include <NDK/Components/GraphicsComponent.hpp>
|
||||||
|
#include <NDK/Components/NodeComponent.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
namespace Ndk
|
||||||
|
{
|
||||||
|
TextAreaWidget::TextAreaWidget(BaseWidget* parent) :
|
||||||
|
BaseWidget(parent),
|
||||||
|
m_cursorPosition(0U),
|
||||||
|
m_multiLineEnabled(false),
|
||||||
|
m_readOnly(false)
|
||||||
|
{
|
||||||
|
m_cursorSprite = Nz::Sprite::New();
|
||||||
|
m_cursorSprite->SetColor(Nz::Color(192, 192, 192));
|
||||||
|
m_cursorSprite->SetSize(1.f, float(m_drawer.GetFont()->GetSizeInfo(m_drawer.GetCharacterSize()).lineHeight));
|
||||||
|
|
||||||
|
m_cursorEntity = CreateEntity();
|
||||||
|
m_cursorEntity->AddComponent<GraphicsComponent>().Attach(m_cursorSprite, 10);
|
||||||
|
m_cursorEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||||
|
m_cursorEntity->Enable(false);
|
||||||
|
|
||||||
|
m_textSprite = Nz::TextSprite::New();
|
||||||
|
|
||||||
|
m_textEntity = CreateEntity();
|
||||||
|
m_textEntity->AddComponent<GraphicsComponent>().Attach(m_textSprite);
|
||||||
|
m_textEntity->AddComponent<NodeComponent>().SetParent(this);
|
||||||
|
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::AppendText(const Nz::String& text)
|
||||||
|
{
|
||||||
|
m_drawer.AppendText(text);
|
||||||
|
|
||||||
|
m_textSprite->Update(m_drawer);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t TextAreaWidget::GetHoveredGlyph(float x, float y) const
|
||||||
|
{
|
||||||
|
std::size_t glyphCount = m_drawer.GetGlyphCount();
|
||||||
|
if (glyphCount > 0)
|
||||||
|
{
|
||||||
|
std::size_t lineCount = m_drawer.GetLineCount();
|
||||||
|
std::size_t line = 0U;
|
||||||
|
for (; line < lineCount - 1; ++line)
|
||||||
|
{
|
||||||
|
Nz::Rectf lineBounds = m_drawer.GetLine(line).bounds;
|
||||||
|
if (lineBounds.GetMaximum().y > y)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t upperLimit = (line != lineCount - 1) ? m_drawer.GetLine(line + 1).glyphIndex : glyphCount + 1;
|
||||||
|
|
||||||
|
std::size_t i = m_drawer.GetLine(line).glyphIndex;
|
||||||
|
for (; i < upperLimit - 1; ++i)
|
||||||
|
{
|
||||||
|
Nz::Rectf bounds = m_drawer.GetGlyph(i).bounds;
|
||||||
|
if (x < bounds.x + bounds.width * 0.75f)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::ResizeToContent()
|
||||||
|
{
|
||||||
|
SetContentSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::SetText(const Nz::String& text)
|
||||||
|
{
|
||||||
|
m_drawer.SetText(text);
|
||||||
|
|
||||||
|
m_textSprite->Update(m_drawer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::Write(const Nz::String& text)
|
||||||
|
{
|
||||||
|
if (m_cursorPosition >= m_drawer.GetGlyphCount())
|
||||||
|
{
|
||||||
|
AppendText(text);
|
||||||
|
SetCursorPosition(m_drawer.GetGlyphCount());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Nz::String currentText = m_drawer.GetText();
|
||||||
|
currentText.Insert(currentText.GetCharacterPosition(m_cursorPosition), text);
|
||||||
|
SetText(currentText);
|
||||||
|
|
||||||
|
SetCursorPosition(m_cursorPosition + text.GetLength());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::RefreshCursor()
|
||||||
|
{
|
||||||
|
std::size_t lineCount = m_drawer.GetLineCount();
|
||||||
|
std::size_t line = 0U;
|
||||||
|
for (std::size_t i = line + 1; i < lineCount; ++i)
|
||||||
|
{
|
||||||
|
if (m_drawer.GetLine(i).glyphIndex > m_cursorPosition)
|
||||||
|
break;
|
||||||
|
|
||||||
|
line = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& lineInfo = m_drawer.GetLine(line);
|
||||||
|
|
||||||
|
std::size_t glyphCount = m_drawer.GetGlyphCount();
|
||||||
|
float position;
|
||||||
|
if (glyphCount > 0 && lineInfo.glyphIndex < m_cursorPosition)
|
||||||
|
{
|
||||||
|
const auto& glyph = m_drawer.GetGlyph(std::min(m_cursorPosition, glyphCount - 1));
|
||||||
|
position = glyph.bounds.x;
|
||||||
|
if (m_cursorPosition >= glyphCount)
|
||||||
|
position += glyph.bounds.width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
position = 0.f;
|
||||||
|
|
||||||
|
m_cursorEntity->GetComponent<Ndk::NodeComponent>().SetPosition(position, lineInfo.bounds.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key)
|
||||||
|
{
|
||||||
|
switch (key.code)
|
||||||
|
{
|
||||||
|
case Nz::Keyboard::Delete:
|
||||||
|
{
|
||||||
|
const Nz::String& text = m_drawer.GetText();
|
||||||
|
|
||||||
|
Nz::String newText;
|
||||||
|
if (m_cursorPosition > 0)
|
||||||
|
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorPosition) - 1));
|
||||||
|
|
||||||
|
if (m_cursorPosition < m_drawer.GetGlyphCount())
|
||||||
|
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorPosition + 1)));
|
||||||
|
|
||||||
|
m_drawer.SetText(newText);
|
||||||
|
m_textSprite->Update(m_drawer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::Keyboard::Left:
|
||||||
|
MoveCursor(-1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Nz::Keyboard::Right:
|
||||||
|
MoveCursor(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::OnKeyReleased(const Nz::WindowEvent::KeyEvent& key)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::OnMouseEnter()
|
||||||
|
{
|
||||||
|
m_cursorEntity->Enable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::OnMouseButtonPress(int x, int y, Nz::Mouse::Button button)
|
||||||
|
{
|
||||||
|
if (button == Nz::Mouse::Left)
|
||||||
|
{
|
||||||
|
GrabKeyboard();
|
||||||
|
|
||||||
|
SetCursorPosition(GetHoveredGlyph(float(x), float(y)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::OnMouseExit()
|
||||||
|
{
|
||||||
|
m_cursorEntity->Enable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextAreaWidget::OnTextEntered(char32_t character, bool /*repeated*/)
|
||||||
|
{
|
||||||
|
if (m_readOnly)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (character)
|
||||||
|
{
|
||||||
|
case '\b':
|
||||||
|
{
|
||||||
|
const Nz::String& text = m_drawer.GetText();
|
||||||
|
|
||||||
|
Nz::String newText;
|
||||||
|
if (m_cursorPosition > 1)
|
||||||
|
newText.Append(text.SubString(0, text.GetCharacterPosition(m_cursorPosition - 1) - 1));
|
||||||
|
|
||||||
|
if (m_cursorPosition < m_drawer.GetGlyphCount())
|
||||||
|
newText.Append(text.SubString(text.GetCharacterPosition(m_cursorPosition)));
|
||||||
|
|
||||||
|
SetText(newText);
|
||||||
|
MoveCursor(-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
if (!m_multiLineEnabled)
|
||||||
|
break;
|
||||||
|
|
||||||
|
Write(Nz::String('\n'));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (Nz::Unicode::GetCategory(character) == Nz::Unicode::Category_Other_Control)
|
||||||
|
break;
|
||||||
|
|
||||||
|
Write(Nz::String::Unicode(character));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -69,6 +69,15 @@ ACTION.Function = function ()
|
||||||
Target = "../SDK/include/NDK/Systems.hpp"
|
Target = "../SDK/include/NDK/Systems.hpp"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
table.insert(paths, {
|
||||||
|
Excludes = {},
|
||||||
|
HeaderGuard = "NDK_WIDGETS_GLOBAL_HPP",
|
||||||
|
Name = "NDK Widgets",
|
||||||
|
SearchDir = "../SDK/include/NDK/Widgets",
|
||||||
|
TopDir = "NDK",
|
||||||
|
Target = "../SDK/include/NDK/Widgets.hpp"
|
||||||
|
})
|
||||||
|
|
||||||
for k,v in ipairs(paths) do
|
for k,v in ipairs(paths) do
|
||||||
print(v.Name)
|
print(v.Name)
|
||||||
local header, err = io.open(v.Target, "w+")
|
local header, err = io.open(v.Target, "w+")
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ TOOL.Files = {
|
||||||
-- Excludes client-only files
|
-- Excludes client-only files
|
||||||
TOOL.FilesExcluded = {
|
TOOL.FilesExcluded = {
|
||||||
"../SDK/**/CameraComponent.*",
|
"../SDK/**/CameraComponent.*",
|
||||||
|
"../SDK/**/Canvas.*",
|
||||||
"../SDK/**/Console.*",
|
"../SDK/**/Console.*",
|
||||||
"../SDK/**/GraphicsComponent.*",
|
"../SDK/**/GraphicsComponent.*",
|
||||||
"../SDK/**/LightComponent.*",
|
"../SDK/**/LightComponent.*",
|
||||||
|
|
@ -33,6 +34,7 @@ TOOL.FilesExcluded = {
|
||||||
"../SDK/**/Particle*Component.*",
|
"../SDK/**/Particle*Component.*",
|
||||||
"../SDK/**/ParticleSystem.*",
|
"../SDK/**/ParticleSystem.*",
|
||||||
"../SDK/**/RenderSystem.*",
|
"../SDK/**/RenderSystem.*",
|
||||||
|
"../SDK/**/*Widget*.*",
|
||||||
"../SDK/**/LuaBinding_Audio.*",
|
"../SDK/**/LuaBinding_Audio.*",
|
||||||
"../SDK/**/LuaBinding_Graphics.*",
|
"../SDK/**/LuaBinding_Graphics.*",
|
||||||
"../SDK/**/LuaBinding_Renderer.*"
|
"../SDK/**/LuaBinding_Renderer.*"
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ int main()
|
||||||
|
|
||||||
// Les UVs de ce fichier sont retournées (repère OpenGL, origine coin bas-gauche) par rapport à ce que le moteur attend (haut-gauche)
|
// Les UVs de ce fichier sont retournées (repère OpenGL, origine coin bas-gauche) par rapport à ce que le moteur attend (haut-gauche)
|
||||||
// Nous devons donc indiquer au moteur de les retourner lors du chargement
|
// Nous devons donc indiquer au moteur de les retourner lors du chargement
|
||||||
params.mesh.flipUVs = true;
|
params.mesh.texCoordScale.Set(1.f, -1.f);
|
||||||
|
|
||||||
// Nazara va par défaut optimiser les modèles pour un rendu plus rapide, cela peut prendre du temps et n'est pas nécessaire ici
|
// Nazara va par défaut optimiser les modèles pour un rendu plus rapide, cela peut prendre du temps et n'est pas nécessaire ici
|
||||||
params.mesh.optimizeIndexBuffers = false;
|
params.mesh.optimizeIndexBuffers = false;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
#include "Common.hpp"
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||||
|
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||||
|
#include <NDK/Systems/RenderSystem.hpp>
|
||||||
|
|
||||||
|
ParticleDemo::ParticleDemo(const Nz::String& name, const ExampleShared& exampleShared) :
|
||||||
|
m_shared(exampleShared),
|
||||||
|
m_index(s_demoIndex++),
|
||||||
|
m_name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleDemo::Enter(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
m_shared.demoName->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_index+1) + " - " + m_name, 48));
|
||||||
|
m_fpsCounter = 0;
|
||||||
|
m_updateClock.Restart();
|
||||||
|
|
||||||
|
Ndk::RenderSystem& renderSystem2D = m_shared.world2D->GetSystem<Ndk::RenderSystem>();
|
||||||
|
Ndk::RenderSystem& renderSystem3D = m_shared.world3D->GetSystem<Ndk::RenderSystem>();
|
||||||
|
m_oldBackground2D = renderSystem2D.GetDefaultBackground();
|
||||||
|
m_oldBackground3D = renderSystem3D.GetDefaultBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleDemo::Leave(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
m_shared.world2D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(m_oldBackground2D);
|
||||||
|
m_shared.world3D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(m_oldBackground3D);
|
||||||
|
|
||||||
|
m_entities.clear();
|
||||||
|
m_particleGroups.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParticleDemo::Update(Ndk::StateMachine& fsm, float elapsedTime)
|
||||||
|
{
|
||||||
|
m_fpsCounter++;
|
||||||
|
if (m_updateClock.GetMilliseconds() > 1000)
|
||||||
|
{
|
||||||
|
m_updateClock.Restart();
|
||||||
|
|
||||||
|
m_shared.fpsCount->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_fpsCounter) + " FPS", 24));
|
||||||
|
m_fpsCounter = 0;
|
||||||
|
|
||||||
|
unsigned int particleCount = 0;
|
||||||
|
for (const Ndk::EntityHandle& entity : m_particleGroups)
|
||||||
|
{
|
||||||
|
const Ndk::ParticleGroupComponent& group = entity->GetComponent<Ndk::ParticleGroupComponent>();
|
||||||
|
particleCount += group.GetParticleCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_shared.particleCount->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(particleCount) + " particles", 36));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleDemo::RegisterEntity(const Ndk::EntityHandle& entity)
|
||||||
|
{
|
||||||
|
m_entities.emplace_back(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticleDemo::RegisterParticleGroup(const Ndk::EntityHandle& entity)
|
||||||
|
{
|
||||||
|
NazaraAssert(entity->HasComponent<Ndk::ParticleGroupComponent>(), "Must have particle group component");
|
||||||
|
|
||||||
|
m_particleGroups.emplace_back(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t ParticleDemo::s_demoIndex = 0;
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_EXAMPLES_PARTICLES_COMMON_HPP
|
||||||
|
#define NAZARA_EXAMPLES_PARTICLES_COMMON_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Clock.hpp>
|
||||||
|
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||||
|
#include <Nazara/Graphics/TextSprite.hpp>
|
||||||
|
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||||
|
#include <NDK/Components/ParticleGroupComponent.hpp>
|
||||||
|
#include <NDK/EntityOwner.hpp>
|
||||||
|
#include <NDK/StateMachine.hpp>
|
||||||
|
#include <NDK/World.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <random>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class ParticleDemo;
|
||||||
|
|
||||||
|
struct ExampleShared
|
||||||
|
{
|
||||||
|
mutable std::mt19937 randomGen;
|
||||||
|
std::vector<std::shared_ptr<ParticleDemo>> demos;
|
||||||
|
Nz::RenderWindow* target;
|
||||||
|
Nz::TextSpriteRef demoName;
|
||||||
|
Nz::TextSpriteRef fpsCount;
|
||||||
|
Nz::TextSpriteRef particleCount;
|
||||||
|
Ndk::EntityHandle viewer2D;
|
||||||
|
Ndk::EntityHandle viewer3D;
|
||||||
|
Ndk::WorldHandle world2D;
|
||||||
|
Ndk::WorldHandle world3D;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ParticleDemo : public Ndk::State
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ParticleDemo(const Nz::String& name, const ExampleShared& exampleShared);
|
||||||
|
~ParticleDemo() = default;
|
||||||
|
|
||||||
|
void Enter(Ndk::StateMachine& fsm) override;
|
||||||
|
void Leave(Ndk::StateMachine& fsm) override;
|
||||||
|
|
||||||
|
bool Update(Ndk::StateMachine& fsm, float elapsedTime) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const ExampleShared& m_shared;
|
||||||
|
|
||||||
|
void RegisterEntity(const Ndk::EntityHandle& entity);
|
||||||
|
void RegisterParticleGroup(const Ndk::EntityHandle& entity);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::size_t m_index;
|
||||||
|
std::vector<Ndk::EntityOwner> m_entities;
|
||||||
|
std::vector<Ndk::EntityOwner> m_particleGroups;
|
||||||
|
Nz::BackgroundRef m_oldBackground2D;
|
||||||
|
Nz::BackgroundRef m_oldBackground3D;
|
||||||
|
Nz::Clock m_updateClock;
|
||||||
|
Nz::String m_name;
|
||||||
|
unsigned int m_fpsCounter;
|
||||||
|
|
||||||
|
static std::size_t s_demoIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_EXAMPLES_PARTICLES_COMMON_HPP
|
||||||
|
|
@ -0,0 +1,170 @@
|
||||||
|
#include "LogoDemo.hpp"
|
||||||
|
#include <Nazara/Graphics.hpp>
|
||||||
|
#include <Nazara/Utility.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/Systems.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const float duration = 10.f;
|
||||||
|
const float maxVel = 50.f;
|
||||||
|
const float pauseTime = 3.f;
|
||||||
|
const float startTime = 2.f;
|
||||||
|
const float speed = 3.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SpriteController : public Nz::ParticleController
|
||||||
|
{
|
||||||
|
void Apply(Nz::ParticleGroup& system, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime) override
|
||||||
|
{
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto posPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto velPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
posPtr[i] += velPtr[i] * elapsedTime * factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool enabled = false;
|
||||||
|
float factor = 1.f;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class SpriteRenderer : public Nz::ParticleRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SpriteRenderer(Nz::MaterialRef mat) :
|
||||||
|
m_material(mat)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Render(const Nz::ParticleGroup& system, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||||
|
{
|
||||||
|
Nz::Vector2f size(1.f, 1.f);
|
||||||
|
Nz::SparsePtr<const Nz::Vector2f> sizePtr(&size, 0);
|
||||||
|
Nz::SparsePtr<const Nz::Vector2f> sinCosPtr(nullptr, 0);
|
||||||
|
|
||||||
|
renderQueue->AddBillboards(0, m_material, endId - startId + 1, mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position), sizePtr, sinCosPtr, mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Nz::MaterialRef m_material;
|
||||||
|
};
|
||||||
|
|
||||||
|
LogoExample::LogoExample(ExampleShared& sharedData) :
|
||||||
|
ParticleDemo("Logo", sharedData)
|
||||||
|
{
|
||||||
|
Nz::ImageParams params;
|
||||||
|
params.loadFormat = Nz::PixelFormatType_RGBA8;
|
||||||
|
|
||||||
|
if (!m_logo.LoadFromFile("resources/Logo.png", params))
|
||||||
|
NazaraError("Failed to load logo!");
|
||||||
|
|
||||||
|
unsigned int width = m_logo.GetWidth();
|
||||||
|
unsigned int height = m_logo.GetHeight();
|
||||||
|
m_pixels.reserve(width * height);
|
||||||
|
|
||||||
|
for (unsigned int y = 0; y < height; ++y)
|
||||||
|
{
|
||||||
|
for (unsigned int x = 0; x < width; ++x)
|
||||||
|
{
|
||||||
|
Nz::Color color = m_logo.GetPixelColor(x, y);
|
||||||
|
if (color.a == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PixelData data;
|
||||||
|
data.pos.Set(x, y);
|
||||||
|
data.color = color;
|
||||||
|
|
||||||
|
m_pixels.push_back(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Nz::MaterialRef material = Nz::Material::New();
|
||||||
|
material->EnableBlending(true);
|
||||||
|
material->EnableDepthWrite(false);
|
||||||
|
material->EnableFaceCulling(false);
|
||||||
|
material->SetDstBlend(Nz::BlendFunc_InvSrcAlpha);
|
||||||
|
material->SetSrcBlend(Nz::BlendFunc_SrcAlpha);
|
||||||
|
|
||||||
|
m_controller = new SpriteController;
|
||||||
|
m_renderer = new SpriteRenderer(std::move(material));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogoExample::Enter(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
ParticleDemo::Enter(fsm);
|
||||||
|
|
||||||
|
m_shared.world3D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(nullptr);
|
||||||
|
|
||||||
|
Nz::TextureRef backgroundTexture = Nz::Texture::New();
|
||||||
|
if (backgroundTexture->LoadFromFile("resources/stars-background.jpg"))
|
||||||
|
m_shared.world2D->GetSystem<Ndk::RenderSystem>().SetDefaultBackground(Nz::TextureBackground::New(std::move(backgroundTexture)));
|
||||||
|
|
||||||
|
Ndk::EntityHandle particleGroupEntity = m_shared.world2D->CreateEntity();
|
||||||
|
Ndk::ParticleGroupComponent& particleGroup = particleGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(m_pixels.size(), Nz::ParticleLayout_Sprite);
|
||||||
|
RegisterParticleGroup(particleGroupEntity);
|
||||||
|
|
||||||
|
particleGroup.AddController(m_controller);
|
||||||
|
particleGroup.SetRenderer(m_renderer);
|
||||||
|
|
||||||
|
m_particles = static_cast<Nz::ParticleStruct_Sprite*>(particleGroup.CreateParticles(m_pixels.size()));
|
||||||
|
ResetParticles(-duration * (speed / 2.f));
|
||||||
|
|
||||||
|
m_accumulator = pauseTime + duration;
|
||||||
|
m_totalAccumulator = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogoExample::Leave(Ndk::StateMachine & fsm)
|
||||||
|
{
|
||||||
|
ParticleDemo::Leave(fsm);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LogoExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
|
||||||
|
{
|
||||||
|
if (!ParticleDemo::Update(fsm, elapsedTime))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_totalAccumulator += elapsedTime;
|
||||||
|
if (m_totalAccumulator <= startTime)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
m_accumulator += elapsedTime;
|
||||||
|
|
||||||
|
SpriteController* controller = static_cast<SpriteController*>(m_controller.Get());
|
||||||
|
if (m_accumulator > pauseTime + 2.f * duration)
|
||||||
|
{
|
||||||
|
ResetParticles(0.f);
|
||||||
|
m_accumulator = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
controller->enabled = (m_accumulator > pauseTime);
|
||||||
|
controller->factor = -speed + speed * (m_accumulator - pauseTime) / (duration);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogoExample::ResetParticles(float elapsed)
|
||||||
|
{
|
||||||
|
Nz::Vector2f center = {m_shared.target->GetWidth() / 2.f, m_shared.target->GetHeight() / 2.f};
|
||||||
|
Nz::Vector2f offset = center - Nz::Vector2f(Nz::Vector2ui(m_logo.GetSize()) / 2);
|
||||||
|
|
||||||
|
float ratio = float(m_shared.target->GetWidth()) / m_shared.target->GetHeight();
|
||||||
|
std::uniform_real_distribution<float> disX(-maxVel * ratio, maxVel * ratio);
|
||||||
|
std::uniform_real_distribution<float> disY(-maxVel, maxVel);
|
||||||
|
|
||||||
|
Nz::ParticleStruct_Sprite* sprite = m_particles;
|
||||||
|
for (PixelData& data : m_pixels)
|
||||||
|
{
|
||||||
|
sprite->color = data.color;
|
||||||
|
sprite->position = offset + Nz::Vector2f(data.pos);
|
||||||
|
sprite->rotation = 0.f;
|
||||||
|
sprite->velocity.Set(disX(m_shared.randomGen), disY(m_shared.randomGen), 0.f);
|
||||||
|
sprite->position += sprite->velocity * elapsed;
|
||||||
|
sprite++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_EXAMPLES_PARTICLES_LOGO_HPP
|
||||||
|
#define NAZARA_EXAMPLES_PARTICLES_LOGO_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
|
#include <Nazara/Graphics/ParticleStruct.hpp>
|
||||||
|
#include <NDK/State.hpp>
|
||||||
|
#include <vector>
|
||||||
|
#include "Common.hpp"
|
||||||
|
|
||||||
|
class LogoExample : public ParticleDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LogoExample(ExampleShared& sharedData);
|
||||||
|
~LogoExample() = default;
|
||||||
|
|
||||||
|
void Enter(Ndk::StateMachine& fsm) override;
|
||||||
|
void Leave(Ndk::StateMachine& fsm) override;
|
||||||
|
bool Update(Ndk::StateMachine& fsm, float elapsedTime) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ResetParticles(float elapsed);
|
||||||
|
|
||||||
|
struct PixelData
|
||||||
|
{
|
||||||
|
Nz::Vector2ui pos;
|
||||||
|
Nz::Color color;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<PixelData> m_pixels;
|
||||||
|
Nz::BackgroundRef m_oldBackground;
|
||||||
|
Nz::ParticleStruct_Sprite* m_particles;
|
||||||
|
Nz::Image m_logo;
|
||||||
|
Nz::ParticleControllerRef m_controller;
|
||||||
|
Nz::ParticleRendererRef m_renderer;
|
||||||
|
float m_accumulator;
|
||||||
|
float m_totalAccumulator;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_EXAMPLES_PARTICLES_LOGO_HPP
|
||||||
|
|
@ -0,0 +1,826 @@
|
||||||
|
#include "SpacebattleDemo.hpp"
|
||||||
|
#include <Nazara/Audio/Sound.hpp>
|
||||||
|
#include <Nazara/Core/OffsetOf.hpp>
|
||||||
|
#include <Nazara/Graphics.hpp>
|
||||||
|
#include <Nazara/Utility.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/Systems.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const float maxLaserLife = 15.f;
|
||||||
|
const float maxSmokeLife = 20.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SpaceshipComponent : public Ndk::Component<SpaceshipComponent>
|
||||||
|
{
|
||||||
|
SpaceshipComponent()
|
||||||
|
{
|
||||||
|
engineSound.SetBuffer(Nz::SoundBufferManager::Get("resources/spaceship_loop.wav"));
|
||||||
|
engineSound.EnableSpatialization(true);
|
||||||
|
engineSound.SetMinDistance(10.f);
|
||||||
|
engineSound.SetPitch(1.5f);
|
||||||
|
|
||||||
|
hitSound.SetBuffer(Nz::SoundBufferManager::Get("resources/explosion.wav"));
|
||||||
|
hitSound.EnableSpatialization(true);
|
||||||
|
hitSound.SetMinDistance(150.f);
|
||||||
|
|
||||||
|
laserSound.SetBuffer(Nz::SoundBufferManager::Get("resources/laser.wav"));
|
||||||
|
laserSound.EnableSpatialization(true);
|
||||||
|
laserSound.SetMinDistance(150.f);
|
||||||
|
laserSound.SetVolume(60.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::array<Nz::SpriteRef, 2> laserBeamSprites;
|
||||||
|
Nz::Sound engineSound;
|
||||||
|
Nz::Sound hitSound;
|
||||||
|
Nz::Sound laserSound;
|
||||||
|
Nz::UInt64 hitTime = 0;
|
||||||
|
Nz::Vector3f targetPos = Nz::Vector3f::Zero();
|
||||||
|
bool attacking = true;
|
||||||
|
|
||||||
|
static Ndk::ComponentIndex componentIndex;
|
||||||
|
};
|
||||||
|
Ndk::ComponentIndex SpaceshipComponent::componentIndex;
|
||||||
|
|
||||||
|
struct LaserBeamComponent : public Ndk::Component<LaserBeamComponent>
|
||||||
|
{
|
||||||
|
LaserBeamComponent()
|
||||||
|
{
|
||||||
|
Nz::MaterialRef laserBeamMaterial = Nz::MaterialLibrary::Get("LaserBeam");
|
||||||
|
for (Nz::Sprite& sprite : sprites)
|
||||||
|
{
|
||||||
|
sprite.SetMaterial(laserBeamMaterial);
|
||||||
|
sprite.SetOrigin(Nz::Vector2f(0.f, 0.5f));
|
||||||
|
sprite.SetTextureCoords(Nz::Rectf(0.f, 0.f, 50.f, 1.f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnAttached() override
|
||||||
|
{
|
||||||
|
auto& spaceshipCom = m_entity->GetComponent<SpaceshipComponent>();
|
||||||
|
spaceshipCom.laserSound.Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::array<Nz::Sprite, 2> sprites;
|
||||||
|
Nz::Vector3f origin = Nz::Vector3f::Zero();
|
||||||
|
float length = 1500.f;
|
||||||
|
float life = 2.f;
|
||||||
|
float width = 2.f;
|
||||||
|
|
||||||
|
static Ndk::ComponentIndex componentIndex;
|
||||||
|
};
|
||||||
|
Ndk::ComponentIndex LaserBeamComponent::componentIndex;
|
||||||
|
|
||||||
|
class LaserBeamSystem : public Ndk::System<LaserBeamSystem>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LaserBeamSystem(const ExampleShared& sharedData) :
|
||||||
|
m_sharedData(sharedData)
|
||||||
|
{
|
||||||
|
Requires<Ndk::GraphicsComponent, LaserBeamComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnEntityAdded(Ndk::Entity* entity) override
|
||||||
|
{
|
||||||
|
auto& laserComponent = entity->GetComponent<LaserBeamComponent>();
|
||||||
|
auto& gfxComponent = entity->GetComponent<Ndk::GraphicsComponent>();
|
||||||
|
|
||||||
|
for (Nz::Sprite& sprite : laserComponent.sprites)
|
||||||
|
sprite.SetSize({laserComponent.length, laserComponent.width});
|
||||||
|
|
||||||
|
gfxComponent.Attach(&laserComponent.sprites[0], Nz::Matrix4f::Transform(laserComponent.origin, Nz::EulerAnglesf(0.f, 90.f, 0.f)));
|
||||||
|
gfxComponent.Attach(&laserComponent.sprites[1], Nz::Matrix4f::Transform(laserComponent.origin, Nz::EulerAnglesf(90.f, 90.f, 0.f)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUpdate(float elapsedTime) override
|
||||||
|
{
|
||||||
|
const float scrollSpeed = 2.f;
|
||||||
|
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||||
|
{
|
||||||
|
auto& laserComponent = entity->GetComponent<LaserBeamComponent>();
|
||||||
|
for (Nz::Sprite& sprite : laserComponent.sprites)
|
||||||
|
{
|
||||||
|
Nz::Rectf rect = sprite.GetTextureCoords();
|
||||||
|
rect.x = std::fmod(rect.x - elapsedTime * scrollSpeed, rect.width);
|
||||||
|
|
||||||
|
sprite.SetTextureCoords(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Ndk::SystemIndex systemIndex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const ExampleShared& m_sharedData;
|
||||||
|
};
|
||||||
|
Ndk::SystemIndex LaserBeamSystem::systemIndex;
|
||||||
|
|
||||||
|
class SpaceshipSystem : public Ndk::System<SpaceshipSystem>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SpaceshipSystem(const ExampleShared& sharedData) :
|
||||||
|
m_sharedData(sharedData)
|
||||||
|
{
|
||||||
|
Requires<Ndk::NodeComponent, Ndk::VelocityComponent, SpaceshipComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnEntityAdded(Ndk::Entity* entity) override
|
||||||
|
{
|
||||||
|
std::uniform_real_distribution<float> pitchDis(0.8f, 1.5f);
|
||||||
|
|
||||||
|
auto& nodeComponent = entity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
auto& spaceshipComponent = entity->GetComponent<SpaceshipComponent>();
|
||||||
|
|
||||||
|
spaceshipComponent.engineSound.SetPosition(nodeComponent.GetPosition());
|
||||||
|
spaceshipComponent.engineSound.Play();
|
||||||
|
spaceshipComponent.engineSound.EnableLooping(true);
|
||||||
|
|
||||||
|
spaceshipComponent.laserSound.SetPitch(pitchDis(m_sharedData.randomGen));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUpdate(float elapsedTime) override
|
||||||
|
{
|
||||||
|
const float escapeMaxDist = 50.f;
|
||||||
|
const float speed = 200.f;
|
||||||
|
|
||||||
|
Nz::UInt64 curTime = Nz::GetElapsedMilliseconds();
|
||||||
|
std::uniform_real_distribution<float> dis(-escapeMaxDist, escapeMaxDist);
|
||||||
|
|
||||||
|
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||||
|
{
|
||||||
|
auto& nodeComponent = entity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
auto& spaceshipComponent = entity->GetComponent<SpaceshipComponent>();
|
||||||
|
auto& velocityComponent = entity->GetComponent<Ndk::VelocityComponent>();
|
||||||
|
|
||||||
|
//< I agree, I need some kind of SoundEmitterComponent
|
||||||
|
spaceshipComponent.engineSound.SetPosition(nodeComponent.GetPosition());
|
||||||
|
spaceshipComponent.engineSound.SetVelocity(velocityComponent.linearVelocity);
|
||||||
|
|
||||||
|
spaceshipComponent.hitSound.SetPosition(nodeComponent.GetPosition());
|
||||||
|
spaceshipComponent.hitSound.SetVelocity(velocityComponent.linearVelocity);
|
||||||
|
|
||||||
|
spaceshipComponent.laserSound.SetPosition(nodeComponent.GetPosition());
|
||||||
|
spaceshipComponent.laserSound.SetVelocity(velocityComponent.linearVelocity);
|
||||||
|
|
||||||
|
Nz::Vector3f targetDir = spaceshipComponent.targetPos - nodeComponent.GetPosition();
|
||||||
|
targetDir.Normalize();
|
||||||
|
|
||||||
|
Nz::Quaternionf targetRotation = Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), targetDir);
|
||||||
|
|
||||||
|
nodeComponent.SetRotation(Nz::Quaternionf::Slerp(nodeComponent.GetRotation(), targetRotation, elapsedTime * 1.5f));
|
||||||
|
|
||||||
|
Nz::Vector3f actualDir = nodeComponent.GetForward();
|
||||||
|
float sqDistance = spaceshipComponent.targetPos.SquaredDistance(nodeComponent.GetPosition());
|
||||||
|
|
||||||
|
if (spaceshipComponent.attacking)
|
||||||
|
{
|
||||||
|
float dotProduct = targetDir.DotProduct(actualDir);
|
||||||
|
if (dotProduct > 0.9f && sqDistance < (150.f * 150.f) && !entity->HasComponent<LaserBeamComponent>())
|
||||||
|
{
|
||||||
|
auto& laserBeam = entity->AddComponent<LaserBeamComponent>();
|
||||||
|
laserBeam.origin = Nz::Vector3f::Forward() * 12.f + Nz::Vector3f::Down() * 2.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sqDistance < (100.f * 100.f))
|
||||||
|
{
|
||||||
|
entity->RemoveComponent<LaserBeamComponent>();
|
||||||
|
|
||||||
|
spaceshipComponent.targetPos -= Nz::Vector3f(dis(m_sharedData.randomGen), dis(m_sharedData.randomGen), dis(m_sharedData.randomGen)) * -actualDir * escapeMaxDist / 2.f;
|
||||||
|
spaceshipComponent.attacking = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sqDistance < (50.f * 50.f) && spaceshipComponent.hitTime == 0)
|
||||||
|
{
|
||||||
|
spaceshipComponent.targetPos = Nz::Vector3f::Zero();
|
||||||
|
spaceshipComponent.attacking = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spaceshipComponent.hitTime == 0 || curTime - spaceshipComponent.hitTime <= 1000)
|
||||||
|
velocityComponent.linearVelocity = actualDir * speed;
|
||||||
|
else if (curTime - spaceshipComponent.hitTime > 10000)
|
||||||
|
entity->Kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Ndk::SystemIndex systemIndex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const ExampleShared& m_sharedData;
|
||||||
|
};
|
||||||
|
Ndk::SystemIndex SpaceshipSystem::systemIndex;
|
||||||
|
|
||||||
|
struct TorpedoParticle
|
||||||
|
{
|
||||||
|
Nz::Color color;
|
||||||
|
Nz::Vector2f size;
|
||||||
|
Nz::Vector3f position;
|
||||||
|
Nz::Vector3f velocity;
|
||||||
|
float rotation;
|
||||||
|
float life;
|
||||||
|
};
|
||||||
|
|
||||||
|
SpacebattleExample::SpacebattleExample(ExampleShared& sharedData) :
|
||||||
|
ParticleDemo("Space battle", sharedData)
|
||||||
|
{
|
||||||
|
Ndk::InitializeComponent<LaserBeamComponent>("Lasrbeam");
|
||||||
|
Ndk::InitializeComponent<SpaceshipComponent>("Spceship");
|
||||||
|
Ndk::InitializeSystem<LaserBeamSystem>();
|
||||||
|
Ndk::InitializeSystem<SpaceshipSystem>();
|
||||||
|
|
||||||
|
Nz::ModelParameters parameters;
|
||||||
|
parameters.mesh.optimizeIndexBuffers = false;
|
||||||
|
|
||||||
|
Nz::Color grey(100, 100, 100);
|
||||||
|
|
||||||
|
if (!m_turret.baseModel.LoadFromFile("resources/Turret/base.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load base.obj");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < m_turret.baseModel.GetMaterialCount(); ++i)
|
||||||
|
m_turret.baseModel.GetMaterial(i)->SetDiffuseColor(grey);
|
||||||
|
|
||||||
|
if (!m_turret.rotatingBaseModel.LoadFromFile("resources/Turret/rotating_base.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load rotating_base.obj");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < m_turret.rotatingBaseModel.GetMaterialCount(); ++i)
|
||||||
|
m_turret.rotatingBaseModel.GetMaterial(i)->SetDiffuseColor(grey);
|
||||||
|
|
||||||
|
if (!m_turret.cannonBaseModel.LoadFromFile("resources/Turret/cannon_base.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load cannon_base.obj");
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < m_turret.cannonBaseModel.GetMaterialCount(); ++i)
|
||||||
|
m_turret.cannonBaseModel.GetMaterial(i)->SetDiffuseColor(grey);
|
||||||
|
|
||||||
|
parameters.mesh.texCoordScale.Set(40.f, 40.f);
|
||||||
|
parameters.mesh.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 180.f, 0.f));
|
||||||
|
if (!m_turret.cannonModel.LoadFromFile("resources/Turret/cannon.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load cannon.obj");
|
||||||
|
|
||||||
|
// Since OBJ don't support normal maps..
|
||||||
|
m_turret.cannonModel.GetMaterial(0)->SetNormalMap("resources/Turret/198_norm.jpg");
|
||||||
|
|
||||||
|
parameters.mesh.matrix.MakeIdentity();
|
||||||
|
parameters.mesh.texCoordScale.Set(1.f, 1.f);
|
||||||
|
|
||||||
|
parameters.mesh.center = true;
|
||||||
|
if (!m_spacestationModel.LoadFromFile("resources/SpaceStation/space_station.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load space_station.obj");
|
||||||
|
|
||||||
|
parameters.mesh.texCoordScale.Set(1.f, -1.f);
|
||||||
|
parameters.mesh.matrix.MakeRotation(Nz::EulerAnglesf(0.f, -90.f, 0.f));
|
||||||
|
|
||||||
|
if (!m_spaceshipModel.LoadFromFile("resources/space_frigate_6/space_frigate_6.obj", parameters))
|
||||||
|
NazaraWarning("Failed to load space_frigate_6.obj");
|
||||||
|
|
||||||
|
// Since OBJ don't support normal maps..
|
||||||
|
for (unsigned int i = 0; i < m_spaceshipModel.GetMaterialCount(); ++i)
|
||||||
|
{
|
||||||
|
m_spaceshipModel.GetMaterial(i)->SetEmissiveMap("resources/space_frigate_6/space_frigate_6_illumination.jpg");
|
||||||
|
m_spaceshipModel.GetMaterial(i)->SetNormalMap("resources/space_frigate_6/space_frigate_6_normal.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
Nz::TextureRef skyboxCubemap = Nz::Texture::New();
|
||||||
|
if (skyboxCubemap->Create(Nz::ImageType_Cubemap, Nz::PixelFormatType_RGBA8, 2048, 2048))
|
||||||
|
{
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_PositiveX, "resources/purple_nebula_skybox/purple_nebula_skybox_right1.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_PositiveY, "resources/purple_nebula_skybox/purple_nebula_skybox_top3.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_PositiveZ, "resources/purple_nebula_skybox/purple_nebula_skybox_front5.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_NegativeX, "resources/purple_nebula_skybox/purple_nebula_skybox_left2.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_NegativeY, "resources/purple_nebula_skybox/purple_nebula_skybox_bottom4.png");
|
||||||
|
skyboxCubemap->LoadFaceFromFile(Nz::CubemapFace_NegativeZ, "resources/purple_nebula_skybox/purple_nebula_skybox_back6.png");
|
||||||
|
|
||||||
|
m_skybox.SetTexture(std::move(skyboxCubemap));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_torpedoDeclaration = Nz::ParticleDeclaration::New();
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Color, Nz::ComponentType_Color, NazaraOffsetOf(TorpedoParticle, color));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Position, Nz::ComponentType_Float3, NazaraOffsetOf(TorpedoParticle, position));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Rotation, Nz::ComponentType_Float1, NazaraOffsetOf(TorpedoParticle, rotation));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Size, Nz::ComponentType_Float2, NazaraOffsetOf(TorpedoParticle, size));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Life, Nz::ComponentType_Float1, NazaraOffsetOf(TorpedoParticle, life));
|
||||||
|
m_torpedoDeclaration->EnableComponent(Nz::ParticleComponent_Velocity, Nz::ComponentType_Float3, NazaraOffsetOf(TorpedoParticle, velocity));
|
||||||
|
|
||||||
|
Nz::TextureSampler diffuseSampler;
|
||||||
|
diffuseSampler.SetWrapMode(Nz::SamplerWrap_Repeat);
|
||||||
|
|
||||||
|
Nz::MaterialRef material = Nz::Material::New("Translucent3D");
|
||||||
|
material->SetDiffuseMap("resources/LaserBeam.png");
|
||||||
|
material->SetDiffuseSampler(diffuseSampler);
|
||||||
|
|
||||||
|
Nz::MaterialLibrary::Register("LaserBeam", std::move(material));
|
||||||
|
|
||||||
|
Nz::MaterialRef sparkleMat1 = Nz::Material::New("Translucent3D");
|
||||||
|
|
||||||
|
sparkleMat1->SetDiffuseMap("resources/flare1.png");
|
||||||
|
Nz::MaterialLibrary::Register("TorpedoFlare1", std::move(sparkleMat1));
|
||||||
|
|
||||||
|
m_spaceshipTemplate = m_shared.world3D->CreateEntity();
|
||||||
|
m_spaceshipTemplate->Enable(false);
|
||||||
|
|
||||||
|
auto& gfxComponent = m_spaceshipTemplate->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
auto& nodeComponent = m_spaceshipTemplate->AddComponent<Ndk::NodeComponent>();
|
||||||
|
auto& velocityComponent = m_spaceshipTemplate->AddComponent<Ndk::VelocityComponent>();
|
||||||
|
auto& spaceshipComponent = m_spaceshipTemplate->AddComponent<SpaceshipComponent>();
|
||||||
|
gfxComponent.Attach(&m_spaceshipModel);
|
||||||
|
|
||||||
|
m_ambientMusic.OpenFromFile("resources/ambience.ogg");
|
||||||
|
m_ambientMusic.SetVolume(60.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::Enter(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
ParticleDemo::Enter(fsm);
|
||||||
|
|
||||||
|
m_shared.world3D->AddSystem<LaserBeamSystem>(m_shared);
|
||||||
|
m_shared.world3D->AddSystem<SpaceshipSystem>(m_shared);
|
||||||
|
|
||||||
|
Ndk::RenderSystem& renderSystem2D = m_shared.world2D->GetSystem<Ndk::RenderSystem>();
|
||||||
|
Ndk::RenderSystem& renderSystem3D = m_shared.world3D->GetSystem<Ndk::RenderSystem>();
|
||||||
|
renderSystem2D.SetDefaultBackground(nullptr);
|
||||||
|
renderSystem3D.SetDefaultBackground(&m_skybox);
|
||||||
|
|
||||||
|
CreateSpaceShip();
|
||||||
|
CreateTurret();
|
||||||
|
|
||||||
|
Ndk::EntityHandle light = m_shared.world3D->CreateEntity();
|
||||||
|
Ndk::NodeComponent& lightNode = light->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::LightComponent& lightComp = light->AddComponent<Ndk::LightComponent>(Nz::LightType_Directional);
|
||||||
|
lightNode.SetRotation(Nz::EulerAnglesf(-30.f, 0.f, 0.f));
|
||||||
|
RegisterEntity(light);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cameraNode = m_shared.viewer3D->GetComponent<Ndk::NodeComponent>();
|
||||||
|
cameraNode.SetParent(m_turret.cannonAnchorEntity);
|
||||||
|
cameraNode.SetPosition(Nz::Vector3f::Up() * 4.f - Nz::Vector3f::Backward() * 6.f);
|
||||||
|
cameraNode.SetRotation(Nz::EulerAnglesf(0.f, 180.f, 0.f));
|
||||||
|
|
||||||
|
m_introTimer = 10.f;
|
||||||
|
m_spaceshipSpawnCounter = -5.f;
|
||||||
|
m_turretBaseRotation = 0.f;
|
||||||
|
m_turretCannonBaseRotation = 0.f;
|
||||||
|
m_turretShootTimer = 0.f;
|
||||||
|
|
||||||
|
Ndk::EntityHandle torpedoGroupEntity = m_shared.world3D->CreateEntity();
|
||||||
|
m_torpedoGroup = torpedoGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(200, m_torpedoDeclaration).CreateHandle();
|
||||||
|
RegisterParticleGroup(torpedoGroupEntity);
|
||||||
|
|
||||||
|
m_torpedoGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||||
|
auto rotationPtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
rotationPtr[i] += elapsedTime * 90.f;
|
||||||
|
positionPtr[i] += velocityPtr[i] * elapsedTime;
|
||||||
|
|
||||||
|
lifePtr[i] -= elapsedTime;
|
||||||
|
if (lifePtr[i] < 0.f)
|
||||||
|
group.KillParticle(i);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
m_torpedoGroup->AddController(Nz::ParticleFunctionController::New([this] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto positionPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto rotationPtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
auto velocityPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
auto& spaceshipSystem = m_shared.world3D->GetSystem<SpaceshipSystem>();
|
||||||
|
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
Nz::Spheref torpedoSphere(positionPtr[i], std::max(sizePtr[i].x, sizePtr[i].y) * 0.1f);
|
||||||
|
|
||||||
|
for (const Ndk::EntityHandle& entity : spaceshipSystem.GetEntities())
|
||||||
|
{
|
||||||
|
auto& spaceshipNode = entity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Nz::Spheref spaceshipSphere(spaceshipNode.GetPosition(), 10.f);
|
||||||
|
if (torpedoSphere.Intersect(spaceshipSphere))
|
||||||
|
{
|
||||||
|
entity->RemoveComponent<LaserBeamComponent>();
|
||||||
|
|
||||||
|
group.KillParticle(i);
|
||||||
|
|
||||||
|
const float hitMaxDist = 500.f;
|
||||||
|
|
||||||
|
std::uniform_real_distribution<float> dis(-hitMaxDist, hitMaxDist);
|
||||||
|
|
||||||
|
auto& spaceshipComponent = entity->GetComponent<SpaceshipComponent>();
|
||||||
|
spaceshipComponent.attacking = false;
|
||||||
|
spaceshipComponent.engineSound.Stop();
|
||||||
|
spaceshipComponent.hitSound.Play();
|
||||||
|
spaceshipComponent.hitTime = Nz::GetElapsedMilliseconds();
|
||||||
|
spaceshipComponent.targetPos = Nz::Vector3f(dis(m_shared.randomGen), dis(m_shared.randomGen), dis(m_shared.randomGen));
|
||||||
|
|
||||||
|
auto& emitter = entity->AddComponent<Ndk::ParticleEmitterComponent>();
|
||||||
|
emitter.SetEmissionCount(2);
|
||||||
|
emitter.SetEmissionRate(200.f);
|
||||||
|
|
||||||
|
emitter.SetSetupFunc([this] (const Ndk::EntityHandle& entity, Nz::ParticleMapper& mapper, unsigned int count)
|
||||||
|
{
|
||||||
|
auto& gen = m_shared.randomGen;
|
||||||
|
|
||||||
|
const float maxFireVel = 15.f;
|
||||||
|
std::uniform_real_distribution<float> lifeDis(-0.5f, 0.5f);
|
||||||
|
std::uniform_real_distribution<float> normalDis(-1.f, 1.f);
|
||||||
|
std::uniform_real_distribution<float> posDis(-0.1f, 0.1f);
|
||||||
|
std::uniform_real_distribution<float> rotDis(-180.f, 180.f);
|
||||||
|
std::uniform_real_distribution<float> sizeDis(1.0f, 4.f);
|
||||||
|
std::uniform_real_distribution<float> velDis(-maxFireVel, maxFireVel);
|
||||||
|
|
||||||
|
Nz::Vector3f pos = entity->GetComponent<Ndk::NodeComponent>().GetPosition();
|
||||||
|
|
||||||
|
Nz::ParticleStruct_Billboard* billboards = static_cast<Nz::ParticleStruct_Billboard*>(mapper.GetPointer());
|
||||||
|
Nz::ParticleStruct_Billboard* smokeParticles = static_cast<Nz::ParticleStruct_Billboard*>(m_smokeGroup->CreateParticles(count));
|
||||||
|
for (unsigned int i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
billboards[i].color = Nz::Color::White;
|
||||||
|
billboards[i].life = 1.f + lifeDis(gen);
|
||||||
|
billboards[i].position = pos + Nz::Vector3f(posDis(gen), posDis(gen), posDis(gen));
|
||||||
|
billboards[i].rotation = rotDis(gen);
|
||||||
|
billboards[i].size = {1.28f, 1.28f};
|
||||||
|
billboards[i].size *= sizeDis(gen);
|
||||||
|
billboards[i].velocity.Set(normalDis(gen), normalDis(gen), normalDis(gen));
|
||||||
|
billboards[i].velocity.Normalize();
|
||||||
|
billboards[i].velocity *= velDis(gen);
|
||||||
|
|
||||||
|
smokeParticles[i].color = Nz::Color(128, 128, 128, 0);
|
||||||
|
smokeParticles[i].life = maxSmokeLife;
|
||||||
|
smokeParticles[i].position = billboards[i].position;
|
||||||
|
smokeParticles[i].rotation = billboards[i].rotation;
|
||||||
|
smokeParticles[i].size = {2.56f, 2.56f};
|
||||||
|
smokeParticles[i].size *= sizeDis(gen);
|
||||||
|
smokeParticles[i].velocity = billboards[i].velocity / 2.f;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
m_fireGroup->AddEmitter(entity);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
m_torpedoGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([sparkleMat1 = Nz::MaterialLibrary::Get("TorpedoFlare1")] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||||
|
{
|
||||||
|
auto positionPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto rotationPtr = mapper.GetComponentPtr<const float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<const Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
auto velocityPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
renderQueue->AddBillboards(0, sparkleMat1, endId - startId + 1, positionPtr, sizePtr, rotationPtr);
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
Nz::AbstractRenderQueue::PointLight pointLight;
|
||||||
|
pointLight.ambientFactor = 0.f;
|
||||||
|
pointLight.attenuation = 0.9f;
|
||||||
|
pointLight.color = Nz::Color::Cyan;
|
||||||
|
pointLight.diffuseFactor = 1.f;
|
||||||
|
pointLight.position = positionPtr[i];
|
||||||
|
pointLight.radius = std::max(sizePtr[i].x, sizePtr[i].y) * 2.f;
|
||||||
|
pointLight.invRadius = 1.f / pointLight.radius;
|
||||||
|
pointLight.shadowMap = nullptr;
|
||||||
|
|
||||||
|
renderQueue->AddPointLight(pointLight);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Ndk::EntityHandle fireGroupEntity = m_shared.world3D->CreateEntity();
|
||||||
|
m_fireGroup = fireGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(40000, Nz::ParticleDeclaration::Get(Nz::ParticleLayout_Billboard)).CreateHandle();
|
||||||
|
RegisterParticleGroup(fireGroupEntity);
|
||||||
|
|
||||||
|
Ndk::EntityHandle smokeGroupEntity = m_shared.world3D->CreateEntity();
|
||||||
|
m_smokeGroup = smokeGroupEntity->AddComponent<Ndk::ParticleGroupComponent>(40000, Nz::ParticleDeclaration::Get(Nz::ParticleLayout_Billboard)).CreateHandle();
|
||||||
|
RegisterParticleGroup(smokeGroupEntity);
|
||||||
|
|
||||||
|
auto movementController = Nz::ParticleFunctionController::New([this] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||||
|
auto posPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
auto velPtr = mapper.GetComponentPtr<Nz::Vector3f>(Nz::ParticleComponent_Velocity);
|
||||||
|
|
||||||
|
auto& spaceshipSystem = m_shared.world3D->GetSystem<SpaceshipSystem>();
|
||||||
|
|
||||||
|
const Nz::Vector2f sizeGrowth(0.5f);
|
||||||
|
|
||||||
|
float velFactor = std::pow(0.9f, elapsedTime * 15.f);
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
float& remainingLife = lifePtr[i];
|
||||||
|
|
||||||
|
remainingLife -= elapsedTime;
|
||||||
|
if (remainingLife <= 0.f)
|
||||||
|
{
|
||||||
|
group.KillParticle(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Nz::Vector3f& position = posPtr[i];
|
||||||
|
Nz::Vector2f& size = sizePtr[i];
|
||||||
|
Nz::Vector3f& velocity = velPtr[i];
|
||||||
|
|
||||||
|
position += velPtr[i] * elapsedTime;
|
||||||
|
size += sizeGrowth * elapsedTime;
|
||||||
|
velocity *= (velocity.GetSquaredLength() >= 1.f) ? velFactor : 1.f;
|
||||||
|
|
||||||
|
if (remainingLife <= 18.f)
|
||||||
|
{
|
||||||
|
for (const Ndk::EntityHandle& entity : spaceshipSystem.GetEntities())
|
||||||
|
{
|
||||||
|
auto& spaceshipNode = entity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Nz::Spheref spaceshipSphere(spaceshipNode.GetPosition(), 5.f);
|
||||||
|
if (spaceshipSphere.Contains(position))
|
||||||
|
{
|
||||||
|
auto& spaceshipVel = entity->GetComponent<Ndk::VelocityComponent>();
|
||||||
|
|
||||||
|
Nz::Vector3f force = spaceshipVel.linearVelocity * 2.f + (position - spaceshipSphere.GetPosition()) * 10.f;
|
||||||
|
velocity += force * elapsedTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TorpedoParticle* torpedos = static_cast<TorpedoParticle*>(m_torpedoGroup->GetBuffer());
|
||||||
|
std::size_t torpedoCount = m_torpedoGroup->GetParticleCount();
|
||||||
|
for (std::size_t j = 0; j < torpedoCount; ++j)
|
||||||
|
{
|
||||||
|
Nz::Spheref tordedoSphere(torpedos[j].position, 5.f);
|
||||||
|
|
||||||
|
if (tordedoSphere.Contains(position))
|
||||||
|
{
|
||||||
|
Nz::Spheref tordedoCenter(torpedos[j].position, 2.f);
|
||||||
|
if (tordedoCenter.Contains(position))
|
||||||
|
{
|
||||||
|
group.KillParticle(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Nz::Vector3f dir = (torpedos[j].position - position);
|
||||||
|
float length;
|
||||||
|
dir.Normalize(&length);
|
||||||
|
|
||||||
|
remainingLife -= 100.f * elapsedTime / length;
|
||||||
|
size -= 100.f * sizeGrowth * elapsedTime / length;
|
||||||
|
velocity += 500.f * dir * elapsedTime / length;
|
||||||
|
velocity += torpedos[j].velocity * elapsedTime;
|
||||||
|
|
||||||
|
break; //< There's no way a particle would be in multiple torpedo at once
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
m_fireGroup->AddController(movementController);
|
||||||
|
m_fireGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
|
||||||
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||||
|
|
||||||
|
float velFactor = std::pow(0.9f, elapsedTime / 0.1f);
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
colorPtr[i].a = static_cast<Nz::UInt8>(Nz::Clamp(lifePtr[i] * 255.f, 0.f, 255.f));
|
||||||
|
}));
|
||||||
|
|
||||||
|
m_smokeGroup->AddController(movementController);
|
||||||
|
m_smokeGroup->AddController(Nz::ParticleFunctionController::New([] (Nz::ParticleGroup& group, Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, float elapsedTime)
|
||||||
|
{
|
||||||
|
auto colorPtr = mapper.GetComponentPtr<Nz::Color>(Nz::ParticleComponent_Color);
|
||||||
|
auto lifePtr = mapper.GetComponentPtr<float>(Nz::ParticleComponent_Life);
|
||||||
|
|
||||||
|
for (unsigned int i = startId; i <= endId; ++i)
|
||||||
|
{
|
||||||
|
float alpha = std::min((maxSmokeLife - lifePtr[i]) * 255.f / 5.f, 255.f);
|
||||||
|
alpha -= std::max((maxSmokeLife - lifePtr[i]) / maxSmokeLife * 255.f, 0.f);
|
||||||
|
|
||||||
|
colorPtr[i].a = static_cast<Nz::UInt8>(Nz::Clamp(alpha, 0.f, 255.f));
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
Nz::MaterialRef fireMat = Nz::Material::New("Translucent3D");
|
||||||
|
fireMat->EnableFaceCulling(true);
|
||||||
|
fireMat->SetDiffuseMap("resources/fire_particle.png");
|
||||||
|
// Additive blending for fire
|
||||||
|
fireMat->SetDstBlend(Nz::BlendFunc_One);
|
||||||
|
fireMat->SetSrcBlend(Nz::BlendFunc_SrcAlpha);
|
||||||
|
|
||||||
|
Nz::MaterialRef smokeMat = Nz::Material::New("Translucent3D");
|
||||||
|
smokeMat->EnableFaceCulling(true);
|
||||||
|
smokeMat->SetDiffuseColor(Nz::Color(128, 128, 128));
|
||||||
|
smokeMat->SetDiffuseMap("resources/smoke.png");
|
||||||
|
|
||||||
|
m_fireGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([fireMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||||
|
{
|
||||||
|
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
|
||||||
|
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto rotPtr = mapper.GetComponentPtr<const float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<const Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
|
||||||
|
renderQueue->AddBillboards(0, fireMat, endId - startId + 1, posPtr, sizePtr, rotPtr, colorPtr);
|
||||||
|
}));
|
||||||
|
|
||||||
|
m_smokeGroup->SetRenderer(Nz::ParticleFunctionRenderer::New([smokeMat] (const Nz::ParticleGroup& group, const Nz::ParticleMapper& mapper, unsigned int startId, unsigned int endId, Nz::AbstractRenderQueue* renderQueue)
|
||||||
|
{
|
||||||
|
auto colorPtr = mapper.GetComponentPtr<const Nz::Color>(Nz::ParticleComponent_Color);
|
||||||
|
auto posPtr = mapper.GetComponentPtr<const Nz::Vector3f>(Nz::ParticleComponent_Position);
|
||||||
|
auto rotPtr = mapper.GetComponentPtr<const float>(Nz::ParticleComponent_Rotation);
|
||||||
|
auto sizePtr = mapper.GetComponentPtr<const Nz::Vector2f>(Nz::ParticleComponent_Size);
|
||||||
|
|
||||||
|
renderQueue->AddBillboards(0, smokeMat, endId - startId + 1, posPtr, sizePtr, rotPtr, colorPtr);
|
||||||
|
}));
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
m_ambientMusic.Play();
|
||||||
|
m_turretFireSound.LoadFromFile("resources/turretFire.wav");
|
||||||
|
m_turretReloadSound.LoadFromFile("resources/turretReload.wav");
|
||||||
|
|
||||||
|
//m_onMouseMoved.Connect(m_shared.target->GetEventHandler().OnMouseMoved, this, &SpacebattleExample::OnMouseMoved);
|
||||||
|
//m_shared.target->SetCursor(Nz::WindowCursor_None);
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Nz::TextSpriteRef introText = Nz::TextSprite::New();
|
||||||
|
introText->Update(Nz::SimpleTextDrawer::Draw("--Tourelle de défense du secteur A407M2--\nLes contrôles ont été adaptés à vos contrôleurs:\nZQSD pour orienter la tourelle, espace pour tirer.\n", 72));
|
||||||
|
introText->SetScale(0.5f);
|
||||||
|
|
||||||
|
m_introText = m_shared.world3D->CreateEntity();
|
||||||
|
Ndk::NodeComponent& introNode = m_introText->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::GraphicsComponent& introGfx = m_introText->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
introGfx.Attach(introText, 1);
|
||||||
|
RegisterEntity(m_introText);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonNode = m_turret.cannonEntity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Nz::Boxf introAABB = introGfx.GetBoundingVolume().aabb;
|
||||||
|
introNode.SetPosition(cannonNode.GetForward() * 500.f + introNode.GetLeft() * introAABB.width / 2.f + introNode.GetUp() * introAABB.height / 2.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::Leave(Ndk::StateMachine& fsm)
|
||||||
|
{
|
||||||
|
m_ambientMusic.Stop();
|
||||||
|
m_shared.world3D->RemoveSystem<LaserBeamSystem>();
|
||||||
|
m_shared.world3D->RemoveSystem<SpaceshipSystem>();
|
||||||
|
m_turretFireSound.Stop();
|
||||||
|
m_turretReloadSound.Stop();
|
||||||
|
|
||||||
|
ParticleDemo::Leave(fsm);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SpacebattleExample::Update(Ndk::StateMachine& fsm, float elapsedTime)
|
||||||
|
{
|
||||||
|
if (!ParticleDemo::Update(fsm, elapsedTime))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const float speed = 100.f;
|
||||||
|
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Z))
|
||||||
|
m_turretCannonBaseRotation = std::max(m_turretCannonBaseRotation - speed * elapsedTime, -65.f);
|
||||||
|
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::S))
|
||||||
|
m_turretCannonBaseRotation = std::min(m_turretCannonBaseRotation + speed * elapsedTime, 40.f);
|
||||||
|
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Q))
|
||||||
|
m_turretBaseRotation += speed * elapsedTime;
|
||||||
|
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::D))
|
||||||
|
m_turretBaseRotation -= speed * elapsedTime;
|
||||||
|
|
||||||
|
m_turret.cannonBaseEntity->GetComponent<Ndk::NodeComponent>().SetRotation(Nz::EulerAnglesf(m_turretCannonBaseRotation, 0.f, 0.f));
|
||||||
|
m_turret.rotatingBaseEntity->GetComponent<Ndk::NodeComponent>().SetRotation(Nz::EulerAnglesf(0.f, m_turretBaseRotation, 0.f));
|
||||||
|
|
||||||
|
bool discharged = m_turretShootTimer < 1.f;
|
||||||
|
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Space) && !discharged)
|
||||||
|
{
|
||||||
|
m_turretFireSound.Play();
|
||||||
|
|
||||||
|
m_turretShootTimer = -1.f;
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonNode = m_turret.cannonEntity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
TorpedoParticle* particle = static_cast<TorpedoParticle*>(m_torpedoGroup->CreateParticle());
|
||||||
|
particle->color = Nz::Color::White;
|
||||||
|
particle->position = cannonNode.ToGlobalPosition(Nz::Vector3f::Forward() * 10.f);
|
||||||
|
particle->rotation = 0.f;
|
||||||
|
particle->life = 15.f;
|
||||||
|
particle->size.Set(13.34f, 7.41f);
|
||||||
|
particle->size *= 2.f;
|
||||||
|
particle->velocity = cannonNode.GetForward() * 100.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_turretShootTimer += elapsedTime * 2.f;
|
||||||
|
if (discharged && m_turretShootTimer >= 1.f)
|
||||||
|
m_turretReloadSound.Play();
|
||||||
|
|
||||||
|
m_turret.cannonEntity->GetComponent<Ndk::NodeComponent>().SetPosition(Nz::Vector3f::Backward() * std::sin(std::min(m_turretShootTimer, 0.f) * float(M_PI)) * 3.f);
|
||||||
|
|
||||||
|
m_spaceshipSpawnCounter += elapsedTime;
|
||||||
|
if (m_spaceshipSpawnCounter >= 10.f)
|
||||||
|
{
|
||||||
|
m_spaceshipSpawnCounter -= 10.f;
|
||||||
|
|
||||||
|
auto& spacestationNode = m_spacestationEntity->GetComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Ndk::EntityHandle spaceship = m_spaceshipTemplate->Clone();
|
||||||
|
RegisterEntity(spaceship);
|
||||||
|
auto& nodeComponent = spaceship->GetComponent<Ndk::NodeComponent>();
|
||||||
|
auto& spaceshipComponent = spaceship->GetComponent<SpaceshipComponent>();
|
||||||
|
|
||||||
|
spaceshipComponent.targetPos = m_shared.viewer3D->GetComponent<Ndk::NodeComponent>().GetPosition();
|
||||||
|
nodeComponent.SetPosition(spacestationNode.GetPosition());
|
||||||
|
nodeComponent.SetRotation(Nz::Quaternionf::RotationBetween(Nz::Vector3f::Forward(), spacestationNode.GetRight()));
|
||||||
|
nodeComponent.Move(Nz::Vector3f::Forward() * 15.f + Nz::Vector3f::Down() * 5.f, Nz::CoordSys_Local);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_introTimer -= elapsedTime;
|
||||||
|
if (m_introTimer <= 0.f && m_introText)
|
||||||
|
m_introText->Kill();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::CreateSpaceShip()
|
||||||
|
{
|
||||||
|
m_spacestationEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_spacestationEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& spacestationNode = m_spacestationEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
spacestationNode.SetPosition(Nz::Vector3f::Forward() * 500.f + Nz::Vector3f::Up() * 200.f + Nz::Vector3f::Right() * 250.f);
|
||||||
|
spacestationNode.SetRotation(Nz::EulerAnglesf(0.f, 15.f, 0.f));
|
||||||
|
spacestationNode.SetScale(0.1f);
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& spacestationGfx = m_spacestationEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
spacestationGfx.Attach(&m_spacestationModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::CreateTurret()
|
||||||
|
{
|
||||||
|
// Fixed base
|
||||||
|
m_turret.baseEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.baseEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& baseNode = m_turret.baseEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
//baseNode.SetParent(m_spacestationEntity);
|
||||||
|
baseNode.SetRotation(Nz::EulerAnglesf(0.f, 180.f, 0.f));
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& baseGfx = m_turret.baseEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
baseGfx.Attach(&m_turret.baseModel);
|
||||||
|
|
||||||
|
// Rotating base
|
||||||
|
m_turret.rotatingBaseEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.rotatingBaseEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& rotatingBaseNode = m_turret.rotatingBaseEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
rotatingBaseNode.SetParent(m_turret.baseEntity);
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& rotatingBaseGfx = m_turret.rotatingBaseEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
rotatingBaseGfx.Attach(&m_turret.rotatingBaseModel);
|
||||||
|
|
||||||
|
// Cannon base
|
||||||
|
m_turret.cannonBaseEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.cannonBaseEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonBaseNode = m_turret.cannonBaseEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
cannonBaseNode.SetPosition({0.f, 3.39623547f, 0.f});
|
||||||
|
cannonBaseNode.SetParent(m_turret.rotatingBaseEntity);
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& cannonBaseGfx = m_turret.cannonBaseEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
cannonBaseGfx.Attach(&m_turret.cannonBaseModel);
|
||||||
|
|
||||||
|
// Cannon anchor
|
||||||
|
m_turret.cannonAnchorEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.cannonAnchorEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonAnchorNode = m_turret.cannonAnchorEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
cannonAnchorNode.SetPosition({0.f, 2.96482944f, 3.20705462f});
|
||||||
|
cannonAnchorNode.SetParent(m_turret.cannonBaseEntity);
|
||||||
|
|
||||||
|
// Cannon
|
||||||
|
m_turret.cannonEntity = m_shared.world3D->CreateEntity();
|
||||||
|
RegisterEntity(m_turret.cannonEntity);
|
||||||
|
|
||||||
|
Ndk::NodeComponent& cannonNode = m_turret.cannonEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
cannonNode.SetParent(m_turret.cannonAnchorEntity);
|
||||||
|
cannonNode.SetRotation(Nz::EulerAnglesf(0.f, 180.f, 0.f));
|
||||||
|
|
||||||
|
Ndk::GraphicsComponent& cannonGfx = m_turret.cannonEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
cannonGfx.Attach(&m_turret.cannonModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpacebattleExample::OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event)
|
||||||
|
{
|
||||||
|
const float speed = 0.1f;
|
||||||
|
|
||||||
|
m_turretCannonBaseRotation = Nz::Clamp(m_turretCannonBaseRotation + speed * event.deltaY, -65.f, 40.f);
|
||||||
|
m_turretBaseRotation -= event.deltaX * speed;
|
||||||
|
|
||||||
|
Nz::Mouse::SetPosition(m_shared.target->GetWidth() / 2, m_shared.target->GetHeight() / 2, *m_shared.target);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_EXAMPLES_PARTICLES_SPACEBATTLE_HPP
|
||||||
|
#define NAZARA_EXAMPLES_PARTICLES_SPACEBATTLE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Audio/Music.hpp>
|
||||||
|
#include <Nazara/Audio/Sound.hpp>
|
||||||
|
#include <Nazara/Graphics/AbstractBackground.hpp>
|
||||||
|
#include <Nazara/Graphics/Model.hpp>
|
||||||
|
#include <Nazara/Graphics/ParticleStruct.hpp>
|
||||||
|
#include <Nazara/Graphics/SkyboxBackground.hpp>
|
||||||
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
|
#include <Nazara/Utility/EventHandler.hpp>
|
||||||
|
#include <NDK/Entity.hpp>
|
||||||
|
#include <NDK/State.hpp>
|
||||||
|
#include <vector>
|
||||||
|
#include "Common.hpp"
|
||||||
|
|
||||||
|
class SpacebattleExample : public ParticleDemo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SpacebattleExample(ExampleShared& sharedData);
|
||||||
|
~SpacebattleExample() = default;
|
||||||
|
|
||||||
|
void Enter(Ndk::StateMachine& fsm) override;
|
||||||
|
void Leave(Ndk::StateMachine& fsm) override;
|
||||||
|
bool Update(Ndk::StateMachine& fsm, float elapsedTime) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CreateSpaceShip();
|
||||||
|
void CreateTurret();
|
||||||
|
void OnMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
|
||||||
|
|
||||||
|
struct Turret
|
||||||
|
{
|
||||||
|
Nz::Model baseModel;
|
||||||
|
Nz::Model cannonModel;
|
||||||
|
Nz::Model cannonBaseModel;
|
||||||
|
Nz::Model rotatingBaseModel;
|
||||||
|
Ndk::EntityHandle baseEntity;
|
||||||
|
Ndk::EntityHandle cannonAnchorEntity;
|
||||||
|
Ndk::EntityHandle cannonEntity;
|
||||||
|
Ndk::EntityHandle cannonBaseEntity;
|
||||||
|
Ndk::EntityHandle rotatingBaseEntity;
|
||||||
|
};
|
||||||
|
|
||||||
|
Turret m_turret;
|
||||||
|
float m_introTimer;
|
||||||
|
float m_spaceshipSpawnCounter;
|
||||||
|
float m_turretBaseRotation;
|
||||||
|
float m_turretCannonBaseRotation;
|
||||||
|
float m_turretShootTimer;
|
||||||
|
Nz::Model m_spaceshipModel;
|
||||||
|
Nz::Model m_spacestationModel;
|
||||||
|
Nz::Music m_ambientMusic;
|
||||||
|
Nz::ParticleDeclarationRef m_torpedoDeclaration;
|
||||||
|
Nz::ParticleRendererRef m_laserBeamRenderer;
|
||||||
|
Nz::Sound m_turretFireSound;
|
||||||
|
Nz::Sound m_turretReloadSound;
|
||||||
|
Nz::SkyboxBackground m_skybox;
|
||||||
|
Ndk::EntityHandle m_introText;
|
||||||
|
Ndk::EntityHandle m_spaceshipTemplate;
|
||||||
|
Ndk::EntityHandle m_spacestationEntity;
|
||||||
|
Ndk::ParticleGroupComponentHandle m_fireGroup;
|
||||||
|
Ndk::ParticleGroupComponentHandle m_smokeGroup;
|
||||||
|
Ndk::ParticleGroupComponentHandle m_torpedoGroup;
|
||||||
|
|
||||||
|
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_onMouseMoved);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NAZARA_EXAMPLES_PARTICLES_SPACEBATTLE_HPP
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
EXAMPLE.Name = "Particles"
|
||||||
|
|
||||||
|
EXAMPLE.EnableConsole = true
|
||||||
|
|
||||||
|
EXAMPLE.Files = {
|
||||||
|
"*.hpp",
|
||||||
|
"*.inl",
|
||||||
|
"*.cpp"
|
||||||
|
}
|
||||||
|
|
||||||
|
EXAMPLE.Libraries = {
|
||||||
|
"NazaraSDK"
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,202 @@
|
||||||
|
#include <Nazara/Audio.hpp>
|
||||||
|
#include <Nazara/Core.hpp>
|
||||||
|
#include <Nazara/Graphics.hpp>
|
||||||
|
#include <Nazara/Lua.hpp>
|
||||||
|
#include <Nazara/Network.hpp>
|
||||||
|
#include <Nazara/Noise.hpp>
|
||||||
|
#include <Nazara/Physics3D.hpp>
|
||||||
|
#include <Nazara/Renderer.hpp>
|
||||||
|
#include <Nazara/Utility.hpp>
|
||||||
|
#include <NDK/Application.hpp>
|
||||||
|
#include <NDK/Components.hpp>
|
||||||
|
#include <NDK/Systems.hpp>
|
||||||
|
#include <NDK/StateMachine.hpp>
|
||||||
|
#include "LogoDemo.hpp"
|
||||||
|
#include "SpacebattleDemo.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
Nz::ContextParameters::defaultCompatibilityProfile = true;
|
||||||
|
|
||||||
|
Ndk::Application app;
|
||||||
|
|
||||||
|
// Mix all sounds in mono (in order to give them 3D position)
|
||||||
|
Nz::SoundBufferParams soundParams;
|
||||||
|
soundParams.forceMono = true;
|
||||||
|
|
||||||
|
Nz::SoundBufferManager::SetDefaultParameters(soundParams);
|
||||||
|
|
||||||
|
// Pour commencer le mode vidéo, celui-ci va définir la taille de la zone de rendu et le nombre de bits par pixels
|
||||||
|
Nz::VideoMode mode = Nz::VideoMode::GetDesktopMode(); // Nous récupérons le mode vidéo du bureau
|
||||||
|
|
||||||
|
// Nous allons prendre les trois quarts de la résolution du bureau pour notre fenêtre
|
||||||
|
mode.width = 3 * mode.width / 4;
|
||||||
|
mode.height = 3 * mode.height / 4;
|
||||||
|
|
||||||
|
Nz::ContextParameters targetParams;
|
||||||
|
targetParams.antialiasingLevel = 0;
|
||||||
|
|
||||||
|
Nz::RenderWindow& window = app.AddWindow<Nz::RenderWindow>(mode, "Nazara demo - Particles", Nz::WindowStyle_Closable, targetParams);
|
||||||
|
//Nz::RenderWindow& window = app.AddWindow<Nz::RenderWindow>(Nz::VideoMode(1920, 1080), "Nazara demo - Particles", Nz::WindowStyle_Fullscreen, targetParams);
|
||||||
|
|
||||||
|
Ndk::World& world3D = app.AddWorld();
|
||||||
|
Ndk::World& world2D = app.AddWorld();
|
||||||
|
|
||||||
|
std::random_device randomDevice;
|
||||||
|
|
||||||
|
ExampleShared shared;
|
||||||
|
shared.randomGen.seed(randomDevice());
|
||||||
|
shared.target = &window;
|
||||||
|
shared.world2D = &world2D;
|
||||||
|
shared.world3D = &world3D;
|
||||||
|
|
||||||
|
shared.demoName = Nz::TextSprite::New();
|
||||||
|
shared.demoName->Update(Nz::SimpleTextDrawer::Draw("XX - DemoName", 48));
|
||||||
|
|
||||||
|
shared.fpsCount = Nz::TextSprite::New();
|
||||||
|
shared.fpsCount->Update(Nz::SimpleTextDrawer::Draw("XXXXX FPS", 24));
|
||||||
|
|
||||||
|
shared.particleCount = Nz::TextSprite::New();
|
||||||
|
shared.particleCount->Update(Nz::SimpleTextDrawer::Draw("XXXXX particles", 36));
|
||||||
|
|
||||||
|
world2D.GetSystem<Ndk::RenderSystem>().SetGlobalUp(Nz::Vector3f::Down());
|
||||||
|
world3D.GetSystem<Ndk::RenderSystem>().ChangeRenderTechnique<Nz::DeferredRenderTechnique>();
|
||||||
|
|
||||||
|
|
||||||
|
Ndk::EntityHandle viewEntity = world2D.CreateEntity();
|
||||||
|
viewEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
|
||||||
|
Ndk::CameraComponent& viewer = viewEntity->AddComponent<Ndk::CameraComponent>();
|
||||||
|
viewer.SetTarget(&window);
|
||||||
|
viewer.SetProjectionType(Nz::ProjectionType_Orthogonal);
|
||||||
|
|
||||||
|
shared.viewer2D = viewEntity;
|
||||||
|
|
||||||
|
Ndk::EntityHandle cameraEntity = world3D.CreateEntity();
|
||||||
|
cameraEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
cameraEntity->AddComponent<Ndk::ListenerComponent>();
|
||||||
|
|
||||||
|
Ndk::CameraComponent& camera = cameraEntity->AddComponent<Ndk::CameraComponent>();
|
||||||
|
camera.SetTarget(&window);
|
||||||
|
camera.SetZFar(10000.f);
|
||||||
|
|
||||||
|
shared.viewer3D = cameraEntity;
|
||||||
|
|
||||||
|
Ndk::EntityHandle demoNameEntity = world2D.CreateEntity();
|
||||||
|
Ndk::NodeComponent& demoNameNode = demoNameEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::GraphicsComponent& demoNameGfx = demoNameEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
demoNameGfx.Attach(shared.demoName, 1);
|
||||||
|
|
||||||
|
Ndk::EntityHandle fpsCountEntity = world2D.CreateEntity();
|
||||||
|
Ndk::NodeComponent& fpsNode = fpsCountEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::GraphicsComponent& fpsGfx = fpsCountEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
fpsGfx.Attach(shared.fpsCount, 1);
|
||||||
|
|
||||||
|
Ndk::EntityHandle particleCountEntity = world2D.CreateEntity();
|
||||||
|
Ndk::NodeComponent& particleCountNode = particleCountEntity->AddComponent<Ndk::NodeComponent>();
|
||||||
|
Ndk::GraphicsComponent& particleCountGfx = particleCountEntity->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
particleCountGfx.Attach(shared.particleCount, 1);
|
||||||
|
|
||||||
|
|
||||||
|
Nz::Boxf fpsCountBox = fpsGfx.GetBoundingVolume().aabb;
|
||||||
|
Nz::Boxf particleCountBox = particleCountGfx.GetBoundingVolume().aabb;
|
||||||
|
|
||||||
|
demoNameNode.SetPosition(5.f, 5.f);
|
||||||
|
particleCountNode.SetPosition(5.f, window.GetHeight() - particleCountBox.height - 5.f);
|
||||||
|
fpsNode.SetPosition(5.f, window.GetHeight() - fpsCountBox.height - particleCountBox.height - 5.f);
|
||||||
|
|
||||||
|
|
||||||
|
//shared.demos.push_back(std::make_shared<LogoExample>(shared));
|
||||||
|
shared.demos.push_back(std::make_shared<SpacebattleExample>(shared));
|
||||||
|
|
||||||
|
std::size_t demoIndex = 0;
|
||||||
|
Ndk::StateMachine stateMachine(shared.demos[demoIndex]);
|
||||||
|
|
||||||
|
window.EnableEventPolling(true);
|
||||||
|
|
||||||
|
while (app.Run())
|
||||||
|
{
|
||||||
|
Nz::WindowEvent event;
|
||||||
|
while (window.PollEvent(&event))
|
||||||
|
{
|
||||||
|
switch (event.type)
|
||||||
|
{
|
||||||
|
case Nz::WindowEventType_KeyPressed:
|
||||||
|
{
|
||||||
|
switch (event.key.code)
|
||||||
|
{
|
||||||
|
case Nz::Keyboard::Backspace:
|
||||||
|
stateMachine.ChangeState(stateMachine.GetCurrentState());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Nz::Keyboard::Escape:
|
||||||
|
app.Quit();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Nz::Keyboard::Left:
|
||||||
|
{
|
||||||
|
if (shared.demos.size() <= 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (demoIndex == 0)
|
||||||
|
demoIndex = shared.demos.size();
|
||||||
|
|
||||||
|
demoIndex--;
|
||||||
|
stateMachine.ChangeState(shared.demos[demoIndex]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::Keyboard::Right:
|
||||||
|
{
|
||||||
|
if (shared.demos.size() <= 1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
demoIndex++;
|
||||||
|
if (demoIndex == shared.demos.size())
|
||||||
|
demoIndex = 0;
|
||||||
|
|
||||||
|
stateMachine.ChangeState(shared.demos[demoIndex]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::Keyboard::Pause:
|
||||||
|
{
|
||||||
|
auto& velocitySystem = shared.world3D->GetSystem<Ndk::VelocitySystem>();
|
||||||
|
velocitySystem.Enable(!velocitySystem.IsEnabled());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::Keyboard::F5:
|
||||||
|
{
|
||||||
|
Nz::Image screenshot;
|
||||||
|
screenshot.Create(Nz::ImageType_2D, Nz::PixelFormatType_RGBA8, 1920, 1080);
|
||||||
|
window.CopyToImage(&screenshot);
|
||||||
|
|
||||||
|
static unsigned int counter = 1;
|
||||||
|
screenshot.SaveToFile("screenshot_" + Nz::String::Number(counter++) + ".png");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Nz::WindowEventType_Quit:
|
||||||
|
window.Close();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stateMachine.Update(app.GetUpdateTime());
|
||||||
|
|
||||||
|
window.Display();
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -73,6 +73,7 @@ namespace Nz
|
||||||
|
|
||||||
bool FillAndQueueBuffer(unsigned int buffer);
|
bool FillAndQueueBuffer(unsigned int buffer);
|
||||||
void MusicThread();
|
void MusicThread();
|
||||||
|
void StopThread();
|
||||||
|
|
||||||
static MusicLoader::LoaderList s_loaders;
|
static MusicLoader::LoaderList s_loaders;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline ByteStream(Stream* stream = nullptr);
|
inline ByteStream(Stream* stream = nullptr);
|
||||||
ByteStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
ByteStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
|
||||||
ByteStream(void* ptr, Nz::UInt64 size);
|
ByteStream(void* ptr, Nz::UInt64 size);
|
||||||
ByteStream(const void* ptr, Nz::UInt64 size);
|
ByteStream(const void* ptr, Nz::UInt64 size);
|
||||||
ByteStream(const ByteStream&) = delete;
|
ByteStream(const ByteStream&) = delete;
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Nz
|
||||||
|
|
||||||
inline void SetDataEndianness(Endianness endiannes);
|
inline void SetDataEndianness(Endianness endiannes);
|
||||||
inline void SetStream(Stream* stream);
|
inline void SetStream(Stream* stream);
|
||||||
void SetStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
void SetStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
|
||||||
void SetStream(void* ptr, Nz::UInt64 size);
|
void SetStream(void* ptr, Nz::UInt64 size);
|
||||||
void SetStream(const void* ptr, Nz::UInt64 size);
|
void SetStream(const void* ptr, Nz::UInt64 size);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#ifndef NAZARA_ENUMS_CORE_HPP
|
#ifndef NAZARA_ENUMS_CORE_HPP
|
||||||
#define NAZARA_ENUMS_CORE_HPP
|
#define NAZARA_ENUMS_CORE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Flags.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
enum CoordSys
|
enum CoordSys
|
||||||
|
|
@ -73,23 +75,31 @@ namespace Nz
|
||||||
HashType_Max = HashType_Whirlpool
|
HashType_Max = HashType_Whirlpool
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OpenModeFlags
|
enum OpenMode
|
||||||
{
|
{
|
||||||
OpenMode_NotOpen = 0x00, // Use the current mod of opening
|
OpenMode_NotOpen, // Use the current mod of opening
|
||||||
|
|
||||||
OpenMode_Append = 0x01, // Disable writing on existing parts and put the cursor at the end
|
OpenMode_Append, // Disable writing on existing parts and put the cursor at the end
|
||||||
OpenMode_Lock = 0x02, // Disable modifying the file before it is open
|
OpenMode_Lock, // Disable modifying the file before it is open
|
||||||
OpenMode_MustExit = 0x04, // Fail if the file doesn't exists, even if opened in write mode
|
OpenMode_MustExist, // Fail if the file doesn't exists, even if opened in write mode
|
||||||
OpenMode_ReadOnly = 0x08, // Open in read only
|
OpenMode_ReadOnly, // Open in read only
|
||||||
OpenMode_Text = 0x10, // Open in text mod
|
OpenMode_Text, // Open in text mod
|
||||||
OpenMode_Truncate = 0x20, // Create the file if it doesn't exist and empty it if it exists
|
OpenMode_Truncate, // Create the file if it doesn't exist and empty it if it exists
|
||||||
OpenMode_WriteOnly = 0x40, // Open in write only, create the file if it doesn't exist
|
OpenMode_WriteOnly, // Open in write only, create the file if it doesn't exist
|
||||||
|
|
||||||
OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly, // Open in read and write
|
OpenMode_Max = OpenMode_WriteOnly
|
||||||
|
|
||||||
OpenMode_Max = OpenMode_WriteOnly * 2 - 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct EnableFlagsOperators<OpenMode>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
using OpenModeFlags = Flags<OpenMode>;
|
||||||
|
|
||||||
|
constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly;
|
||||||
|
|
||||||
enum ParameterType
|
enum ParameterType
|
||||||
{
|
{
|
||||||
ParameterType_Boolean,
|
ParameterType_Boolean,
|
||||||
|
|
@ -173,16 +183,24 @@ namespace Nz
|
||||||
SphereType_Max = SphereType_UV
|
SphereType_Max = SphereType_UV
|
||||||
};
|
};
|
||||||
|
|
||||||
enum StreamOptionFlags
|
enum StreamOption
|
||||||
{
|
{
|
||||||
StreamOption_None = 0,
|
StreamOption_None,
|
||||||
|
|
||||||
StreamOption_Sequential = 0x1,
|
StreamOption_Sequential,
|
||||||
StreamOption_Text = 0x2,
|
StreamOption_Text,
|
||||||
|
|
||||||
StreamOption_Max = StreamOption_Text * 2 - 1
|
StreamOption_Max = StreamOption_Text
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct EnableFlagsOperators<StreamOption>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
using StreamOptionFlags = Flags<StreamOption>;
|
||||||
|
|
||||||
enum Ternary
|
enum Ternary
|
||||||
{
|
{
|
||||||
Ternary_False,
|
Ternary_False,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
File();
|
File();
|
||||||
File(const String& filePath);
|
File(const String& filePath);
|
||||||
File(const String& filePath, UInt32 openMode);
|
File(const String& filePath, OpenModeFlags openMode);
|
||||||
File(const File&) = delete;
|
File(const File&) = delete;
|
||||||
File(File&& file) noexcept;
|
File(File&& file) noexcept;
|
||||||
~File();
|
~File();
|
||||||
|
|
@ -57,8 +57,8 @@ namespace Nz
|
||||||
|
|
||||||
bool IsOpen() const;
|
bool IsOpen() const;
|
||||||
|
|
||||||
bool Open(unsigned int openMode = OpenMode_NotOpen);
|
bool Open(OpenModeFlags openMode = OpenMode_NotOpen);
|
||||||
bool Open(const String& filePath, unsigned int openMode = OpenMode_NotOpen);
|
bool Open(const String& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
|
||||||
|
|
||||||
bool Rename(const String& newFilePath);
|
bool Rename(const String& newFilePath);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
// Copyright (C) 2016 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_FLAGS_HPP
|
||||||
|
#define NAZARA_FLAGS_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template<typename E>
|
||||||
|
class Flags
|
||||||
|
{
|
||||||
|
static_assert(std::is_enum<E>::value, "Type must be an enumeration");
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr Flags(UInt32 value);
|
||||||
|
constexpr Flags(E enumVal);
|
||||||
|
|
||||||
|
explicit constexpr operator bool() const;
|
||||||
|
explicit constexpr operator UInt32() const;
|
||||||
|
|
||||||
|
constexpr Flags operator~() const;
|
||||||
|
constexpr Flags operator&(Flags rhs) const;
|
||||||
|
constexpr Flags operator|(Flags rhs) const;
|
||||||
|
constexpr Flags operator^(Flags rhs) const;
|
||||||
|
|
||||||
|
constexpr bool operator==(Flags rhs) const;
|
||||||
|
constexpr bool operator!=(Flags rhs) const;
|
||||||
|
|
||||||
|
/*constexpr*/ Flags& operator|=(Flags rhs);
|
||||||
|
/*constexpr*/ Flags& operator&=(Flags rhs);
|
||||||
|
/*constexpr*/ Flags& operator^=(Flags rhs);
|
||||||
|
|
||||||
|
static constexpr UInt32 GetFlagValue(E enumValue);
|
||||||
|
|
||||||
|
private:
|
||||||
|
UInt32 m_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
// From: https://www.justsoftwaresolutions.co.uk/cplusplus/using-enum-classes-as-bitfields.html
|
||||||
|
template<typename E>
|
||||||
|
struct EnableFlagsOperators
|
||||||
|
{
|
||||||
|
static constexpr bool value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator~(E lhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator|(E lhs, E rhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator&(E lhs, E rhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator^(E lhs, E rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/Flags.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_FLAGS_HPP
|
||||||
|
|
@ -0,0 +1,134 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/Flags.hpp>
|
||||||
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* \ingroup core
|
||||||
|
* \class Nz::Flags
|
||||||
|
* \brief Core class that represents a set of bits
|
||||||
|
*
|
||||||
|
* This class meets the requirements of Container, AllocatorAwareContainer, SequenceContainer
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E>::Flags(UInt32 value) :
|
||||||
|
m_value(value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E>::Flags(E enumVal) :
|
||||||
|
Flags(GetFlagValue(enumVal))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E>::operator bool() const
|
||||||
|
{
|
||||||
|
return m_value != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E>::operator UInt32() const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E> Flags<E>::operator~() const
|
||||||
|
{
|
||||||
|
return Flags(~m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E> Flags<E>::operator&(Flags rhs) const
|
||||||
|
{
|
||||||
|
return Flags(m_value & rhs.m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E> Flags<E>::operator|(Flags rhs) const
|
||||||
|
{
|
||||||
|
return Flags(m_value | rhs.m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr Flags<E> Flags<E>::operator^(Flags rhs) const
|
||||||
|
{
|
||||||
|
return Flags(m_value ^ rhs.m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr bool Flags<E>::operator==(Flags rhs) const
|
||||||
|
{
|
||||||
|
return m_value == rhs.m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr bool Flags<E>::operator!=(Flags rhs) const
|
||||||
|
{
|
||||||
|
return !operator==(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
/*constexpr*/ Flags<E>& Flags<E>::operator|=(Flags rhs)
|
||||||
|
{
|
||||||
|
m_value |= rhs.m_value;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
/*constexpr*/ Flags<E>& Flags<E>::operator&=(Flags rhs)
|
||||||
|
{
|
||||||
|
m_value &= rhs.m_value;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
/*constexpr*/ Flags<E>& Flags<E>::operator^=(Flags rhs)
|
||||||
|
{
|
||||||
|
m_value ^= rhs.m_value;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr UInt32 Flags<E>::GetFlagValue(E enumValue)
|
||||||
|
{
|
||||||
|
return 1U << static_cast<UInt32>(enumValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator~(E lhs)
|
||||||
|
{
|
||||||
|
return ~Flags<E>(lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator|(E lhs, E rhs)
|
||||||
|
{
|
||||||
|
return Flags<E>(lhs) | rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator&(E lhs, E rhs)
|
||||||
|
{
|
||||||
|
return Flags<E>(lhs) & rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator^(E lhs, E rhs)
|
||||||
|
{
|
||||||
|
return Flags<E>(lhs) ^ rhs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline MemoryStream();
|
inline MemoryStream();
|
||||||
inline MemoryStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
inline MemoryStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
|
||||||
MemoryStream(const MemoryStream&) = default;
|
MemoryStream(const MemoryStream&) = default;
|
||||||
MemoryStream(MemoryStream&&) = default;
|
MemoryStream(MemoryStream&&) = default;
|
||||||
~MemoryStream() = default;
|
~MemoryStream() = default;
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Nz
|
||||||
UInt64 GetCursorPos() const override;
|
UInt64 GetCursorPos() const override;
|
||||||
UInt64 GetSize() const override;
|
UInt64 GetSize() const override;
|
||||||
|
|
||||||
void SetBuffer(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
|
void SetBuffer(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
|
||||||
bool SetCursorPos(UInt64 offset) override;
|
bool SetCursorPos(UInt64 offset) override;
|
||||||
|
|
||||||
MemoryStream& operator=(const MemoryStream&) = default;
|
MemoryStream& operator=(const MemoryStream&) = default;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Nz
|
||||||
* \param byteArray Bytes to stream
|
* \param byteArray Bytes to stream
|
||||||
* \param openMode Reading/writing mode for the stream
|
* \param openMode Reading/writing mode for the stream
|
||||||
*/
|
*/
|
||||||
inline MemoryStream::MemoryStream(ByteArray* byteArray, UInt32 openMode) :
|
inline MemoryStream::MemoryStream(ByteArray* byteArray, OpenModeFlags openMode) :
|
||||||
MemoryStream()
|
MemoryStream()
|
||||||
{
|
{
|
||||||
SetBuffer(byteArray, openMode);
|
SetBuffer(byteArray, openMode);
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ namespace Nz
|
||||||
virtual UInt64 GetCursorPos() const = 0;
|
virtual UInt64 GetCursorPos() const = 0;
|
||||||
virtual String GetDirectory() const;
|
virtual String GetDirectory() const;
|
||||||
virtual String GetPath() const;
|
virtual String GetPath() const;
|
||||||
inline UInt32 GetOpenMode() const;
|
inline OpenModeFlags GetOpenMode() const;
|
||||||
inline UInt32 GetStreamOptions() const;
|
inline StreamOptionFlags GetStreamOptions() const;
|
||||||
|
|
||||||
virtual UInt64 GetSize() const = 0;
|
virtual UInt64 GetSize() const = 0;
|
||||||
|
|
||||||
|
|
@ -55,14 +55,14 @@ namespace Nz
|
||||||
Stream& operator=(Stream&&) = default;
|
Stream& operator=(Stream&&) = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
inline Stream(UInt32 streamOptions = StreamOption_None, UInt32 openMode = OpenMode_NotOpen);
|
inline Stream(StreamOptionFlags streamOptions = StreamOption_None, OpenModeFlags openMode = OpenMode_NotOpen);
|
||||||
|
|
||||||
virtual void FlushStream() = 0;
|
virtual void FlushStream() = 0;
|
||||||
virtual std::size_t ReadBlock(void* buffer, std::size_t size) = 0;
|
virtual std::size_t ReadBlock(void* buffer, std::size_t size) = 0;
|
||||||
virtual std::size_t WriteBlock(const void* buffer, std::size_t size) = 0;
|
virtual std::size_t WriteBlock(const void* buffer, std::size_t size) = 0;
|
||||||
|
|
||||||
UInt32 m_openMode;
|
OpenModeFlags m_openMode;
|
||||||
UInt32 m_streamOptions;
|
StreamOptionFlags m_streamOptions;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Nz
|
||||||
* \param openMode Reading/writing mode for the stream
|
* \param openMode Reading/writing mode for the stream
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline Stream::Stream(UInt32 streamOptions, UInt32 openMode) :
|
inline Stream::Stream(StreamOptionFlags streamOptions, OpenModeFlags openMode) :
|
||||||
m_openMode(openMode),
|
m_openMode(openMode),
|
||||||
m_streamOptions(streamOptions)
|
m_streamOptions(streamOptions)
|
||||||
{
|
{
|
||||||
|
|
@ -53,7 +53,7 @@ namespace Nz
|
||||||
* \return Reading/writing mode for the stream
|
* \return Reading/writing mode for the stream
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline UInt32 Stream::GetOpenMode() const
|
inline OpenModeFlags Stream::GetOpenMode() const
|
||||||
{
|
{
|
||||||
return m_openMode;
|
return m_openMode;
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +63,7 @@ namespace Nz
|
||||||
* \return Options of the stream
|
* \return Options of the stream
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline UInt32 Stream::GetStreamOptions() const
|
inline StreamOptionFlags Stream::GetStreamOptions() const
|
||||||
{
|
{
|
||||||
return m_streamOptions;
|
return m_streamOptions;
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +116,7 @@ namespace Nz
|
||||||
* \param size Size meant to be read
|
* \param size Size meant to be read
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraAssert if stream is not readable
|
* \remark Produces a NazaraAssert if stream is not readable
|
||||||
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
|
* \remark If preallocated space of buffer is less than the size, the behavior is undefined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline std::size_t Stream::Read(void* buffer, std::size_t size)
|
inline std::size_t Stream::Read(void* buffer, std::size_t size)
|
||||||
|
|
@ -134,7 +134,7 @@ namespace Nz
|
||||||
* \param size Size meant to be written
|
* \param size Size meant to be written
|
||||||
*
|
*
|
||||||
* \remark Produces a NazaraAssert if stream is not writable
|
* \remark Produces a NazaraAssert if stream is not writable
|
||||||
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
|
* \remark If preallocated space of buffer is less than the size, the behavior is undefined
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline std::size_t Stream::Write(const void* buffer, std::size_t size)
|
inline std::size_t Stream::Write(const void* buffer, std::size_t size)
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ namespace Nz
|
||||||
|
|
||||||
char* GetBuffer();
|
char* GetBuffer();
|
||||||
std::size_t GetCapacity() const;
|
std::size_t GetCapacity() const;
|
||||||
|
std::size_t GetCharacterPosition(std::size_t characterIndex) const;
|
||||||
const char* GetConstBuffer() const;
|
const char* GetConstBuffer() const;
|
||||||
std::size_t GetLength() const;
|
std::size_t GetLength() const;
|
||||||
std::size_t GetSize() const;
|
std::size_t GetSize() const;
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
#include <Nazara/Graphics/Billboard.hpp>
|
#include <Nazara/Graphics/Billboard.hpp>
|
||||||
#include <Nazara/Graphics/ColorBackground.hpp>
|
#include <Nazara/Graphics/ColorBackground.hpp>
|
||||||
#include <Nazara/Graphics/Config.hpp>
|
#include <Nazara/Graphics/Config.hpp>
|
||||||
|
#include <Nazara/Graphics/CullingList.hpp>
|
||||||
#include <Nazara/Graphics/DeferredBloomPass.hpp>
|
#include <Nazara/Graphics/DeferredBloomPass.hpp>
|
||||||
#include <Nazara/Graphics/DeferredDOFPass.hpp>
|
#include <Nazara/Graphics/DeferredDOFPass.hpp>
|
||||||
#include <Nazara/Graphics/DeferredFinalPass.hpp>
|
#include <Nazara/Graphics/DeferredFinalPass.hpp>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,180 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_CULLINGLIST_HPP
|
||||||
|
#define NAZARA_CULLINGLIST_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/Signal.hpp>
|
||||||
|
#include <Nazara/Graphics/Config.hpp>
|
||||||
|
#include <Nazara/Graphics/Enums.hpp>
|
||||||
|
#include <Nazara/Math/BoundingVolume.hpp>
|
||||||
|
#include <Nazara/Math/Frustum.hpp>
|
||||||
|
#include <Nazara/Math/Sphere.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
class CullingList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template<CullTest> class Entry;
|
||||||
|
class NoTestEntry;
|
||||||
|
class SphereEntry;
|
||||||
|
class VolumeEntry;
|
||||||
|
|
||||||
|
template<CullTest> friend class Entry;
|
||||||
|
friend NoTestEntry;
|
||||||
|
friend SphereEntry;
|
||||||
|
friend VolumeEntry;
|
||||||
|
|
||||||
|
using ResultContainer = std::vector<const T*>;
|
||||||
|
|
||||||
|
CullingList() = default;
|
||||||
|
CullingList(const CullingList& renderable) = delete;
|
||||||
|
CullingList(CullingList&& renderable) = delete;
|
||||||
|
~CullingList();
|
||||||
|
|
||||||
|
std::size_t Cull(const Frustumf& frustum, bool* forceInvalidation = nullptr);
|
||||||
|
|
||||||
|
NoTestEntry RegisterNoTest(const T* renderable);
|
||||||
|
SphereEntry RegisterSphereTest(const T* renderable);
|
||||||
|
VolumeEntry RegisterVolumeTest(const T* renderable);
|
||||||
|
|
||||||
|
CullingList& operator=(const CullingList& renderable) = delete;
|
||||||
|
CullingList& operator=(CullingList&& renderable) = delete;
|
||||||
|
|
||||||
|
// STL API
|
||||||
|
typename ResultContainer::iterator begin();
|
||||||
|
typename ResultContainer::const_iterator begin() const;
|
||||||
|
|
||||||
|
typename ResultContainer::const_iterator cbegin() const;
|
||||||
|
typename ResultContainer::const_iterator cend() const;
|
||||||
|
typename ResultContainer::const_reverse_iterator crbegin() const;
|
||||||
|
typename ResultContainer::const_reverse_iterator crend() const;
|
||||||
|
|
||||||
|
bool empty() const;
|
||||||
|
|
||||||
|
typename ResultContainer::iterator end();
|
||||||
|
typename ResultContainer::const_iterator end() const;
|
||||||
|
|
||||||
|
typename ResultContainer::reverse_iterator rbegin();
|
||||||
|
typename ResultContainer::const_reverse_iterator rbegin() const;
|
||||||
|
|
||||||
|
typename ResultContainer::reverse_iterator rend();
|
||||||
|
typename ResultContainer::const_reverse_iterator rend() const;
|
||||||
|
|
||||||
|
typename ResultContainer::size_type size() const;
|
||||||
|
|
||||||
|
NazaraSignal(OnCullingListRelease, CullingList* /*cullingList*/);
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline void NotifyForceInvalidation(CullTest type, std::size_t index);
|
||||||
|
inline void NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr);
|
||||||
|
inline void NotifyRelease(CullTest type, std::size_t index);
|
||||||
|
inline void NotifySphereUpdate(std::size_t index, const Spheref& sphere);
|
||||||
|
inline void NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume);
|
||||||
|
|
||||||
|
struct NoTestVisibilityEntry
|
||||||
|
{
|
||||||
|
NoTestEntry* entry;
|
||||||
|
const T* renderable;
|
||||||
|
bool forceInvalidation;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SphereVisibilityEntry
|
||||||
|
{
|
||||||
|
Spheref sphere;
|
||||||
|
SphereEntry* entry;
|
||||||
|
const T* renderable;
|
||||||
|
bool forceInvalidation;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VolumeVisibilityEntry
|
||||||
|
{
|
||||||
|
BoundingVolumef volume;
|
||||||
|
VolumeEntry* entry;
|
||||||
|
const T* renderable;
|
||||||
|
bool forceInvalidation;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<NoTestVisibilityEntry> m_noTestList;
|
||||||
|
std::vector<SphereVisibilityEntry> m_sphereTestList;
|
||||||
|
std::vector<VolumeVisibilityEntry> m_volumeTestList;
|
||||||
|
ResultContainer m_results;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<CullTest Type>
|
||||||
|
class CullingList<T>::Entry
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Entry();
|
||||||
|
Entry(const Entry&) = delete;
|
||||||
|
Entry(Entry&& entry);
|
||||||
|
~Entry();
|
||||||
|
|
||||||
|
void ForceInvalidation();
|
||||||
|
|
||||||
|
CullingList* GetParent() const;
|
||||||
|
|
||||||
|
void UpdateIndex(std::size_t index);
|
||||||
|
|
||||||
|
Entry& operator=(const Entry&) = delete;
|
||||||
|
Entry& operator=(Entry&& entry);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Entry(CullingList* parent, std::size_t index);
|
||||||
|
|
||||||
|
std::size_t m_index;
|
||||||
|
CullingList* m_parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class CullingList<T>::NoTestEntry : public CullingList::template Entry<CullTest::NoTest>
|
||||||
|
{
|
||||||
|
friend CullingList;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NoTestEntry();
|
||||||
|
|
||||||
|
private:
|
||||||
|
NoTestEntry(CullingList* parent, std::size_t index);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class CullingList<T>::SphereEntry : public CullingList::template Entry<CullTest::Sphere>
|
||||||
|
{
|
||||||
|
friend CullingList;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SphereEntry();
|
||||||
|
|
||||||
|
void UpdateSphere(const Spheref& sphere);
|
||||||
|
|
||||||
|
private:
|
||||||
|
SphereEntry(CullingList* parent, std::size_t index);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class CullingList<T>::VolumeEntry : public CullingList::template Entry<CullTest::Volume>
|
||||||
|
{
|
||||||
|
friend CullingList;
|
||||||
|
|
||||||
|
public:
|
||||||
|
VolumeEntry();
|
||||||
|
|
||||||
|
void UpdateVolume(const BoundingVolumef& sphere);
|
||||||
|
|
||||||
|
private:
|
||||||
|
VolumeEntry(CullingList* parent, std::size_t index);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/CullingList.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_CULLINGLIST_HPP
|
||||||
|
|
@ -0,0 +1,431 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/CullingList.hpp>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
CullingList<T>::~CullingList()
|
||||||
|
{
|
||||||
|
OnCullingListRelease(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::size_t CullingList<T>::Cull(const Frustumf& frustum, bool* forceInvalidation)
|
||||||
|
{
|
||||||
|
m_results.clear();
|
||||||
|
|
||||||
|
bool forcedInvalidation = false;
|
||||||
|
|
||||||
|
std::size_t visibleHash = 0U;
|
||||||
|
|
||||||
|
for (NoTestVisibilityEntry& entry : m_noTestList)
|
||||||
|
{
|
||||||
|
m_results.push_back(entry.renderable);
|
||||||
|
Nz::HashCombine(visibleHash, entry.renderable);
|
||||||
|
|
||||||
|
if (entry.forceInvalidation)
|
||||||
|
{
|
||||||
|
forcedInvalidation = true;
|
||||||
|
entry.forceInvalidation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SphereVisibilityEntry& entry : m_sphereTestList)
|
||||||
|
{
|
||||||
|
if (frustum.Contains(entry.sphere))
|
||||||
|
{
|
||||||
|
m_results.push_back(entry.renderable);
|
||||||
|
Nz::HashCombine(visibleHash, entry.renderable);
|
||||||
|
|
||||||
|
if (entry.forceInvalidation)
|
||||||
|
{
|
||||||
|
forcedInvalidation = true;
|
||||||
|
entry.forceInvalidation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (VolumeVisibilityEntry& entry : m_volumeTestList)
|
||||||
|
{
|
||||||
|
if (frustum.Contains(entry.volume))
|
||||||
|
{
|
||||||
|
m_results.push_back(entry.renderable);
|
||||||
|
Nz::HashCombine(visibleHash, entry.renderable);
|
||||||
|
|
||||||
|
if (entry.forceInvalidation)
|
||||||
|
{
|
||||||
|
forcedInvalidation = true;
|
||||||
|
entry.forceInvalidation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forceInvalidation)
|
||||||
|
*forceInvalidation = forcedInvalidation;
|
||||||
|
|
||||||
|
return visibleHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::NoTestEntry CullingList<T>::RegisterNoTest(const T* renderable)
|
||||||
|
{
|
||||||
|
NoTestEntry entry(this, m_noTestList.size());
|
||||||
|
m_noTestList.emplace_back(NoTestVisibilityEntry{&entry, renderable, false}); //< Address of entry will be updated when moving
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::SphereEntry CullingList<T>::RegisterSphereTest(const T* renderable)
|
||||||
|
{
|
||||||
|
SphereEntry entry(this, m_sphereTestList.size());
|
||||||
|
m_sphereTestList.emplace_back(SphereVisibilityEntry{Nz::Spheref(), &entry, renderable, false}); //< Address of entry will be updated when moving
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::VolumeEntry CullingList<T>::RegisterVolumeTest(const T* renderable)
|
||||||
|
{
|
||||||
|
VolumeEntry entry(this, m_volumeTestList.size());
|
||||||
|
m_volumeTestList.emplace_back(VolumeVisibilityEntry{Nz::BoundingVolumef(), &entry, renderable, false}); //< Address of entry will be updated when moving
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interface STD
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::iterator CullingList<T>::begin()
|
||||||
|
{
|
||||||
|
return m_results.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::const_iterator CullingList<T>::begin() const
|
||||||
|
{
|
||||||
|
return m_results.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::const_iterator CullingList<T>::cbegin() const
|
||||||
|
{
|
||||||
|
return m_results.cbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::const_iterator CullingList<T>::cend() const
|
||||||
|
{
|
||||||
|
return m_results.cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::const_reverse_iterator CullingList<T>::crbegin() const
|
||||||
|
{
|
||||||
|
return m_results.crbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::const_reverse_iterator CullingList<T>::crend() const
|
||||||
|
{
|
||||||
|
return m_results.crend();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool CullingList<T>::empty() const
|
||||||
|
{
|
||||||
|
return m_results.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::iterator CullingList<T>::end()
|
||||||
|
{
|
||||||
|
return m_results.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::const_iterator CullingList<T>::end() const
|
||||||
|
{
|
||||||
|
return m_results.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::reverse_iterator CullingList<T>::rbegin()
|
||||||
|
{
|
||||||
|
return m_results.rbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::const_reverse_iterator CullingList<T>::rbegin() const
|
||||||
|
{
|
||||||
|
return m_results.rbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::reverse_iterator CullingList<T>::rend()
|
||||||
|
{
|
||||||
|
return m_results.rend();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::const_reverse_iterator CullingList<T>::rend() const
|
||||||
|
{
|
||||||
|
return m_results.rend();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename CullingList<T>::ResultContainer::size_type CullingList<T>::size() const
|
||||||
|
{
|
||||||
|
return m_results.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CullingList<T>::NotifyForceInvalidation(CullTest type, std::size_t index)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case CullTest::NoTest:
|
||||||
|
{
|
||||||
|
m_noTestList[index].forceInvalidation = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CullTest::Sphere:
|
||||||
|
{
|
||||||
|
m_sphereTestList[index].forceInvalidation = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CullTest::Volume:
|
||||||
|
{
|
||||||
|
m_volumeTestList[index].forceInvalidation = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
NazaraInternalError("Unhandled culltype");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CullingList<T>::NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case CullTest::NoTest:
|
||||||
|
{
|
||||||
|
NoTestVisibilityEntry& entry = m_noTestList[index];
|
||||||
|
NazaraAssert(entry.entry == oldPtr, "Invalid entry");
|
||||||
|
|
||||||
|
entry.entry = static_cast<NoTestEntry*>(newPtr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CullTest::Sphere:
|
||||||
|
{
|
||||||
|
SphereVisibilityEntry& entry = m_sphereTestList[index];
|
||||||
|
NazaraAssert(entry.entry == oldPtr, "Invalid sphere entry");
|
||||||
|
|
||||||
|
entry.entry = static_cast<SphereEntry*>(newPtr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CullTest::Volume:
|
||||||
|
{
|
||||||
|
VolumeVisibilityEntry& entry = m_volumeTestList[index];
|
||||||
|
NazaraAssert(entry.entry == oldPtr, "Invalid volume entry");
|
||||||
|
|
||||||
|
entry.entry = static_cast<VolumeEntry*>(newPtr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
NazaraInternalError("Unhandled culltype");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CullingList<T>::NotifyRelease(CullTest type, std::size_t index)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case CullTest::NoTest:
|
||||||
|
{
|
||||||
|
m_noTestList[index] = std::move(m_noTestList.back());
|
||||||
|
m_noTestList[index].entry->UpdateIndex(index);
|
||||||
|
m_noTestList.pop_back();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CullTest::Sphere:
|
||||||
|
{
|
||||||
|
m_sphereTestList[index] = std::move(m_sphereTestList.back());
|
||||||
|
m_sphereTestList[index].entry->UpdateIndex(index);
|
||||||
|
m_sphereTestList.pop_back();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CullTest::Volume:
|
||||||
|
{
|
||||||
|
m_volumeTestList[index] = std::move(m_volumeTestList.back());
|
||||||
|
m_volumeTestList[index].entry->UpdateIndex(index);
|
||||||
|
m_volumeTestList.pop_back();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
NazaraInternalError("Unhandled culltype");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CullingList<T>::NotifySphereUpdate(std::size_t index, const Spheref& sphere)
|
||||||
|
{
|
||||||
|
m_sphereTestList[index].sphere = sphere;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CullingList<T>::NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume)
|
||||||
|
{
|
||||||
|
m_volumeTestList[index].volume = boundingVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<CullTest Type>
|
||||||
|
CullingList<T>::Entry<Type>::Entry() :
|
||||||
|
m_parent(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<CullTest Type>
|
||||||
|
CullingList<T>::Entry<Type>::Entry(CullingList* parent, std::size_t index) :
|
||||||
|
m_index(index),
|
||||||
|
m_parent(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<CullTest Type>
|
||||||
|
CullingList<T>::Entry<Type>::Entry(Entry&& entry) :
|
||||||
|
m_index(entry.m_index),
|
||||||
|
m_parent(entry.m_parent)
|
||||||
|
{
|
||||||
|
if (m_parent)
|
||||||
|
m_parent->NotifyMovement(Type, m_index, &entry, this);
|
||||||
|
|
||||||
|
entry.m_parent = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<CullTest Type>
|
||||||
|
CullingList<T>::Entry<Type>::~Entry()
|
||||||
|
{
|
||||||
|
if (m_parent)
|
||||||
|
m_parent->NotifyRelease(Type, m_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<CullTest Type>
|
||||||
|
void CullingList<T>::Entry<Type>::ForceInvalidation()
|
||||||
|
{
|
||||||
|
m_parent->NotifyForceInvalidation(Type, m_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<CullTest Type>
|
||||||
|
CullingList<T>* CullingList<T>::Entry<Type>::GetParent() const
|
||||||
|
{
|
||||||
|
return m_parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<CullTest Type>
|
||||||
|
void CullingList<T>::Entry<Type>::UpdateIndex(std::size_t index)
|
||||||
|
{
|
||||||
|
m_index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
template<CullTest Type>
|
||||||
|
#ifdef NAZARA_COMPILER_MSVC
|
||||||
|
// MSVC bug
|
||||||
|
typename CullingList<T>::Entry<Type>& CullingList<T>::Entry<Type>::operator=(Entry&& entry)
|
||||||
|
#else
|
||||||
|
typename CullingList<T>::template Entry<Type>& CullingList<T>::Entry<Type>::operator=(Entry&& entry)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
m_index = entry.m_index;
|
||||||
|
m_parent = entry.m_parent;
|
||||||
|
if (m_parent)
|
||||||
|
m_parent->NotifyMovement(Type, m_index, &entry, this);
|
||||||
|
|
||||||
|
entry.m_parent = nullptr;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
CullingList<T>::NoTestEntry::NoTestEntry() :
|
||||||
|
Entry<CullTest::NoTest>()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
CullingList<T>::NoTestEntry::NoTestEntry(CullingList* parent, std::size_t index) :
|
||||||
|
Entry<CullTest::NoTest>(parent, index)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
CullingList<T>::SphereEntry::SphereEntry() :
|
||||||
|
Entry<CullTest::Sphere>()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
CullingList<T>::SphereEntry::SphereEntry(CullingList* parent, std::size_t index) :
|
||||||
|
Entry<CullTest::Sphere>(parent, index)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CullingList<T>::SphereEntry::UpdateSphere(const Spheref& sphere)
|
||||||
|
{
|
||||||
|
this->m_parent->NotifySphereUpdate(this->m_index, sphere);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
CullingList<T>::VolumeEntry::VolumeEntry() :
|
||||||
|
Entry<CullTest::Volume>()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
CullingList<T>::VolumeEntry::VolumeEntry(CullingList* parent, std::size_t index) :
|
||||||
|
Entry<CullTest::Volume>(parent, index)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void CullingList<T>::VolumeEntry::UpdateVolume(const BoundingVolumef& volume)
|
||||||
|
{
|
||||||
|
this->m_parent->NotifyVolumeUpdate(this->m_index, volume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/DebugOff.hpp>
|
||||||
|
|
@ -19,6 +19,13 @@ namespace Nz
|
||||||
BackgroundType_Max = BackgroundType_User
|
BackgroundType_Max = BackgroundType_User
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class CullTest
|
||||||
|
{
|
||||||
|
NoTest,
|
||||||
|
Sphere,
|
||||||
|
Volume
|
||||||
|
};
|
||||||
|
|
||||||
enum ProjectionType
|
enum ProjectionType
|
||||||
{
|
{
|
||||||
ProjectionType_Orthogonal,
|
ProjectionType_Orthogonal,
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include <Nazara/Core/RefCounted.hpp>
|
#include <Nazara/Core/RefCounted.hpp>
|
||||||
#include <Nazara/Core/Signal.hpp>
|
#include <Nazara/Core/Signal.hpp>
|
||||||
#include <Nazara/Graphics/Config.hpp>
|
#include <Nazara/Graphics/Config.hpp>
|
||||||
|
#include <Nazara/Graphics/CullingList.hpp>
|
||||||
#include <Nazara/Math/BoundingVolume.hpp>
|
#include <Nazara/Math/BoundingVolume.hpp>
|
||||||
#include <Nazara/Math/Frustum.hpp>
|
#include <Nazara/Math/Frustum.hpp>
|
||||||
#include <Nazara/Math/Matrix4.hpp>
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
|
|
@ -31,15 +32,17 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
struct InstanceData;
|
struct InstanceData;
|
||||||
|
|
||||||
InstancedRenderable() = default;
|
inline InstancedRenderable();
|
||||||
inline InstancedRenderable(const InstancedRenderable& renderable);
|
inline InstancedRenderable(const InstancedRenderable& renderable);
|
||||||
InstancedRenderable(InstancedRenderable&& renderable) = delete;
|
InstancedRenderable(InstancedRenderable&& renderable) = delete;
|
||||||
virtual ~InstancedRenderable();
|
virtual ~InstancedRenderable();
|
||||||
|
|
||||||
|
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
|
||||||
|
|
||||||
|
virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const;
|
||||||
|
|
||||||
inline void EnsureBoundingVolumeUpdated() const;
|
inline void EnsureBoundingVolumeUpdated() const;
|
||||||
|
|
||||||
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
|
|
||||||
virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const;
|
|
||||||
virtual const BoundingVolumef& GetBoundingVolume() const;
|
virtual const BoundingVolumef& GetBoundingVolume() const;
|
||||||
virtual void InvalidateData(InstanceData* instanceData, UInt32 flags) const;
|
virtual void InvalidateData(InstanceData* instanceData, UInt32 flags) const;
|
||||||
virtual void UpdateBoundingVolume(InstanceData* instanceData) const;
|
virtual void UpdateBoundingVolume(InstanceData* instanceData) const;
|
||||||
|
|
@ -49,6 +52,7 @@ namespace Nz
|
||||||
InstancedRenderable& operator=(InstancedRenderable&& renderable) = delete;
|
InstancedRenderable& operator=(InstancedRenderable&& renderable) = delete;
|
||||||
|
|
||||||
// Signals:
|
// Signals:
|
||||||
|
NazaraSignal(OnInstancedRenderableInvalidateBoundingVolume, const InstancedRenderable* /*instancedRenderable*/);
|
||||||
NazaraSignal(OnInstancedRenderableInvalidateData, const InstancedRenderable* /*instancedRenderable*/, UInt32 /*flags*/);
|
NazaraSignal(OnInstancedRenderableInvalidateData, const InstancedRenderable* /*instancedRenderable*/, UInt32 /*flags*/);
|
||||||
NazaraSignal(OnInstancedRenderableRelease, const InstancedRenderable* /*instancedRenderable*/);
|
NazaraSignal(OnInstancedRenderableRelease, const InstancedRenderable* /*instancedRenderable*/);
|
||||||
|
|
||||||
|
|
@ -83,14 +87,16 @@ namespace Nz
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void MakeBoundingVolume() const = 0;
|
inline void InvalidateBoundingVolume();
|
||||||
void InvalidateBoundingVolume();
|
|
||||||
inline void InvalidateInstanceData(UInt32 flags);
|
inline void InvalidateInstanceData(UInt32 flags);
|
||||||
inline void UpdateBoundingVolume() const;
|
|
||||||
|
virtual void MakeBoundingVolume() const = 0;
|
||||||
|
|
||||||
mutable BoundingVolumef m_boundingVolume;
|
mutable BoundingVolumef m_boundingVolume;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline void UpdateBoundingVolume() const;
|
||||||
|
|
||||||
mutable bool m_boundingVolumeUpdated;
|
mutable bool m_boundingVolumeUpdated;
|
||||||
|
|
||||||
static InstancedRenderableLibrary::LibraryMap s_library;
|
static InstancedRenderableLibrary::LibraryMap s_library;
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,19 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
/*!
|
||||||
|
* \brief Constructs a InstancedRenderable object by default
|
||||||
|
*/
|
||||||
|
inline InstancedRenderable::InstancedRenderable() :
|
||||||
|
m_boundingVolumeUpdated(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Constructs a InstancedRenderable object by assignation
|
* \brief Constructs a InstancedRenderable object by assignation
|
||||||
*
|
*
|
||||||
* \param renderable InstancedRenderable to copy into this
|
* \param renderable InstancedRenderable to copy into this
|
||||||
*/
|
*/
|
||||||
|
|
||||||
inline InstancedRenderable::InstancedRenderable(const InstancedRenderable& renderable) :
|
inline InstancedRenderable::InstancedRenderable(const InstancedRenderable& renderable) :
|
||||||
RefCounted(),
|
RefCounted(),
|
||||||
m_boundingVolume(renderable.m_boundingVolume),
|
m_boundingVolume(renderable.m_boundingVolume),
|
||||||
|
|
@ -34,6 +41,8 @@ namespace Nz
|
||||||
inline void InstancedRenderable::InvalidateBoundingVolume()
|
inline void InstancedRenderable::InvalidateBoundingVolume()
|
||||||
{
|
{
|
||||||
m_boundingVolumeUpdated = false;
|
m_boundingVolumeUpdated = false;
|
||||||
|
|
||||||
|
OnInstancedRenderableInvalidateBoundingVolume(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -69,6 +78,7 @@ namespace Nz
|
||||||
inline void InstancedRenderable::UpdateBoundingVolume() const
|
inline void InstancedRenderable::UpdateBoundingVolume() const
|
||||||
{
|
{
|
||||||
MakeBoundingVolume();
|
MakeBoundingVolume();
|
||||||
|
|
||||||
m_boundingVolumeUpdated = true;
|
m_boundingVolumeUpdated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ namespace Nz
|
||||||
void* GenerateParticle();
|
void* GenerateParticle();
|
||||||
void* GenerateParticles(unsigned int count);
|
void* GenerateParticles(unsigned int count);
|
||||||
|
|
||||||
|
inline void* GetBuffer();
|
||||||
|
inline const void* GetBuffer() const;
|
||||||
const ParticleDeclarationConstRef& GetDeclaration() const;
|
const ParticleDeclarationConstRef& GetDeclaration() const;
|
||||||
std::size_t GetMaxParticleCount() const;
|
std::size_t GetMaxParticleCount() const;
|
||||||
std::size_t GetParticleCount() const;
|
std::size_t GetParticleCount() const;
|
||||||
|
|
@ -94,4 +96,6 @@ namespace Nz
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/ParticleGroup.inl>
|
||||||
|
|
||||||
#endif // NAZARA_PARTICLEGROUP_HPP
|
#endif // NAZARA_PARTICLEGROUP_HPP
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
// Copyright (C) 2016 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/ParticleGroup.hpp>
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
/*!
|
||||||
|
* \brief Gets a raw pointer to the particle buffer
|
||||||
|
*
|
||||||
|
* This can be useful when working directly with a struct, or needing to iterate over all particles.
|
||||||
|
*
|
||||||
|
* \return Pointer to the buffer
|
||||||
|
*
|
||||||
|
* \see GetParticleCount
|
||||||
|
*/
|
||||||
|
inline void* ParticleGroup::GetBuffer()
|
||||||
|
{
|
||||||
|
return m_buffer.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets a raw pointer to the particle buffer
|
||||||
|
*
|
||||||
|
* This can be useful when working directly with a struct, or needing to iterate over all particles.
|
||||||
|
*
|
||||||
|
* \return Pointer to the buffer
|
||||||
|
*
|
||||||
|
* \see GetParticleCount
|
||||||
|
*/
|
||||||
|
inline const void* ParticleGroup::GetBuffer() const
|
||||||
|
{
|
||||||
|
return m_buffer.data();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/DebugOff.hpp>
|
||||||
|
|
@ -22,6 +22,7 @@ namespace Nz
|
||||||
|
|
||||||
template<typename T> SparsePtr<T> GetComponentPtr(ParticleComponent component);
|
template<typename T> SparsePtr<T> GetComponentPtr(ParticleComponent component);
|
||||||
template<typename T> SparsePtr<const T> GetComponentPtr(ParticleComponent component) const;
|
template<typename T> SparsePtr<const T> GetComponentPtr(ParticleComponent component) const;
|
||||||
|
inline void* GetPointer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const ParticleDeclaration* m_declaration;
|
const ParticleDeclaration* m_declaration;
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,18 @@ namespace Nz
|
||||||
return SparsePtr<const T>();
|
return SparsePtr<const T>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Gets a raw pointer to the particle buffer
|
||||||
|
*
|
||||||
|
* This can be useful when working directly with a struct
|
||||||
|
*
|
||||||
|
* \return Pointer to the buffer
|
||||||
|
*/
|
||||||
|
inline void* ParticleMapper::GetPointer()
|
||||||
|
{
|
||||||
|
return m_ptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Graphics/DebugOff.hpp>
|
#include <Nazara/Graphics/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -21,16 +21,16 @@ namespace Nz
|
||||||
Vector3f normal;
|
Vector3f normal;
|
||||||
Vector3f position;
|
Vector3f position;
|
||||||
Vector3f velocity;
|
Vector3f velocity;
|
||||||
UInt32 life;
|
float life;
|
||||||
float rotation;
|
float rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ParticleStruct_Model
|
struct ParticleStruct_Model
|
||||||
{
|
{
|
||||||
|
Quaternionf rotation;
|
||||||
Vector3f position;
|
Vector3f position;
|
||||||
Vector3f velocity;
|
Vector3f velocity;
|
||||||
UInt32 life;
|
float life;
|
||||||
Quaternionf rotation;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ParticleStruct_Sprite
|
struct ParticleStruct_Sprite
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Nz
|
||||||
Color color;
|
Color color;
|
||||||
Vector3f position;
|
Vector3f position;
|
||||||
Vector3f velocity;
|
Vector3f velocity;
|
||||||
UInt32 life;
|
float life;
|
||||||
float rotation;
|
float rotation;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ namespace Nz
|
||||||
virtual ~Renderable();
|
virtual ~Renderable();
|
||||||
|
|
||||||
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const = 0;
|
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const = 0;
|
||||||
|
|
||||||
virtual bool Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const;
|
virtual bool Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const;
|
||||||
|
|
||||||
inline void EnsureBoundingVolumeUpdated() const;
|
inline void EnsureBoundingVolumeUpdated() const;
|
||||||
virtual const BoundingVolumef& GetBoundingVolume() const;
|
virtual const BoundingVolumef& GetBoundingVolume() const;
|
||||||
virtual void UpdateBoundingVolume(const Matrix4f& transformMatrix);
|
virtual void UpdateBoundingVolume(const Matrix4f& transformMatrix);
|
||||||
|
|
@ -36,11 +38,12 @@ namespace Nz
|
||||||
protected:
|
protected:
|
||||||
virtual void MakeBoundingVolume() const = 0;
|
virtual void MakeBoundingVolume() const = 0;
|
||||||
inline void InvalidateBoundingVolume();
|
inline void InvalidateBoundingVolume();
|
||||||
inline void UpdateBoundingVolume() const;
|
|
||||||
|
|
||||||
mutable BoundingVolumef m_boundingVolume;
|
mutable BoundingVolumef m_boundingVolume;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline void UpdateBoundingVolume() const;
|
||||||
|
|
||||||
mutable bool m_boundingVolumeUpdated;
|
mutable bool m_boundingVolumeUpdated;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
m_scale = scale;
|
m_scale = scale;
|
||||||
|
|
||||||
|
InvalidateBoundingVolume();
|
||||||
InvalidateVertices();
|
InvalidateVertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <Nazara/Lua/LuaInstance.hpp>
|
#include <Nazara/Lua/LuaInstance.hpp>
|
||||||
#include <Nazara/Core/Algorithm.hpp>
|
#include <Nazara/Core/Algorithm.hpp>
|
||||||
|
#include <Nazara/Core/Flags.hpp>
|
||||||
#include <Nazara/Core/MemoryHelper.hpp>
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
#include <Nazara/Core/StringStream.hpp>
|
#include <Nazara/Core/StringStream.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
@ -99,19 +100,50 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
std::enable_if_t<std::is_enum<T>::value && !EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
||||||
{
|
{
|
||||||
using UnderlyingT = std::underlying_type_t<T>;
|
using UnderlyingT = std::underlying_type_t<T>;
|
||||||
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), TypeTag<UnderlyingT>());
|
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), TypeTag<UnderlyingT>());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
|
std::enable_if_t<std::is_enum<T>::value && !EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
|
||||||
{
|
{
|
||||||
using UnderlyingT = std::underlying_type_t<T>;
|
using UnderlyingT = std::underlying_type_t<T>;
|
||||||
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
|
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::enable_if_t<std::is_enum<T>::value && EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
||||||
|
{
|
||||||
|
using UnderlyingT = std::underlying_type_t<T>;
|
||||||
|
|
||||||
|
UnderlyingT pot2Val;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, TypeTag<UnderlyingT>());
|
||||||
|
|
||||||
|
*arg = static_cast<T>(IntegralLog2Pot(pot2Val));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::enable_if_t<std::is_enum<T>::value && EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
|
||||||
|
{
|
||||||
|
using UnderlyingT = std::underlying_type_t<T>;
|
||||||
|
|
||||||
|
UnderlyingT pot2Val;
|
||||||
|
unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, 1U << static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
|
||||||
|
|
||||||
|
*arg = static_cast<T>(IntegralLog2Pot(pot2Val));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Flags<E>* arg, TypeTag<Flags<E>>)
|
||||||
|
{
|
||||||
|
*arg = Flags<E>(instance.CheckBoundInteger<UInt32>(index));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
|
||||||
{
|
{
|
||||||
|
|
@ -184,12 +216,26 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_enum<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
std::enable_if_t<std::is_enum<T>::value && !EnableFlagsOperators<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
||||||
{
|
{
|
||||||
using EnumT = typename std::underlying_type<T>::type;
|
using EnumT = typename std::underlying_type<T>::type;
|
||||||
return LuaImplReplyVal(instance, static_cast<EnumT>(val), TypeTag<EnumT>());
|
return LuaImplReplyVal(instance, static_cast<EnumT>(val), TypeTag<EnumT>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::enable_if_t<std::is_enum<T>::value && EnableFlagsOperators<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
||||||
|
{
|
||||||
|
Flags<T> flags(val);
|
||||||
|
return LuaImplReplyVal(instance, flags, TypeTag<decltype(flags)>());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename E>
|
||||||
|
int LuaImplReplyVal(const LuaInstance& instance, Flags<E> val, TypeTag<Flags<E>>)
|
||||||
|
{
|
||||||
|
instance.PushInteger(UInt32(val));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::enable_if_t<std::is_integral<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
std::enable_if_t<std::is_integral<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2015 Jérôme Leclercq
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ namespace Nz
|
||||||
void OnEmptyStream() override;
|
void OnEmptyStream() override;
|
||||||
|
|
||||||
void FreeStream();
|
void FreeStream();
|
||||||
void InitStream(std::size_t minCapacity, UInt64 cursorPos, UInt32 openMode);
|
void InitStream(std::size_t minCapacity, UInt64 cursorPos, OpenModeFlags openMode);
|
||||||
|
|
||||||
static bool Initialize();
|
static bool Initialize();
|
||||||
static void Uninitialize();
|
static void Uninitialize();
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,14 @@
|
||||||
// Try to identify the compiler
|
// Try to identify the compiler
|
||||||
#if defined(__BORLANDC__)
|
#if defined(__BORLANDC__)
|
||||||
#define NAZARA_COMPILER_BORDLAND
|
#define NAZARA_COMPILER_BORDLAND
|
||||||
#define NAZARA_COMPILER_SUPPORTS_CPP11 (defined(__cplusplus) && __cplusplus >= 201103L)
|
|
||||||
#define NAZARA_DEPRECATED(txt)
|
#define NAZARA_DEPRECATED(txt)
|
||||||
#define NAZARA_FUNCTION __FUNC__
|
#define NAZARA_FUNCTION __FUNC__
|
||||||
#elif defined(__clang__)
|
#elif defined(__clang__)
|
||||||
#define NAZARA_COMPILER_CLANG
|
#define NAZARA_COMPILER_CLANG
|
||||||
#define NAZARA_COMPILER_SUPPORTS_CPP11 (defined(__cplusplus) && __cplusplus >= 201103L)
|
|
||||||
#define NAZARA_DEPRECATED(txt) __attribute__((__deprecated__(txt)))
|
#define NAZARA_DEPRECATED(txt) __attribute__((__deprecated__(txt)))
|
||||||
#define NAZARA_FUNCTION __PRETTY_FUNCTION__
|
#define NAZARA_FUNCTION __PRETTY_FUNCTION__
|
||||||
#elif defined(__GNUC__) || defined(__MINGW32__)
|
#elif defined(__GNUC__) || defined(__MINGW32__)
|
||||||
#define NAZARA_COMPILER_GCC
|
#define NAZARA_COMPILER_GCC
|
||||||
#define NAZARA_COMPILER_SUPPORTS_CPP11 (defined(__cplusplus) && __cplusplus >= 201103L)
|
|
||||||
#define NAZARA_DEPRECATED(txt) __attribute__((__deprecated__(txt)))
|
#define NAZARA_DEPRECATED(txt) __attribute__((__deprecated__(txt)))
|
||||||
#define NAZARA_FUNCTION __PRETTY_FUNCTION__
|
#define NAZARA_FUNCTION __PRETTY_FUNCTION__
|
||||||
|
|
||||||
|
|
@ -50,26 +47,31 @@
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__INTEL_COMPILER) || defined(__ICL)
|
#elif defined(__INTEL_COMPILER) || defined(__ICL)
|
||||||
#define NAZARA_COMPILER_INTEL
|
#define NAZARA_COMPILER_INTEL
|
||||||
#define NAZARA_COMPILER_SUPPORTS_CPP11 (defined(__cplusplus) && __cplusplus >= 201103L)
|
|
||||||
#define NAZARA_DEPRECATED(txt)
|
#define NAZARA_DEPRECATED(txt)
|
||||||
#define NAZARA_FUNCTION __FUNCTION__
|
#define NAZARA_FUNCTION __FUNCTION__
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
#define NAZARA_COMPILER_MSVC
|
#define NAZARA_COMPILER_MSVC
|
||||||
#define NAZARA_COMPILER_SUPPORTS_CPP11 (_MSC_VER >= 1900)
|
|
||||||
#define NAZARA_DEPRECATED(txt) __declspec(deprecated(txt))
|
#define NAZARA_DEPRECATED(txt) __declspec(deprecated(txt))
|
||||||
#define NAZARA_FUNCTION __FUNCSIG__
|
#define NAZARA_FUNCTION __FUNCSIG__
|
||||||
|
|
||||||
|
#if _MSC_VER >= 1900
|
||||||
|
#define NAZARA_COMPILER_SUPPORTS_CPP11
|
||||||
|
#endif
|
||||||
|
|
||||||
#pragma warning(disable: 4251)
|
#pragma warning(disable: 4251)
|
||||||
#else
|
#else
|
||||||
#define NAZARA_COMPILER_UNKNOWN
|
#define NAZARA_COMPILER_UNKNOWN
|
||||||
#define NAZARA_COMPILER_SUPPORTS_CPP11 (defined(__cplusplus) && __cplusplus >= 201103L)
|
|
||||||
#define NAZARA_DEPRECATED(txt)
|
#define NAZARA_DEPRECATED(txt)
|
||||||
#define NAZARA_FUNCTION __func__ // __func__ has been standardized in C++ 2011
|
#define NAZARA_FUNCTION __func__ // __func__ has been standardized in C++ 2011
|
||||||
|
|
||||||
#pragma message This compiler is not fully supported
|
#pragma message This compiler is not fully supported
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !NAZARA_COMPILER_SUPPORTS_CPP11
|
#if !defined(NAZARA_COMPILER_SUPPORTS_CPP11) && defined(__cplusplus) && __cplusplus >= 201103L
|
||||||
|
#define NAZARA_COMPILER_SUPPORTS_CPP11
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NAZARA_COMPILER_SUPPORTS_CPP11
|
||||||
#error Nazara requires a C++11 compliant compiler
|
#error Nazara requires a C++11 compliant compiler
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,14 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline RenderWindow();
|
inline RenderWindow();
|
||||||
inline RenderWindow(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
|
inline RenderWindow(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
|
||||||
inline RenderWindow(WindowHandle handle, const RenderWindowParameters& parameters = RenderWindowParameters());
|
inline RenderWindow(WindowHandle handle, const RenderWindowParameters& parameters = RenderWindowParameters());
|
||||||
|
|
||||||
RenderWindow(const RenderWindow&) = delete;
|
RenderWindow(const RenderWindow&) = delete;
|
||||||
RenderWindow(RenderWindow&&) = delete; ///TODO
|
RenderWindow(RenderWindow&&) = delete; ///TODO
|
||||||
virtual ~RenderWindow();
|
virtual ~RenderWindow();
|
||||||
|
|
||||||
inline bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
|
inline bool Create(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
|
||||||
inline bool Create(WindowHandle handle, const RenderWindowParameters& parameters = RenderWindowParameters());
|
inline bool Create(WindowHandle handle, const RenderWindowParameters& parameters = RenderWindowParameters());
|
||||||
|
|
||||||
void Display();
|
void Display();
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
inline RenderWindow::RenderWindow(VideoMode mode, const String& title, UInt32 style, const RenderWindowParameters& parameters) :
|
inline RenderWindow::RenderWindow(VideoMode mode, const String& title, WindowStyleFlags style, const RenderWindowParameters& parameters) :
|
||||||
RenderWindow()
|
RenderWindow()
|
||||||
{
|
{
|
||||||
ErrorFlags errFlags(ErrorFlag_ThrowException, true);
|
ErrorFlags errFlags(ErrorFlag_ThrowException, true);
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Nz
|
||||||
Create(handle, parameters);
|
Create(handle, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool RenderWindow::Create(VideoMode mode, const String& title, UInt32 style, const RenderWindowParameters& parameters)
|
inline bool RenderWindow::Create(VideoMode mode, const String& title, WindowStyleFlags style, const RenderWindowParameters& parameters)
|
||||||
{
|
{
|
||||||
m_parameters = parameters;
|
m_parameters = parameters;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,139 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Renderer module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_TEXTURE_HPP
|
||||||
|
#define NAZARA_TEXTURE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||||
|
#include <Nazara/Core/ObjectRef.hpp>
|
||||||
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceManager.hpp>
|
||||||
|
#include <Nazara/Core/Signal.hpp>
|
||||||
|
#include <Nazara/Renderer/Config.hpp>
|
||||||
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
|
#include <Nazara/Utility/AbstractImage.hpp>
|
||||||
|
#include <Nazara/Utility/CubemapParams.hpp>
|
||||||
|
#include <Nazara/Utility/Image.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
class Texture;
|
||||||
|
|
||||||
|
using TextureConstRef = ObjectRef<const Texture>;
|
||||||
|
using TextureLibrary = ObjectLibrary<Texture>;
|
||||||
|
using TextureManager = ResourceManager<Texture, ImageParams>;
|
||||||
|
using TextureRef = ObjectRef<Texture>;
|
||||||
|
|
||||||
|
struct TextureImpl;
|
||||||
|
|
||||||
|
class NAZARA_RENDERER_API Texture : public AbstractImage, public Resource
|
||||||
|
{
|
||||||
|
friend TextureLibrary;
|
||||||
|
friend TextureManager;
|
||||||
|
friend class Renderer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Texture() = default;
|
||||||
|
Texture(ImageType type, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth = 1, UInt8 levelCount = 1);
|
||||||
|
explicit Texture(const Image& image);
|
||||||
|
Texture(const Texture&) = delete;
|
||||||
|
Texture(Texture&&) = delete;
|
||||||
|
~Texture();
|
||||||
|
|
||||||
|
bool Create(ImageType type, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth = 1, UInt8 levelCount = 1);
|
||||||
|
void Destroy();
|
||||||
|
|
||||||
|
bool Download(Image* image) const;
|
||||||
|
|
||||||
|
bool EnableMipmapping(bool enable);
|
||||||
|
|
||||||
|
void EnsureMipmapsUpdate() const;
|
||||||
|
|
||||||
|
unsigned int GetDepth(UInt8 level = 0) const override;
|
||||||
|
PixelFormatType GetFormat() const override;
|
||||||
|
unsigned int GetHeight(UInt8 level = 0) const override;
|
||||||
|
UInt8 GetLevelCount() const override;
|
||||||
|
UInt8 GetMaxLevel() const override;
|
||||||
|
std::size_t GetMemoryUsage() const override;
|
||||||
|
std::size_t GetMemoryUsage(UInt8 level) const override;
|
||||||
|
Vector3ui GetSize(UInt8 level = 0) const override;
|
||||||
|
ImageType GetType() const override;
|
||||||
|
unsigned int GetWidth(UInt8 level = 0) const override;
|
||||||
|
|
||||||
|
bool HasMipmaps() const;
|
||||||
|
|
||||||
|
void InvalidateMipmaps();
|
||||||
|
bool IsValid() const;
|
||||||
|
|
||||||
|
// Load
|
||||||
|
bool LoadFromFile(const String& filePath, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||||
|
bool LoadFromImage(const Image& image, bool generateMipmaps = true);
|
||||||
|
bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||||
|
bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||||
|
|
||||||
|
// LoadArray
|
||||||
|
bool LoadArrayFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
bool LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||||
|
|
||||||
|
// LoadCubemap
|
||||||
|
bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||||
|
bool LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams());
|
||||||
|
bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||||
|
bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||||
|
|
||||||
|
// LoadFace
|
||||||
|
bool LoadFaceFromFile(CubemapFace face, const String& filePath, const ImageParams& params = ImageParams());
|
||||||
|
bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||||
|
bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams());
|
||||||
|
|
||||||
|
// Save
|
||||||
|
bool SaveToFile(const String& filePath, const ImageParams& params = ImageParams());
|
||||||
|
bool SaveToStream(Stream& stream, const String& format, const ImageParams& params = ImageParams());
|
||||||
|
|
||||||
|
bool SetMipmapRange(UInt8 minLevel, UInt8 maxLevel);
|
||||||
|
|
||||||
|
bool Update(const Image& image, UInt8 level = 0);
|
||||||
|
bool Update(const Image& image, const Boxui& box, UInt8 level = 0);
|
||||||
|
bool Update(const Image& image, const Rectui& rect, unsigned int z = 0, UInt8 level = 0);
|
||||||
|
bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||||
|
bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||||
|
bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||||
|
|
||||||
|
// Fonctions OpenGL
|
||||||
|
unsigned int GetOpenGLID() const;
|
||||||
|
|
||||||
|
Texture& operator=(const Texture&) = delete;
|
||||||
|
Texture& operator=(Texture&&) = delete;
|
||||||
|
|
||||||
|
static bool IsFormatSupported(PixelFormatType format);
|
||||||
|
static bool IsMipmappingSupported();
|
||||||
|
static bool IsTypeSupported(ImageType type);
|
||||||
|
template<typename... Args> static TextureRef New(Args&&... args);
|
||||||
|
|
||||||
|
// Signals:
|
||||||
|
NazaraSignal(OnTextureDestroy, const Texture* /*texture*/);
|
||||||
|
NazaraSignal(OnTextureRelease, const Texture* /*texture*/);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool CreateTexture(bool proxy);
|
||||||
|
|
||||||
|
static bool Initialize();
|
||||||
|
static void Uninitialize();
|
||||||
|
|
||||||
|
TextureImpl* m_impl = nullptr;
|
||||||
|
|
||||||
|
static TextureLibrary::LibraryMap s_library;
|
||||||
|
static TextureManager::ManagerMap s_managerMap;
|
||||||
|
static TextureManager::ManagerParams s_managerParameters;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Renderer/Texture.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_TEXTURE_HPP
|
||||||
|
|
@ -22,6 +22,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Glyph;
|
struct Glyph;
|
||||||
|
struct Line;
|
||||||
|
|
||||||
AbstractTextDrawer() = default;
|
AbstractTextDrawer() = default;
|
||||||
virtual ~AbstractTextDrawer();
|
virtual ~AbstractTextDrawer();
|
||||||
|
|
@ -31,15 +32,24 @@ namespace Nz
|
||||||
virtual std::size_t GetFontCount() const = 0;
|
virtual std::size_t GetFontCount() const = 0;
|
||||||
virtual const Glyph& GetGlyph(std::size_t index) const = 0;
|
virtual const Glyph& GetGlyph(std::size_t index) const = 0;
|
||||||
virtual std::size_t GetGlyphCount() const = 0;
|
virtual std::size_t GetGlyphCount() const = 0;
|
||||||
|
virtual const Line& GetLine(std::size_t index) const = 0;
|
||||||
|
virtual std::size_t GetLineCount() const = 0;
|
||||||
|
|
||||||
struct Glyph
|
struct Glyph
|
||||||
{
|
{
|
||||||
Color color;
|
Color color;
|
||||||
|
Rectf bounds;
|
||||||
Rectui atlasRect;
|
Rectui atlasRect;
|
||||||
Vector2f corners[4];
|
Vector2f corners[4];
|
||||||
AbstractImage* atlas;
|
AbstractImage* atlas;
|
||||||
bool flipped;
|
bool flipped;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Line
|
||||||
|
{
|
||||||
|
Rectf bounds;
|
||||||
|
std::size_t glyphIndex;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#ifndef NAZARA_ENUMS_UTILITY_HPP
|
#ifndef NAZARA_ENUMS_UTILITY_HPP
|
||||||
#define NAZARA_ENUMS_UTILITY_HPP
|
#define NAZARA_ENUMS_UTILITY_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/Flags.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
enum AnimationType
|
enum AnimationType
|
||||||
|
|
@ -430,20 +432,29 @@ namespace Nz
|
||||||
WindowEventType_Max = WindowEventType_TextEntered
|
WindowEventType_Max = WindowEventType_TextEntered
|
||||||
};
|
};
|
||||||
|
|
||||||
enum WindowStyleFlags
|
enum WindowStyle
|
||||||
{
|
{
|
||||||
WindowStyle_None = 0x0, ///< Window has no border nor titlebar.
|
WindowStyle_None, ///< Window has no border nor titlebar.
|
||||||
WindowStyle_Fullscreen = 0x1, ///< At the window creation, the OS tries to set it in fullscreen.
|
WindowStyle_Fullscreen, ///< At the window creation, the OS tries to set it in fullscreen.
|
||||||
|
|
||||||
WindowStyle_Closable = 0x2, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
|
WindowStyle_Closable, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
|
||||||
WindowStyle_Resizable = 0x4, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
|
WindowStyle_Resizable, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
|
||||||
WindowStyle_Titlebar = 0x8, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
|
WindowStyle_Titlebar, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
|
||||||
|
|
||||||
WindowStyle_Threaded = 0x10, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
|
WindowStyle_Threaded, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
|
||||||
|
|
||||||
WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar,
|
WindowStyle_Max = WindowStyle_Threaded
|
||||||
WindowStyle_Max = WindowStyle_Threaded*2-1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct EnableFlagsOperators<WindowStyle>
|
||||||
|
{
|
||||||
|
static constexpr bool value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
using WindowStyleFlags = Flags<WindowStyle>;
|
||||||
|
|
||||||
|
constexpr WindowStyleFlags WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NAZARA_ENUMS_UTILITY_HPP
|
#endif // NAZARA_ENUMS_UTILITY_HPP
|
||||||
|
|
|
||||||
|
|
@ -28,25 +28,15 @@ namespace Nz
|
||||||
{
|
{
|
||||||
struct NAZARA_UTILITY_API MeshParams : ResourceParameters
|
struct NAZARA_UTILITY_API MeshParams : ResourceParameters
|
||||||
{
|
{
|
||||||
MeshParams(); // Vérifie que le storage par défaut est supporté (software autrement)
|
MeshParams();
|
||||||
|
|
||||||
// La transformation appliquée à tous les sommets du mesh
|
Matrix4f matrix = Matrix4f::Identity(); ///< A matrix which will transform every vertex position
|
||||||
Matrix4f matrix = Matrix4f::Identity();
|
UInt32 storage = DataStorage_Hardware; ///< The place where the buffers will be allocated
|
||||||
|
Vector2f texCoordOffset = {0.f, 0.f}; ///< Offset to apply on the texture coordinates (not scaled)
|
||||||
// Si ceci sera le stockage utilisé par les buffers
|
Vector2f texCoordScale = {1.f, 1.f}; ///< Scale to apply on the texture coordinates
|
||||||
UInt32 storage = DataStorage_Hardware;
|
bool animated = true; ///< If true, will load an animated version of the model if possible
|
||||||
|
bool center = false; ///< If true, will center the mesh vertices around the origin
|
||||||
// Charger une version animée du mesh si possible ?
|
bool optimizeIndexBuffers = true; ///< Optimize the index buffers after loading, improve cache locality (and thus rendering speed) but increase loading time.
|
||||||
bool animated = true;
|
|
||||||
|
|
||||||
// Faut-il centrer le mesh autour de l'origine ?
|
|
||||||
bool center = false;
|
|
||||||
|
|
||||||
// Faut-il retourner les UV ?
|
|
||||||
bool flipUVs = false;
|
|
||||||
|
|
||||||
// Faut-il optimiser les index buffers ? (Rendu plus rapide, mais le chargement dure plus longtemps)
|
|
||||||
bool optimizeIndexBuffers = true;
|
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ namespace Nz
|
||||||
std::size_t GetFontCount() const override;
|
std::size_t GetFontCount() const override;
|
||||||
const Glyph& GetGlyph(std::size_t index) const override;
|
const Glyph& GetGlyph(std::size_t index) const override;
|
||||||
std::size_t GetGlyphCount() const override;
|
std::size_t GetGlyphCount() const override;
|
||||||
|
const Line& GetLine(std::size_t index) const override;
|
||||||
|
std::size_t GetLineCount() const override;
|
||||||
UInt32 GetStyle() const;
|
UInt32 GetStyle() const;
|
||||||
const String& GetText() const;
|
const String& GetText() const;
|
||||||
|
|
||||||
|
|
@ -68,6 +70,7 @@ namespace Nz
|
||||||
NazaraSlot(Font, OnFontRelease, m_fontReleaseSlot);
|
NazaraSlot(Font, OnFontRelease, m_fontReleaseSlot);
|
||||||
|
|
||||||
mutable std::vector<Glyph> m_glyphs;
|
mutable std::vector<Glyph> m_glyphs;
|
||||||
|
mutable std::vector<Line> m_lines;
|
||||||
Color m_color;
|
Color m_color;
|
||||||
FontRef m_font;
|
FontRef m_font;
|
||||||
mutable Rectf m_workingBounds;
|
mutable Rectf m_workingBounds;
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Nz
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Window();
|
inline Window();
|
||||||
inline Window(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
|
||||||
inline Window(WindowHandle handle);
|
inline Window(WindowHandle handle);
|
||||||
Window(const Window&) = delete;
|
Window(const Window&) = delete;
|
||||||
inline Window(Window&& window) noexcept;
|
inline Window(Window&& window) noexcept;
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Nz
|
||||||
|
|
||||||
inline void Close();
|
inline void Close();
|
||||||
|
|
||||||
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
|
bool Create(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
|
||||||
bool Create(WindowHandle handle);
|
bool Create(WindowHandle handle);
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
@ -62,7 +62,7 @@ namespace Nz
|
||||||
unsigned int GetHeight() const;
|
unsigned int GetHeight() const;
|
||||||
Vector2i GetPosition() const;
|
Vector2i GetPosition() const;
|
||||||
Vector2ui GetSize() const;
|
Vector2ui GetSize() const;
|
||||||
UInt32 GetStyle() const;
|
WindowStyleFlags GetStyle() const;
|
||||||
String GetTitle() const;
|
String GetTitle() const;
|
||||||
unsigned int GetWidth() const;
|
unsigned int GetWidth() const;
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue