Time, Mr. Freeman?
This commit is contained in:
@ -31,7 +31,7 @@ add_subdirectory(game)
|
|||||||
# add_subdirectory(save)
|
# add_subdirectory(save)
|
||||||
add_subdirectory(scene)
|
add_subdirectory(scene)
|
||||||
# add_subdirectory(state)
|
# add_subdirectory(state)
|
||||||
# add_subdirectory(time)
|
add_subdirectory(time)
|
||||||
add_subdirectory(util)
|
add_subdirectory(util)
|
||||||
|
|
||||||
# Definitions
|
# Definitions
|
||||||
|
@ -21,7 +21,7 @@ void Game::init() {
|
|||||||
nextFrameScene = std::make_shared<Scene>(shared_from_this(), initialScene);
|
nextFrameScene = std::make_shared<Scene>(shared_from_this(), initialScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::update() {
|
void Game::update(float_t delta) {
|
||||||
renderHost.update(shared_from_this());
|
renderHost.update(shared_from_this());
|
||||||
|
|
||||||
if(nextFrameScene) {
|
if(nextFrameScene) {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "dawnlibs.hpp"
|
#include "dawnlibs.hpp"
|
||||||
#include "display/RenderHost.hpp"
|
#include "display/RenderHost.hpp"
|
||||||
#include "input/InputManager.hpp"
|
#include "input/InputManager.hpp"
|
||||||
|
#include "time/TimeManager.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class Scene;
|
class Scene;
|
||||||
@ -19,6 +20,7 @@ namespace Dawn {
|
|||||||
public:
|
public:
|
||||||
RenderHost renderHost;
|
RenderHost renderHost;
|
||||||
InputManager inputManager;
|
InputManager inputManager;
|
||||||
|
TimeManager timeManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the game instance, does not initialize anything.
|
* Constructs the game instance, does not initialize anything.
|
||||||
|
9
src/dawn/time/CMakeLists.txt
Normal file
9
src/dawn/time/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Copyright (c) 2022 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
|
PRIVATE
|
||||||
|
ITimeManager.cpp
|
||||||
|
)
|
17
src/dawn/time/ITimeManager.cpp
Normal file
17
src/dawn/time/ITimeManager.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "ITimeManager.hpp"
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
void ITimeManager::tick(float_t delta) {
|
||||||
|
this->delta = delta;
|
||||||
|
this->time += delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
ITimeManager::~ITimeManager() {
|
||||||
|
|
||||||
|
}
|
34
src/dawn/time/ITimeManager.hpp
Normal file
34
src/dawn/time/ITimeManager.hpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dawnlibs.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class ITimeManager {
|
||||||
|
public:
|
||||||
|
float_t delta = 0.016f;
|
||||||
|
float_t time = 0.016f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ticks / updates the time management system.
|
||||||
|
*
|
||||||
|
* @param delta Time delta in seconds.
|
||||||
|
*/
|
||||||
|
void tick(float_t delta);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the real world time epoch.
|
||||||
|
*
|
||||||
|
* @return Epoch time in milliseconds.
|
||||||
|
*/
|
||||||
|
virtual int64_t getRealTime() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans up the time manager.
|
||||||
|
*/
|
||||||
|
virtual ~ITimeManager();
|
||||||
|
};
|
||||||
|
}
|
@ -25,4 +25,4 @@ target_include_directories(${DAWN_TARGET_NAME}
|
|||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(display)
|
add_subdirectory(display)
|
||||||
add_subdirectory(input)
|
add_subdirectory(input)
|
||||||
# add_subdirectory(time)
|
add_subdirectory(time)
|
9
src/dawnglfw/time/CMakeLists.txt
Normal file
9
src/dawnglfw/time/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Copyright (c) 2022 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
|
PRIVATE
|
||||||
|
TimeManager.cpp
|
||||||
|
)
|
17
src/dawnglfw/time/TimeManager.cpp
Normal file
17
src/dawnglfw/time/TimeManager.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#include "TimeManager.hpp"
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <chrono>
|
||||||
|
#include <ctime>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace Dawn;
|
||||||
|
|
||||||
|
int64_t TimeManager::getRealTime() {
|
||||||
|
auto millisec_since_epoch = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()) .count();
|
||||||
|
return millisec_since_epoch;
|
||||||
|
}
|
14
src/dawnglfw/time/TimeManager.hpp
Normal file
14
src/dawnglfw/time/TimeManager.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (c) 2023 Dominic Masters
|
||||||
|
//
|
||||||
|
// This software is released under the MIT License.
|
||||||
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "time/ITimeManager.hpp"
|
||||||
|
|
||||||
|
namespace Dawn {
|
||||||
|
class TimeManager : public ITimeManager {
|
||||||
|
public:
|
||||||
|
int64_t getRealTime() override;
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user