Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
MiniMapTexture.h
Go to the documentation of this file.
1/* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. 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 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_MINIMAPTEXTURE
19#define INCLUDED_MINIMAPTEXTURE
20
21#include "graphics/Color.h"
23#include "graphics/Texture.h"
24#include "maths/Vector2D.h"
29
30#include <memory>
31#include <string>
32#include <unordered_map>
33#include <vector>
34
35class CLOSTexture;
36class CSimulation2;
37class CTerrain;
39
41{
43public:
46
47 /**
48 * Marks the texture as dirty if it's old enough to redraw it on Render.
49 */
50 void Update(const float deltaRealTime);
51
52 /**
53 * Redraws the texture if it's dirty.
54 */
55 void Render(
56 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
57 CLOSTexture& losTexture, CTerritoryTexture& territoryTexture);
58
59 const CTexturePtr& GetTexture() const { return m_FinalTexture; }
60
61 bool IsFlipped() const { return m_Flipped; }
62
63 /**
64 * @return The maximum height for unit passage in water.
65 */
66 static float GetShallowPassageHeight();
67
68 struct Icon
69 {
73 float halfSize;
74 };
75 // Returns icons for corresponding entities on the minimap texture.
76 const std::vector<Icon>& GetIcons() { return m_Icons; }
77
78private:
79 void CreateTextures(
80 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
81 const CTerrain& terrain);
82 void DestroyTextures();
84 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
85 const CTerrain& terrain);
87 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
88 CLOSTexture& losTexture, CTerritoryTexture& territoryTexture);
90 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
91 const float entityRadius, const double& currentTime);
92 void DrawEntities(
93 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
94 const float entityRadius);
95
97
101 bool m_Flipped = false;
102
103 // minimap texture handles
104 std::unique_ptr<Renderer::Backend::ITexture> m_TerrainTexture;
105
107
108 std::unique_ptr<Renderer::Backend::IFramebuffer>
110
111 // texture data
112 std::unique_ptr<u32[]> m_TerrainData;
113
114 // map size
116
117 // Maximal water height to allow the passage of a unit (for underwater shallows).
119 float m_WaterHeight = 0.0f;
120
123
128
129 bool m_UseInstancing = false;
130 // Vertex data if instancing is supported.
133
135
136 size_t m_EntitiesDrawn = 0;
137
138 double m_PingDuration = 25.0;
140 double m_NextBlinkTime = 0.0;
141 bool m_BlinkState = false;
142
143 std::vector<Icon> m_Icons;
144 // We store the map as a member to avoid redundant reallocations on each
145 // update. We use a grid approach to combine icons by distance.
147 {
148 std::string path;
149 u8 r, g, b;
150 };
152 {
153 size_t operator()(const CellIconKey& key) const;
154 };
156 {
157 bool operator()(const CellIconKey& lhs, const CellIconKey& rhs) const;
158 };
159 struct CellIcon
160 {
161 // TODO: use CVector2DI.
163 float halfSize;
165 };
166 std::unordered_map<CellIconKey, std::vector<CellIcon>, CellIconKeyHash, CellIconKeyEqual> m_IconsCache;
167};
168
169#endif // INCLUDED_MINIMAPTEXTURE
std::shared_ptr< CShaderTechnique > CShaderTechniquePtr
Definition: ShaderTechniquePtr.h:28
Maintains the LOS (fog-of-war / shroud-of-darkness) texture, used for rendering and for the minimap.
Definition: LOSTexture.h:39
Definition: MiniMapTexture.h:41
VertexArray::Attribute m_AttributePos
Definition: MiniMapTexture.h:126
VertexIndexArray m_IndexArray
Definition: MiniMapTexture.h:124
float m_WaterHeight
Definition: MiniMapTexture.h:119
VertexArray::Attribute m_AttributeColor
Definition: MiniMapTexture.h:127
VertexArray m_InstanceVertexArray
Definition: MiniMapTexture.h:131
std::vector< Icon > m_Icons
Definition: MiniMapTexture.h:143
const std::vector< Icon > & GetIcons()
Definition: MiniMapTexture.h:76
CShaderTechniquePtr m_TerritoryTechnique
Definition: MiniMapTexture.h:134
NONCOPYABLE(CMiniMapTexture)
std::unordered_map< CellIconKey, std::vector< CellIcon >, CellIconKeyHash, CellIconKeyEqual > m_IconsCache
Definition: MiniMapTexture.h:166
void Render(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, CLOSTexture &losTexture, CTerritoryTexture &territoryTexture)
Redraws the texture if it's dirty.
Definition: MiniMapTexture.cpp:356
void DrawEntities(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const float entityRadius)
Definition: MiniMapTexture.cpp:802
bool IsFlipped() const
Definition: MiniMapTexture.h:61
Renderer::Backend::IVertexInputLayout * m_EntitiesVertexInputLayout
Definition: MiniMapTexture.h:122
void UpdateAndUploadEntities(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const float entityRadius, const double &currentTime)
Definition: MiniMapTexture.cpp:621
double m_NextBlinkTime
Definition: MiniMapTexture.h:140
ssize_t m_MapSize
Definition: MiniMapTexture.h:115
double m_PingDuration
Definition: MiniMapTexture.h:138
VertexArray::Attribute m_InstanceAttributePosition
Definition: MiniMapTexture.h:132
void RenderFinalTexture(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, CLOSTexture &losTexture, CTerritoryTexture &territoryTexture)
Definition: MiniMapTexture.cpp:495
const CTexturePtr & GetTexture() const
Definition: MiniMapTexture.h:59
void Update(const float deltaRealTime)
Marks the texture as dirty if it's old enough to redraw it on Render.
Definition: MiniMapTexture.cpp:347
bool m_UseInstancing
Definition: MiniMapTexture.h:129
size_t m_EntitiesDrawn
Definition: MiniMapTexture.h:136
std::unique_ptr< Renderer::Backend::IFramebuffer > m_FinalTextureFramebuffer
Definition: MiniMapTexture.h:109
float m_ShallowPassageHeight
Definition: MiniMapTexture.h:118
double m_LastFinalTextureUpdate
Definition: MiniMapTexture.h:100
bool m_BlinkState
Definition: MiniMapTexture.h:141
void RebuildTerrainTexture(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CTerrain &terrain)
Definition: MiniMapTexture.cpp:427
bool m_FinalTextureDirty
Definition: MiniMapTexture.h:99
CMiniMapTexture(Renderer::Backend::IDevice *device, CSimulation2 &simulation)
Definition: MiniMapTexture.cpp:193
std::unique_ptr< u32[]> m_TerrainData
Definition: MiniMapTexture.h:112
void CreateTextures(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CTerrain &terrain)
Definition: MiniMapTexture.cpp:370
void DestroyTextures()
Definition: MiniMapTexture.cpp:420
CSimulation2 & m_Simulation
Definition: MiniMapTexture.h:96
VertexArray m_VertexArray
Definition: MiniMapTexture.h:125
double m_HalfBlinkDuration
Definition: MiniMapTexture.h:139
CTexturePtr m_FinalTexture
Definition: MiniMapTexture.h:106
~CMiniMapTexture()
Definition: MiniMapTexture.cpp:342
bool m_TerrainTextureDirty
Definition: MiniMapTexture.h:98
std::unique_ptr< Renderer::Backend::ITexture > m_TerrainTexture
Definition: MiniMapTexture.h:104
Renderer::Backend::IVertexInputLayout * m_QuadVertexInputLayout
Definition: MiniMapTexture.h:121
static float GetShallowPassageHeight()
Definition: MiniMapTexture.cpp:869
bool m_Flipped
Definition: MiniMapTexture.h:101
Public API for simulation system.
Definition: Simulation2.h:47
Definition: Terrain.h:52
Maintains the territory boundary texture, used for rendering and for the minimap.
Definition: TerritoryTexture.h:31
Definition: Vector2D.h:32
Definition: IDeviceCommandContext.h:42
Definition: IDevice.h:48
IVertexInputLayout stores precompiled list of vertex attributes.
Definition: IShaderProgram.h:74
Definition: VertexArray.h:138
A VertexArray that is specialised to handle 16-bit array indices.
Definition: VertexArray.h:220
std::shared_ptr< CTexture > CTexturePtr
Definition: Texture.h:23
Definition: Color.h:43
Definition: MiniMapTexture.h:156
bool operator()(const CellIconKey &lhs, const CellIconKey &rhs) const
Definition: MiniMapTexture.cpp:183
Definition: MiniMapTexture.h:152
size_t operator()(const CellIconKey &key) const
Definition: MiniMapTexture.cpp:172
Definition: MiniMapTexture.h:147
std::string path
Definition: MiniMapTexture.h:148
u8 r
Definition: MiniMapTexture.h:149
u8 b
Definition: MiniMapTexture.h:149
u8 g
Definition: MiniMapTexture.h:149
Definition: MiniMapTexture.h:160
CVector2D worldPosition
Definition: MiniMapTexture.h:164
u16 gridY
Definition: MiniMapTexture.h:162
float halfSize
Definition: MiniMapTexture.h:163
u16 gridX
Definition: MiniMapTexture.h:162
Definition: MiniMapTexture.h:69
CColor color
Definition: MiniMapTexture.h:71
CTexturePtr texture
Definition: MiniMapTexture.h:70
float halfSize
Definition: MiniMapTexture.h:73
CVector2D worldPosition
Definition: MiniMapTexture.h:72
Definition: VertexArray.h:141
uint8_t u8
Definition: types.h:37
uint16_t u16
Definition: types.h:38
intptr_t ssize_t
Definition: wposix_types.h:82
pthread_key_t key
Definition: wpthread.cpp:140