mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-01 01:38:14 +00:00
Adding self updates and removing the renderer
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
//
|
||||
// Created by Zoe Roux on 2021-05-14.
|
||||
//
|
||||
|
||||
#include "Renderer.hpp"
|
||||
|
||||
namespace WAL
|
||||
{
|
||||
void Renderer::render()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
};
|
||||
}
|
||||
@@ -12,4 +12,7 @@ namespace WAL
|
||||
|
||||
void System::onFixedUpdate(Entity &entity)
|
||||
{}
|
||||
|
||||
void System::onSelfUpdate()
|
||||
{}
|
||||
}
|
||||
@@ -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
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user