Peoplemon  0.1.0
Peoplemon 3 game source documentation
Position.hpp
Go to the documentation of this file.
1 #ifndef CORE_SYSTEMS_POSITION_HPP
2 #define CORE_SYSTEMS_POSITION_HPP
3 
4 #include <BLIB/Containers/Grid.hpp>
5 #include <BLIB/ECS.hpp>
6 #include <BLIB/Engine/System.hpp>
7 #include <BLIB/Events.hpp>
8 #include <BLIB/Tilemap/Position.hpp>
10 #include <Core/Events/Maps.hpp>
11 #include <unordered_map>
12 
13 namespace core
14 {
15 namespace system
16 {
17 class Systems;
18 
26 class Position
27 : public bl::engine::System
28 , public bl::event::Listener<event::EntityMoved, bl::ecs::event::ComponentAdded<bl::tmap::Position>,
29  bl::ecs::event::ComponentRemoved<bl::tmap::Position>,
30  event::MapSwitch> {
31 public:
37  Position(Systems& owner);
38 
43  virtual ~Position() = default;
44 
51  bl::ecs::Entity getEntity(const bl::tmap::Position& pos) const;
52 
59  bool spaceFree(const bl::tmap::Position& position) const;
60 
70  bl::ecs::Entity search(const bl::tmap::Position& start, bl::tmap::Direction dir,
71  unsigned int range);
72 
77  void editorPushLevel();
78 
83  void editorPopLevel();
84 
85 private:
86  Systems& owner;
87  std::vector<bl::ctr::Vector2D<bl::ecs::Entity>> entityMap;
88 
89  virtual void observe(const event::EntityMoved& event) override;
90  virtual void observe(const bl::ecs::event::ComponentAdded<bl::tmap::Position>& event) override;
91  virtual void observe(
92  const bl::ecs::event::ComponentRemoved<bl::tmap::Position>& event) override;
93  virtual void observe(const event::MapSwitch& event) override;
94 
95  virtual void init(bl::engine::Engine&) override;
96  virtual void update(std::mutex&, float, float, float, float) override;
97 
98  bl::ecs::Entity& get(const bl::tmap::Position& pos);
99 };
100 
101 } // namespace system
102 } // namespace core
103 
104 #endif
Core classes and functionality for both the editor and game.
Fired after an entity begins moving from one position to another.
Definition: EntityMoved.hpp:18
Fired right before a map is entered. Use this event for initializing data structures that depend on m...
Definition: Maps.hpp:22
The primary entity positioning system. Handles determining which entities get updated as well as trac...
Definition: Position.hpp:30
Position(Systems &owner)
Construct the Position system.
Definition: Position.cpp:13
virtual ~Position()=default
Destroy the Position system.
bl::ecs::Entity search(const bl::tmap::Position &start, bl::tmap::Direction dir, unsigned int range)
Searches for an entity from the starting position in the given direction for the given number of spac...
Definition: Position.cpp:39
void editorPushLevel()
Called by the editor when a level is added.
Definition: Position.cpp:111
bl::ecs::Entity getEntity(const bl::tmap::Position &pos) const
Returns the entity at the given position or InvalidEntity if not found.
Definition: Position.cpp:96
void editorPopLevel()
Called by the editor when a level is removed.
Definition: Position.cpp:116
bool spaceFree(const bl::tmap::Position &position) const
Returns whether or not a tile is currently occupied.
Definition: Position.cpp:28
Owns all primary systems and a reference to the engine.
Definition: Systems.hpp:47