Creating the timer system

This commit is contained in:
Zoe Roux
2021-05-31 17:28:56 +02:00
parent 44b68b15e6
commit 1cf2a9ee9f
4 changed files with 67 additions and 4 deletions
+3 -1
View File
@@ -11,6 +11,7 @@
#include <Model/Model.hpp>
#include <Drawables/2D/Rectangle.hpp>
#include <TraceLog.hpp>
#include "System/Timer/TimerSystem.hpp"
#include "Component/BombHolder/BombHolderComponent.hpp"
#include "System/BombHolder/BombHolderSystem.hpp"
#include "System/Renderer/Renderer3DSystem.hpp"
@@ -42,7 +43,8 @@ namespace BBM
void addSystems(WAL::Wal &wal)
{
wal.addSystem<KeyboardSystem>()
wal.addSystem<TimerSystem>()
.addSystem<KeyboardSystem>()
.addSystem<GamepadSystem>()
.addSystem<ControllableSystem>()
.addSystem<BombHolderSystem>(wal)
+27
View File
@@ -0,0 +1,27 @@
//
// Created by Zoe Roux on 5/31/21.
//
#include "TimerSystem.hpp"
#include "Component/Timer/TimerComponent.hpp"
using namespace std::chrono_literals;
namespace BBM
{
TimerSystem::TimerSystem()
: WAL::System({
typeid(TimerComponent)
})
{}
void TimerSystem::onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime)
{
auto &timer = entity.getComponent<TimerComponent>();
timer.ringIn -= dtime;
if (timer.ringIn <= 0ns) {
timer.setDisable(true);
timer.callback(entity);
}
}
}
+26
View File
@@ -0,0 +1,26 @@
//
// Created by Zoe Roux on 5/31/21.
//
#pragma once
#include <System/System.hpp>
namespace BBM
{
class TimerSystem : public WAL::System
{
public:
//! @inherit
void onUpdate(WAL::Entity &entity, std::chrono::nanoseconds dtime) override;
//! @brief A default constructor
TimerSystem();
//! @brief A timer system is copy constructable.
TimerSystem(const TimerSystem &) = default;
//! @brief A default destructor
~TimerSystem() override = default;
//! @breief A timer system is assignable.
TimerSystem &operator=(const TimerSystem &) = default;
};
}