(NDK) Added Velocity component/system
Former-commit-id: 427b7175fbf9723fcd1d54fc279b8b70167745d4
This commit is contained in:
parent
2ab0defa48
commit
ead468525e
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_COMPONENTS_VELOCITYCOMPONENT_HPP
|
||||
#define NDK_COMPONENTS_VELOCITYCOMPONENT_HPP
|
||||
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NDK/Component.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class Entity;
|
||||
|
||||
class NDK_API VelocityComponent : public Component<VelocityComponent>
|
||||
{
|
||||
public:
|
||||
VelocityComponent(const NzVector3f& velocity = NzVector3f::Zero());
|
||||
~VelocityComponent() = default;
|
||||
|
||||
NzVector3f linearVelocity;
|
||||
|
||||
VelocityComponent& operator=(const NzVector3f& vel);
|
||||
|
||||
static ComponentIndex componentIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Components/VelocityComponent.inl>
|
||||
|
||||
#endif // NDK_COMPONENTS_VELOCITYCOMPONENT_HPP
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/Entity.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline VelocityComponent::VelocityComponent(const NzVector3f& velocity) :
|
||||
linearVelocity(velocity)
|
||||
{
|
||||
}
|
||||
|
||||
inline VelocityComponent& VelocityComponent::operator=(const NzVector3f& vel)
|
||||
{
|
||||
linearVelocity = vel;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_SYSTEMS_VELOCITYSYSTEM_HPP
|
||||
#define NDK_SYSTEMS_VELOCITYSYSTEM_HPP
|
||||
|
||||
#include <NDK/System.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API VelocitySystem : public System<VelocitySystem>
|
||||
{
|
||||
public:
|
||||
VelocitySystem();
|
||||
~VelocitySystem() = default;
|
||||
|
||||
void Update(float elapsedTime);
|
||||
|
||||
static SystemIndex systemIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Systems/VelocitySystem.inl>
|
||||
|
||||
#endif // NDK_SYSTEMS_VELOCITYSYSTEM_HPP
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
ComponentIndex VelocityComponent::componentIndex;
|
||||
}
|
||||
|
|
@ -15,7 +15,9 @@
|
|||
#include <NDK/BaseSystem.hpp>
|
||||
#include <NDK/Components/ListenerComponent.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -49,9 +51,11 @@ namespace Ndk
|
|||
// Composants
|
||||
InitializeComponent<ListenerComponent>("NdkList");
|
||||
InitializeComponent<NodeComponent>("NdkNode");
|
||||
InitializeComponent<VelocityComponent>("NdkVeloc");
|
||||
|
||||
// Systèmes
|
||||
InitializeSystem<ListenerSystem>();
|
||||
InitializeSystem<VelocitySystem>();
|
||||
|
||||
NazaraNotice("Initialized: SDK");
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
|
||||
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
#include <NDK/Components/NodeComponent.hpp>
|
||||
#include <NDK/Components/VelocityComponent.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
VelocitySystem::VelocitySystem()
|
||||
{
|
||||
Requires<NodeComponent, VelocityComponent>();
|
||||
}
|
||||
|
||||
void VelocitySystem::Update(float elapsedTime)
|
||||
{
|
||||
for (const Ndk::EntityHandle& entity : GetEntities())
|
||||
{
|
||||
NodeComponent& node = entity->GetComponent<NodeComponent>();
|
||||
const VelocityComponent& velocity = entity->GetComponent<VelocityComponent>();
|
||||
|
||||
node.Move(velocity.linearVelocity * elapsedTime);
|
||||
}
|
||||
}
|
||||
|
||||
SystemIndex VelocitySystem::systemIndex;
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
#include <NDK/World.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NDK/Systems/ListenerSystem.hpp>
|
||||
#include <NDK/Systems/VelocitySystem.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
|
|
@ -17,6 +18,7 @@ namespace Ndk
|
|||
void World::AddDefaultSystems()
|
||||
{
|
||||
AddSystem<ListenerSystem>();
|
||||
AddSystem<VelocitySystem>();
|
||||
}
|
||||
|
||||
const EntityHandle& World::CreateEntity()
|
||||
|
|
|
|||
Loading…
Reference in New Issue