Move SDK include and source to base

This commit is contained in:
Lynix
2020-02-24 18:23:30 +01:00
parent f0d11aea72
commit b6b3ac9f31
149 changed files with 34 additions and 33 deletions

View File

@@ -1,25 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_ALGORITHM_HPP
#define NDK_ALGORITHM_HPP
#include <NazaraSDK/Prerequisites.hpp>
namespace Ndk
{
template<unsigned int N> ComponentId BuildComponentId(const char (&name)[N]);
template<typename ComponentType> ComponentIndex GetComponentIndex();
template<typename SystemType> SystemIndex GetSystemIndex();
template<typename ComponentType, unsigned int N> ComponentIndex InitializeComponent(const char (&name)[N]);
template<typename SystemType> SystemIndex InitializeSystem();
template<typename ComponentType, typename C> bool IsComponent(C& component);
template<typename SystemType, typename S> bool IsSystem(S& system);
}
#include <NazaraSDK/Algorithm.inl>
#endif // NDK_ALGORITHM_HPP

View File

@@ -1,107 +0,0 @@
// 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 Prerequisites.hpp
#include <Nazara/Core/Endianness.hpp>
namespace Ndk
{
/*!
* \ingroup NDK
* \brief Builds a component id based on a name
* \return Identifier for the component
*
* \param name Name to generate id from
*/
///TODO: constexpr with the C++14
template<unsigned int N>
ComponentId BuildComponentId(const char (&name)[N])
{
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 - 1; ++i)
componentId |= static_cast<ComponentId>(name[i]) << i*8;
return componentId;
}
/*!
* \ingroup NDK
* \brief Gets the component id of a component
* \return Identifier for the component
*/
template<typename ComponentType>
ComponentIndex GetComponentIndex()
{
return ComponentType::componentIndex;
}
/*!
* \ingroup NDK
* \brief Gets the system id of a system
* \return Identifier for the system
*/
template<typename SystemType>
SystemIndex GetSystemIndex()
{
return SystemType::systemIndex;
}
/*!
* \ingroup NDK
* \brief Initializes the a component
* \return Identifier for the component
*
* \param name Name to generate id from
*/
template<typename ComponentType, unsigned int N>
ComponentIndex InitializeComponent(const char (&name)[N])
{
ComponentType::componentIndex = ComponentType::RegisterComponent(name);
return ComponentType::componentIndex;
}
/*!
* \ingroup NDK
* \brief Initializes the a system
* \return Identifier for the system
*/
template<typename SystemType>
SystemIndex InitializeSystem()
{
SystemType::systemIndex = SystemType::RegisterSystem();
return SystemType::systemIndex;
}
/*!
* \brief Checks whether the parameter is a component
* \return true If it is the case
*
* \param component Component to check
*/
template<typename ComponentType, typename C>
bool IsComponent(C& component)
{
return component.GetIndex() == GetComponentIndex<ComponentType>();
}
/*!
* \brief Checks whether the parameter is a system
* \return true If it is the case
*
* \param system System to check
*/
template<typename SystemType, typename S>
bool IsSystem(S& system)
{
return system.GetIndex() == GetSystemIndex<SystemType>();
}
}

View File

@@ -1,149 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_APPLICATION_HPP
#define NDK_APPLICATION_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/World.hpp>
#include <Nazara/Core/Clock.hpp>
#include <map>
#include <list>
#include <set>
#ifndef NDK_SERVER
#include <NazaraSDK/Canvas.hpp>
#include <NazaraSDK/Console.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Platform/Window.hpp>
#endif
namespace Ndk
{
class NDK_API Application
{
public:
#ifndef NDK_SERVER
struct ConsoleOverlay;
struct FPSCounterOverlay;
#endif
inline Application();
Application(int argc, char* argv[]);
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);
#ifndef NDK_SERVER
inline void EnableConsole(bool enable);
inline void EnableFPSCounter(bool enable);
inline ConsoleOverlay& GetConsoleOverlay(std::size_t windowIndex = 0U);
inline FPSCounterOverlay& GetFPSCounterOverlay(std::size_t windowIndex = 0U);
#endif
inline const std::set<Nz::String>& GetOptions() const;
inline const std::map<Nz::String, Nz::String>& GetParameters() const;
inline float GetUpdateTime() const;
inline bool HasOption(const Nz::String& option) const;
inline bool HasParameter(const Nz::String& key, Nz::String* value) const;
#ifndef NDK_SERVER
inline bool IsConsoleEnabled() const;
inline bool IsFPSCounterEnabled() const;
#endif
bool Run();
#ifndef NDK_SERVER
inline void MakeExitOnLastWindowClosed(bool exitOnClosedWindows);
#endif
inline void Quit();
Application& operator=(const Application&) = delete;
Application& operator=(Application&&) = delete;
inline static Application* Instance();
#ifndef NDK_SERVER
struct ConsoleOverlay
{
Console* console;
NazaraSlot(Nz::EventHandler, OnEvent, eventSlot);
NazaraSlot(Nz::EventHandler, OnKeyPressed, keyPressedSlot);
NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, resizedSlot);
NazaraSlot(Nz::Log, OnLogWrite, logSlot);
};
struct FPSCounterOverlay
{
Nz::TextSpriteRef sprite;
EntityOwner entity;
float elapsedTime = 0.f;
unsigned int frameCount = 0;
};
#endif
private:
#ifndef NDK_SERVER
enum OverlayFlags
{
OverlayFlags_Console = 0x1,
OverlayFlags_FPSCounter = 0x2
};
struct WindowInfo
{
inline WindowInfo(std::unique_ptr<Nz::Window>&& window);
Nz::RenderTarget* renderTarget;
std::unique_ptr<Nz::Window> window;
std::unique_ptr<ConsoleOverlay> console;
std::unique_ptr<Canvas> canvas;
std::unique_ptr<FPSCounterOverlay> fpsCounter;
std::unique_ptr<World> overlayWorld;
};
void SetupConsole(WindowInfo& info);
void SetupFPSCounter(WindowInfo& info);
void SetupOverlay(WindowInfo& info);
template<typename T> void SetupWindow(WindowInfo& info, T* renderTarget, std::true_type /*isRenderTarget*/);
template<typename T> void SetupWindow(WindowInfo& /*info*/, T* /*renderTarget*/, std::false_type /*isNotRenderTarget*/);
std::vector<WindowInfo> m_windows;
#endif
std::map<Nz::String, Nz::String> m_parameters;
std::set<Nz::String> m_options;
std::list<World> m_worlds;
Nz::Clock m_updateClock;
#ifndef NDK_SERVER
Nz::UInt32 m_overlayFlags;
bool m_exitOnClosedWindows;
#endif
bool m_shouldQuit;
float m_updateTime;
static Application* s_application;
};
}
#include <NazaraSDK/Application.inl>
#endif // NDK_APPLICATION_HPP

View File

@@ -1,379 +0,0 @@
// 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 Prerequisites.hpp
#include <Nazara/Core/ErrorFlags.hpp>
#include <NazaraSDK/Sdk.hpp>
namespace Ndk
{
/*!
* \brief Constructs an Application object without passing command-line arguments
*
* This calls Sdk::Initialize()
*
* \remark Only one Application instance can exist at a time
*/
inline Application::Application() :
#ifndef NDK_SERVER
m_overlayFlags(0U),
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
Sdk::Initialize();
}
/*!
* \brief Destructs the application object
*
* This destroy all worlds and windows and then calls Sdk::Uninitialize
*/
inline Application::~Application()
{
m_worlds.clear();
#ifndef NDK_SERVER
m_windows.clear();
#endif
// Free of SDK
Sdk::Uninitialize();
// Automatic free of modules
s_application = nullptr;
}
/*!
* \brief Adds a window to the application
* \return A reference to the newly created windows
*
* \param args Arguments used to create the window
*/
#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(std::make_unique<T>(std::forward<Args>(args)...));
WindowInfo& info = m_windows.back();
T& window = static_cast<T&>(*info.window.get()); //< Warning: ugly
SetupWindow(info, &window, std::is_base_of<Nz::RenderTarget, T>());
return window;
}
#endif
/*!
* \brief Adds a world to the application
* \return A reference to the newly created world
*
* \param args Arguments used to create the world
*/
template<typename... Args>
World& Application::AddWorld(Args&&... args)
{
m_worlds.emplace_back(std::forward<Args>(args)...);
return m_worlds.back();
}
/*!
* \brief Enable/disable debug console
*
* \param enable Should the console overlay be enabled
*/
#ifndef NDK_SERVER
inline void Application::EnableConsole(bool enable)
{
if (enable != ((m_overlayFlags & OverlayFlags_Console) != 0))
{
if (enable)
{
if (m_overlayFlags == 0)
{
for (WindowInfo& info : m_windows)
SetupOverlay(info);
}
for (WindowInfo& info : m_windows)
{
if (info.renderTarget)
SetupConsole(info);
}
m_overlayFlags |= OverlayFlags_Console;
}
else
{
for (WindowInfo& info : m_windows)
info.console.reset();
m_overlayFlags &= ~OverlayFlags_Console;
if (m_overlayFlags == 0)
{
for (WindowInfo& info : m_windows)
info.overlayWorld.reset();
}
}
}
}
#endif
/*!
* \brief Enable/disable debug FPS counter
*
* \param enable Should the FPS counter be displayed
*/
#ifndef NDK_SERVER
inline void Application::EnableFPSCounter(bool enable)
{
if (enable != ((m_overlayFlags & OverlayFlags_FPSCounter) != 0))
{
if (enable)
{
if (m_overlayFlags == 0)
{
for (WindowInfo& info : m_windows)
SetupOverlay(info);
}
for (WindowInfo& info : m_windows)
{
if (info.renderTarget)
SetupFPSCounter(info);
}
m_overlayFlags |= OverlayFlags_FPSCounter;
}
else
{
for (WindowInfo& info : m_windows)
info.fpsCounter.reset();
m_overlayFlags &= ~OverlayFlags_FPSCounter;
if (m_overlayFlags == 0)
{
for (WindowInfo& info : m_windows)
info.overlayWorld.reset();
}
}
}
}
#endif
/*!
* \brief Gets the console overlay for a specific window
*
* \param windowIndex Index of the window to get
*
* \remark The console overlay must be enabled
*
* \return A reference to the console overlay of the window
*
* \see IsConsoleOverlayEnabled
*/
#ifndef NDK_SERVER
inline Application::ConsoleOverlay& Application::GetConsoleOverlay(std::size_t windowIndex)
{
NazaraAssert(m_overlayFlags & OverlayFlags_Console, "Console overlay is not enabled");
NazaraAssert(windowIndex <= m_windows.size(), "Window index is out of range");
return *m_windows[windowIndex].console;
}
#endif
/*!
* \brief Gets the console overlay for a specific window
*
* \param windowIndex Index of the window to get
*
* \remark The console overlay must be enabled
*
* \return A reference to the console overlay of the window
*
* \see IsFPSCounterEnabled
*/
#ifndef NDK_SERVER
inline Application::FPSCounterOverlay& Application::GetFPSCounterOverlay(std::size_t windowIndex)
{
NazaraAssert(m_overlayFlags & OverlayFlags_FPSCounter, "FPS counter overlay is not enabled");
NazaraAssert(windowIndex <= m_windows.size(), "Window index is out of range");
return *m_windows[windowIndex].fpsCounter;
}
#endif
/*!
* \brief Gets the options used to start the application
*
* Options are defined as "-optionName" in command-line and are always lower-case
*
* \return Command-line options
*/
inline const std::set<Nz::String>& Application::GetOptions() const
{
return m_options;
}
/*!
* \brief Gets the parameters used to start the application
*
* Parameters are defined as "-key=value" in command-line, their key is lower-case but value capitals are kept.
*
* \return Command-line parameters
*/
inline const std::map<Nz::String, Nz::String>& Application::GetParameters() const
{
return m_parameters;
}
/*!
* \brief Gets the update time of the application
* \return Update rate
*/
inline float Application::GetUpdateTime() const
{
return m_updateTime;
}
/*!
* \brief Query for a command-line option
*
* \param option Option name
*
* \remark option must be lower-case
*
* \return True if option is present
*
* \see GetOptions
*/
inline bool Application::HasOption(const Nz::String& option) const
{
return m_options.count(option) != 0;
}
/*!
* \brief Query for a command-line option
*
* \param key Parameter name
* \param value Optional string to receive the parameter value
*
* \remark key must be lower-case
*
* \return True if parameter is present
*
* \see GetParameters
*/
inline bool Application::HasParameter(const Nz::String& key, Nz::String* value) const
{
auto it = m_parameters.find(key);
if (it == m_parameters.end())
return false;
if (value)
*value = it->second;
return true;
}
/*!
* \brief Checks if the console overlay is enabled
*
* \remark This has nothing to do with the visibility state of the console
*
* \return True if the console overlay is enabled
*
* \see GetConsoleOverlay
*/
#ifndef NDK_SERVER
inline bool Application::IsConsoleEnabled() const
{
return (m_overlayFlags & OverlayFlags_Console) != 0;
}
#endif
/*!
* \brief Checks if the FPS counter overlay is enabled
* \return True if the FPS counter overlay is enabled
*
* \see GetFPSCounterOverlay
*/
#ifndef NDK_SERVER
inline bool Application::IsFPSCounterEnabled() const
{
return (m_overlayFlags & OverlayFlags_FPSCounter) != 0;
}
#endif
/*!
* \brief Makes the application exit when there's no more open window
*
* \param exitOnClosedWindows Should exit be called when no more window is open
*/
#ifndef NDK_SERVER
inline void Application::MakeExitOnLastWindowClosed(bool exitOnClosedWindows)
{
m_exitOnClosedWindows = exitOnClosedWindows;
}
#endif
/*!
* \brief Quits the application
*/
inline void Application::Quit()
{
m_shouldQuit = true;
}
/*!
* \brief Gets the singleton instance of the application
* \return Singleton application
*/
inline Application* Application::Instance()
{
return s_application;
}
#ifndef NDK_SERVER
template<typename T>
inline void Application::SetupWindow(WindowInfo& info, T* renderTarget, std::true_type)
{
info.renderTarget = renderTarget;
if (m_overlayFlags)
{
SetupOverlay(info);
if (m_overlayFlags & OverlayFlags_Console)
SetupConsole(info);
if (m_overlayFlags & OverlayFlags_FPSCounter)
SetupFPSCounter(info);
}
}
template<typename T>
inline void Application::SetupWindow(WindowInfo&, T*, std::false_type)
{
}
inline Application::WindowInfo::WindowInfo(std::unique_ptr<Nz::Window>&& windowPtr) :
renderTarget(nullptr),
window(std::move(windowPtr))
{
}
#endif
}

View File

@@ -1,74 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_BASECOMPONENT_HPP
#define NDK_BASECOMPONENT_HPP
#include <NazaraSDK/Entity.hpp>
#include <functional>
#include <unordered_map>
#include <vector>
namespace Ndk
{
class NDK_API BaseComponent
{
friend Entity;
friend class Sdk;
public:
using Factory = std::function<BaseComponent*()>;
BaseComponent(ComponentIndex componentIndex);
BaseComponent(BaseComponent&&) noexcept = default;
virtual ~BaseComponent();
virtual std::unique_ptr<BaseComponent> Clone() const = 0;
inline const EntityHandle& GetEntity() const;
ComponentIndex GetIndex() const;
inline static ComponentIndex GetMaxComponentIndex();
BaseComponent& operator=(const BaseComponent&) = delete;
BaseComponent& operator=(BaseComponent&&) noexcept = default;
protected:
BaseComponent(const BaseComponent&) = default;
ComponentIndex m_componentIndex;
EntityHandle m_entity;
static ComponentIndex RegisterComponent(ComponentId id, Factory factoryFunc);
private:
virtual void OnAttached();
virtual void OnComponentAttached(BaseComponent& component);
virtual void OnComponentDetached(BaseComponent& component);
virtual void OnDetached();
virtual void OnEntityDestruction();
virtual void OnEntityDisabled();
virtual void OnEntityEnabled();
void SetEntity(Entity* entity);
static bool Initialize();
static void Uninitialize();
struct ComponentEntry
{
ComponentId id;
Factory factory;
};
static std::vector<ComponentEntry> s_entries;
static std::unordered_map<ComponentId, ComponentIndex> s_idToIndex;
};
}
#include <NazaraSDK/BaseComponent.inl>
#endif // NDK_BASECOMPONENT_HPP

View File

@@ -1,115 +0,0 @@
// 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 Prerequisites.hpp
#include <Nazara/Core/Error.hpp>
namespace Ndk
{
/*!
* \brief Constructs a BaseComponent object with an index
*
* \param index Index of the component
*/
inline BaseComponent::BaseComponent(ComponentIndex index) :
m_componentIndex(index),
m_entity(nullptr)
{
}
/*!
* \brief Gets the entity owning this component
* \return A handle to the entity owning this component, may be invalid if no entity owns it.
*/
inline const EntityHandle& BaseComponent::GetEntity() const
{
return m_entity;
}
/*!
* \brief Gets the index of the component
* \return Index of the component
*/
inline ComponentIndex BaseComponent::GetIndex() const
{
return m_componentIndex;
}
/*!
* \brief Gets the maximal index of the components
* \return Index of the maximal component
*/
inline ComponentIndex BaseComponent::GetMaxComponentIndex()
{
return static_cast<ComponentIndex>(s_entries.size());
}
/*!
* \brief Registers a component
* \return Index of the registered component
*
* \param id Index of the component
* \param factory Factory to create the component
*
* \remark Produces a NazaraAssert if the identifier is already in use
*/
inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc)
{
// We add our component to the end
ComponentIndex index = static_cast<ComponentIndex>(s_entries.size());
s_entries.resize(index + 1);
// We retrieve it and affect it
ComponentEntry& entry = s_entries.back();
entry.factory = factoryFunc;
entry.id = id;
// We ensure that id is not already in use
NazaraAssert(s_idToIndex.find(id) == s_idToIndex.end(), "This id is already in use");
s_idToIndex[id] = index;
return index;
}
/*!
* \brief Sets the entity on which the component operates
*/
inline void BaseComponent::SetEntity(Entity* entity)
{
if (m_entity != entity)
{
if (m_entity)
OnDetached();
m_entity = entity;
if (m_entity)
OnAttached();
}
}
/*!
* \brief Initializes the BaseComponent
* \return true
*/
inline bool BaseComponent::Initialize()
{
// Nothing to do
return true;
}
/*!
* \brief Uninitializes the BaseComponent
*/
inline void BaseComponent::Uninitialize()
{
s_entries.clear();
s_idToIndex.clear();
}
}

View File

@@ -1,105 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_BASESYSTEM_HPP
#define NDK_BASESYSTEM_HPP
#include <Nazara/Core/Bitset.hpp>
#include <NazaraSDK/EntityList.hpp>
namespace Ndk
{
class World;
class NDK_API BaseSystem
{
friend class Sdk;
friend Entity;
friend World;
public:
inline BaseSystem(SystemIndex systemId);
BaseSystem(const BaseSystem&) = delete;
BaseSystem(BaseSystem&&) noexcept = default;
virtual ~BaseSystem();
inline void Enable(bool enable = true);
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 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 Update(float elapsedTime);
BaseSystem& operator=(const BaseSystem&) = delete;
BaseSystem& operator=(BaseSystem&&) noexcept = default;
protected:
template<typename ComponentType> void Excludes();
template<typename ComponentType1, typename ComponentType2, typename... Rest> void Excludes();
inline void ExcludesComponent(ComponentIndex index);
static SystemIndex GetNextIndex();
template<typename ComponentType> void Requires();
template<typename ComponentType1, typename ComponentType2, typename... Rest> void Requires();
inline void RequiresComponent(ComponentIndex index);
template<typename ComponentType> void RequiresAny();
template<typename ComponentType1, typename ComponentType2, typename... Rest> void RequiresAny();
inline void RequiresAnyComponent(ComponentIndex index);
virtual void OnUpdate(float elapsedTime) = 0;
private:
inline void AddEntity(Entity* entity);
virtual void OnEntityAdded(Entity* entity);
virtual void OnEntityRemoved(Entity* entity);
virtual void OnEntityValidation(Entity* entity, bool justAdded);
inline void RemoveEntity(Entity* entity);
inline void SetWorld(World* world) noexcept;
inline void ValidateEntity(Entity* entity, bool justAdded);
static inline bool Initialize();
static inline void Uninitialize();
Nz::Bitset<> m_excludedComponents;
mutable Nz::Bitset<> m_filterResult;
Nz::Bitset<> m_requiredAnyComponents;
Nz::Bitset<> m_requiredComponents;
EntityList m_entities;
SystemIndex m_systemIndex;
World* m_world;
bool m_updateEnabled;
float m_fixedUpdateRate;
float m_maxUpdateRate;
float m_updateCounter;
int m_updateOrder;
static SystemIndex s_nextIndex;
};
}
#include <NazaraSDK/BaseSystem.inl>
#endif // NDK_BASESYSTEM_HPP

View File

@@ -1,383 +0,0 @@
// 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 Prerequisites.hpp
#include <Nazara/Core/Error.hpp>
#include <type_traits>
namespace Ndk
{
/*!
* \brief Constructs a BaseSystem object with an index
*
* \param systemId Index of the system
*/
inline BaseSystem::BaseSystem(SystemIndex systemId) :
m_systemIndex(systemId),
m_world(nullptr),
m_updateEnabled(true),
m_updateOrder(0)
{
SetFixedUpdateRate(0);
SetMaximumUpdateRate(30);
}
/*!
* \brief Enables the system
*
* \param enable Should the system be enabled
*/
inline void BaseSystem::Enable(bool enable)
{
m_updateEnabled = enable;
}
/*!
* \brief Gets every entities that system handle
* \return A constant reference to the list of entities
*/
inline const EntityList& BaseSystem::GetEntities() const
{
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
*/
inline SystemIndex BaseSystem::GetIndex() const
{
return m_systemIndex;
}
/*!
* \brief Gets the update order of the system
* \return Update order
*
* \see SetUpdateOrder
*/
inline int BaseSystem::GetUpdateOrder() const
{
return m_updateOrder;
}
/*!
* \brief Gets the world on which the system operate
* \return World in which the system is
*/
inline World& BaseSystem::GetWorld() const
{
return *m_world;
}
/*!
* \brief Checks whether or not the system is enabled
* \return true If it is the case
*/
inline bool BaseSystem::IsEnabled() const
{
return m_updateEnabled;
}
/*!
* \brief Checks whether or not the system has the entity
* \return true If it is the case
*
* \param entity Pointer to the entity
*/
inline bool BaseSystem::HasEntity(const Entity* entity) const
{
return m_entities.Has(entity);
}
/*!
* \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::SetMaximumUpdateRate(float updatePerSecond)
{
m_updateCounter = 0.f;
m_maxUpdateRate = (updatePerSecond > 0.f) ? 1.f / updatePerSecond : 0.f; // 0.f means no limit
}
/*!
* \brief Updates the system
*
* \param elapsedTime Delta time used for the update
*/
inline void BaseSystem::Update(float elapsedTime)
{
if (!IsEnabled())
return;
m_updateCounter += elapsedTime;
if (m_maxUpdateRate > 0.f)
{
if (m_updateCounter >= m_maxUpdateRate)
{
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
{
if (m_fixedUpdateRate > 0.f)
{
while (m_updateCounter >= m_fixedUpdateRate)
{
OnUpdate(m_fixedUpdateRate);
m_updateCounter -= m_fixedUpdateRate;
}
}
else
OnUpdate(elapsedTime);
}
}
/*!
* \brief Excludes some component from the system
*/
template<typename ComponentType>
void BaseSystem::Excludes()
{
static_assert(std::is_base_of<BaseComponent, ComponentType>::value , "ComponentType is not a component");
ExcludesComponent(GetComponentIndex<ComponentType>());
}
/*!
* \brief Excludes some components from the system
*/
template<typename ComponentType1, typename ComponentType2, typename... Rest>
void BaseSystem::Excludes()
{
Excludes<ComponentType1>();
Excludes<ComponentType2, Rest...>();
}
/*!
* \brief Excludes some component from the system by index
*
* \param index Index of the component
*/
inline void BaseSystem::ExcludesComponent(ComponentIndex index)
{
m_excludedComponents.UnboundedSet(index);
}
/*!
* \brief Gets the next index for the system
* \return Next unique index for the system
*/
inline SystemIndex BaseSystem::GetNextIndex()
{
return s_nextIndex++;
}
/*!
* \brief Requires some component from the system
*/
template<typename ComponentType>
void BaseSystem::Requires()
{
static_assert(std::is_base_of<BaseComponent, ComponentType>::value, "ComponentType is not a component");
RequiresComponent(GetComponentIndex<ComponentType>());
}
/*!
* \brief Requires some components from the system
*/
template<typename ComponentType1, typename ComponentType2, typename... Rest>
void BaseSystem::Requires()
{
Requires<ComponentType1>();
Requires<ComponentType2, Rest...>();
}
/*!
* \brief Requires some component for the system by index
*
* \param index Index of the component
*/
inline void BaseSystem::RequiresComponent(ComponentIndex index)
{
m_requiredComponents.UnboundedSet(index);
}
/*!
* \brief Requires any component from the system
*/
template<typename ComponentType>
void BaseSystem::RequiresAny()
{
static_assert(std::is_base_of<BaseComponent, ComponentType>::value, "ComponentType is not a component");
RequiresAnyComponent(GetComponentIndex<ComponentType>());
}
/*!
* \brief Requires any components from the system
*/
template<typename ComponentType1, typename ComponentType2, typename... Rest>
void BaseSystem::RequiresAny()
{
RequiresAny<ComponentType1>();
RequiresAny<ComponentType2, Rest...>();
}
/*!
* \brief Requires any component for the system by index
*
* \param index Index of the component
*/
inline void BaseSystem::RequiresAnyComponent(ComponentIndex index)
{
m_requiredAnyComponents.UnboundedSet(index);
}
/*!
* \brief Adds an entity to a system
*
* \param entity Pointer to the entity
*
* \remark Produces a NazaraAssert if entity is invalid
*/
inline void BaseSystem::AddEntity(Entity* entity)
{
NazaraAssert(entity, "Invalid entity");
m_entities.Insert(entity);
entity->RegisterSystem(m_systemIndex);
OnEntityAdded(entity);
}
/*!
* \brief Removes an entity to a system
*
* \param entity Pointer to the entity
*
* \remark Produces a NazaraAssert if entity is invalid
*/
inline void BaseSystem::RemoveEntity(Entity* entity)
{
NazaraAssert(entity, "Invalid entity");
m_entities.Remove(entity);
entity->UnregisterSystem(m_systemIndex);
OnEntityRemoved(entity); // And we alert our callback
}
/*!
* \brief Validates an entity to a system
*
* \param entity Pointer to the entity
* \param justAdded Is the entity newly added
*
* \remark Produces a NazaraAssert if entity is invalid or if system does not hold this entity
*/
inline void BaseSystem::ValidateEntity(Entity* entity, bool justAdded)
{
NazaraAssert(entity, "Invalid entity");
NazaraAssert(HasEntity(entity), "Entity should be part of system");
OnEntityValidation(entity, justAdded);
}
/*!
* \brief Sets the world on which the system operates
*/
inline void BaseSystem::SetWorld(World* world) noexcept
{
m_world = world;
}
/*!
* \brief Initializes the BaseSystem
* \return true
*/
inline bool BaseSystem::Initialize()
{
s_nextIndex = 0;
return true;
}
/*!
* \brief Uninitialize the BaseSystem
*/
inline void BaseSystem::Uninitialize()
{
// Nothing to do
}
}

View File

@@ -1,175 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_BASEWIDGET_HPP
#define NDK_BASEWIDGET_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/Entity.hpp>
#include <NazaraSDK/EntityOwner.hpp>
#include <NazaraSDK/World.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Platform/Event.hpp>
#include <Nazara/Platform/Mouse.hpp>
#include <Nazara/Utility/Node.hpp>
#include <limits>
namespace Ndk
{
class Canvas;
class NDK_API BaseWidget : public Nz::Node
{
friend Canvas;
public:
BaseWidget(BaseWidget* parent);
BaseWidget(const BaseWidget&) = delete;
BaseWidget(BaseWidget&&) = delete;
virtual ~BaseWidget();
template<typename T, typename... Args> T* Add(Args&&... args);
inline void AddChild(std::unique_ptr<BaseWidget>&& widget);
inline void Center();
inline void CenterHorizontal();
inline void CenterVertical();
void ClearFocus();
inline void ClearRenderingRect();
void Destroy();
void EnableBackground(bool enable);
template<typename F> void ForEachWidgetChild(F iterator);
template<typename F> void ForEachWidgetChild(F iterator) const;
//virtual BaseWidget* Clone() const = 0;
inline const Nz::Color& GetBackgroundColor() const;
inline Canvas* GetCanvas();
inline Nz::SystemCursor GetCursor() const;
inline float GetHeight() const;
inline float GetMaximumHeight() const;
inline Nz::Vector2f GetMaximumSize() const;
inline float GetMaximumWidth() const;
inline float GetMinimumHeight() const;
inline Nz::Vector2f GetMinimumSize() const;
inline float GetMinimumWidth() const;
inline float GetPreferredHeight() const;
inline Nz::Vector2f GetPreferredSize() const;
inline float GetPreferredWidth() const;
inline const Nz::Rectf& GetRenderingRect() const;
inline Nz::Vector2f GetSize() const;
inline float GetWidth() const;
inline std::size_t GetWidgetChildCount() const;
bool HasFocus() const;
inline bool IsVisible() const;
void Resize(const Nz::Vector2f& size);
void SetBackgroundColor(const Nz::Color& color);
void SetCursor(Nz::SystemCursor systemCursor);
void SetFocus();
void SetParent(BaseWidget* widget);
inline void SetFixedHeight(float fixedHeight);
inline void SetFixedSize(const Nz::Vector2f& fixedSize);
inline void SetFixedWidth(float fixedWidth);
inline void SetMaximumHeight(float maximumHeight);
inline void SetMaximumSize(const Nz::Vector2f& maximumSize);
inline void SetMaximumWidth(float maximumWidth);
inline void SetMinimumHeight(float minimumHeight);
inline void SetMinimumSize(const Nz::Vector2f& minimumSize);
inline void SetMinimumWidth(float minimumWidth);
virtual void SetRenderingRect(const Nz::Rectf& renderingRect);
void Show(bool show = true);
BaseWidget& operator=(const BaseWidget&) = delete;
BaseWidget& operator=(BaseWidget&&) = delete;
protected:
const EntityHandle& CreateEntity();
void DestroyEntity(Entity* entity);
virtual void Layout();
void InvalidateNode() override;
Nz::Rectf GetScissorRect() const;
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);
virtual void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button);
virtual void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button);
virtual void OnMouseWheelMoved(int x, int y, float delta);
virtual void OnMouseExit();
virtual void OnParentResized(const Nz::Vector2f& newSize);
virtual void OnTextEntered(char32_t character, bool repeated);
inline void SetPreferredSize(const Nz::Vector2f& preferredSize);
private:
inline BaseWidget();
void DestroyChild(BaseWidget* widget);
void DestroyChildren();
inline bool IsRegisteredToCanvas() const;
inline void NotifyParentResized(const Nz::Vector2f& newSize);
void RegisterToCanvas();
inline void UpdateCanvasIndex(std::size_t index);
void UnregisterFromCanvas();
void UpdatePositionAndSize();
struct WidgetEntity
{
EntityOwner handle;
bool isEnabled = true;
NazaraSlot(Ndk::Entity, OnEntityDisabled, onDisabledSlot);
NazaraSlot(Ndk::Entity, OnEntityEnabled, onEnabledSlot);
};
static constexpr std::size_t InvalidCanvasIndex = std::numeric_limits<std::size_t>::max();
std::size_t m_canvasIndex;
std::vector<WidgetEntity> m_entities;
std::vector<std::unique_ptr<BaseWidget>> m_children;
Canvas* m_canvas;
EntityOwner m_backgroundEntity;
WorldHandle m_world;
Nz::Color m_backgroundColor;
Nz::Rectf m_renderingRect;
Nz::SpriteRef m_backgroundSprite;
Nz::SystemCursor m_cursor;
Nz::Vector2f m_maximumSize;
Nz::Vector2f m_minimumSize;
Nz::Vector2f m_preferredSize;
Nz::Vector2f m_size;
BaseWidget* m_widgetParent;
bool m_visible;
};
}
#include <NazaraSDK/BaseWidget.inl>
#endif // NDK_BASEWIDGET_HPP

View File

@@ -1,270 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/BaseWidget.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <limits>
namespace Ndk
{
inline BaseWidget::BaseWidget() :
m_canvasIndex(InvalidCanvasIndex),
m_canvas(nullptr),
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
m_renderingRect(-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()),
m_cursor(Nz::SystemCursor_Default),
m_maximumSize(std::numeric_limits<float>::infinity()),
m_minimumSize(0.f),
m_preferredSize(-1),
m_size(50.f, 50.f),
m_widgetParent(nullptr),
m_visible(true)
{
}
template<typename T, typename... Args>
inline T* BaseWidget::Add(Args&&... args)
{
std::unique_ptr<T> widget = std::make_unique<T>(this, std::forward<Args>(args)...);
T* widgetPtr = widget.get();
AddChild(std::move(widget));
return widgetPtr;
}
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)
{
widget->Show(m_visible);
widget->SetParent(this);
m_children.emplace_back(std::move(widget));
}
inline void BaseWidget::Center()
{
NazaraAssert(m_widgetParent, "Widget has no parent");
Nz::Vector2f parentSize = m_widgetParent->GetSize();
Nz::Vector2f mySize = GetSize();
SetPosition((parentSize.x - mySize.x) / 2.f, (parentSize.y - mySize.y) / 2.f);
}
inline 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 void BaseWidget::ClearRenderingRect()
{
SetRenderingRect(Nz::Rectf(-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()));
}
template<typename F>
inline void BaseWidget::ForEachWidgetChild(F iterator)
{
for (const auto& child : m_children)
iterator(child.get());
}
template<typename F>
inline void BaseWidget::ForEachWidgetChild(F iterator) const
{
for (const auto& child : m_children)
iterator(static_cast<const BaseWidget*>(child.get()));
}
inline const Nz::Color& BaseWidget::GetBackgroundColor() const
{
return m_backgroundColor;
}
inline Canvas* BaseWidget::GetCanvas()
{
return m_canvas;
}
inline Nz::SystemCursor BaseWidget::GetCursor() const
{
return m_cursor;
}
inline float BaseWidget::GetHeight() const
{
return m_size.y;
}
inline float BaseWidget::GetMaximumHeight() const
{
return m_maximumSize.y;
}
inline Nz::Vector2f BaseWidget::GetMaximumSize() const
{
return m_maximumSize;
}
inline float BaseWidget::GetMaximumWidth() const
{
return m_maximumSize.x;
}
inline float BaseWidget::GetMinimumHeight() const
{
return m_minimumSize.y;
}
inline Nz::Vector2f BaseWidget::GetMinimumSize() const
{
return m_minimumSize;
}
inline float BaseWidget::GetMinimumWidth() const
{
return m_minimumSize.x;
}
inline float BaseWidget::GetPreferredHeight() const
{
return m_preferredSize.y;
}
inline Nz::Vector2f BaseWidget::GetPreferredSize() const
{
return m_preferredSize;
}
inline float BaseWidget::GetPreferredWidth() const
{
return m_preferredSize.x;
}
inline const Nz::Rectf& BaseWidget::GetRenderingRect() const
{
return m_renderingRect;
}
inline Nz::Vector2f BaseWidget::GetSize() const
{
return Nz::Vector2f(GetWidth(), GetHeight());
}
inline float BaseWidget::GetWidth() const
{
return m_size.x;
}
inline std::size_t BaseWidget::GetWidgetChildCount() const
{
return m_children.size();
}
inline bool BaseWidget::IsVisible() const
{
return m_visible;
}
inline void BaseWidget::SetFixedHeight(float fixedHeight)
{
SetMaximumHeight(fixedHeight);
SetMinimumHeight(fixedHeight);
}
inline void BaseWidget::SetFixedSize(const Nz::Vector2f& fixedSize)
{
SetMaximumSize(fixedSize);
SetMinimumSize(fixedSize);
}
inline void BaseWidget::SetFixedWidth(float fixedWidth)
{
SetMaximumWidth(fixedWidth);
SetMinimumWidth(fixedWidth);
}
inline void BaseWidget::SetMaximumHeight(float maximumHeight)
{
Nz::Vector2f maximumSize = GetMaximumSize();
maximumSize.y = maximumHeight;
SetMaximumSize(maximumSize);
}
inline void BaseWidget::SetMaximumSize(const Nz::Vector2f& maximumSize)
{
m_maximumSize = maximumSize;
Nz::Vector2f size = GetSize();
if (size.x > m_maximumSize.x || size.y > m_maximumSize.y)
Resize(size); //< Will clamp automatically
}
inline void BaseWidget::SetMaximumWidth(float maximumWidth)
{
Nz::Vector2f maximumSize = GetMaximumSize();
maximumSize.x = maximumWidth;
SetMaximumSize(maximumSize);
}
inline void BaseWidget::SetMinimumHeight(float minimumHeight)
{
Nz::Vector2f minimumSize = GetMinimumSize();
minimumSize.y = minimumHeight;
SetMinimumSize(minimumSize);
}
inline void BaseWidget::SetMinimumSize(const Nz::Vector2f& minimumSize)
{
m_minimumSize = minimumSize;
Nz::Vector2f size = GetSize();
if (size.x < m_minimumSize.x || size.y < m_minimumSize.y)
Resize(size); //< Will clamp automatically
}
inline void BaseWidget::SetMinimumWidth(float minimumWidth)
{
Nz::Vector2f minimumSize = GetMinimumSize();
minimumSize.x = minimumWidth;
SetMinimumSize(minimumSize);
}
inline void BaseWidget::SetPreferredSize(const Nz::Vector2f& preferredSize)
{
m_preferredSize = preferredSize;
//Resize(m_preferredSize);
}
inline bool BaseWidget::IsRegisteredToCanvas() const
{
return m_canvas && m_canvasIndex != InvalidCanvasIndex;
}
inline void BaseWidget::NotifyParentResized(const Nz::Vector2f& newSize)
{
for (const auto& widgetPtr : m_children)
widgetPtr->OnParentResized(newSize);
}
inline void BaseWidget::UpdateCanvasIndex(std::size_t index)
{
m_canvasIndex = index;
}
}

View File

@@ -1,87 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_CANVAS_HPP
#define NDK_CANVAS_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <Nazara/Platform/CursorController.hpp>
#include <Nazara/Platform/EventHandler.hpp>
namespace Ndk
{
class NDK_API Canvas : public BaseWidget
{
friend BaseWidget;
public:
struct Padding;
inline Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController);
Canvas(const Canvas&) = delete;
Canvas(Canvas&&) = delete;
inline ~Canvas();
inline const WorldHandle& GetWorld() const;
Canvas& operator=(const Canvas&) = delete;
Canvas& operator=(Canvas&&) = delete;
NazaraSignal(OnUnhandledKeyPressed, const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnUnhandledKeyReleased, const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::KeyEvent& /*event*/);
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(std::size_t canvasIndex);
void UnregisterWidget(std::size_t index);
private:
void OnEventMouseButtonPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
void OnEventMouseButtonRelease(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseButtonEvent& event);
void OnEventMouseLeft(const Nz::EventHandler* eventHandler);
void OnEventMouseMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseMoveEvent& event);
void OnEventMouseWheelMoved(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::MouseWheelEvent& event);
void OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
struct WidgetEntry
{
BaseWidget* widget;
Nz::Boxf box;
Nz::SystemCursor cursor;
};
NazaraSlot(Nz::EventHandler, OnKeyPressed, m_keyPressedSlot);
NazaraSlot(Nz::EventHandler, OnKeyReleased, m_keyReleasedSlot);
NazaraSlot(Nz::EventHandler, OnMouseButtonPressed, m_mouseButtonPressedSlot);
NazaraSlot(Nz::EventHandler, OnMouseButtonReleased, m_mouseButtonReleasedSlot);
NazaraSlot(Nz::EventHandler, OnMouseLeft, m_mouseLeftSlot);
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot);
NazaraSlot(Nz::EventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot);
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
std::size_t m_keyboardOwner;
std::size_t m_hoveredWidget;
std::vector<WidgetEntry> m_widgetEntries;
Nz::CursorControllerHandle m_cursorController;
WorldHandle m_world;
};
}
#include <NazaraSDK/Canvas.inl>
#endif // NDK_CANVAS_HPP

View File

@@ -1,90 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Canvas.hpp>
#include <Nazara/Platform/Cursor.hpp>
namespace Ndk
{
inline Canvas::Canvas(WorldHandle world, Nz::EventHandler& eventHandler, Nz::CursorControllerHandle cursorController) :
m_keyboardOwner(InvalidCanvasIndex),
m_hoveredWidget(InvalidCanvasIndex),
m_cursorController(cursorController),
m_world(std::move(world))
{
m_canvas = this;
m_widgetParent = nullptr;
// Register ourselves as a widget to handle cursor change
RegisterToCanvas();
// Connect to every meaningful event
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, this, &Canvas::OnEventKeyPressed);
m_keyReleasedSlot.Connect(eventHandler.OnKeyReleased, this, &Canvas::OnEventKeyReleased);
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, this, &Canvas::OnEventMouseButtonPressed);
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, this, &Canvas::OnEventMouseButtonRelease);
m_mouseLeftSlot.Connect(eventHandler.OnMouseLeft, this, &Canvas::OnEventMouseLeft);
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved);
m_mouseWheelMovedSlot.Connect(eventHandler.OnMouseWheelMoved, this, &Canvas::OnEventMouseWheelMoved);
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered);
}
inline Canvas::~Canvas()
{
// Destroy children explicitly because they signal us when getting destroyed, and that can't happen after our own destruction
DestroyChildren();
// Prevent our parent from trying to call us
m_canvasIndex = InvalidCanvasIndex;
}
inline const WorldHandle& Canvas::GetWorld() const
{
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)
{
WidgetEntry& entry = m_widgetEntries[index];
Nz::Vector3f pos = entry.widget->GetPosition(Nz::CoordSys_Global);
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)
{
WidgetEntry& entry = m_widgetEntries[index];
entry.cursor = entry.widget->GetCursor();
if (m_cursorController && m_hoveredWidget == index)
m_cursorController->UpdateCursor(Nz::Cursor::Get(entry.cursor));
}
inline void Canvas::SetKeyboardOwner(std::size_t canvasIndex)
{
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,32 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_COMPONENT_HPP
#define NDK_COMPONENT_HPP
#include <NazaraSDK/BaseComponent.hpp>
namespace Ndk
{
template<typename ComponentType>
class Component : public BaseComponent, public Nz::HandledObject<ComponentType>
{
public:
Component();
virtual ~Component();
std::unique_ptr<BaseComponent> Clone() const override;
static ComponentIndex RegisterComponent(ComponentId id);
template<unsigned int N>
static ComponentIndex RegisterComponent(const char (&name)[N]);
};
}
#include <NazaraSDK/Component.inl>
#endif // NDK_COMPONENT_HPP

View File

@@ -1,76 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Algorithm.hpp>
#include <type_traits>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::Component<ComponentType>
* \brief NDK class that represents a component for an entity which interacts with a system
*
* \remark This class is meant to be derived as CRTP: "Component<Subtype>"
*/
/*!
* \brief Constructs a Component object by default
*/
template<typename ComponentType>
Component<ComponentType>::Component() :
BaseComponent(GetComponentIndex<ComponentType>())
{
}
template<typename ComponentType>
Component<ComponentType>::~Component() = default;
/*!
* \brief Clones the component
* \return The clone newly created
*
* \remark The component to clone should be trivially copy constructible
*/
template<typename ComponentType>
std::unique_ptr<BaseComponent> Component<ComponentType>::Clone() const
{
///FIXME: Pas encore supporté par GCC (4.9.2)
//static_assert(std::is_trivially_copy_constructible<ComponentType>::value, "ComponentType must be copy-constructible");
return std::make_unique<ComponentType>(static_cast<const ComponentType&>(*this));
}
/*!
* \brief Registers the component by assigning it an index
*/
template<typename ComponentType>
ComponentIndex Component<ComponentType>::RegisterComponent(ComponentId id)
{
//We use the lambda to create a factory function
auto factory = []() -> BaseComponent*
{
return nullptr; //< Temporary workaround to allow non-default-constructed components, will be updated for serialization
//return new ComponentType;
};
return BaseComponent::RegisterComponent(id, factory);
}
/*!
* \brief Registers the component by assigning it an index based on the name
*/
template<typename ComponentType>
template<unsigned int N>
ComponentIndex Component<ComponentType>::RegisterComponent(const char (&name)[N])
{
// We convert the string to a number which will be used as unique identifier
ComponentId id = BuildComponentId(name);
return RegisterComponent(id);
}
}

View File

@@ -1,24 +0,0 @@
// This file was automatically generated
#pragma once
#ifndef NDK_COMPONENTS_GLOBAL_HPP
#define NDK_COMPONENTS_GLOBAL_HPP
#include <NazaraSDK/Components/CameraComponent.hpp>
#include <NazaraSDK/Components/CollisionComponent2D.hpp>
#include <NazaraSDK/Components/CollisionComponent3D.hpp>
#include <NazaraSDK/Components/ConstraintComponent2D.hpp>
#include <NazaraSDK/Components/DebugComponent.hpp>
#include <NazaraSDK/Components/GraphicsComponent.hpp>
#include <NazaraSDK/Components/LifetimeComponent.hpp>
#include <NazaraSDK/Components/LightComponent.hpp>
#include <NazaraSDK/Components/ListenerComponent.hpp>
#include <NazaraSDK/Components/NodeComponent.hpp>
#include <NazaraSDK/Components/ParticleEmitterComponent.hpp>
#include <NazaraSDK/Components/ParticleGroupComponent.hpp>
#include <NazaraSDK/Components/PhysicsComponent2D.hpp>
#include <NazaraSDK/Components/PhysicsComponent3D.hpp>
#include <NazaraSDK/Components/VelocityComponent.hpp>
#endif // NDK_COMPONENTS_GLOBAL_HPP

View File

@@ -1,120 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_CAMERACOMPONENT_HPP
#define NDK_COMPONENTS_CAMERACOMPONENT_HPP
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Utility/Node.hpp>
#include <NazaraSDK/Component.hpp>
namespace Ndk
{
class CameraComponent;
using CameraComponentHandle = Nz::ObjectHandle<CameraComponent>;
class NDK_API CameraComponent : public Component<CameraComponent>, public Nz::AbstractViewer
{
public:
inline CameraComponent();
inline CameraComponent(const CameraComponent& camera);
~CameraComponent() = default;
void ApplyView() const override;
inline void EnsureFrustumUpdate() const;
inline void EnsureProjectionMatrixUpdate() const;
inline void EnsureViewMatrixUpdate() const;
inline void EnsureViewportUpdate() const;
float GetAspectRatio() const override;
Nz::Vector3f GetEyePosition() const override;
Nz::Vector3f GetForward() const override;
inline float GetFOV() const;
const Nz::Frustumf& GetFrustum() const override;
inline unsigned int GetLayer() const;
const Nz::Matrix4f& GetProjectionMatrix() const override;
inline const Nz::Vector3f& GetProjectionScale() const;
Nz::ProjectionType GetProjectionType() const override;
inline const Nz::Vector2f& GetSize() const;
const Nz::RenderTarget* GetTarget() const override;
inline const Nz::Rectf& GetTargetRegion() const;
const Nz::Matrix4f& GetViewMatrix() const override;
const Nz::Recti& GetViewport() const override;
float GetZFar() const override;
float GetZNear() const override;
inline void SetFOV(float fov);
void SetLayer(unsigned int layer);
inline void SetProjectionScale(const Nz::Vector3f& scale);
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);
inline void SetZFar(float zFar);
inline void SetZNear(float zNear);
inline bool UpdateVisibility(std::size_t visibilityHash);
static ComponentIndex componentIndex;
private:
inline void InvalidateFrustum() const;
inline void InvalidateProjectionMatrix() const;
inline void InvalidateViewMatrix() const;
inline void InvalidateViewport() const;
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
void OnNodeInvalidated(const Nz::Node* node);
void OnRenderTargetRelease(const Nz::RenderTarget* renderTarget);
void OnRenderTargetSizeChange(const Nz::RenderTarget* renderTarget);
void UpdateFrustum() const;
void UpdateProjectionMatrix() const;
void UpdateViewMatrix() const;
void UpdateViewport() const;
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
NazaraSlot(Nz::RenderTarget, OnRenderTargetRelease, m_targetReleaseSlot);
NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, m_targetResizeSlot);
std::size_t m_visibilityHash;
Nz::ProjectionType m_projectionType;
mutable Nz::Frustumf m_frustum;
mutable Nz::Matrix4f m_projectionMatrix;
mutable Nz::Matrix4f m_viewMatrix;
Nz::Rectf m_targetRegion;
mutable Nz::Recti m_viewport;
const Nz::RenderTarget* m_target;
Nz::Vector2f m_size;
Nz::Vector3f m_projectionScale;
mutable bool m_frustumUpdated;
mutable bool m_projectionMatrixUpdated;
mutable bool m_viewMatrixUpdated;
mutable bool m_viewportUpdated;
mutable float m_aspectRatio;
float m_fov;
float m_zFar;
float m_zNear;
unsigned int m_layer;
};
}
#include <NazaraSDK/Components/CameraComponent.inl>
#endif // NDK_COMPONENTS_CAMERACOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -1,353 +0,0 @@
// 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 Prerequisites.hpp
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Algorithm.hpp>
namespace Ndk
{
/*!
* \brief Constructs an CameraComponent object by default
*/
inline CameraComponent::CameraComponent() :
m_visibilityHash(0U),
m_projectionType(Nz::ProjectionType_Perspective),
m_targetRegion(0.f, 0.f, 1.f, 1.f),
m_target(nullptr),
m_size(0.f),
m_projectionScale(1.f, 1.f, 1.f),
m_frustumUpdated(false),
m_projectionMatrixUpdated(false),
m_viewMatrixUpdated(false),
m_viewportUpdated(false),
m_aspectRatio(0.f),
m_fov(70.f),
m_zFar(100.f),
m_zNear(1.f),
m_layer(0)
{
}
/*!
* \brief Constructs a CameraComponent object by copy semantic
*
* \param camera CameraComponent to copy
*/
inline CameraComponent::CameraComponent(const CameraComponent& camera) :
Component(camera),
AbstractViewer(camera),
m_visibilityHash(camera.m_visibilityHash),
m_projectionType(camera.m_projectionType),
m_targetRegion(camera.m_targetRegion),
m_target(nullptr),
m_size(camera.m_size),
m_projectionScale(camera.m_projectionScale),
m_frustumUpdated(false),
m_projectionMatrixUpdated(false),
m_viewMatrixUpdated(false),
m_viewportUpdated(false),
m_aspectRatio(camera.m_aspectRatio),
m_fov(camera.m_fov),
m_zFar(camera.m_zFar),
m_zNear(camera.m_zNear),
m_layer(camera.m_layer)
{
SetTarget(camera.m_target);
}
/*!
* \brief Ensures the frustum is up to date
*/
inline void CameraComponent::EnsureFrustumUpdate() const
{
if (!m_frustumUpdated)
UpdateFrustum();
}
/*!
* \brief Ensures the projection matrix is up to date
*/
inline void CameraComponent::EnsureProjectionMatrixUpdate() const
{
if (!m_projectionMatrixUpdated)
UpdateProjectionMatrix();
}
/*!
* \brief Ensures the view matrix is up to date
*/
inline void CameraComponent::EnsureViewMatrixUpdate() const
{
if (!m_viewMatrixUpdated)
UpdateViewMatrix();
}
/*!
* \brief Ensures the view port is up to date
*/
inline void CameraComponent::EnsureViewportUpdate() const
{
if (!m_viewportUpdated)
UpdateViewport();
}
/*!
* \brief Gets the field of view of the camera
* \return Field of view of the camera
*/
inline float CameraComponent::GetFOV() const
{
return m_fov;
}
/*!
* \brief Gets the layer of the camera
* \return Layer of the camera
*/
inline unsigned int CameraComponent::GetLayer() const
{
return m_layer;
}
/*!
* \brief Gets the projection scale of the camera
* \return Projection scale
*/
const Nz::Vector3f& CameraComponent::GetProjectionScale() const
{
return m_projectionScale;
}
/*!
* \brief Gets the size of the camera
* \return Size of the camera
*/
inline const Nz::Vector2f & CameraComponent::GetSize() const
{
return m_size;
}
/*!
* \brief Gets the target region of the camera
* \return A constant reference to the target region of the camera
*/
inline const Nz::Rectf& CameraComponent::GetTargetRegion() const
{
return m_targetRegion;
}
/*!
* \brief Sets the field of view of the camera
*
* \param fov Field of view of the camera
*
* \remark Produces a NazaraAssert if angle is zero
*/
inline void CameraComponent::SetFOV(float fov)
{
NazaraAssert(!Nz::NumberEquals(fov, 0.f), "FOV must be different from zero");
m_fov = fov;
InvalidateProjectionMatrix();
}
/*!
* \brief Sets the camera projection scale
*
* \param scale New projection scale
*/
inline void CameraComponent::SetProjectionScale(const Nz::Vector3f& scale)
{
m_projectionScale = scale;
InvalidateProjectionMatrix();
}
/*!
* \brief Sets the projection type of the camera
*
* \param projectionType Projection type of the camera
*/
inline void CameraComponent::SetProjectionType(Nz::ProjectionType projectionType)
{
m_projectionType = projectionType;
InvalidateProjectionMatrix();
}
/*!
* \brief Sets the size of the camera
*
* \param size Size of the camera
*/
inline void CameraComponent::SetSize(const Nz::Vector2f& size)
{
m_size = size;
InvalidateProjectionMatrix();
}
/*!
* \brief Sets the size of the camera
*
* \param width Size in X of the camera
* \param height Size in Y of the camera
*/
inline void CameraComponent::SetSize(float width, float height)
{
SetSize({width, height});
}
/*!
* \brief Sets the target of the camera
*
* \param renderTarget A constant reference to the render target of the camera
*/
inline void CameraComponent::SetTarget(const Nz::RenderTarget* renderTarget)
{
m_target = renderTarget;
if (m_target)
{
m_targetResizeSlot.Connect(m_target->OnRenderTargetSizeChange, this, &CameraComponent::OnRenderTargetSizeChange);
m_targetReleaseSlot.Connect(m_target->OnRenderTargetRelease, this, &CameraComponent::OnRenderTargetRelease);
}
else
{
m_targetResizeSlot.Disconnect();
m_targetReleaseSlot.Disconnect();
}
}
/*!
* \brief Sets the target region of the camera
*
* \param region A constant reference to the target region of the camera
*/
inline void CameraComponent::SetTargetRegion(const Nz::Rectf& region)
{
m_targetRegion = region;
InvalidateViewport();
}
/*!
* \brief Sets the view port of the camera
*
* \param viewport A constant reference to the view port of the camera
*
* \remark Produces a NazaraAssert if the camera has no target
*/
inline void CameraComponent::SetViewport(const Nz::Recti& viewport)
{
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
Nz::Vector2f invSize = 1.f / Nz::Vector2f(m_target->GetSize());
SetTargetRegion(Nz::Rectf(invSize.x * viewport.x, invSize.y * viewport.y, invSize.x * viewport.width, invSize.y * viewport.height));
}
/*!
* \brief Sets the Z far distance of the camera
*
* \param zFar Z far distance of the camera
*/
inline void CameraComponent::SetZFar(float zFar)
{
m_zFar = zFar;
InvalidateProjectionMatrix();
}
/*!
* \brief Sets the Z near distance of the camera
*
* \param zNear Z near distance of the camera
*
* \remark Produces a NazaraAssert if zNear is zero
*/
inline void CameraComponent::SetZNear(float zNear)
{
NazaraAssert(!Nz::NumberEquals(zNear, 0.f), "zNear cannot be zero");
m_zNear = zNear;
InvalidateProjectionMatrix();
}
/*!
* \brief Update the camera component visibility hash
*
* This is used with CullingList (which produce a visibility hash)
*
* \param visibilityHash New visibility hash
*
* \return True if the visibility hash is not the same as before
*/
inline bool CameraComponent::UpdateVisibility(std::size_t visibilityHash)
{
if (m_visibilityHash != visibilityHash)
{
m_visibilityHash = visibilityHash;
return true;
}
return false;
}
/*!
* \brief Invalidates the frustum
*/
inline void CameraComponent::InvalidateFrustum() const
{
m_frustumUpdated = false;
}
/*!
* \brief Invalidates the projection matrix
*/
inline void CameraComponent::InvalidateProjectionMatrix() const
{
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
}
/*!
* \brief Invalidates the view matrix
*/
inline void CameraComponent::InvalidateViewMatrix() const
{
m_frustumUpdated = false;
m_viewMatrixUpdated = false;
}
/*!
* \brief Invalidates the view port
*/
inline void CameraComponent::InvalidateViewport() const
{
m_frustumUpdated = false;
m_projectionMatrixUpdated = false;
m_viewportUpdated = false;
}
}

View File

@@ -1,66 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP
#define NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP
#include <Nazara/Physics2D/Collider2D.hpp>
#include <Nazara/Physics2D/RigidBody2D.hpp>
#include <NazaraSDK/Component.hpp>
#include <memory>
namespace Ndk
{
class CollisionComponent2D;
using CollisionComponent2DHandle = Nz::ObjectHandle<CollisionComponent2D>;
class NDK_API CollisionComponent2D : public Component<CollisionComponent2D>
{
friend class ConstraintComponent2D;
friend class PhysicsComponent2D;
friend class PhysicsSystem2D;
public:
CollisionComponent2D(Nz::Collider2DRef geom = Nz::Collider2DRef());
CollisionComponent2D(const CollisionComponent2D& collision);
~CollisionComponent2D() = default;
Nz::Rectf GetAABB() const;
const Nz::Collider2DRef& GetGeom() const;
const Nz::Vector2f& GetGeomOffset() const;
void Recenter(const Nz::Vector2f& origin);
void SetGeom(Nz::Collider2DRef geom);
void SetGeomOffset(const Nz::Vector2f& geomOffset);
CollisionComponent2D& operator=(Nz::Collider2DRef geom);
CollisionComponent2D& operator=(CollisionComponent2D&& collision) = default;
static ComponentIndex componentIndex;
private:
void InitializeStaticBody();
Nz::RigidBody2D* GetRigidBody();
const Nz::RigidBody2D* GetRigidBody() const;
Nz::RigidBody2D* GetStaticBody();
const Nz::RigidBody2D* GetStaticBody() const;
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
std::unique_ptr<Nz::RigidBody2D> m_staticBody;
Nz::Collider2DRef m_geom;
bool m_bodyUpdated;
};
}
#include <NazaraSDK/Components/CollisionComponent2D.inl>
#endif // NDK_COMPONENTS_COLLISIONCOMPONENT2D_HPP

View File

@@ -1,64 +0,0 @@
// 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 Prerequisites.hpp
namespace Ndk
{
/*!
* \brief Constructs a CollisionComponent2D object with a geometry
*
* \param geom Reference to a geometry symbolizing the entity
*/
inline CollisionComponent2D::CollisionComponent2D(Nz::Collider2DRef geom) :
m_geom(std::move(geom)),
m_bodyUpdated(false)
{
}
/*!
* \brief Constructs a CollisionComponent2D object by copy semantic
*
* \param collision CollisionComponent2D to copy
*/
inline CollisionComponent2D::CollisionComponent2D(const CollisionComponent2D& collision) :
m_geom(collision.m_geom),
m_bodyUpdated(false)
{
}
/*!
* \brief Gets the geometry representing the entity
* \return A constant reference to the physics geometry
*/
inline const Nz::Collider2DRef& CollisionComponent2D::GetGeom() const
{
return m_geom;
}
/*!
* \brief Assigns the geometry to this component
* \return A reference to this
*
* \param geom Reference to a geometry symbolizing the entity
*/
inline CollisionComponent2D& CollisionComponent2D::operator=(Nz::Collider2DRef geom)
{
SetGeom(geom);
return *this;
}
inline Nz::RigidBody2D* CollisionComponent2D::GetStaticBody()
{
return m_staticBody.get();
}
inline const Nz::RigidBody2D* CollisionComponent2D::GetStaticBody() const
{
return m_staticBody.get();
}
}

View File

@@ -1,58 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_COMPONENTS_COLLISIONCOMPONENT3D_HPP
#define NDK_COMPONENTS_COLLISIONCOMPONENT3D_HPP
#include <Nazara/Physics3D/Collider3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NazaraSDK/Component.hpp>
#include <memory>
namespace Ndk
{
class CollisionComponent3D;
using CollisionComponent3DHandle = Nz::ObjectHandle<CollisionComponent3D>;
class NDK_API CollisionComponent3D : public Component<CollisionComponent3D>
{
friend class PhysicsSystem3D;
public:
CollisionComponent3D(Nz::Collider3DRef geom = Nz::Collider3DRef());
CollisionComponent3D(const CollisionComponent3D& collision);
~CollisionComponent3D() = default;
const Nz::Collider3DRef& GetGeom() const;
void SetGeom(Nz::Collider3DRef geom);
CollisionComponent3D& operator=(Nz::Collider3DRef geom);
CollisionComponent3D& operator=(CollisionComponent3D&& collision) = default;
static ComponentIndex componentIndex;
private:
void InitializeStaticBody();
Nz::RigidBody3D* GetStaticBody();
void OnAttached() override;
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;
bool m_bodyUpdated;
};
}
#include <NazaraSDK/Components/CollisionComponent3D.inl>
#endif // NDK_COMPONENTS_COLLISIONCOMPONENT3D_HPP

View File

@@ -1,64 +0,0 @@
// 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 Prerequisites.hpp
namespace Ndk
{
/*!
* \brief Constructs a CollisionComponent3D object with a geometry
*
* \param geom Reference to a geometry symbolizing the entity
*/
inline CollisionComponent3D::CollisionComponent3D(Nz::Collider3DRef geom) :
m_geom(std::move(geom)),
m_bodyUpdated(false)
{
}
/*!
* \brief Constructs a CollisionComponent3D object by copy semantic
*
* \param collision CollisionComponent3D to copy
*/
inline CollisionComponent3D::CollisionComponent3D(const CollisionComponent3D& collision) :
m_geom(collision.m_geom),
m_bodyUpdated(false)
{
}
/*!
* \brief Gets the geometry representing the entity
* \return A constant reference to the physics geometry
*/
inline const Nz::Collider3DRef& CollisionComponent3D::GetGeom() const
{
return m_geom;
}
/*!
* \brief Assigns the geometry to this component
* \return A reference to this
*
* \param geom Reference to a geometry symbolizing the entity
*/
inline CollisionComponent3D& CollisionComponent3D::operator=(Nz::Collider3DRef geom)
{
SetGeom(geom);
return *this;
}
/*!
* \brief Gets the static body used by the entity
* \return A pointer to the entity
*/
inline Nz::RigidBody3D* CollisionComponent3D::GetStaticBody()
{
return m_staticBody.get();
}
}

View File

@@ -1,51 +0,0 @@
// Copyright (C) 2019 Jérôme Leclercq
// 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_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP
#define NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP
#include <Nazara/Physics2D/Constraint2D.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <NazaraSDK/Component.hpp>
#include <NazaraSDK/Entity.hpp>
#include <memory>
#include <vector>
namespace Ndk
{
class ConstraintComponent2D;
using ConstraintComponent2DHandle = Nz::ObjectHandle<ConstraintComponent2D>;
class NDK_API ConstraintComponent2D : public Component<ConstraintComponent2D>
{
public:
ConstraintComponent2D() = default;
ConstraintComponent2D(const ConstraintComponent2D& joint);
ConstraintComponent2D(ConstraintComponent2D&& joint) = default;
template<typename T, typename... Args> T* CreateConstraint(const Ndk::EntityHandle& first, const Ndk::EntityHandle& second, Args&&... args);
bool RemoveConstraint(Nz::Constraint2D* constraint);
static ComponentIndex componentIndex;
private:
struct ConstraintData
{
std::unique_ptr<Nz::Constraint2D> constraint;
NazaraSlot(Ndk::Entity, OnEntityDestruction, onBodyADestruction);
NazaraSlot(Ndk::Entity, OnEntityDestruction, onBodyBDestruction);
};
std::vector<ConstraintData> m_constraints;
};
}
#include <NazaraSDK/Components/ConstraintComponent2D.inl>
#endif// NDK_COMPONENTS_CONSTRAINTCOMPONENT2D_HPP

View File

@@ -1,46 +0,0 @@
// Copyright (C) 2019 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NazaraSDK/Components/ConstraintComponent2D.hpp>
#include <NazaraSDK/Components/PhysicsComponent2D.hpp>
#include <NazaraSDK/Components/CollisionComponent2D.hpp>
namespace Ndk
{
template<typename T, typename ...Args>
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");
m_constraints.emplace_back();
auto& constraintData = m_constraints.back();
constraintData.constraint = std::make_unique<T>(*firstBody, *secondBody, std::forward<Args>(args)...);
constraintData.onBodyADestruction.Connect(first->OnEntityDestruction, [this, constraint = constraintData.constraint.get()](const Ndk::Entity* /*entity*/)
{
RemoveConstraint(constraint);
});
constraintData.onBodyBDestruction.Connect(second->OnEntityDestruction, [this, constraint = constraintData.constraint.get()](const Ndk::Entity* /*entity*/)
{
RemoveConstraint(constraint);
});
return static_cast<T*>(constraintData.constraint.get());
}
}

View File

@@ -1,91 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_DEBUGCOMPONENT_HPP
#define NDK_COMPONENTS_DEBUGCOMPONENT_HPP
#include <Nazara/Core/Flags.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <NazaraSDK/Component.hpp>
namespace Ndk
{
enum class DebugDraw
{
Collider2D,
Collider3D,
GraphicsAABB,
GraphicsOBB,
Max = GraphicsOBB
};
}
namespace Nz
{
template<>
struct EnumAsFlags<Ndk::DebugDraw>
{
static constexpr Ndk::DebugDraw max = Ndk::DebugDraw::GraphicsOBB;
};
}
namespace Ndk
{
using DebugDrawFlags = Nz::Flags<DebugDraw>;
constexpr DebugDrawFlags DebugDraw_None = 0;
class DebugComponent;
class GraphicsComponent;
using DebugComponentHandle = Nz::ObjectHandle<DebugComponent>;
class NDK_API DebugComponent : public Component<DebugComponent>
{
friend class DebugSystem;
public:
inline DebugComponent(DebugDrawFlags flags = DebugDraw_None);
inline DebugComponent(const DebugComponent& debug);
~DebugComponent() = default;
inline void Disable(DebugDrawFlags flags);
inline void Enable(DebugDrawFlags flags);
inline DebugDrawFlags GetFlags() const;
inline bool IsEnabled(DebugDrawFlags flags) const;
inline DebugComponent& operator=(const DebugComponent& debug);
static ComponentIndex componentIndex;
private:
void DetachDebugRenderables(GraphicsComponent& gfxComponent);
inline const Nz::InstancedRenderableRef& GetDebugRenderable(DebugDraw option) const;
inline DebugDrawFlags GetEnabledFlags() const;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
inline void UpdateDebugRenderable(DebugDraw option, Nz::InstancedRenderableRef renderable);
inline void UpdateEnabledFlags(DebugDrawFlags flags);
static constexpr std::size_t DebugModeCount = static_cast<std::size_t>(DebugDraw::Max) + 1;
std::array<Nz::InstancedRenderableRef, DebugModeCount> m_debugRenderables;
DebugDrawFlags m_enabledFlags;
DebugDrawFlags m_flags;
};
}
#include <NazaraSDK/Components/DebugComponent.inl>
#endif // NDK_COMPONENTS_DEBUGCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -1,74 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Components/DebugComponent.hpp>
namespace Ndk
{
inline DebugComponent::DebugComponent(DebugDrawFlags flags) :
m_flags(flags)
{
}
inline DebugComponent::DebugComponent(const DebugComponent& debug) :
m_flags(debug.m_flags)
{
}
inline void DebugComponent::Disable(DebugDrawFlags flags)
{
m_flags &= ~flags;
if (m_entity)
m_entity->Invalidate();
}
inline void DebugComponent::Enable(DebugDrawFlags flags)
{
m_flags |= flags;
if (m_entity)
m_entity->Invalidate();
}
inline DebugDrawFlags DebugComponent::GetFlags() const
{
return m_flags;
}
inline bool DebugComponent::IsEnabled(DebugDrawFlags flags) const
{
return (m_flags & flags) == flags;
}
inline DebugComponent& DebugComponent::operator=(const DebugComponent& debug)
{
m_flags = debug.m_flags;
if (m_entity)
m_entity->Invalidate();
return *this;
}
inline const Nz::InstancedRenderableRef& DebugComponent::GetDebugRenderable(DebugDraw option) const
{
return m_debugRenderables[static_cast<std::size_t>(option)];
}
inline DebugDrawFlags DebugComponent::GetEnabledFlags() const
{
return m_enabledFlags;
}
inline void DebugComponent::UpdateDebugRenderable(DebugDraw option, Nz::InstancedRenderableRef renderable)
{
m_debugRenderables[static_cast<std::size_t>(option)] = std::move(renderable);
}
inline void DebugComponent::UpdateEnabledFlags(DebugDrawFlags flags)
{
m_enabledFlags = flags;
}
}

View File

@@ -1,170 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#include <Nazara/Graphics/CullingList.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Utility/Node.hpp>
#include <NazaraSDK/Component.hpp>
#include <unordered_map>
namespace Ndk
{
class GraphicsComponent;
using GraphicsComponentCullingList = Nz::CullingList<GraphicsComponent>;
using GraphicsComponentHandle = Nz::ObjectHandle<GraphicsComponent>;
class NDK_API GraphicsComponent : public Component<GraphicsComponent>
{
friend class RenderSystem;
public:
using RenderableList = std::vector<Nz::InstancedRenderableRef>;
inline GraphicsComponent();
inline GraphicsComponent(const GraphicsComponent& graphicsComponent);
~GraphicsComponent() = default;
inline void AddToCullingList(GraphicsComponentCullingList* cullingList) const;
void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const;
void AddToRenderQueueByCulling(const Nz::Frustumf& frustum, Nz::AbstractRenderQueue* renderQueue) const;
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 EnsureBoundingVolumesUpdate() const;
inline void EnsureTransformMatrixUpdate() const;
template<typename Func> void ForEachRenderable(const Func& func) const;
inline const Nz::Boxf& GetAABB() const;
inline void GetAttachedRenderables(RenderableList* renderables) const;
inline std::size_t GetAttachedRenderableCount() const;
inline const Nz::BoundingVolumef& GetBoundingVolume(std::size_t renderableIndex) const;
inline const Nz::Matrix4f& GetLocalMatrix(std::size_t renderableIndex) const;
inline const Nz::Matrix4f& GetTransformMatrix(std::size_t renderableIndex) const;
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 ForceCullingInvalidation();
inline void InvalidateAABB() 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 UpdateBoundingVolumes() const;
void UpdateTransformMatrix() const;
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
using CullingListBoxEntry = GraphicsComponentCullingList::BoxEntry;
struct CullingBoxEntry
{
CullingListBoxEntry listEntry;
NazaraSlot(GraphicsComponentCullingList, OnCullingListRelease, cullingListReleaseSlot);
};
struct MaterialEntry
{
NazaraSlot(Nz::Material, OnMaterialReflectionModeChange, reflectionModelChangeSlot);
std::size_t renderableCounter;
};
struct Renderable
{
Renderable(const Nz::Matrix4f& transformMatrix) :
data(transformMatrix),
dataUpdated(false)
{
}
Renderable(const Renderable&) = delete;
Renderable(Renderable&& rhs) noexcept = default;
~Renderable()
{
// Disconnect release slot before releasing instanced renderable reference
renderableReleaseSlot.Disconnect();
}
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::BoundingVolumef boundingVolume;
mutable Nz::InstancedRenderable::InstanceData data;
Nz::InstancedRenderableRef renderable;
mutable bool dataUpdated;
};
std::size_t m_reflectiveMaterialCount;
mutable std::vector<CullingBoxEntry> m_cullingBoxEntries;
std::vector<Renderable> m_renderables;
std::unordered_map<const Nz::Material*, MaterialEntry> m_materialEntries;
mutable Nz::Boxf m_aabb;
mutable Nz::Matrix4f m_transformMatrix;
Nz::Recti m_scissorRect;
Nz::TextureRef m_reflectionMap;
mutable bool m_boundingVolumesUpdated;
mutable bool m_transformMatrixUpdated;
unsigned int m_reflectionMapSize;
};
}
#include <NazaraSDK/Components/GraphicsComponent.inl>
#endif // NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -1,291 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Components/GraphicsComponent.hpp>
#include <NazaraSDK/World.hpp>
#include <NazaraSDK/Systems/RenderSystem.hpp>
#include <algorithm>
namespace Ndk
{
inline GraphicsComponent::GraphicsComponent() :
m_reflectiveMaterialCount(0),
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),
m_reflectiveMaterialCount(0),
m_aabb(graphicsComponent.m_aabb),
m_transformMatrix(graphicsComponent.m_transformMatrix),
m_scissorRect(graphicsComponent.m_scissorRect),
m_boundingVolumesUpdated(graphicsComponent.m_boundingVolumesUpdated),
m_transformMatrixUpdated(graphicsComponent.m_transformMatrixUpdated)
{
m_renderables.reserve(graphicsComponent.m_renderables.size());
for (const Renderable& r : graphicsComponent.m_renderables)
Attach(r.renderable, r.data.localMatrix, r.data.renderOrder);
}
inline void GraphicsComponent::AddToCullingList(GraphicsComponentCullingList* cullingList) const
{
m_cullingBoxEntries.emplace_back();
CullingBoxEntry& entry = m_cullingBoxEntries.back();
entry.cullingListReleaseSlot.Connect(cullingList->OnCullingListRelease, this, &GraphicsComponent::RemoveFromCullingList);
entry.listEntry = cullingList->RegisterBoxTest(this);
InvalidateAABB();
}
/*!
* \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();
}
InvalidateAABB();
}
/*!
* \brief Detaches a renderable to the entity
*
* \param renderable Reference to a renderable element
*/
inline void GraphicsComponent::Detach(const Nz::InstancedRenderable* renderable)
{
for (auto it = m_renderables.begin(); it != m_renderables.end(); ++it)
{
if (it->renderable == renderable)
{
InvalidateAABB();
std::size_t materialCount = renderable->GetMaterialCount();
for (std::size_t i = 0; i < materialCount; ++i)
UnregisterMaterial(renderable->GetMaterial(i));
m_renderables.erase(it);
ForceCullingInvalidation();
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
*/
inline void GraphicsComponent::EnsureBoundingVolumesUpdate() const
{
if (!m_boundingVolumesUpdated)
UpdateBoundingVolumes();
}
/*!
* \brief Ensures the transformation matrix is up to date
*/
inline void GraphicsComponent::EnsureTransformMatrixUpdate() const
{
if (!m_transformMatrixUpdated)
UpdateTransformMatrix();
}
/*!
* \brief Gets the axis-aligned bounding box of the entity
* \return A constant reference to the AABB
*/
inline const Nz::Boxf& GraphicsComponent::GetAABB() const
{
EnsureBoundingVolumesUpdate();
return m_aabb;
}
/*!
* \brief Gets the set of renderable elements
*
* \param renderables Pointer to the list of renderables
*
* \remark Produces a NazaraAssert if renderables is invalid
*/
inline void GraphicsComponent::GetAttachedRenderables(RenderableList* renderables) const
{
NazaraAssert(renderables, "Invalid renderable list");
renderables->reserve(renderables->size() + m_renderables.size());
for (const Renderable& r : m_renderables)
renderables->push_back(r.renderable);
}
/*!
* \brief Gets the number of renderable elements attached to the entity
* \return Number of renderable elements
*/
inline std::size_t GraphicsComponent::GetAttachedRenderableCount() const
{
return m_renderables.size();
}
inline const Nz::BoundingVolumef& GraphicsComponent::GetBoundingVolume(std::size_t renderableIndex) const
{
EnsureBoundingVolumesUpdate();
assert(renderableIndex < m_renderables.size());
return m_renderables[renderableIndex].boundingVolume;
}
inline const Nz::Matrix4f& GraphicsComponent::GetLocalMatrix(std::size_t renderableIndex) const
{
assert(renderableIndex < m_renderables.size());
return m_renderables[renderableIndex].data.localMatrix;
}
inline const Nz::Matrix4f& GraphicsComponent::GetTransformMatrix(std::size_t renderableIndex) const
{
EnsureBoundingVolumesUpdate();
assert(renderableIndex < m_renderables.size());
return m_renderables[renderableIndex].data.transformMatrix;
}
/*!
* \brief Calls a function for every renderable attached to this component
*
* \param func Callback function which will be called with renderable data
*/
template<typename Func>
void GraphicsComponent::ForEachRenderable(const Func& func) const
{
for (const auto& renderableData : m_renderables)
func(renderableData.renderable, renderableData.data.localMatrix, renderableData.data.renderOrder);
}
inline void GraphicsComponent::RemoveFromCullingList(GraphicsComponentCullingList* cullingList) const
{
for (auto it = m_cullingBoxEntries.begin(); it != m_cullingBoxEntries.end(); ++it)
{
if (it->listEntry.GetParent() == cullingList)
{
if (m_cullingBoxEntries.size() > 1)
*it = std::move(m_cullingBoxEntries.back());
m_cullingBoxEntries.pop_back();
break;
}
}
}
inline void GraphicsComponent::SetScissorRect(const Nz::Recti& scissorRect)
{
m_scissorRect = scissorRect;
for (CullingBoxEntry& entry : m_cullingBoxEntries)
entry.listEntry.ForceInvalidation(); //< Invalidate render queues
}
inline void GraphicsComponent::UpdateLocalMatrix(const Nz::InstancedRenderable* instancedRenderable, const Nz::Matrix4f& localMatrix)
{
for (auto& renderable : m_renderables)
{
if (renderable.renderable == instancedRenderable)
{
renderable.data.localMatrix = localMatrix;
InvalidateAABB();
break;
}
}
}
inline void GraphicsComponent::UpdateRenderOrder(const Nz::InstancedRenderable* instancedRenderable, int renderOrder)
{
for (auto& renderable : m_renderables)
{
if (renderable.renderable == instancedRenderable)
{
renderable.data.renderOrder = renderOrder;
break;
}
}
}
/*!
* \brief Invalidates the bounding volume
*/
inline void GraphicsComponent::ForceCullingInvalidation()
{
for (CullingBoxEntry& entry : m_cullingBoxEntries)
entry.listEntry.ForceInvalidation(); //< Invalidate render queues
}
inline void GraphicsComponent::InvalidateAABB() const
{
m_boundingVolumesUpdated = false;
}
/*!
* \brief Invalidates every renderable elements
*/
inline void GraphicsComponent::InvalidateRenderables()
{
for (Renderable& r : m_renderables)
r.dataUpdated = false;
}
/*!
* \brief Invalidates the transformation matrix
*/
inline void GraphicsComponent::InvalidateTransformMatrix()
{
m_transformMatrixUpdated = false;
InvalidateAABB();
InvalidateRenderables();
}
}

View File

@@ -1,40 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_COMPONENTS_LIFETIMECOMPONENT_HPP
#define NDK_COMPONENTS_LIFETIMECOMPONENT_HPP
#include <NazaraSDK/Component.hpp>
namespace Ndk
{
class LifetimeComponent;
using LifetimeComponentHandle = Nz::ObjectHandle<LifetimeComponent>;
class NDK_API LifetimeComponent : public Component<LifetimeComponent>
{
friend class LifetimeSystem;
public:
inline LifetimeComponent(float lifetime);
LifetimeComponent(const LifetimeComponent&) = default;
~LifetimeComponent() = default;
inline float GetRemainingTime() const;
static ComponentIndex componentIndex;
private:
inline bool UpdateLifetime(float elapsedTime);
float m_lifetime;
};
}
#include <NazaraSDK/Components/LifetimeComponent.inl>
#endif // NDK_COMPONENTS_LIFETIMECOMPONENT_HPP

View File

@@ -1,24 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Components/LifetimeComponent.hpp>
namespace Ndk
{
inline LifetimeComponent::LifetimeComponent(float lifetime) :
m_lifetime(lifetime)
{
}
inline float Ndk::LifetimeComponent::GetRemainingTime() const
{
return m_lifetime;
}
inline bool LifetimeComponent::UpdateLifetime(float elapsedTime)
{
m_lifetime -= elapsedTime;
return m_lifetime < 0.f;
}
}

View File

@@ -1,36 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_LIGHTCOMPONENT_HPP
#define NDK_COMPONENTS_LIGHTCOMPONENT_HPP
#include <Nazara/Graphics/Light.hpp>
#include <NazaraSDK/Component.hpp>
namespace Ndk
{
class LightComponent;
using LightComponentHandle = Nz::ObjectHandle<LightComponent>;
class NDK_API LightComponent : public Component<LightComponent>, public Nz::Light
{
public:
inline LightComponent(Nz::LightType lightType = Nz::LightType_Point);
LightComponent(const LightComponent& light) = default;
~LightComponent() = default;
LightComponent& operator=(const LightComponent& light) = default;
static ComponentIndex componentIndex;
};
}
#include <NazaraSDK/Components/LightComponent.inl>
#endif // NDK_COMPONENTS_LIGHTCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -1,15 +0,0 @@
// 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 Prerequisites.hpp
namespace Ndk
{
/*!
* \brief Constructs an LightComponent object with a light type
*/
inline LightComponent::LightComponent(Nz::LightType lightType) :
Nz::Light(lightType)
{
}
}

View File

@@ -1,38 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_LISTENERCOMPONENT_HPP
#define NDK_COMPONENTS_LISTENERCOMPONENT_HPP
#include <NazaraSDK/Component.hpp>
namespace Ndk
{
class ListenerComponent;
using ListenerComponentHandle = Nz::ObjectHandle<ListenerComponent>;
class NDK_API ListenerComponent : public Component<ListenerComponent>
{
public:
inline ListenerComponent();
~ListenerComponent() = default;
inline bool IsActive() const;
inline void SetActive(bool active = true);
static ComponentIndex componentIndex;
private:
bool m_isActive;
};
}
#include <NazaraSDK/Components/ListenerComponent.inl>
#endif // NDK_COMPONENTS_LISTENERCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -1,36 +0,0 @@
// 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 Prerequisites.hpp
namespace Ndk
{
/*!
* \brief Constructs an ListenerComponent object by default
*/
inline ListenerComponent::ListenerComponent() :
m_isActive(true)
{
}
/*!
* \brief Checks whether the listener is activated
* \param true If it is the case
*/
inline bool ListenerComponent::IsActive() const
{
return m_isActive;
}
/*!
* \brief Enables the listener
*
* \param active Should the listener be active
*/
inline void ListenerComponent::SetActive(bool active)
{
m_isActive = active;
}
}

View File

@@ -1,35 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_COMPONENTS_NODECOMPONENT_HPP
#define NDK_COMPONENTS_NODECOMPONENT_HPP
#include <Nazara/Utility/Node.hpp>
#include <NazaraSDK/Component.hpp>
namespace Ndk
{
class Entity;
class NodeComponent;
using NodeComponentHandle = Nz::ObjectHandle<NodeComponent>;
class NDK_API NodeComponent : public Component<NodeComponent>, public Nz::Node
{
public:
NodeComponent() = default;
~NodeComponent() = default;
void SetParent(Entity* entity, bool keepDerived = false);
using Nz::Node::SetParent;
static ComponentIndex componentIndex;
};
}
#include <NazaraSDK/Components/NodeComponent.inl>
#endif // NDK_COMPONENTS_NODECOMPONENT_HPP

View File

@@ -1,30 +0,0 @@
// 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 Prerequisites.hpp
#include <Nazara/Core/Error.hpp>
#include <NazaraSDK/Entity.hpp>
namespace Ndk
{
/*!
* \brief Sets the parent node of the entity
*
* \param entity Pointer to the entity considered as parent
* \param keepDerived Should this component considered as a derived
*
* \remark Produces a NazaraAssert if entity has no component NodeComponent
*/
inline void NodeComponent::SetParent(Entity* entity, bool keepDerived)
{
if (entity)
{
NazaraAssert(entity->HasComponent<NodeComponent>(), "Entity must have a NodeComponent");
Nz::Node::SetParent(entity->GetComponent<NodeComponent>(), keepDerived);
}
else
Nz::Node::SetParent(nullptr, keepDerived);
}
}

View File

@@ -1,49 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
#define NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
#include <Nazara/Graphics/ParticleEmitter.hpp>
#include <NazaraSDK/Component.hpp>
namespace Ndk
{
class ParticleEmitterComponent;
using ParticleEmitterComponentHandle = Nz::ObjectHandle<ParticleEmitterComponent>;
class NDK_API ParticleEmitterComponent : public Component<ParticleEmitterComponent>, public Nz::ParticleEmitter
{
public:
using SetupFunc = std::function<void(const EntityHandle& /*entity*/, Nz::ParticleMapper& /*mapper*/, unsigned int /*count*/)>;
inline ParticleEmitterComponent();
ParticleEmitterComponent(const ParticleEmitterComponent& emitter) = default;
ParticleEmitterComponent(ParticleEmitterComponent&& emitter) = default;
~ParticleEmitterComponent() = default;
inline void Enable(bool active = true);
inline bool IsActive() const;
inline void SetSetupFunc(SetupFunc func);
static ComponentIndex componentIndex;
private:
void SetupParticles(Nz::ParticleMapper& mapper, unsigned int count) const override;
SetupFunc m_setupFunc;
bool m_isActive;
};
}
#include <NazaraSDK/Components/ParticleEmitterComponent.inl>
#endif // NDK_COMPONENTS_PARTICLEEMITTERCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -1,47 +0,0 @@
// 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 Prerequisites.hpp
namespace Ndk
{
/*!
* \brief Constructs an ParticleEmitterComponent object by default
*/
inline ParticleEmitterComponent::ParticleEmitterComponent() :
m_isActive(true)
{
}
/*!
* \brief Enables the emission of particles
*
* \param active Should the emitter be active
*/
inline void Ndk::ParticleEmitterComponent::Enable(bool active)
{
m_isActive = active;
}
/*!
* \brief Checks whether the emission of particles is activated
* \param true If it is the case
*/
inline bool ParticleEmitterComponent::IsActive() const
{
return m_isActive;
}
/*!
* \brief Sets the function use for setting up particles
*
* \param func Function to set up particles
*/
inline void Ndk::ParticleEmitterComponent::SetSetupFunc(SetupFunc func)
{
m_setupFunc = std::move(func);
}
}

View File

@@ -1,41 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP
#define NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP
#include <Nazara/Graphics/ParticleGroup.hpp>
#include <NazaraSDK/Component.hpp>
namespace Ndk
{
class ParticleGroupComponent;
using ParticleGroupComponentHandle = Nz::ObjectHandle<ParticleGroupComponent>;
class NDK_API ParticleGroupComponent : public Component<ParticleGroupComponent>, public Nz::ParticleGroup
{
public:
inline ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleLayout layout);
inline ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleDeclarationConstRef declaration);
ParticleGroupComponent(const ParticleGroupComponent&) = default;
~ParticleGroupComponent() = default;
void AddEmitter(Entity* emitter);
using ParticleGroup::AddEmitter;
void RemoveEmitter(Entity* emitter);
using ParticleGroup::RemoveEmitter;
static ComponentIndex componentIndex;
};
}
#include <NazaraSDK/Components/ParticleGroupComponent.inl>
#endif // NDK_COMPONENTS_PARTICLEGROUPCOMPONENT_HPP
#endif // NDK_SERVER

View File

@@ -1,76 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Components/ParticleEmitterComponent.hpp>
#include <Nazara/Core/Error.hpp>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::ParticleGroupComponent
* \brief NDK class that represents the component for a group of particles
*/
/*!
* \brief Constructs a ParticleGroupComponent object with a maximal number of particles and a layout
*
* \param maxParticleCount Maximum number of particles to generate
* \param layout Enumeration for the layout of data information for the particles
*/
inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleLayout layout) :
ParticleGroup(maxParticleCount, layout)
{
}
/*!
* \brief Constructs a ParticleGroupComponent object with a maximal number of particles and a particle declaration
*
* \param maxParticleCount Maximum number of particles to generate
* \param declaration Data information for the particles
*/
inline ParticleGroupComponent::ParticleGroupComponent(unsigned int maxParticleCount, Nz::ParticleDeclarationConstRef declaration) :
ParticleGroup(maxParticleCount, std::move(declaration))
{
}
/*!
* \brief Adds an emitter to the particles
*
* \param emitter Emitter for the particles
*
* \remark Produces a NazaraAssert if emitter is invalid
* \remark Produces a NazaraAssert if entity has no component of type ParticleEmitterComponent
*/
inline void ParticleGroupComponent::AddEmitter(Entity* emitter)
{
NazaraAssert(emitter && emitter->IsValid(), "Invalid entity");
NazaraAssert(emitter->HasComponent<ParticleEmitterComponent>(), "Entity must have a ParticleEmitterComponent");
auto& emitterComponent = emitter->GetComponent<ParticleEmitterComponent>();
ParticleGroup::AddEmitter(&emitterComponent);
}
/*!
* \brief Removes an emitter to the particles
*
* \param emitter Emitter for the particles to remove
*
* \remark Produces a NazaraAssert if emitter is invalid
* \remark Produces a NazaraAssert if entity has no component of type ParticleEmitterComponent
*/
inline void ParticleGroupComponent::RemoveEmitter(Entity* emitter)
{
NazaraAssert(emitter && emitter->IsValid(), "Invalid entity");
NazaraAssert(emitter->HasComponent<ParticleEmitterComponent>(), "Entity must have a ParticleEmitterComponent");
auto& emitterComponent = emitter->GetComponent<ParticleEmitterComponent>();
ParticleGroup::RemoveEmitter(&emitterComponent);
}
}

View File

@@ -1,130 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_COMPONENTS_PHYSICSCOMPONENT2D_HPP
#define NDK_COMPONENTS_PHYSICSCOMPONENT2D_HPP
#include <Nazara/Physics2D/RigidBody2D.hpp>
#include <NazaraSDK/Component.hpp>
#include <memory>
namespace Ndk
{
class PhysicsComponent2D;
using PhysicsComponent2DHandle = Nz::ObjectHandle<PhysicsComponent2D>;
class NDK_API PhysicsComponent2D : public Component<PhysicsComponent2D>
{
friend class CollisionComponent2D;
friend class PhysicsSystem2D;
friend class ConstraintComponent2D;
public:
using VelocityFunc = Nz::RigidBody2D::VelocityFunc;
PhysicsComponent2D();
PhysicsComponent2D(const PhysicsComponent2D& physics);
~PhysicsComponent2D() = default;
inline void AddForce(const Nz::Vector2f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddForce(const Nz::Vector2f& force, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddImpulse(const Nz::Vector2f& impulse, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddImpulse(const Nz::Vector2f& impulse, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddTorque(const Nz::RadianAnglef& torque);
inline bool ClosestPointQuery(const Nz::Vector2f& position, Nz::Vector2f* closestPoint, float* closestDistance) const;
inline void EnableNodeSynchronization(bool nodeSynchronization);
inline void ForceSleep();
inline void ForEachArbiter(const std::function<void(Nz::Arbiter2D&)>& callback);
inline Nz::Rectf GetAABB() const;
inline float GetAngularDamping() const;
inline Nz::RadianAnglef GetAngularVelocity() const;
NAZARA_DEPRECATED("Name error, please use GetMassCenter")
inline Nz::Vector2f GetCenterOfGravity(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
inline float GetElasticity(std::size_t shapeIndex = 0) const;
inline float GetFriction(std::size_t shapeIndex = 0) const;
inline float GetMass() const;
inline Nz::Vector2f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
inline float GetMomentOfInertia() const;
inline Nz::Vector2f GetPosition() const;
inline Nz::RadianAnglef GetRotation() const;
inline Nz::Vector2f GetSurfaceVelocity(std::size_t shapeIndex = 0) const;
inline std::size_t GetShapeCount() const;
inline Nz::Vector2f GetVelocity() const;
const VelocityFunc& GetVelocityFunction() const;
inline bool IsNodeSynchronizationEnabled() const;
inline bool IsSleeping() const;
inline bool IsValid() const;
inline void ResetVelocityFunction();
inline void SetAngularDamping(float angularDamping);
inline void SetAngularVelocity(const Nz::RadianAnglef& angularVelocity);
inline void SetElasticity(float elasticity);
inline void SetElasticity(std::size_t shapeIndex, float friction);
inline void SetFriction(float friction);
inline void SetFriction(std::size_t shapeIndex, float friction);
inline void SetMass(float mass, bool recomputeMoment = true);
inline void SetMassCenter(const Nz::Vector2f& center, Nz::CoordSys coordSys = Nz::CoordSys_Local);
inline void SetMomentOfInertia(float moment);
inline void SetPosition(const Nz::Vector2f& position);
inline void SetRotation(const Nz::RadianAnglef& rotation);
inline void SetSurfaceVelocity(const Nz::Vector2f& velocity);
inline void SetSurfaceVelocity(std::size_t shapeIndex, const Nz::Vector2f& velocity);
inline void SetVelocity(const Nz::Vector2f& velocity);
inline void SetVelocityFunction(VelocityFunc velocityFunc);
inline void UpdateVelocity(const Nz::Vector2f& gravity, float damping, float deltaTime);
inline void Wakeup();
static ComponentIndex componentIndex;
private:
inline void ApplyPhysicsState(Nz::RigidBody2D& rigidBody) const;
inline void CopyPhysicsState(const Nz::RigidBody2D& rigidBody);
Nz::RigidBody2D* GetRigidBody();
const Nz::RigidBody2D* GetRigidBody() const;
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
void OnEntityDestruction() override;
struct PendingPhysObjectStates
{
struct ShapeStates
{
Nz::Vector2f surfaceVelocity;
float elasticity;
float friction;
};
VelocityFunc velocityFunc;
std::vector<ShapeStates> shapes;
Nz::RadianAnglef angularVelocity;
Nz::Vector2f massCenter;
Nz::Vector2f velocity;
bool valid = false;
float mass;
float momentOfInertia;
};
std::unique_ptr<Nz::RigidBody2D> m_object;
PendingPhysObjectStates m_pendingStates;
bool m_nodeSynchronizationEnabled;
};
}
#include <NazaraSDK/Components/PhysicsComponent2D.inl>
#endif // NDK_COMPONENTS_PHYSICSCOMPONENT2D_HPP

View File

@@ -1,725 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Components/PhysicsComponent2D.hpp>
#include <Nazara/Core/Error.hpp>
namespace Ndk
{
/*!
* \brief Constructs a PhysicsComponent2D object by default
*/
inline PhysicsComponent2D::PhysicsComponent2D() :
m_nodeSynchronizationEnabled(true)
{
}
/*!
* \brief Constructs a PhysicsComponent2D object by copy semantic
*
* \param physics PhysicsComponent2D to copy
*/
inline PhysicsComponent2D::PhysicsComponent2D(const PhysicsComponent2D& physics)
{
CopyPhysicsState(*physics.GetRigidBody());
}
/*!
* \brief Applies a physics force to the entity
*
* \param force Force to apply on the entity
* \param coordSys System coordinates to consider
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::AddForce(const Nz::Vector2f& force, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->AddForce(force, coordSys);
}
/*!
* \brief Applies a physics force to the entity
*
* \param force Force to apply on the entity
* \param point Point where to apply the force
* \param coordSys System coordinates to consider
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::AddForce(const Nz::Vector2f& force, const Nz::Vector2f& point, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
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
*
* \param torque Torque to apply on the entity
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::AddTorque(const Nz::RadianAnglef& torque)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->AddTorque(torque);
}
/*!
* \brief Finds the closest point on the entity relative to a position
* \return True if such a point exists (will return false if no collider exists)
*
* \param position The starting point which will be used for the query
* \param closestPoint The closest point on entity surface
* \param closestDistance The distance between the closest point and the starting point, may be negative if starting point is inside the entity
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline bool PhysicsComponent2D::ClosestPointQuery(const Nz::Vector2f& position, Nz::Vector2f* closestPoint, float* closestDistance) const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->ClosestPointQuery(position, closestPoint, closestDistance);
}
/*!
* \brief Enables position/rotation synchronization with the NodeComponent
*
* By default, at every update of the PhysicsSystem2D, the NodeComponent's position and rotation (if any) will be synchronized with
* the values of the PhysicsComponent2D. This function allows to enable/disable this behavior on a per-entity basis.
*
* \param nodeSynchronization Should synchronization occur between NodeComponent and PhysicsComponent2D
*/
inline void PhysicsComponent2D::EnableNodeSynchronization(bool nodeSynchronization)
{
m_nodeSynchronizationEnabled = nodeSynchronization;
if (m_entity)
m_entity->Invalidate();
}
/*!
TODO
*/
inline void PhysicsComponent2D::ForceSleep()
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->ForceSleep();
}
/*!
TODO
*/
inline void PhysicsComponent2D::ForEachArbiter(const std::function<void(Nz::Arbiter2D&)>& callback)
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->ForEachArbiter(callback);
}
/*!
* \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::Rectf PhysicsComponent2D::GetAABB() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetAABB();
}
/*!
* \brief Gets the angular damping or moment of inertia of the physics object
* \return Angular damping of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*
* \see GetMomentOfInertia
*/
inline float PhysicsComponent2D::GetAngularDamping() const
{
NazaraAssert(m_object, "Invalid physics object");
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::RadianAnglef PhysicsComponent2D::GetAngularVelocity() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetAngularVelocity();
}
/*!
* \brief Gets the gravity center of the physics object
* \return Gravity center of the object
*
* \param coordSys System coordinates to consider
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector2f PhysicsComponent2D::GetCenterOfGravity(Nz::CoordSys coordSys) const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetMassCenter(coordSys);
}
/*!
* \brief Gets the elasticity of a shape belonging to this physics object
* \return Elasticity of the shape
*
* \param shapeIndex Shape index of the collider we're interested
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent2D::GetElasticity(std::size_t shapeIndex) const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetElasticity(shapeIndex);
}
/*!
* \brief Gets the friction of a shape belonging to this physics object
* \return Friction of the shape
*
* \param shapeIndex Shape index of the collider we're interested
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent2D::GetFriction(std::size_t shapeIndex) const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetFriction(shapeIndex);
}
/*!
* \brief Gets the mass of the physics object
* \return Mass of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent2D::GetMass() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetMass();
}
/*!
* \brief Gets the gravity center of the physics object
* \return Gravity center of the object
*
* \param coordSys System coordinates to consider
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector2f PhysicsComponent2D::GetMassCenter(Nz::CoordSys coordSys) const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetMassCenter(coordSys);
}
/*!
* \brief Gets the angular damping or moment of inertia of the physics object
* \return Moment of inertia of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*
* \see GetAngularDamping
*/
inline float PhysicsComponent2D::GetMomentOfInertia() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetMomentOfInertia();
}
/*!
* \brief Gets the position of the physics object
* \return Position of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector2f PhysicsComponent2D::GetPosition() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetPosition();
}
/*!
* \brief Gets the rotation of the physics object
* \return Rotation of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::RadianAnglef PhysicsComponent2D::GetRotation() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetRotation();
}
/*!
* \brief Gets the surface velocity of a shape belonging to this physics object
* \return Surface velocity of the shape
*
* \param shapeIndex Shape index of the collider we're interested
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector2f PhysicsComponent2D::GetSurfaceVelocity(std::size_t shapeIndex) const
{
return m_object->GetSurfaceVelocity(shapeIndex);
}
/*!
* \brief Gets the rotation of the physics object
* \return Shape count of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline std::size_t PhysicsComponent2D::GetShapeCount() const
{
return m_object->GetShapeCount();
}
/*!
* \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::Vector2f PhysicsComponent2D::GetVelocity() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetVelocity();
}
/*!
* \brief Gets the custom velocity function of the physics object
* \return Velocity function of the object (may be empty if default function is used)
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline auto PhysicsComponent2D::GetVelocityFunction() const -> const VelocityFunc&
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetVelocityFunction();
}
/*!
* \brief Checks if position & rotation are synchronized with NodeComponent
* \return true If synchronization is enabled
*
* \see EnableNodeSynchronization
*/
inline bool PhysicsComponent2D::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 PhysicsComponent2D::IsSleeping() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->IsSleeping();
}
/*!
* \brief Checks if this component is bound to a valid rigid body
*
* A component may not be bound to a rigid body if the component is not bound to an entity or if this entity is being destroyed
*
* \return true If bound, false otherwise
*/
inline bool PhysicsComponent2D::IsValid() const
{
return bool(m_object);
}
/*!
* \brief Reset velocity function to default one
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::ResetVelocityFunction()
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->ResetVelocityFunction();
}
/*!
* \brief Sets the angular damping or moment of inertia of the physics object
*
* \param angularDamping Angular damping of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*
* \see SetMomentOfInertia
*/
inline void PhysicsComponent2D::SetAngularDamping(float angularDamping)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetAngularDamping(angularDamping);
}
/*!
* \brief Sets the angular velocity of the physics object
*
* \param angularVelocity Angular velocity of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::SetAngularVelocity(const Nz::RadianAnglef& angularVelocity)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetAngularVelocity(angularVelocity);
}
/*!
* \brief Sets the elasticity of the whole physics object
*
* Overrides all shapes elasticity with a single value
*
* \param elasticity Elasticity to be applied
*
* \remark Elasticity must be positive or zero
*/
inline void PhysicsComponent2D::SetElasticity(float elasticity)
{
NazaraAssert(m_object, "Invalid physics object");
NazaraAssert(elasticity >= 0.f, "Friction must be positive");
m_object->SetElasticity(elasticity);
}
/*!
* \brief Sets the elasticity of a single shape of the physics object
*
* \param shapeIndex Target shape index
* \param elasticity Elasticity to be applied
*
* \remark Elasticity must be positive or zero
*/
inline void PhysicsComponent2D::SetElasticity(std::size_t shapeIndex, float elasticity)
{
NazaraAssert(m_object, "Invalid physics object");
NazaraAssert(elasticity >= 0.f, "Friction must be positive");
m_object->SetElasticity(shapeIndex, elasticity);
}
/*!
* \brief Sets the friction of the whole physics object
*
* Overrides all shapes friction with a single value
*
* \param friction Friction to be applied
*
* \remark Friction must be positive or zero
*/
inline void PhysicsComponent2D::SetFriction(float friction)
{
NazaraAssert(m_object, "Invalid physics object");
NazaraAssert(friction >= 0.f, "Friction must be positive");
m_object->SetFriction(friction);
}
/*!
* \brief Sets the friction of a single shape of the physics object
*
* \param shapeIndex Target shape index
* \param friction Friction to be applied
*
* \remark Friction must be positive or zero
*/
inline void PhysicsComponent2D::SetFriction(std::size_t shapeIndex, float friction)
{
NazaraAssert(m_object, "Invalid physics object");
NazaraAssert(friction >= 0.f, "Friction must be positive");
m_object->SetFriction(shapeIndex, friction);
}
/*!
* \brief Sets the mass of the physics object
*
* \param mass Mass of the object
* \param recomputeMoment Should the moment of inertia be recomputed according to the new mass
*
* \remark Mass must be positive or zero
*/
inline void PhysicsComponent2D::SetMass(float mass, bool recomputeMoment)
{
NazaraAssert(m_object, "Invalid physics object");
NazaraAssert(mass >= 0.f, "Mass should be positive");
m_object->SetMass(mass, recomputeMoment);
}
/*!
* \brief Sets the gravity center of the physics object
*
* \param center Gravity center of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::SetMassCenter(const Nz::Vector2f& center, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetMassCenter(center, coordSys);
}
/*!
* \brief Sets the angular damping or moment of inertia of the physics object
*
* \param moment Moment of inertia of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*
* \see SetAngularDamping
*/
inline void PhysicsComponent2D::SetMomentOfInertia(float moment)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetMomentOfInertia(moment);
}
/*!
* \brief Sets the position of the physics object
*
* \param position Position of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::SetPosition(const Nz::Vector2f& position)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetPosition(position);
}
/*!
* \brief Sets the rotation of the physics object
*
* \param rotation Rotation of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent2D::SetRotation(const Nz::RadianAnglef& rotation)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetRotation(rotation);
}
/*!
* \brief Sets the surface velocity of the whole physics object
*
* Overrides all shapes surface velocity with a single value
*
* \param velocity Surface velocity to be applied
*/
inline void PhysicsComponent2D::SetSurfaceVelocity(const Nz::Vector2f& velocity)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetSurfaceVelocity(velocity);
}
/*!
* \brief Sets the surface velocity of a single shape of the physics object
*
* \param shapeIndex Target shape index
* \param velocity Surface velocity to be applied
*/
inline void PhysicsComponent2D::SetSurfaceVelocity(std::size_t shapeIndex, const Nz::Vector2f& velocity)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetSurfaceVelocity(shapeIndex, velocity);
}
/*!
* \brief Sets the velocity of the physics object
*
* \param velocity Velocity of the object
*/
inline void PhysicsComponent2D::SetVelocity(const Nz::Vector2f& velocity)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetVelocity(velocity);
}
/*!
* \brief Sets a custom velocity function for the physics object
*
* A velocity function is called (for non-kinematic and non-static objects) at every physics update to compute the new velocity of the object.
* You may call UpdateVelocity (the default velocity function) to let the physics engine compute that itself and then adjust it using GetVelocity/SetVelocity as you need.
*
* \param velocityFunc New custom velocity function
*
* \remark Passing an empty VelocityFunc has the same effect as calling ResetVelocityFunction
* \see ResetVelocityFunction
* \see UpdateVelocity
*/
inline void PhysicsComponent2D::SetVelocityFunction(VelocityFunc velocityFunc)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetVelocityFunction(std::move(velocityFunc));
}
/*!
* \brief Calls the physics engine default velocity function
*
* \param gravity Physics system gravity
* \param damping Physics system damping (adjusted to deltaTime)
* \param deltaTime Elapsed time since last physics update
*/
inline void PhysicsComponent2D::UpdateVelocity(const Nz::Vector2f& gravity, float damping, float deltaTime)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->UpdateVelocity(gravity, damping, deltaTime);
}
/*!
TODO
*/
inline void PhysicsComponent2D::Wakeup()
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->Wakeup();
}
inline void PhysicsComponent2D::ApplyPhysicsState(Nz::RigidBody2D& rigidBody) const
{
assert(m_pendingStates.valid);
rigidBody.SetAngularVelocity(m_pendingStates.angularVelocity);
rigidBody.SetMass(m_pendingStates.mass);
rigidBody.SetMassCenter(m_pendingStates.massCenter);
rigidBody.SetMomentOfInertia(m_pendingStates.momentOfInertia);
rigidBody.SetVelocity(m_pendingStates.velocity);
rigidBody.SetVelocityFunction(m_pendingStates.velocityFunc);
for (std::size_t i = 0; i < m_pendingStates.shapes.size(); ++i)
{
auto& shapeData = m_pendingStates.shapes[i];
rigidBody.SetElasticity(i, shapeData.elasticity);
rigidBody.SetFriction(i, shapeData.friction);
rigidBody.SetSurfaceVelocity(i, shapeData.surfaceVelocity);
}
}
inline void PhysicsComponent2D::CopyPhysicsState(const Nz::RigidBody2D& rigidBody)
{
m_pendingStates.valid = true;
m_pendingStates.angularVelocity = rigidBody.GetAngularVelocity();
m_pendingStates.mass = rigidBody.GetMass();
m_pendingStates.massCenter = rigidBody.GetMassCenter();
m_pendingStates.momentOfInertia = rigidBody.GetMomentOfInertia();
m_pendingStates.velocity = rigidBody.GetVelocity();
m_pendingStates.velocityFunc = rigidBody.GetVelocityFunction();
m_pendingStates.shapes.resize(rigidBody.GetShapeCount());
for (std::size_t i = 0; i < m_pendingStates.shapes.size(); ++i)
{
auto& shapeData = m_pendingStates.shapes[i];
shapeData.elasticity = rigidBody.GetElasticity(i);
shapeData.friction = rigidBody.GetFriction(i);
shapeData.surfaceVelocity = rigidBody.GetSurfaceVelocity(i);
}
}
/*!
* \brief Gets the underlying physics object
* \return A reference to the physics object
*/
inline Nz::RigidBody2D* PhysicsComponent2D::GetRigidBody()
{
return m_object.get();
}
inline const Nz::RigidBody2D* PhysicsComponent2D::GetRigidBody() const
{
return m_object.get();
}
}

View File

@@ -1,101 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP
#define NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NazaraSDK/Component.hpp>
#include <memory>
namespace Ndk
{
class PhysicsComponent3D;
using PhysicsComponent3DHandle = Nz::ObjectHandle<PhysicsComponent3D>;
class NDK_API PhysicsComponent3D : public Component<PhysicsComponent3D>
{
friend class CollisionComponent3D;
friend class PhysicsSystem3D;
public:
inline PhysicsComponent3D();
PhysicsComponent3D(const PhysicsComponent3D& physics);
~PhysicsComponent3D() = default;
inline void AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys = Nz::CoordSys_Global);
inline void EnableAutoSleep(bool autoSleep);
inline void EnableNodeSynchronization(bool nodeSynchronization);
inline Nz::Boxf GetAABB() const;
inline Nz::Vector3f GetAngularDamping() const;
inline Nz::Vector3f GetAngularVelocity() const;
inline float GetGravityFactor() const;
inline float GetLinearDamping() const;
inline Nz::Vector3f GetLinearVelocity() const;
inline float GetMass() const;
inline Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const;
inline const Nz::Matrix4f& GetMatrix() const;
inline Nz::Vector3f GetPosition() const;
inline Nz::Quaternionf GetRotation() const;
inline bool IsAutoSleepEnabled() const;
inline bool IsMoveable() const;
inline bool IsNodeSynchronizationEnabled() const;
inline bool IsSleeping() const;
inline void SetAngularDamping(const Nz::Vector3f& angularDamping);
inline void SetAngularVelocity(const Nz::Vector3f& angularVelocity);
inline void SetGravityFactor(float gravityFactor);
inline void SetLinearDamping(float damping);
inline void SetLinearVelocity(const Nz::Vector3f& velocity);
inline void SetMass(float mass);
inline void SetMassCenter(const Nz::Vector3f& center);
inline void SetMaterial(const Nz::String& materialName);
inline void SetMaterial(int materialIndex);
inline void SetPosition(const Nz::Vector3f& position);
inline void SetRotation(const Nz::Quaternionf& rotation);
static ComponentIndex componentIndex;
private:
inline void ApplyPhysicsState(Nz::RigidBody3D& rigidBody) const;
inline void CopyPhysicsState(const Nz::RigidBody3D& rigidBody);
inline Nz::RigidBody3D* GetRigidBody();
inline 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;
};
}
#include <NazaraSDK/Components/PhysicsComponent3D.inl>
#endif // NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP

View File

@@ -1,504 +0,0 @@
// 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 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) :
m_nodeSynchronizationEnabled(physics.m_nodeSynchronizationEnabled)
{
// 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());
}
/*!
* \brief Applies a force to the entity
*
* \param force Force to apply on the entity
* \param coordSys System coordinates to consider
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->AddForce(force, coordSys);
}
/*!
* \brief Applies a force to the entity
*
* \param force Force to apply on the entity
* \param point Point where to apply the force
* \param coordSys System coordinates to consider
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->AddForce(force, point, coordSys);
}
/*!
* \brief Applies a torque to the entity
*
* \param torque Torque to apply on the entity
* \param coordSys System coordinates to consider
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->AddTorque(torque, coordSys);
}
/*!
* \brief Enables auto sleep of physics object
*
* \param autoSleep Should the physics of the object be disabled when too far from others
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::EnableAutoSleep(bool autoSleep)
{
NazaraAssert(m_object, "Invalid physics object");
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");
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");
return m_object->GetAngularVelocity();
}
/*!
* \brief Gets the gravity factor of the physics object
* \return Gravity factor of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent3D::GetGravityFactor() const
{
NazaraAssert(m_object, "Invalid physics object");
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
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent3D::GetMass() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetMass();
}
/*!
* \brief Gets the gravity center of the physics object
* \return Gravity center of the object
*
* \param coordSys System coordinates to consider
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent3D::GetMassCenter(Nz::CoordSys coordSys) const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetMassCenter(coordSys);
}
/*!
* \brief Gets the matrix of the physics object
* \return Matrix of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline const Nz::Matrix4f& PhysicsComponent3D::GetMatrix() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetMatrix();
}
/*!
* \brief Gets the position of the physics object
* \return Position of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent3D::GetPosition() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetPosition();
}
/*!
* \brief Gets the rotation of the physics object
* \return Rotation of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Quaternionf PhysicsComponent3D::GetRotation() const
{
NazaraAssert(m_object, "Invalid physics object");
return m_object->GetRotation();
}
/*!
* \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");
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");
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
*
* \param angularVelocity Angular velocity of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetAngularVelocity(const Nz::Vector3f& angularVelocity)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetAngularVelocity(angularVelocity);
}
/*!
* \brief Sets the gravity factor of the physics object
*
* \param gravityFactor Gravity factor of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetGravityFactor(float gravityFactor)
{
NazaraAssert(m_object, "Invalid physics object");
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
*
* \param mass Mass of the object
*
* \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 must be positive and finite");
NazaraAssert(std::isfinite(mass), "Mass must be positive and finite");
m_object->SetMass(mass);
}
/*!
* \brief Sets the gravity center of the physics object
*
* \param center Gravity center of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetMassCenter(const Nz::Vector3f& center)
{
NazaraAssert(m_object, "Invalid physics object");
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
*
* \param position Position of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetPosition(const Nz::Vector3f& position)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetPosition(position);
}
/*!
* \brief Sets the rotation of the physics object
*
* \param rotation Rotation of the object
*
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent3D::SetRotation(const Nz::Quaternionf& rotation)
{
NazaraAssert(m_object, "Invalid physics object");
m_object->SetRotation(rotation);
}
inline void PhysicsComponent3D::ApplyPhysicsState(Nz::RigidBody3D& rigidBody) const
{
assert(m_pendingStates.valid);
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();
}
/*!
* \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,36 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_COMPONENTS_VELOCITYCOMPONENT_HPP
#define NDK_COMPONENTS_VELOCITYCOMPONENT_HPP
#include <Nazara/Math/Vector3.hpp>
#include <NazaraSDK/Component.hpp>
namespace Ndk
{
class VelocityComponent;
using VelocityComponentHandle = Nz::ObjectHandle<VelocityComponent>;
class NDK_API VelocityComponent : public Component<VelocityComponent>
{
public:
VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero(), Nz::CoordSys coordSystem = Nz::CoordSys_Global);
~VelocityComponent() = default;
Nz::Vector3f linearVelocity;
Nz::CoordSys coordSys;
VelocityComponent& operator=(const Nz::Vector3f& vel);
static ComponentIndex componentIndex;
};
}
#include <NazaraSDK/Components/VelocityComponent.inl>
#endif // NDK_COMPONENTS_VELOCITYCOMPONENT_HPP

View File

@@ -1,37 +0,0 @@
// 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 Prerequisites.hpp
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::VelocityComponent
* \brief NDK class that represents the component for velocity
*/
/*!
* \brief Constructs a VelocityComponent object with a velocity
*
* \param velocity Linear velocity
*/
inline VelocityComponent::VelocityComponent(const Nz::Vector3f& velocity, Nz::CoordSys coordSystem) :
linearVelocity(velocity),
coordSys(coordSystem)
{
}
/*!
* \brief Assigns the velocity to this component
* \return A reference to this
*
* \param vel Linear velocity
*/
inline VelocityComponent& VelocityComponent::operator=(const Nz::Vector3f& vel)
{
linearVelocity = vel;
return *this;
}
}

View File

@@ -1,88 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#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/Node.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <NazaraSDK/EntityOwner.hpp>
namespace Nz
{
struct WindowEvent;
}
namespace Ndk
{
class AbstractTextAreaWidget;
class Console;
class Entity;
class RichTextAreaWidget;
class ScrollAreaWidget;
class TextAreaWidget;
using ConsoleHandle = Nz::ObjectHandle<Console>;
class NDK_API Console : public BaseWidget, public Nz::HandledObject<Console>
{
public:
Console(BaseWidget* parent);
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();
void ClearFocus();
inline unsigned int GetCharacterSize() const;
inline const RichTextAreaWidget* GetHistory() const;
inline const TextAreaWidget* GetInput() const;
inline const Nz::FontRef& GetTextFont() const;
void SetCharacterSize(unsigned int size);
void SetFocus();
void SetTextFont(Nz::FontRef font);
Console& operator=(const Console& console) = delete;
Console& operator=(Console&& console) = default;
NazaraSignal(OnCommand, Console* /*console*/, const Nz::String& /*command*/);
private:
void ExecuteInput(const AbstractTextAreaWidget* textArea, bool* ignoreDefaultAction);
void Layout() override;
struct Line
{
Nz::Color color;
Nz::String text;
};
std::size_t m_historyPosition;
std::vector<Nz::String> m_commandHistory;
std::vector<Line> m_historyLines;
ScrollAreaWidget* m_historyArea;
RichTextAreaWidget* m_history;
TextAreaWidget* m_input;
Nz::FontRef m_defaultFont;
unsigned int m_characterSize;
unsigned int m_maxHistoryLines;
};
}
#include <NazaraSDK/Console.inl>
#endif // NDK_CONSOLE_HPP
#endif // NDK_SERVER

View File

@@ -1,46 +0,0 @@
// 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 Prerequisites.hpp
namespace Ndk
{
/*!
* \brief Gets the character size
* \return Height of the character
*/
inline unsigned int Console::GetCharacterSize() const
{
return m_characterSize;
}
/*!
* \brief Gets the entity representing the history of the console
* \return History of the console
*/
inline const RichTextAreaWidget* Console::GetHistory() const
{
return m_history;
}
/*!
* \brief Gets the entity representing the input of the console
* \return Input of the console
*/
inline const TextAreaWidget* Console::GetInput() const
{
return m_input;
}
/*!
* \brief Gets the font used by the console
* \return A reference to the font currenty used
*/
inline const Nz::FontRef& Console::GetTextFont() const
{
return m_defaultFont;
}
}

View File

@@ -1,114 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_ENTITY_HPP
#define NDK_ENTITY_HPP
#include <Nazara/Core/Bitset.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Core/Signal.hpp>
#include <NazaraSDK/Algorithm.hpp>
#include <NazaraSDK/Prerequisites.hpp>
#include <memory>
#include <vector>
namespace Ndk
{
class BaseComponent;
class BaseSystem;
class Entity;
class EntityList;
class World;
using EntityHandle = Nz::ObjectHandle<Entity>;
class NDK_API Entity : public Nz::HandledObject<Entity>
{
friend BaseSystem;
friend EntityList;
friend World;
public:
Entity(const Entity&) = delete;
Entity(Entity&& entity) noexcept;
~Entity();
BaseComponent& AddComponent(std::unique_ptr<BaseComponent>&& component);
template<typename ComponentType, typename... Args> ComponentType& AddComponent(Args&&... args);
const EntityHandle& Clone() const;
inline void Disable();
std::unique_ptr<BaseComponent> DropComponent(ComponentIndex index);
template<typename ComponentType> std::unique_ptr<BaseComponent> DropComponent();
void Enable(bool enable = true);
inline BaseComponent& GetComponent(ComponentIndex index);
template<typename ComponentType> ComponentType& GetComponent();
inline const BaseComponent& GetComponent(ComponentIndex index) const;
template<typename ComponentType> const ComponentType& GetComponent() const;
inline const Nz::Bitset<>& GetComponentBits() const;
inline EntityId GetId() const;
inline const Nz::Bitset<>& GetSystemBits() const;
inline World* GetWorld() const;
inline bool HasComponent(ComponentIndex index) const;
template<typename ComponentType> bool HasComponent() const;
void Kill();
void Invalidate();
inline bool IsEnabled() const;
bool IsDying() const;
inline bool IsValid() const;
inline void RemoveAllComponents();
inline void RemoveComponent(ComponentIndex index);
template<typename ComponentType> void RemoveComponent();
inline Nz::String ToString() const;
Entity& operator=(const Entity&) = delete;
Entity& operator=(Entity&&) = delete;
NazaraSignal(OnEntityDestruction, Entity* /*entity*/);
NazaraSignal(OnEntityDisabled, Entity* /*entity*/);
NazaraSignal(OnEntityEnabled, Entity* /*entity*/);
private:
Entity(World* world, EntityId id);
void Create();
void Destroy();
inline Nz::Bitset<>& GetRemovedComponentBits();
inline void RegisterEntityList(EntityList* list);
inline void RegisterSystem(SystemIndex index);
inline void SetWorld(World* world) noexcept;
inline void UnregisterEntityList(EntityList* list);
inline void UnregisterSystem(SystemIndex index);
std::vector<std::unique_ptr<BaseComponent>> m_components;
std::vector<EntityList*> m_containedInLists;
Nz::Bitset<> m_componentBits;
Nz::Bitset<> m_removedComponentBits;
Nz::Bitset<> m_systemBits;
Nz::MovablePtr<World> m_world;
EntityId m_id;
bool m_enabled;
bool m_valid;
};
}
#include <NazaraSDK/Entity.inl>
#endif // NDK_ENTITY_HPP

View File

@@ -1,331 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Entity.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <algorithm>
#include <cassert>
#include <type_traits>
namespace Ndk
{
/*!
* \brief Adds a component to the entity
* \return A reference to the newly added component
*
* \param args Arguments to create in place the component to add to the entity
*/
template<typename ComponentType, typename... Args>
ComponentType& Entity::AddComponent(Args&&... args)
{
static_assert(std::is_base_of<BaseComponent, ComponentType>::value, "ComponentType is not a component");
// Affectation and return of the component
std::unique_ptr<ComponentType> ptr(new ComponentType(std::forward<Args>(args)...));
return static_cast<ComponentType&>(AddComponent(std::move(ptr)));
}
/*!
* \brief Disables the entity
*
* This is just a shortcut to Enable(false)
*/
inline void Entity::Disable()
{
Enable(false);
}
/*!
* \brief Gets a component in the entity by index
* \return A reference to the component
*
* \param index Index of the component
*
* \remark Produces a NazaraAssert if component is not available in this entity or is invalid
*/
inline BaseComponent& Entity::GetComponent(ComponentIndex index)
{
NazaraAssert(HasComponent(index), "This component is not part of the entity");
BaseComponent* component = m_components[index].get();
NazaraAssert(component, "Invalid component pointer");
return *component;
}
/*!
* \brief Gets a component in the entity by type
* \return A reference to the component
*
* \remark Produces a NazaraAssert if component is not available in this entity
*/
template<typename ComponentType>
std::unique_ptr<BaseComponent> Entity::DropComponent()
{
static_assert(std::is_base_of<BaseComponent, ComponentType>::value, "ComponentType is not a component");
ComponentIndex index = GetComponentIndex<ComponentType>();
return DropComponent(index);
}
template<typename ComponentType>
ComponentType& Entity::GetComponent()
{
static_assert(std::is_base_of<BaseComponent, ComponentType>::value, "ComponentType is not a component");
ComponentIndex index = GetComponentIndex<ComponentType>();
return static_cast<ComponentType&>(GetComponent(index));
}
/*!
* \brief Gets a component in the entity by index
* \return A constant reference to the component
*
* \param index Index of the component
*
* \remark Produces a NazaraAssert if component is not available in this entity or is invalid
*/
inline const BaseComponent& Entity::GetComponent(ComponentIndex index) const
{
NazaraAssert(HasComponent(index), "This component is not part of the entity");
BaseComponent* component = m_components[index].get();
NazaraAssert(component, "Invalid component pointer");
return *component;
}
/*!
* \brief Gets a component in the entity by type
* \return A constant reference to the component
*
* \remark Produces a NazaraAssert if component is not available in this entity
*/
template<typename ComponentType>
const ComponentType& Entity::GetComponent() const
{
static_assert(std::is_base_of<BaseComponent, ComponentType>::value, "ComponentType is not a component");
ComponentIndex index = GetComponentIndex<ComponentType>();
return static_cast<ComponentType&>(GetComponent(index));
}
/*!
* \brief Gets the bits representing the components in the entiy
* \return A constant reference to the set of component's bits
*/
inline const Nz::Bitset<>& Entity::GetComponentBits() const
{
return m_componentBits;
}
/*!
* \brief Gets the identifier of the entity
* \return Identifier of the entity
*/
inline EntityId Entity::GetId() const
{
return m_id;
}
/*!
* \brief Gets the bits representing the systems in the entiy
* \return A constant reference to the set of system's bits
*/
inline const Nz::Bitset<>& Entity::GetSystemBits() const
{
return m_systemBits;
}
/*!
* \brief Gets the world in which the entity is
* \return Pointer to the world
*/
inline World* Entity::GetWorld() const
{
return m_world;
}
/*!
* \brief Checks whether or not a component is present in the entity by index
* \return true If it is the case
*
* \param index Index of the component
*/
inline bool Entity::HasComponent(ComponentIndex index) const
{
return m_componentBits.UnboundedTest(index);
}
/*!
* \brief Checks whether or not a component is present in the entity by type
* \return true If it is the case
*/
template<typename ComponentType>
bool Entity::HasComponent() const
{
static_assert(std::is_base_of<BaseComponent, ComponentType>::value, "ComponentType is not a component");
ComponentIndex index = GetComponentIndex<ComponentType>();
return HasComponent(index);
}
/*!
* \brief Checks whether or not the entity is enabled
* \return true If it is the case
*/
inline bool Entity::IsEnabled() const
{
return m_enabled;
}
/*!
* \brief Checks whether or not the entity is valid
* \return true If it is the case
*/
inline bool Entity::IsValid() const
{
return m_valid;
}
/*!
* \brief Removes every components
*/
inline void Entity::RemoveAllComponents()
{
m_removedComponentBits = m_componentBits;
Invalidate();
}
/*!
* \brief Removes a component in the entity by index
*
* \param index Index of the component
*/
inline void Entity::RemoveComponent(ComponentIndex index)
{
m_removedComponentBits.UnboundedSet(index);
Invalidate();
}
/*!
* \brief Removes a component in the entity by type
*/
template<typename ComponentType>
void Entity::RemoveComponent()
{
static_assert(std::is_base_of<BaseComponent, ComponentType>(), "ComponentType is not a component");
ComponentIndex index = GetComponentIndex<ComponentType>();
RemoveComponent(index);
}
/*!
* \brief Gives a string representation
* \return A string representation of the object: "Entity(GetId())"
*/
inline Nz::String Entity::ToString() const
{
Nz::StringStream ss;
return ss << "Entity(" << GetId() << ')';
}
/*!
* \brief Gets the bits representing the removed components in the entiy
* \return A constant reference to the set of remove component's bits
*/
inline Nz::Bitset<>& Entity::GetRemovedComponentBits()
{
return m_removedComponentBits;
}
inline void Entity::RegisterEntityList(EntityList* list)
{
m_containedInLists.push_back(list);
}
inline void Entity::RegisterSystem(SystemIndex index)
{
m_systemBits.UnboundedSet(index);
}
/*!
* \brief Sets the world of the entity
*
* \param world World in which the entity will be
*
* \remark Produces a NazaraAssert if world is invalid
*/
inline void Entity::SetWorld(World* world) noexcept
{
NazaraAssert(world, "An entity must be attached to a world at any time");
m_world = world;
}
/*!
* \brief Unregisters a system for the entity
*
* \param index Index of the system
*/
inline void Entity::UnregisterEntityList(EntityList* list)
{
auto it = std::find(m_containedInLists.begin(), m_containedInLists.end(), list);
assert(it != m_containedInLists.end());
// Swap and pop idiom
*it = m_containedInLists.back();
m_containedInLists.pop_back();
}
inline void Entity::UnregisterSystem(SystemIndex index)
{
m_systemBits.UnboundedReset(index);
}
}
namespace std
{
template<>
struct hash<Ndk::EntityHandle>
{
/*!
* \brief Specialisation of std to hash
* \return Result of the hash
*
* \param handle Entity to hash
*/
size_t operator()(const Ndk::EntityHandle& handle) const
{
// Hash the pointer will work until the entity is updated and moved
// so, we have to hash the ID of the entity (which is constant)
Ndk::EntityId id = (handle.IsValid()) ? handle->GetId() : std::numeric_limits<Ndk::EntityId>::max();
return hash<Ndk::EntityId>()(id);
}
};
}

View File

@@ -1,86 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_ENTITYLIST_HPP
#define NDK_ENTITYLIST_HPP
#include <Nazara/Core/Bitset.hpp>
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/Entity.hpp>
namespace Ndk
{
class NDK_API EntityList
{
friend Entity;
public:
class iterator;
friend iterator;
using size_type = std::size_t;
inline EntityList();
inline EntityList(const EntityList& entityList);
inline EntityList(EntityList&& entityList) noexcept;
inline ~EntityList();
inline void Clear();
inline bool Has(const Entity* entity) const;
inline bool Has(EntityId entity) const;
inline void Insert(Entity* entity);
inline void Remove(Entity* entity);
inline void Reserve(std::size_t entityCount);
// STL API
inline iterator begin() const;
inline bool empty() const;
inline iterator end() const;
inline size_type size() const;
inline EntityList& operator=(const EntityList& entityList);
inline EntityList& operator=(EntityList&& entityList) noexcept;
private:
inline std::size_t FindNext(std::size_t currentId) const;
inline World* GetWorld() const;
inline void NotifyEntityDestruction(const Entity* entity);
Nz::Bitset<Nz::UInt64> m_entityBits;
World* m_world;
};
class NDK_API EntityList::iterator : public std::iterator<std::forward_iterator_tag, const EntityHandle>
{
friend EntityList;
public:
inline iterator(const iterator& it);
const EntityHandle& operator*() const;
inline iterator& operator=(const iterator& it);
inline iterator& operator++();
inline iterator operator++(int);
friend inline bool operator==(const iterator& lhs, const iterator& rhs);
friend inline bool operator!=(const iterator& lhs, const iterator& rhs);
friend inline void swap(iterator& lhs, iterator& rhs);
private:
inline iterator(const EntityList* world, std::size_t nextId);
std::size_t m_nextEntityId;
const EntityList* m_list;
};
}
#include <NazaraSDK/EntityList.inl>
#endif // NDK_ENTITYLIST_HPP

View File

@@ -1,278 +0,0 @@
// 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 Prerequisites.hpp
#include <Nazara/Core/Error.hpp>
#include <algorithm>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::EntityList
* \brief NDK class that represents a set of entities to help performing batch operations
*/
/*!
* \brief Construct a new entity list
*/
inline EntityList::EntityList() :
m_world(nullptr)
{
}
/*!
* \brief Construct a new entity list by copying another one
*/
inline EntityList::EntityList(const EntityList& entityList) :
m_entityBits(entityList.m_entityBits),
m_world(entityList.m_world)
{
for (const Ndk::EntityHandle& entity : *this)
entity->RegisterEntityList(this);
}
/*!
* \brief Construct a new entity list by moving a list into this one
*/
inline EntityList::EntityList(EntityList&& entityList) noexcept :
m_entityBits(std::move(entityList.m_entityBits)),
m_world(entityList.m_world)
{
for (const Ndk::EntityHandle& entity : *this)
{
entity->UnregisterEntityList(&entityList);
entity->RegisterEntityList(this);
}
}
inline EntityList::~EntityList()
{
for (const Ndk::EntityHandle& entity : *this)
entity->UnregisterEntityList(this);
}
/*!
* \brief Clears the set from every entities
*
* \remark This resets the implicit world member, allowing you to insert entities from a different world than previously
*/
inline void EntityList::Clear()
{
for (const Ndk::EntityHandle& entity : *this)
entity->UnregisterEntityList(this);
m_entityBits.Clear();
m_world = nullptr;
}
/*!
* \brief Checks whether or not the EntityList contains the entity
* \return true If it is the case
*
* \param entity Pointer to the entity
*
* \remark If the Insert function was called since the EntityList construction (or last call to Clear), the entity passed by parameter must belong to the same world as the previously inserted entities.
*/
inline bool EntityList::Has(const Entity* entity) const
{
NazaraAssert(!m_world || !entity || entity->GetWorld() == m_world, "Incompatible world");
return entity && entity->IsValid() && Has(entity->GetId());
}
/*!
* \brief Checks whether or not the set contains the entity by id
* \return true If it is the case
*
* \param id Identifier of the entity
*/
inline bool EntityList::Has(EntityId entity) const
{
return m_entityBits.UnboundedTest(entity);
}
/*!
* \brief Inserts the entity into the set
*
* Marks an entity as present in this entity list, it must belongs to the same world as others entities contained in this list.
*
* \param entity Valid pointer to an entity
*
* \remark If entity is already contained, no action is performed
* \remark If any entity has been inserted since construction (or last Clear call), the entity must belong to the same world as the previously inserted entities
*/
inline void EntityList::Insert(Entity* entity)
{
NazaraAssert(entity, "Invalid entity");
if (!Has(entity))
{
entity->RegisterEntityList(this);
m_entityBits.UnboundedSet(entity->GetId(), true);
m_world = entity->GetWorld();
}
}
/*!
* \brief Removes the entity from the set
*
* \param entity Pointer to the entity
*
* \remark If entity is not contained, no action is performed
* \remark This function never resets the implicit world member, even if it empties the list. Use the Clear method if you want to reset it.
*
* \see Clear
*/
inline void EntityList::Remove(Entity* entity)
{
if (Has(entity))
{
m_entityBits.Reset(entity->GetId());
entity->UnregisterEntityList(this);
}
}
/*!
* \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
{
return EntityList::iterator(this, m_entityBits.FindFirst());
}
inline bool EntityList::empty() const
{
return !m_entityBits.TestAny();
}
inline EntityList::iterator EntityList::end() const
{
return EntityList::iterator(this, m_entityBits.npos);
}
inline EntityList::size_type EntityList::size() const
{
return m_entityBits.Count();
}
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;
for (const Ndk::EntityHandle& entity : *this)
entity->RegisterEntityList(this);
return *this;
}
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;
for (const Ndk::EntityHandle& entity : *this)
{
entity->UnregisterEntityList(&entityList);
entity->RegisterEntityList(this);
}
return *this;
}
inline std::size_t EntityList::FindNext(std::size_t currentId) const
{
return m_entityBits.FindNext(currentId);
}
inline World* EntityList::GetWorld() const
{
return m_world;
}
inline void EntityList::NotifyEntityDestruction(const Entity* entity)
{
assert(Has(entity));
m_entityBits.Reset(entity->GetId());
}
inline EntityList::iterator::iterator(const EntityList* list, std::size_t nextId) :
m_nextEntityId(nextId),
m_list(list)
{
}
inline EntityList::iterator::iterator(const iterator& it) :
m_nextEntityId(it.m_nextEntityId),
m_list(it.m_list)
{
}
inline EntityList::iterator& EntityList::iterator::operator=(const iterator& it)
{
m_nextEntityId = it.m_nextEntityId;
m_list = it.m_list;
return *this;
}
inline EntityList::iterator& EntityList::iterator::operator++()
{
m_nextEntityId = m_list->FindNext(m_nextEntityId);
return *this;
}
inline EntityList::iterator EntityList::iterator::operator++(int)
{
std::size_t previousId = m_nextEntityId;
m_nextEntityId = m_list->FindNext(m_nextEntityId);
return iterator(m_list, previousId);
}
inline bool operator==(const EntityList::iterator& lhs, const EntityList::iterator& rhs)
{
NazaraAssert(lhs.m_list == rhs.m_list, "Cannot compare iterator coming from different lists");
return lhs.m_nextEntityId == rhs.m_nextEntityId;
}
inline bool operator!=(const EntityList::iterator& lhs, const EntityList::iterator& rhs)
{
return !operator==(lhs, rhs);
}
inline void swap(EntityList::iterator& lhs, EntityList::iterator& rhs)
{
NazaraAssert(lhs.m_list == rhs.m_list, "Cannot compare iterator coming from different lists");
using std::swap;
swap(lhs.m_nextEntityId, rhs.m_nextEntityId);
}
}

View File

@@ -1,35 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_ENTITYOWNER_HPP
#define NDK_ENTITYOWNER_HPP
#include <NazaraSDK/Entity.hpp>
namespace Ndk
{
class EntityOwner : public EntityHandle
{
public:
EntityOwner() = default;
EntityOwner(Entity* entity);
EntityOwner(const EntityOwner& handle) = delete;
EntityOwner(EntityOwner&& handle) noexcept = default;
~EntityOwner();
void Release();
void Reset(Entity* entity = nullptr);
void Reset(EntityOwner&& handle);
EntityOwner& operator=(Entity* entity);
EntityOwner& operator=(const EntityOwner& handle) = delete;
EntityOwner& operator=(EntityOwner&& handle) noexcept;
};
}
#include <NazaraSDK/EntityOwner.inl>
#endif // NDK_ENTITYOWNER_HPP

View File

@@ -1,105 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/EntityOwner.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <functional>
#include <limits>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::EntityOwner
* \brief NDK class that represents the owner of the entity and so its lifetime
*/
/*!
* \brief Constructs a EntityOwner object
*
* \param entity Entity to own
*/
inline EntityOwner::EntityOwner(Entity* entity) :
EntityOwner()
{
Reset(entity);
}
/*!
* \brief Destructs the object and calls Reset
*
* \see Reset
*/
inline EntityOwner::~EntityOwner()
{
Reset(nullptr);
}
/*!
* \brief Release the ownership of the entity without killing it
*/
inline void EntityOwner::Release()
{
EntityHandle::Reset(nullptr);
}
/*!
* \brief Resets the ownership of the entity, previous is killed
*
* \param entity Entity to own
*/
inline void EntityOwner::Reset(Entity* entity)
{
if (IsValid())
GetObject()->Kill();
EntityHandle::Reset(entity);
}
/*!
* \brief Resets the ownership of the entity by move semantic
*
* \param handle EntityOwner to move into this
*/
inline void EntityOwner::Reset(EntityOwner&& handle)
{
Reset(handle.GetObject());
handle.Release();
}
/*!
* \brief Resets the ownership of the entity to the affected one
*
* \param entity Entity to own
*/
inline EntityOwner& EntityOwner::operator=(Entity* entity)
{
Reset(entity);
return *this;
}
/*!
* \brief Steals ownership of a EntityOwner
*
* \param handle Handle to the new entity to own, or an invalid handle
*/
inline EntityOwner& EntityOwner::operator=(EntityOwner&& handle) noexcept
{
Reset(); //< Kill previously owned entity, if any
EntityHandle::operator=(std::move(handle));
return *this;
}
}
namespace std
{
template<>
struct hash<Ndk::EntityOwner> : public hash<Ndk::EntityHandle>
{
};
}

View File

@@ -1,54 +0,0 @@
/*
Nazara Development Kit ("NDK"), also called Nazara Engine - SDK ("Software Development Kit")
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#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/Prerequisites.hpp>
// Importation/Exportation of the API
#if defined(NAZARA_STATIC)
#define NDK_API
#else
#ifdef NDK_BUILD
#define NDK_API NAZARA_EXPORT
#else
#define NDK_API NAZARA_IMPORT
#endif
#endif
namespace Ndk
{
using ComponentId = Nz::UInt64;
using ComponentIndex = Nz::UInt32;
using EntityId = Nz::UInt32;
using SystemIndex = Nz::UInt32;
}
#endif // NDK_PREREQUISITES_HPP

View File

@@ -1,31 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SDK_HPP
#define NDK_SDK_HPP
#include <NazaraSDK/Prerequisites.hpp>
namespace Ndk
{
class NDK_API Sdk
{
public:
Sdk() = delete;
~Sdk() = delete;
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static unsigned int s_referenceCounter;
};
}
#include <NazaraSDK/Sdk.inl>
#endif // NDK_SDK_HPP

View File

@@ -1,16 +0,0 @@
// 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 Prerequisites.hpp
namespace Ndk
{
/*!
* \brief Checks whether the module is initialized
* \return true if module is initialized
*/
inline bool Sdk::IsInitialized()
{
return s_referenceCounter != 0;
}
}

View File

@@ -1,28 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_STATE_HPP
#define NDK_STATE_HPP
#include <NazaraSDK/Prerequisites.hpp>
namespace Ndk
{
class StateMachine;
class NDK_API State
{
public:
State() = default;
virtual ~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

View File

@@ -1,61 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_STATEMACHINE_HPP
#define NDK_STATEMACHINE_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/State.hpp>
#include <memory>
#include <vector>
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 IsTopState(const State* state) const;
inline void PopState();
inline void PopStatesUntil(std::shared_ptr<State> state);
inline void PushState(std::shared_ptr<State> state);
inline void ResetState(std::shared_ptr<State> state);
inline bool Update(float elapsedTime);
inline StateMachine& operator=(StateMachine&& fsm) = default;
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;
};
}
#include <NazaraSDK/StateMachine.inl>
#endif // NDK_STATEMACHINE_HPP

View File

@@ -1,204 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/StateMachine.hpp>
#include <Nazara/Core/Error.hpp>
#include <utility>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::StateMachine
* \brief NDK class that represents a state machine, to represent the multiple states of your program as a stack
*/
/*!
* \brief Constructs a StateMachine object with an original state
*
* \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)
{
if (originalState)
PushState(std::move(originalState));
}
/*!
* \brief Destructs the object
*
* \remark Calls "Leave" on all the states from top to bottom
*/
inline StateMachine::~StateMachine()
{
// 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)
{
// 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 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())
return false;
return m_states.back().get() == state;
}
/*!
* \brief Pops the state on the top of the machine
*
* \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 void StateMachine::PopState()
{
StateTransition transition;
transition.type = TransitionType::Pop;
m_transitions.emplace_back(std::move(transition));
}
/*!
* \brief Pops all states of the machine until a specific one is reached
*
* \param state State to find on the stack. If nullptr is passed, no action is performed
*
* \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 void StateMachine::PopStatesUntil(std::shared_ptr<State> state)
{
if (state)
{
StateTransition transition;
transition.state = std::move(state);
transition.type = TransitionType::PopUntil;
m_transitions.emplace_back(std::move(transition));
}
}
/*!
* \brief Pushes a new state on the top of the machine
*
* \param state Next state to represent if it is nullptr, it performs no action
*
* \remark 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)
{
StateTransition transition;
transition.state = std::move(state);
transition.type = TransitionType::Push;
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 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::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)
{
transition.state = std::move(state);
transition.type = TransitionType::Push;
m_transitions.emplace_back(std::move(transition));
}
}
/*!
* \brief Updates all the states
* \return true If update is successful for everyone of them
*
* \param elapsedTime Delta time used for the update
*/
inline bool StateMachine::Update(float elapsedTime)
{
// Use a classic for instead of a range-for because some state may push/pop on enter/leave, adding new transitions as we iterate
// (range-for is a problem here because it doesn't handle mutable containers)
for (std::size_t i = 0; i < m_transitions.size(); ++i)
{
StateTransition& transition = m_transitions[i];
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,32 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SYSTEM_HPP
#define NDK_SYSTEM_HPP
#include <NazaraSDK/BaseSystem.hpp>
namespace Ndk
{
template<typename SystemType>
class System : public BaseSystem
{
public:
System();
System(const System&) = delete;
System(System&&) noexcept = default;
virtual ~System();
System& operator=(const System&) = delete;
System& operator=(System&&) noexcept = default;
static SystemIndex RegisterSystem();
};
}
#include <NazaraSDK/System.inl>
#endif // NDK_SYSTEM_HPP

View File

@@ -1,40 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Algorithm.hpp>
#include <type_traits>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::System<SystemType>
* \brief NDK class that represents a system which interacts on a world
*
* \remark This class is meant to be derived as CRTP: "System<Subtype>"
*/
/*!
* \brief Constructs a System object by default
*/
template<typename SystemType>
System<SystemType>::System() :
BaseSystem(GetSystemIndex<SystemType>())
{
}
template<typename SystemType>
System<SystemType>::~System() = default;
/*!
* \brief Registers the system by assigning it an index
*/
template<typename SystemType>
SystemIndex System<SystemType>::RegisterSystem()
{
return GetNextIndex();
}
}

View File

@@ -1,17 +0,0 @@
// This file was automatically generated
#pragma once
#ifndef NDK_SYSTEMS_GLOBAL_HPP
#define NDK_SYSTEMS_GLOBAL_HPP
#include <NazaraSDK/Systems/DebugSystem.hpp>
#include <NazaraSDK/Systems/LifetimeSystem.hpp>
#include <NazaraSDK/Systems/ListenerSystem.hpp>
#include <NazaraSDK/Systems/ParticleSystem.hpp>
#include <NazaraSDK/Systems/PhysicsSystem2D.hpp>
#include <NazaraSDK/Systems/PhysicsSystem3D.hpp>
#include <NazaraSDK/Systems/RenderSystem.hpp>
#include <NazaraSDK/Systems/VelocitySystem.hpp>
#endif // NDK_SYSTEMS_GLOBAL_HPP

View File

@@ -1,58 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_SYSTEMS_DEBUGSYSTEM_HPP
#define NDK_SYSTEMS_DEBUGSYSTEM_HPP
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <NazaraSDK/System.hpp>
namespace Ndk
{
class NDK_API DebugSystem : public System<DebugSystem>
{
public:
DebugSystem();
~DebugSystem() = default;
void EnableDepthBuffer(bool enable);
inline bool IsDepthBufferEnabled() const;
static SystemIndex systemIndex;
private:
Nz::InstancedRenderableRef GenerateBox(Nz::Boxf box);
Nz::InstancedRenderableRef GenerateCollision2DMesh(Entity* entity, Nz::Vector3f* offset);
Nz::InstancedRenderableRef GenerateCollision3DMesh(Entity* entity);
std::pair<Nz::IndexBufferRef, Nz::VertexBufferRef> GetBoxMesh();
Nz::MaterialRef GetCollisionMaterial();
Nz::MaterialRef GetGlobalAABBMaterial();
Nz::MaterialRef GetLocalAABBMaterial();
Nz::MaterialRef GetOBBMaterial();
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
Nz::MaterialRef m_globalAabbMaterial;
Nz::MaterialRef m_localAabbMaterial;
Nz::MaterialRef m_collisionMaterial;
Nz::MaterialRef m_obbMaterial;
Nz::IndexBufferRef m_boxMeshIndexBuffer;
Nz::VertexBufferRef m_boxMeshVertexBuffer;
bool m_isDepthBufferEnabled;
};
}
#include <NazaraSDK/Systems/DebugSystem.inl>
#endif // NDK_SYSTEMS_DEBUGSYSTEM_HPP
#endif // NDK_SERVER

View File

@@ -1,13 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Systems/DebugSystem.hpp>
namespace Ndk
{
inline bool DebugSystem::IsDepthBufferEnabled() const
{
return m_isDepthBufferEnabled;
}
}

View File

@@ -1,29 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SYSTEMS_LIFETIMESYSTEM_HPP
#define NDK_SYSTEMS_LIFETIMESYSTEM_HPP
#include <NazaraSDK/System.hpp>
namespace Ndk
{
class NDK_API LifetimeSystem : public System<LifetimeSystem>
{
public:
LifetimeSystem();
~LifetimeSystem() = default;
static SystemIndex systemIndex;
private:
void OnUpdate(float elapsedTime) override;
};
}
#include <NazaraSDK/Systems/LifetimeSystem.inl>
#endif // NDK_SYSTEMS_LIFETIMESYSTEM_HPP

View File

@@ -1,3 +0,0 @@
// 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 Prerequisites.hpp

View File

@@ -1,31 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_SYSTEMS_LISTENERSYSTEM_HPP
#define NDK_SYSTEMS_LISTENERSYSTEM_HPP
#include <NazaraSDK/System.hpp>
namespace Ndk
{
class NDK_API ListenerSystem : public System<ListenerSystem>
{
public:
ListenerSystem();
~ListenerSystem() = default;
static SystemIndex systemIndex;
private:
void OnUpdate(float elapsedTime) override;
};
}
#include <NazaraSDK/Systems/ListenerSystem.inl>
#endif // NDK_SYSTEMS_LISTENERSYSTEM_HPP
#endif // NDK_SERVER

View File

@@ -1,3 +0,0 @@
// 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 Prerequisites.hpp

View File

@@ -1,31 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_SYSTEMS_PARTICLESYSTEM_HPP
#define NDK_SYSTEMS_PARTICLESYSTEM_HPP
#include <NazaraSDK/System.hpp>
namespace Ndk
{
class NDK_API ParticleSystem : public System<ParticleSystem>
{
public:
ParticleSystem();
~ParticleSystem() = default;
static SystemIndex systemIndex;
private:
void OnUpdate(float elapsedTime) override;
};
}
#include <NazaraSDK/Systems/ParticleSystem.inl>
#endif // NDK_SYSTEMS_PARTICLESYSTEM_HPP
#endif // NDK_SERVER

View File

@@ -1,3 +0,0 @@
// 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 Prerequisites.hpp

View File

@@ -1,132 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SYSTEMS_PHYSICSSYSTEM2D_HPP
#define NDK_SYSTEMS_PHYSICSSYSTEM2D_HPP
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <NazaraSDK/EntityList.hpp>
#include <NazaraSDK/System.hpp>
#include <memory>
namespace Ndk
{
class NDK_API PhysicsSystem2D : public System<PhysicsSystem2D>
{
friend class CollisionComponent2D;
friend class PhysicsComponent2D;
using ContactEndCallback = std::function<void(PhysicsSystem2D& world, Nz::Arbiter2D& arbiter, const EntityHandle& bodyA, const EntityHandle& bodyB, void* userdata)>;
using ContactPreSolveCallback = std::function<bool(PhysicsSystem2D& world, Nz::Arbiter2D& arbiter, const EntityHandle& bodyA, const EntityHandle& bodyB, void* userdata)>;
using ContactPostSolveCallback = std::function<void(PhysicsSystem2D& world, Nz::Arbiter2D& arbiter, const EntityHandle& bodyA, const EntityHandle& bodyB, void* userdata)>;
using ContactStartCallback = std::function<bool(PhysicsSystem2D& world, Nz::Arbiter2D& arbiter, const EntityHandle& bodyA, const EntityHandle& bodyB, void* userdata)>;
using DebugDrawCircleCallback = std::function<void(const Nz::Vector2f& origin, const Nz::RadianAnglef& rotation, float radius, Nz::Color outlineColor, Nz::Color fillColor, void* userdata)>;
using DebugDrawDotCallback = std::function<void(const Nz::Vector2f& origin, float radius, Nz::Color color, void* userdata)>;
using DebugDrawPolygonCallback = std::function<void(const Nz::Vector2f* vertices, std::size_t vertexCount, float radius, Nz::Color outlineColor, Nz::Color fillColor, void* userdata)>;
using DebugDrawSegmentCallback = std::function<void(const Nz::Vector2f& first, const Nz::Vector2f& second, Nz::Color color, void* userdata)>;
using DebugDrawTickSegmentCallback = std::function<void(const Nz::Vector2f& first, const Nz::Vector2f& second, float thickness, Nz::Color outlineColor, Nz::Color fillColor, void* userdata)>;
using DebugDrawGetColorCallback = std::function<Nz::Color(const EntityHandle& body, std::size_t shapeIndex, void* userdata)>;
public:
struct Callback;
struct DebugDrawOptions;
struct NearestQueryResult;
struct RaycastHit;
PhysicsSystem2D();
~PhysicsSystem2D() = default;
void DebugDraw(const DebugDrawOptions& options, bool drawShapes = true, bool drawConstraints = true, bool drawCollisions = true);
inline float GetDamping() const;
inline Nz::Vector2f GetGravity() const;
inline std::size_t GetIterationCount() const;
inline std::size_t GetMaxStepCount() const;
inline float GetStepSize() const;
bool NearestBodyQuery(const Nz::Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, EntityHandle* nearestBody = nullptr);
bool NearestBodyQuery(const Nz::Vector2f& from, float maxDistance, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, NearestQueryResult* result);
void RaycastQuery(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, const std::function<void(const RaycastHit&)>& callback);
bool RaycastQuery(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<RaycastHit>* hitInfos);
bool RaycastQueryFirst(const Nz::Vector2f& from, const Nz::Vector2f& to, float radius, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, RaycastHit* hitInfo = nullptr);
void RegionQuery(const Nz::Rectf& boundingBox, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, const std::function<void(const EntityHandle&)>& callback);
void RegionQuery(const Nz::Rectf& boundingBox, Nz::UInt32 collisionGroup, Nz::UInt32 categoryMask, Nz::UInt32 collisionMask, std::vector<EntityHandle>* bodies);
void RegisterCallbacks(unsigned int collisionId, Callback callbacks);
void RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, Callback callbacks);
inline void SetDamping(float dampingValue);
inline void SetGravity(const Nz::Vector2f& gravity);
inline void SetIterationCount(std::size_t iterationCount);
inline void SetMaxStepCount(std::size_t maxStepCount);
inline void SetSleepTime(float sleepTime);
inline void SetStepSize(float stepSize);
inline void UseSpatialHash(float cellSize, std::size_t entityCount);
struct Callback
{
ContactEndCallback endCallback = nullptr;
ContactPreSolveCallback preSolveCallback = nullptr;
ContactPostSolveCallback postSolveCallback = nullptr;
ContactStartCallback startCallback = nullptr;
void* userdata;
};
struct DebugDrawOptions
{
Nz::Color constraintColor;
Nz::Color collisionPointColor;
Nz::Color shapeOutlineColor;
DebugDrawCircleCallback circleCallback;
DebugDrawGetColorCallback colorCallback;
DebugDrawDotCallback dotCallback;
DebugDrawPolygonCallback polygonCallback;
DebugDrawSegmentCallback segmentCallback;
DebugDrawTickSegmentCallback thickSegmentCallback;
void* userdata;
};
struct NearestQueryResult
{
EntityHandle nearestBody;
Nz::Vector2f closestPoint;
Nz::Vector2f fraction;
float distance;
};
struct RaycastHit
{
EntityHandle body;
Nz::Vector2f hitPos;
Nz::Vector2f hitNormal;
float fraction;
};
static SystemIndex systemIndex;
private:
void CreatePhysWorld() const;
const EntityHandle& GetEntityFromBody(const Nz::RigidBody2D& body) const;
inline Nz::PhysWorld2D& GetPhysWorld();
inline const Nz::PhysWorld2D& GetPhysWorld() const;
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
EntityList m_dynamicObjects;
EntityList m_staticObjects;
mutable std::unique_ptr<Nz::PhysWorld2D> m_physWorld; ///TODO: std::optional (Should I make a Nz::Optional class?)
};
}
#include <NazaraSDK/Systems/PhysicsSystem2D.inl>
#endif // NDK_SYSTEMS_PHYSICSSYSTEM2D_HPP

View File

@@ -1,94 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Systems/PhysicsSystem2D.hpp>
namespace Ndk
{
inline float PhysicsSystem2D::GetDamping() const
{
return GetPhysWorld().GetDamping();
}
inline Nz::Vector2f PhysicsSystem2D::GetGravity() const
{
return GetPhysWorld().GetGravity();
}
inline std::size_t PhysicsSystem2D::GetIterationCount() const
{
return GetPhysWorld().GetIterationCount();
}
inline std::size_t PhysicsSystem2D::GetMaxStepCount() const
{
return GetPhysWorld().GetMaxStepCount();
}
inline float PhysicsSystem2D::GetStepSize() const
{
return GetPhysWorld().GetStepSize();
}
inline void PhysicsSystem2D::SetDamping(float dampingValue)
{
GetPhysWorld().SetDamping(dampingValue);
}
inline void PhysicsSystem2D::SetGravity(const Nz::Vector2f& gravity)
{
GetPhysWorld().SetGravity(gravity);
}
inline void PhysicsSystem2D::SetIterationCount(std::size_t iterationCount)
{
GetPhysWorld().SetIterationCount(iterationCount);
}
inline void PhysicsSystem2D::SetMaxStepCount(std::size_t maxStepCount)
{
GetPhysWorld().SetMaxStepCount(maxStepCount);
}
inline void PhysicsSystem2D::SetSleepTime(float sleepTime)
{
GetPhysWorld().SetSleepTime(sleepTime);
}
inline void PhysicsSystem2D::SetStepSize(float stepSize)
{
GetPhysWorld().SetStepSize(stepSize);
}
inline void PhysicsSystem2D::UseSpatialHash(float cellSize, std::size_t entityCount)
{
GetPhysWorld().UseSpatialHash(cellSize, entityCount);
}
/*!
* \brief Gets the physical world
* \return A reference to the physical world
*/
inline Nz::PhysWorld2D& PhysicsSystem2D::GetPhysWorld()
{
if (!m_physWorld)
CreatePhysWorld();
return *m_physWorld;
}
/*!
* \brief Gets the physical world
* \return A constant reference to the physical world
*/
inline const Nz::PhysWorld2D& PhysicsSystem2D::GetPhysWorld() const
{
if (!m_physWorld)
CreatePhysWorld();
return *m_physWorld;
}
}

View File

@@ -1,41 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SYSTEMS_PHYSICSSYSTEM3D_HPP
#define NDK_SYSTEMS_PHYSICSSYSTEM3D_HPP
#include <Nazara/Physics3D/PhysWorld3D.hpp>
#include <NazaraSDK/EntityList.hpp>
#include <NazaraSDK/System.hpp>
#include <memory>
namespace Ndk
{
class NDK_API PhysicsSystem3D : public System<PhysicsSystem3D>
{
public:
PhysicsSystem3D();
~PhysicsSystem3D() = default;
Nz::PhysWorld3D& GetWorld();
const Nz::PhysWorld3D& GetWorld() const;
static SystemIndex systemIndex;
private:
void CreatePhysWorld() const;
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
EntityList m_dynamicObjects;
EntityList m_staticObjects;
mutable std::unique_ptr<Nz::PhysWorld3D> m_world; ///TODO: std::optional (Should I make a Nz::Optional class?)
};
}
#include <NazaraSDK/Systems/PhysicsSystem3D.inl>
#endif // NDK_SYSTEMS_PHYSICSSYSTEM3D_HPP

View File

@@ -1,32 +0,0 @@
// 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 Prerequisites.hpp
namespace Ndk
{
/*!
* \brief Gets the physical world
* \return A reference to the physical world
*/
inline Nz::PhysWorld3D& PhysicsSystem3D::GetWorld()
{
if (!m_world)
CreatePhysWorld();
return *m_world;
}
/*!
* \brief Gets the physical world
* \return A constant reference to the physical world
*/
inline const Nz::PhysWorld3D& PhysicsSystem3D::GetWorld() const
{
if (!m_world)
CreatePhysWorld();
return *m_world;
}
}

View File

@@ -1,85 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_SYSTEMS_RENDERSYSTEM_HPP
#define NDK_SYSTEMS_RENDERSYSTEM_HPP
#include <Nazara/Graphics/AbstractBackground.hpp>
#include <Nazara/Graphics/CullingList.hpp>
#include <Nazara/Graphics/DepthRenderTechnique.hpp>
#include <Nazara/Renderer/RenderTexture.hpp>
#include <NazaraSDK/EntityList.hpp>
#include <NazaraSDK/System.hpp>
#include <NazaraSDK/Components/GraphicsComponent.hpp>
#include <vector>
namespace Ndk
{
class AbstractViewer;
class NDK_API RenderSystem : public System<RenderSystem>
{
public:
RenderSystem();
~RenderSystem() = default;
template<typename T> T& ChangeRenderTechnique();
inline Nz::AbstractRenderTechnique& ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique);
inline void EnableCulling(bool enable);
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 bool IsCullingEnabled() const;
inline void SetDefaultBackground(Nz::BackgroundRef background);
inline void SetGlobalForward(const Nz::Vector3f& direction);
inline void SetGlobalRight(const Nz::Vector3f& direction);
inline void SetGlobalUp(const Nz::Vector3f& direction);
static SystemIndex systemIndex;
private:
inline void InvalidateCoordinateSystem();
void OnEntityRemoved(Entity* entity) override;
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
void UpdateDynamicReflections();
void UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer);
void UpdatePointSpotShadowMaps();
std::unique_ptr<Nz::AbstractRenderTechnique> m_renderTechnique;
std::vector<GraphicsComponentCullingList::VolumeEntry> m_volumeEntries;
std::vector<EntityHandle> m_cameras;
EntityList m_drawables;
EntityList m_directionalLights;
EntityList m_lights;
EntityList m_pointSpotLights;
EntityList m_particleGroups;
EntityList m_realtimeReflected;
GraphicsComponentCullingList m_drawableCulling;
Nz::BackgroundRef m_background;
Nz::DepthRenderTechnique m_shadowTechnique;
Nz::Matrix4f m_coordinateSystemMatrix;
Nz::RenderTexture m_shadowRT;
bool m_coordinateSystemInvalidated;
bool m_forceRenderQueueInvalidation;
bool m_isCullingEnabled;
};
}
#include <NazaraSDK/Systems/RenderSystem.inl>
#endif // NDK_SYSTEMS_RENDERSYSTEM_HPP
#endif // NDK_SERVER

View File

@@ -1,186 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Systems/RenderSystem.hpp>
namespace Ndk
{
/*!
* \brief Changes the render technique used for the system
* \return A reference to the render technique type
*/
template<typename T>
inline T& RenderSystem::ChangeRenderTechnique()
{
static_assert(std::is_base_of<Nz::AbstractRenderTechnique, T>::value, "RenderTechnique is not a subtype of AbstractRenderTechnique");
return static_cast<T&>(ChangeRenderTechnique(std::make_unique<T>()));
}
/*!
* \brief Changes the render technique used for the system
* \return A reference to the abstract render technique
*
* \param renderTechnique Render technique to use
*/
inline Nz::AbstractRenderTechnique& RenderSystem::ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& renderTechnique)
{
m_renderTechnique = std::move(renderTechnique);
return *m_renderTechnique;
}
/*!
* \brief Enables/disables object culling
*
* Object culling is an algorithm used by the render system to detect invisible objects (which will not appear on screen) before they are rendered.
* This includes Frustum Culling and potentially Occlusion Culling.
*
* Disabling this is not recommended, as the system will draw every object in the world which could induce a performance loss.
*
* \param enable Whether to enable or disable culling
*
* \see IsCullingEnabled
*/
inline void RenderSystem::EnableCulling(bool enable)
{
m_isCullingEnabled = enable;
}
/*!
* \brief Gets the background used for rendering
* \return A reference to the background
*/
inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const
{
return m_background;
}
/*!
* \brief Gets the coordinates matrix used for rendering
* \return A constant reference to the matrix of coordinates
*/
inline const Nz::Matrix4f& RenderSystem::GetCoordinateSystemMatrix() const
{
return m_coordinateSystemMatrix;
}
/*!
* \brief Gets the "forward" global direction
* \return The forward direction, by default, it's -UnitZ() (Right hand coordinates)
*/
inline Nz::Vector3f RenderSystem::GetGlobalForward() const
{
return Nz::Vector3f(-m_coordinateSystemMatrix.m13, -m_coordinateSystemMatrix.m23, -m_coordinateSystemMatrix.m33);
}
/*!
* \brief Gets the "right" global direction
* \return The right direction, by default, it's UnitX() (Right hand coordinates)
*/
inline Nz::Vector3f RenderSystem::GetGlobalRight() const
{
return Nz::Vector3f(m_coordinateSystemMatrix.m11, m_coordinateSystemMatrix.m21, m_coordinateSystemMatrix.m31);
}
/*!
* \brief Gets the "up" global direction
* \return The up direction, by default, it's UnitY() (Right hand coordinates)
*/
inline Nz::Vector3f RenderSystem::GetGlobalUp() const
{
return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32);
}
/*!
* \brief Gets the render technique used for rendering
* \return A reference to the abstract render technique being used
*/
inline Nz::AbstractRenderTechnique& RenderSystem::GetRenderTechnique() const
{
return *m_renderTechnique.get();
}
/*!
* \brief Query if culling is enabled (enabled by default)
* \return True if culling is enabled, false otherwise
*
* \see EnableCulling
*/
inline bool RenderSystem::IsCullingEnabled() const
{
return m_isCullingEnabled;
}
/*!
* \brief Sets the background used for rendering
*
* \param background A reference to the background
*/
inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background)
{
m_background = std::move(background);
}
/*!
* \brief Sets the "forward" global direction
*
* \param direction The new forward direction
*/
inline void RenderSystem::SetGlobalForward(const Nz::Vector3f& direction)
{
m_coordinateSystemMatrix.m13 = -direction.x;
m_coordinateSystemMatrix.m23 = -direction.y;
m_coordinateSystemMatrix.m33 = -direction.z;
InvalidateCoordinateSystem();
}
/*!
* \brief Sets the "right" global direction
*
* \param direction The new right direction
*/
inline void RenderSystem::SetGlobalRight(const Nz::Vector3f& direction)
{
m_coordinateSystemMatrix.m11 = direction.x;
m_coordinateSystemMatrix.m21 = direction.y;
m_coordinateSystemMatrix.m31 = direction.z;
InvalidateCoordinateSystem();
}
/*!
* \brief Sets the "up" global direction
*
* \param direction The new up direction
*/
inline void RenderSystem::SetGlobalUp(const Nz::Vector3f& direction)
{
m_coordinateSystemMatrix.m12 = direction.x;
m_coordinateSystemMatrix.m22 = direction.y;
m_coordinateSystemMatrix.m32 = direction.z;
InvalidateCoordinateSystem();
}
/*!
* \brief Invalidates the matrix of coordinates for the system
*/
inline void RenderSystem::InvalidateCoordinateSystem()
{
m_coordinateSystemInvalidated = true;
}
}

View File

@@ -1,29 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_SYSTEMS_VELOCITYSYSTEM_HPP
#define NDK_SYSTEMS_VELOCITYSYSTEM_HPP
#include <NazaraSDK/System.hpp>
namespace Ndk
{
class NDK_API VelocitySystem : public System<VelocitySystem>
{
public:
VelocitySystem();
~VelocitySystem() = default;
static SystemIndex systemIndex;
private:
void OnUpdate(float elapsedTime) override;
};
}
#include <NazaraSDK/Systems/VelocitySystem.inl>
#endif // NDK_SYSTEMS_VELOCITYSYSTEM_HPP

View File

@@ -1,3 +0,0 @@
// 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 Prerequisites.hpp

View File

@@ -1,20 +0,0 @@
// This file was automatically generated
#pragma once
#ifndef NDK_WIDGETS_GLOBAL_HPP
#define NDK_WIDGETS_GLOBAL_HPP
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.hpp>
#include <NazaraSDK/Widgets/BoxLayout.hpp>
#include <NazaraSDK/Widgets/ButtonWidget.hpp>
#include <NazaraSDK/Widgets/CheckboxWidget.hpp>
#include <NazaraSDK/Widgets/Enums.hpp>
#include <NazaraSDK/Widgets/ImageWidget.hpp>
#include <NazaraSDK/Widgets/LabelWidget.hpp>
#include <NazaraSDK/Widgets/ProgressBarWidget.hpp>
#include <NazaraSDK/Widgets/RichTextAreaWidget.hpp>
#include <NazaraSDK/Widgets/ScrollAreaWidget.hpp>
#include <NazaraSDK/Widgets/TextAreaWidget.hpp>
#endif // NDK_WIDGETS_GLOBAL_HPP

View File

@@ -1,135 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_ABSTRACTTEXTAREAWIDGET_HPP
#define NDK_WIDGETS_ABSTRACTTEXTAREAWIDGET_HPP
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <NazaraSDK/Widgets/Enums.hpp>
#include <functional>
#include <vector>
namespace Ndk
{
class NDK_API AbstractTextAreaWidget : public BaseWidget
{
public:
using CharacterFilter = std::function<bool(char32_t)>;
AbstractTextAreaWidget(BaseWidget* parent);
AbstractTextAreaWidget(const AbstractTextAreaWidget&) = delete;
AbstractTextAreaWidget(AbstractTextAreaWidget&&) = default;
~AbstractTextAreaWidget() = default;
virtual void Clear();
//virtual TextAreaWidget* Clone() const = 0;
void EnableLineWrap(bool enable = true);
inline void EnableMultiline(bool enable = true);
inline void EnableTabWriting(bool enable = true);
inline void Erase(std::size_t glyphPosition);
virtual void Erase(std::size_t firstGlyph, std::size_t lastGlyph) = 0;
inline void EraseSelection();
inline const CharacterFilter& GetCharacterFilter() const;
inline const Nz::Vector2ui& GetCursorPosition() const;
inline Nz::Vector2ui GetCursorPosition(std::size_t glyphIndex) const;
inline EchoMode GetEchoMode() const;
inline std::size_t GetGlyphIndex() const;
inline std::size_t GetGlyphIndex(const Nz::Vector2ui& cursorPosition) const;
inline const Nz::String& GetText() const;
Nz::Vector2ui GetHoveredGlyph(float x, float y) const;
inline bool HasSelection() const;
inline bool IsLineWrapEnabled() const;
inline bool IsMultilineEnabled() const;
inline bool IsReadOnly() const;
inline bool IsTabWritingEnabled() const;
inline void MoveCursor(int offset);
inline void MoveCursor(const Nz::Vector2i& offset);
inline Nz::Vector2ui NormalizeCursorPosition(Nz::Vector2ui cursorPosition) const;
inline void SetCharacterFilter(CharacterFilter filter);
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 SetSelection(Nz::Vector2ui fromPosition, Nz::Vector2ui toPosition);
inline void Write(const Nz::String& text);
inline void Write(const Nz::String& text, const Nz::Vector2ui& glyphPosition);
virtual void Write(const Nz::String& text, std::size_t glyphPosition) = 0;
AbstractTextAreaWidget& operator=(const AbstractTextAreaWidget&) = delete;
AbstractTextAreaWidget& operator=(AbstractTextAreaWidget&&) = default;
NazaraSignal(OnTextAreaCursorMove, const AbstractTextAreaWidget* /*textArea*/, Nz::Vector2ui* /*newCursorPosition*/);
NazaraSignal(OnTextAreaKeyBackspace, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyDown, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyEnd, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyHome, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyLeft, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyReturn, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyRight, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaKeyUp, const AbstractTextAreaWidget* /*textArea*/, bool* /*ignoreDefaultAction*/);
NazaraSignal(OnTextAreaSelection, const AbstractTextAreaWidget* /*textArea*/, Nz::Vector2ui* /*start*/, Nz::Vector2ui* /*end*/);
protected:
virtual Nz::AbstractTextDrawer& GetTextDrawer() = 0;
virtual const Nz::AbstractTextDrawer& GetTextDrawer() const = 0;
void Layout() override;
virtual void HandleIndentation(bool add) = 0;
virtual void HandleSelectionIndentation(bool add) = 0;
virtual void HandleWordCursorMove(bool left) = 0;
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 OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button) override;
void OnMouseButtonRelease(int /*x*/, int /*y*/, Nz::Mouse::Button button) override;
void OnMouseEnter() override;
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
void OnTextEntered(char32_t character, bool repeated) override;
inline void SetCursorPositionInternal(std::size_t glyphIndex);
inline void SetCursorPositionInternal(Nz::Vector2ui cursorPosition);
void RefreshCursor();
virtual void UpdateDisplayText() = 0;
void UpdateTextSprite();
CharacterFilter m_characterFilter;
EchoMode m_echoMode;
EntityHandle m_cursorEntity;
EntityHandle m_textEntity;
Nz::TextSpriteRef m_textSprite;
Nz::Vector2ui m_cursorPositionBegin;
Nz::Vector2ui m_cursorPositionEnd;
Nz::Vector2ui m_selectionCursor;
std::vector<Nz::SpriteRef> m_cursorSprites;
bool m_isLineWrapEnabled;
bool m_isMouseButtonDown;
bool m_multiLineEnabled;
bool m_readOnly;
bool m_tabEnabled; // writes (Shift+)Tab character if set to true
};
}
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.inl>
#endif // NDK_WIDGETS_ABSTRACTTEXTAREAWIDGET_HPP

View File

@@ -1,252 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.hpp>
namespace Ndk
{
inline void AbstractTextAreaWidget::EnableMultiline(bool enable)
{
m_multiLineEnabled = enable;
}
inline void AbstractTextAreaWidget::EnableTabWriting(bool enable)
{
m_tabEnabled = enable;
}
inline void AbstractTextAreaWidget::Erase(std::size_t glyphPosition)
{
Erase(glyphPosition, glyphPosition + 1U);
}
inline void AbstractTextAreaWidget::EraseSelection()
{
if (!HasSelection())
return;
Erase(GetGlyphIndex(m_cursorPositionBegin), GetGlyphIndex(m_cursorPositionEnd));
}
inline const AbstractTextAreaWidget::CharacterFilter& AbstractTextAreaWidget::GetCharacterFilter() const
{
return m_characterFilter;
}
inline const Nz::Vector2ui& AbstractTextAreaWidget::GetCursorPosition() const
{
return m_cursorPositionBegin;
}
Nz::Vector2ui AbstractTextAreaWidget::GetCursorPosition(std::size_t glyphIndex) const
{
const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer();
glyphIndex = std::min(glyphIndex, GetTextDrawer().GetGlyphCount());
std::size_t lineCount = textDrawer.GetLineCount();
std::size_t line = 0U;
for (std::size_t i = line + 1; i < lineCount; ++i)
{
if (textDrawer.GetLine(i).glyphIndex > glyphIndex)
break;
line = i;
}
const auto& lineInfo = textDrawer.GetLine(line);
Nz::Vector2ui cursorPos;
cursorPos.y = static_cast<unsigned int>(line);
cursorPos.x = static_cast<unsigned int>(glyphIndex - lineInfo.glyphIndex);
return cursorPos;
}
inline EchoMode AbstractTextAreaWidget::GetEchoMode() const
{
return m_echoMode;
}
inline std::size_t AbstractTextAreaWidget::GetGlyphIndex() const
{
return GetGlyphIndex(m_cursorPositionBegin);
}
inline std::size_t AbstractTextAreaWidget::GetGlyphIndex(const Nz::Vector2ui& cursorPosition) const
{
const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer();
std::size_t glyphIndex = textDrawer.GetLine(cursorPosition.y).glyphIndex + cursorPosition.x;
if (textDrawer.GetLineCount() > cursorPosition.y + 1)
glyphIndex = std::min(glyphIndex, textDrawer.GetLine(cursorPosition.y + 1).glyphIndex - 1);
else
glyphIndex = std::min(glyphIndex, textDrawer.GetGlyphCount());
return glyphIndex;
}
inline bool AbstractTextAreaWidget::HasSelection() const
{
return m_cursorPositionBegin != m_cursorPositionEnd;
}
inline bool AbstractTextAreaWidget::IsLineWrapEnabled() const
{
return m_isLineWrapEnabled;
}
inline bool AbstractTextAreaWidget::IsMultilineEnabled() const
{
return m_multiLineEnabled;
}
inline bool AbstractTextAreaWidget::IsTabWritingEnabled() const
{
return m_tabEnabled;
}
inline bool AbstractTextAreaWidget::IsReadOnly() const
{
return m_readOnly;
}
inline void AbstractTextAreaWidget::MoveCursor(int offset)
{
std::size_t cursorGlyph = GetGlyphIndex(m_cursorPositionBegin);
if (offset >= 0)
SetCursorPosition(cursorGlyph + static_cast<std::size_t>(offset));
else
{
std::size_t nOffset = static_cast<std::size_t>(-offset);
if (nOffset >= cursorGlyph)
SetCursorPosition(0);
else
SetCursorPosition(cursorGlyph - nOffset);
}
}
inline void AbstractTextAreaWidget::MoveCursor(const Nz::Vector2i& offset)
{
auto ClampOffset = [] (unsigned int cursorPosition, int cursorOffset) -> unsigned int
{
if (cursorOffset >= 0)
return cursorPosition + cursorOffset;
else
{
unsigned int nOffset = static_cast<unsigned int>(-cursorOffset);
if (nOffset >= cursorPosition)
return 0;
else
return cursorPosition - nOffset;
}
};
Nz::Vector2ui cursorPosition = m_cursorPositionBegin;
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 Nz::Vector2ui AbstractTextAreaWidget::NormalizeCursorPosition(Nz::Vector2ui cursorPosition) const
{
const Nz::AbstractTextDrawer& textDrawer = GetTextDrawer();
std::size_t lineCount = textDrawer.GetLineCount();
if (cursorPosition.y >= lineCount)
cursorPosition.y = static_cast<unsigned int>(lineCount - 1);
const auto& lineInfo = textDrawer.GetLine(cursorPosition.y);
if (cursorPosition.y + 1 < lineCount)
{
const auto& nextLineInfo = textDrawer.GetLine(cursorPosition.y + 1);
cursorPosition.x = std::min(cursorPosition.x, static_cast<unsigned int>(nextLineInfo.glyphIndex - lineInfo.glyphIndex - 1));
}
return cursorPosition;
}
inline void AbstractTextAreaWidget::SetCharacterFilter(CharacterFilter filter)
{
m_characterFilter = std::move(filter);
}
inline void AbstractTextAreaWidget::SetCursorPosition(std::size_t glyphIndex)
{
Nz::Vector2ui position = GetCursorPosition(glyphIndex);
Nz::Vector2ui newPosition = position;
OnTextAreaCursorMove(this, &newPosition);
if (position == newPosition)
SetCursorPositionInternal(position);
else
SetCursorPositionInternal(GetGlyphIndex(newPosition));
}
inline void AbstractTextAreaWidget::SetCursorPosition(Nz::Vector2ui cursorPosition)
{
OnTextAreaCursorMove(this, &cursorPosition);
return SetCursorPositionInternal(NormalizeCursorPosition(cursorPosition));
}
inline void AbstractTextAreaWidget::SetEchoMode(EchoMode echoMode)
{
m_echoMode = echoMode;
UpdateDisplayText();
}
inline void AbstractTextAreaWidget::SetReadOnly(bool readOnly)
{
m_readOnly = readOnly;
m_cursorEntity->Enable(!m_readOnly && HasFocus());
}
inline void AbstractTextAreaWidget::SetSelection(Nz::Vector2ui fromPosition, Nz::Vector2ui toPosition)
{
// Ensure begin is before end
if (toPosition.y < fromPosition.y || (toPosition.y == fromPosition.y && toPosition.x < fromPosition.x))
std::swap(fromPosition, toPosition);
if (m_cursorPositionBegin != fromPosition || m_cursorPositionEnd != toPosition)
{
OnTextAreaSelection(this, &fromPosition, &toPosition);
// Ensure begin is before end a second time (in case signal changed it)
if (toPosition.y < fromPosition.y || (toPosition.y == fromPosition.y && toPosition.x < fromPosition.x))
std::swap(fromPosition, toPosition);
m_cursorPositionBegin = NormalizeCursorPosition(fromPosition);
m_cursorPositionEnd = NormalizeCursorPosition(toPosition);
RefreshCursor();
}
}
inline void AbstractTextAreaWidget::Write(const Nz::String& text)
{
Write(text, GetGlyphIndex(m_cursorPositionBegin));
}
inline void AbstractTextAreaWidget::Write(const Nz::String& text, const Nz::Vector2ui& glyphPosition)
{
Write(text, GetGlyphIndex(glyphPosition));
}
void AbstractTextAreaWidget::SetCursorPositionInternal(std::size_t glyphIndex)
{
return SetCursorPositionInternal(GetCursorPosition(glyphIndex));
}
inline void AbstractTextAreaWidget::SetCursorPositionInternal(Nz::Vector2ui cursorPosition)
{
m_cursorPositionBegin = cursorPosition;
m_cursorPositionEnd = m_cursorPositionBegin;
RefreshCursor();
}
}

View File

@@ -1,48 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_BOXLAYOUT_HPP
#define NDK_WIDGETS_BOXLAYOUT_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <NazaraSDK/Widgets/Enums.hpp>
#include <vector>
namespace Ndk
{
class NDK_API BoxLayout : public BaseWidget
{
public:
inline BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation);
BoxLayout(const BoxLayout&) = delete;
BoxLayout(BoxLayout&&) = default;
~BoxLayout() = default;
void Layout() override;
BoxLayout& operator=(const BoxLayout&) = delete;
BoxLayout& operator=(BoxLayout&&) = default;
private:
struct ChildInfo
{
BaseWidget* widget;
bool isConstrained;
float maximumSize;
float minimumSize;
float size;
};
std::vector<ChildInfo> m_childInfos;
BoxLayoutOrientation m_orientation;
float m_spacing;
};
}
#include <NazaraSDK/Widgets/BoxLayout.inl>
#endif // NDK_WIDGETS_BOXLAYOUT_HPP

View File

@@ -1,15 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Widgets/BoxLayout.hpp>
namespace Ndk
{
BoxLayout::BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation) :
BaseWidget(parent),
m_orientation(orientation),
m_spacing(5.f)
{
}
}

View File

@@ -1,99 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_BUTTONWIDGET_HPP
#define NDK_WIDGETS_BUTTONWIDGET_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
namespace Nz
{
class AbstractTextDrawer;
}
namespace Ndk
{
class NDK_API ButtonWidget : public BaseWidget
{
public:
ButtonWidget(BaseWidget* parent);
ButtonWidget(const ButtonWidget&) = delete;
ButtonWidget(ButtonWidget&&) = default;
~ButtonWidget() = default;
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;
EntityHandle m_textEntity;
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;
};
}
#include <NazaraSDK/Widgets/ButtonWidget.inl>
#endif // NDK_WIDGETS_BUTTONWIDGET_HPP

View File

@@ -1,102 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/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);
Nz::Vector2f textSize = Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths());
SetMinimumSize(textSize);
SetPreferredSize(textSize + Nz::Vector2f(20.f, 10.f));
Layout();
}
}

View File

@@ -1,105 +0,0 @@
// 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_CHECKBOXWIDGET_HPP
#define NDK_WIDGETS_CHECKBOXWIDGET_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <NazaraSDK/Components/NodeComponent.hpp>
#include <NazaraSDK/Widgets/Enums.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Math/Vector2.hpp>
namespace Nz
{
class AbstractTextDrawer;
}
namespace Ndk
{
class NDK_API CheckboxWidget : public BaseWidget
{
friend class Sdk;
public:
CheckboxWidget(BaseWidget* parent);
CheckboxWidget(const CheckboxWidget&) = delete;
CheckboxWidget(CheckboxWidget&&) = default;
~CheckboxWidget() = default;
//virtual CheckboxWidget* Clone() const = 0;
inline void EnableAdaptativeMargin(bool enable = true);
inline void EnableCheckbox(bool enable = true);
inline void EnableTristate(bool enable = true);
inline bool IsCheckboxEnabled() const;
inline bool IsMarginAdaptative() const;
inline bool IsTristateEnabled() const;
inline const Nz::Vector2f& GetCheckboxSize() const;
inline Nz::Vector2f GetCheckboxBorderSize() const;
inline CheckboxState GetState() const;
inline float GetTextMargin() const;
inline void SetCheckboxSize(const Nz::Vector2f& size);
CheckboxState SwitchToNextState();
void SetState(CheckboxState state);
inline void SetTextMargin(float margin);
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
CheckboxWidget& operator=(const CheckboxWidget&) = delete;
CheckboxWidget& operator=(CheckboxWidget&&) = default;
NazaraSignal(OnStateChanged, const CheckboxWidget* /*checkbox*/);
private:
static bool Initialize();
static void Uninitialize();
void Layout() override;
void UpdateCheckbox();
void UpdateSize();
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
inline bool ContainsCheckbox(int x, int y) const;
EntityHandle m_checkboxBorderEntity;
EntityHandle m_checkboxBackgroundEntity;
EntityHandle m_checkboxContentEntity;
EntityHandle m_textEntity;
Nz::TextureRef m_checkMark;
Nz::SpriteRef m_checkboxContentSprite;
Nz::SpriteRef m_checkboxBorderSprite;
Nz::SpriteRef m_checkboxBackgroundSprite;
Nz::TextSpriteRef m_textSprite;
static Nz::Color s_backgroundColor;
static Nz::Color s_disabledBackgroundColor;
static Nz::Color s_disabledBorderColor;
static Nz::Color s_borderColor;
bool m_adaptativeMargin;
bool m_checkboxEnabled;
bool m_tristateEnabled;
static float s_borderScale;
float m_textMargin;
CheckboxState m_state;
};
}
#include <NazaraSDK/Widgets/CheckboxWidget.inl>
#endif // NDK_WIDGETS_CHECKBOXWIDGET_HPP

View File

@@ -1,94 +0,0 @@
// 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
namespace Ndk
{
inline void CheckboxWidget::EnableAdaptativeMargin(bool enable)
{
m_adaptativeMargin = enable;
Layout();
}
inline void CheckboxWidget::EnableCheckbox(bool enable)
{
m_checkboxEnabled = enable;
UpdateCheckbox();
}
inline void CheckboxWidget::EnableTristate(bool enable)
{
m_tristateEnabled = enable;
if (m_tristateEnabled && GetState() == CheckboxState_Tristate)
SetState(CheckboxState_Unchecked);
}
inline bool CheckboxWidget::IsCheckboxEnabled() const
{
return m_checkboxEnabled;
}
inline bool CheckboxWidget::IsMarginAdaptative() const
{
return m_adaptativeMargin;
}
inline bool CheckboxWidget::IsTristateEnabled() const
{
return m_tristateEnabled;
}
inline const Nz::Vector2f& CheckboxWidget::GetCheckboxSize() const
{
return m_checkboxBorderSprite->GetSize();
}
inline Nz::Vector2f CheckboxWidget::GetCheckboxBorderSize() const
{
return GetCheckboxSize() / s_borderScale;
}
inline CheckboxState CheckboxWidget::GetState() const
{
return m_state;
}
inline float CheckboxWidget::GetTextMargin() const
{
return m_textMargin;
}
inline void CheckboxWidget::SetCheckboxSize(const Nz::Vector2f& size)
{
m_checkboxBorderSprite->SetSize(size);
m_checkboxBackgroundSprite->SetSize(size - GetCheckboxBorderSize() * 2.f);
m_checkboxContentSprite->SetSize(GetCheckboxSize() - GetCheckboxBorderSize() * 2.f - Nz::Vector2f { 4.f, 4.f });
UpdateSize();
Layout();
}
inline void CheckboxWidget::SetTextMargin(float margin)
{
m_textMargin = margin;
Layout();
}
inline void CheckboxWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
{
m_textSprite->Update(drawer);
UpdateSize();
Layout();
}
inline bool CheckboxWidget::ContainsCheckbox(int x, int y) const
{
Nz::Vector2f checkboxSize = GetCheckboxSize();
Nz::Vector3f pos = m_checkboxBorderEntity->GetComponent<NodeComponent>().GetPosition(Nz::CoordSys_Local);
return x > pos.x && x < pos.x + checkboxSize.x &&
y > pos.y && y < pos.y + checkboxSize.y;
}
}

View File

@@ -1,37 +0,0 @@
// 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 NAZARA_ENUMS_SDK_HPP
#define NAZARA_ENUMS_SDK_HPP
namespace Ndk
{
enum BoxLayoutOrientation
{
BoxLayoutOrientation_Horizontal,
BoxLayoutOrientation_Vertical
};
enum CheckboxState
{
CheckboxState_Checked,
CheckboxState_Tristate,
CheckboxState_Unchecked,
CheckboxState_Max = CheckboxState_Unchecked
};
enum EchoMode
{
EchoMode_Normal,
EchoMode_Password,
EchoMode_PasswordExceptLast,
EchoMode_Max = EchoMode_PasswordExceptLast
};
}
#endif // NAZARA_ENUMS_SDK_HPP

View File

@@ -1,51 +0,0 @@
// 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 <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <NazaraSDK/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);
ImageWidget(const ImageWidget&) = delete;
ImageWidget(ImageWidget&&) = default;
~ImageWidget() = default;
//virtual ImageWidget* Clone() const = 0;
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);
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 <NazaraSDK/Widgets/ImageWidget.inl>
#endif // NDK_WIDGETS_IMAGEWIDGET_HPP

View File

@@ -1,47 +0,0 @@
// 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 <NazaraSDK/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)
{
m_sprite->SetTexture(texture, false);
Nz::Vector2f textureSize = Nz::Vector2f(Nz::Vector2ui(m_sprite->GetMaterial()->GetDiffuseMap()->GetSize()));
SetMinimumSize(textureSize);
SetPreferredSize(textureSize);
}
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,42 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_LABELWIDGET_HPP
#define NDK_WIDGETS_LABELWIDGET_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
namespace Nz
{
class AbstractTextDrawer;
}
namespace Ndk
{
class NDK_API LabelWidget : public BaseWidget
{
public:
LabelWidget(BaseWidget* parent);
LabelWidget(const LabelWidget&) = delete;
LabelWidget(LabelWidget&&) = default;
~LabelWidget() = default;
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
LabelWidget& operator=(const LabelWidget&) = delete;
LabelWidget& operator=(LabelWidget&&) = default;
private:
EntityHandle m_textEntity;
Nz::TextSpriteRef m_textSprite;
};
}
#include <NazaraSDK/Widgets/LabelWidget.inl>
#endif // NDK_WIDGETS_LABELWIDGET_HPP

View File

@@ -1,17 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Widgets/LabelWidget.hpp>
namespace Ndk
{
inline void LabelWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
{
m_textSprite->Update(drawer);
Nz::Vector2f size = Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths());
SetMinimumSize(size);
SetPreferredSize(size);
}
}

View File

@@ -1,101 +0,0 @@
// 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_PROGRESSBARWIDGET_HPP
#define NDK_WIDGETS_PROGRESSBARWIDGET_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Graphics/Sprite.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Utility/SimpleTextDrawer.hpp>
namespace Ndk
{
class NDK_API ProgressBarWidget : public BaseWidget
{
friend class Sdk;
public:
ProgressBarWidget(BaseWidget* parent);
ProgressBarWidget(const ProgressBarWidget&) = delete;
ProgressBarWidget(ProgressBarWidget&&) = default;
~ProgressBarWidget() = default;
//virtual ProgressBarWidget* Clone() const = 0;
inline void EnableText(bool enable = true);
inline void EnableBorder(bool enable = true);
inline bool IsTextEnabled() const;
inline bool IsBorderEnabled() const;
inline unsigned GetPercentageValue() const;
inline Nz::Vector2f GetProgressBarSize() const;
inline Nz::Vector2f GetProgressBarBorderSize() const;
inline float GetTextMargin() const;
inline const Nz::Color& GetBarBackgroundColor() const;
inline const Nz::Color& GetBarBackgroundCornerColor() const;
inline const Nz::Color& GetBarColor() const;
inline const Nz::Color& GetBarCornerColor() const;
inline const Nz::TextureRef& GetBarBackgroundTexture() const;
inline const Nz::TextureRef& GetBarTexture() const;
static const Nz::Color& GetDefaultBarColor();
static const Nz::Color& GetDefaultBarCornerColor();
static const Nz::Color& GetDefaultBarBackgroundColor();
static const Nz::Color& GetDefaultBarBackgroundCornerColor();
inline void SetBarBackgroundColor(const Nz::Color& globalColor, const Nz::Color& cornerColor);
inline void SetBarBackgroundTexture(Nz::TextureRef texture, bool resetColors = true);
inline void SetBarColor(const Nz::Color& globalColor, const Nz::Color& cornerColor);
inline void SetBarTexture(Nz::TextureRef texture, bool resetColors = true);
inline void SetPercentageValue(unsigned percentage);
inline void SetTextMargin(float margin);
inline void SetTextColor(const Nz::Color& color);
NazaraSignal(OnValueChanged, const ProgressBarWidget* /*progressBar*/);
private:
void Layout() override;
inline void UpdateText();
EntityHandle m_borderEntity;
EntityHandle m_barEntity;
EntityHandle m_textEntity;
static Nz::Color s_borderColor;
static Nz::Color s_barBackgroundColor;
static Nz::Color s_barBackgroundCornerColor;
static Nz::Color s_barColor;
static Nz::Color s_barCornerColor;
Nz::Color m_textColor;
Nz::SpriteRef m_borderSprite;
Nz::SpriteRef m_barBackgroundSprite;
Nz::SpriteRef m_barSprite;
Nz::TextSpriteRef m_textSprite;
static float s_borderScale;
float m_textMargin;
unsigned m_value;
};
}
#include <NazaraSDK/Widgets/ProgressBarWidget.inl>
#endif // NDK_WIDGETS_PROGRESSBARWIDGET_HPP

View File

@@ -1,155 +0,0 @@
// 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
namespace Ndk
{
inline void ProgressBarWidget::EnableText(bool enable)
{
m_textEntity->Enable(enable);
Layout();
}
inline void ProgressBarWidget::EnableBorder(bool enable)
{
m_borderEntity->Enable(enable);
}
inline bool ProgressBarWidget::IsTextEnabled() const
{
return m_textEntity->IsEnabled();
}
inline bool ProgressBarWidget::IsBorderEnabled() const
{
return m_borderEntity->IsEnabled();
}
inline unsigned ProgressBarWidget::GetPercentageValue() const
{
return m_value;
}
inline Nz::Vector2f ProgressBarWidget::GetProgressBarSize() const
{
Nz::Vector3f progressBarSize = m_borderSprite->GetBoundingVolume().obb.localBox.GetLengths();
if (IsTextEnabled())
{
Nz::Vector3f textSize = m_textSprite->GetBoundingVolume().obb.localBox.GetLengths();
progressBarSize -= { textSize.x + m_textMargin, 0.f, 0.f };
}
return { progressBarSize.x, progressBarSize.y };
}
inline Nz::Vector2f ProgressBarWidget::GetProgressBarBorderSize() const
{
Nz::Vector2f barSize = GetProgressBarSize();
return { barSize.y / s_borderScale, barSize.y / s_borderScale };
}
inline float ProgressBarWidget::GetTextMargin() const
{
return m_textMargin;
}
inline const Nz::Color& ProgressBarWidget::GetBarBackgroundColor() const
{
return m_barBackgroundSprite->GetColor();
}
inline const Nz::Color& ProgressBarWidget::GetBarBackgroundCornerColor() const
{
return m_barBackgroundSprite->GetCornerColor(Nz::RectCorner_LeftTop);
}
inline const Nz::Color& ProgressBarWidget::GetBarColor() const
{
return m_barSprite->GetColor();
}
inline const Nz::Color& ProgressBarWidget::GetBarCornerColor() const
{
return m_barSprite->GetCornerColor(Nz::RectCorner_LeftTop);
}
inline const Nz::TextureRef& ProgressBarWidget::GetBarBackgroundTexture() const
{
return m_barBackgroundSprite->GetMaterial()->GetDiffuseMap();
}
inline const Nz::TextureRef& ProgressBarWidget::GetBarTexture() const
{
return m_barSprite->GetMaterial()->GetDiffuseMap();
}
inline void ProgressBarWidget::SetBarBackgroundColor(const Nz::Color& globalColor, const Nz::Color& cornerColor)
{
m_barBackgroundSprite->SetColor(globalColor);
m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_LeftTop, cornerColor);
m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_RightTop, cornerColor);
m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_LeftBottom, globalColor);
m_barBackgroundSprite->SetCornerColor(Nz::RectCorner_RightBottom, globalColor);
}
inline void ProgressBarWidget::SetBarBackgroundTexture(Nz::TextureRef texture, bool resetColors)
{
m_barBackgroundSprite->SetTexture(texture, false);
if (resetColors)
SetBarBackgroundColor(Nz::Color::White, Nz::Color::White);
}
inline void ProgressBarWidget::SetBarColor(const Nz::Color& globalColor, const Nz::Color& cornerColor)
{
m_barSprite->SetColor(globalColor);
m_barSprite->SetCornerColor(Nz::RectCorner_LeftTop, cornerColor);
m_barSprite->SetCornerColor(Nz::RectCorner_RightTop, cornerColor);
m_barSprite->SetCornerColor(Nz::RectCorner_LeftBottom, globalColor);
m_barSprite->SetCornerColor(Nz::RectCorner_RightBottom, globalColor);
}
inline void ProgressBarWidget::SetBarTexture(Nz::TextureRef texture, bool resetColors)
{
m_barSprite->SetTexture(texture, false);
if (resetColors)
SetBarColor(Nz::Color::White, Nz::Color::White);
}
inline void ProgressBarWidget::SetPercentageValue(unsigned percentage)
{
m_value = percentage;
OnValueChanged(this);
Layout();
}
inline void ProgressBarWidget::SetTextMargin(float margin)
{
m_textMargin = margin;
if (IsTextEnabled())
Layout();
}
inline void ProgressBarWidget::SetTextColor(const Nz::Color& color)
{
m_textColor = color;
UpdateText();
}
inline void ProgressBarWidget::UpdateText()
{
if (IsTextEnabled())
{
Nz::Vector2f size = GetSize();
m_textSprite->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_value).Append('%'), static_cast<unsigned int>(std::min(size.x, size.y) / 2.f), 0u, m_textColor));
}
}
}

View File

@@ -1,68 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_RICHTEXTAREAWIDGET_HPP
#define NDK_WIDGETS_RICHTEXTAREAWIDGET_HPP
#include <Nazara/Utility/RichTextDrawer.hpp>
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.hpp>
namespace Ndk
{
class NDK_API RichTextAreaWidget : public AbstractTextAreaWidget
{
public:
RichTextAreaWidget(BaseWidget* parent);
RichTextAreaWidget(const RichTextAreaWidget&) = delete;
RichTextAreaWidget(RichTextAreaWidget&&) = default;
~RichTextAreaWidget() = default;
void AppendText(const Nz::String& text);
void Clear() override;
void Erase(std::size_t firstGlyph, std::size_t lastGlyph) override;
inline unsigned int GetCharacterSize() const;
inline float GetCharacterSpacingOffset() const;
inline float GetLineSpacingOffset() const;
inline const Nz::Color& GetTextColor() const;
inline Nz::Font* GetTextFont() const;
inline const Nz::Color& GetTextOutlineColor() const;
inline float GetTextOutlineThickness() const;
inline Nz::TextStyleFlags GetTextStyle() const;
inline void SetCharacterSize(unsigned int characterSize);
inline void SetCharacterSpacingOffset(float offset);
inline void SetLineSpacingOffset(float offset);
inline void SetTextColor(const Nz::Color& color);
inline void SetTextFont(Nz::FontRef font);
inline void SetTextOutlineColor(const Nz::Color& color);
inline void SetTextOutlineThickness(float thickness);
inline void SetTextStyle(Nz::TextStyleFlags style);
void Write(const Nz::String& text, std::size_t glyphPosition) override;
RichTextAreaWidget& operator=(const RichTextAreaWidget&) = delete;
RichTextAreaWidget& operator=(RichTextAreaWidget&&) = default;
private:
Nz::AbstractTextDrawer& GetTextDrawer() override;
const Nz::AbstractTextDrawer& GetTextDrawer() const override;
void HandleIndentation(bool add) override;
void HandleSelectionIndentation(bool add) override;
void HandleWordCursorMove(bool left) override;
void UpdateDisplayText() override;
Nz::RichTextDrawer m_drawer;
};
}
#include <NazaraSDK/Widgets/RichTextAreaWidget.inl>
#endif // NDK_WIDGETS_TEXTAREAWIDGET_HPP

View File

@@ -1,88 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Widgets/RichTextAreaWidget.hpp>
namespace Ndk
{
inline unsigned int RichTextAreaWidget::GetCharacterSize() const
{
return m_drawer.GetDefaultCharacterSize();
}
inline float RichTextAreaWidget::GetCharacterSpacingOffset() const
{
return m_drawer.GetDefaultCharacterSpacingOffset();
}
inline float RichTextAreaWidget::GetLineSpacingOffset() const
{
return m_drawer.GetDefaultLineSpacingOffset();
}
inline const Nz::Color& RichTextAreaWidget::GetTextColor() const
{
return m_drawer.GetDefaultColor();
}
inline Nz::Font* RichTextAreaWidget::GetTextFont() const
{
return m_drawer.GetDefaultFont();
}
inline const Nz::Color& RichTextAreaWidget::GetTextOutlineColor() const
{
return m_drawer.GetDefaultOutlineColor();
}
inline float RichTextAreaWidget::GetTextOutlineThickness() const
{
return m_drawer.GetDefaultOutlineThickness();
}
inline Nz::TextStyleFlags RichTextAreaWidget::GetTextStyle() const
{
return m_drawer.GetDefaultStyle();
}
inline void RichTextAreaWidget::SetCharacterSize(unsigned int characterSize)
{
m_drawer.SetDefaultCharacterSize(characterSize);
}
inline void RichTextAreaWidget::SetCharacterSpacingOffset(float offset)
{
m_drawer.SetDefaultCharacterSpacingOffset(offset);
}
inline void RichTextAreaWidget::SetLineSpacingOffset(float offset)
{
m_drawer.SetDefaultLineSpacingOffset(offset);
}
inline void RichTextAreaWidget::SetTextColor(const Nz::Color& color)
{
m_drawer.SetDefaultColor(color);
}
inline void RichTextAreaWidget::SetTextFont(Nz::FontRef font)
{
m_drawer.SetDefaultFont(std::move(font));
}
inline void RichTextAreaWidget::SetTextOutlineColor(const Nz::Color& color)
{
m_drawer.SetDefaultOutlineColor(color);
}
inline void RichTextAreaWidget::SetTextOutlineThickness(float thickness)
{
m_drawer.SetDefaultOutlineThickness(thickness);
}
inline void RichTextAreaWidget::SetTextStyle(Nz::TextStyleFlags style)
{
m_drawer.SetDefaultStyle(style);
}
}

View File

@@ -1,74 +0,0 @@
// Copyright (C) 2019 Jérôme Leclercq
// 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_SCROLLAREAWIDGET_HPP
#define NDK_WIDGETS_SCROLLAREAWIDGET_HPP
#include <NazaraSDK/Prerequisites.hpp>
#include <NazaraSDK/BaseWidget.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
namespace Ndk
{
class NDK_API ScrollAreaWidget : public BaseWidget
{
public:
ScrollAreaWidget(BaseWidget* parent, BaseWidget* content);
ScrollAreaWidget(const ScrollAreaWidget&) = delete;
ScrollAreaWidget(ScrollAreaWidget&&) = default;
~ScrollAreaWidget() = default;
void EnableScrollbar(bool enable);
inline float GetScrollHeight() const;
inline float GetScrollRatio() const;
inline bool HasScrollbar() const;
inline bool IsScrollbarEnabled() const;
inline bool IsScrollbarVisible() const;
inline void ScrollToHeight(float height);
void ScrollToRatio(float ratio);
ScrollAreaWidget& operator=(const ScrollAreaWidget&) = delete;
ScrollAreaWidget& operator=(ScrollAreaWidget&&) = default;
private:
enum class ScrollBarStatus
{
Grabbed,
Hovered,
None
};
Nz::Rectf GetScrollbarRect() const;
void Layout() 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;
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
void OnMouseWheelMoved(int x, int y, float delta) override;
void UpdateScrollbarStatus(ScrollBarStatus status);
BaseWidget* m_content;
EntityHandle m_scrollbarBackgroundEntity;
EntityHandle m_scrollbarEntity;
Nz::SpriteRef m_scrollbarBackgroundSprite;
Nz::SpriteRef m_scrollbarSprite;
Nz::Vector2i m_grabbedDelta;
ScrollBarStatus m_scrollbarStatus;
bool m_isScrollbarEnabled;
bool m_hasScrollbar;
float m_scrollRatio;
};
}
#include <NazaraSDK/Widgets/ScrollAreaWidget.inl>
#endif // NDK_WIDGETS_SCROLLAREAWIDGET_HPP

View File

@@ -1,39 +0,0 @@
// Copyright (C) 2019 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <NazaraSDK/Widgets/ScrollAreaWidget.hpp>
namespace Ndk
{
inline float ScrollAreaWidget::GetScrollHeight() const
{
return m_scrollRatio * m_content->GetHeight();
}
inline float ScrollAreaWidget::GetScrollRatio() const
{
return m_scrollRatio;
}
inline bool ScrollAreaWidget::HasScrollbar() const
{
return m_hasScrollbar;
}
inline bool ScrollAreaWidget::IsScrollbarEnabled() const
{
return m_isScrollbarEnabled;
}
inline bool ScrollAreaWidget::IsScrollbarVisible() const
{
return HasScrollbar() && IsScrollbarEnabled();
}
inline void ScrollAreaWidget::ScrollToHeight(float height)
{
float contentHeight = m_content->GetHeight();
ScrollToRatio(height / contentHeight);
}
}

View File

@@ -1,77 +0,0 @@
// 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 Prerequisites.hpp
#pragma once
#ifndef NDK_WIDGETS_TEXTAREAWIDGET_HPP
#define NDK_WIDGETS_TEXTAREAWIDGET_HPP
#include <Nazara/Utility/SimpleTextDrawer.hpp>
#include <NazaraSDK/Widgets/AbstractTextAreaWidget.hpp>
namespace Ndk
{
class NDK_API TextAreaWidget : public AbstractTextAreaWidget
{
public:
TextAreaWidget(BaseWidget* parent);
TextAreaWidget(const TextAreaWidget&) = delete;
TextAreaWidget(TextAreaWidget&&) = default;
~TextAreaWidget() = default;
void AppendText(const Nz::String& text);
void Clear() override;
using AbstractTextAreaWidget::Erase;
void Erase(std::size_t firstGlyph, std::size_t lastGlyph) override;
inline unsigned int GetCharacterSize() const;
inline const Nz::String& GetDisplayText() const;
inline float GetCharacterSpacingOffset() const;
inline float GetLineSpacingOffset() const;
inline const Nz::String& GetText() const;
inline const Nz::Color& GetTextColor() const;
inline Nz::Font* GetTextFont() const;
inline const Nz::Color& GetTextOulineColor() const;
inline float GetTextOulineThickness() const;
inline Nz::TextStyleFlags GetTextStyle() const;
inline void SetCharacterSize(unsigned int characterSize);
inline void SetCharacterSpacingOffset(float offset);
inline void SetLineSpacingOffset(float offset);
inline void SetText(const Nz::String& text);
inline void SetTextColor(const Nz::Color& text);
inline void SetTextFont(Nz::FontRef font);
inline void SetTextOutlineColor(const Nz::Color& color);
inline void SetTextOutlineThickness(float thickness);
inline void SetTextStyle(Nz::TextStyleFlags style);
using AbstractTextAreaWidget::Write;
void Write(const Nz::String& text, std::size_t glyphPosition) override;
TextAreaWidget& operator=(const TextAreaWidget&) = delete;
TextAreaWidget& operator=(TextAreaWidget&&) = default;
NazaraSignal(OnTextChanged, const AbstractTextAreaWidget* /*textArea*/, const Nz::String& /*text*/);
private:
Nz::AbstractTextDrawer& GetTextDrawer() override;
const Nz::AbstractTextDrawer& GetTextDrawer() const override;
void HandleIndentation(bool add) override;
void HandleSelectionIndentation(bool add) override;
void HandleWordCursorMove(bool left) override;
void UpdateDisplayText() override;
void UpdateMinimumSize();
Nz::SimpleTextDrawer m_drawer;
Nz::String m_text;
};
}
#include <NazaraSDK/Widgets/TextAreaWidget.inl>
#endif // NDK_WIDGETS_TEXTAREAWIDGET_HPP

View File

@@ -1,124 +0,0 @@
// 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 Prerequisites.hpp
#include <NazaraSDK/Widgets/TextAreaWidget.hpp>
namespace Ndk
{
inline unsigned int TextAreaWidget::GetCharacterSize() const
{
return m_drawer.GetCharacterSize();
}
inline const Nz::String& TextAreaWidget::GetDisplayText() const
{
return m_drawer.GetText();
}
inline float TextAreaWidget::GetCharacterSpacingOffset() const
{
return m_drawer.GetCharacterSpacingOffset();
}
inline float TextAreaWidget::GetLineSpacingOffset() const
{
return m_drawer.GetLineSpacingOffset();
}
inline const Nz::String& TextAreaWidget::GetText() const
{
return m_text;
}
inline const Nz::Color& TextAreaWidget::GetTextColor() const
{
return m_drawer.GetColor();
}
inline Nz::Font* TextAreaWidget::GetTextFont() const
{
return m_drawer.GetFont();
}
inline const Nz::Color& TextAreaWidget::GetTextOulineColor() const
{
return m_drawer.GetOutlineColor();
}
inline float TextAreaWidget::GetTextOulineThickness() const
{
return m_drawer.GetOutlineThickness();
}
inline Nz::TextStyleFlags TextAreaWidget::GetTextStyle() const
{
return m_drawer.GetStyle();
}
inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
{
m_drawer.SetCharacterSize(characterSize);
UpdateMinimumSize();
UpdateDisplayText();
}
inline void TextAreaWidget::SetCharacterSpacingOffset(float offset)
{
m_drawer.SetCharacterSpacingOffset(offset);
UpdateMinimumSize();
UpdateDisplayText();
}
inline void TextAreaWidget::SetLineSpacingOffset(float offset)
{
m_drawer.SetLineSpacingOffset(offset);
UpdateDisplayText();
}
inline void TextAreaWidget::SetText(const Nz::String& text)
{
m_text = text;
OnTextChanged(this, m_text);
UpdateDisplayText();
}
inline void TextAreaWidget::SetTextColor(const Nz::Color& text)
{
m_drawer.SetColor(text);
UpdateDisplayText();
}
inline void TextAreaWidget::SetTextFont(Nz::FontRef font)
{
m_drawer.SetFont(font);
UpdateDisplayText();
}
inline void TextAreaWidget::SetTextOutlineColor(const Nz::Color& color)
{
m_drawer.SetOutlineColor(color);
UpdateDisplayText();
}
inline void TextAreaWidget::SetTextOutlineThickness(float thickness)
{
m_drawer.SetOutlineThickness(thickness);
UpdateDisplayText();
}
inline void TextAreaWidget::SetTextStyle(Nz::TextStyleFlags style)
{
m_drawer.SetStyle(style);
UpdateDisplayText();
}
}

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