Bomberman
System.hpp
Go to the documentation of this file.
1 //
2 // Created by Zoe Roux on 2021-05-14.
3 //
4 
5 #pragma once
6 
7 #include <chrono>
8 #include <vector>
9 #include <typeinfo>
10 #include <typeindex>
11 #include "Entity/Entity.hpp"
12 #include "Wal.hpp"
13 #include "View/View.hpp"
14 #include "ISystem.hpp"
15 #include <iostream>
16 
17 namespace WAL
18 {
21  template<typename ...Dependencies>
22  class System : public ISystem
23  {
24  public:
26  ~System() override = default;
28  System(System &&) noexcept = default;
29 
31  View<Dependencies...> &getView() override
32  {
33  return this->_wal.getScene()->template view<Dependencies...>();
34  }
35 
39  virtual void onUpdate(ViewEntity<Dependencies...> &entity, std::chrono::nanoseconds dtime) {}
40 
44  virtual void onFixedUpdate(ViewEntity<Dependencies...> &entity) {}
45 
48  virtual void onSelfUpdate(std::chrono::nanoseconds dtime) {}
49 
50 
53  void update(std::chrono::nanoseconds dtime) final
54  {
55  for (auto &entity : this->getView())
56  this->onUpdate(entity, dtime);
57  this->onSelfUpdate(dtime);
58  }
59 
62  void fixedUpdate() final
63  {
64  for (auto &entity : this->getView())
65  this->onFixedUpdate(entity);
66  }
67  protected:
70 
72  explicit System(Wal &wal)
73  : _wal(wal)
74  {}
76  System(const System &) = default;
78  System &operator=(const System &) = default;
79  };
80 } // namespace WAL
WAL::ViewEntity
Definition: View.hpp:19
WAL
Definition: Component.cpp:7
WAL::Wal::getScene
std::shared_ptr< Scene > getScene() const
Retrieve the current scene.
Definition: Wal.hpp:94
View.hpp
WAL::System::onSelfUpdate
virtual void onSelfUpdate(std::chrono::nanoseconds dtime)
A method called after all entities that this system manage has been updated.
Definition: System.hpp:48
WAL::System::System
System(Wal &wal)
A system can't be instantiated, it should be derived.
Definition: System.hpp:72
WAL::System::System
System(System &&) noexcept=default
A system can be moved.
WAL::System::getView
View< Dependencies... > & getView() override
Get a view of all entities containing every dependencies of this system.
Definition: System.hpp:31
WAL::ISystem
A base class that represent a system.
Definition: ISystem.hpp:15
WAL::Wal
The main WAL class, it is used to setup and run the ECS.
Definition: Wal.hpp:27
Entity.hpp
WAL::System::_wal
Wal & _wal
A reference to the ECS.
Definition: System.hpp:69
WAL::System::onFixedUpdate
virtual void onFixedUpdate(ViewEntity< Dependencies... > &entity)
An alternative of onUpdate that is called every 8ms (120 times per seconds). If the system slow down,...
Definition: System.hpp:44
WAL::System::~System
~System() override=default
A virtual, default, destructor.
WAL::System::fixedUpdate
void fixedUpdate() final
An alternative of update that is called every 8ms (120 times per seconds). If the system slow down,...
Definition: System.hpp:62
WAL::System::update
void update(std::chrono::nanoseconds dtime) final
Update the whole system (every entities that this system is responsible can be updated.
Definition: System.hpp:53
WAL::View
A view allowing one to easily access entities containing a set list of component. A view is always up...
Definition: View.hpp:133
ISystem.hpp
WAL::System
A base system of WAL.
Definition: System.hpp:22
Wal.hpp
WAL::System::onUpdate
virtual void onUpdate(ViewEntity< Dependencies... > &entity, std::chrono::nanoseconds dtime)
Update the corresponding component of the given entity.
Definition: System.hpp:39
WAL::System::operator=
System & operator=(const System &)=default
A system can't be instantiated, it should be derived.