supertux
collision_movement_manager.hpp
1 // SuperTux
2 // Copyright (C) 2020 Maxim Bernard <mbernard2@videotron.ca>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_COLLISION_COLLISION_MOVEMENT_MANAGER_HPP
18 #define HEADER_SUPERTUX_COLLISION_COLLISION_MOVEMENT_MANAGER_HPP
19 
20 #include "collision/collision_object.hpp"
21 #include "object/tilemap.hpp"
22 #include "math/vector.hpp"
23 
24 #include <unordered_map>
25 
33 {
34 private:
35 
37  class TargetMovementData final
38  {
39  public:
40  TargetMovementData() :
41  m_moving_objects(),
42  m_moving_tilemaps()
43  {}
44 
45  void register_movement(CollisionObject& moving_object, const Vector& movement);
46  void register_movement(TileMap& moving_tilemap, const Vector& movement);
47 
48  const std::unordered_map<CollisionObject*, Vector>& get_objects_map() const
49  {
50  return m_moving_objects;
51  }
52 
53  const std::unordered_map<TileMap*, Vector>& get_tilemaps_map() const
54  {
55  return m_moving_tilemaps;
56  }
57 
58  private:
59  std::unordered_map<CollisionObject*, Vector> m_moving_objects;
60  std::unordered_map<TileMap*, Vector> m_moving_tilemaps;
61  };
62 
63 public:
64 
66  m_movements_per_target()
67  {}
68 
69  void register_movement(CollisionObject& moving_object, CollisionObject& target_object, const Vector& movement);
70 
71  void register_movement(TileMap& moving_tilemap, CollisionObject& target_object, const Vector& movement);
72 
78 
79 
80 private:
81 
84  std::unordered_map<CollisionObject*, TargetMovementData> m_movements_per_target;
85 
86 
87 private:
90 };
91 
92 #endif
93 
94 /* EOF */
This class takes care of moving objects that have collided on top of other moving objects or on top o...
Definition: collision_movement_manager.hpp:32
void apply_all_ground_movement()
Moves all target objects according to their colliding object or tilemap whose movement vector has the...
Definition: collision_movement_manager.cpp:39
Definition: collision_object.hpp:33
This class is responsible for managing an array of tiles.
Definition: tilemap.hpp:49