Adding self updates and removing the renderer

This commit is contained in:
Zoe Roux
2021-05-18 10:36:18 +02:00
parent c6012f1be6
commit 02874fdc47
7 changed files with 17 additions and 44 deletions
-2
View File
@@ -13,8 +13,6 @@ add_library(wal
sources/Scene/SceneManager.hpp
sources/Scene/Scene.cpp
sources/Scene/Scene.hpp
sources/Renderer/Renderer.cpp
sources/Renderer/Renderer.hpp
sources/Events/EventManager.cpp
sources/Events/EventManager.hpp
sources/Exception/WalError.cpp
-13
View File
@@ -1,13 +0,0 @@
//
// Created by Zoe Roux on 2021-05-14.
//
#include "Renderer.hpp"
namespace WAL
{
void Renderer::render()
{
}
}
-16
View File
@@ -1,16 +0,0 @@
//
// Created by Zoe Roux on 2021-05-14.
//
#pragma once
namespace WAL
{
//! @brief The renderer class used to display things.
class Renderer
{
public:
void render();
};
}
+3
View File
@@ -12,4 +12,7 @@ namespace WAL
void System::onFixedUpdate(Entity &entity)
{}
void System::onSelfUpdate()
{}
}
+3
View File
@@ -30,6 +30,9 @@ namespace WAL
//! @remark This should be used for Physics, AI and everything that could be imprecise due to float rounding.
//! @param entity The entity to update.
virtual void onFixedUpdate(Entity &entity);
//! @brief A method called after all entities that this system manage has been updated.
virtual void onSelfUpdate();
protected:
//! @brief A system can't be instantiated, it should be derived.
System() = default;
+10 -9
View File
@@ -13,31 +13,31 @@ namespace WAL
SceneManager &Wal::getSceneManager()
{
return this->_scenes;
return this->_sceneManager;
}
void Wal::run()
{
auto lastTick = std::chrono::steady_clock::now();
std::chrono::nanoseconds dtime(0);
std::chrono::nanoseconds fBehind(0);
while (!this->_shouldClose) {
auto now = std::chrono::steady_clock::now();
dtime += now - lastTick;
std::chrono::nanoseconds dtime = now - lastTick;
fBehind += dtime;
lastTick = now;
this->_update(dtime);
while (dtime > Wal::timestep) {
dtime -= Wal::timestep;
while (fBehind > Wal::timestep) {
fBehind -= Wal::timestep;
this->_fixedUpdate();
}
this->_renderer->render();
this->_update(dtime);
}
}
void Wal::_update(std::chrono::nanoseconds dtime)
{
auto &entities = this->_scenes.getCurrent().getEntities();
auto &entities = this->_sceneManager.getCurrent().getEntities();
for (auto &system : this->_systems) {
for (auto &entity : entities) {
@@ -47,12 +47,13 @@ namespace WAL
// TODO handle dependencies.
system->onUpdate(entity, dtime);
}
system->onSelfUpdate();
}
}
void Wal::_fixedUpdate()
{
auto &entities = this->_scenes.getCurrent().getEntities();
auto &entities = this->_sceneManager.getCurrent().getEntities();
for (auto &system : this->_systems) {
for (auto &entity : entities) {
+1 -4
View File
@@ -10,7 +10,6 @@
#include <typeinfo>
#include <Exception/WalError.hpp>
#include "Events/EventManager.hpp"
#include "Renderer/Renderer.hpp"
#include "Scene/SceneManager.hpp"
#include "Entity/Entity.hpp"
#include "System/System.hpp"
@@ -22,13 +21,11 @@ namespace WAL
{
private:
//! @brief The scene manager that allow multiple scene to work together.
SceneManager _scenes;
SceneManager _sceneManager;
//! @brief The event manager
EventManager _eventManager;
//! @brief The list of registered systems
std::vector<std::unique_ptr<System>> _systems = {};
//! @brief The renderer used to draw entities
std::unique_ptr<Renderer> _renderer;
//! @brief True if the engine should close after the end of the current tick.
bool _shouldClose = false;