diff --git a/SDK/include/NDK/Components/VelocityComponent.hpp b/SDK/include/NDK/Components/VelocityComponent.hpp new file mode 100644 index 000000000..99a0cad6d --- /dev/null +++ b/SDK/include/NDK/Components/VelocityComponent.hpp @@ -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 +#include + +namespace Ndk +{ + class Entity; + + class NDK_API VelocityComponent : public Component + { + public: + VelocityComponent(const NzVector3f& velocity = NzVector3f::Zero()); + ~VelocityComponent() = default; + + NzVector3f linearVelocity; + + VelocityComponent& operator=(const NzVector3f& vel); + + static ComponentIndex componentIndex; + }; +} + +#include + +#endif // NDK_COMPONENTS_VELOCITYCOMPONENT_HPP diff --git a/SDK/include/NDK/Components/VelocityComponent.inl b/SDK/include/NDK/Components/VelocityComponent.inl new file mode 100644 index 000000000..55e319351 --- /dev/null +++ b/SDK/include/NDK/Components/VelocityComponent.inl @@ -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 +#include + +namespace Ndk +{ + inline VelocityComponent::VelocityComponent(const NzVector3f& velocity) : + linearVelocity(velocity) + { + } + + inline VelocityComponent& VelocityComponent::operator=(const NzVector3f& vel) + { + linearVelocity = vel; + return *this; + } +} diff --git a/SDK/include/NDK/Systems/VelocitySystem.hpp b/SDK/include/NDK/Systems/VelocitySystem.hpp new file mode 100644 index 000000000..b297d1959 --- /dev/null +++ b/SDK/include/NDK/Systems/VelocitySystem.hpp @@ -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 + +namespace Ndk +{ + class NDK_API VelocitySystem : public System + { + public: + VelocitySystem(); + ~VelocitySystem() = default; + + void Update(float elapsedTime); + + static SystemIndex systemIndex; + }; +} + +#include + +#endif // NDK_SYSTEMS_VELOCITYSYSTEM_HPP diff --git a/SDK/include/NDK/Systems/VelocitySystem.inl b/SDK/include/NDK/Systems/VelocitySystem.inl new file mode 100644 index 000000000..e5f296d27 --- /dev/null +++ b/SDK/include/NDK/Systems/VelocitySystem.inl @@ -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 diff --git a/SDK/src/NDK/Components/VelocityComponent.cpp b/SDK/src/NDK/Components/VelocityComponent.cpp new file mode 100644 index 000000000..15c5ca31f --- /dev/null +++ b/SDK/src/NDK/Components/VelocityComponent.cpp @@ -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 + +namespace Ndk +{ + ComponentIndex VelocityComponent::componentIndex; +} diff --git a/SDK/src/NDK/Sdk.cpp b/SDK/src/NDK/Sdk.cpp index 070446cc7..6d2bff6d4 100644 --- a/SDK/src/NDK/Sdk.cpp +++ b/SDK/src/NDK/Sdk.cpp @@ -15,7 +15,9 @@ #include #include #include +#include #include +#include namespace Ndk { @@ -49,9 +51,11 @@ namespace Ndk // Composants InitializeComponent("NdkList"); InitializeComponent("NdkNode"); + InitializeComponent("NdkVeloc"); // Systèmes InitializeSystem(); + InitializeSystem(); NazaraNotice("Initialized: SDK"); return true; diff --git a/SDK/src/NDK/Systems/VelocitySystem.cpp b/SDK/src/NDK/Systems/VelocitySystem.cpp new file mode 100644 index 000000000..415889e20 --- /dev/null +++ b/SDK/src/NDK/Systems/VelocitySystem.cpp @@ -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 +#include +#include + +namespace Ndk +{ + VelocitySystem::VelocitySystem() + { + Requires(); + } + + void VelocitySystem::Update(float elapsedTime) + { + for (const Ndk::EntityHandle& entity : GetEntities()) + { + NodeComponent& node = entity->GetComponent(); + const VelocityComponent& velocity = entity->GetComponent(); + + node.Move(velocity.linearVelocity * elapsedTime); + } + } + + SystemIndex VelocitySystem::systemIndex; +} diff --git a/SDK/src/NDK/World.cpp b/SDK/src/NDK/World.cpp index efa1d3a41..c1a91fa10 100644 --- a/SDK/src/NDK/World.cpp +++ b/SDK/src/NDK/World.cpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace Ndk { @@ -17,6 +18,7 @@ namespace Ndk void World::AddDefaultSystems() { AddSystem(); + AddSystem(); } const EntityHandle& World::CreateEntity()