Base refactor

This commit is contained in:
2023-11-14 09:16:48 -06:00
parent 214082d00f
commit 1817dcaf3a
410 changed files with 749 additions and 20823 deletions

View File

@ -1,10 +0,0 @@
# 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
ITimeManager.cpp
)

View File

@ -1,41 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "ITimeManager.hpp"
using namespace Dawn;
ITimeManager::ITimeManager() {
}
void ITimeManager::update(const float_t delta) {
this->delta = delta;
this->time += delta;
if(!this->isPaused) {
this->unpausedTime += delta;
// Timeout effect provider
std::erase_if(this->timeoutProvider.listeners, [&](auto &listener) {
listener.data -= delta;
if(listener.data > 0) return false;
listener.callback();
return true;
});
}
}
void ITimeManager::pause() {
if(this->isPaused) return;
this->isPaused = true;
this->eventTimePaused.invoke();
}
void ITimeManager::resume() {
if(!this->isPaused) return;
this->isPaused = false;
this->eventTimeResumed.invoke();
}

View File

@ -1,93 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "state/StateProvider.hpp"
#include "state/StateEvent.hpp"
namespace Dawn {
class ITimeManager {
public:
float_t time = 0.0f;
float_t unpausedTime = 0.0f;
float_t delta = 0.016f;
bool_t isPaused = false;
StateProviderSet<float_t> timeoutProvider;
StateEvent<> eventTimePaused;
StateEvent<> eventTimeResumed;
/**
* Constructor for the Time Manager.
*/
ITimeManager();
/**
* Updates / Ticks the time manager instance.
*
* @param delta Time in seconds to tick the instance by.
*/
void update(const float_t delta);
/**
* Pauses the game.
*/
void pause();
/**
* Resumes the game.
*/
void resume();
/**
* Returns the current system timestamp.
*
* @return Current timestamp.
*/
virtual int64_t getTimestamp() = 0;
};
/**
* Use timeout provider method. Invokes your callback after some specified
* time has passed.
*
* @tparam T Your context type (usually SceneItemComponent).
* @param someCallback Callback to be invoked.
* @param timeout Timeout to wait before the method is invoked.
* @param context Context of the component, just use (this).
* @return Method that when invoked will unsubscribe from the timeout.
*/
template<class T>
std::function<void()> useTimeout(
std::function<void()> someCallback,
float_t timeout,
T *context
) {
return context->getGame()->timeManager.timeoutProvider.addEffect(someCallback, timeout, context);
}
/**
* Use interval provider method. Invokes your callback at a consistant and
* common time based on the interval you provide.
*
* @tparam T Your context type (usually SceneItemComponent).
* @param someCallback Callback to be invoked.
* @param timeout Interval to invoke your callback.
* @param context Context of the component, just use (this).
* @return Method that when invoked will unsubscribe from the interval.
*/
template<class T>
std::function<void()> useInterval(
std::function<void()> callback,
float_t interval,
T *context
) {
return context->getGame()->timeManager.intervalProvider.addEffect(
callback, { .interval = interval, .time = 0 }, context
);
}
}