Merge branch 'master' into vulkan

This commit is contained in:
Lynix 2017-07-04 22:41:29 +02:00
commit 9944a228b5
839 changed files with 12369 additions and 5421 deletions

5
.gitignore vendored
View File

@ -15,12 +15,14 @@ examples/bin/*.exe
examples/bin/*.pdb
examples/bin/*.dll
examples/bin/*.so
examples/bin/Demo*
# Unit tests
tests/*.exe
tests/*.pdb
tests/*.dll
tests/*.so
tests/NazaraUnitTests*
# Example generated files
examples/bin/HardwareInfo.txt
@ -49,6 +51,7 @@ build/**/*.project
# GMake
build/**/*.make
build/**/*.d
# Visual Studio
build/**/*.pdb
@ -60,7 +63,7 @@ build/**/*.vcxprojResolveAssemblyReference.cache
build/**/*.nativecodeanalysis.all.xml
build/**/*.nativecodeanalysis.xml
build/**/*.VC.opendb
build/**/*.VC.db
build/**/*.VC.db*
# Compiled Object files
build/**/*.slo

View File

@ -38,7 +38,7 @@ PROJECT_NAME = "Nazara Engine"
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = 0.2
PROJECT_NUMBER = 0.3
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -23,20 +23,22 @@ namespace Ndk
using Factory = std::function<BaseComponent*()>;
BaseComponent(ComponentIndex componentIndex);
BaseComponent(const BaseComponent&) = default;
BaseComponent(BaseComponent&&) = default;
virtual ~BaseComponent();
virtual std::unique_ptr<BaseComponent> Clone() const = 0;
inline const EntityHandle& GetEntity() const;
ComponentIndex GetIndex() const;
inline static ComponentIndex GetMaxComponentIndex();
BaseComponent& operator=(const BaseComponent&) = default;
BaseComponent& operator=(const BaseComponent&) = delete;
BaseComponent& operator=(BaseComponent&&) = default;
protected:
BaseComponent(const BaseComponent&) = default;
ComponentIndex m_componentIndex;
EntityHandle m_entity;
@ -47,6 +49,7 @@ namespace Ndk
virtual void OnComponentAttached(BaseComponent& component);
virtual void OnComponentDetached(BaseComponent& component);
virtual void OnDetached();
virtual void OnEntityDestruction();
void SetEntity(Entity* entity);

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -19,11 +19,19 @@ namespace Ndk
{
}
/*!
* \brief Gets the entity owning this component
* \return A handle to the entity owning this component, may be invalid if no entity owns it.
*/
inline const EntityHandle& BaseComponent::GetEntity() const
{
return m_entity;
}
/*!
* \brief Gets the index of the component
* \return Index of the component
*/
inline ComponentIndex BaseComponent::GetIndex() const
{
return m_componentIndex;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -9,6 +9,7 @@
#include <Nazara/Core/Bitset.hpp>
#include <NDK/Entity.hpp>
#include <NDK/EntityList.hpp>
#include <vector>
namespace Ndk
@ -33,7 +34,7 @@ namespace Ndk
bool Filters(const Entity* entity) const;
inline const std::vector<EntityHandle>& GetEntities() const;
inline const EntityList& GetEntities() const;
inline SystemIndex GetIndex() const;
inline int GetUpdateOrder() const;
inline float GetUpdateRate() const;
@ -84,12 +85,11 @@ namespace Ndk
static inline bool Initialize();
static inline void Uninitialize();
std::vector<EntityHandle> m_entities;
Nz::Bitset<Nz::UInt64> m_entityBits;
Nz::Bitset<> m_excludedComponents;
mutable Nz::Bitset<> m_filterResult;
Nz::Bitset<> m_requiredAnyComponents;
Nz::Bitset<> m_requiredComponents;
EntityList m_entities;
SystemIndex m_systemIndex;
World* m_world;
bool m_updateEnabled;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -56,7 +56,7 @@ namespace Ndk
* \return A constant reference to the list of entities
*/
inline const std::vector<EntityHandle>& BaseSystem::GetEntities() const
inline const EntityList& BaseSystem::GetEntities() const
{
return m_entities;
}
@ -121,10 +121,7 @@ namespace Ndk
inline bool BaseSystem::HasEntity(const Entity* entity) const
{
if (!entity)
return false;
return m_entityBits.UnboundedTest(entity->GetId());
return m_entities.Has(entity);
}
/*!
@ -288,9 +285,7 @@ namespace Ndk
{
NazaraAssert(entity, "Invalid entity");
m_entities.emplace_back(entity);
m_entityBits.UnboundedSet(entity->GetId(), true);
m_entities.Insert(entity);
entity->RegisterSystem(m_systemIndex);
OnEntityAdded(entity);
@ -308,14 +303,7 @@ namespace Ndk
{
NazaraAssert(entity, "Invalid entity");
auto it = std::find(m_entities.begin(), m_entities.end(), *entity);
NazaraAssert(it != m_entities.end(), "Entity is not part of this system");
// To avoid moving a lot of handles, we swap and pop
std::swap(*it, m_entities.back());
m_entities.pop_back(); // We get it out of the vector
m_entityBits.Reset(entity->GetId());
m_entities.Remove(entity);
entity->UnregisterSystem(m_systemIndex);
OnEntityRemoved(entity); // And we alert our callback
@ -360,7 +348,7 @@ namespace Ndk
}
/*!
* \brief Uninitializes the BaseSystem
* \brief Uninitialize the BaseSystem
*/
inline void BaseSystem::Uninitialize()

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -12,9 +12,11 @@
#include <NDK/EntityOwner.hpp>
#include <NDK/World.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Utility/Cursor.hpp>
#include <Nazara/Utility/Event.hpp>
#include <Nazara/Utility/Mouse.hpp>
#include <Nazara/Utility/Node.hpp>
#include <limits>
namespace Ndk
{
@ -32,28 +34,39 @@ namespace Ndk
BaseWidget(BaseWidget&&) = default;
virtual ~BaseWidget();
template<typename T, typename... Args> T& Add(Args&&... args);
template<typename T, typename... Args> T* Add(Args&&... args);
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
inline void Center();
inline void Destroy();
void EnableBackground(bool enable);
//virtual BaseWidget* Clone() const = 0;
inline const Nz::Color& GetBackgroundColor() const;
inline Canvas* GetCanvas();
inline Nz::SystemCursor GetCursor() const;
inline const Padding& GetPadding() const;
inline Nz::Vector2f GetContentOrigin() const;
inline const Nz::Vector2f& GetContentSize() const;
inline Nz::Vector2f GetSize() const;
inline bool IsVisible() const;
void GrabKeyboard();
virtual void ResizeToContent() = 0;
void SetBackgroundColor(const Nz::Color& color);
void SetCursor(Nz::SystemCursor systemCursor);
inline void SetContentSize(const Nz::Vector2f& size);
inline void SetPadding(float left, float top, float right, float bottom);
void SetSize(const Nz::Vector2f& size);
void Show(bool show = true);
BaseWidget& operator=(const BaseWidget&) = delete;
BaseWidget& operator=(BaseWidget&&) = default;
@ -78,12 +91,21 @@ namespace Ndk
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 OnParentResized(const Nz::Vector2f& newSize);
virtual void OnTextEntered(char32_t character, bool repeated);
private:
inline BaseWidget();
inline void DestroyChild(BaseWidget* widget);
void DestroyChildren();
inline bool IsRegisteredToCanvas() const;
inline void NotifyParentResized(const Nz::Vector2f& newSize);
void RegisterToCanvas();
inline void UpdateCanvasIndex(std::size_t index);
void UnregisterFromCanvas();
static constexpr std::size_t InvalidCanvasIndex = std::numeric_limits<std::size_t>::max();
std::size_t m_canvasIndex;
std::vector<EntityOwner> m_entities;
@ -94,8 +116,10 @@ namespace Ndk
WorldHandle m_world;
Nz::Color m_backgroundColor;
Nz::SpriteRef m_backgroundSprite;
Nz::SystemCursor m_cursor;
Nz::Vector2f m_contentSize;
BaseWidget* m_widgetParent;
bool m_visible;
};
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -9,26 +9,31 @@
namespace Ndk
{
inline BaseWidget::BaseWidget() :
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
m_canvasIndex(InvalidCanvasIndex),
m_canvas(nullptr),
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
m_cursor(Nz::SystemCursor_Default),
m_contentSize(50.f, 50.f),
m_widgetParent(nullptr)
m_widgetParent(nullptr),
m_visible(true)
{
SetPadding(5.f, 5.f, 5.f, 5.f);
}
template<typename T, typename... Args>
inline T& BaseWidget::Add(Args&&... args)
inline T* BaseWidget::Add(Args&&... args)
{
std::unique_ptr<T> widget = std::make_unique<T>(this, std::forward<Args>(args)...);
T& widgetRef = *widget;
T* widgetPtr = widget.get();
AddChild(std::move(widget));
return widgetRef;
return widgetPtr;
}
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)
{
widget->Show(m_visible);
widget->SetParent(this);
m_children.emplace_back(std::move(widget));
}
@ -41,16 +46,31 @@ namespace Ndk
SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f);
}
inline const Nz::Color& BaseWidget::GetBackgroundColor() const
{
return m_backgroundColor;
}
inline Canvas* BaseWidget::GetCanvas()
{
return m_canvas;
}
inline Nz::SystemCursor BaseWidget::GetCursor() const
{
return m_cursor;
}
inline const BaseWidget::Padding& BaseWidget::GetPadding() const
{
return m_padding;
}
inline Nz::Vector2f BaseWidget::GetContentOrigin() const
{
return { m_padding.left, m_padding.top };
}
inline const Nz::Vector2f& BaseWidget::GetContentSize() const
{
return m_contentSize;
@ -61,10 +81,16 @@ namespace Ndk
return Nz::Vector2f(m_contentSize.x + m_padding.left + m_padding.right, m_contentSize.y + m_padding.top + m_padding.bottom);
}
inline bool BaseWidget::IsVisible() const
{
return m_visible;
}
inline void BaseWidget::SetContentSize(const Nz::Vector2f& size)
{
NotifyParentResized(size);
m_contentSize = size;
Layout();
}
@ -78,6 +104,17 @@ namespace Ndk
Layout();
}
inline bool BaseWidget::IsRegisteredToCanvas() const
{
return m_canvas && m_canvasIndex != InvalidCanvasIndex;
}
inline void BaseWidget::NotifyParentResized(const Nz::Vector2f& newSize)
{
for (const auto& widgetPtr : m_children)
widgetPtr->OnParentResized(newSize);
}
inline void BaseWidget::UpdateCanvasIndex(std::size_t index)
{
m_canvasIndex = index;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -9,6 +9,7 @@
#include <NDK/Prerequesites.hpp>
#include <NDK/BaseWidget.hpp>
#include <Nazara/Utility/CursorController.hpp>
#include <Nazara/Utility/EventHandler.hpp>
namespace Ndk
@ -20,10 +21,10 @@ namespace Ndk
public:
struct Padding;
inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler);
inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController);
Canvas(const Canvas&) = delete;
Canvas(Canvas&&) = delete;
~Canvas() = default;
inline ~Canvas();
inline const WorldHandle& GetWorld() const;
@ -33,9 +34,8 @@ namespace Ndk
Canvas& operator=(Canvas&&) = delete;
protected:
void Layout() override;
void NotifyWidgetUpdate(std::size_t index);
inline void NotifyWidgetBoxUpdate(std::size_t index);
inline void NotifyWidgetCursorUpdate(std::size_t index);
std::size_t RegisterWidget(BaseWidget* widget);
@ -56,6 +56,7 @@ namespace Ndk
{
BaseWidget* widget;
Nz::Boxf box;
Nz::SystemCursor cursor;
};
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
@ -67,6 +68,7 @@ namespace Ndk
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
std::vector<WidgetBox> m_widgetBoxes;
Nz::CursorControllerHandle m_cursorController;
const WidgetBox* m_hoveredWidget;
BaseWidget* m_keyboardOwner;
WorldHandle m_world;

View File

@ -1,18 +1,25 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Canvas.hpp>
#include <Nazara/Utility/Cursor.hpp>
namespace Ndk
{
inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler) :
inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController) :
m_cursorController(cursorController),
m_hoveredWidget(nullptr),
m_keyboardOwner(nullptr),
m_world(std::move(world))
{
m_canvas = this;
m_widgetParent = nullptr;
// Register ourselves as a widget to handle cursor change
RegisterToCanvas();
// Connect to every meaningful event
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, this, &Canvas::OnKeyPressed);
m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, this, &Canvas::OnKeyReleased);
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, this, &Canvas::OnMouseButtonPressed);
@ -20,6 +27,18 @@ namespace Ndk
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnMouseMoved);
m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnMouseLeft);
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnTextEntered);
// Disable padding by default
SetPadding(0.f, 0.f, 0.f, 0.f);
}
inline Canvas::~Canvas()
{
// Destroy children explicitly because they signal us when getting destroyed, and that can't happen after our own destruction
DestroyChildren();
// Prevent our parent from trying to call us
m_canvasIndex = InvalidCanvasIndex;
}
inline const WorldHandle& Canvas::GetWorld() const
@ -27,6 +46,25 @@ namespace Ndk
return m_world;
}
inline void Canvas::NotifyWidgetBoxUpdate(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);
}
inline void Canvas::NotifyWidgetCursorUpdate(std::size_t index)
{
WidgetBox& entry = m_widgetBoxes[index];
entry.cursor = entry.widget->GetCursor();
if (m_cursorController && m_hoveredWidget == &entry)
m_cursorController->UpdateCursor(Nz::Cursor::Get(entry.cursor));
}
inline void Ndk::Canvas::SetKeyboardOwner(BaseWidget* widget)
{
m_keyboardOwner = widget;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -44,7 +44,7 @@ namespace Ndk
const Nz::Frustumf& GetFrustum() const override;
inline unsigned int GetLayer() const;
const Nz::Matrix4f& GetProjectionMatrix() const override;
inline Nz::ProjectionType GetProjectionType() const;
Nz::ProjectionType GetProjectionType() const override;
inline const Nz::Vector2f& GetSize() const;
const Nz::RenderTarget* GetTarget() const override;
inline const Nz::Rectf& GetTargetRegion() const;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -39,6 +39,7 @@ namespace Ndk
inline CameraComponent::CameraComponent(const CameraComponent& camera) :
Component(camera),
AbstractViewer(camera),
HandledObject(camera),
m_visibilityHash(camera.m_visibilityHash),
m_projectionType(camera.m_projectionType),
m_targetRegion(camera.m_targetRegion),
@ -116,16 +117,6 @@ namespace Ndk
return m_layer;
}
/*!
* \brief Gets the projection type of the camera
* \return Projection type of the camera
*/
inline Nz::ProjectionType CameraComponent::GetProjectionType() const
{
return m_projectionType;
}
/*!
* \brief Gets the size of the camera
* \return Size of the camera

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -51,6 +51,9 @@ namespace Ndk
inline void RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const;
inline void UpdateLocalMatrix(const Nz::InstancedRenderable* instancedRenderable, const Nz::Matrix4f& localMatrix);
inline void UpdateRenderOrder(const Nz::InstancedRenderable* instancedRenderable, int renderOrder);
static ComponentIndex componentIndex;
private:

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -142,6 +142,32 @@ namespace Ndk
}
}
inline void GraphicsComponent::UpdateLocalMatrix(const Nz::InstancedRenderable* instancedRenderable, const Nz::Matrix4f& localMatrix)
{
for (auto& renderable : m_renderables)
{
if (renderable.renderable == instancedRenderable)
{
renderable.data.localMatrix = localMatrix;
InvalidateBoundingVolume();
break;
}
}
}
inline void GraphicsComponent::UpdateRenderOrder(const Nz::InstancedRenderable* instancedRenderable, int renderOrder)
{
for (auto& renderable : m_renderables)
{
if (renderable.renderable == instancedRenderable)
{
renderable.data.renderOrder = renderOrder;
break;
}
}
}
/*!
* \brief Invalidates the bounding volume
*/

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -55,6 +55,7 @@ namespace Ndk
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
void OnEntityDestruction() override;
std::unique_ptr<Nz::RigidBody2D> m_object;
};

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -62,6 +62,7 @@ namespace Ndk
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
void OnEntityDestruction() override;
std::unique_ptr<Nz::RigidBody3D> m_object;
};

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -19,7 +19,7 @@
namespace Nz
{
class LuaInstance;
class LuaState;
}
namespace Ndk
@ -32,7 +32,7 @@ namespace Ndk
class NDK_API Console : public Nz::Node, public Nz::HandledObject<Console>
{
public:
Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance);
Console(World& world, const Nz::Vector2f& size, Nz::LuaState& state);
Console(const Console& console) = delete;
Console(Console&& console) = default;
~Console() = default;
@ -83,7 +83,7 @@ namespace Ndk
EntityOwner m_input;
EntityOwner m_inputBackground;
Nz::FontRef m_defaultFont;
Nz::LuaInstance& m_instance;
Nz::LuaState& m_state;
Nz::SpriteRef m_historyBackgroundSprite;
Nz::SpriteRef m_inputBackgroundSprite;
Nz::SimpleTextDrawer m_historyDrawer;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -9,6 +9,7 @@
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/Signal.hpp>
#include <NDK/Algorithm.hpp>
#include <memory>
#include <vector>
@ -16,14 +17,17 @@
namespace Ndk
{
class BaseComponent;
class BaseSystem;
class Entity;
class EntityList;
class World;
using EntityHandle = Nz::ObjectHandle<Entity>;
class NDK_API Entity : public Nz::HandledObject<Entity>
{
friend class BaseSystem;
friend BaseSystem;
friend EntityList;
friend World;
public:
@ -65,6 +69,8 @@ namespace Ndk
Entity& operator=(const Entity&) = delete;
Entity& operator=(Entity&&) = delete;
NazaraSignal(OnEntityDestruction, Entity* /*entity*/);
private:
Entity(World* world, EntityId id);
@ -75,13 +81,16 @@ namespace Ndk
inline Nz::Bitset<>& GetRemovedComponentBits();
inline void RegisterEntityList(EntityList* list);
inline void RegisterSystem(SystemIndex index);
inline void SetWorld(World* world) noexcept;
inline void UnregisterEntityList(EntityList* list);
inline void UnregisterSystem(SystemIndex index);
std::vector<std::unique_ptr<BaseComponent>> m_components;
std::vector<EntityList*> m_containedInLists;
Nz::Bitset<> m_componentBits;
Nz::Bitset<> m_removedComponentBits;
Nz::Bitset<> m_systemBits;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -6,6 +6,7 @@
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <algorithm>
#include <cassert>
#include <type_traits>
#include <utility>
@ -257,11 +258,10 @@ namespace Ndk
return m_removedComponentBits;
}
/*!
* \brief Registers a system for the entity
*
* \param index Index of the system
*/
inline void Entity::RegisterEntityList(EntityList* list)
{
m_containedInLists.push_back(list);
}
inline void Entity::RegisterSystem(SystemIndex index)
{
@ -289,6 +289,16 @@ namespace Ndk
* \param index Index of the system
*/
inline void Entity::UnregisterEntityList(EntityList* list)
{
auto it = std::find(m_containedInLists.begin(), m_containedInLists.end(), list);
assert(it != m_containedInLists.end());
// Swap and pop idiom
*it = m_containedInLists.back();
m_containedInLists.pop_back();
}
inline void Entity::UnregisterSystem(SystemIndex index)
{
m_systemBits.UnboundedReset(index);

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -15,46 +15,68 @@ namespace Ndk
{
class NDK_API EntityList
{
public:
using Container = std::vector<EntityHandle>;
friend Entity;
EntityList() = default;
~EntityList() = default;
public:
class iterator;
friend iterator;
using size_type = std::size_t;
inline EntityList();
inline EntityList(const EntityList& entityList);
inline EntityList(EntityList&& entityList) noexcept;
inline ~EntityList();
inline void Clear();
inline bool Has(const Entity* entity);
inline bool Has(EntityId entity);
inline bool Has(const Entity* entity) const;
inline bool Has(EntityId entity) const;
inline void Insert(Entity* entity);
inline void Remove(Entity* entity);
// STL API
inline Container::iterator begin();
inline Container::const_iterator begin() const;
inline Container::const_iterator cbegin() const;
inline Container::const_iterator cend() const;
inline Container::const_reverse_iterator crbegin() const;
inline Container::const_reverse_iterator crend() const;
inline iterator begin() const;
inline bool empty() const;
inline iterator end() const;
inline size_type size() const;
inline Container::iterator end();
inline Container::const_iterator end() const;
inline Container::reverse_iterator rbegin();
inline Container::const_reverse_iterator rbegin() const;
inline Container::reverse_iterator rend();
inline Container::const_reverse_iterator rend() const;
inline Container::size_type size() const;
inline EntityList& operator=(const EntityList& entityList);
inline EntityList& operator=(EntityList&& entityList) noexcept;
private:
std::vector<EntityHandle> m_entities;
inline std::size_t FindNext(std::size_t currentId) const;
inline World* GetWorld() const;
inline void NotifyEntityDestruction(const Entity* entity);
Nz::Bitset<Nz::UInt64> m_entityBits;
World* m_world;
};
class NDK_API EntityList::iterator : public std::iterator<std::forward_iterator_tag, const EntityHandle>
{
friend EntityList;
public:
inline iterator(const iterator& it);
const EntityHandle& operator*() const;
inline iterator& operator=(const iterator& it);
inline iterator& operator++();
inline iterator operator++(int);
friend inline bool operator==(const iterator& lhs, const iterator& rhs);
friend inline bool operator!=(const iterator& lhs, const iterator& rhs);
friend inline void swap(iterator& lhs, iterator& rhs);
private:
inline iterator(const EntityList* world, std::size_t nextId);
std::size_t m_nextEntityId;
const EntityList* m_list;
};
}

View File

@ -1,7 +1,8 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/EntityList.hpp>
#include <Nazara/Core/Error.hpp>
#include <algorithm>
@ -14,24 +15,71 @@ namespace Ndk
*/
/*!
* \brief Clears the set from every entities
* \brief Construct a new entity list
*/
inline void EntityList::Clear()
inline EntityList::EntityList() :
m_world(nullptr)
{
m_entities.clear();
m_entityBits.Clear();
}
/*!
* \brief Checks whether or not the set contains the entity
* \brief Construct a new entity list by copying another one
*/
inline EntityList::EntityList(const EntityList& entityList) :
m_entityBits(entityList.m_entityBits),
m_world(entityList.m_world)
{
for (const Ndk::EntityHandle& entity : *this)
entity->RegisterEntityList(this);
}
/*!
* \brief Construct a new entity list by moving a list into this one
*/
inline EntityList::EntityList(EntityList&& entityList) noexcept :
m_entityBits(std::move(entityList.m_entityBits)),
m_world(entityList.m_world)
{
for (const Ndk::EntityHandle& entity : *this)
{
entity->UnregisterEntityList(&entityList);
entity->RegisterEntityList(this);
}
}
inline EntityList::~EntityList()
{
for (const Ndk::EntityHandle& entity : *this)
entity->UnregisterEntityList(this);
}
/*!
* \brief Clears the set from every entities
*
* \remark This resets the implicit world member, allowing you to insert entities from a different world than previously
*/
inline void EntityList::Clear()
{
for (const Ndk::EntityHandle& entity : *this)
entity->UnregisterEntityList(this);
m_entityBits.Clear();
m_world = nullptr;
}
/*!
* \brief Checks whether or not the EntityList contains the entity
* \return true If it is the case
*
* \param entity Pointer to the entity
*
* \remark If the Insert function was called since the EntityList construction (or last call to Clear), the entity passed by parameter must belong to the same world as the previously inserted entities.
*/
inline bool EntityList::Has(const Entity* entity)
inline bool EntityList::Has(const Entity* entity) const
{
NazaraAssert(!m_world || !entity || entity->GetWorld() == m_world, "Incompatible world");
return entity && entity->IsValid() && Has(entity->GetId());
}
@ -41,8 +89,7 @@ namespace Ndk
*
* \param id Identifier of the entity
*/
inline bool EntityList::Has(EntityId entity)
inline bool EntityList::Has(EntityId entity) const
{
return m_entityBits.UnboundedTest(entity);
}
@ -50,17 +97,23 @@ namespace Ndk
/*!
* \brief Inserts the entity into the set
*
* \param entity Pointer to the entity
* Marks an entity as present in this entity list, it must belongs to the same world as others entities contained in this list.
*
* \param entity Valid pointer to an entity
*
* \remark If entity is already contained, no action is performed
* \remark If any entity has been inserted since construction (or last Clear call), the entity must belong to the same world as the previously inserted entities
*/
inline void EntityList::Insert(Entity* entity)
{
NazaraAssert(entity, "Invalid entity");
if (!Has(entity))
{
m_entities.emplace_back(entity);
entity->RegisterEntityList(this);
m_entityBits.UnboundedSet(entity->GetId(), true);
m_world = entity->GetWorld();
}
}
@ -70,89 +123,138 @@ namespace Ndk
* \param entity Pointer to the entity
*
* \remark If entity is not contained, no action is performed
* \remark This function never resets the implicit world member, even if it empties the list. Use the Clear method if you want to reset it.
*
* \see Clear
*/
inline void EntityList::Remove(Entity* entity)
{
if (Has(entity))
{
auto it = std::find(m_entities.begin(), m_entities.end(), *entity);
NazaraAssert(it != m_entities.end(), "Entity should be part of the vector");
m_entityBits.Reset(entity->GetId());
std::swap(*it, m_entities.back());
m_entities.pop_back(); // We get it out of the vector
m_entityBits.UnboundedSet(entity->GetId(), false);
entity->UnregisterEntityList(this);
}
}
// Nz::Interface STD
inline EntityList::Container::iterator EntityList::begin()
// STL Interface
inline EntityList::iterator EntityList::begin() const
{
return m_entities.begin();
}
inline EntityList::Container::const_iterator EntityList::begin() const
{
return m_entities.begin();
}
inline EntityList::Container::const_iterator EntityList::cbegin() const
{
return m_entities.cbegin();
}
inline EntityList::Container::const_iterator EntityList::cend() const
{
return m_entities.cend();
}
inline EntityList::Container::const_reverse_iterator EntityList::crbegin() const
{
return m_entities.crbegin();
}
inline EntityList::Container::const_reverse_iterator EntityList::crend() const
{
return m_entities.crend();
return EntityList::iterator(this, m_entityBits.FindFirst());
}
inline bool EntityList::empty() const
{
return m_entities.empty();
return !m_entityBits.TestAny();
}
inline EntityList::Container::iterator EntityList::end()
inline EntityList::iterator EntityList::end() const
{
return m_entities.end();
return EntityList::iterator(this, m_entityBits.npos);
}
inline EntityList::Container::const_iterator EntityList::end() const
inline EntityList::size_type EntityList::size() const
{
return m_entities.end();
return m_entityBits.Count();
}
inline EntityList::Container::reverse_iterator EntityList::rbegin()
inline EntityList& EntityList::operator=(const EntityList& entityList)
{
return m_entities.rbegin();
m_entityBits = entityList.m_entityBits;
m_world = entityList.m_world;
for (const Ndk::EntityHandle& entity : *this)
entity->RegisterEntityList(this);
return *this;
}
inline EntityList::Container::const_reverse_iterator EntityList::rbegin() const
inline EntityList& EntityList::operator=(EntityList&& entityList) noexcept
{
return m_entities.rbegin();
m_entityBits = std::move(entityList.m_entityBits);
m_world = entityList.m_world;
for (const Ndk::EntityHandle& entity : *this)
{
entity->UnregisterEntityList(&entityList);
entity->RegisterEntityList(this);
}
return *this;
}
inline EntityList::Container::reverse_iterator EntityList::rend()
inline std::size_t EntityList::FindNext(std::size_t currentId) const
{
return m_entities.rend();
return m_entityBits.FindNext(currentId);
}
inline EntityList::Container::const_reverse_iterator EntityList::rend() const
inline World* EntityList::GetWorld() const
{
return m_entities.rend();
return m_world;
}
inline EntityList::Container::size_type EntityList::size() const
inline void EntityList::NotifyEntityDestruction(const Entity* entity)
{
return m_entities.size();
assert(Has(entity));
m_entityBits.Reset(entity->GetId());
}
inline EntityList::iterator::iterator(const EntityList* list, std::size_t nextId) :
m_nextEntityId(nextId),
m_list(list)
{
}
inline EntityList::iterator::iterator(const iterator& it) :
m_nextEntityId(it.m_nextEntityId),
m_list(it.m_list)
{
}
inline EntityList::iterator& EntityList::iterator::operator=(const iterator& it)
{
m_nextEntityId = it.m_nextEntityId;
m_list = it.m_list;
return *this;
}
inline EntityList::iterator& EntityList::iterator::operator++()
{
m_nextEntityId = m_list->FindNext(m_nextEntityId);
return *this;
}
inline EntityList::iterator EntityList::iterator::operator++(int)
{
std::size_t previousId = m_nextEntityId;
m_nextEntityId = m_list->FindNext(m_nextEntityId);
return iterator(m_list, previousId);
}
inline bool operator==(const EntityList::iterator& lhs, const EntityList::iterator& rhs)
{
NazaraAssert(lhs.m_list == rhs.m_list, "Cannot compare iterator coming from different lists");
return lhs.m_nextEntityId == rhs.m_nextEntityId;
}
inline bool operator!=(const EntityList::iterator& lhs, const EntityList::iterator& rhs)
{
return !operator==(lhs, rhs);
}
inline void swap(EntityList::iterator& lhs, EntityList::iterator& rhs)
{
NazaraAssert(lhs.m_list == rhs.m_list, "Cannot compare iterator coming from different lists");
using std::swap;
swap(lhs.m_nextEntityId, rhs.m_nextEntityId);
}
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -24,7 +24,7 @@ namespace Ndk
template<typename T> void BindComponent(const Nz::String& name);
void RegisterClasses(Nz::LuaInstance& instance);
void RegisterClasses(Nz::LuaState& state);
std::unique_ptr<LuaBinding_Base> core;
std::unique_ptr<LuaBinding_Base> math;
@ -40,13 +40,13 @@ namespace Ndk
private:
template<typename T>
static int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle);
static int AddComponentOfType(Nz::LuaState& lua, EntityHandle& handle);
template<typename T>
static int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component);
static int PushComponentOfType(Nz::LuaState& lua, BaseComponent& component);
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
using GetComponentFunc = int(*)(Nz::LuaInstance&, BaseComponent&);
using AddComponentFunc = int(*)(Nz::LuaState&, EntityHandle&);
using GetComponentFunc = int(*)(Nz::LuaState&, BaseComponent&);
struct ComponentBinding
{
@ -56,7 +56,7 @@ namespace Ndk
Nz::String name;
};
ComponentBinding* QueryComponentIndex(Nz::LuaInstance& lua, int argIndex = 2);
ComponentBinding* QueryComponentIndex(Nz::LuaState& lua, int argIndex = 2);
std::vector<ComponentBinding> m_componentBinding;
std::unordered_map<Nz::String, ComponentIndex> m_componentBindingByName;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -33,7 +33,7 @@ namespace Ndk
}
template<typename T>
int LuaBinding::AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
int LuaBinding::AddComponentOfType(Nz::LuaState& lua, EntityHandle& handle)
{
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
@ -43,7 +43,7 @@ namespace Ndk
}
template<typename T>
int LuaBinding::PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
int LuaBinding::PushComponentOfType(Nz::LuaState& lua, BaseComponent& component)
{
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -21,7 +21,7 @@ namespace Ndk
LuaBinding_Audio(LuaBinding& binding);
~LuaBinding_Audio() = default;
void Register(Nz::LuaInstance& instance) override;
void Register(Nz::LuaState& state) override;
Nz::LuaClass<Nz::Music> music;
Nz::LuaClass<Nz::Sound> sound;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -30,7 +30,7 @@ namespace Ndk
LuaBinding_Base(LuaBinding& binding);
virtual ~LuaBinding_Base();
virtual void Register(Nz::LuaInstance& instance) = 0;
virtual void Register(Nz::LuaState& state) = 0;
// Implementation lies in the respective .cpp files (still searching for a cleaner way..)
static std::unique_ptr<LuaBinding_Base> BindCore(LuaBinding& binding);

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -21,7 +21,7 @@ namespace Ndk
LuaBinding_Core(LuaBinding& binding);
~LuaBinding_Core() = default;
void Register(Nz::LuaInstance& instance) override;
void Register(Nz::LuaState& state) override;
Nz::LuaClass<Nz::Clock> clock;
Nz::LuaClass<Nz::Directory> directory;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -22,7 +22,7 @@ namespace Ndk
LuaBinding_Graphics(LuaBinding& binding);
~LuaBinding_Graphics() = default;
void Register(Nz::LuaInstance& instance) override;
void Register(Nz::LuaState& state) override;
Nz::LuaClass<Nz::AbstractViewer> abstractViewer;
Nz::LuaClass<Nz::InstancedRenderableRef> instancedRenderable;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -23,7 +23,7 @@ namespace Ndk
LuaBinding_Math(LuaBinding& binding);
~LuaBinding_Math() = default;
void Register(Nz::LuaInstance& instance) override;
void Register(Nz::LuaState& state) override;
Nz::LuaClass<Nz::EulerAnglesd> eulerAngles;
Nz::LuaClass<Nz::Matrix4d> matrix4d;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -9,6 +9,7 @@
#include <Nazara/Network/AbstractSocket.hpp>
#include <Nazara/Network/IpAddress.hpp>
#include <Nazara/Network/UdpSocket.hpp>
#include <NDK/Lua/LuaBinding_Base.hpp>
namespace Ndk
@ -19,10 +20,11 @@ namespace Ndk
LuaBinding_Network(LuaBinding& binding);
~LuaBinding_Network() = default;
void Register(Nz::LuaInstance& instance) override;
void Register(Nz::LuaState& state) override;
Nz::LuaClass<Nz::AbstractSocket> abstractSocket;
Nz::LuaClass<Nz::IpAddress> ipAddress;
Nz::LuaClass<Nz::UdpSocket> udpSocket;
};
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -18,7 +18,7 @@ namespace Ndk
LuaBinding_Renderer(LuaBinding& binding);
~LuaBinding_Renderer() = default;
void Register(Nz::LuaInstance& instance) override;
void Register(Nz::LuaState& state) override;
Nz::LuaClass<Nz::TextureRef> texture;
Nz::LuaClass<Nz::TextureLibrary> textureLibrary;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -22,7 +22,7 @@ namespace Ndk
LuaBinding_SDK(LuaBinding& binding);
~LuaBinding_SDK() = default;
void Register(Nz::LuaInstance& instance) override;
void Register(Nz::LuaState& state) override;
Nz::LuaClass<Application*> application;
Nz::LuaClass<EntityHandle> entity;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -21,7 +21,7 @@ namespace Ndk
LuaBinding_Utility(LuaBinding& binding);
~LuaBinding_Utility() = default;
void Register(Nz::LuaInstance& instance) override;
void Register(Nz::LuaState& state) override;
// Utility
Nz::LuaClass<Nz::AbstractImageRef> abstractImage;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -11,7 +11,7 @@
namespace Nz
{
class LuaInstance;
class LuaState;
}
namespace Ndk
@ -28,7 +28,7 @@ namespace Ndk
static bool Initialize();
static void RegisterClasses(Nz::LuaInstance& instance);
static void RegisterClasses(Nz::LuaState& state);
static void Uninitialize();

View File

@ -1,10 +1,10 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/LuaAPI.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Lua/LuaInstance.hpp>
#include <Nazara/Lua/LuaState.hpp>
#include <Nazara/Math/EulerAngles.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
@ -28,103 +28,103 @@
namespace Nz
{
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Color* color, TypeTag<Color>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Color* color, TypeTag<Color>)
{
instance.CheckType(index, Nz::LuaType_Table);
state.CheckType(index, Nz::LuaType_Table);
color->r = instance.CheckField<UInt8>("r", index);
color->g = instance.CheckField<UInt8>("g", index);
color->b = instance.CheckField<UInt8>("b", index);
color->a = instance.CheckField<UInt8>("a", 255, index);
color->r = state.CheckField<UInt8>("r", index);
color->g = state.CheckField<UInt8>("g", index);
color->b = state.CheckField<UInt8>("b", index);
color->a = state.CheckField<UInt8>("a", 255, index);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesd* angles, TypeTag<EulerAnglesd>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, EulerAnglesd* angles, TypeTag<EulerAnglesd>)
{
switch (instance.GetType(index))
switch (state.GetType(index))
{
case Nz::LuaType_Table:
angles->Set(instance.CheckField<double>("pitch", index), instance.CheckField<double>("yaw", index), instance.CheckField<double>("roll", index));
angles->Set(state.CheckField<double>("pitch", index), state.CheckField<double>("yaw", index), state.CheckField<double>("roll", index));
return 1;
default:
{
if (instance.IsOfType(index, "EulerAngles"))
angles->Set(*static_cast<EulerAnglesd*>(instance.ToUserdata(index)));
if (state.IsOfType(index, "EulerAngles"))
angles->Set(*static_cast<EulerAnglesd*>(state.ToUserdata(index)));
else
angles->Set(*static_cast<Quaterniond*>(instance.CheckUserdata(index, "Quaternion")));
angles->Set(*static_cast<Quaterniond*>(state.CheckUserdata(index, "Quaternion")));
return 1;
}
}
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesf* angles, TypeTag<EulerAnglesf>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, EulerAnglesf* angles, TypeTag<EulerAnglesf>)
{
EulerAnglesd anglesDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &anglesDouble, TypeTag<EulerAnglesd>());
unsigned int ret = LuaImplQueryArg(state, index, &anglesDouble, TypeTag<EulerAnglesd>());
angles->Set(anglesDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, FontRef* fontRef, TypeTag<FontRef>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, FontRef* fontRef, TypeTag<FontRef>)
{
*fontRef = *static_cast<FontRef*>(instance.CheckUserdata(index, "Font"));
*fontRef = *static_cast<FontRef*>(state.CheckUserdata(index, "Font"));
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, FontParams* params, TypeTag<FontParams>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, FontParams* params, TypeTag<FontParams>)
{
NazaraUnused(params);
instance.CheckType(index, Nz::LuaType_Table);
state.CheckType(index, Nz::LuaType_Table);
// Structure is empty for now
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, ImageParams* params, TypeTag<ImageParams>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, ImageParams* params, TypeTag<ImageParams>)
{
instance.CheckType(index, Nz::LuaType_Table);
state.CheckType(index, Nz::LuaType_Table);
params->levelCount = instance.CheckField<Nz::UInt8>("LevelCount");
params->loadFormat = instance.CheckField<Nz::PixelFormatType>("LoadFormat");
params->levelCount = state.CheckField<Nz::UInt8>("LevelCount");
params->loadFormat = state.CheckField<Nz::PixelFormatType>("LoadFormat");
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag<IpAddress>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, IpAddress* address, TypeTag<IpAddress>)
{
switch (instance.GetType(index))
switch (state.GetType(index))
{
case Nz::LuaType_String:
address->BuildFromAddress(instance.CheckString(index));
address->BuildFromAddress(state.CheckString(index));
return 1;
default:
*address = *static_cast<IpAddress*>(instance.CheckUserdata(index, "IpAddress"));
*address = *static_cast<IpAddress*>(state.CheckUserdata(index, "IpAddress"));
return 1;
}
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Matrix4d* mat, TypeTag<Matrix4d>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Matrix4d* mat, TypeTag<Matrix4d>)
{
switch (instance.GetType(index))
switch (state.GetType(index))
{
case Nz::LuaType_Table:
{
double values[16];
for (std::size_t i = 0; i < 16; ++i)
{
instance.PushInteger(i + 1);
instance.GetTable();
state.PushInteger(i + 1);
state.GetTable();
values[i] = instance.CheckNumber(-1);
instance.Pop();
values[i] = state.CheckNumber(-1);
state.Pop();
}
mat->Set(values);
@ -133,500 +133,500 @@ namespace Nz
default:
{
if (instance.IsOfType(index, "Matrix4"))
mat->Set(*static_cast<Matrix4d*>(instance.ToUserdata(index)));
if (state.IsOfType(index, "Matrix4"))
mat->Set(*static_cast<Matrix4d*>(state.ToUserdata(index)));
return 1;
}
}
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Matrix4f* mat, TypeTag<Matrix4f>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Matrix4f* mat, TypeTag<Matrix4f>)
{
Matrix4d matDouble = Matrix4d::Identity();
unsigned int ret = LuaImplQueryArg(instance, index, &matDouble, TypeTag<Matrix4d>());
unsigned int ret = LuaImplQueryArg(state, index, &matDouble, TypeTag<Matrix4d>());
mat->Set(matDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MeshParams* params, TypeTag<MeshParams>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, MeshParams* params, TypeTag<MeshParams>)
{
instance.CheckType(index, Nz::LuaType_Table);
state.CheckType(index, Nz::LuaType_Table);
params->animated = instance.CheckField<bool>("Animated", params->animated);
params->center = instance.CheckField<bool>("Center", params->center);
params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
params->texCoordOffset = instance.CheckField<Vector2f>("TexCoordOffset", params->texCoordOffset);
params->texCoordScale = instance.CheckField<Vector2f>("TexCoordScale", params->texCoordScale);
params->animated = state.CheckField<bool>("Animated", params->animated);
params->center = state.CheckField<bool>("Center", params->center);
params->matrix = state.CheckField<Matrix4f>("Matrix", params->matrix);
params->optimizeIndexBuffers = state.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
params->texCoordOffset = state.CheckField<Vector2f>("TexCoordOffset", params->texCoordOffset);
params->texCoordScale = state.CheckField<Vector2f>("TexCoordScale", params->texCoordScale);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Quaterniond* quat, TypeTag<Quaterniond>)
{
switch (instance.GetType(index))
switch (state.GetType(index))
{
case Nz::LuaType_Table:
quat->Set(instance.CheckField<double>("w", index), instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", index));
quat->Set(state.CheckField<double>("w", index), state.CheckField<double>("x", index), state.CheckField<double>("y", index), state.CheckField<double>("z", index));
return 1;
default:
{
if (instance.IsOfType(index, "EulerAngles"))
quat->Set(*static_cast<EulerAnglesd*>(instance.ToUserdata(index)));
if (state.IsOfType(index, "EulerAngles"))
quat->Set(*static_cast<EulerAnglesd*>(state.ToUserdata(index)));
else
quat->Set(*static_cast<Quaterniond*>(instance.CheckUserdata(index, "Quaternion")));
quat->Set(*static_cast<Quaterniond*>(state.CheckUserdata(index, "Quaternion")));
return 1;
}
}
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag<Quaternionf>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Quaternionf* quat, TypeTag<Quaternionf>)
{
Quaterniond quatDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag<Quaterniond>());
unsigned int ret = LuaImplQueryArg(state, index, &quatDouble, TypeTag<Quaterniond>());
quat->Set(quatDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Rectd* rect, TypeTag<Rectd>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Rectd* rect, TypeTag<Rectd>)
{
instance.CheckType(index, LuaType_Table);
state.CheckType(index, LuaType_Table);
rect->x = instance.CheckField<double>("x", index);
rect->y = instance.CheckField<double>("y", index);
rect->width = instance.CheckField<double>("width", index);
rect->height = instance.CheckField<double>("height", index);
rect->x = state.CheckField<double>("x", index);
rect->y = state.CheckField<double>("y", index);
rect->width = state.CheckField<double>("width", index);
rect->height = state.CheckField<double>("height", index);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Rectf* rect, TypeTag<Rectf>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Rectf* rect, TypeTag<Rectf>)
{
Rectd rectDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &rectDouble, TypeTag<Rectd>());
unsigned int ret = LuaImplQueryArg(state, index, &rectDouble, TypeTag<Rectd>());
rect->Set(rectDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Recti* rect, TypeTag<Recti>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Recti* rect, TypeTag<Recti>)
{
Rectd rectDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &rectDouble, TypeTag<Rectd>());
unsigned int ret = LuaImplQueryArg(state, index, &rectDouble, TypeTag<Rectd>());
rect->Set(rectDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Rectui* rect, TypeTag<Rectui>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Rectui* rect, TypeTag<Rectui>)
{
Rectd rectDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &rectDouble, TypeTag<Rectd>());
unsigned int ret = LuaImplQueryArg(state, index, &rectDouble, TypeTag<Rectd>());
rect->Set(rectDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2d* vec, TypeTag<Vector2d>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector2d* vec, TypeTag<Vector2d>)
{
switch (instance.GetType(index))
switch (state.GetType(index))
{
case Nz::LuaType_Number:
if (index < 0 && index > -2)
instance.Error("Vector2 expected, two numbers are required to convert it");
state.Error("Vector2 expected, two numbers are required to convert it");
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1));
vec->Set(state.CheckNumber(index), state.CheckNumber(index + 1));
return 2;
case Nz::LuaType_Table:
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index));
vec->Set(state.CheckField<double>("x", index), state.CheckField<double>("y", index));
return 1;
default:
vec->Set(*static_cast<Vector2d*>(instance.CheckUserdata(index, "Vector2")));
vec->Set(*static_cast<Vector2d*>(state.CheckUserdata(index, "Vector2")));
return 1;
}
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2f* vec, TypeTag<Vector2f>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector2f* vec, TypeTag<Vector2f>)
{
Vector2d vecDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag<Vector2d>());
vec->Set(vecDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2ui* vec, TypeTag<Vector2ui>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector2ui* vec, TypeTag<Vector2ui>)
{
Vector2d vecDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag<Vector2d>());
vec->Set(vecDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3d* vec, TypeTag<Vector3d>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector3d* vec, TypeTag<Vector3d>)
{
switch (instance.GetType(index))
switch (state.GetType(index))
{
case Nz::LuaType_Number:
if (index < 0 && index > -3)
instance.Error("Vector3 expected, three numbers are required to convert it");
state.Error("Vector3 expected, three numbers are required to convert it");
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1), instance.CheckNumber(index + 2, 0.0));
vec->Set(state.CheckNumber(index), state.CheckNumber(index + 1), state.CheckNumber(index + 2, 0.0));
return 3;
case Nz::LuaType_Table:
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", 0.0, index));
vec->Set(state.CheckField<double>("x", index), state.CheckField<double>("y", index), state.CheckField<double>("z", 0.0, index));
return 1;
default:
vec->Set(*static_cast<Vector3d*>(instance.CheckUserdata(index, "Vector3")));
vec->Set(*static_cast<Vector3d*>(state.CheckUserdata(index, "Vector3")));
return 1;
}
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3f* vec, TypeTag<Vector3f>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector3f* vec, TypeTag<Vector3f>)
{
Vector3d vecDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag<Vector3d>());
vec->Set(vecDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3ui* vec, TypeTag<Vector3ui>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Vector3ui* vec, TypeTag<Vector3ui>)
{
Vector3d vecDouble;
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
unsigned int ret = LuaImplQueryArg(state, index, &vecDouble, TypeTag<Vector3d>());
vec->Set(vecDouble);
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Ndk::EntityHandle* handle, TypeTag<Ndk::EntityHandle>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Ndk::EntityHandle* handle, TypeTag<Ndk::EntityHandle>)
{
*handle = *static_cast<Ndk::EntityHandle*>(instance.CheckUserdata(index, "Entity"));
*handle = *static_cast<Ndk::EntityHandle*>(state.CheckUserdata(index, "Entity"));
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Ndk::WorldHandle* handle, TypeTag<Ndk::WorldHandle>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Ndk::WorldHandle* handle, TypeTag<Ndk::WorldHandle>)
{
*handle = *static_cast<Ndk::WorldHandle*>(instance.CheckUserdata(index, "World"));
*handle = *static_cast<Ndk::WorldHandle*>(state.CheckUserdata(index, "World"));
return 1;
}
#ifndef NDK_SERVER
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, InstancedRenderableRef* renderable, TypeTag<InstancedRenderableRef>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, InstancedRenderableRef* renderable, TypeTag<InstancedRenderableRef>)
{
if (instance.IsOfType(index, "InstancedRenderable") ||
instance.IsOfType(index, "Model") ||
instance.IsOfType(index, "Sprite"))
if (state.IsOfType(index, "InstancedRenderable") ||
state.IsOfType(index, "Model") ||
state.IsOfType(index, "Sprite"))
{
*renderable = *static_cast<InstancedRenderableRef*>(instance.ToUserdata(index));
*renderable = *static_cast<InstancedRenderableRef*>(state.ToUserdata(index));
}
else
instance.ArgError(index, "is not a InstancedRenderable instance");
state.ArgError(index, "is not a InstancedRenderable instance");
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MaterialRef* materialRef, TypeTag<MaterialRef>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, MaterialRef* materialRef, TypeTag<MaterialRef>)
{
*materialRef = *static_cast<MaterialRef*>(instance.CheckUserdata(index, "Material"));
*materialRef = *static_cast<MaterialRef*>(state.CheckUserdata(index, "Material"));
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MaterialParams* params, TypeTag<MaterialParams>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, MaterialParams* params, TypeTag<MaterialParams>)
{
instance.CheckType(index, Nz::LuaType_Table);
state.CheckType(index, Nz::LuaType_Table);
params->loadAlphaMap = instance.CheckField<bool>("LoadAlphaMap", params->loadAlphaMap);
params->loadDiffuseMap = instance.CheckField<bool>("LoadDiffuseMap", params->loadDiffuseMap);
params->loadEmissiveMap = instance.CheckField<bool>("LoadEmissiveMap", params->loadEmissiveMap);
params->loadHeightMap = instance.CheckField<bool>("LoadHeightMap", params->loadHeightMap);
params->loadNormalMap = instance.CheckField<bool>("LoadNormalMap", params->loadNormalMap);
params->loadSpecularMap = instance.CheckField<bool>("LoadSpecularMap", params->loadSpecularMap);
params->shaderName = instance.CheckField<String>("ShaderName", params->shaderName);
params->loadAlphaMap = state.CheckField<bool>("LoadAlphaMap", params->loadAlphaMap);
params->loadDiffuseMap = state.CheckField<bool>("LoadDiffuseMap", params->loadDiffuseMap);
params->loadEmissiveMap = state.CheckField<bool>("LoadEmissiveMap", params->loadEmissiveMap);
params->loadHeightMap = state.CheckField<bool>("LoadHeightMap", params->loadHeightMap);
params->loadNormalMap = state.CheckField<bool>("LoadNormalMap", params->loadNormalMap);
params->loadSpecularMap = state.CheckField<bool>("LoadSpecularMap", params->loadSpecularMap);
params->shaderName = state.CheckField<String>("ShaderName", params->shaderName);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, ModelParameters* params, TypeTag<ModelParameters>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, ModelParameters* params, TypeTag<ModelParameters>)
{
instance.CheckType(index, Nz::LuaType_Table);
state.CheckType(index, Nz::LuaType_Table);
params->loadMaterials = instance.CheckField<bool>("LoadMaterials", params->loadMaterials);
params->loadMaterials = state.CheckField<bool>("LoadMaterials", params->loadMaterials);
LuaImplQueryArg(instance, -1, &params->material, TypeTag<MaterialParams>());
LuaImplQueryArg(instance, -1, &params->mesh, TypeTag<MeshParams>());
LuaImplQueryArg(state, -1, &params->material, TypeTag<MaterialParams>());
LuaImplQueryArg(state, -1, &params->mesh, TypeTag<MeshParams>());
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MusicParams* params, TypeTag<MusicParams>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, MusicParams* params, TypeTag<MusicParams>)
{
instance.CheckType(index, Nz::LuaType_Table);
state.CheckType(index, Nz::LuaType_Table);
params->forceMono = instance.CheckField<bool>("ForceMono", params->forceMono);
params->forceMono = state.CheckField<bool>("ForceMono", params->forceMono);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SoundBufferParams* params, TypeTag<SoundBufferParams>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, SoundBufferParams* params, TypeTag<SoundBufferParams>)
{
instance.CheckType(index, Nz::LuaType_Table);
state.CheckType(index, Nz::LuaType_Table);
params->forceMono = instance.CheckField<bool>("ForceMono", params->forceMono);
params->forceMono = state.CheckField<bool>("ForceMono", params->forceMono);
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SpriteRef* spriteRef, TypeTag<SpriteRef>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, SpriteRef* spriteRef, TypeTag<SpriteRef>)
{
*spriteRef = *static_cast<SpriteRef*>(instance.CheckUserdata(index, "Sprite"));
*spriteRef = *static_cast<SpriteRef*>(state.CheckUserdata(index, "Sprite"));
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, TextureRef* textureRef, TypeTag<TextureRef>)
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, TextureRef* textureRef, TypeTag<TextureRef>)
{
*textureRef = *static_cast<TextureRef*>(instance.CheckUserdata(index, "Texture"));
*textureRef = *static_cast<TextureRef*>(state.CheckUserdata(index, "Texture"));
return 1;
}
#endif
inline int LuaImplReplyVal(const LuaInstance& instance, Color&& val, TypeTag<Color>)
inline int LuaImplReplyVal(const LuaState& state, Color&& val, TypeTag<Color>)
{
instance.PushTable();
instance.PushField("r", val.r);
instance.PushField("g", val.g);
instance.PushField("b", val.b);
instance.PushField("a", val.a);
state.PushTable();
state.PushField("r", val.r);
state.PushField("g", val.g);
state.PushField("b", val.b);
state.PushField("a", val.a);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesd&& val, TypeTag<EulerAnglesd>)
inline int LuaImplReplyVal(const LuaState& state, EulerAnglesd&& val, TypeTag<EulerAnglesd>)
{
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
state.PushInstance<EulerAnglesd>("EulerAngles", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesf&& val, TypeTag<EulerAnglesf>)
inline int LuaImplReplyVal(const LuaState& state, EulerAnglesf&& val, TypeTag<EulerAnglesf>)
{
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
state.PushInstance<EulerAnglesd>("EulerAngles", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, FontRef&& val, TypeTag<FontRef>)
inline int LuaImplReplyVal(const LuaState& state, FontRef&& val, TypeTag<FontRef>)
{
instance.PushInstance<FontRef>("Font", val);
state.PushInstance<FontRef>("Font", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Font::SizeInfo&& val, TypeTag<Font::SizeInfo>)
inline int LuaImplReplyVal(const LuaState& state, Font::SizeInfo&& val, TypeTag<Font::SizeInfo>)
{
instance.PushTable();
instance.PushField("LineHeight", val.lineHeight);
instance.PushField("SpaceAdvance", val.spaceAdvance);
instance.PushField("UnderlinePosition", val.underlinePosition);
instance.PushField("UnderlineThickness", val.underlineThickness);
state.PushTable();
state.PushField("LineHeight", val.lineHeight);
state.PushField("SpaceAdvance", val.spaceAdvance);
state.PushField("UnderlinePosition", val.underlinePosition);
state.PushField("UnderlineThickness", val.underlineThickness);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, ImageParams&& val, TypeTag<ImageParams>)
inline int LuaImplReplyVal(const LuaState& state, ImageParams&& val, TypeTag<ImageParams>)
{
instance.PushTable(0, 2);
instance.PushField("LevelCount", val.levelCount);
instance.PushField("LoadFormat", val.loadFormat);
state.PushTable(0, 2);
state.PushField("LevelCount", val.levelCount);
state.PushField("LoadFormat", val.loadFormat);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress&& val, TypeTag<IpAddress>)
inline int LuaImplReplyVal(const LuaState& state, IpAddress&& val, TypeTag<IpAddress>)
{
instance.PushInstance<IpAddress>("IpAddress", val);
state.PushInstance<IpAddress>("IpAddress", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Matrix4d&& val, TypeTag<Matrix4d>)
inline int LuaImplReplyVal(const LuaState& state, Matrix4d&& val, TypeTag<Matrix4d>)
{
instance.PushInstance<Matrix4d>("Matrix4", val);
state.PushInstance<Matrix4d>("Matrix4", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Matrix4f&& val, TypeTag<Matrix4f>)
inline int LuaImplReplyVal(const LuaState& state, Matrix4f&& val, TypeTag<Matrix4f>)
{
instance.PushInstance<Matrix4d>("Matrix4", val);
state.PushInstance<Matrix4d>("Matrix4", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Quaterniond&& val, TypeTag<Quaterniond>)
inline int LuaImplReplyVal(const LuaState& state, Quaterniond&& val, TypeTag<Quaterniond>)
{
instance.PushInstance<Quaterniond>("Quaternion", val);
state.PushInstance<Quaterniond>("Quaternion", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Quaternionf&& val, TypeTag<Quaternionf>)
inline int LuaImplReplyVal(const LuaState& state, Quaternionf&& val, TypeTag<Quaternionf>)
{
instance.PushInstance<Quaterniond>("Quaternion", val);
state.PushInstance<Quaterniond>("Quaternion", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Rectd&& val, TypeTag<Rectd>)
inline int LuaImplReplyVal(const LuaState& state, Rectd&& val, TypeTag<Rectd>)
{
instance.PushInstance<Rectd>("Rect", val);
state.PushInstance<Rectd>("Rect", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Rectf&& val, TypeTag<Rectf>)
inline int LuaImplReplyVal(const LuaState& state, Rectf&& val, TypeTag<Rectf>)
{
instance.PushInstance<Rectd>("Rect", val);
state.PushInstance<Rectd>("Rect", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Recti&& val, TypeTag<Recti>)
inline int LuaImplReplyVal(const LuaState& state, Recti&& val, TypeTag<Recti>)
{
instance.PushInstance<Rectd>("Rect", val);
state.PushInstance<Rectd>("Rect", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Rectui&& val, TypeTag<Rectui>)
inline int LuaImplReplyVal(const LuaState& state, Rectui&& val, TypeTag<Rectui>)
{
instance.PushInstance<Rectd>("Rect", val);
state.PushInstance<Rectd>("Rect", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2d&& val, TypeTag<Vector2d>)
inline int LuaImplReplyVal(const LuaState& state, Vector2d&& val, TypeTag<Vector2d>)
{
instance.PushInstance<Vector2d>("Vector2", val);
state.PushInstance<Vector2d>("Vector2", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2f&& val, TypeTag<Vector2f>)
inline int LuaImplReplyVal(const LuaState& state, Vector2f&& val, TypeTag<Vector2f>)
{
instance.PushInstance<Vector2d>("Vector2", val);
state.PushInstance<Vector2d>("Vector2", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2ui&& val, TypeTag<Vector2ui>)
inline int LuaImplReplyVal(const LuaState& state, Vector2ui&& val, TypeTag<Vector2ui>)
{
instance.PushInstance<Vector2d>("Vector2", val);
state.PushInstance<Vector2d>("Vector2", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3d&& val, TypeTag<Vector3d>)
inline int LuaImplReplyVal(const LuaState& state, Vector3d&& val, TypeTag<Vector3d>)
{
instance.PushInstance<Vector3d>("Vector3", val);
state.PushInstance<Vector3d>("Vector3", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3f&& val, TypeTag<Vector3f>)
inline int LuaImplReplyVal(const LuaState& state, Vector3f&& val, TypeTag<Vector3f>)
{
instance.PushInstance<Vector3d>("Vector3", val);
state.PushInstance<Vector3d>("Vector3", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3ui&& val, TypeTag<Vector3ui>)
inline int LuaImplReplyVal(const LuaState& state, Vector3ui&& val, TypeTag<Vector3ui>)
{
instance.PushInstance<Vector3d>("Vector3", val);
state.PushInstance<Vector3d>("Vector3", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Entity* ptr, TypeTag<Ndk::Entity*>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::Entity* ptr, TypeTag<Ndk::Entity*>)
{
instance.PushInstance<Ndk::EntityHandle>("Entity", ptr);
state.PushInstance<Ndk::EntityHandle>("Entity", ptr);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Application* ptr, TypeTag<Ndk::Application*>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::Application* ptr, TypeTag<Ndk::Application*>)
{
instance.PushInstance<Ndk::Application*>("Application", ptr);
state.PushInstance<Ndk::Application*>("Application", ptr);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::EntityHandle&& handle, TypeTag<Ndk::EntityHandle>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::EntityHandle&& handle, TypeTag<Ndk::EntityHandle>)
{
instance.PushInstance<Ndk::EntityHandle>("Entity", handle);
state.PushInstance<Ndk::EntityHandle>("Entity", handle);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::NodeComponentHandle&& handle, TypeTag<Ndk::NodeComponentHandle>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::NodeComponentHandle&& handle, TypeTag<Ndk::NodeComponentHandle>)
{
instance.PushInstance<Ndk::NodeComponentHandle>("NodeComponent", handle);
state.PushInstance<Ndk::NodeComponentHandle>("NodeComponent", handle);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::VelocityComponentHandle&& handle, TypeTag<Ndk::VelocityComponentHandle>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::VelocityComponentHandle&& handle, TypeTag<Ndk::VelocityComponentHandle>)
{
instance.PushInstance<Ndk::VelocityComponentHandle>("VelocityComponent", handle);
state.PushInstance<Ndk::VelocityComponentHandle>("VelocityComponent", handle);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::World* ptr, TypeTag<Ndk::World*>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::World* ptr, TypeTag<Ndk::World*>)
{
instance.PushInstance<Ndk::WorldHandle>("World", ptr);
state.PushInstance<Ndk::WorldHandle>("World", ptr);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::WorldHandle&& handle, TypeTag<Ndk::WorldHandle>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::WorldHandle&& handle, TypeTag<Ndk::WorldHandle>)
{
instance.PushInstance<Ndk::WorldHandle>("World", handle);
state.PushInstance<Ndk::WorldHandle>("World", handle);
return 1;
}
#ifndef NDK_SERVER
inline int LuaImplReplyVal(const LuaInstance& instance, MaterialRef&& handle, TypeTag<MaterialRef>)
inline int LuaImplReplyVal(const LuaState& state, MaterialRef&& handle, TypeTag<MaterialRef>)
{
instance.PushInstance<MaterialRef>("Material", handle);
state.PushInstance<MaterialRef>("Material", handle);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
inline int LuaImplReplyVal(const LuaState& state, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
{
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
state.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, SpriteRef&& handle, TypeTag<SpriteRef>)
inline int LuaImplReplyVal(const LuaState& state, SpriteRef&& handle, TypeTag<SpriteRef>)
{
instance.PushInstance<SpriteRef>("Sprite", handle);
state.PushInstance<SpriteRef>("Sprite", handle);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, TextureRef&& handle, TypeTag<TextureRef>)
inline int LuaImplReplyVal(const LuaState& state, TextureRef&& handle, TypeTag<TextureRef>)
{
instance.PushInstance<TextureRef>("Texture", handle);
state.PushInstance<TextureRef>("Texture", handle);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::CameraComponentHandle&& handle, TypeTag<Ndk::CameraComponentHandle>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::CameraComponentHandle&& handle, TypeTag<Ndk::CameraComponentHandle>)
{
instance.PushInstance<Ndk::CameraComponentHandle>("CameraComponent", handle);
state.PushInstance<Ndk::CameraComponentHandle>("CameraComponent", handle);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::ConsoleHandle&& handle, TypeTag<Ndk::ConsoleHandle>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::ConsoleHandle&& handle, TypeTag<Ndk::ConsoleHandle>)
{
instance.PushInstance<Ndk::ConsoleHandle>("Console", handle);
state.PushInstance<Ndk::ConsoleHandle>("Console", handle);
return 1;
}
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::GraphicsComponentHandle&& handle, TypeTag<Ndk::GraphicsComponentHandle>)
inline int LuaImplReplyVal(const LuaState& state, Ndk::GraphicsComponentHandle&& handle, TypeTag<Ndk::GraphicsComponentHandle>)
{
instance.PushInstance<Ndk::GraphicsComponentHandle>("GraphicsComponent", handle);
state.PushInstance<Ndk::GraphicsComponentHandle>("GraphicsComponent", handle);
return 1;
}
#endif

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -10,6 +10,7 @@
#include <NDK/Prerequesites.hpp>
#include <NDK/State.hpp>
#include <memory>
#include <vector>
namespace Ndk
{
@ -25,14 +26,21 @@ namespace Ndk
inline const std::shared_ptr<State>& GetCurrentState() const;
inline bool IsTopState(const State* state) const;
inline std::shared_ptr<State> PopState();
inline bool PopStatesUntil(std::shared_ptr<State> state);
inline void PushState(std::shared_ptr<State> state);
inline void SetState(std::shared_ptr<State> state);
inline bool Update(float elapsedTime);
inline StateMachine& operator=(StateMachine&& fsm) = default;
StateMachine& operator=(const StateMachine&) = delete;
private:
std::shared_ptr<State> m_currentState;
std::shared_ptr<State> m_nextState;
std::vector<std::shared_ptr<State>> m_states;
};
}

View File

@ -1,9 +1,8 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <Nazara/Core/Error.hpp>
#include <NDK/StateMachine.hpp>
#include <utility>
namespace Ndk
@ -11,7 +10,7 @@ namespace Ndk
/*!
* \ingroup NDK
* \class Ndk::StateMachine
* \brief NDK class that represents a state machine, to represent the multiple states of your program
* \brief NDK class that represents a state machine, to represent the multiple states of your program as a stack
*/
/*!
@ -23,61 +22,153 @@ namespace Ndk
* \remark Produces a NazaraAssert if nullptr is given
*/
inline StateMachine::StateMachine(std::shared_ptr<State> originalState) :
m_currentState(std::move(originalState))
inline StateMachine::StateMachine(std::shared_ptr<State> originalState)
{
NazaraAssert(m_currentState, "StateMachine must have a state to begin with");
m_currentState->Enter(*this);
NazaraAssert(originalState, "StateMachine must have a state to begin with");
PushState(std::move(originalState));
}
/*!
* \brief Destructs the object
*
* \remark Calls "Leave" on the state
* \remark Calls "Leave" on all the states
*/
inline StateMachine::~StateMachine()
{
m_currentState->Leave(*this);
for (std::shared_ptr<State>& state : m_states)
state->Leave(*this);
}
/*!
* \brief Changes the current state of the machine
* \brief Replaces the current state on the top of the machine
*
* \param state Next state to represent
* \param state State to replace the top one if it is nullptr, no action is performed
*/
inline void StateMachine::ChangeState(std::shared_ptr<State> state)
{
m_nextState = std::move(state);
if (state)
{
PopState();
PushState(std::move(state));
}
}
/*!
* \brief Gets the current state of the machine
* \brief Gets the current state on the top of the machine
* \return A constant reference to the state
*
* \remark The stack is supposed to be non empty, otherwise it is undefined behaviour
*
* \see PopStatesUntil
*/
inline const std::shared_ptr<State>& StateMachine::GetCurrentState() const
{
return m_currentState;
return m_states.back();
}
/*!
* \brief Updates the state
* \return True if update is successful
* \brief Checks whether the state is on the top of the machine
* \return true If it is the case
*
* \param state State to compare the top with
*/
inline bool StateMachine::IsTopState(const State* state) const
{
if (m_states.empty())
return false;
return m_states.back().get() == state;
}
/*!
* \brief Pops the state on the top of the machine
* \return Old state on the top, nullptr if stack was empty
*
* \remark This method can completely empty the stack
*/
inline std::shared_ptr<State> StateMachine::PopState()
{
if (m_states.empty())
return nullptr;
m_states.back()->Leave(*this);
std::shared_ptr<State> oldTopState = std::move(m_states.back());
m_states.pop_back();
return oldTopState;
}
/*!
* \brief Pops all the states of the machine until a specific one is reached
* \return true If that specific state is on top, false if stack is empty
*
* \param state State to find on the stack if it is nullptr, no action is performed
*
* \remark This method can completely empty the stack
*/
inline bool StateMachine::PopStatesUntil(std::shared_ptr<State> state)
{
if (!state)
return false;
while (!m_states.empty() && !IsTopState(state.get()))
PopState();
return !m_states.empty();
}
/*!
* \brief Pushes a new state on the top of the machine
*
* \param state Next state to represent if it is nullptr, it performs no action
*
* \remark Produces a NazaraAssert if the same state is pushed two times on the stack
*/
inline void StateMachine::PushState(std::shared_ptr<State> state)
{
if (state)
{
NazaraAssert(std::find(m_states.begin(), m_states.end(), state) == m_states.end(), "The same state was pushed two times");
m_states.push_back(std::move(state));
m_states.back()->Enter(*this);
}
}
/*!
* \brief Pops every states of the machine to put a new one
*
* \param state State to reset the stack with if it is nullptr, no action is performed
*/
inline void StateMachine::SetState(std::shared_ptr<State> state)
{
if (state)
{
while (!m_states.empty())
PopState();
PushState(std::move(state));
}
}
/*!
* \brief Updates all the states
* \return true If update is successful for everyone of them
*
* \param elapsedTime Delta time used for the update
*/
inline bool StateMachine::Update(float elapsedTime)
{
if (m_nextState)
{
m_currentState->Leave(*this);
m_currentState = std::move(m_nextState);
m_currentState->Enter(*this);
}
return m_currentState->Update(*this, elapsedTime);
return std::all_of(m_states.begin(), m_states.end(), [=](std::shared_ptr<State>& state) {
return state->Update(*this, elapsedTime);
});
}
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,3 +1,3 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,3 +1,3 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -57,7 +57,7 @@ namespace Ndk
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
std::vector<GraphicsComponentCullingList::VolumeEntry> m_volumeEntries;
EntityList m_cameras;
std::vector<EntityHandle> m_cameras;
EntityList m_drawables;
EntityList m_directionalLights;
EntityList m_lights;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,3 +1,3 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -27,7 +27,7 @@ namespace Ndk
//virtual ButtonWidget* Clone() const = 0;
void ResizeToContent();
void ResizeToContent() override;
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
@ -40,7 +40,6 @@ namespace Ndk
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;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -35,6 +35,7 @@ namespace Ndk
inline std::size_t GetCursorPosition() const;
inline std::size_t GetLineCount() const;
inline const Nz::String& GetText() const;
inline const Nz::Color& GetTextColor() const;
std::size_t GetHoveredGlyph(float x, float y) const;
@ -47,15 +48,24 @@ namespace Ndk
inline void SetCursorPosition(std::size_t cursorPosition);
inline void SetReadOnly(bool readOnly = true);
void SetText(const Nz::String& text);
inline void SetText(const Nz::String& text);
inline void SetTextColor(const Nz::Color& text);
void Write(const Nz::String& text);
TextAreaWidget& operator=(const TextAreaWidget&) = delete;
TextAreaWidget& operator=(TextAreaWidget&&) = default;
NazaraSignal(OnTextAreaCursorMove, const TextAreaWidget* /*textArea*/, std::size_t* /*newCursorPosition*/);
NazaraSignal(OnTextAreaKeyBackspace, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyDown, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyLeft, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyReturn, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyRight, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyUp, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
private:
void RefreshCursor();
void Layout() override;
void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key) override;
@ -65,6 +75,8 @@ namespace Ndk
void OnMouseExit() override;
void OnTextEntered(char32_t character, bool repeated) override;
void RefreshCursor();
EntityHandle m_cursorEntity;
EntityHandle m_textEntity;
Nz::SimpleTextDrawer m_drawer;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -35,6 +35,11 @@ namespace Ndk
return m_drawer.GetText();
}
inline const Nz::Color& TextAreaWidget::GetTextColor() const
{
return m_drawer.GetColor();
}
inline bool Ndk::TextAreaWidget::IsMultilineEnabled() const
{
return m_multiLineEnabled;
@ -61,6 +66,8 @@ namespace Ndk
inline void TextAreaWidget::SetCursorPosition(std::size_t cursorPosition)
{
OnTextAreaCursorMove(this, &cursorPosition);
m_cursorPosition = std::min(cursorPosition, m_drawer.GetGlyphCount());
RefreshCursor();
@ -72,4 +79,20 @@ namespace Ndk
m_cursorEntity->Enable(!m_readOnly);
}
inline void TextAreaWidget::SetText(const Nz::String& text)
{
m_drawer.SetText(text);
m_textSprite->Update(m_drawer);
SetCursorPosition(m_cursorPosition); //< Refresh cursor position (prevent it from being outside of the text)
}
inline void TextAreaWidget::SetTextColor(const Nz::Color& text)
{
m_drawer.SetColor(text);
m_textSprite->Update(m_drawer);
}
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -10,6 +10,7 @@
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <NDK/Entity.hpp>
#include <NDK/EntityList.hpp>
#include <NDK/System.hpp>
#include <algorithm>
#include <memory>
@ -28,7 +29,7 @@ namespace Ndk
friend Entity;
public:
using EntityList = std::vector<EntityHandle>;
using EntityVector = std::vector<EntityHandle>;
inline World(bool addDefaultSystems = true);
World(const World&) = delete;
@ -41,21 +42,21 @@ namespace Ndk
template<typename SystemType, typename... Args> SystemType& AddSystem(Args&&... args);
const EntityHandle& CreateEntity();
inline EntityList CreateEntities(unsigned int count);
inline EntityVector CreateEntities(unsigned int count);
void Clear() noexcept;
const EntityHandle& CloneEntity(EntityId id);
const EntityHandle& GetEntity(EntityId id);
inline const EntityList& GetEntities();
inline const EntityHandle& GetEntity(EntityId id);
inline const EntityList& GetEntities() const;
inline BaseSystem& GetSystem(SystemIndex index);
template<typename SystemType> SystemType& GetSystem();
inline bool HasSystem(SystemIndex index) const;
template<typename SystemType> bool HasSystem() const;
void KillEntity(Entity* entity);
inline void KillEntities(const EntityList& list);
inline void KillEntity(Entity* entity);
inline void KillEntities(const EntityVector& list);
inline bool IsEntityValid(const Entity* entity) const;
inline bool IsEntityIdValid(EntityId id) const;
@ -79,19 +80,22 @@ namespace Ndk
struct EntityBlock
{
EntityBlock(Entity&& e) :
entity(std::move(e))
entity(std::move(e)),
handle(&entity)
{
}
EntityBlock(EntityBlock&& block) = default;
Entity entity;
std::size_t aliveIndex;
EntityHandle handle;
};
std::vector<std::unique_ptr<BaseSystem>> m_systems;
std::vector<BaseSystem*> m_orderedSystems;
std::vector<EntityBlock> m_entities;
std::vector<EntityBlock*> m_entityBlocks;
std::vector<std::unique_ptr<EntityBlock>> m_waitingEntities;
std::vector<EntityId> m_freeIdList;
EntityList m_aliveEntities;
Nz::Bitset<Nz::UInt64> m_dirtyEntities;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -82,9 +82,9 @@ namespace Ndk
* \param count Number of entities to create
*/
inline World::EntityList World::CreateEntities(unsigned int count)
inline World::EntityVector World::CreateEntities(unsigned int count)
{
EntityList list;
EntityVector list;
list.reserve(count);
for (unsigned int i = 0; i < count; ++i)
@ -98,7 +98,7 @@ namespace Ndk
* \return A constant reference to the entities
*/
inline const World::EntityList& World::GetEntities()
inline const EntityList& World::GetEntities() const
{
return m_aliveEntities;
}
@ -164,18 +164,53 @@ namespace Ndk
return HasSystem(index);
}
/*!
* \brief Marks an entity for deletion
*
* \param Pointer to the entity
*
* \remark If the entity pointer is invalid, nothing is done
* \remark For safety, entities are not killed until the next world update
*/
inline void World::KillEntity(Entity* entity)
{
if (IsEntityValid(entity))
m_killedEntities.UnboundedSet(entity->GetId(), true);
}
/*!
* \brief Kills a set of entities
*
* This function has the same effect as calling KillEntity for every entity contained in the vector
*
* \param list Set of entities to kill
*/
inline void World::KillEntities(const EntityList& list)
inline void World::KillEntities(const EntityVector& list)
{
for (const EntityHandle& entity : list)
KillEntity(entity);
}
/*!
* \brief Gets an entity
* \return A constant reference to a handle of the entity
*
* \param id Identifier of the entity
*
* \remark Handle referenced by this function can move in memory when updating the world, do not keep a reference to a handle from a world update to another
* \remark If an invalid identifier is provided, an error got triggered and an invalid handle is returned
*/
inline const EntityHandle& World::GetEntity(EntityId id)
{
if (IsEntityIdValid(id))
return m_entityBlocks[id]->handle;
else
{
NazaraError("Invalid ID");
return EntityHandle::InvalidHandle;
}
}
/*!
* \brief Checks whether or not an entity is valid
* \return true If it is the case
@ -197,7 +232,7 @@ namespace Ndk
inline bool World::IsEntityIdValid(EntityId id) const
{
return id < m_entities.size() && m_entities[id].entity.IsValid();
return id < m_entityBlocks.size() && m_entityBlocks[id]->entity.IsValid();
}
/*!
@ -266,10 +301,12 @@ namespace Ndk
{
m_aliveEntities = std::move(world.m_aliveEntities);
m_dirtyEntities = std::move(world.m_dirtyEntities);
m_entityBlocks = std::move(world.m_entityBlocks);
m_freeIdList = std::move(world.m_freeIdList);
m_killedEntities = std::move(world.m_killedEntities);
m_orderedSystems = std::move(world.m_orderedSystems);
m_orderedSystemsUpdated = world.m_orderedSystemsUpdated;
m_waitingEntities = std::move(world.m_waitingEntities);
m_entities = std::move(world.m_entities);
for (EntityBlock& block : m_entities)
@ -284,7 +321,7 @@ namespace Ndk
inline void World::Invalidate()
{
m_dirtyEntities.Resize(m_entities.size(), false);
m_dirtyEntities.Resize(m_entityBlocks.size(), false);
m_dirtyEntities.Set(true); // Activation of all bits
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -164,25 +164,25 @@ namespace Ndk
LuaAPI::RegisterClasses(overlay->lua);
// Override "print" function to add a line in the console
overlay->lua.PushFunction([&consoleRef] (Nz::LuaInstance& instance)
overlay->lua.PushFunction([&consoleRef] (Nz::LuaState& state)
{
Nz::StringStream stream;
unsigned int argCount = instance.GetStackTop();
instance.GetGlobal("tostring");
unsigned int argCount = state.GetStackTop();
state.GetGlobal("tostring");
for (unsigned int i = 1; i <= argCount; ++i)
{
instance.PushValue(-1); // tostring function
instance.PushValue(i); // argument
instance.Call(1, 1);
state.PushValue(-1); // tostring function
state.PushValue(i); // argument
state.Call(1, 1);
std::size_t length;
const char* str = instance.CheckString(-1, &length);
const char* str = state.CheckString(-1, &length);
if (i > 1)
stream << '\t';
stream << Nz::String(str, length);
instance.Pop(1);
state.Pop(1);
}
consoleRef.AddLine(stream);

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -54,6 +54,15 @@ namespace Ndk
{
}
/*!
* \brief Operation to perform when the entity is destroyed and we're still attached to it
*
* \remark This is always called before the entity proper destruction, and thus its components.
*/
void BaseComponent::OnEntityDestruction()
{
}
std::vector<BaseComponent::ComponentEntry> BaseComponent::s_entries;
std::unordered_map<ComponentId, ComponentIndex> BaseComponent::s_idToIndex;
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -7,6 +7,7 @@
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/World.hpp>
#include <algorithm>
namespace Ndk
{
@ -20,15 +21,22 @@ namespace Ndk
m_widgetParent = parent;
m_world = m_canvas->GetWorld();
m_canvasIndex = m_canvas->RegisterWidget(this);
RegisterToCanvas();
}
BaseWidget::~BaseWidget()
{
m_canvas->UnregisterWidget(m_canvasIndex);
UnregisterFromCanvas();
}
inline void BaseWidget::EnableBackground(bool enable)
void BaseWidget::Destroy()
{
NazaraAssert(this != m_canvas, "Canvas cannot be destroyed by calling Destroy()");
m_widgetParent->DestroyChild(this); //< This does delete us
}
void BaseWidget::EnableBackground(bool enable)
{
if (m_backgroundEntity.IsValid() == enable)
return;
@ -39,7 +47,7 @@ namespace Ndk
m_backgroundSprite->SetColor(m_backgroundColor);
m_backgroundSprite->SetMaterial(Nz::Material::New((m_backgroundColor.IsOpaque()) ? "Basic2D" : "Translucent2D"));
m_backgroundEntity = m_world->CreateEntity();
m_backgroundEntity = CreateEntity();
m_backgroundEntity->AddComponent<GraphicsComponent>().Attach(m_backgroundSprite, -1);
m_backgroundEntity->AddComponent<NodeComponent>().SetParent(this);
@ -52,15 +60,61 @@ namespace Ndk
}
}
void BaseWidget::GrabKeyboard()
{
m_canvas->SetKeyboardOwner(this);
}
void BaseWidget::SetBackgroundColor(const Nz::Color& color)
{
m_backgroundColor = color;
if (m_backgroundSprite)
{
m_backgroundSprite->SetColor(color);
m_backgroundSprite->GetMaterial()->Configure((color.IsOpaque()) ? "Basic2D" : "Translucent2D"); //< Our sprite has its own material (see EnableBackground)
}
}
void BaseWidget::SetCursor(Nz::SystemCursor systemCursor)
{
m_cursor = systemCursor;
if (IsRegisteredToCanvas())
m_canvas->NotifyWidgetCursorUpdate(m_canvasIndex);
}
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)});
}
void BaseWidget::Show(bool show)
{
if (m_visible != show)
{
m_visible = show;
if (m_visible)
RegisterToCanvas();
else
UnregisterFromCanvas();
for (const EntityHandle& entity : m_entities)
entity->Enable(show);
for (const auto& widgetPtr : m_children)
widgetPtr->Show(show);
}
}
EntityHandle BaseWidget::CreateEntity()
{
m_entities.emplace_back(m_world->CreateEntity());
return m_entities.back();
EntityHandle newEntity = m_world->CreateEntity();
newEntity->Enable(m_visible);
m_entities.emplace_back(newEntity);
return newEntity;
}
void BaseWidget::DestroyEntity(Entity* entity)
@ -71,31 +125,21 @@ namespace Ndk
m_entities.erase(it);
}
void BaseWidget::GrabKeyboard()
{
m_canvas->SetKeyboardOwner(this);
}
void BaseWidget::Layout()
{
if (m_canvas)
m_canvas->NotifyWidgetUpdate(m_canvasIndex);
if (IsRegisteredToCanvas())
m_canvas->NotifyWidgetBoxUpdate(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);
if (IsRegisteredToCanvas())
m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex);
}
void BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key)
@ -126,7 +170,44 @@ namespace Ndk
{
}
void BaseWidget::OnParentResized(const Nz::Vector2f& newSize)
{
}
void BaseWidget::OnTextEntered(char32_t character, bool repeated)
{
}
void BaseWidget::DestroyChild(BaseWidget* widget)
{
auto it = std::find_if(m_children.begin(), m_children.end(), [widget] (const std::unique_ptr<BaseWidget>& widgetPtr) -> bool
{
return widgetPtr.get() == widget;
});
NazaraAssert(it != m_children.end(), "Child widget not found in parent");
m_children.erase(it);
}
void BaseWidget::DestroyChildren()
{
m_children.clear();
}
void BaseWidget::RegisterToCanvas()
{
NazaraAssert(!IsRegisteredToCanvas(), "Widget is already registered to canvas");
m_canvasIndex = m_canvas->RegisterWidget(this);
}
void BaseWidget::UnregisterFromCanvas()
{
if (IsRegisteredToCanvas())
{
m_canvas->UnregisterWidget(m_canvasIndex);
m_canvasIndex = InvalidCanvasIndex;
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -14,56 +14,38 @@ namespace Ndk
{
}
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.cursor = widget->GetCursor();
box.widget = widget;
std::size_t index = m_widgetBoxes.size();
m_widgetBoxes.emplace_back(box);
NotifyWidgetUpdate(index);
NotifyWidgetBoxUpdate(index);
return index;
}
void Canvas::UnregisterWidget(std::size_t index)
{
WidgetBox& entry = m_widgetBoxes[index];
if (m_hoveredWidget == &entry)
m_hoveredWidget = nullptr;
if (m_keyboardOwner == entry.widget)
m_keyboardOwner = nullptr;
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();
}
m_widgetBoxes.pop_back();
}
void Canvas::OnMouseButtonPressed(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::MouseButtonEvent& event)
@ -93,11 +75,12 @@ namespace Ndk
const WidgetBox* bestEntry = nullptr;
float bestEntryArea = std::numeric_limits<float>::infinity();
Nz::Vector3f mousePos(float(event.x), float(event.y), 0.f);
for (const WidgetBox& entry : m_widgetBoxes)
{
const Nz::Boxf& box = entry.box;
if (box.Contains(Nz::Vector3f(event.x, event.y, 0.f)))
if (box.Contains(mousePos))
{
float area = box.width * box.height;
if (area < bestEntryArea)
@ -117,6 +100,9 @@ namespace Ndk
m_hoveredWidget = bestEntry;
m_hoveredWidget->widget->OnMouseEnter();
if (m_cursorController)
m_cursorController->UpdateCursor(Nz::Cursor::Get(m_hoveredWidget->cursor));
}
int x = static_cast<int>(std::round(event.x - m_hoveredWidget->box.x));
@ -128,6 +114,9 @@ namespace Ndk
{
m_hoveredWidget->widget->OnMouseExit();
m_hoveredWidget = nullptr;
if (m_cursorController)
m_cursorController->UpdateCursor(Nz::Cursor::Get(Nz::SystemCursor_Default));
}
}

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
@ -93,6 +93,17 @@ namespace Ndk
return m_projectionMatrix;
}
/*!
* \brief Gets the projection type of the camera
* \return Projection type of the camera
*/
Nz::ProjectionType CameraComponent::GetProjectionType() const
{
return m_projectionType;
}
/*!
* \brief Gets the target of the camera
* \return A constant reference to the render target of the camera

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp

Some files were not shown because too many files have changed in this diff Show More