Utility: Add velocity component and system

This commit is contained in:
SirLynix 2022-07-02 19:43:58 +02:00
parent 99b4397d78
commit d5f70279a1
7 changed files with 175 additions and 0 deletions

View File

@ -30,5 +30,6 @@
#define NAZARA_UTILITY_COMPONENTS_HPP
#include <Nazara/Utility/Components/NodeComponent.hpp>
#include <Nazara/Utility/Components/VelocityComponent.hpp>
#endif // NAZARA_UTILITY_COMPONENTS_HPP

View File

@ -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 <Nazara/Prerequisites.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Config.hpp>
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 <Nazara/Utility/Components/VelocityComponent.inl>
#endif // NAZARA_UTILITY_COMPONENTS_VELOCITYCOMPONENT_HPP

View File

@ -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 <Nazara/Utility/Components/VelocityComponent.hpp>
#include <Nazara/Utility/Debug.hpp>
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 <Nazara/Utility/DebugOff.hpp>

View File

@ -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 <Nazara/Utility/Systems/VelocitySystem.hpp>
#endif // NAZARA_UTILITY_SYSTEMS_HPP

View File

@ -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 <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utils/TypeList.hpp>
#include <entt/entt.hpp>
namespace Nz
{
class NAZARA_UTILITY_API VelocitySystem
{
public:
using Components = TypeList<class NodeComponent, class VelocityComponent>;
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 <Nazara/Utility/Systems/VelocitySystem.inl>
#endif // NAZARA_UTILITY_SYSTEMS_VELOCITYSYSTEM_HPP

View File

@ -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 <Nazara/Utility/Systems/VelocitySystem.hpp>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
inline VelocitySystem::VelocitySystem(entt::registry& registry) :
m_registry(registry)
{
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@ -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 <Nazara/Utility/Systems/VelocitySystem.hpp>
#include <Nazara/Utility/Components/NodeComponent.hpp>
#include <Nazara/Utility/Components/VelocityComponent.hpp>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
void VelocitySystem::Update(float elapsedTime)
{
auto view = m_registry.view<NodeComponent, VelocityComponent>();
for (auto [entity, nodeComponent, velocityComponent] : view.each())
{
NazaraUnused(entity);
nodeComponent.Move(velocityComponent.GetLinearVelocity() * elapsedTime);
}
}
}