About to add evet

This commit is contained in:
2023-11-17 13:21:56 -06:00
parent 5901b9e07c
commit 41c26dd103
7 changed files with 45 additions and 39 deletions

View File

@ -1,30 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Home</title>
<style type="text/css">
body {
background-color: #000000;
color: #ffffff;
}
canvas {
border: 1px solid red;
}
</style>
</head>
<body>
<h1>Hello Emscripten</h1>
<canvas id="tutorial" width="300" height="300"></canvas>
<script type="text/javascript">
window.Module = {};
window.Module.canvas = document.getElementById('tutorial');
</script>
<script src="./build/src/dawnhelloworld/HelloWorld.js"></script>
</body>
</html>

20
src/dawn/event/Event.hpp Normal file
View File

@ -0,0 +1,20 @@
// 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 {
template<typename T>
class Event {
private:
public:
Event() {}
virtual ~Event() {}
virtual void operator()(T &t) = 0;
}
}

View File

@ -21,7 +21,8 @@ void Game::init() {
nextFrameScene = std::make_shared<Scene>(shared_from_this(), initialScene);
}
void Game::update(float_t delta) {
void Game::update() {
timeManager.update();
renderHost.update(shared_from_this());
if(nextFrameScene) {

View File

@ -7,11 +7,6 @@
using namespace Dawn;
void ITimeManager::tick(float_t delta) {
this->delta = delta;
this->time += delta;
}
ITimeManager::~ITimeManager() {
}

View File

@ -14,10 +14,8 @@ namespace Dawn {
/**
* Ticks / updates the time management system.
*
* @param delta Time delta in seconds.
*/
void tick(float_t delta);
virtual void update() = 0;
/**
* Returns the real world time epoch.

View File

@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT
#include "TimeManager.hpp"
#include <GLFW/glfw3.h>
#include <sys/time.h>
#include <chrono>
#include <ctime>
@ -11,6 +12,19 @@
using namespace Dawn;
TimeManager::TimeManager() {
lastUpdate = glfwGetTime();
}
void TimeManager::update() {
double_t newTime = glfwGetTime();
delta = (
(float_t)(newTime - lastUpdate)
);
time += delta;
lastUpdate = newTime;
}
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;

View File

@ -8,7 +8,15 @@
namespace Dawn {
class TimeManager : public ITimeManager {
private:
double_t lastUpdate = 0;
public:
/**
* Constructs and initializes the TimeManager.
*/
TimeManager();
void update() override;
int64_t getRealTime() override;
};
}