Adding a timer component

This commit is contained in:
Zoe Roux
2021-05-31 17:19:23 +02:00
parent 8009c0619b
commit 44b68b15e6
3 changed files with 70 additions and 1 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ set(SOURCES
sources/Component/Renderer/CameraComponent.hpp
sources/System/Renderer/Render2DScreenSystem.cpp
sources/System/Renderer/Render2DScreenSystem.hpp
sources/System/BombHolder/BombHolderSystem.cpp sources/System/BombHolder/BombHolderSystem.hpp)
sources/System/BombHolder/BombHolderSystem.cpp sources/System/BombHolder/BombHolderSystem.hpp sources/Component/Timer/TimerComponent.cpp sources/Component/Timer/TimerComponent.hpp)
add_executable(bomberman
sources/main.cpp
@@ -0,0 +1,32 @@
//
// Created by Zoe Roux on 5/31/21.
//
#include "TimerComponent.hpp"
#include <utility>
namespace BBM
{
TimerComponent::TimerComponent(WAL::Entity &entity, std::chrono::nanoseconds delay)
: WAL::Component(entity),
ringIn(delay)
{}
TimerComponent::TimerComponent(WAL::Entity &entity, std::chrono::nanoseconds delay, const WAL::Callback<WAL::Entity &> &callback)
: WAL::Component(entity),
ringIn(delay),
callback(callback)
{}
TimerComponent::TimerComponent(WAL::Entity &entity, std::chrono::nanoseconds delay, std::function<void(WAL::Entity &)> callback)
: WAL::Component(entity),
ringIn(delay),
callback(std::move(callback))
{}
WAL::Component *TimerComponent::clone(WAL::Entity &entity) const
{
return new TimerComponent(entity, this->ringIn, this->callback);
}
}
@@ -0,0 +1,37 @@
//
// Created by Zoe Roux on 5/31/21.
//
#pragma once
#include <Component/Component.hpp>
#include <chrono>
#include "Models/Callback.hpp"
namespace BBM
{
//! @brief
class TimerComponent : public WAL::Component
{
public:
//! @brief The callback to call when the timer ring.
WAL::Callback<WAL::Entity &> callback;
//! @brief The ring delay of this timer component.
std::chrono::nanoseconds ringIn;
Component * clone(WAL::Entity &entity) const override;
//! @brief A default constructor
TimerComponent(WAL::Entity &entity, std::chrono::nanoseconds delay);
//! @brief Create a timer with a callback.
TimerComponent(WAL::Entity &entity, std::chrono::nanoseconds delay, const WAL::Callback<WAL::Entity &> &callback);
//! @brief Create a timer with a function to call on ring.
TimerComponent(WAL::Entity &entity, std::chrono::nanoseconds delay, std::function<void (WAL::Entity &)> callback);
//! @brief A timer component is copy constructable
TimerComponent(const TimerComponent &) = default;
//! @brief A default destructor
~TimerComponent() override = default;
//! @brief A component is not assignable.
TimerComponent &operator=(const TimerComponent &) = delete;
};
}