diff --git a/include/Nazara/Utility/Components.hpp b/include/Nazara/Utility/Components.hpp index ee183b2e8..a08f6ad6c 100644 --- a/include/Nazara/Utility/Components.hpp +++ b/include/Nazara/Utility/Components.hpp @@ -30,5 +30,6 @@ #define NAZARA_UTILITY_COMPONENTS_HPP #include +#include #endif // NAZARA_UTILITY_COMPONENTS_HPP diff --git a/include/Nazara/Utility/Components/VelocityComponent.hpp b/include/Nazara/Utility/Components/VelocityComponent.hpp new file mode 100644 index 000000000..2443f6801 --- /dev/null +++ b/include/Nazara/Utility/Components/VelocityComponent.hpp @@ -0,0 +1,38 @@ +// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_UTILITY_COMPONENTS_VELOCITYCOMPONENT_HPP +#define NAZARA_UTILITY_COMPONENTS_VELOCITYCOMPONENT_HPP + +#include +#include +#include + +namespace Nz +{ + class NAZARA_UTILITY_API VelocityComponent + { + public: + inline VelocityComponent(const Vector3f& linearVelocity = Vector3f::Zero()); + VelocityComponent(const VelocityComponent&) = default; + VelocityComponent(VelocityComponent&&) = default; + ~VelocityComponent() = default; + + inline const Vector3f& GetLinearVelocity() const; + + inline void UpdateLinearVelocity(const Vector3f& linearVelocity); + + VelocityComponent& operator=(const VelocityComponent&) = default; + VelocityComponent& operator=(VelocityComponent&&) = default; + + private: + Vector3f m_linearVelocity; + }; +} + +#include + +#endif // NAZARA_UTILITY_COMPONENTS_VELOCITYCOMPONENT_HPP diff --git a/include/Nazara/Utility/Components/VelocityComponent.inl b/include/Nazara/Utility/Components/VelocityComponent.inl new file mode 100644 index 000000000..c4e8c5d09 --- /dev/null +++ b/include/Nazara/Utility/Components/VelocityComponent.inl @@ -0,0 +1,26 @@ +// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + inline VelocityComponent::VelocityComponent(const Vector3f& linearVelocity) : + m_linearVelocity(linearVelocity) + { + } + + inline const Vector3f& VelocityComponent::GetLinearVelocity() const + { + return m_linearVelocity; + } + + inline void VelocityComponent::UpdateLinearVelocity(const Vector3f& linearVelocity) + { + m_linearVelocity = linearVelocity; + } +} + +#include diff --git a/include/Nazara/Utility/Systems.hpp b/include/Nazara/Utility/Systems.hpp new file mode 100644 index 000000000..89e275012 --- /dev/null +++ b/include/Nazara/Utility/Systems.hpp @@ -0,0 +1,34 @@ +// this file was automatically generated and should not be edited + +/* + Nazara Engine - Utility module + + Copyright (C) 2022 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. +*/ + +#pragma once + +#ifndef NAZARA_UTILITY_SYSTEMS_HPP +#define NAZARA_UTILITY_SYSTEMS_HPP + +#include + +#endif // NAZARA_UTILITY_SYSTEMS_HPP diff --git a/include/Nazara/Utility/Systems/VelocitySystem.hpp b/include/Nazara/Utility/Systems/VelocitySystem.hpp new file mode 100644 index 000000000..c68095593 --- /dev/null +++ b/include/Nazara/Utility/Systems/VelocitySystem.hpp @@ -0,0 +1,39 @@ +// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_UTILITY_SYSTEMS_VELOCITYSYSTEM_HPP +#define NAZARA_UTILITY_SYSTEMS_VELOCITYSYSTEM_HPP + +#include +#include +#include +#include + +namespace Nz +{ + class NAZARA_UTILITY_API VelocitySystem + { + public: + using Components = TypeList; + + inline VelocitySystem(entt::registry& registry); + VelocitySystem(const VelocitySystem&) = delete; + VelocitySystem(VelocitySystem&&) = delete; + ~VelocitySystem() = default; + + void Update(float elapsedTime); + + VelocitySystem& operator=(const VelocitySystem&) = delete; + VelocitySystem& operator=(VelocitySystem&&) = delete; + + private: + entt::registry& m_registry; + }; +} + +#include + +#endif // NAZARA_UTILITY_SYSTEMS_VELOCITYSYSTEM_HPP diff --git a/include/Nazara/Utility/Systems/VelocitySystem.inl b/include/Nazara/Utility/Systems/VelocitySystem.inl new file mode 100644 index 000000000..cf5936793 --- /dev/null +++ b/include/Nazara/Utility/Systems/VelocitySystem.inl @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + inline VelocitySystem::VelocitySystem(entt::registry& registry) : + m_registry(registry) + { + } +} + +#include diff --git a/src/Nazara/Utility/Systems/VelocitySystem.cpp b/src/Nazara/Utility/Systems/VelocitySystem.cpp new file mode 100644 index 000000000..b27e59207 --- /dev/null +++ b/src/Nazara/Utility/Systems/VelocitySystem.cpp @@ -0,0 +1,21 @@ +// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +namespace Nz +{ + void VelocitySystem::Update(float elapsedTime) + { + auto view = m_registry.view(); + for (auto [entity, nodeComponent, velocityComponent] : view.each()) + { + NazaraUnused(entity); + nodeComponent.Move(velocityComponent.GetLinearVelocity() * elapsedTime); + } + } +}