summary refs log tree commit diff stats
path: root/src/components/mappable.h
blob: e92074eb7ab1db70ce4be3fe7a33fd3c9b825bb1 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#ifndef MAPPABLE_H_0B0316FB
#define MAPPABLE_H_0B0316FB

#include <map>
#include <string>
#include <vector>
#include <list>
#include "component.h"
#include "renderer/texture.h"
#include "components/ponderable.h"
#include "entity_manager.h"

class MappableComponent : public Component {
public:

  using id_type = EntityManager::id_type;

  /**
   * Helper type that stores information about map adjacency.
   */
  class Adjacent {
  public:

    enum class Type {
      wall,
      wrap,
      warp,
      reverse
    };

    Adjacent(
      Type type = Type::wall,
      size_t mapId = 0) :
        type(type),
        mapId(mapId)
    {
    }

    Type type;
    size_t mapId;
  };

  /**
   * Helper type that stores information about collision boundaries.
   */
  class Boundary {
  public:

    using Type = PonderableComponent::Collision;

    Boundary(
      double axis,
      double lower,
      double upper,
      Type type) :
        axis(axis),
        lower(lower),
        upper(upper),
        type(type)
    {
    }

    double axis;
    double lower;
    double upper;
    Type type;
  };

  /**
   * Helper types for efficient storage and lookup of collision boundaries.
   */
  using asc_boundaries_type =
    std::multimap<
      double,
      const Boundary,
      std::less<double>>;

  using desc_boundaries_type =
    std::multimap<
      double,
      const Boundary,
      std::greater<double>>;

  /**
   * Constructor for initializing the tileset and font attributes, as they are
   * not default constructible.
   */
  MappableComponent(
    Texture tileset,
    Texture font) :
      tileset(std::move(tileset)),
      font(std::move(font))
  {
  }

  /**
   * The ID of the map in the world definition that this entity represents.
   *
   * @managed_by RealizingSystem
   */
  size_t mapId;

  /**
   * The title of the map, which is displayed at the bottom of the screen.
   */
  std::string title;

  /**
   * The map data.
   *
   * @managed_by RealizingSystem
   */
  std::vector<int> tiles;

  /**
   * These objects describe the behavior of the four edges of the map.
   *
   * @managed_by RealizingSystem
   */
  Adjacent leftAdjacent;
  Adjacent rightAdjacent;
  Adjacent upAdjacent;
  Adjacent downAdjacent;

  /**
   * Collision boundaries, for detecting when a ponderable entity is colliding
   * with the environment.
   *
   * @managed_by MappingSystem
   */
  desc_boundaries_type leftBoundaries;
  asc_boundaries_type rightBoundaries;
  desc_boundaries_type upBoundaries;
  asc_boundaries_type downBoundaries;

  /**
   * The list of entities representing the objects owned by the map.
   *
   * @managed_by RealizingSystem
   */
  std::list<id_type> objects;

  /**
   * The tilesets for the map and the map name.
   *
   * TODO: These probably do not belong here.
   */
  Texture tileset;
  Texture font;
};

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