Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
tile_map_view.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include <aegis2d/render/export.hpp>
9
10#include <cstddef>
11#include <cstdint>
12#include <vector>
13
14namespace aegis2d::render {
15
34class AEGIS2D_RENDER_EXPORT TileMapView {
35public:
40 TileMapView(const TileMap& map, TextureManager& textures);
41
46 void draw(IRenderer& renderer, std::int32_t first_layer = 0) const;
47
53 void draw_layer(IRenderer& renderer, std::size_t layer, std::int32_t sprite_layer) const;
54
55private:
56 struct Tile {
57 TextureId texture = no_texture;
58 Rect source{};
59 Vec2 size{};
60 };
61
62 const TileMap* map_;
63 // By global id, flip bits removed; no_texture for ids no tileset has.
64 std::vector<Tile> tiles_;
65 // Cells around the view drawn too, for tiles larger than the cells.
66 int reach_columns_ = 0;
67 int reach_rows_ = 0;
68};
69
70} // namespace aegis2d::render
What the game draws with, whatever the graphics API behind it.
Definition renderer.hpp:81
The game's textures, each loaded once and found by a name such as "player".
Definition texture_manager.hpp:33
A TileMap ready to draw: the textures of its tilesets and where each tile is in them.
Definition tile_map_view.hpp:34
void draw(IRenderer &renderer, std::int32_t first_layer=0) const
Draws every visible tile layer, from the bottom one.
void draw_layer(IRenderer &renderer, std::size_t layer, std::int32_t sprite_layer) const
Draws one layer, if it is a visible tile layer.
TileMapView(const TileMap &map, TextureManager &textures)
Loads the image of each tileset as a texture, named by its path.
OpenGL renderer: sprites, text and camera (client only).
Definition bitmap_font.hpp:16
aegis2d::Vec2 Vec2
2D vector of floats, in logical pixels: the engine-wide aegis2d::Vec2.
Definition renderer.hpp:17
constexpr TextureId no_texture
Texture identifier meaning "no texture": the sprite is a plain tinted rectangle.
Definition renderer.hpp:35
std::uint32_t TextureId
Identifier of a texture loaded by the resource manager.
Definition renderer.hpp:32
Backend-independent renderer interface and the sprite it draws.
Axis-aligned rectangle.
Definition renderer.hpp:20
Orthogonal, finite map made in Tiled, saved as JSON.
Definition tile_map.hpp:131
Textures loaded once and found by name.
Tiled maps (.tmj) and their tilesets (embedded or .tsj), loaded from JSON.