Core: Add Lifetime component and system
This commit is contained in:
21
src/Nazara/Core/Systems/LifetimeSystem.cpp
Normal file
21
src/Nazara/Core/Systems/LifetimeSystem.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Systems/LifetimeSystem.hpp>
|
||||
#include <Nazara/Core/Components/LifetimeComponent.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
void LifetimeSystem::Update(float elapsedTime)
|
||||
{
|
||||
auto view = m_registry.view<LifetimeComponent>();
|
||||
for (auto [entity, lifetimeComponent] : view.each())
|
||||
{
|
||||
lifetimeComponent.DecreaseLifetime(elapsedTime);
|
||||
if (!lifetimeComponent.IsAlive())
|
||||
m_registry.destroy(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user