Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
TileMap.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Graphics module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_TILEMAP_HPP
8 #define NAZARA_TILEMAP_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Graphics/InstancedRenderable.hpp>
12 #include <Nazara/Graphics/Material.hpp>
13 #include <set>
14 
15 namespace Nz
16 {
17  class TileMap;
18 
19  using TileMapConstRef = ObjectRef<const TileMap>;
20  using TileMapLibrary = ObjectLibrary<TileMap>;
21  using TileMapRef = ObjectRef<TileMap>;
22 
23  class NAZARA_GRAPHICS_API TileMap : public InstancedRenderable
24  {
25  friend TileMapLibrary;
26  friend class Graphics;
27 
28  public:
29  struct Tile;
30 
31  inline TileMap(const Nz::Vector2ui& mapSize, const Nz::Vector2f& tileSize, std::size_t materialCount = 1);
32  TileMap(const TileMap& TileMap) = default;
33  TileMap(TileMap&&) = delete;
34  ~TileMap() = default;
35 
36  void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
37 
38  inline void DisableTile(const Vector2ui& tilePos);
39  inline void DisableTiles();
40  inline void DisableTiles(const Vector2ui* tilesPos, std::size_t tileCount);
41 
42  inline void EnableIsometricMode(bool isometric);
43 
44  inline void EnableTile(const Vector2ui& tilePos, const Rectf& coords, const Color& color = Color::White, std::size_t materialIndex = 0U);
45  inline void EnableTile(const Vector2ui& tilePos, const Rectui& rect, const Color& color = Color::White, std::size_t materialIndex = 0U);
46  inline void EnableTiles(const Rectf& coords, const Color& color = Color::White, std::size_t materialIndex = 0U);
47  inline void EnableTiles(const Rectui& rect, const Color& color = Color::White, std::size_t materialIndex = 0U);
48  inline void EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectf& coords, const Color& color = Color::White, std::size_t materialIndex = 0U);
49  inline void EnableTiles(const Vector2ui* tilesPos, std::size_t tileCount, const Rectui& rect, const Color& color = Color::White, std::size_t materialIndex = 0U);
50 
51  inline const Vector2ui& GetMapSize() const;
52  inline Vector2f GetSize() const;
53  inline const Tile& GetTile(const Vector2ui& tilePos) const;
54  inline const Vector2f& GetTileSize() const;
55 
56  inline bool IsIsometricModeEnabled() const;
57 
59 
60  inline TileMap& operator=(const TileMap& TileMap);
61  TileMap& operator=(TileMap&& TileMap) = delete;
62 
63  template<typename... Args> static TileMapRef New(Args&&... args);
64 
65  struct Tile
66  {
67  std::size_t layerIndex = 0U;
68  Color color = Color::White;
69  Rectf textureCoords = Rectf::Zero();
70  bool enabled = false;
71  };
72 
73  private:
74  void MakeBoundingVolume() const override;
75  void UpdateData(InstanceData* instanceData) const override;
76 
77  static bool Initialize();
78  static void Uninitialize();
79 
80  struct Layer
81  {
82  std::set<std::size_t> tiles;
83  };
84 
85  std::vector<Tile> m_tiles;
86  std::vector<Layer> m_layers;
87  Vector2ui m_mapSize;
88  Vector2f m_tileSize;
89  bool m_isometricModeEnabled;
90 
91  static TileMapLibrary::LibraryMap s_library;
92  };
93 }
94 
95 #include <Nazara/Graphics/TileMap.inl>
96 
97 #endif // NAZARA_TILEMAP_HPP
Core class that represents a color.
Definition: Color.hpp:18
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Graphics class that represents the module initializer of Graphics.
Definition: Graphics.hpp:15
Graphics class that represents the rendering queue for our scene.
Definition: AbstractRenderQueue.hpp:26
void SetMaterial(std::size_t matIndex, MaterialRef material)
Changes the material used at the specified index by another one.
Definition: InstancedRenderable.inl:216
Graphics class that represents an instancer renderable.
Definition: InstancedRenderable.hpp:30
Core class that represents a reference to an object.
Definition: ObjectRef.hpp:18
static Rect Zero()
Shorthand for the rectangle (0, 0, 0, 0)
Definition: Rect.inl:795
Graphics class that represent several tiles of the same size assembled into a grid This class is far ...
Definition: TileMap.hpp:23