Merge branch 'master' into NDK-ShadowMapping
Former-commit-id: e2be28b65207dfbb81efe58f31ca31548afecee7
This commit is contained in:
@@ -20,6 +20,6 @@ namespace Ndk
|
||||
template<typename SystemType, typename S> bool IsSystem(S& system);
|
||||
}
|
||||
|
||||
#include <Ndk/Algorithm.inl>
|
||||
#include <NDK/Algorithm.inl>
|
||||
|
||||
#endif // NDK_ALGORITHM_HPP
|
||||
|
||||
@@ -8,14 +8,51 @@
|
||||
#define NDK_APPLICATION_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API Application
|
||||
{
|
||||
public:
|
||||
Application();
|
||||
~Application();
|
||||
inline Application();
|
||||
Application(const Application&) = delete;
|
||||
Application(Application&&) = delete;
|
||||
inline ~Application();
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
template<typename T, typename... Args> T& AddWindow(Args&&... args);
|
||||
#endif
|
||||
template<typename... Args> World& AddWorld(Args&&... args);
|
||||
|
||||
inline float GetUpdateTime() const;
|
||||
|
||||
bool Run();
|
||||
|
||||
inline void Quit();
|
||||
|
||||
Application& operator=(const Application&) = delete;
|
||||
Application& operator=(Application&&) = delete;
|
||||
|
||||
inline static Application* Instance();
|
||||
|
||||
private:
|
||||
#ifndef NDK_SERVER
|
||||
std::vector<std::unique_ptr<Nz::Window>> m_windows;
|
||||
#endif
|
||||
std::list<World> m_worlds;
|
||||
Nz::Clock m_updateClock;
|
||||
#ifndef NDK_SERVER
|
||||
bool m_exitOnClosedWindows;
|
||||
#endif
|
||||
bool m_shouldQuit;
|
||||
float m_updateTime;
|
||||
|
||||
static Application* s_application;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,21 @@
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <type_traits>
|
||||
#include <NDK/Sdk.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline Application::Application()
|
||||
inline Application::Application() :
|
||||
#ifndef NDK_SERVER
|
||||
m_exitOnClosedWindows(true),
|
||||
#endif
|
||||
m_shouldQuit(false),
|
||||
m_updateTime(0.f)
|
||||
{
|
||||
NazaraAssert(s_application == nullptr, "You can create only one application instance per program");
|
||||
s_application = this;
|
||||
|
||||
Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true);
|
||||
|
||||
// Initialisation du SDK
|
||||
@@ -17,9 +26,48 @@ namespace Ndk
|
||||
|
||||
inline Application::~Application()
|
||||
{
|
||||
m_worlds.clear();
|
||||
#ifndef NDK_SERVER
|
||||
m_windows.clear();
|
||||
#endif
|
||||
|
||||
// Libération du SDK
|
||||
Sdk::Uninitialize();
|
||||
|
||||
// Libération automatique des modules
|
||||
s_application = nullptr;
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
template<typename T, typename... Args>
|
||||
T& Application::AddWindow(Args&&... args)
|
||||
{
|
||||
static_assert(std::is_base_of<Nz::Window, T>::value, "Type must inherit Window");
|
||||
|
||||
m_windows.emplace_back(new T(std::forward<Args>(args)...));
|
||||
return static_cast<T&>(*m_windows.back().get());
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename... Args>
|
||||
World& Application::AddWorld(Args&&... args)
|
||||
{
|
||||
m_worlds.emplace_back(std::forward<Args>(args)...);
|
||||
return m_worlds.back();
|
||||
}
|
||||
|
||||
inline float Application::GetUpdateTime() const
|
||||
{
|
||||
return m_updateTime;
|
||||
}
|
||||
|
||||
inline void Application::Quit()
|
||||
{
|
||||
m_shouldQuit = true;
|
||||
}
|
||||
|
||||
inline Application* Application::Instance()
|
||||
{
|
||||
return s_application;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#ifndef NDK_BASECOMPONENT_HPP
|
||||
#define NDK_BASECOMPONENT_HPP
|
||||
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
@@ -31,6 +31,8 @@ namespace Ndk
|
||||
|
||||
ComponentIndex GetIndex() const;
|
||||
|
||||
inline static ComponentIndex GetMaxComponentIndex();
|
||||
|
||||
BaseComponent& operator=(const BaseComponent&) = default;
|
||||
BaseComponent& operator=(BaseComponent&&) = default;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/BaseComponent.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
|
||||
namespace Ndk
|
||||
@@ -17,6 +18,11 @@ namespace Ndk
|
||||
return m_componentIndex;
|
||||
}
|
||||
|
||||
inline ComponentIndex BaseComponent::GetMaxComponentIndex()
|
||||
{
|
||||
return static_cast<ComponentIndex>(s_entries.size());
|
||||
}
|
||||
|
||||
inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc)
|
||||
{
|
||||
// Nous allons rajouter notre composant à la fin
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define NDK_BASESYSTEM_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
@@ -71,7 +71,7 @@ namespace Ndk
|
||||
|
||||
inline void RemoveEntity(Entity* entity);
|
||||
|
||||
inline void SetWorld(World& world);
|
||||
inline void SetWorld(World* world) noexcept;
|
||||
|
||||
inline void ValidateEntity(Entity* entity, bool justAdded);
|
||||
|
||||
|
||||
@@ -60,14 +60,16 @@ namespace Ndk
|
||||
{
|
||||
if (m_updateRate > 0.f)
|
||||
{
|
||||
m_updateCounter -= elapsedTime;
|
||||
if (m_updateCounter >= 0.f)
|
||||
return;
|
||||
m_updateCounter += elapsedTime;
|
||||
|
||||
m_updateCounter += m_updateRate;
|
||||
while (m_updateCounter >= m_updateRate)
|
||||
{
|
||||
OnUpdate(m_updateRate);
|
||||
m_updateCounter -= m_updateRate;
|
||||
}
|
||||
}
|
||||
|
||||
OnUpdate(elapsedTime);
|
||||
else
|
||||
OnUpdate(elapsedTime);
|
||||
}
|
||||
|
||||
template<typename ComponentType>
|
||||
@@ -172,9 +174,9 @@ namespace Ndk
|
||||
OnEntityValidation(entity, justAdded);
|
||||
}
|
||||
|
||||
inline void BaseSystem::SetWorld(World& world)
|
||||
inline void BaseSystem::SetWorld(World* world) noexcept
|
||||
{
|
||||
m_world = &world;
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
inline bool BaseSystem::Initialize()
|
||||
@@ -186,6 +188,6 @@ namespace Ndk
|
||||
|
||||
inline void BaseSystem::Uninitialize()
|
||||
{
|
||||
// Rien à faire
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Ndk/Algorithm.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Ndk
|
||||
|
||||
20
SDK/include/NDK/Components.hpp
Normal file
20
SDK/include/NDK/Components.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// This file was automatically generated on 03 Mar 2016 at 14:09:12
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_COMPONENTS_GLOBAL_HPP
|
||||
#define NDK_COMPONENTS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Components/CollisionComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/PhysicsComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Components/CameraComponent.hpp>
|
||||
#include <NDK/Components/GraphicsComponent.hpp>
|
||||
#include <NDK/Components/LightComponent.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#endif
|
||||
|
||||
#endif // NDK_COMPONENTS_GLOBAL_HPP
|
||||
@@ -33,24 +33,27 @@ namespace Ndk
|
||||
inline void EnsureViewMatrixUpdate() const;
|
||||
inline void EnsureViewportUpdate() const;
|
||||
|
||||
inline float GetAspectRatio() const;
|
||||
inline Nz::Vector3f GetEyePosition() const;
|
||||
inline Nz::Vector3f GetForward() const;
|
||||
inline float GetAspectRatio() const override;
|
||||
inline Nz::Vector3f GetEyePosition() const override;
|
||||
inline Nz::Vector3f GetForward() const override;
|
||||
inline float GetFOV() const;
|
||||
inline const Nz::Frustumf& GetFrustum() const;
|
||||
inline const Nz::Frustumf& GetFrustum() const override;
|
||||
inline unsigned int GetLayer() const;
|
||||
inline const Nz::Matrix4f& GetProjectionMatrix() const;
|
||||
inline const Nz::Matrix4f& GetProjectionMatrix() const override;
|
||||
inline Nz::ProjectionType GetProjectionType() const;
|
||||
inline const Nz::RenderTarget* GetTarget() const;
|
||||
inline const Nz::Vector2f& GetSize() const;
|
||||
inline const Nz::RenderTarget* GetTarget() const override;
|
||||
inline const Nz::Rectf& GetTargetRegion() const;
|
||||
inline const Nz::Matrix4f& GetViewMatrix() const;
|
||||
inline const Nz::Recti& GetViewport() const;
|
||||
inline float GetZFar() const;
|
||||
inline float GetZNear() const;
|
||||
inline const Nz::Matrix4f& GetViewMatrix() const override;
|
||||
inline const Nz::Recti& GetViewport() const override;
|
||||
inline float GetZFar() const override;
|
||||
inline float GetZNear() const override;
|
||||
|
||||
inline void SetFOV(float fov);
|
||||
inline void SetLayer(unsigned int layer);
|
||||
inline void SetProjectionType(Nz::ProjectionType projection);
|
||||
inline void SetSize(const Nz::Vector2f& size);
|
||||
inline void SetSize(float width, float height);
|
||||
inline void SetTarget(const Nz::RenderTarget* renderTarget);
|
||||
inline void SetTargetRegion(const Nz::Rectf& region);
|
||||
inline void SetViewport(const Nz::Recti& viewport);
|
||||
@@ -89,6 +92,7 @@ namespace Ndk
|
||||
Nz::Rectf m_targetRegion;
|
||||
mutable Nz::Recti m_viewport;
|
||||
const Nz::RenderTarget* m_target;
|
||||
Nz::Vector2f m_size;
|
||||
mutable bool m_frustumUpdated;
|
||||
mutable bool m_projectionMatrixUpdated;
|
||||
mutable bool m_viewMatrixUpdated;
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include "CameraComponent.hpp"
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline CameraComponent::CameraComponent() :
|
||||
m_projectionType(Nz::ProjectionType_Perspective),
|
||||
m_targetRegion(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(0.f),
|
||||
m_target(nullptr),
|
||||
m_frustumUpdated(false),
|
||||
m_projectionMatrixUpdated(false),
|
||||
@@ -28,6 +30,7 @@ namespace Ndk
|
||||
AbstractViewer(camera),
|
||||
m_projectionType(camera.m_projectionType),
|
||||
m_targetRegion(camera.m_targetRegion),
|
||||
m_size(camera.m_size),
|
||||
m_target(nullptr),
|
||||
m_frustumUpdated(false),
|
||||
m_projectionMatrixUpdated(false),
|
||||
@@ -102,6 +105,11 @@ namespace Ndk
|
||||
return m_projectionType;
|
||||
}
|
||||
|
||||
inline const Nz::Vector2f & CameraComponent::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline const Nz::RenderTarget* CameraComponent::GetTarget() const
|
||||
{
|
||||
return m_target;
|
||||
@@ -151,6 +159,18 @@ namespace Ndk
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetSize(const Nz::Vector2f& size)
|
||||
{
|
||||
m_size = size;
|
||||
|
||||
InvalidateProjectionMatrix();
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetSize(float width, float height)
|
||||
{
|
||||
SetSize({width, height});
|
||||
}
|
||||
|
||||
inline void CameraComponent::SetTarget(const Nz::RenderTarget* renderTarget)
|
||||
{
|
||||
m_target = renderTarget;
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API GraphicsComponent : public Component<GraphicsComponent>
|
||||
class GraphicsComponent;
|
||||
|
||||
using GraphicsComponentHandle = Nz::ObjectHandle<GraphicsComponent>;
|
||||
|
||||
class NDK_API GraphicsComponent : public Component<GraphicsComponent>, public Nz::HandledObject<GraphicsComponent>
|
||||
{
|
||||
friend class RenderSystem;
|
||||
|
||||
@@ -26,11 +30,15 @@ namespace Ndk
|
||||
|
||||
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
|
||||
|
||||
inline void EnsureBoundingVolumeUpdate() const;
|
||||
inline void EnsureTransformMatrixUpdate() const;
|
||||
|
||||
inline const Nz::BoundingVolumef& GetBoundingVolume() const;
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
|
||||
private:
|
||||
inline void InvalidateBoundingVolume();
|
||||
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, unsigned int index);
|
||||
inline void InvalidateRenderables();
|
||||
inline void InvalidateTransformMatrix();
|
||||
@@ -41,6 +49,7 @@ namespace Ndk
|
||||
void OnDetached() override;
|
||||
void OnNodeInvalidated(const Nz::Node* node);
|
||||
|
||||
void UpdateBoundingVolume() const;
|
||||
void UpdateTransformMatrix() const;
|
||||
|
||||
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
|
||||
@@ -61,7 +70,9 @@ namespace Ndk
|
||||
};
|
||||
|
||||
std::vector<Renderable> m_renderables;
|
||||
mutable Nz::BoundingVolumef m_boundingVolume;
|
||||
mutable Nz::Matrix4f m_transformMatrix;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
mutable bool m_transformMatrixUpdated;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ namespace Ndk
|
||||
{
|
||||
inline GraphicsComponent::GraphicsComponent(const GraphicsComponent& graphicsComponent) :
|
||||
Component(graphicsComponent),
|
||||
m_boundingVolume(graphicsComponent.m_boundingVolume),
|
||||
m_transformMatrix(graphicsComponent.m_transformMatrix),
|
||||
m_boundingVolumeUpdated(graphicsComponent.m_boundingVolumeUpdated),
|
||||
m_transformMatrixUpdated(graphicsComponent.m_transformMatrixUpdated)
|
||||
{
|
||||
m_renderables.reserve(graphicsComponent.m_renderables.size());
|
||||
@@ -39,6 +41,14 @@ namespace Ndk
|
||||
r.data.renderOrder = renderOrder;
|
||||
r.renderable = std::move(renderable);
|
||||
r.renderableInvalidationSlot.Connect(r.renderable->OnInstancedRenderableInvalidateData, std::bind(&GraphicsComponent::InvalidateRenderableData, this, std::placeholders::_1, std::placeholders::_2, m_renderables.size()-1));
|
||||
|
||||
InvalidateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::EnsureBoundingVolumeUpdate() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::EnsureTransformMatrixUpdate() const
|
||||
@@ -47,6 +57,18 @@ namespace Ndk
|
||||
UpdateTransformMatrix();
|
||||
}
|
||||
|
||||
inline const Nz::BoundingVolumef& GraphicsComponent::GetBoundingVolume() const
|
||||
{
|
||||
EnsureBoundingVolumeUpdate();
|
||||
|
||||
return m_boundingVolume;
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::InvalidateBoundingVolume()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
inline void GraphicsComponent::InvalidateRenderables()
|
||||
{
|
||||
for (Renderable& r : m_renderables)
|
||||
@@ -55,6 +77,7 @@ namespace Ndk
|
||||
|
||||
inline void GraphicsComponent::InvalidateTransformMatrix()
|
||||
{
|
||||
m_boundingVolumeUpdated = false;
|
||||
m_transformMatrixUpdated = false;
|
||||
|
||||
InvalidateRenderables();
|
||||
|
||||
@@ -13,8 +13,11 @@
|
||||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
class NodeComponent;
|
||||
|
||||
class NDK_API NodeComponent : public Component<NodeComponent>, public Nz::Node
|
||||
using NodeComponentHandle = Nz::ObjectHandle<NodeComponent>;
|
||||
|
||||
class NDK_API NodeComponent : public Component<NodeComponent>, public Nz::Node, public Nz::HandledObject<NodeComponent>
|
||||
{
|
||||
public:
|
||||
NodeComponent() = default;
|
||||
|
||||
@@ -13,8 +13,11 @@
|
||||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
class VelocityComponent;
|
||||
|
||||
class NDK_API VelocityComponent : public Component<VelocityComponent>
|
||||
using VelocityComponentHandle = Nz::ObjectHandle<VelocityComponent>;
|
||||
|
||||
class NDK_API VelocityComponent : public Component<VelocityComponent>, public Nz::HandledObject<VelocityComponent>
|
||||
{
|
||||
public:
|
||||
VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero());
|
||||
|
||||
101
SDK/include/NDK/Console.hpp
Normal file
101
SDK/include/NDK/Console.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_CONSOLE_HPP
|
||||
#define NDK_CONSOLE_HPP
|
||||
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Graphics/Sprite.hpp>
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Utility/Event.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <NDK/EntityOwner.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class LuaInstance;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class Console;
|
||||
class Entity;
|
||||
|
||||
using ConsoleHandle = Nz::ObjectHandle<Console>;
|
||||
|
||||
class NDK_API Console : public Nz::Node, public Nz::HandledObject<Console>
|
||||
{
|
||||
public:
|
||||
Console(World& world, const Nz::Vector2f& size, Nz::LuaInstance& instance);
|
||||
Console(const Console& console) = delete;
|
||||
Console(Console&& console) = default;
|
||||
~Console() = default;
|
||||
|
||||
void AddLine(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
|
||||
|
||||
void Clear();
|
||||
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const EntityHandle& GetHistory() const;
|
||||
inline const EntityHandle& GetHistoryBackground() const;
|
||||
inline const EntityHandle& GetInput() const;
|
||||
inline const EntityHandle& GetInputBackground() const;
|
||||
inline const Nz::Vector2f& GetSize() const;
|
||||
inline const Nz::FontRef& GetTextFont() const;
|
||||
|
||||
inline bool IsVisible() const;
|
||||
|
||||
void SendCharacter(char32_t character);
|
||||
void SendEvent(Nz::WindowEvent event);
|
||||
|
||||
void SetCharacterSize(unsigned int size);
|
||||
void SetSize(const Nz::Vector2f& size);
|
||||
void SetTextFont(Nz::FontRef font);
|
||||
|
||||
void Show(bool show = true);
|
||||
|
||||
Console& operator=(const Console& console) = delete;
|
||||
Console& operator=(Console&& console) = default;
|
||||
|
||||
private:
|
||||
void AddLineInternal(const Nz::String& text, const Nz::Color& color = Nz::Color::White);
|
||||
void ExecuteInput();
|
||||
void Layout();
|
||||
void RefreshHistory();
|
||||
|
||||
struct Line
|
||||
{
|
||||
Nz::Color color;
|
||||
Nz::String text;
|
||||
};
|
||||
|
||||
std::size_t m_historyPosition;
|
||||
std::vector<Nz::String> m_commandHistory;
|
||||
std::vector<Line> m_historyLines;
|
||||
EntityOwner m_historyBackground;
|
||||
EntityOwner m_history;
|
||||
EntityOwner m_input;
|
||||
EntityOwner m_inputBackground;
|
||||
Nz::FontRef m_defaultFont;
|
||||
Nz::LuaInstance& m_instance;
|
||||
Nz::SpriteRef m_historyBackgroundSprite;
|
||||
Nz::SpriteRef m_inputBackgroundSprite;
|
||||
Nz::SimpleTextDrawer m_historyDrawer;
|
||||
Nz::SimpleTextDrawer m_inputDrawer;
|
||||
Nz::TextSpriteRef m_historyTextSprite;
|
||||
Nz::TextSpriteRef m_inputTextSprite;
|
||||
Nz::Vector2f m_size;
|
||||
bool m_opened;
|
||||
unsigned int m_characterSize;
|
||||
unsigned int m_maxHistoryLines;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Console.inl>
|
||||
|
||||
#endif // NDK_CONSOLE_HPP
|
||||
49
SDK/include/NDK/Console.inl
Normal file
49
SDK/include/NDK/Console.inl
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include "Console.hpp"
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline unsigned int Console::GetCharacterSize() const
|
||||
{
|
||||
return m_characterSize;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetHistory() const
|
||||
{
|
||||
return m_history;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetHistoryBackground() const
|
||||
{
|
||||
return m_historyBackground;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetInput() const
|
||||
{
|
||||
return m_input;
|
||||
}
|
||||
|
||||
inline const EntityHandle& Console::GetInputBackground() const
|
||||
{
|
||||
return m_inputBackground;
|
||||
}
|
||||
|
||||
inline const Nz::Vector2f& Console::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline const Nz::FontRef& Console::GetTextFont() const
|
||||
{
|
||||
return m_defaultFont;
|
||||
}
|
||||
|
||||
inline bool Console::IsVisible() const
|
||||
{
|
||||
return m_opened;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NDK_ENTITY_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@@ -15,13 +16,14 @@
|
||||
namespace Ndk
|
||||
{
|
||||
class BaseComponent;
|
||||
class EntityHandle;
|
||||
class Entity;
|
||||
class World;
|
||||
|
||||
class NDK_API Entity
|
||||
using EntityHandle = Nz::ObjectHandle<Entity>;
|
||||
|
||||
class NDK_API Entity : public Nz::HandledObject<Entity>
|
||||
{
|
||||
friend class BaseSystem;
|
||||
friend EntityHandle;
|
||||
friend World;
|
||||
|
||||
public:
|
||||
@@ -32,7 +34,7 @@ namespace Ndk
|
||||
BaseComponent& AddComponent(std::unique_ptr<BaseComponent>&& component);
|
||||
template<typename ComponentType, typename... Args> ComponentType& AddComponent(Args&&... args);
|
||||
|
||||
EntityHandle CreateHandle();
|
||||
inline void Enable(bool enable);
|
||||
|
||||
inline BaseComponent& GetComponent(ComponentIndex index);
|
||||
template<typename ComponentType> ComponentType& GetComponent();
|
||||
@@ -47,32 +49,36 @@ namespace Ndk
|
||||
void Kill();
|
||||
|
||||
void Invalidate();
|
||||
inline bool IsEnabled() const;
|
||||
inline bool IsValid() const;
|
||||
|
||||
void RemoveAllComponents();
|
||||
void RemoveComponent(ComponentIndex index);
|
||||
template<typename ComponentType> void RemoveComponent();
|
||||
|
||||
inline Nz::String ToString() const;
|
||||
|
||||
Entity& operator=(const Entity&) = delete;
|
||||
Entity& operator=(Entity&&) = delete;
|
||||
|
||||
private:
|
||||
Entity(World& world, EntityId id);
|
||||
Entity(World* world, EntityId id);
|
||||
|
||||
void Create();
|
||||
void Destroy();
|
||||
|
||||
inline void RegisterHandle(EntityHandle* handle);
|
||||
inline void RegisterSystem(SystemIndex index);
|
||||
inline void UnregisterHandle(EntityHandle* handle);
|
||||
|
||||
inline void SetWorld(World* world) noexcept;
|
||||
|
||||
inline void UnregisterSystem(SystemIndex index);
|
||||
|
||||
std::vector<std::unique_ptr<BaseComponent>> m_components;
|
||||
std::vector<EntityHandle*> m_handles;
|
||||
Nz::Bitset<> m_componentBits;
|
||||
Nz::Bitset<> m_systemBits;
|
||||
EntityId m_id;
|
||||
World* m_world;
|
||||
bool m_enabled;
|
||||
bool m_valid;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@@ -19,6 +20,15 @@ namespace Ndk
|
||||
return static_cast<ComponentType&>(AddComponent(std::move(ptr)));
|
||||
}
|
||||
|
||||
inline void Entity::Enable(bool enable)
|
||||
{
|
||||
if (m_enabled != enable)
|
||||
{
|
||||
m_enabled = enable;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
inline BaseComponent& Entity::GetComponent(ComponentIndex index)
|
||||
{
|
||||
///DOC: Le component doit être présent
|
||||
@@ -74,6 +84,11 @@ namespace Ndk
|
||||
return HasComponent(index);
|
||||
}
|
||||
|
||||
inline bool Entity::IsEnabled() const
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
inline bool Entity::IsValid() const
|
||||
{
|
||||
return m_valid;
|
||||
@@ -88,10 +103,10 @@ namespace Ndk
|
||||
RemoveComponent(index);
|
||||
}
|
||||
|
||||
inline void Entity::RegisterHandle(EntityHandle* handle)
|
||||
inline Nz::String Entity::ToString() const
|
||||
{
|
||||
///DOC: Un handle ne doit être enregistré qu'une fois, des erreurs se produisent s'il l'est plus d'une fois
|
||||
m_handles.push_back(handle);
|
||||
Nz::StringStream ss;
|
||||
return ss << "Entity(" << GetId() << ')';
|
||||
}
|
||||
|
||||
inline void Entity::RegisterSystem(SystemIndex index)
|
||||
@@ -99,14 +114,11 @@ namespace Ndk
|
||||
m_systemBits.UnboundedSet(index);
|
||||
}
|
||||
|
||||
inline void Entity::UnregisterHandle(EntityHandle* handle)
|
||||
inline void Entity::SetWorld(World* world) noexcept
|
||||
{
|
||||
///DOC: Un handle ne doit être libéré qu'une fois, et doit faire partie de la liste, sous peine de crash
|
||||
auto it = std::find(m_handles.begin(), m_handles.end(), handle);
|
||||
NazaraAssert(world, "An entity must be attached to a world at any time");
|
||||
|
||||
// On échange cet élément avec le dernier, et on diminue la taille du vector de 1
|
||||
std::swap(*it, m_handles.back());
|
||||
m_handles.pop_back();
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
inline void Entity::UnregisterSystem(SystemIndex index)
|
||||
@@ -114,3 +126,19 @@ namespace Ndk
|
||||
m_systemBits.UnboundedReset(index);
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Ndk::EntityHandle>
|
||||
{
|
||||
size_t operator()(const Ndk::EntityHandle& handle) const
|
||||
{
|
||||
// Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée
|
||||
// pour cette raison, nous devons hasher l'ID de l'entité (qui reste constante)
|
||||
Ndk::EntityId id = (handle.IsValid()) ? handle->GetId() : std::numeric_limits<Ndk::EntityId>::max();
|
||||
|
||||
return hash<Ndk::EntityId>()(id);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_ENTITYHANDLE_HPP
|
||||
#define NDK_ENTITYHANDLE_HPP
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <ostream>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class EntityHandle
|
||||
{
|
||||
friend Entity;
|
||||
|
||||
public:
|
||||
EntityHandle();
|
||||
explicit EntityHandle(Entity* entity);
|
||||
EntityHandle(const EntityHandle& handle);
|
||||
EntityHandle(EntityHandle&& handle);
|
||||
~EntityHandle();
|
||||
|
||||
Entity* GetEntity() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void Reset(Entity* entity = nullptr);
|
||||
void Reset(const EntityHandle& handle);
|
||||
void Reset(EntityHandle&& handle);
|
||||
|
||||
EntityHandle& Swap(EntityHandle& handle);
|
||||
|
||||
Nz::String ToString() const;
|
||||
|
||||
operator bool() const;
|
||||
operator Entity*() const;
|
||||
Entity* operator->() const;
|
||||
|
||||
EntityHandle& operator=(Entity* entity);
|
||||
EntityHandle& operator=(const EntityHandle& handle);
|
||||
EntityHandle& operator=(EntityHandle&& handle);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const EntityHandle& handle);
|
||||
|
||||
friend bool operator==(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator==(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator==(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator!=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator!=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator!=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator<(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator<=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator<=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator>(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
friend bool operator>=(const EntityHandle& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>=(const Entity& lhs, const EntityHandle& rhs);
|
||||
friend bool operator>=(const EntityHandle& lhs, const Entity& rhs);
|
||||
|
||||
static const EntityHandle InvalidHandle;
|
||||
|
||||
private:
|
||||
void OnEntityDestroyed();
|
||||
void OnEntityMoved(Entity* newEntity);
|
||||
|
||||
Entity* m_entity;
|
||||
};
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
void swap(Ndk::EntityHandle& lhs, Ndk::EntityHandle& rhs);
|
||||
}
|
||||
|
||||
#include <NDK/EntityHandle.inl>
|
||||
|
||||
#endif // NDK_ENTITYHANDLE_HPP
|
||||
@@ -1,280 +0,0 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline EntityHandle::EntityHandle() :
|
||||
m_entity(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
inline EntityHandle::EntityHandle(Entity* entity) :
|
||||
EntityHandle()
|
||||
{
|
||||
Reset(entity);
|
||||
}
|
||||
|
||||
inline EntityHandle::EntityHandle(const EntityHandle& handle) :
|
||||
EntityHandle()
|
||||
{
|
||||
Reset(handle);
|
||||
}
|
||||
|
||||
inline EntityHandle::EntityHandle(EntityHandle&& handle) :
|
||||
EntityHandle()
|
||||
{
|
||||
Reset(handle);
|
||||
}
|
||||
|
||||
inline EntityHandle::~EntityHandle()
|
||||
{
|
||||
Reset(nullptr);
|
||||
}
|
||||
|
||||
inline Entity* EntityHandle::GetEntity() const
|
||||
{
|
||||
return m_entity;
|
||||
}
|
||||
|
||||
inline bool EntityHandle::IsValid() const
|
||||
{
|
||||
return m_entity != nullptr;
|
||||
}
|
||||
|
||||
inline void EntityHandle::Reset(Entity* entity)
|
||||
{
|
||||
// Si nous avions déjà une entité, nous devons l'informer que nous ne pointons plus sur elle
|
||||
if (m_entity)
|
||||
m_entity->UnregisterHandle(this);
|
||||
|
||||
m_entity = entity;
|
||||
if (m_entity)
|
||||
// On informe la nouvelle entité que nous pointons sur elle
|
||||
m_entity->RegisterHandle(this);
|
||||
}
|
||||
|
||||
inline void EntityHandle::Reset(const EntityHandle& handle)
|
||||
{
|
||||
Reset(handle.GetEntity());
|
||||
}
|
||||
|
||||
inline void EntityHandle::Reset(EntityHandle&& handle)
|
||||
{
|
||||
Reset(handle.GetEntity());
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::Swap(EntityHandle& handle)
|
||||
{
|
||||
// Comme nous inversons les handles, nous devons prévenir les entités
|
||||
// La version par défaut de swap (à base de move) aurait fonctionné,
|
||||
// mais en enregistrant les handles une fois de plus que nécessaire (à cause de la copie temporaire).
|
||||
if (m_entity)
|
||||
{
|
||||
m_entity->UnregisterHandle(this);
|
||||
m_entity->RegisterHandle(&handle);
|
||||
}
|
||||
|
||||
if (handle.m_entity)
|
||||
{
|
||||
handle.m_entity->UnregisterHandle(&handle);
|
||||
handle.m_entity->RegisterHandle(this);
|
||||
}
|
||||
|
||||
// On effectue l'échange
|
||||
std::swap(m_entity, handle.m_entity);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Nz::String EntityHandle::ToString() const
|
||||
{
|
||||
Nz::StringStream ss;
|
||||
ss << "EntityHandle(";
|
||||
if (IsValid())
|
||||
ss << "Entity(" << m_entity->GetId() << ')';
|
||||
else
|
||||
ss << "Null entity";
|
||||
|
||||
ss << ')';
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline EntityHandle::operator bool() const
|
||||
{
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
inline EntityHandle::operator Entity*() const
|
||||
{
|
||||
return m_entity;
|
||||
}
|
||||
|
||||
inline Entity* EntityHandle::operator->() const
|
||||
{
|
||||
return m_entity;
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::operator=(Entity* entity)
|
||||
{
|
||||
Reset(entity);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::operator=(const EntityHandle& handle)
|
||||
{
|
||||
Reset(handle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline EntityHandle& EntityHandle::operator=(EntityHandle&& handle)
|
||||
{
|
||||
Reset(handle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void EntityHandle::OnEntityDestroyed()
|
||||
{
|
||||
// Un raccourci, un appel à Reset nous enlèverait de la liste des handles que nous ne pouvons pas modifier
|
||||
// maintenant car elle est actuellement parcourue
|
||||
m_entity = nullptr;
|
||||
}
|
||||
|
||||
inline void EntityHandle::OnEntityMoved(Entity* newEntity)
|
||||
{
|
||||
// L'entité a été déplacée (peut arriver lors d'un changement de taille du conteneur du monde)
|
||||
// nous mettons à jour notre pointeur
|
||||
m_entity = newEntity;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const EntityHandle& handle)
|
||||
{
|
||||
out << "EntityHandle(";
|
||||
if (handle.IsValid())
|
||||
out << "Entity(" << handle->GetId() << ')';
|
||||
else
|
||||
out << "Null entity";
|
||||
|
||||
out << ')';
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
inline bool operator==(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return lhs.m_entity == rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator==(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return &lhs == rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator==(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return lhs.m_entity == &rhs;
|
||||
}
|
||||
|
||||
inline bool operator!=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator!=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return lhs.m_entity < rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator<(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return &lhs < rhs.m_entity;
|
||||
}
|
||||
|
||||
inline bool operator<(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return lhs.m_entity < &rhs;
|
||||
}
|
||||
|
||||
inline bool operator<=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
inline bool operator>(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>=(const EntityHandle& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const Entity& lhs, const EntityHandle& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const EntityHandle& lhs, const Entity& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Ndk::EntityHandle>
|
||||
{
|
||||
size_t operator()(const Ndk::EntityHandle& handle) const
|
||||
{
|
||||
// Hasher le pointeur fonctionnerait jusqu'à ce que l'entité soit mise à jour et déplacée
|
||||
// pour cette raison, nous devons hasher l'ID de l'entité (qui reste constante)
|
||||
Ndk::EntityId id = (handle.IsValid()) ? handle->GetId() : std::numeric_limits<Ndk::EntityId>::max();
|
||||
|
||||
return hash<Ndk::EntityId>()(id);
|
||||
}
|
||||
};
|
||||
|
||||
inline void swap(Ndk::EntityHandle& lhs, Ndk::EntityHandle& rhs)
|
||||
{
|
||||
lhs.Swap(rhs);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace Ndk
|
||||
|
||||
std::swap(*it, m_entities.back());
|
||||
m_entities.pop_back(); // On le sort du vector
|
||||
m_entityBits.UnboundedSet(entity->GetId(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
34
SDK/include/NDK/EntityOwner.hpp
Normal file
34
SDK/include/NDK/EntityOwner.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_ENTITYOWNER_HPP
|
||||
#define NDK_ENTITYOWNER_HPP
|
||||
|
||||
#include <NDK/Entity.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class EntityOwner : public EntityHandle
|
||||
{
|
||||
public:
|
||||
EntityOwner() = default;
|
||||
explicit EntityOwner(Entity* entity);
|
||||
EntityOwner(const EntityOwner& handle) = delete;
|
||||
EntityOwner(EntityOwner&& handle);
|
||||
~EntityOwner();
|
||||
|
||||
void Reset(Entity* entity = nullptr);
|
||||
void Reset(EntityOwner&& handle);
|
||||
|
||||
EntityOwner& operator=(Entity* entity);
|
||||
EntityOwner& operator=(const EntityOwner& handle) = delete;
|
||||
EntityOwner& operator=(EntityOwner&& handle);
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/EntityOwner.inl>
|
||||
|
||||
#endif // NDK_ENTITYOwner_HPP
|
||||
62
SDK/include/NDK/EntityOwner.inl
Normal file
62
SDK/include/NDK/EntityOwner.inl
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline EntityOwner::EntityOwner(Entity* entity) :
|
||||
EntityOwner()
|
||||
{
|
||||
Reset(entity);
|
||||
}
|
||||
|
||||
inline EntityOwner::EntityOwner(EntityOwner&& handle) :
|
||||
EntityHandle(std::move(handle))
|
||||
{
|
||||
}
|
||||
|
||||
inline EntityOwner::~EntityOwner()
|
||||
{
|
||||
Reset(nullptr);
|
||||
}
|
||||
|
||||
inline void EntityOwner::Reset(Entity* entity)
|
||||
{
|
||||
if (m_object)
|
||||
m_object->Kill();
|
||||
|
||||
EntityHandle::Reset(entity);
|
||||
}
|
||||
|
||||
inline void EntityOwner::Reset(EntityOwner&& handle)
|
||||
{
|
||||
Reset(handle.GetObject());
|
||||
handle.m_object = nullptr;
|
||||
}
|
||||
|
||||
inline EntityOwner& EntityOwner::operator=(Entity* entity)
|
||||
{
|
||||
Reset(entity);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline EntityOwner& EntityOwner::operator=(EntityOwner&& handle)
|
||||
{
|
||||
Reset(std::move(handle));
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Ndk::EntityOwner> : public hash<Ndk::EntityHandle>
|
||||
{
|
||||
};
|
||||
}
|
||||
40
SDK/include/NDK/LuaAPI.hpp
Normal file
40
SDK/include/NDK/LuaAPI.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_LUAINTERFACE_HPP
|
||||
#define NDK_LUAINTERFACE_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class LuaInstance;
|
||||
}
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class LuaBinding;
|
||||
|
||||
class NDK_API LuaAPI
|
||||
{
|
||||
public:
|
||||
LuaAPI() = delete;
|
||||
~LuaAPI() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static void RegisterClasses(Nz::LuaInstance& instance);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static LuaBinding* s_binding;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/LuaAPI.inl>
|
||||
|
||||
#endif // NDK_LUAINTERFACE_HPP
|
||||
385
SDK/include/NDK/LuaAPI.inl
Normal file
385
SDK/include/NDK/LuaAPI.inl
Normal file
@@ -0,0 +1,385 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <NDK/Application.hpp>
|
||||
#include <NDK/Components.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/World.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <Nazara/Audio/Music.hpp>
|
||||
#include <Nazara/Audio/SoundBuffer.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <NDK/Console.hpp>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Color* color, TypeTag<Color>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
color->r = instance.CheckField<UInt8>("r", index);
|
||||
color->g = instance.CheckField<UInt8>("g", index);
|
||||
color->b = instance.CheckField<UInt8>("b", index);
|
||||
color->a = instance.CheckField<UInt8>("a", 255, index);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesd* angles, TypeTag<EulerAnglesd>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Table:
|
||||
angles->Set(instance.CheckField<double>("pitch", index), instance.CheckField<double>("yaw", index), instance.CheckField<double>("roll", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
{
|
||||
if (instance.IsOfType(index, "EulerAngles"))
|
||||
angles->Set(*(*static_cast<EulerAnglesd**>(instance.ToUserdata(index))));
|
||||
else
|
||||
angles->Set(*(*static_cast<Quaterniond**>(instance.CheckUserdata(index, "Quaternion"))));
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, EulerAnglesf* angles, TypeTag<EulerAnglesf>)
|
||||
{
|
||||
EulerAnglesd anglesDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &anglesDouble, TypeTag<EulerAnglesd>());
|
||||
|
||||
angles->Set(anglesDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaterniond* quat, TypeTag<Quaterniond>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Table:
|
||||
quat->Set(instance.CheckField<double>("w", index), instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
{
|
||||
if (instance.IsOfType(index, "EulerAngles"))
|
||||
quat->Set(*(*static_cast<EulerAnglesd**>(instance.ToUserdata(index))));
|
||||
else
|
||||
quat->Set(*(*static_cast<Quaterniond**>(instance.CheckUserdata(index, "Quaternion"))));
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Quaternionf* quat, TypeTag<Quaternionf>)
|
||||
{
|
||||
Quaterniond quatDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &quatDouble, TypeTag<Quaterniond>());
|
||||
|
||||
quat->Set(quatDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, IpAddress* address, TypeTag<IpAddress>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_String:
|
||||
address->BuildFromAddress(instance.CheckString(index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
*address = *(*static_cast<IpAddress**>(instance.CheckUserdata(index, "IpAddress")));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2d* vec, TypeTag<Vector2d>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
if (index < 0 && index > -2)
|
||||
instance.Error("Vector2 expected, two numbers are required to convert it");
|
||||
|
||||
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1));
|
||||
return 2;
|
||||
|
||||
case Nz::LuaType_Table:
|
||||
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
vec->Set(*(*static_cast<Vector2d**>(instance.CheckUserdata(index, "Vector2"))));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2f* vec, TypeTag<Vector2f>)
|
||||
{
|
||||
Vector2d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector2ui* vec, TypeTag<Vector2ui>)
|
||||
{
|
||||
Vector2d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector2d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3d* vec, TypeTag<Vector3d>)
|
||||
{
|
||||
switch (instance.GetType(index))
|
||||
{
|
||||
case Nz::LuaType_Number:
|
||||
if (index < 0 && index > -3)
|
||||
instance.Error("Vector3 expected, three numbers are required to convert it");
|
||||
|
||||
vec->Set(instance.CheckNumber(index), instance.CheckNumber(index + 1), instance.CheckNumber(index + 2, 0.0));
|
||||
return 3;
|
||||
|
||||
case Nz::LuaType_Table:
|
||||
vec->Set(instance.CheckField<double>("x", index), instance.CheckField<double>("y", index), instance.CheckField<double>("z", 0.0, index));
|
||||
return 1;
|
||||
|
||||
default:
|
||||
vec->Set(*(*static_cast<Vector3d**>(instance.CheckUserdata(index, "Vector3"))));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3f* vec, TypeTag<Vector3f>)
|
||||
{
|
||||
Vector3d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Vector3ui* vec, TypeTag<Vector3ui>)
|
||||
{
|
||||
Vector3d vecDouble;
|
||||
unsigned int ret = LuaImplQueryArg(instance, index, &vecDouble, TypeTag<Vector3d>());
|
||||
|
||||
vec->Set(vecDouble);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, InstancedRenderableRef* renderable, TypeTag<InstancedRenderableRef>)
|
||||
{
|
||||
if (instance.IsOfType(index, "InstancedRenderable"))
|
||||
*renderable = *(*static_cast<InstancedRenderableRef**>(instance.CheckUserdata(index, "InstancedRenderable")));
|
||||
else
|
||||
*renderable = *(*static_cast<InstancedRenderableRef**>(instance.CheckUserdata(index, "Model")));
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MaterialParams* params, TypeTag<MaterialParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->loadAlphaMap = instance.CheckField<bool>("LoadAlphaMap", params->loadAlphaMap);
|
||||
params->loadDiffuseMap = instance.CheckField<bool>("LoadDiffuseMap", params->loadDiffuseMap);
|
||||
params->loadEmissiveMap = instance.CheckField<bool>("LoadEmissiveMap", params->loadEmissiveMap);
|
||||
params->loadHeightMap = instance.CheckField<bool>("LoadHeightMap", params->loadHeightMap);
|
||||
params->loadNormalMap = instance.CheckField<bool>("LoadNormalMap", params->loadNormalMap);
|
||||
params->loadSpecularMap = instance.CheckField<bool>("LoadSpecularMap", params->loadSpecularMap);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MeshParams* params, TypeTag<MeshParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->animated = instance.CheckField<bool>("Animated", params->animated);
|
||||
params->center = instance.CheckField<bool>("Center", params->center);
|
||||
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
|
||||
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
|
||||
params->scale = instance.CheckField<Vector3f>("Scale", params->scale);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, ModelParameters* params, TypeTag<ModelParameters>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->loadMaterials = instance.CheckField<bool>("LoadMaterials", params->loadMaterials);
|
||||
|
||||
LuaImplQueryArg(instance, -1, ¶ms->material, TypeTag<MaterialParams>());
|
||||
LuaImplQueryArg(instance, -1, ¶ms->mesh, TypeTag<MeshParams>());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, MusicParams* params, TypeTag<MusicParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->forceMono = instance.CheckField<bool>("ForceMono", params->forceMono);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, SoundBufferParams* params, TypeTag<SoundBufferParams>)
|
||||
{
|
||||
instance.CheckType(index, Nz::LuaType_Table);
|
||||
|
||||
params->forceMono = instance.CheckField<bool>("ForceMono", params->forceMono);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesd val, TypeTag<EulerAnglesd>)
|
||||
{
|
||||
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, EulerAnglesf val, TypeTag<EulerAnglesf>)
|
||||
{
|
||||
instance.PushInstance<EulerAnglesd>("EulerAngles", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Quaterniond val, TypeTag<Quaterniond>)
|
||||
{
|
||||
instance.PushInstance<Quaterniond>("Quaternion", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Quaternionf val, TypeTag<Quaternionf>)
|
||||
{
|
||||
instance.PushInstance<Quaterniond>("Quaternion", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, IpAddress val, TypeTag<IpAddress>)
|
||||
{
|
||||
instance.PushInstance<IpAddress>("IpAddress", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2d val, TypeTag<Vector2d>)
|
||||
{
|
||||
instance.PushInstance<Vector2d>("Vector2", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2f val, TypeTag<Vector2f>)
|
||||
{
|
||||
instance.PushInstance<Vector2d>("Vector2", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector2ui val, TypeTag<Vector2ui>)
|
||||
{
|
||||
instance.PushInstance<Vector2d>("Vector2", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3d val, TypeTag<Vector3d>)
|
||||
{
|
||||
instance.PushInstance<Vector3d>("Vector3", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3f val, TypeTag<Vector3f>)
|
||||
{
|
||||
instance.PushInstance<Vector3d>("Vector3", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Vector3ui val, TypeTag<Vector3ui>)
|
||||
{
|
||||
instance.PushInstance<Vector3d>("Vector3", val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Entity* ptr, TypeTag<Ndk::Entity*>)
|
||||
{
|
||||
instance.PushInstance<Ndk::EntityHandle>("Entity", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::Application* ptr, TypeTag<Ndk::Application*>)
|
||||
{
|
||||
instance.PushInstance<Ndk::Application*>("Application", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::EntityHandle handle, TypeTag<Ndk::EntityHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::EntityHandle>("Entity", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::NodeComponentHandle handle, TypeTag<Ndk::NodeComponentHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::NodeComponentHandle>("NodeComponent", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::VelocityComponentHandle handle, TypeTag<Ndk::VelocityComponentHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::VelocityComponentHandle>("VelocityComponent", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::World* ptr, TypeTag<Ndk::World*>)
|
||||
{
|
||||
instance.PushInstance<Ndk::WorldHandle>("World", ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::WorldHandle handle, TypeTag<Ndk::WorldHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::WorldHandle>("World", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::ConsoleHandle handle, TypeTag<Ndk::ConsoleHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::ConsoleHandle>("Console", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, Ndk::GraphicsComponentHandle handle, TypeTag<Ndk::GraphicsComponentHandle>)
|
||||
{
|
||||
instance.PushInstance<Ndk::GraphicsComponentHandle>("GraphicsComponent", handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, const SoundBuffer* val, TypeTag<const SoundBuffer*>)
|
||||
{
|
||||
instance.PushInstance<SoundBufferConstRef>("SoundBuffer", val);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
28
SDK/include/NDK/State.hpp
Normal file
28
SDK/include/NDK/State.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_STATE_HPP
|
||||
#define NDK_STATE_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class StateMachine;
|
||||
|
||||
class State
|
||||
{
|
||||
public:
|
||||
State();
|
||||
~State();
|
||||
|
||||
virtual void Enter(StateMachine& fsm) = 0;
|
||||
virtual void Leave(StateMachine& fsm) = 0;
|
||||
virtual bool Update(StateMachine& fsm, float elapsedTime) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NDK_STATE_HPP
|
||||
39
SDK/include/NDK/StateMachine.hpp
Normal file
39
SDK/include/NDK/StateMachine.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_STATEMACHINE_HPP
|
||||
#define NDK_STATEMACHINE_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
#include <NDK/State.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class StateMachine
|
||||
{
|
||||
public:
|
||||
inline StateMachine(std::shared_ptr<State> originalState);
|
||||
StateMachine(const StateMachine&) = delete;
|
||||
inline StateMachine(StateMachine&& fsm) = default;
|
||||
inline ~StateMachine();
|
||||
|
||||
inline void ChangeState(std::shared_ptr<State> state);
|
||||
|
||||
inline bool Update(float elapsedTime);
|
||||
|
||||
inline StateMachine& operator=(StateMachine&& fsm) = default;
|
||||
StateMachine& operator=(const StateMachine&) = delete;
|
||||
|
||||
private:
|
||||
std::shared_ptr<State> m_currentState;
|
||||
std::shared_ptr<State> m_nextState;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/StateMachine.inl>
|
||||
|
||||
#endif // NDK_STATEMACHINE_HPP
|
||||
40
SDK/include/NDK/StateMachine.inl
Normal file
40
SDK/include/NDK/StateMachine.inl
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/StateMachine.hpp>
|
||||
#include <utility>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline StateMachine::StateMachine(std::shared_ptr<State> originalState) :
|
||||
m_currentState(std::move(originalState))
|
||||
{
|
||||
NazaraAssert(m_currentState, "StateMachine must have a state to begin with");
|
||||
m_currentState->Enter(*this);
|
||||
}
|
||||
|
||||
inline StateMachine::~StateMachine()
|
||||
{
|
||||
m_currentState->Leave(*this);
|
||||
}
|
||||
|
||||
|
||||
inline void StateMachine::ChangeState(std::shared_ptr<State> state)
|
||||
{
|
||||
m_nextState = std::move(state);
|
||||
}
|
||||
|
||||
inline bool StateMachine::Update(float elapsedTime)
|
||||
{
|
||||
if (m_nextState)
|
||||
{
|
||||
m_currentState->Leave(*this);
|
||||
m_currentState = std::move(m_nextState);
|
||||
m_currentState->Enter(*this);
|
||||
}
|
||||
|
||||
return m_currentState->Update(*this, elapsedTime);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Ndk/Algorithm.hpp>
|
||||
#include <NDK/Algorithm.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Ndk
|
||||
|
||||
16
SDK/include/NDK/Systems.hpp
Normal file
16
SDK/include/NDK/Systems.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
// This file was automatically generated on 03 Mar 2016 at 14:09:12
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SYSTEMS_GLOBAL_HPP
|
||||
#define NDK_SYSTEMS_GLOBAL_HPP
|
||||
|
||||
#include <NDK/Systems/PhysicsSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
#ifndef NDK_SERVER
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/RenderSystem.hpp>
|
||||
#endif
|
||||
|
||||
#endif // NDK_SYSTEMS_GLOBAL_HPP
|
||||
@@ -27,11 +27,15 @@ namespace Ndk
|
||||
inline RenderSystem(const RenderSystem& renderSystem);
|
||||
~RenderSystem() = default;
|
||||
|
||||
template<typename T> void ChangeRenderTechnique();
|
||||
inline void ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique);
|
||||
|
||||
inline const Nz::BackgroundRef& GetDefaultBackground() const;
|
||||
inline const Nz::Matrix4f& GetCoordinateSystemMatrix() const;
|
||||
inline Nz::Vector3f GetGlobalForward() const;
|
||||
inline Nz::Vector3f GetGlobalRight() const;
|
||||
inline Nz::Vector3f GetGlobalUp() const;
|
||||
inline Nz::AbstractRenderTechnique& GetRenderTechnique() const;
|
||||
|
||||
inline void SetDefaultBackground(Nz::BackgroundRef background);
|
||||
inline void SetGlobalForward(const Nz::Vector3f& direction);
|
||||
@@ -49,6 +53,7 @@ namespace Ndk
|
||||
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
|
||||
void UpdatePointSpotShadowMaps();
|
||||
|
||||
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
|
||||
EntityList m_cameras;
|
||||
EntityList m_drawables;
|
||||
EntityList m_directionalLights;
|
||||
@@ -56,7 +61,6 @@ namespace Ndk
|
||||
EntityList m_pointSpotLights;
|
||||
Nz::BackgroundRef m_background;
|
||||
Nz::DepthRenderTechnique m_shadowTechnique;
|
||||
Nz::ForwardRenderTechnique m_renderTechnique;
|
||||
Nz::Matrix4f m_coordinateSystemMatrix;
|
||||
Nz::RenderTexture m_shadowRT;
|
||||
bool m_coordinateSystemInvalidated;
|
||||
|
||||
@@ -9,6 +9,17 @@ namespace Ndk
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void RenderSystem::ChangeRenderTechnique()
|
||||
{
|
||||
ChangeRenderTechnique(std::make_unique<T>());
|
||||
}
|
||||
|
||||
inline void RenderSystem::ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique)
|
||||
{
|
||||
m_renderTechnique = std::move(renderTechnique);
|
||||
}
|
||||
|
||||
inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const
|
||||
{
|
||||
return m_background;
|
||||
@@ -34,6 +45,11 @@ namespace Ndk
|
||||
return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32);
|
||||
}
|
||||
|
||||
inline Nz::AbstractRenderTechnique& RenderSystem::GetRenderTechnique() const
|
||||
{
|
||||
return *m_renderTechnique.get();
|
||||
}
|
||||
|
||||
inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background)
|
||||
{
|
||||
m_background = std::move(background);
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#define NDK_WORLD_HPP
|
||||
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
#include <NDK/EntityHandle.hpp>
|
||||
#include <NDK/System.hpp>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
@@ -18,7 +18,11 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API World
|
||||
class World;
|
||||
|
||||
using WorldHandle = Nz::ObjectHandle<World>;
|
||||
|
||||
class NDK_API World : public Nz::HandledObject<World>
|
||||
{
|
||||
friend Entity;
|
||||
|
||||
@@ -27,8 +31,8 @@ namespace Ndk
|
||||
|
||||
inline World(bool addDefaultSystems = true);
|
||||
World(const World&) = delete;
|
||||
World(World&&) = delete; ///TODO
|
||||
~World();
|
||||
inline World(World&& world) noexcept;
|
||||
~World() noexcept;
|
||||
|
||||
void AddDefaultSystems();
|
||||
|
||||
@@ -38,7 +42,7 @@ namespace Ndk
|
||||
const EntityHandle& CreateEntity();
|
||||
inline EntityList CreateEntities(unsigned int count);
|
||||
|
||||
void Clear();
|
||||
void Clear() noexcept;
|
||||
|
||||
const EntityHandle& GetEntity(EntityId id);
|
||||
inline const EntityList& GetEntities();
|
||||
@@ -62,7 +66,7 @@ namespace Ndk
|
||||
inline void Update(float elapsedTime);
|
||||
|
||||
World& operator=(const World&) = delete;
|
||||
World& operator=(World&&) = delete; ///TODO
|
||||
inline World& operator=(World&& world) noexcept;
|
||||
|
||||
private:
|
||||
inline void Invalidate();
|
||||
|
||||
@@ -13,6 +13,12 @@ namespace Ndk
|
||||
AddDefaultSystems();
|
||||
}
|
||||
|
||||
inline World::World(World&& world) noexcept :
|
||||
HandledObject(std::move(world))
|
||||
{
|
||||
operator=(std::move(world));
|
||||
}
|
||||
|
||||
inline BaseSystem& World::AddSystem(std::unique_ptr<BaseSystem>&& system)
|
||||
{
|
||||
NazaraAssert(system, "System must be valid");
|
||||
@@ -25,7 +31,7 @@ namespace Ndk
|
||||
|
||||
// Affectation et retour du système
|
||||
m_systems[index] = std::move(system);
|
||||
m_systems[index]->SetWorld(*this);
|
||||
m_systems[index]->SetWorld(this);
|
||||
|
||||
Invalidate(); // On force une mise à jour de toutes les entités
|
||||
|
||||
@@ -152,4 +158,22 @@ namespace Ndk
|
||||
{
|
||||
m_dirtyEntities.UnboundedSet(id, true);
|
||||
}
|
||||
|
||||
inline World& World::operator=(World&& world) noexcept
|
||||
{
|
||||
m_aliveEntities = std::move(world.m_aliveEntities);
|
||||
m_dirtyEntities = std::move(world.m_dirtyEntities);
|
||||
m_freeIdList = std::move(world.m_freeIdList);
|
||||
m_killedEntities = std::move(world.m_killedEntities);
|
||||
|
||||
m_entities = std::move(world.m_entities);
|
||||
for (EntityBlock& block : m_entities)
|
||||
block.entity.SetWorld(this);
|
||||
|
||||
m_systems = std::move(world.m_systems);
|
||||
for (const auto& systemPtr : m_systems)
|
||||
systemPtr->SetWorld(this);
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user