summary refs log tree commit diff stats
path: root/src/systems/pondering.h
blob: 273db67c6aab3384f01bacc88e635c2e190da5fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef PONDERING_H_F2530E0E
#define PONDERING_H_F2530E0E

#include "system.h"
#include "components/ponderable.h"
#include "direction.h"
#include "vector.h"

class PonderingSystem : public System {
public:

  PonderingSystem(Game& game) : System(game)
  {
  }

  void tick(double dt);

  void initializeBody(id_type entity, PonderableComponent::Type type);

  /**
   * Initializes a ponderable map object from its prototype data.
   *
   * @requires entity is ponderable
   * @requires entity is a map object
   */
  void initPrototype(id_type prototype);

  /**
   * Unferries an entity if it is a passenger of another entity. Use before
   * moving a ponderable entity outside the PonderingSystem.
   *
   * @requires entity is ponderable
   */
  void unferry(id_type entity);

private:

  struct CollisionResult
  {
    vec2d pos;
    bool stopProcessing = false;
    bool touchedWall = false;
    bool blockedHoriz = false;
    bool blockedVert = false;
    bool adjacentlyWarping = false;
    Direction adjWarpDir;
    size_t adjWarpMapId;
    bool grounded = false;
    id_type groundEntity;
  };

  void tickBody(
    id_type entity,
    double dt,
    const std::set<id_type>& entities);

  CollisionResult moveBody(
    id_type entity,
    vec2d newPos);

  CollisionResult detectCollisions(
    id_type entity,
    vec2d newPos);

  template <typename Param>
  void detectCollisionsInDirection(
    id_type entity,
    CollisionResult& result);

  void processCollision(
    id_type entity,
    id_type collider,
    Direction dir,
    PonderableComponent::Collision type,
    double axis,
    double lower,
    double upper,
    CollisionResult& result);

};

#endif /* end of include guard: PONDERING_H_F2530E0E */