Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
TileProperties.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2021 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_TILE_PROPERTIES_H
22 #define GF_TILE_PROPERTIES_H
23 
24 #include <functional>
25 
26 #include "GraphicsApi.h"
27 #include "Polyline.h"
28 #include "Rect.h"
29 #include "Vector.h"
30 
31 namespace gf {
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 inline namespace v1 {
34 #endif
35 
44  class GF_GRAPHICS_API TileProperties {
45  public:
46  virtual ~TileProperties();
47 
48  virtual RectF computeBounds(Vector2i layerSize, Vector2f tileSize) = 0;
49 
50  virtual RectI computeVisibleArea(const RectF& local, Vector2f tileSize) = 0;
51 
52  virtual RectF computeCellBounds(Vector2i coords, Vector2f tileSize) = 0;
53 
54  virtual Vector2i computeCoordinates(Vector2f position, Vector2f tileSize) = 0;
55 
56  virtual Polyline computePolyline(Vector2i coords, Vector2f tileSize) = 0;
57 
58  virtual void forEachNeighbor(Vector2i coords, Vector2i layerSize, std::function<void(Vector2i)> func) = 0;
59  };
60 
61 
71  template<typename Helper>
73  public:
74  GenericTileProperties(Helper helper)
75  : m_helper(std::move(helper))
76  {
77  }
78 
79  RectF computeBounds(Vector2i layerSize, Vector2f tileSize) override {
80  return m_helper.computeBounds(layerSize, tileSize);
81  }
82 
83  RectI computeVisibleArea(const RectF& local, Vector2f tileSize) override {
84  return m_helper.computeVisibleArea(local, tileSize);
85  }
86 
87  RectF computeCellBounds(Vector2i coords, Vector2f tileSize) override {
88  return m_helper.computeCellBounds(coords, tileSize);
89  }
90 
91  Vector2i computeCoordinates(Vector2f position, Vector2f tileSize) override {
92  return m_helper.computeCoordinates(position, tileSize);
93  }
94 
95  Polyline computePolyline(Vector2i coords, Vector2f tileSize) override {
96  return m_helper.computePolyline(coords, tileSize);
97  }
98 
99  void forEachNeighbor(Vector2i coords, Vector2i layerSize, std::function<void(Vector2i)> func) override {
100  m_helper.forEachNeighbor(coords, layerSize, std::move(func));
101  }
102 
103  private:
104  Helper m_helper;
105  };
106 
107 
108 #ifndef DOXYGEN_SHOULD_SKIP_THIS
109 }
110 #endif
111 }
112 
113 #endif // GF_TILE_PROPERTIES_H
The properties of tiles.
Definition: TileProperties.h:44
A polyline.
Definition: Polyline.h:46
STL namespace.
GenericTileProperties(Helper helper)
Definition: TileProperties.h:74
Polyline computePolyline(Vector2i coords, Vector2f tileSize) override
Definition: TileProperties.h:95
RectF computeBounds(Vector2i layerSize, Vector2f tileSize) override
Definition: TileProperties.h:79
The namespace for gf classes.
Definition: Action.h:35
void forEachNeighbor(Vector2i coords, Vector2i layerSize, std::function< void(Vector2i)> func) override
Definition: TileProperties.h:99
Vector2i computeCoordinates(Vector2f position, Vector2f tileSize) override
Definition: TileProperties.h:91
The generic properties of tiles.
Definition: TileProperties.h:72
RectF computeCellBounds(Vector2i coords, Vector2f tileSize) override
Definition: TileProperties.h:87
RectI computeVisibleArea(const RectF &local, Vector2f tileSize) override
Definition: TileProperties.h:83