Symphony Of Empires
map_render.hpp
Go to the documentation of this file.
1 // Symphony of Empires
2 // Copyright (C) 2021, Symphony of Empires contributors
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // client/map_render.hpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #pragma once
26 
27 #include <cstddef>
28 #include <vector>
29 #include <memory>
30 #include <utility>
31 #include <functional>
32 #include <atomic>
33 
34 namespace Eng3D {
35  class Texture;
36  class TextureArray;
37  struct Model;
38  class Camera;
39  namespace OpenGL {
40  class Program;
41  class Framebuffer;
42  }
43 }
44 
45 #include "eng3d/texture.hpp"
46 #include "eng3d/color.hpp"
47 #include "eng3d/shader.hpp"
48 #include "eng3d/map.hpp"
49 
50 class World;
51 class Nation;
52 class GameState;
53 enum class MapView;
54 class Input;
55 class ProvinceColors;
56 class Map;
57 
59 struct MapOptions {
60  Option noise{ "NOISE", true }; // Randomization for more variety
61  Option sdf{ "SDF", false }; // Pretty shadow borders
62  Option lighting{ "LIGHTING", true }; // Lights and reflections
63  Option city_lights{ "CITY_LIGHTS", false }; // Lights and reflections
64  Option parallax{ "PARALLAX", false }; // Parallax (3D) topography
65  Option rivers{ "RIVERS", true }; // Overlaid rivers
66  Option water{ "WATER", true }; // Textured water
67  Option grid{ "GRID", true }; // Square grid for the map
68  Option units{ "UNITS", false }; // 3D units
69  Option buildings{ "BUILDINGS", false }; // 3D buildings
70  Option trees{ "TREES", false }; // 3D hyper realistic trees
71  Option compress{ "COMPRESS", false }; // Use compression on textures
72 
73  std::vector<Option> get_options() {
74  return std::vector<Option>{
76  };
77  }
78 };
79 
80 class MapRender : public Eng3D::BaseMap {
81  void update_visibility();
82  void update_city_lights();
83 
84  GameState& gs;
85  Map& map;
86 
87  // Map textures
88  std::shared_ptr<Eng3D::Texture> river_tex;
89 
90  std::unique_ptr<Eng3D::Texture> tile_sheet;
91  std::unique_ptr<Eng3D::Texture> tile_sheet_nation;
92  std::unique_ptr<Eng3D::Texture> province_opt;
93  std::unique_ptr<Eng3D::Texture> border_sdf;
94 
95  std::unique_ptr<Eng3D::OpenGL::Program> map_shader;
96  std::unique_ptr<Eng3D::OpenGL::Program> sdf_shader;
97  std::unique_ptr<Eng3D::OpenGL::Program> border_gen_shader;
98  std::unique_ptr<Eng3D::OpenGL::Program> output_shader;
99 
100  std::atomic<bool> req_update_vision = true;
101 public:
102  MapRender(GameState& gs, Map& map);
103  ~MapRender() = default;
104  void update_mapmode(std::vector<ProvinceColor>& province_colors);
105  void update_nations(std::vector<ProvinceId>& nations);
107  void draw(const Eng3D::Camera& camera, MapView view_mode);
108  void reload_shaders();
110  void update();
111 
113  void update_border_sdf(Eng3D::Rect update_area, glm::ivec2 window_size);
114  inline uint32_t get_province_opt(const ProvinceId id) {
115  return this->province_opt->buffer[id];
116  }
117 
118  inline ProvinceId get_tile_province_id(glm::ivec2 pos) {
119  return ProvinceId(this->terrain_map->buffer.get()[pos.x + pos.y * this->terrain_map->width] & 0xffff);
120  }
121  inline ProvinceId get_tile_province_id(size_t x, size_t y) {
122  return get_tile_province_id(glm::ivec2(x, y));
123  }
124 };
friend MapRender
Definition: map.hpp:65
Option that is passed to the GLSL transpiler for preprocessing the shaders and programming them on th...
Definition: shader.hpp:56
Definition: map.hpp:89
uint32_t get_province_opt(const ProvinceId id)
Definition: map_render.hpp:114
void request_update_visibility()
Definition: map_render.cpp:381
ProvinceId get_tile_province_id(size_t x, size_t y)
Definition: map_render.hpp:121
void reload_shaders()
Definition: map_render.cpp:132
ProvinceId get_tile_province_id(glm::ivec2 pos)
Definition: map_render.hpp:118
~MapRender()=default
void update_nations(std::vector< ProvinceId > &nations)
Definition: map_render.cpp:357
void update_options(MapOptions options)
Definition: map_render.cpp:164
void update_border_sdf(Eng3D::Rect update_area, glm::ivec2 window_size)
Creates the "waving" border around the continent to give it a 19th century map feel Generate a distan...
Definition: map_render.cpp:251
void update()
Definition: map_render.cpp:426
void draw(const Eng3D::Camera &camera, MapView view_mode)
Definition: map_render.cpp:463
MapOptions options
Definition: map_render.hpp:112
void update_mapmode(std::vector< ProvinceColor > &province_colors)
Definition: map_render.cpp:342
Definition: world.hpp:114
MapView
Definition: map.hpp:63
Eng3D::OpenGL::Option Option
Definition: map_render.hpp:56
OpenGL::Framebuffer Framebuffer
Definition: framebuffer.hpp:41
Option noise
Definition: map_render.hpp:60
Option buildings
Definition: map_render.hpp:69
Option sdf
Definition: map_render.hpp:61
Option lighting
Definition: map_render.hpp:62
std::vector< Option > get_options()
Definition: map_render.hpp:73
Option trees
Definition: map_render.hpp:70
Option rivers
Definition: map_render.hpp:65
Option water
Definition: map_render.hpp:66
Option city_lights
Definition: map_render.hpp:63
Option parallax
Definition: map_render.hpp:64
Option units
Definition: map_render.hpp:68
Option compress
Definition: map_render.hpp:71
Option grid
Definition: map_render.hpp:67