]> git.localhorst.tv Git - blobs.git/blob - src/world/Planet.hpp
figure out our creature's metabolism
[blobs.git] / src / world / Planet.hpp
1 #ifndef BLOBS_WORLD_PLANET_HPP_
2 #define BLOBS_WORLD_PLANET_HPP_
3
4 #include "Body.hpp"
5
6 #include "Set.hpp"
7 #include "Tile.hpp"
8 #include "../graphics/glm.hpp"
9 #include "../graphics/SimpleVAO.hpp"
10
11 #include <cassert>
12 #include <vector>
13 #include <GL/glew.h>
14
15
16 namespace blobs {
17 namespace world {
18
19 class TileType;
20
21 /// A planet has six surfaces, numbered 0 to 5, each filled with
22 /// sidelength² tiles.
23 class Planet
24 : public Body {
25
26 public:
27         explicit Planet(int sidelength);
28         ~Planet();
29
30         Planet(const Planet &) = delete;
31         Planet &operator =(const Planet &) = delete;
32
33         Planet(Planet &&) = delete;
34         Planet &operator =(Planet &&) = delete;
35
36 public:
37         /// Get the tile at given surface and coordinates.
38         Tile &TileAt(int surface, int x, int y) {
39                 return tiles[IndexOf(surface, x, y)];
40         }
41         const Tile &TileAt(int surface, int x, int y) const {
42                 return tiles[IndexOf(surface, x, y)];
43         }
44
45         /// Convert coordinates into a tile index.
46         int IndexOf(int surface, int x, int y) const {
47                 assert(0 <= surface && surface <= 5);
48                 assert(0 <= x && x <= sidelength);
49                 assert(0 <= y && y <= sidelength);
50                 return surface * TilesPerSurface() + y * SideLength() + x;
51         }
52         /// The length of the side of each surface.
53         int SideLength() const {
54                 return sidelength;
55         }
56         /// The number of tiles of one surface.
57         int TilesPerSurface() const {
58                 return SideLength() * SideLength();
59         }
60         /// Total number of tiles of all surfaces combined.
61         int TilesTotal() const {
62                 return 6 * TilesPerSurface();
63         }
64
65         glm::dvec3 TileCenter(int surface, int x, int y) const noexcept;
66
67         void Atmosphere(int a) noexcept { atmosphere = a; }
68         int Atmosphere() const noexcept { return atmosphere; }
69         bool HasAtmosphere() const noexcept { return atmosphere >= 0; }
70
71         void BuildVAO(const Set<TileType> &);
72         void Draw(app::Assets &, graphics::Viewport &) override;
73
74 private:
75         int sidelength;
76         std::vector<Tile> tiles;
77
78         int atmosphere;
79
80         struct Attributes {
81                 glm::vec3 position;
82                 glm::vec3 tex_coord;
83         };
84         graphics::SimpleVAO<Attributes, unsigned int> vao;
85
86 };
87
88 void GenerateEarthlike(const Set<TileType> &, Planet &) noexcept;
89 void GenerateTest(const Set<TileType> &, Planet &) noexcept;
90
91 }
92 }
93
94 #endif