Merge branch 'master' into console-widget

This commit is contained in:
Jérôme Leclercq
2018-04-12 12:47:17 +02:00
1058 changed files with 145127 additions and 7192 deletions

View File

@@ -1,13 +1,13 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_ALGORITHM_HPP
#define NDK_ALGORITHM_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <Nazara/Core/Endianness.hpp>
@@ -21,7 +21,7 @@ namespace Ndk
static_assert(N-1 <= sizeof(ComponentId), "Name too long for this size of component id");
ComponentId componentId = 0;
for (unsigned int i = 0; i < N; ++i)
for (unsigned int i = 0; i < N - 1; ++i)
componentId |= static_cast<ComponentId>(name[i]) << i*8;
return componentId;

View File

@@ -1,20 +1,18 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_APPLICATION_HPP
#define NDK_APPLICATION_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/EntityOwner.hpp>
#include <NDK/Prerequisites.hpp>
#include <NDK/World.hpp>
#include <Nazara/Core/Clock.hpp>
#include <map>
#include <list>
#include <set>
#include <vector>
#ifndef NDK_SERVER
#include <NDK/Canvas.hpp>

View File

@@ -1,10 +1,8 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Application.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <type_traits>
#include <NDK/Sdk.hpp>
namespace Ndk

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -50,6 +50,8 @@ namespace Ndk
virtual void OnComponentDetached(BaseComponent& component);
virtual void OnDetached();
virtual void OnEntityDestruction();
virtual void OnEntityDisabled();
virtual void OnEntityEnabled();
void SetEntity(Entity* entity);

View File

@@ -1,8 +1,7 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/BaseComponent.hpp>
#include <Nazara/Core/Error.hpp>
namespace Ndk

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -8,9 +8,7 @@
#define NDK_BASESYSTEM_HPP
#include <Nazara/Core/Bitset.hpp>
#include <NDK/Entity.hpp>
#include <NDK/EntityList.hpp>
#include <vector>
namespace Ndk
{
@@ -24,28 +22,28 @@ namespace Ndk
public:
inline BaseSystem(SystemIndex systemId);
inline BaseSystem(const BaseSystem&);
BaseSystem(const BaseSystem&) = delete;
BaseSystem(BaseSystem&&) noexcept = default;
virtual ~BaseSystem();
inline void Enable(bool enable = true);
virtual std::unique_ptr<BaseSystem> Clone() const = 0;
bool Filters(const Entity* entity) const;
inline const EntityList& GetEntities() const;
inline float GetFixedUpdateRate() const;
inline SystemIndex GetIndex() const;
inline float GetMaximumUpdateRate() const;
inline int GetUpdateOrder() const;
inline float GetUpdateRate() const;
inline World& GetWorld() const;
inline bool IsEnabled() const;
inline bool HasEntity(const Entity* entity) const;
inline void SetFixedUpdateRate(float updatePerSecond);
inline void SetMaximumUpdateRate(float updatePerSecond);
void SetUpdateOrder(int updateOrder);
inline void SetUpdateRate(float updatePerSecond);
inline void Update(float elapsedTime);
@@ -93,8 +91,9 @@ namespace Ndk
SystemIndex m_systemIndex;
World* m_world;
bool m_updateEnabled;
float m_fixedUpdateRate;
float m_maxUpdateRate;
float m_updateCounter;
float m_updateRate;
int m_updateOrder;
static SystemIndex s_nextIndex;

View File

@@ -1,8 +1,7 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/BaseSystem.hpp>
#include <Nazara/Core/Error.hpp>
#include <type_traits>
@@ -20,24 +19,8 @@ namespace Ndk
m_updateEnabled(true),
m_updateOrder(0)
{
SetUpdateRate(30);
}
/*!
* \brief Constructs a BaseSystem object by copy semantic
*
* \param system System to copy
*/
inline BaseSystem::BaseSystem(const BaseSystem& system) :
m_excludedComponents(system.m_excludedComponents),
m_requiredComponents(system.m_requiredComponents),
m_systemIndex(system.m_systemIndex),
m_updateEnabled(system.m_updateEnabled),
m_updateCounter(0.f),
m_updateRate(system.m_updateRate),
m_updateOrder(system.m_updateOrder)
{
SetFixedUpdateRate(0);
SetMaximumUpdateRate(30);
}
/*!
@@ -61,6 +44,24 @@ namespace Ndk
return m_entities;
}
/*!
* \brief Gets the maximum rate of update of the system
* \return Update rate
*/
inline float BaseSystem::GetFixedUpdateRate() const
{
return (m_fixedUpdateRate > 0.f) ? 1.f / m_fixedUpdateRate : 0.f;
}
/*!
* \brief Gets the maximum rate of update of the system
* \return Update rate
*/
inline float BaseSystem::GetMaximumUpdateRate() const
{
return (m_maxUpdateRate > 0.f) ? 1.f / m_maxUpdateRate : 0.f;
}
/*!
* \brief Gets the index of the system
* \return Index of the system
@@ -82,16 +83,6 @@ namespace Ndk
return m_updateOrder;
}
/*!
* \brief Gets the rate of update of the system
* \return Update rate
*/
inline float BaseSystem::GetUpdateRate() const
{
return (m_updateRate > 0.f) ? 1.f / m_updateRate : 0.f;
}
/*!
* \brief Gets the world on which the system operate
* \return World in which the system is
@@ -125,15 +116,25 @@ namespace Ndk
}
/*!
* \brief Sets the rate of update for the system
* \brief Sets the fixed update rate for the system
*
* \param updatePerSecond Update rate, 0 means update rate is not fixed
*/
inline void BaseSystem::SetFixedUpdateRate(float updatePerSecond)
{
m_updateCounter = 0.f;
m_fixedUpdateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
}
/*!
* \brief Sets the maximum update rate for the system
*
* \param updatePerSecond Update rate, 0 means as much as possible
*/
inline void BaseSystem::SetUpdateRate(float updatePerSecond)
inline void BaseSystem::SetMaximumUpdateRate(float updatePerSecond)
{
m_updateCounter = 0.f;
m_updateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
m_maxUpdateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
}
/*!
@@ -147,18 +148,42 @@ namespace Ndk
if (!IsEnabled())
return;
if (m_updateRate > 0.f)
{
m_updateCounter += elapsedTime;
m_updateCounter += elapsedTime;
while (m_updateCounter >= m_updateRate)
if (m_maxUpdateRate > 0.f)
{
if (m_updateCounter >= m_maxUpdateRate)
{
OnUpdate(m_updateRate);
m_updateCounter -= m_updateRate;
if (m_fixedUpdateRate > 0.f)
{
while (m_updateCounter >= m_fixedUpdateRate)
{
OnUpdate(m_fixedUpdateRate);
m_updateCounter -= m_fixedUpdateRate;
}
}
else
{
float updateRate = std::max(elapsedTime, m_maxUpdateRate);
OnUpdate(updateRate);
m_updateCounter -= updateRate;
}
}
}
else
OnUpdate(elapsedTime);
{
if (m_fixedUpdateRate > 0.f)
{
while (m_updateCounter >= m_fixedUpdateRate)
{
OnUpdate(m_fixedUpdateRate);
m_updateCounter -= m_fixedUpdateRate;
}
}
else
OnUpdate(elapsedTime);
}
}
/*!

View File

@@ -1,18 +1,17 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_BASEWIDGET_HPP
#define NDK_BASEWIDGET_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
#include <NDK/Entity.hpp>
#include <NDK/EntityOwner.hpp>
#include <NDK/World.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Event.hpp>
#include <Nazara/Platform/Mouse.hpp>
#include <Nazara/Utility/Node.hpp>
@@ -38,8 +37,12 @@ namespace Ndk
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
inline void Center();
inline void CenterHorizontal();
inline void CenterVertical();
inline void Destroy();
void ClearFocus();
void Destroy();
void EnableBackground(bool enable);
@@ -53,15 +56,16 @@ namespace Ndk
inline const Nz::Vector2f& GetContentSize() const;
inline Nz::Vector2f GetSize() const;
inline bool IsVisible() const;
bool HasFocus() const;
void GrabKeyboard();
inline bool IsVisible() const;
virtual void ResizeToContent() = 0;
void SetBackgroundColor(const Nz::Color& color);
void SetCursor(Nz::SystemCursor systemCursor);
inline void SetContentSize(const Nz::Vector2f& size);
void SetFocus();
inline void SetPadding(float left, float top, float right, float bottom);
void SetSize(const Nz::Vector2f& size);
@@ -79,12 +83,16 @@ namespace Ndk
};
protected:
EntityHandle CreateEntity();
const EntityHandle& CreateEntity(bool isContentEntity);
void DestroyEntity(Entity* entity);
virtual void Layout();
void InvalidateNode() override;
virtual void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key);
virtual bool IsFocusable() const;
virtual void OnFocusLost();
virtual void OnFocusReceived();
virtual bool OnKeyPressed(const Nz::WindowEvent::KeyEvent& key);
virtual void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key);
virtual void OnMouseEnter();
virtual void OnMouseMoved(int x, int y, int deltaX, int deltaY);
@@ -104,11 +112,18 @@ namespace Ndk
void RegisterToCanvas();
inline void UpdateCanvasIndex(std::size_t index);
void UnregisterFromCanvas();
void UpdatePositionAndSize();
struct WidgetEntity
{
EntityOwner handle;
bool isContent;
};
static constexpr std::size_t InvalidCanvasIndex = std::numeric_limits<std::size_t>::max();
std::size_t m_canvasIndex;
std::vector<EntityOwner> m_entities;
std::vector<WidgetEntity> m_entities;
std::vector<std::unique_ptr<BaseWidget>> m_children;
Canvas* m_canvas;
EntityOwner m_backgroundEntity;

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/BaseWidget.hpp>
#include <Nazara/Core/Error.hpp>
@@ -46,6 +46,24 @@ namespace Ndk
SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f);
}
inline void BaseWidget::CenterHorizontal()
{
NazaraAssert(m_widgetParent, "Widget has no parent");
Nz::Vector2f parentSize = m_widgetParent->GetSize();
Nz::Vector2f mySize = GetSize();
SetPosition((parentSize.x - mySize.x) / 2.f, GetPosition(Nz::CoordSys_Local).y);
}
inline void BaseWidget::CenterVertical()
{
NazaraAssert(m_widgetParent, "Widget has no parent");
Nz::Vector2f parentSize = m_widgetParent->GetSize();
Nz::Vector2f mySize = GetSize();
SetPosition(GetPosition(Nz::CoordSys_Local).x, (parentSize.y - mySize.y) / 2.f);
}
inline const Nz::Color& BaseWidget::GetBackgroundColor() const
{
return m_backgroundColor;

View File

@@ -1,13 +1,13 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_CANVAS_HPP
#define NDK_CANVAS_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
#include <NDK/BaseWidget.hpp>
#include <Nazara/Platform/CursorController.hpp>
#include <Nazara/Platform/EventHandler.hpp>
@@ -34,12 +34,16 @@ namespace Ndk
Canvas& operator=(Canvas&&) = delete;
protected:
inline void ClearKeyboardOwner(std::size_t canvasIndex);
inline bool IsKeyboardOwner(std::size_t canvasIndex) const;
inline void NotifyWidgetBoxUpdate(std::size_t index);
inline void NotifyWidgetCursorUpdate(std::size_t index);
std::size_t RegisterWidget(BaseWidget* widget);
inline void SetKeyboardOwner(BaseWidget* widget);
inline void SetKeyboardOwner(std::size_t canvasIndex);
void UnregisterWidget(std::size_t index);
@@ -52,7 +56,7 @@ namespace Ndk
void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
struct WidgetBox
struct WidgetEntry
{
BaseWidget* widget;
Nz::Boxf box;
@@ -67,10 +71,10 @@ namespace Ndk
NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot);
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
std::vector<WidgetBox> m_widgetBoxes;
std::size_t m_keyboardOwner;
std::size_t m_hoveredWidget;
std::vector<WidgetEntry> m_widgetEntries;
Nz::CursorControllerHandle m_cursorController;
const WidgetBox* m_hoveredWidget;
BaseWidget* m_keyboardOwner;
WorldHandle m_world;
};
}

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Canvas.hpp>
#include <Nazara/Platform/Cursor.hpp>
@@ -8,9 +8,9 @@
namespace Ndk
{
inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController) :
m_keyboardOwner(InvalidCanvasIndex),
m_hoveredWidget(InvalidCanvasIndex),
m_cursorController(cursorController),
m_hoveredWidget(nullptr),
m_keyboardOwner(nullptr),
m_world(std::move(world))
{
m_canvas = this;
@@ -46,27 +46,47 @@ namespace Ndk
return m_world;
}
inline void Canvas::ClearKeyboardOwner(std::size_t canvasIndex)
{
if (m_keyboardOwner == canvasIndex)
SetKeyboardOwner(InvalidCanvasIndex);
}
inline bool Canvas::IsKeyboardOwner(std::size_t canvasIndex) const
{
return m_keyboardOwner == canvasIndex;
}
inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index)
{
WidgetBox& entry = m_widgetBoxes[index];
WidgetEntry& entry = m_widgetEntries[index];
Nz::Vector3f pos = entry.widget->GetPosition();
Nz::Vector2f size = entry.widget->GetContentSize();
Nz::Vector2f size = entry.widget->GetSize();
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];
WidgetEntry& entry = m_widgetEntries[index];
entry.cursor = entry.widget->GetCursor();
if (m_cursorController && m_hoveredWidget == &entry)
if (m_cursorController && m_hoveredWidget == index)
m_cursorController->UpdateCursor(Nz::Cursor::Get(entry.cursor));
}
inline void Ndk::Canvas::SetKeyboardOwner(BaseWidget* widget)
inline void Canvas::SetKeyboardOwner(std::size_t canvasIndex)
{
m_keyboardOwner = widget;
if (m_keyboardOwner != canvasIndex)
{
if (m_keyboardOwner != InvalidCanvasIndex)
m_widgetEntries[m_keyboardOwner].widget->OnFocusLost();
m_keyboardOwner = canvasIndex;
if (m_keyboardOwner != InvalidCanvasIndex)
m_widgetEntries[m_keyboardOwner].widget->OnFocusReceived();
}
}
}

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Algorithm.hpp>
#include <type_traits>

View File

@@ -17,5 +17,6 @@
#include <NDK/Components/PhysicsComponent2D.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Components/VelocityComponent.hpp>
#include <NDK/Components/ConstraintComponent2D.hpp>
#endif // NDK_COMPONENTS_GLOBAL_HPP

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -19,7 +19,6 @@
namespace Ndk
{
class CameraComponent;
class Entity;
using CameraComponentHandle = Nz::ObjectHandle<CameraComponent>;

View File

@@ -1,8 +1,7 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Components/CameraComponent.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Algorithm.hpp>
@@ -238,10 +237,9 @@ namespace Ndk
NazaraAssert(m_target, "Component has no render target");
// We compute the region necessary to make this view port with the actual size of the target
float invWidth = 1.f / m_target->GetWidth();
float invHeight = 1.f / m_target->GetHeight();
Nz::Vector2f invSize = 1.f / Nz::Vector2f(m_target->GetSize());
SetTargetRegion(Nz::Rectf(invWidth * viewport.x, invHeight * viewport.y, invWidth * viewport.width, invHeight * viewport.height));
SetTargetRegion(Nz::Rectf(invSize.x * viewport.x, invSize.y * viewport.y, invSize.x * viewport.width, invSize.y * viewport.height));
}
/*!

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -8,21 +8,16 @@
#define NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP
#include <Nazara/Physics2D/Collider2D.hpp>
#include <Nazara/Physics2D/RigidBody2D.hpp>
#include <NDK/Component.hpp>
#include <memory>
namespace Nz
{
class RigidBody2D;
}
namespace Ndk
{
class Entity;
class NDK_API CollisionComponent2D : public Component<CollisionComponent2D>
{
friend class PhysicsSystem2D;
friend class ConstraintComponent2D;
public:
CollisionComponent2D(Nz::Collider2DRef geom = Nz::Collider2DRef());

View File

@@ -1,12 +1,6 @@
// 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/Components/CollisionComponent2D.hpp>
#include <NDK/Entity.hpp>
#include <NDK/World.hpp>
#include <NDK/Components/PhysicsComponent2D.hpp>
#include <NDK/Systems/PhysicsSystem2D.hpp>
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -8,18 +8,12 @@
#define NDK_COMPONENTS_COLLISIONCOMPONENT3D_HPP
#include <Nazara/Physics3D/Collider3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NDK/Component.hpp>
#include <memory>
namespace Nz
{
class RigidBody3D;
}
namespace Ndk
{
class Entity;
class NDK_API CollisionComponent3D : public Component<CollisionComponent3D>
{
friend class PhysicsSystem3D;
@@ -46,6 +40,8 @@ namespace Ndk
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
void OnEntityDisabled() override;
void OnEntityEnabled() override;
std::unique_ptr<Nz::RigidBody3D> m_staticBody;
Nz::Collider3DRef m_geom;

View File

@@ -1,11 +1,6 @@
// 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/Entity.hpp>
#include <NDK/World.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -0,0 +1,34 @@
#pragma once
#ifndef NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP
#define NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP
#include <NDK/Component.hpp>
#include <Nazara/Physics2D/Constraint2D.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <vector>
#include <memory>
namespace Ndk
{
class NDK_API ConstraintComponent2D : public Component<ConstraintComponent2D>
{
public:
ConstraintComponent2D() = default;
ConstraintComponent2D(const ConstraintComponent2D& joint) = default;
ConstraintComponent2D(ConstraintComponent2D&& joint) = default;
template<typename T, typename... Args> inline Nz::ObjectRef<T> CreateConstraint(const Ndk::EntityHandle& first, const Ndk::EntityHandle& second, Args&&... args);
static ComponentIndex componentIndex;
private:
std::vector<Nz::Constraint2DRef> m_constraints;
};
}
#include <NDK/Components/ConstraintComponent2D.inl>
#endif// NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP

View File

@@ -0,0 +1,31 @@
#include <NDK/Components/ConstraintComponent2D.hpp>
#include <NDK/Components/PhysicsComponent2D.hpp>
#include <NDK/Components/CollisionComponent2D.hpp>
namespace Ndk
{
template<typename T, typename ...Args>
Nz::ObjectRef<T> ConstraintComponent2D::CreateConstraint(const Ndk::EntityHandle& first, const Ndk::EntityHandle& second, Args && ...args)
{
auto FetchBody = [](const Ndk::EntityHandle& entity) -> Nz::RigidBody2D*
{
if (entity->HasComponent<Ndk::PhysicsComponent2D>())
return entity->GetComponent<Ndk::PhysicsComponent2D>().GetRigidBody();
else if (entity->HasComponent<Ndk::CollisionComponent2D>())
return entity->GetComponent<Ndk::CollisionComponent2D>().GetStaticBody();
return nullptr;
};
Nz::RigidBody2D* firstBody = FetchBody(first);
NazaraAssert(firstBody, "First entity has no CollisionComponent2D nor PhysicsComponent2D component");
Nz::RigidBody2D* secondBody = FetchBody(second);
NazaraAssert(secondBody, "Second entity has no CollisionComponent2D nor PhysicsComponent2D component");
Nz::ObjectRef<T> constraint = T::New(*firstBody, *secondBody, std::forward<Args>(args)...);
m_constraints.push_back(constraint);
return constraint;
}
}

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -12,6 +12,7 @@
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Utility/Node.hpp>
#include <NDK/Component.hpp>
#include <unordered_map>
namespace Ndk
{
@@ -27,20 +28,22 @@ namespace Ndk
public:
using RenderableList = std::vector<Nz::InstancedRenderableRef>;
GraphicsComponent() = default;
GraphicsComponent();
inline GraphicsComponent(const GraphicsComponent& graphicsComponent);
~GraphicsComponent() = default;
inline void AddToCullingList(GraphicsComponentCullingList* cullingList) const;
void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const;
void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
void Attach(Nz::InstancedRenderableRef renderable, const Nz::Matrix4f& localMatrix, int renderOrder = 0);
inline void Clear();
inline void Detach(const Nz::InstancedRenderable* renderable);
inline bool DoesRequireRealTimeReflections() const;
inline void EnsureBoundingVolumeUpdate() const;
inline void EnsureTransformMatrixUpdate() const;
@@ -51,28 +54,51 @@ namespace Ndk
inline void RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const;
inline void SetScissorRect(const Nz::Recti& scissorRect);
inline void UpdateLocalMatrix(const Nz::InstancedRenderable* instancedRenderable, const Nz::Matrix4f& localMatrix);
inline void UpdateRenderOrder(const Nz::InstancedRenderable* instancedRenderable, int renderOrder);
static ComponentIndex componentIndex;
private:
struct Renderable;
void ConnectInstancedRenderableSignals(Renderable& renderable);
inline void InvalidateBoundingVolume() const;
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index);
void InvalidateRenderableMaterial(const Nz::InstancedRenderable* renderable, std::size_t skinIndex, std::size_t matIndex, const Nz::MaterialRef& newMat);
inline void InvalidateRenderables();
void InvalidateReflectionMap();
inline void InvalidateTransformMatrix();
void RegisterMaterial(Nz::Material* material, std::size_t count = 1);
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
void OnInstancedRenderableResetMaterials(const Nz::InstancedRenderable* renderable, std::size_t newMaterialCount);
void OnInstancedRenderableSkinChange(const Nz::InstancedRenderable* renderable, std::size_t newSkinIndex);
void OnMaterialReflectionChange(const Nz::Material* material, Nz::ReflectionMode reflectionMode);
void OnNodeInvalidated(const Nz::Node* node);
void UnregisterMaterial(Nz::Material* material);
void UpdateBoundingVolume() const;
void UpdateTransformMatrix() const;
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
struct MaterialEntry
{
NazaraSlot(Nz::Material, OnMaterialReflectionModeChange, reflectionModelChangeSlot);
std::size_t renderableCounter;
};
struct Renderable
{
Renderable(const Nz::Matrix4f& transformMatrix) :
@@ -81,15 +107,8 @@ namespace Ndk
{
}
Renderable(Renderable&& rhs) noexcept :
renderableBoundingVolumeInvalidationSlot(std::move(rhs.renderableBoundingVolumeInvalidationSlot)),
renderableDataInvalidationSlot(std::move(rhs.renderableDataInvalidationSlot)),
renderableReleaseSlot(std::move(rhs.renderableReleaseSlot)),
data(std::move(rhs.data)),
renderable(std::move(rhs.renderable)),
dataUpdated(rhs.dataUpdated)
{
}
Renderable(const Renderable&) = delete;
Renderable(Renderable&& rhs) noexcept = default;
~Renderable()
{
@@ -97,21 +116,15 @@ namespace Ndk
renderableReleaseSlot.Disconnect();
}
Renderable& operator=(Renderable&& r) noexcept
{
data = std::move(r.data);
dataUpdated = r.dataUpdated;
renderable = std::move(r.renderable);
renderableBoundingVolumeInvalidationSlot = std::move(r.renderableBoundingVolumeInvalidationSlot);
renderableDataInvalidationSlot = std::move(r.renderableDataInvalidationSlot);
renderableReleaseSlot = std::move(r.renderableReleaseSlot);
return *this;
}
Renderable& operator=(const Renderable&) = delete;
Renderable& operator=(Renderable&& r) noexcept = default;
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateBoundingVolume, renderableBoundingVolumeInvalidationSlot);
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateData, renderableDataInvalidationSlot);
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateMaterial, renderableMaterialInvalidationSlot);
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableRelease, renderableReleaseSlot);
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableResetMaterials, renderableResetMaterialsSlot);
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableSkinChange, renderableSkinChangeSlot);
mutable Nz::InstancedRenderable::InstanceData data;
Nz::InstancedRenderableRef renderable;
@@ -127,12 +140,17 @@ namespace Ndk
NazaraSlot(GraphicsComponentCullingList, OnCullingListRelease, cullingListReleaseSlot);
};
std::size_t m_reflectiveMaterialCount;
mutable std::vector<VolumeCullingEntry> m_volumeCullingEntries;
std::vector<Renderable> m_renderables;
std::unordered_map<const Nz::Material*, MaterialEntry> m_materialEntries;
mutable Nz::BoundingVolumef m_boundingVolume;
mutable Nz::Matrix4f m_transformMatrix;
Nz::Recti m_scissorRect;
Nz::TextureRef m_reflectionMap;
mutable bool m_boundingVolumeUpdated;
mutable bool m_transformMatrixUpdated;
unsigned int m_reflectionMapSize;
};
}

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/World.hpp>
@@ -9,12 +9,16 @@
namespace Ndk
{
inline GraphicsComponent::GraphicsComponent() :
m_scissorRect(-1, -1)
{
}
/*!
* \brief Constructs a GraphicsComponent object by copy semantic
*
* \param graphicsComponent GraphicsComponent to copy
*/
inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) :
Component(graphicsComponent),
HandledObject(graphicsComponent),
@@ -25,7 +29,7 @@ namespace Ndk
{
m_renderables.reserve(graphicsComponent.m_renderables.size());
for (const Renderable& r : graphicsComponent.m_renderables)
Attach(r.renderable, r.data.renderOrder);
Attach(r.renderable, r.data.localMatrix, r.data.renderOrder);
}
inline void GraphicsComponent::AddToCullingList(GraphicsComponentCullingList* cullingList) const
@@ -38,14 +42,32 @@ namespace Ndk
InvalidateBoundingVolume();
}
/*!
* \brief Attaches a renderable to the entity
*
* \param renderable Reference to a renderable element
* \param renderOrder Render order of the element
*/
inline void GraphicsComponent::Attach(Nz::InstancedRenderableRef renderable, int renderOrder)
{
return Attach(std::move(renderable), Nz::Matrix4f::Identity(), renderOrder);
}
/*!
* \brief Clears every renderable elements
*/
inline void GraphicsComponent::Clear()
{
m_materialEntries.clear();
m_renderables.clear();
if (m_reflectiveMaterialCount > 0)
{
m_reflectiveMaterialCount = 0;
InvalidateReflectionMap();
}
InvalidateBoundingVolume();
}
@@ -62,12 +84,29 @@ namespace Ndk
if (it->renderable == renderable)
{
InvalidateBoundingVolume();
std::size_t materialCount = renderable->GetMaterialCount();
for (std::size_t i = 0; i < materialCount; ++i)
UnregisterMaterial(renderable->GetMaterial(i));
m_renderables.erase(it);
break;
}
}
}
/*!
* \brief Checks if this graphics component requires real-time reflections to be generated
*
* If any of the materials attached to a GraphicsComponent (via the attached instanced renderable) needs real-time reflections, this function will return true.
*
* \return True if real-time reflections needs to be generated or false
*/
inline bool GraphicsComponent::DoesRequireRealTimeReflections() const
{
return m_reflectiveMaterialCount != 0 && m_reflectionMap;
}
/*!
* \brief Ensures the bounding volume is up to date
*/
@@ -142,6 +181,14 @@ namespace Ndk
}
}
inline void GraphicsComponent::SetScissorRect(const Nz::Recti& scissorRect)
{
m_scissorRect = scissorRect;
for (VolumeCullingEntry& entry : m_volumeCullingEntries)
entry.listEntry.ForceInvalidation(); //< Invalidate render queues
}
inline void GraphicsComponent::UpdateLocalMatrix(const Nz::InstancedRenderable* instancedRenderable, const Nz::Matrix4f& localMatrix)
{
for (auto& renderable : m_renderables)
@@ -198,4 +245,4 @@ namespace Ndk
InvalidateBoundingVolume();
InvalidateRenderables();
}
}
}

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <Nazara/Core/Error.hpp>
#include <NDK/Entity.hpp>

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -9,7 +9,6 @@
#define NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
#include <Nazara/Graphics/ParticleEmitter.hpp>
#include <Nazara/Graphics/ParticleGroup.hpp>
#include <NDK/Component.hpp>
namespace Ndk

View File

@@ -1,8 +1,6 @@
// 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/Components/ParticleEmitterComponent.hpp>
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,8 +1,7 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Components/ParticleGroupComponent.hpp>
#include <NDK/Components/ParticleEmitterComponent.hpp>
#include <Nazara/Core/Error.hpp>
@@ -50,7 +49,7 @@ namespace Ndk
inline void ParticleGroupComponent::AddEmitter(Entity* emitter)
{
NazaraAssert(emitter && emitter->IsValid(), "Invalid entity");
NazaraAssert(emitter->HasComponent<ParticleEmitterComponent>(), "Entity must have a NodeComponent");
NazaraAssert(emitter->HasComponent<ParticleEmitterComponent>(), "Entity must have a ParticleEmitterComponent");
auto& emitterComponent = emitter->GetComponent<ParticleEmitterComponent>();
ParticleGroup::AddEmitter(&emitterComponent);
@@ -69,7 +68,7 @@ namespace Ndk
inline void ParticleGroupComponent::RemoveEmitter(Entity* emitter)
{
NazaraAssert(emitter && emitter->IsValid(), "Invalid entity");
NazaraAssert(emitter->HasComponent<ParticleEmitterComponent>(), "Entity must have a NodeComponent");
NazaraAssert(emitter->HasComponent<ParticleEmitterComponent>(), "Entity must have a ParticleEmitterComponent");
auto& emitterComponent = emitter->GetComponent<ParticleEmitterComponent>();
ParticleGroup::RemoveEmitter(&emitterComponent);

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -13,20 +13,21 @@
namespace Ndk
{
class Entity;
class NDK_API PhysicsComponent2D : public Component<PhysicsComponent2D>
{
friend class CollisionComponent2D;
friend class PhysicsSystem2D;
friend class ConstraintComponent2D;
public:
PhysicsComponent2D() = default;
PhysicsComponent2D(const PhysicsComponent2D& physics);
~PhysicsComponent2D() = default;
void AddForce(const Nz::Vector2f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddForce(const Nz::Vector2f& force, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddImpulse(const Nz::Vector2f& impulse, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddImpulse(const Nz::Vector2f& impulse, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddTorque(float torque);
Nz::Rectf GetAABB() const;
@@ -49,7 +50,7 @@ namespace Ndk
static ComponentIndex componentIndex;
private:
Nz::RigidBody2D& GetRigidBody();
Nz::RigidBody2D* GetRigidBody();
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;

View File

@@ -1,9 +1,8 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <Nazara/Core/Error.hpp>
#include "PhysicsComponent2D.hpp"
namespace Ndk
{
@@ -51,7 +50,38 @@ namespace Ndk
m_object->AddForce(force, point, coordSys);
}
/*!
* \brief Applies a impulse to the entity
*
* \param impulse Impulse to apply on the entity
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::AddImpulse(const Nz::Vector2f& impulse, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->AddImpulse(impulse, coordSys);
}
/*!
* \brief Applies a impulse to the entity
*
* \param impulse Impulse to apply on the entity
* \param point Point where the impulse is applied
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::AddImpulse(const Nz::Vector2f& impulse, const Nz::Vector2f& point, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->AddImpulse(impulse, point, coordSys);
}
/*!
* \brief Applies a torque to the entity
*
@@ -277,8 +307,8 @@ namespace Ndk
* \return A reference to the physics object
*/
inline Nz::RigidBody2D& PhysicsComponent2D::GetRigidBody()
inline Nz::RigidBody2D* PhysicsComponent2D::GetRigidBody()
{
return *m_object.get();
return m_object.get();
}
}

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -13,15 +13,13 @@
namespace Ndk
{
class Entity;
class NDK_API PhysicsComponent3D : public Component<PhysicsComponent3D>
{
friend class CollisionComponent3D;
friend class PhysicsSystem3D;
public:
PhysicsComponent3D() = default;
inline PhysicsComponent3D();
PhysicsComponent3D(const PhysicsComponent3D& physics);
~PhysicsComponent3D() = default;
@@ -30,41 +28,67 @@ namespace Ndk
void AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void EnableAutoSleep(bool autoSleep);
void EnableNodeSynchronization(bool nodeSynchronization);
Nz::Boxf GetAABB() const;
Nz::Vector3f GetAngularDamping() const;
Nz::Vector3f GetAngularVelocity() const;
float GetGravityFactor() const;
float GetLinearDamping() const;
Nz::Vector3f GetLinearVelocity() const;
float GetMass() const;
Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
const Nz::Matrix4f& GetMatrix() const;
Nz::Vector3f GetPosition() const;
Nz::Quaternionf GetRotation() const;
Nz::Vector3f GetVelocity() const;
bool IsAutoSleepEnabled() const;
bool IsMoveable() const;
bool IsNodeSynchronizationEnabled() const;
bool IsSleeping() const;
void SetAngularDamping(const Nz::Vector3f& angularDamping);
void SetAngularVelocity(const Nz::Vector3f& angularVelocity);
void SetGravityFactor(float gravityFactor);
void SetLinearDamping(float damping);
void SetLinearVelocity(const Nz::Vector3f& velocity);
void SetMass(float mass);
void SetMassCenter(const Nz::Vector3f& center);
void SetMaterial(const Nz::String& materialName);
void SetMaterial(int materialIndex);
void SetPosition(const Nz::Vector3f& position);
void SetRotation(const Nz::Quaternionf& rotation);
void SetVelocity(const Nz::Vector3f& velocity);
static ComponentIndex componentIndex;
private:
Nz::RigidBody3D& GetRigidBody();
void ApplyPhysicsState(Nz::RigidBody3D& rigidBody) const;
void CopyPhysicsState(const Nz::RigidBody3D& rigidBody);
Nz::RigidBody3D* GetRigidBody();
const Nz::RigidBody3D& GetRigidBody() const;
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
void OnEntityDestruction() override;
void OnEntityDisabled() override;
void OnEntityEnabled() override;
struct PendingPhysObjectStates
{
Nz::Vector3f angularDamping;
Nz::Vector3f massCenter;
bool autoSleep;
bool valid = false;
float gravityFactor;
float linearDamping;
float mass;
};
std::unique_ptr<Nz::RigidBody3D> m_object;
PendingPhysObjectStates m_pendingStates;
bool m_nodeSynchronizationEnabled;
};
}

View File

@@ -1,21 +1,27 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <Nazara/Core/Error.hpp>
#include "PhysicsComponent3D.hpp"
namespace Ndk
{
inline PhysicsComponent3D::PhysicsComponent3D() :
m_nodeSynchronizationEnabled(true)
{
}
/*!
* \brief Constructs a PhysicsComponent3D object by copy semantic
*
* \param physics PhysicsComponent3D to copy
*/
inline PhysicsComponent3D::PhysicsComponent3D(const PhysicsComponent3D& physics)
inline PhysicsComponent3D::PhysicsComponent3D(const PhysicsComponent3D& physics) :
m_nodeSynchronizationEnabled(physics.m_nodeSynchronizationEnabled)
{
// No copy of physical object (because we only create it when attached to an entity)
NazaraUnused(physics);
// We can't make a copy of the RigidBody3D, as we are not attached yet (and will possibly be attached to another world)
CopyPhysicsState(physics.GetRigidBody());
}
/*!
@@ -74,7 +80,6 @@ namespace Ndk
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::EnableAutoSleep(bool autoSleep)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -82,13 +87,28 @@ namespace Ndk
m_object->EnableAutoSleep(autoSleep);
}
/*!
* \brief Enables position/rotation synchronization with the NodeComponent
*
* By default, at every update of the PhysicsSystem3D, the NodeComponent's position and rotation (if any) will be synchronized with
* the values of the PhysicsComponent3D. This function allows to enable/disable this behavior on a per-entity basis.
*
* \param nodeSynchronization Should synchronization occur between NodeComponent and PhysicsComponent3D
*/
inline void PhysicsComponent3D::EnableNodeSynchronization(bool nodeSynchronization)
{
m_nodeSynchronizationEnabled = nodeSynchronization;
if (m_entity)
m_entity->Invalidate();
}
/*!
* \brief Gets the AABB of the physics object
* \return AABB of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Boxf PhysicsComponent3D::GetAABB() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -96,13 +116,23 @@ namespace Ndk
return m_object->GetAABB();
}
/*!
* \brief Gets the angular damping of the physics object
* \return Angular damping of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent3D::GetAngularDamping() const
{
return m_object->GetAngularDamping();
}
/*!
* \brief Gets the angular velocity of the physics object
* \return Angular velocity of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent3D::GetAngularVelocity() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -116,7 +146,6 @@ namespace Ndk
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent3D::GetGravityFactor() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -124,6 +153,33 @@ namespace Ndk
return m_object->GetGravityFactor();
}
/*!
* \brief Gets the linear damping of the physics object
* \return Linear damping of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent3D::GetLinearDamping() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetLinearDamping();
}
/*!
* \brief Gets the linear velocity of the physics object
* \return Linear velocity of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent3D::GetLinearVelocity() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetLinearVelocity();
}
/*!
* \brief Gets the mass of the physics object
* \return Mass of the object
@@ -142,7 +198,7 @@ namespace Ndk
* \brief Gets the gravity center of the physics object
* \return Gravity center of the object
*
* \param coordSys System coordinates to consider
* \param coordSys System coordinates to consider
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
@@ -196,27 +252,12 @@ namespace Ndk
return m_object->GetRotation();
}
/*!
* \brief Gets the velocity of the physics object
* \return Velocity of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent3D::GetVelocity() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetVelocity();
}
/*!
* \brief Checks whether the auto sleep is enabled
* \return true If it is the case
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline bool PhysicsComponent3D::IsAutoSleepEnabled() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -224,13 +265,36 @@ namespace Ndk
return m_object->IsAutoSleepEnabled();
}
/*!
* \brief Checks whether the object is moveable
* \return true If it is the case
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline bool PhysicsComponent3D::IsMoveable() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->IsMoveable();
}
/*!
* \brief Checks if position & rotation are synchronized with NodeComponent
* \return true If synchronization is enabled
*
* \see EnableNodeSynchronization
*/
inline bool PhysicsComponent3D::IsNodeSynchronizationEnabled() const
{
return m_nodeSynchronizationEnabled;
}
/*!
* \brief Checks whether the entity is currently sleeping
* \return true If it is the case
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline bool PhysicsComponent3D::IsSleeping() const
{
NazaraAssert(m_object, "Invalid physics object");
@@ -238,6 +302,20 @@ namespace Ndk
return m_object->IsSleeping();
}
/*!
* \brief Sets the angular damping of the physics object
*
* \param angularDamping Angular damping of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetAngularDamping(const Nz::Vector3f& angularDamping)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetAngularDamping(angularDamping);
}
/*!
* \brief Sets the angular velocity of the physics object
*
@@ -245,7 +323,6 @@ namespace Ndk
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetAngularVelocity(const Nz::Vector3f& angularVelocity)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -260,7 +337,6 @@ namespace Ndk
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetGravityFactor(float gravityFactor)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -268,6 +344,34 @@ namespace Ndk
m_object->SetGravityFactor(gravityFactor);
}
/*!
* \brief Sets the linear damping of the physics object
*
* \param damping Linear damping of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetLinearDamping(float damping)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetLinearDamping(damping);
}
/*!
* \brief Sets the linear velocity of the physics object
*
* \param velocity New linear velocity of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetLinearVelocity(const Nz::Vector3f& velocity)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetLinearVelocity(velocity);
}
/*!
* \brief Sets the mass of the physics object
*
@@ -276,11 +380,11 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
* \remark Produces a NazaraAssert if the mass is negative
*/
inline void PhysicsComponent3D::SetMass(float mass)
{
NazaraAssert(m_object, "Invalid physics object");
NazaraAssert(mass > 0.f, "Mass should be positive");
NazaraAssert(mass >= 0.f, "Mass must be positive and finite");
NazaraAssert(std::isfinite(mass), "Mass must be positive and finite");
m_object->SetMass(mass);
}
@@ -292,7 +396,6 @@ namespace Ndk
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetMassCenter(const Nz::Vector3f& center)
{
NazaraAssert(m_object, "Invalid physics object");
@@ -300,6 +403,34 @@ namespace Ndk
m_object->SetMassCenter(center);
}
/*!
* \brief Sets the material of the object, affecting how object does respond to collisions
*
* \param materialName Name of the material, previously registered to physics world
*
* \remark materialName must exists in PhysWorld before this call
*/
inline void PhysicsComponent3D::SetMaterial(const Nz::String& materialName)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetMaterial(materialName);
}
/*!
* \brief Sets the material of the object, affecting how object does respond to collisions
*
* \param materialIndex Id of the material, previously retrieved from a physics world
*
* \remark materialIndex must come from a call to in PhysWorld::CreateMaterial
*/
inline void PhysicsComponent3D::SetMaterial(int materialIndex)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetMaterial(materialIndex);
}
/*!
* \brief Sets the position of the physics object
*
@@ -330,27 +461,43 @@ namespace Ndk
m_object->SetRotation(rotation);
}
/*!
* \brief Sets the velocity of the physics object
*
* \param velocity Velocity of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetVelocity(const Nz::Vector3f& velocity)
inline void PhysicsComponent3D::ApplyPhysicsState(Nz::RigidBody3D& rigidBody) const
{
NazaraAssert(m_object, "Invalid physics object");
assert(m_pendingStates.valid);
m_object->SetVelocity(velocity);
rigidBody.EnableAutoSleep(m_pendingStates.autoSleep);
rigidBody.SetAngularDamping(m_pendingStates.angularDamping);
rigidBody.SetGravityFactor(m_pendingStates.gravityFactor);
rigidBody.SetLinearDamping(m_pendingStates.linearDamping);
rigidBody.SetMass(m_pendingStates.mass);
rigidBody.SetMassCenter(m_pendingStates.massCenter);
}
inline void PhysicsComponent3D::CopyPhysicsState(const Nz::RigidBody3D& rigidBody)
{
m_pendingStates.autoSleep = rigidBody.IsAutoSleepEnabled();
m_pendingStates.angularDamping = rigidBody.GetAngularDamping();
m_pendingStates.gravityFactor = rigidBody.GetGravityFactor();
m_pendingStates.linearDamping = rigidBody.GetLinearDamping();
m_pendingStates.mass = rigidBody.GetMass();
m_pendingStates.massCenter = rigidBody.GetMassCenter(Nz::CoordSys_Local);
m_pendingStates.valid = true;
}
/*!
* \brief Gets the underlying physics object
* \return A reference to the physics object
*/
inline Nz::RigidBody3D* PhysicsComponent3D::GetRigidBody()
{
return m_object.get();
}
inline Nz::RigidBody3D& PhysicsComponent3D::GetRigidBody()
/*!
* \brief Gets the underlying physics object
* \return A reference to the physics object
*/
inline const Nz::RigidBody3D& PhysicsComponent3D::GetRigidBody() const
{
return *m_object.get();
}

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,9 +1,6 @@
// 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/Entity.hpp>
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -12,7 +12,6 @@
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Platform/Event.hpp>
#include <Nazara/Utility/Node.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <NDK/BaseWidget.hpp>
@@ -21,6 +20,7 @@
namespace Nz
{
class LuaState;
struct WindowEvent;
}
namespace Ndk

View File

@@ -1,9 +1,6 @@
// 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 "Console.hpp"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -11,6 +11,7 @@
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/Signal.hpp>
#include <NDK/Algorithm.hpp>
#include <NDK/Prerequisites.hpp>
#include <memory>
#include <vector>
@@ -40,7 +41,8 @@ namespace Ndk
const EntityHandle& Clone() const;
inline void Enable(bool enable = true);
inline void Disable();
void Enable(bool enable = true);
inline BaseComponent& GetComponent(ComponentIndex index);
template<typename ComponentType> ComponentType& GetComponent();

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Entity.hpp>
#include <Nazara/Core/Error.hpp>
@@ -8,7 +8,6 @@
#include <algorithm>
#include <cassert>
#include <type_traits>
#include <utility>
namespace Ndk
{
@@ -30,18 +29,13 @@ namespace Ndk
}
/*!
* \brief Enables the entity
* \brief Disables the entity
*
* \param enable Should the entity be enabled
* This is just a shortcut to Enable(false)
*/
inline void Entity::Enable(bool enable)
inline void Entity::Disable()
{
if (m_enabled != enable)
{
m_enabled = enable;
Invalidate();
}
Enable(false);
}
/*!
@@ -325,4 +319,4 @@ namespace std
return hash<Ndk::EntityId>()(id);
}
};
}
}

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -8,7 +8,7 @@
#define NDK_ENTITYLIST_HPP
#include <Nazara/Core/Bitset.hpp>
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
#include <NDK/Entity.hpp>
namespace Ndk
@@ -35,6 +35,7 @@ namespace Ndk
inline void Insert(Entity* entity);
inline void Remove(Entity* entity);
inline void Reserve(std::size_t entityCount);
// STL API
inline iterator begin() const;

View File

@@ -1,8 +1,7 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/EntityList.hpp>
#include <Nazara/Core/Error.hpp>
#include <algorithm>
@@ -137,6 +136,16 @@ namespace Ndk
}
}
/*!
* \brief Reserves enough space to contains entityCount entities
*
* \param entityCount Number of entities to reserve
*/
inline void EntityList::Reserve(std::size_t entityCount)
{
m_entityBits.Reserve(entityCount);
}
// STL Interface
inline EntityList::iterator EntityList::begin() const
{
@@ -160,6 +169,9 @@ namespace Ndk
inline EntityList& EntityList::operator=(const EntityList& entityList)
{
for (const Ndk::EntityHandle& entity : *this)
entity->UnregisterEntityList(this);
m_entityBits = entityList.m_entityBits;
m_world = entityList.m_world;
@@ -171,6 +183,12 @@ namespace Ndk
inline EntityList& EntityList::operator=(EntityList&& entityList) noexcept
{
if (this == &entityList)
return *this;
for (const Ndk::EntityHandle& entity : *this)
entity->UnregisterEntityList(this);
m_entityBits = std::move(entityList.m_entityBits);
m_world = entityList.m_world;

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -31,4 +31,4 @@ namespace Ndk
#include <NDK/EntityOwner.inl>
#endif // NDK_ENTITYOwner_HPP
#endif // NDK_ENTITYOWNER_HPP

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <Nazara/Core/StringStream.hpp>
#include <functional>

View File

@@ -1,13 +1,12 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_LUABINDING_HPP
#define NDK_LUABINDING_HPP
#include <NDK/BaseComponent.hpp>
#include <NDK/Entity.hpp>
#include <NDK/Lua/LuaBinding_Base.hpp>
#include <memory>

View File

@@ -1,8 +1,6 @@
// 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/Lua/LuaBinding.hpp>
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -9,7 +9,7 @@
#include <Nazara/Lua/LuaClass.hpp>
#include <Nazara/Lua/LuaInstance.hpp>
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -11,6 +11,7 @@
#include <NDK/Components.hpp>
#include <NDK/Console.hpp>
#include <NDK/Entity.hpp>
#include <NDK/World.hpp>
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,13 +1,13 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_LUAINTERFACE_HPP
#define NDK_LUAINTERFACE_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
namespace Nz
{

View File

@@ -1,8 +1,7 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/LuaAPI.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Lua/LuaState.hpp>
#include <Nazara/Math/EulerAngles.hpp>
@@ -16,7 +15,6 @@
#include <NDK/Components.hpp>
#include <NDK/Entity.hpp>
#include <NDK/World.hpp>
#include <algorithm>
#ifndef NDK_SERVER
#include <Nazara/Audio/Music.hpp>
@@ -310,9 +308,22 @@ namespace Nz
return ret;
}
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Ndk::Entity** handle, TypeTag<Ndk::Entity*>)
{
if (!state.IsOfType(index, LuaType_Nil))
*handle = *static_cast<Ndk::EntityHandle*>(state.CheckUserdata(index, "Entity"));
else
*handle = nullptr;
return 1;
}
inline unsigned int LuaImplQueryArg(const LuaState& state, int index, Ndk::EntityHandle* handle, TypeTag<Ndk::EntityHandle>)
{
*handle = *static_cast<Ndk::EntityHandle*>(state.CheckUserdata(index, "Entity"));
if (!state.IsOfType(index, LuaType_Nil))
*handle = *static_cast<Ndk::EntityHandle*>(state.CheckUserdata(index, "Entity"));
else
handle->Reset();
return 1;
}

View File

@@ -22,15 +22,15 @@
SOFTWARE.
*/
#ifndef NDK_PREREQUESITES_HPP
#define NDK_PREREQUESITES_HPP
#ifndef NDK_PREREQUISITES_HPP
#define NDK_PREREQUISITES_HPP
/*!
* \defgroup NDK (NazaraSDK) Nazara Development Kit
* A library grouping every modules of Nazara into multiple higher-level features suchs as scene management (handled by an ECS), application, lua binding, etc.
*/
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Prerequisites.hpp>
// Importation/Exportation of the API
#if defined(NAZARA_STATIC)
@@ -51,4 +51,4 @@ namespace Ndk
using SystemIndex = Nz::UInt32;
}
#endif // NDK_PREREQUESITES_HPP
#endif // NDK_PREREQUISITES_HPP

View File

@@ -1,13 +1,13 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_SDK_HPP
#define NDK_SDK_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,13 +1,13 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_STATE_HPP
#define NDK_STATE_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
namespace Ndk
{

View File

@@ -1,13 +1,13 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_STATEMACHINE_HPP
#define NDK_STATEMACHINE_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
#include <NDK/State.hpp>
#include <memory>
#include <vector>
@@ -24,15 +24,13 @@ namespace Ndk
inline void ChangeState(std::shared_ptr<State> state);
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 PopState();
inline void PopStatesUntil(std::shared_ptr<State> state);
inline void PushState(std::shared_ptr<State> state);
inline void SetState(std::shared_ptr<State> state);
inline void ResetState(std::shared_ptr<State> state);
inline bool Update(float elapsedTime);
@@ -40,7 +38,21 @@ namespace Ndk
StateMachine& operator=(const StateMachine&) = delete;
private:
enum class TransitionType
{
Pop,
PopUntil,
Push,
};
struct StateTransition
{
TransitionType type;
std::shared_ptr<State> state;
};
std::vector<std::shared_ptr<State>> m_states;
std::vector<StateTransition> m_transitions;
};
}

View File

@@ -1,7 +1,8 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/StateMachine.hpp>
#include <Nazara/Core/Error.hpp>
#include <utility>
@@ -16,66 +17,56 @@ namespace Ndk
/*!
* \brief Constructs a StateMachine object with an original state
*
* \param originalState State which is the entry point of the application
*
* \remark Calls "Enter" on the state
* \remark Produces a NazaraAssert if nullptr is given
* \param originalState State which is the entry point of the application, a nullptr will create an empty state machine
*/
inline StateMachine::StateMachine(std::shared_ptr<State> originalState)
{
NazaraAssert(originalState, "StateMachine must have a state to begin with");
PushState(std::move(originalState));
if (originalState)
PushState(std::move(originalState));
}
/*!
* \brief Destructs the object
*
* \remark Calls "Leave" on all the states
* \remark Calls "Leave" on all the states from top to bottom
*/
inline StateMachine::~StateMachine()
{
for (std::shared_ptr<State>& state : m_states)
state->Leave(*this);
// Leave state from top to bottom (as if states were popped out)
for (auto it = m_states.rbegin(); it != m_states.rend(); ++it)
(*it)->Leave(*this);
}
/*!
* \brief Replaces the current state on the top of the machine
*
* \param state State to replace the top one if it is nullptr, no action is performed
*
* \remark It is forbidden for a state machine to have (at any moment) the same state in its list multiple times
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
*/
inline void StateMachine::ChangeState(std::shared_ptr<State> state)
{
if (state)
{
PopState();
PushState(std::move(state));
// Change state is just a pop followed by a push
StateTransition transition;
transition.type = TransitionType::Pop;
m_transitions.emplace_back(std::move(transition));
transition.state = std::move(state);
transition.type = TransitionType::Push;
m_transitions.emplace_back(std::move(transition));
}
}
/*!
* \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_states.back();
}
/*!
* \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
* \remark Because all actions popping or pushing a state don't take effect until next state machine update, this can return false on a just pushed state
*/
inline bool StateMachine::IsTopState(const State* state) const
{
if (m_states.empty())
@@ -86,40 +77,36 @@ namespace Ndk
/*!
* \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
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
*/
inline std::shared_ptr<State> StateMachine::PopState()
inline void StateMachine::PopState()
{
if (m_states.empty())
return nullptr;
StateTransition transition;
transition.type = TransitionType::Pop;
m_states.back()->Leave(*this);
std::shared_ptr<State> oldTopState = std::move(m_states.back());
m_states.pop_back();
return oldTopState;
m_transitions.emplace_back(std::move(transition));
}
/*!
* \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
* \brief Pops all states of the machine until a specific one is reached
*
* \param state State to find on the stack if it is nullptr, no action is performed
* \param state State to find on the stack. If nullptr is passed, no action is performed
*
* \remark This method can completely empty the stack
* \remark This method will completely empty the stack if state is not present
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
*/
inline bool StateMachine::PopStatesUntil(std::shared_ptr<State> state)
inline void StateMachine::PopStatesUntil(std::shared_ptr<State> state)
{
if (!state)
return false;
if (state)
{
StateTransition transition;
transition.state = std::move(state);
transition.type = TransitionType::PopUntil;
while (!m_states.empty() && !IsTopState(state.get()))
PopState();
return !m_states.empty();
m_transitions.emplace_back(std::move(transition));
}
}
/*!
@@ -127,34 +114,40 @@ namespace Ndk
*
* \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
* \remark It is forbidden for a state machine to have (at any moment) the same state in its list multiple times
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
*/
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");
StateTransition transition;
transition.state = std::move(state);
transition.type = TransitionType::Push;
m_states.push_back(std::move(state));
m_states.back()->Enter(*this);
m_transitions.emplace_back(std::move(transition));
}
}
/*!
* \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
* \param state State to reset the stack with. If state is invalid, this will clear the state machine
*
* \remark It is forbidden for a state machine to have (at any moment) the same state in its list multiple times
* \remark Like all actions popping or pushing a state, this is not immediate and will only take effect when state machine is updated
*/
inline void StateMachine::SetState(std::shared_ptr<State> state)
inline void StateMachine::ResetState(std::shared_ptr<State> state)
{
StateTransition transition;
transition.type = TransitionType::PopUntil; //< Pop until nullptr, which basically clears the state machine
m_transitions.emplace_back(std::move(transition));
if (state)
{
while (!m_states.empty())
PopState();
PushState(std::move(state));
transition.state = std::move(state);
transition.type = TransitionType::Push;
m_transitions.emplace_back(std::move(transition));
}
}
@@ -164,9 +157,41 @@ namespace Ndk
*
* \param elapsedTime Delta time used for the update
*/
inline bool StateMachine::Update(float elapsedTime)
{
for (StateTransition& transition : m_transitions)
{
switch (transition.type)
{
case TransitionType::Pop:
{
std::shared_ptr<State>& topState = m_states.back();
topState->Leave(*this); //< Call leave before popping to ensure consistent IsTopState behavior
m_states.pop_back();
break;
}
case TransitionType::PopUntil:
{
while (!m_states.empty() && m_states.back() != transition.state)
{
m_states.back()->Leave(*this);
m_states.pop_back();
}
break;
}
case TransitionType::Push:
{
m_states.emplace_back(std::move(transition.state));
m_states.back()->Enter(*this);
break;
}
}
}
m_transitions.clear();
return std::all_of(m_states.begin(), m_states.end(), [=](std::shared_ptr<State>& state) {
return state->Update(*this, elapsedTime);
});

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -16,12 +16,10 @@ namespace Ndk
{
public:
System();
System(const System&) = default;
System(const System&) = delete;
System(System&&) = default;
virtual ~System();
std::unique_ptr<BaseSystem> Clone() const override;
System& operator=(const System&) = delete;
System& operator=(System&&) = default;

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Algorithm.hpp>
#include <type_traits>
@@ -28,22 +28,6 @@ namespace Ndk
template<typename SystemType>
System<SystemType>::~System() = default;
/*!
* \brief Clones the system
* \return The clone newly created
*
* \remark The system to clone should be trivially copy constructible
*/
template<typename SystemType>
std::unique_ptr<BaseSystem> System<SystemType>::Clone() const
{
///FIXME: Not fully supported in GCC (4.9.2)
//static_assert(std::is_trivially_copy_constructible<SystemType>::value, "SystemType should be copy-constructible");
return std::make_unique<SystemType>(static_cast<const SystemType&>(*this));
}
/*!
* \brief Registers the system by assigning it an index
*/

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,3 +1,3 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,3 +1,3 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -18,7 +18,6 @@ namespace Ndk
{
public:
PhysicsSystem3D();
PhysicsSystem3D(const PhysicsSystem3D& system);
~PhysicsSystem3D() = default;
Nz::PhysWorld3D& GetWorld();

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -11,16 +11,16 @@
#include <Nazara/Graphics/AbstractBackground.hpp>
#include <Nazara/Graphics/CullingList.hpp>
#include <Nazara/Graphics/DepthRenderTechnique.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Renderer/RenderTexture.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/EntityList.hpp>
#include <NDK/System.hpp>
#include <unordered_map>
#include <NDK/Components/GraphicsComponent.hpp>
#include <vector>
namespace Ndk
{
class AbstractViewer;
class NDK_API RenderSystem : public System<RenderSystem>
{
public:
@@ -52,6 +52,7 @@ namespace Ndk
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
void UpdateDynamicReflections();
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
void UpdatePointSpotShadowMaps();
@@ -63,6 +64,7 @@ namespace Ndk
EntityList m_lights;
EntityList m_pointSpotLights;
EntityList m_particleGroups;
EntityList m_realtimeReflected;
GraphicsComponentCullingList m_drawableCulling;
Nz::BackgroundRef m_background;
Nz::DepthRenderTechnique m_shadowTechnique;

View File

@@ -1,20 +1,9 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{
/*!
* \brief Constructs a RenderSystem object by copy semantic
*
* \param renderSystem RenderSystem to copy
*/
inline RenderSystem::RenderSystem(const RenderSystem& renderSystem) :
System(renderSystem)
{
}
/*!
* \brief Changes the render technique used for the system
* \return A reference to the render technique type

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once

View File

@@ -1,3 +1,3 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp

View File

@@ -7,6 +7,8 @@
#include <NDK/Widgets/ButtonWidget.hpp>
#include <NDK/Widgets/CheckboxWidget.hpp>
#include <NDK/Widgets/Enums.hpp>
#include <NDK/Widgets/ImageWidget.hpp>
#include <NDK/Widgets/LabelWidget.hpp>
#include <NDK/Widgets/ProgressBarWidget.hpp>
#include <NDK/Widgets/TextAreaWidget.hpp>

View File

@@ -1,22 +1,25 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_BUTTONWIDGET_HPP
#define NDK_WIDGETS_BUTTONWIDGET_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
#include <NDK/BaseWidget.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
namespace Nz
{
class AbstractTextDrawer;
}
namespace Ndk
{
class World;
class NDK_API ButtonWidget : public BaseWidget
{
public:
@@ -29,17 +32,44 @@ namespace Ndk
void ResizeToContent() override;
inline const Nz::Color& GetColor() const;
inline const Nz::Color& GetCornerColor() const;
inline const Nz::Color& GetHoverColor() const;
inline const Nz::Color& GetHoverCornerColor() const;
inline const Nz::Color& GetPressColor() const;
inline const Nz::Color& GetPressCornerColor() const;
inline const Nz::TextureRef& GetTexture() const;
inline const Nz::TextureRef& GetHoverTexture() const;
inline const Nz::TextureRef& GetPressTexture() const;
inline void SetColor(const Nz::Color& color, const Nz::Color& cornerColor);
inline void SetHoverColor(const Nz::Color& color, const Nz::Color& cornerColor);
inline void SetPressColor(const Nz::Color& color, const Nz::Color& cornerColor);
inline void SetTexture(const Nz::TextureRef& texture);
inline void SetHoverTexture(const Nz::TextureRef& texture);
inline void SetPressTexture(const Nz::TextureRef& texture);
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
ButtonWidget& operator=(const ButtonWidget&) = delete;
ButtonWidget& operator=(ButtonWidget&&) = default;
static const Nz::Color& GetDefaultColor();
static const Nz::Color& GetDefaultCornerColor();
static const Nz::Color& GetDefaultHoverColor();
static const Nz::Color& GetDefaultHoverCornerColor();
static const Nz::Color& GetDefaultPressColor();
static const Nz::Color& GetDefaultPressCornerColor();
NazaraSignal(OnButtonTrigger, const ButtonWidget* /*button*/);
private:
void Layout() override;
void OnMouseEnter() override;
void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) override;
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
void OnMouseExit() override;
@@ -47,6 +77,24 @@ namespace Ndk
EntityHandle m_gradientEntity;
Nz::SpriteRef m_gradientSprite;
Nz::TextSpriteRef m_textSprite;
Nz::Color m_color;
Nz::Color m_cornerColor;
Nz::Color m_hoverColor;
Nz::Color m_hoverCornerColor;
Nz::Color m_pressColor;
Nz::Color m_pressCornerColor;
Nz::TextureRef m_texture;
Nz::TextureRef m_hoverTexture;
Nz::TextureRef m_pressTexture;
static Nz::Color s_color;
static Nz::Color s_cornerColor;
static Nz::Color s_hoverColor;
static Nz::Color s_hoverCornerColor;
static Nz::Color s_pressColor;
static Nz::Color s_pressCornerColor;
};
}

View File

@@ -1,11 +1,94 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Widgets/ButtonWidget.hpp>
namespace Ndk
{
inline const Nz::Color& ButtonWidget::GetColor() const
{
return m_color;
}
inline const Nz::Color& ButtonWidget::GetCornerColor() const
{
return m_cornerColor;
}
inline const Nz::Color& ButtonWidget::GetHoverColor() const
{
return m_hoverColor;
}
inline const Nz::Color& ButtonWidget::GetHoverCornerColor() const
{
return m_hoverCornerColor;
}
inline const Nz::Color& ButtonWidget::GetPressColor() const
{
return m_pressColor;
}
inline const Nz::Color& ButtonWidget::GetPressCornerColor() const
{
return m_pressCornerColor;
}
inline const Nz::TextureRef& ButtonWidget::GetTexture() const
{
return m_texture;
}
inline const Nz::TextureRef& ButtonWidget::GetHoverTexture() const
{
return m_hoverTexture;
}
inline const Nz::TextureRef& ButtonWidget::GetPressTexture() const
{
return m_pressTexture;
}
inline void ButtonWidget::SetColor(const Nz::Color& color, const Nz::Color& cornerColor)
{
m_color = color;
m_cornerColor = cornerColor;
m_gradientSprite->SetColor(m_color);
m_gradientSprite->SetCornerColor(Nz::RectCorner_LeftBottom, m_cornerColor);
m_gradientSprite->SetCornerColor(Nz::RectCorner_RightBottom, m_cornerColor);
}
inline void ButtonWidget::SetHoverColor(const Nz::Color& color, const Nz::Color& cornerColor)
{
m_hoverColor = color;
m_hoverCornerColor = cornerColor;
}
inline void ButtonWidget::SetPressColor(const Nz::Color& color, const Nz::Color& cornerColor)
{
m_pressColor = color;
m_pressCornerColor = cornerColor;
}
inline void ButtonWidget::SetTexture(const Nz::TextureRef& texture)
{
m_texture = texture;
m_gradientSprite->SetTexture(m_texture);
}
inline void ButtonWidget::SetHoverTexture(const Nz::TextureRef& texture)
{
m_hoverTexture = texture;
}
inline void ButtonWidget::SetPressTexture(const Nz::TextureRef& texture)
{
m_pressTexture = texture;
}
inline void ButtonWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
{
m_textSprite->Update(drawer);

View File

@@ -1,27 +1,28 @@
// Copyright (C) 2017 Samy Bensaid
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_CHECKBOXWIDGET_HPP
#define NDK_WIDGETS_CHECKBOXWIDGET_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
#include <NDK/BaseWidget.hpp>
#include <NDK/Widgets/Enums.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Widgets/Enums.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Rect.hpp>
namespace Nz
{
class AbstractTextDrawer;
}
namespace Ndk
{
class World;
class NDK_API CheckboxWidget : public BaseWidget
{
friend class Sdk;

View File

@@ -1,6 +1,6 @@
// Copyright (C) 2017 Samy Bensaid
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,6 +1,6 @@
// Copyright (C) 2017 Samy Bensaid
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -17,6 +17,15 @@ namespace Ndk
CheckboxState_Max = CheckboxState_Unchecked
};
enum EchoMode
{
EchoMode_Normal,
EchoMode_Password,
EchoMode_PasswordExceptLast,
EchoMode_Max = EchoMode_PasswordExceptLast
};
}
#endif // NAZARA_ENUMS_SDK_HPP

View File

@@ -0,0 +1,53 @@
// Copyright (C) 2017 Samy Bensaid
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_IMAGEWIDGET_HPP
#define NDK_WIDGETS_IMAGEWIDGET_HPP
#include <NDK/Prerequisites.hpp>
#include <NDK/BaseWidget.hpp>
#include <NDK/Entity.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Math/Vector2.hpp>
namespace Ndk
{
class NDK_API ImageWidget : public BaseWidget
{
public:
ImageWidget(BaseWidget* parent = nullptr);
ImageWidget(const ImageWidget&) = delete;
ImageWidget(ImageWidget&&) = default;
~ImageWidget() = default;
//virtual ImageWidget* Clone() const = 0;
void ResizeToContent() override;
inline const Nz::Color& GetColor() const;
inline const Nz::TextureRef& GetTexture() const;
inline const Nz::Rectf& GetTextureCoords() const;
inline void SetColor(const Nz::Color& color);
inline void SetTexture(const Nz::TextureRef& texture, bool resizeToContent = true);
inline void SetTextureCoords(const Nz::Rectf& coords);
inline void SetTextureRect(const Nz::Rectui& rect);
ImageWidget& operator=(const ImageWidget&) = delete;
ImageWidget& operator=(ImageWidget&&) = default;
private:
void Layout() override;
Ndk::EntityHandle m_entity;
Nz::SpriteRef m_sprite;
};
}
#include <NDK/Widgets/ImageWidget.inl>
#endif // NDK_WIDGETS_IMAGEWIDGET_HPP

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2017 Samy Bensaid
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Widgets/ImageWidget.hpp>
namespace Ndk
{
inline const Nz::Color& ImageWidget::GetColor() const
{
return m_sprite->GetColor();
}
inline const Nz::TextureRef& ImageWidget::GetTexture() const
{
return m_sprite->GetMaterial()->GetDiffuseMap();
}
inline const Nz::Rectf& ImageWidget::GetTextureCoords() const
{
return m_sprite->GetTextureCoords();
}
inline void ImageWidget::SetColor(const Nz::Color& color)
{
m_sprite->SetColor(color);
}
inline void ImageWidget::SetTexture(const Nz::TextureRef& texture, bool resizeToContent)
{
m_sprite->SetTexture(texture, false);
if (resizeToContent)
ResizeToContent();
}
inline void ImageWidget::SetTextureCoords(const Nz::Rectf& coords)
{
m_sprite->SetTextureCoords(coords);
}
inline void ImageWidget::SetTextureRect(const Nz::Rectui& rect)
{
m_sprite->SetTextureRect(rect);
}
}

View File

@@ -1,21 +1,23 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_LABELWIDGET_HPP
#define NDK_WIDGETS_LABELWIDGET_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
#include <NDK/BaseWidget.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
namespace Nz
{
class AbstractTextDrawer;
}
namespace Ndk
{
class World;
class NDK_API LabelWidget : public BaseWidget
{
public:
@@ -26,7 +28,7 @@ namespace Ndk
//virtual LabelWidget* Clone() const = 0;
void ResizeToContent();
void ResizeToContent() override;
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
@@ -34,6 +36,8 @@ namespace Ndk
LabelWidget& operator=(LabelWidget&&) = default;
private:
void Layout() override;
EntityHandle m_textEntity;
Nz::TextSpriteRef m_textSprite;
};

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Widgets/LabelWidget.hpp>

View File

@@ -1,26 +1,23 @@
// Copyright (C) 2017 Samy Bensaid
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_PROGRESSBARWIDGET_HPP
#define NDK_WIDGETS_PROGRESSBARWIDGET_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/Prerequisites.hpp>
#include <NDK/BaseWidget.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
namespace Ndk
{
class World;
class NDK_API ProgressBarWidget : public BaseWidget
{
friend class Sdk;

View File

@@ -1,6 +1,6 @@
// Copyright (C) 2017 Samy Bensaid
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
namespace Ndk
{

View File

@@ -1,21 +1,19 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_TEXTAREAWIDGET_HPP
#define NDK_WIDGETS_TEXTAREAWIDGET_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/BaseWidget.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <NDK/BaseWidget.hpp>
#include <NDK/Widgets/Enums.hpp>
namespace Ndk
{
class World;
class NDK_API TextAreaWidget : public BaseWidget
{
public:
@@ -32,9 +30,11 @@ namespace Ndk
inline void EnableMultiline(bool enable = true);
inline unsigned int GetCharacterSize() const;
inline const Nz::Vector2ui& GetCursorPosition() const;
inline std::size_t GetGlyphUnderCursor() const;
inline std::size_t GetLineCount() const;
inline const Nz::String& GetDisplayText() const;
inline EchoMode GetEchoMode() const;
inline std::size_t GetGlyphIndex(const Nz::Vector2ui& cursorPosition);
inline const Nz::String& GetText() const;
inline const Nz::Color& GetTextColor() const;
@@ -48,8 +48,10 @@ namespace Ndk
void ResizeToContent() override;
inline void SetCharacterSize(unsigned int characterSize);
inline void SetCursorPosition(std::size_t glyphIndex);
inline void SetCursorPosition(Nz::Vector2ui cursorPosition);
inline void SetEchoMode(EchoMode echoMode);
inline void SetReadOnly(bool readOnly = true);
inline void SetText(const Nz::String& text);
inline void SetTextColor(const Nz::Color& text);
@@ -66,27 +68,30 @@ namespace Ndk
NazaraSignal(OnTextAreaKeyReturn, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyRight, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyUp, const TextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextChanged, const TextAreaWidget* /*textArea*/, const Nz::String& /*text*/);
private:
void Layout() override;
void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
bool IsFocusable() const override;
void OnFocusLost() override;
void OnFocusReceived() override;
bool OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override;
void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key) override;
void OnMouseEnter() override;
void OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button) override;
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
void OnMouseExit() override;
void OnTextEntered(char32_t character, bool repeated) override;
void RefreshCursor();
void UpdateDisplayText();
EchoMode m_echoMode;
EntityHandle m_cursorEntity;
EntityHandle m_textEntity;
Nz::SimpleTextDrawer m_drawer;
Nz::SpriteRef m_cursorSprite;
Nz::String m_text;
Nz::TextSpriteRef m_textSprite;
Nz::Vector2ui m_cursorPosition;
std::size_t m_cursorGlyph;
bool m_multiLineEnabled;
bool m_readOnly;
};

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Widgets/TextAreaWidget.hpp>
@@ -8,11 +8,13 @@ namespace Ndk
{
inline void TextAreaWidget::Clear()
{
m_cursorPosition = 0;
m_cursorPosition.MakeZero();
m_drawer.Clear();
m_text.Clear();
m_textSprite->Update(m_drawer);
RefreshCursor();
OnTextChanged(this, m_text);
}
inline void TextAreaWidget::EnableMultiline(bool enable)
@@ -20,24 +22,40 @@ namespace Ndk
m_multiLineEnabled = enable;
}
inline unsigned int TextAreaWidget::GetCharacterSize() const
{
return m_drawer.GetCharacterSize();
}
inline const Nz::Vector2ui& TextAreaWidget::GetCursorPosition() const
{
return m_cursorPosition;
}
inline std::size_t Ndk::TextAreaWidget::GetGlyphUnderCursor() const
inline const Nz::String& TextAreaWidget::GetDisplayText() const
{
return m_cursorGlyph;
return m_drawer.GetText();
}
inline std::size_t TextAreaWidget::GetLineCount() const
inline std::size_t TextAreaWidget::GetGlyphIndex(const Nz::Vector2ui& cursorPosition)
{
return m_drawer.GetLineCount();
std::size_t glyphIndex = m_drawer.GetLine(cursorPosition.y).glyphIndex + cursorPosition.x;
if (m_drawer.GetLineCount() > cursorPosition.y + 1)
glyphIndex = std::min(glyphIndex, m_drawer.GetLine(cursorPosition.y + 1).glyphIndex - 1);
else
glyphIndex = std::min(glyphIndex, m_drawer.GetGlyphCount());
return glyphIndex;
}
inline EchoMode TextAreaWidget::GetEchoMode() const
{
return m_echoMode;
}
inline const Nz::String& TextAreaWidget::GetText() const
{
return m_drawer.GetText();
return m_text;
}
inline const Nz::Color& TextAreaWidget::GetTextColor() const
@@ -57,27 +75,28 @@ namespace Ndk
inline void TextAreaWidget::MoveCursor(int offset)
{
std::size_t cursorGlyph = GetGlyphIndex(m_cursorPosition);
if (offset >= 0)
SetCursorPosition(m_cursorGlyph + static_cast<std::size_t>(offset));
SetCursorPosition(cursorGlyph + static_cast<std::size_t>(offset));
else
{
std::size_t nOffset = static_cast<std::size_t>(-offset);
if (nOffset >= m_cursorGlyph)
if (nOffset >= cursorGlyph)
SetCursorPosition(0);
else
SetCursorPosition(m_cursorGlyph - nOffset);
SetCursorPosition(cursorGlyph - nOffset);
}
}
inline void TextAreaWidget::MoveCursor(const Nz::Vector2i& offset)
{
auto BoundOffset = [] (unsigned int cursorPosition, int offset) -> unsigned int
auto ClampOffset = [] (unsigned int cursorPosition, int cursorOffset) -> unsigned int
{
if (offset >= 0)
return cursorPosition + offset;
if (cursorOffset >= 0)
return cursorPosition + cursorOffset;
else
{
unsigned int nOffset = static_cast<unsigned int>(-offset);
unsigned int nOffset = static_cast<unsigned int>(-cursorOffset);
if (nOffset >= cursorPosition)
return 0;
else
@@ -86,23 +105,28 @@ namespace Ndk
};
Nz::Vector2ui cursorPosition = m_cursorPosition;
cursorPosition.x = BoundOffset(static_cast<unsigned int>(cursorPosition.x), offset.x);
cursorPosition.y = BoundOffset(static_cast<unsigned int>(cursorPosition.y), offset.y);
cursorPosition.x = ClampOffset(static_cast<unsigned int>(cursorPosition.x), offset.x);
cursorPosition.y = ClampOffset(static_cast<unsigned int>(cursorPosition.y), offset.y);
SetCursorPosition(cursorPosition);
}
inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
{
m_drawer.SetCharacterSize(characterSize);
}
inline void TextAreaWidget::SetCursorPosition(std::size_t glyphIndex)
{
OnTextAreaCursorMove(this, &glyphIndex);
m_cursorGlyph = std::min(glyphIndex, m_drawer.GetGlyphCount());
glyphIndex = std::min(glyphIndex, m_drawer.GetGlyphCount());
std::size_t lineCount = m_drawer.GetLineCount();
std::size_t line = 0U;
for (std::size_t i = line + 1; i < lineCount; ++i)
{
if (m_drawer.GetLine(i).glyphIndex > m_cursorGlyph)
if (m_drawer.GetLine(i).glyphIndex > glyphIndex)
break;
line = i;
@@ -110,8 +134,8 @@ namespace Ndk
const auto& lineInfo = m_drawer.GetLine(line);
m_cursorPosition.y = line;
m_cursorPosition.x = m_cursorGlyph - lineInfo.glyphIndex;
m_cursorPosition.y = static_cast<unsigned int>(line);
m_cursorPosition.x = static_cast<unsigned int>(glyphIndex - lineInfo.glyphIndex);
RefreshCursor();
}
@@ -135,25 +159,28 @@ namespace Ndk
OnTextAreaCursorMove(this, &glyphIndex);
m_cursorGlyph = std::min(glyphIndex, m_drawer.GetGlyphCount());
RefreshCursor();
}
inline void TextAreaWidget::SetEchoMode(EchoMode echoMode)
{
m_echoMode = echoMode;
UpdateDisplayText();
}
inline void TextAreaWidget::SetReadOnly(bool readOnly)
{
m_readOnly = readOnly;
m_cursorEntity->Enable(!m_readOnly);
m_cursorEntity->Enable(!m_readOnly && HasFocus());
}
inline void TextAreaWidget::SetText(const Nz::String& text)
{
m_drawer.SetText(text);
m_text = text;
OnTextChanged(this, m_text);
m_textSprite->Update(m_drawer);
SetCursorPosition(m_cursorPosition); //< Refresh cursor position (prevent it from being outside of the text)
UpdateDisplayText();
}
inline void TextAreaWidget::SetTextColor(const Nz::Color& text)

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#pragma once
@@ -15,7 +15,6 @@
#include <algorithm>
#include <memory>
#include <vector>
#include <unordered_map>
namespace Ndk
{
@@ -30,6 +29,7 @@ namespace Ndk
public:
using EntityVector = std::vector<EntityHandle>;
struct ProfilerData;
inline World(bool addDefaultSystems = true);
World(const World&) = delete;
@@ -47,10 +47,19 @@ namespace Ndk
void Clear() noexcept;
const EntityHandle& CloneEntity(EntityId id);
inline void DisableProfiler();
inline void EnableProfiler(bool enable = true);
template<typename F> void ForEachSystem(const F& iterationFunc);
template<typename F> void ForEachSystem(const F& iterationFunc) const;
inline const EntityHandle& GetEntity(EntityId id);
inline const EntityList& GetEntities() const;
inline const ProfilerData& GetProfilerData() const;
inline BaseSystem& GetSystem(SystemIndex index);
inline const BaseSystem& GetSystem(SystemIndex index) const;
template<typename SystemType> SystemType& GetSystem();
template<typename SystemType> const SystemType& GetSystem() const;
inline bool HasSystem(SystemIndex index) const;
template<typename SystemType> bool HasSystem() const;
@@ -60,17 +69,27 @@ namespace Ndk
inline bool IsEntityValid(const Entity* entity) const;
inline bool IsEntityIdValid(EntityId id) const;
inline bool IsProfilerEnabled() const;
void Refresh();
inline void RemoveAllSystems();
inline void RemoveSystem(SystemIndex index);
template<typename SystemType> void RemoveSystem();
inline void ResetProfiler();
void Update();
inline void Update(float elapsedTime);
void Update(float elapsedTime);
World& operator=(const World&) = delete;
inline World& operator=(World&& world) noexcept;
struct ProfilerData
{
Nz::UInt64 refreshTime = 0;
std::vector<Nz::UInt64> updateTime;
std::size_t updateCount = 0;
};
private:
inline void Invalidate();
inline void Invalidate(EntityId id);
@@ -96,11 +115,13 @@ namespace Ndk
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;
ProfilerData m_profilerData;
Nz::Bitset<Nz::UInt64> m_dirtyEntities;
Nz::Bitset<Nz::UInt64> m_freeEntityIds;
Nz::Bitset<Nz::UInt64> m_killedEntities;
bool m_orderedSystemsUpdated;
bool m_isProfilerEnabled;
};
}

View File

@@ -1,7 +1,8 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/World.hpp>
#include <Nazara/Core/Error.hpp>
#include <type_traits>
@@ -13,7 +14,9 @@ namespace Ndk
* \param addDefaultSystems Should default provided systems be used
*/
inline World::World(bool addDefaultSystems)
inline World::World(bool addDefaultSystems) :
m_orderedSystemsUpdated(false),
m_isProfilerEnabled(false)
{
if (addDefaultSystems)
AddDefaultSystems();
@@ -46,7 +49,10 @@ namespace Ndk
// We must ensure that the vector is big enough to hold the new system
if (index >= m_systems.size())
{
m_systems.resize(index + 1);
m_profilerData.updateTime.resize(index + 1, 0);
}
// Affectation and return of system
m_systems[index] = std::move(system);
@@ -81,7 +87,6 @@ namespace Ndk
*
* \param count Number of entities to create
*/
inline World::EntityVector World::CreateEntities(unsigned int count)
{
EntityVector list;
@@ -93,25 +98,121 @@ namespace Ndk
return list;
}
/*!
* \brief Disables the profiler, clearing up results
*
* This is just a shortcut to EnableProfiler(false)
*
* \param enable Should the entity be enabled
*
* \see EnableProfiler
*/
inline void World::DisableProfiler()
{
EnableProfiler(false);
}
/*!
* \brief Enables/Disables the internal profiler
*
* Worlds come with a built-in profiler, allowing to measure update count along with time passed in refresh and system updates.
* This is disabled by default as it adds an small overhead to the update process.
*
* \param enable Should the profiler be enabled
*
* \remark Disabling the profiler clears up results, as if ResetProfiler has been called
*/
inline void World::EnableProfiler(bool enable)
{
if (m_isProfilerEnabled != enable)
{
m_isProfilerEnabled = enable;
if (enable)
ResetProfiler();
}
}
/*!
* \brief Executes a function on every present system
*
* Calls iterationFunc on every previously added system, in the same order as their indexes
*
* \param iterationFunc Function to be called
*/
template<typename F>
void World::ForEachSystem(const F& iterationFunc)
{
for (const auto& systemPtr : m_systems)
{
if (systemPtr)
iterationFunc(*systemPtr);
}
}
/*!
* \brief Executes a function on every present system
*
* Calls iterationFunc on every previously added system, in the same order as their indexes
*
* \param iterationFunc Function to be called
*/
template<typename F>
void World::ForEachSystem(const F& iterationFunc) const
{
for (const auto& systemPtr : m_systems)
{
if (systemPtr)
iterationFunc(static_cast<const Ndk::BaseSystem&>(*systemPtr)); //< Force const reference
}
}
/*!
* \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 handle reference 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 Gets every entities in the world
* \return A constant reference to the entities
*/
inline const EntityList& World::GetEntities() const
{
return m_aliveEntities;
}
/*!
* \brief Gets the latest profiler data
* \return A constant reference to the profiler data
*/
inline const World::ProfilerData& World::GetProfilerData() const
{
return m_profilerData;
}
/*!
* \brief Gets a system in the world by index
* \return A reference to the system
*
* \param index Index of the system
*
* \remark Produces a NazaraAssert if system is not available in this world
* \remark The world must have the system before calling this function
*/
inline BaseSystem& World::GetSystem(SystemIndex index)
{
NazaraAssert(HasSystem(index), "This system is not part of the world");
@@ -122,13 +223,30 @@ namespace Ndk
return *system;
}
/*!
* \brief Gets a system in the world by index
* \return A const reference to the system
*
* \param index Index of the system
*
* \remark The world must have the system before calling this function
*/
inline const BaseSystem& World::GetSystem(SystemIndex index) const
{
NazaraAssert(HasSystem(index), "This system is not part of the world");
const BaseSystem* system = m_systems[index].get();
NazaraAssert(system, "Invalid system pointer");
return *system;
}
/*!
* \brief Gets a system in the world by type
* \return A reference to the system
*
* \remark Produces a NazaraAssert if system is not available in this world
*/
template<typename SystemType>
SystemType& World::GetSystem()
{
@@ -138,6 +256,21 @@ namespace Ndk
return static_cast<SystemType&>(GetSystem(index));
}
/*!
* \brief Gets a system in the world by type
* \return A const reference to the system
*
* \remark Produces a NazaraAssert if system is not available in this world
*/
template<typename SystemType>
const SystemType& World::GetSystem() const
{
static_assert(std::is_base_of<BaseSystem, SystemType>::value, "SystemType is not a system");
SystemIndex index = GetSystemIndex<SystemType>();
return static_cast<const SystemType&>(GetSystem(index));
}
/*!
* \brief Checks whether or not a system is present in the world by index
* \return true If it is the case
@@ -191,26 +324,6 @@ namespace Ndk
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
@@ -229,12 +342,22 @@ namespace Ndk
*
* \param id Identifier of the entity
*/
inline bool World::IsEntityIdValid(EntityId id) const
{
return id < m_entityBlocks.size() && m_entityBlocks[id]->entity.IsValid();
}
/*!
* \brief Checks whether or not the profiler is enabled
* \return true If it is the case
*
* \see EnableProfiler
*/
inline bool World::IsProfilerEnabled() const
{
return m_isProfilerEnabled;
}
/*!
* \brief Removes each system from the world
*/
@@ -264,10 +387,21 @@ namespace Ndk
}
}
/*!
* \brief Clear profiler results
*
* This reset the profiler results, filling all counters with zero
*/
inline void World::ResetProfiler()
{
m_profilerData.refreshTime = 0;
m_profilerData.updateCount = 0;
std::fill(m_profilerData.updateTime.begin(), m_profilerData.updateTime.end(), 0);
}
/*!
* \brief Removes a system from the world by type
*/
template<typename SystemType>
void World::RemoveSystem()
{
@@ -277,21 +411,6 @@ namespace Ndk
RemoveSystem(index);
}
/*!
* \brief Updates the world
*
* \param elapsedTime Delta time used for the update
*/
inline void World::Update(float elapsedTime)
{
Update(); //< Update entities
// And then update systems
for (auto& systemPtr : m_orderedSystems)
systemPtr->Update(elapsedTime);
}
/*!
* \brief Moves a world into another world object
* \return A reference to the object
@@ -302,19 +421,25 @@ 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_freeEntityIds = std::move(world.m_freeEntityIds);
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_profilerData = std::move(world.m_profilerData);
m_isProfilerEnabled = world.m_isProfilerEnabled;
m_entities = std::move(world.m_entities);
for (EntityBlock& block : m_entities)
block.entity.SetWorld(this);
m_waitingEntities = std::move(world.m_waitingEntities);
for (auto& blockPtr : m_waitingEntities)
blockPtr->entity.SetWorld(this);
m_systems = std::move(world.m_systems);
for (const auto& systemPtr : m_systems)
systemPtr->SetWorld(this);
if (systemPtr)
systemPtr->SetWorld(this);
return *this;
}

View File

@@ -1,6 +1,6 @@
// 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
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NDK/Application.hpp>
#include <Nazara/Core/Log.hpp>
@@ -12,6 +12,7 @@
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Systems/RenderSystem.hpp>
#include <NDK/LuaAPI.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#endif
@@ -106,8 +107,7 @@ namespace Ndk
if (m_shouldQuit)
return false;
m_updateTime = m_updateClock.GetSeconds();
m_updateClock.Restart();
m_updateTime = m_updateClock.Restart() / 1'000'000.f;
for (World& world : m_worlds)
world.Update(m_updateTime);
@@ -147,7 +147,10 @@ namespace Ndk
Nz::Vector2ui windowDimensions;
if (info.window->IsValid())
windowDimensions.Set(info.window->GetWidth(), info.window->GetHeight());
{
windowDimensions = info.window->GetSize();
windowDimensions.y /= 4;
}
else
windowDimensions.MakeZero();
@@ -163,6 +166,7 @@ namespace Ndk
consoleRef.AddLine(str);
});
overlay->lua.LoadLibraries();
LuaAPI::RegisterClasses(overlay->lua);
// Override "print" function to add a line in the console
@@ -213,7 +217,8 @@ namespace Ndk
overlay->resizedSlot.Connect(info.renderTarget->OnRenderTargetSizeChange, [&consoleRef] (const Nz::RenderTarget* renderTarget)
{
consoleRef.SetSize({float(renderTarget->GetWidth()), renderTarget->GetHeight() / 4.f});
Nz::Vector2ui size = renderTarget->GetSize();
consoleRef.SetSize({float(size.x), size.y / 4.f});
});
info.console = std::move(overlay);

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