Working on time and input
This commit is contained in:
10
src/dawn/time/CMakeLists.txt
Normal file
10
src/dawn/time/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
TimeManager.cpp
|
||||
)
|
32
src/dawn/time/TimeManager.cpp
Normal file
32
src/dawn/time/TimeManager.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TimeManager.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TimeManager::TimeManager() {
|
||||
|
||||
}
|
||||
|
||||
void TimeManager::update(float_t delta) {
|
||||
this->delta = delta;
|
||||
this->time += delta;
|
||||
if(!this->isPaused) {
|
||||
this->unpausedTime += delta;
|
||||
}
|
||||
}
|
||||
|
||||
void TimeManager::pause() {
|
||||
if(this->isPaused) return;
|
||||
this->isPaused = true;
|
||||
this->eventTimePaused.invoke();
|
||||
}
|
||||
|
||||
void TimeManager::resume() {
|
||||
if(!this->isPaused) return;
|
||||
this->isPaused = false;
|
||||
this->eventTimeResumed.invoke();
|
||||
}
|
43
src/dawn/time/TimeManager.hpp
Normal file
43
src/dawn/time/TimeManager.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawnlibs.hpp"
|
||||
#include "event/Event.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class TimeManager {
|
||||
public:
|
||||
float_t time = 0.0f;
|
||||
float_t unpausedTime = 0.0f;
|
||||
float_t delta = 0.016f;
|
||||
bool_t isPaused = false;
|
||||
|
||||
Event<> eventTimePaused;
|
||||
Event<> eventTimeResumed;
|
||||
|
||||
/**
|
||||
* Constructor for the Time Manager.
|
||||
*/
|
||||
TimeManager();
|
||||
|
||||
/**
|
||||
* Updates / Ticks the time manager instance.
|
||||
*
|
||||
* @param delta Time in seconds to tick the instance by.
|
||||
*/
|
||||
void update(float_t delta);
|
||||
|
||||
/**
|
||||
* Pauses the game.
|
||||
*/
|
||||
void pause();
|
||||
|
||||
/**
|
||||
* Resumes the game.
|
||||
*/
|
||||
void resume();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user