Index: source/graphics/GameView.h =================================================================== --- source/graphics/GameView.h +++ source/graphics/GameView.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -23,10 +23,10 @@ #include "lib/input.h" // InReaction - can't forward-declare enum -class CGame; -class CObjectManager; class CCamera; class CCinemaManager; +class CGame; +class CObjectManager; class CVector3D; struct SViewPort; @@ -86,6 +86,7 @@ void EnumerateObjects(const CFrustum& frustum, SceneCollector* c) override; CLOSTexture& GetLOSTexture() override; CTerritoryTexture& GetTerritoryTexture() override; + CMiniMapTexture& GetMiniMapTexture() override; private: // Unloads all graphics resources loaded by RegisterInit. Index: source/graphics/GameView.cpp =================================================================== --- source/graphics/GameView.cpp +++ source/graphics/GameView.cpp @@ -25,6 +25,7 @@ #include "graphics/HFTracer.h" #include "graphics/LOSTexture.h" #include "graphics/LightEnv.h" +#include "graphics/MiniMapTexture.h" #include "graphics/Model.h" #include "graphics/ObjectManager.h" #include "graphics/Patch.h" @@ -71,6 +72,7 @@ ObjectManager(MeshManager, SkeletonAnimManager, *game->GetSimulation2()), LOSTexture(*game->GetSimulation2()), TerritoryTexture(*game->GetSimulation2()), + MiniMapTexture(*game->GetSimulation2()), ViewCamera(), CullCamera(), LockCullCamera(false), @@ -86,6 +88,7 @@ CObjectManager ObjectManager; CLOSTexture LOSTexture; CTerritoryTexture TerritoryTexture; + CMiniMapTexture MiniMapTexture; /** * this camera controls the eye position when rendering @@ -192,7 +195,7 @@ CCinemaManager* CGameView::GetCinema() { return &m->CinemaManager; -}; +} CLOSTexture& CGameView::GetLOSTexture() { @@ -204,6 +207,11 @@ return m->TerritoryTexture; } +CMiniMapTexture& CGameView::GetMiniMapTexture() +{ + return m->MiniMapTexture; +} + int CGameView::Initialize() { m->CameraController->LoadConfig(); @@ -301,6 +309,8 @@ void CGameView::Update(const float deltaRealTime) { + m->MiniMapTexture.Update(deltaRealTime); + // If camera movement is being handled by the touch-input system, // then we should stop to avoid conflicting with it if (g_TouchInput.IsEnabled()) Index: source/graphics/MiniMapTexture.h =================================================================== --- source/graphics/MiniMapTexture.h +++ source/graphics/MiniMapTexture.h @@ -0,0 +1,82 @@ +/* Copyright (C) 2021 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_MINIMAPTEXTURE +#define INCLUDED_MINIMAPTEXTURE + +#include "graphics/ShaderTechniquePtr.h" +#include "lib/ogl.h" + +class CSimulation2; +class CTerrain; + +class CMiniMapTexture +{ + NONCOPYABLE(CMiniMapTexture); +public: + CMiniMapTexture(CSimulation2& simulation); + ~CMiniMapTexture(); + + /** + * Marks the texture as dirty if it's old enough to redraw it on Render. + */ + void Update(const float deltaRealTime); + + /** + * Redraws the texture if it's dirty. + */ + void Render(); + + GLuint GetTerrainTexture() const { return m_TerrainTexture; } + + GLsizei GetTerrainTextureSize() const { return m_TextureSize; } + + /** + * @return The maximum height for unit passage in water. + */ + static float GetShallowPassageHeight(); + +private: + void CreateTextures(const CTerrain* terrain); + void DestroyTextures(); + void RebuildTerrainTexture(const CTerrain* terrain); + + CSimulation2& m_Simulation; + + bool m_Dirty = true; + + // minimap texture handles + GLuint m_TerrainTexture; + + // texture data + u32* m_TerrainData; + + // map size + ssize_t m_MapSize; + + // texture size + GLsizei m_TextureSize; + + // 1.f if map is circular or 1.414f if square (to shrink it inside the circle) + float m_MapScale; + + // Maximal water height to allow the passage of a unit (for underwater shallows). + float m_ShallowPassageHeight = 0.0f; + float m_WaterHeight = 0.0f; +}; + +#endif // INCLUDED_MINIMAPTEXTURE \ No newline at end of file Index: source/graphics/MiniMapTexture.cpp =================================================================== --- source/graphics/MiniMapTexture.cpp +++ source/graphics/MiniMapTexture.cpp @@ -0,0 +1,209 @@ +/* Copyright (C) 2021 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "MiniMapTexture.h" + +#include "graphics/MiniPatch.h" +#include "graphics/ShaderManager.h" +#include "graphics/Terrain.h" +#include "graphics/TerrainTextureEntry.h" +#include "graphics/TerrainTextureManager.h" +#include "graphics/TerritoryTexture.h" +#include "lib/bits.h" +#include "ps/CStrInternStatic.h" +#include "ps/Filesystem.h" +#include "ps/Game.h" +#include "ps/World.h" +#include "ps/XML/Xeromyces.h" +#include "renderer/Renderer.h" +#include "renderer/RenderingOptions.h" +#include "renderer/WaterManager.h" +#include "scriptinterface/Object.h" +#include "simulation2/Simulation2.h" +#include "simulation2/components/ICmpMinimap.h" +#include "simulation2/components/ICmpRangeManager.h" +#include "simulation2/system/ParamNode.h" + +namespace +{ + +unsigned int ScaleColor(unsigned int color, float x) +{ + unsigned int r = unsigned(float(color & 0xff) * x); + unsigned int g = unsigned(float((color>>8) & 0xff) * x); + unsigned int b = unsigned(float((color>>16) & 0xff) * x); + return (0xff000000 | b | g<<8 | r<<16); +} + +} // anonymous namespace + +CMiniMapTexture::CMiniMapTexture(CSimulation2& simulation) + : m_Simulation(simulation) +{ + // Register Relax NG validator. + CXeromyces::AddValidator(g_VFS, "pathfinder", "simulation/data/pathfinder.rng"); + + m_ShallowPassageHeight = GetShallowPassageHeight(); +} + +CMiniMapTexture::~CMiniMapTexture() +{ + DestroyTextures(); +} + +void CMiniMapTexture::Update(const float UNUSED(deltaRealTime)) +{ + if (m_WaterHeight != g_Renderer.GetWaterManager()->m_WaterHeight) + m_Dirty = true; +} + +void CMiniMapTexture::Render() +{ + if (!m_Dirty) + return; + + const CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); + if (!terrain) + return; + + CmpPtr cmpRangeManager(m_Simulation, SYSTEM_ENTITY); + ENSURE(cmpRangeManager); + + m_MapSize = terrain->GetVerticesPerSide(); + m_TextureSize = (GLsizei)round_up_to_pow2((size_t)m_MapSize); + m_MapScale = cmpRangeManager->GetLosCircular() ? 1.f : 1.414f; + + if (!m_TerrainTexture) + CreateTextures(terrain); + + RebuildTerrainTexture(terrain); +} + +void CMiniMapTexture::CreateTextures(const CTerrain* terrain) +{ + DestroyTextures(); + + // Create terrain texture + glGenTextures(1, &m_TerrainTexture); + g_Renderer.BindTexture(0, m_TerrainTexture); + + // Initialise texture with solid black, for the areas we don't + // overwrite with glTexSubImage2D later + u32* texData = new u32[m_TextureSize * m_TextureSize]; + for (ssize_t i = 0; i < m_TextureSize * m_TextureSize; ++i) + texData[i] = 0xFF000000; + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_TextureSize, m_TextureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData); + delete[] texData; + + m_TerrainData = new u32[(m_MapSize - 1) * (m_MapSize - 1)]; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + // Rebuild and upload both of them + RebuildTerrainTexture(terrain); +} + +void CMiniMapTexture::DestroyTextures() +{ + if (m_TerrainTexture) + { + glDeleteTextures(1, &m_TerrainTexture); + m_TerrainTexture = 0; + } + + SAFE_ARRAY_DELETE(m_TerrainData); +} + +void CMiniMapTexture::RebuildTerrainTexture(const CTerrain* terrain) +{ + u32 x = 0; + u32 y = 0; + u32 w = m_MapSize - 1; + u32 h = m_MapSize - 1; + m_WaterHeight = g_Renderer.GetWaterManager()->m_WaterHeight; + + m_Dirty = false; + + for (u32 j = 0; j < h; ++j) + { + u32* dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x; + for (u32 i = 0; i < w; ++i) + { + float avgHeight = ( terrain->GetVertexGroundLevel((int)i, (int)j) + + terrain->GetVertexGroundLevel((int)i+1, (int)j) + + terrain->GetVertexGroundLevel((int)i, (int)j+1) + + terrain->GetVertexGroundLevel((int)i+1, (int)j+1) + ) / 4.0f; + + if (avgHeight < m_WaterHeight && avgHeight > m_WaterHeight - m_ShallowPassageHeight) + { + // shallow water + *dataPtr++ = 0xffc09870; + } + else if (avgHeight < m_WaterHeight) + { + // Set water as constant color for consistency on different maps + *dataPtr++ = 0xffa07850; + } + else + { + int hmap = ((int)terrain->GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8; + int val = (hmap / 3) + 170; + + u32 color = 0xFFFFFFFF; + + CMiniPatch* mp = terrain->GetTile(x + i, y + j); + if (mp) + { + CTerrainTextureEntry* tex = mp->GetTextureEntry(); + if (tex) + { + // If the texture can't be loaded yet, set the dirty flags + // so we'll try regenerating the terrain texture again soon + if(!tex->GetTexture()->TryLoad()) + m_Dirty = true; + + color = tex->GetBaseColor(); + } + } + + *dataPtr++ = ScaleColor(color, float(val) / 255.0f); + } + } + } + + // Upload the texture + g_Renderer.BindTexture(0, m_TerrainTexture); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_MapSize - 1, m_MapSize - 1, GL_RGBA, GL_UNSIGNED_BYTE, m_TerrainData); + g_Renderer.BindTexture(0, 0); +} + +// static +float CMiniMapTexture::GetShallowPassageHeight() +{ + float shallowPassageHeight = 0.0f; + CParamNode externalParamNode; + CParamNode::LoadXML(externalParamNode, L"simulation/data/pathfinder.xml", "pathfinder"); + const CParamNode pathingSettings = externalParamNode.GetChild("Pathfinder").GetChild("PassabilityClasses"); + if (pathingSettings.GetChild("default").IsOk() && pathingSettings.GetChild("default").GetChild("MaxWaterDepth").IsOk()) + shallowPassageHeight = pathingSettings.GetChild("default").GetChild("MaxWaterDepth").ToFloat(); + return shallowPassageHeight; +} Index: source/gui/ObjectTypes/CChart.h =================================================================== --- source/gui/ObjectTypes/CChart.h +++ source/gui/ObjectTypes/CChart.h @@ -18,7 +18,6 @@ #ifndef INCLUDED_CCHART #define INCLUDED_CCHART -#include "graphics/ShaderProgramPtr.h" #include "gui/ObjectBases/IGUIObject.h" #include "gui/ObjectBases/IGUITextOwner.h" #include "gui/SettingTypes/CGUIColor.h" Index: source/gui/ObjectTypes/CMiniMap.h =================================================================== --- source/gui/ObjectTypes/CMiniMap.h +++ source/gui/ObjectTypes/CMiniMap.h @@ -33,11 +33,6 @@ CMiniMap(CGUI& pGUI); virtual ~CMiniMap(); - /** - * @return The maximum height for unit passage in water. - */ - static float GetShallowPassageHeight(); - protected: virtual void Draw(CCanvas2D& canvas); @@ -51,38 +46,18 @@ */ virtual bool IsMouseOver() const; - // create the minimap textures - void CreateTextures(); - - // rebuild the terrain texture map - void RebuildTerrainTexture(); - - // destroy and free any memory and textures - void Destroy(); - +private: void SetCameraPos(); bool FireWorldClickEvent(int button, int clicks); static const CStr EventNameWorldClick; - // the terrain we are mini-mapping - const CTerrain* m_Terrain; - const CCamera* m_Camera; //Whether or not the mouse is currently down bool m_Clicking; - // minimap texture handles - GLuint m_TerrainTexture; - - // texture data - u32* m_TerrainData; - - // whether we need to regenerate the terrain texture - bool m_TerrainDirty; - // Whether to draw a black square around and under the minimap. CGUISimpleSetting m_Mask; @@ -97,11 +72,6 @@ // 1.f if map is circular or 1.414f if square (to shrink it inside the circle) float m_MapScale; - // maximal water height to allow the passage of a unit (for underwater shallows). - float m_ShallowPassageHeight; - - float m_WaterHeight; - void DrawTexture(CShaderProgramPtr shader, float coordMax, float angle, float x, float y, float x2, float y2) const; void DrawViewRect(const CMatrix3D& transform) const; Index: source/gui/ObjectTypes/CMiniMap.cpp =================================================================== --- source/gui/ObjectTypes/CMiniMap.cpp +++ source/gui/ObjectTypes/CMiniMap.cpp @@ -22,6 +22,7 @@ #include "graphics/Canvas2D.h" #include "graphics/GameView.h" #include "graphics/LOSTexture.h" +#include "graphics/MiniMapTexture.h" #include "graphics/MiniPatch.h" #include "graphics/ShaderManager.h" #include "graphics/Terrain.h" @@ -66,14 +67,6 @@ // TODO: we should be cleverer about drawing them to reduce clutter const u16 MAX_ENTITIES_DRAWN = 65535; -unsigned int ScaleColor(unsigned int color, float x) -{ - unsigned int r = unsigned(float(color & 0xff) * x); - unsigned int g = unsigned(float((color>>8) & 0xff) * x); - unsigned int b = unsigned(float((color>>16) & 0xff) * x); - return (0xff000000 | b | g<<8 | r<<16); -} - // Adds segments pieces lying inside the circle to lines. void CropPointsByCircle(const std::array& points, const CVector3D& center, const float radius, std::vector* lines) { @@ -111,18 +104,13 @@ CMiniMap::CMiniMap(CGUI& pGUI) : IGUIObject(pGUI), - m_TerrainTexture(0), m_TerrainData(0), m_MapSize(0), m_Terrain(0), m_TerrainDirty(true), m_MapScale(1.f), + m_MapSize(0), m_MapScale(1.f), m_EntitiesDrawn(0), m_IndexArray(GL_STATIC_DRAW), m_VertexArray(GL_DYNAMIC_DRAW), m_Mask(this, "mask", false), - m_NextBlinkTime(0.0), m_PingDuration(25.0), m_BlinkState(false), m_WaterHeight(0.0) + m_NextBlinkTime(0.0), m_PingDuration(25.0), m_BlinkState(false) { m_Clicking = false; m_MouseHovering = false; - // Register Relax NG validator - CXeromyces::AddValidator(g_VFS, "pathfinder", "simulation/data/pathfinder.rng"); - - m_ShallowPassageHeight = GetShallowPassageHeight(); - m_AttributePos.type = GL_FLOAT; m_AttributePos.elems = 2; m_VertexArray.AddAttribute(&m_AttributePos); @@ -142,7 +130,6 @@ m_IndexArray.Upload(); m_IndexArray.FreeBackingStore(); - VertexArrayIterator attrPos = m_AttributePos.GetIterator(); VertexArrayIterator attrColor = m_AttributeColor.GetIterator(); for (u16 i = 0; i < MAX_ENTITIES_DRAWN; ++i) @@ -172,10 +159,7 @@ m_HalfBlinkDuration = blinkDuration/2; } -CMiniMap::~CMiniMap() -{ - Destroy(); -} +CMiniMap::~CMiniMap() = default; void CMiniMap::HandleMessage(SGUIMessage& Message) { @@ -438,19 +422,18 @@ CmpPtr cmpRangeManager(*sim, SYSTEM_ENTITY); ENSURE(cmpRangeManager); + CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture(); + CMiniMapTexture& miniMapTexture = g_Game->GetView()->GetMiniMapTexture(); + // Set our globals in case they hadn't been set before m_Camera = g_Game->GetView()->GetCamera(); - m_Terrain = g_Game->GetWorld()->GetTerrain(); + const CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); m_Width = (u32)(m_CachedActualSize.right - m_CachedActualSize.left); m_Height = (u32)(m_CachedActualSize.bottom - m_CachedActualSize.top); - m_MapSize = m_Terrain->GetVerticesPerSide(); - m_TextureSize = (GLsizei)round_up_to_pow2((size_t)m_MapSize); + m_MapSize = terrain->GetVerticesPerSide(); + m_TextureSize = miniMapTexture.GetTerrainTextureSize(); m_MapScale = (cmpRangeManager->GetLosCircular() ? 1.f : 1.414f); - if (!m_TerrainTexture || g_GameRestarted) - CreateTextures(); - - // only update 2x / second // (note: since units only move a few pixels per second on the minimap, // we can get away with infrequent updates; this is slow) @@ -459,11 +442,7 @@ const double cur_time = timer_Time(); const bool doUpdate = cur_time - last_time > 0.5; if (doUpdate) - { last_time = cur_time; - if (m_TerrainDirty || m_WaterHeight != g_Renderer.GetWaterManager()->m_WaterHeight) - RebuildTerrainTexture(); - } const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom; const float x2 = m_CachedActualSize.right, y2 = m_CachedActualSize.top; @@ -471,8 +450,6 @@ const float angle = GetAngle(); const float unitScale = (cmpRangeManager->GetLosCircular() ? 1.f : m_MapScale/2.f); - CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture(); - CShaderProgramPtr shader; CShaderTechniquePtr tech; @@ -486,7 +463,8 @@ shader = tech->GetShader(); // Draw the main textured quad - shader->BindTexture(str_baseTex, m_TerrainTexture); + if (miniMapTexture.GetTerrainTexture()) + shader->BindTexture(str_baseTex, miniMapTexture.GetTerrainTexture()); if (m_Mask) { shader->BindTexture(str_maskTex, losTexture.GetTexture()); @@ -508,7 +486,8 @@ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } - DrawTexture(shader, texCoordMax, angle, x, y, x2, y2); + if (miniMapTexture.GetTerrainTexture()) + DrawTexture(shader, texCoordMax, angle, x, y, x2, y2); if (!m_Mask) { @@ -674,116 +653,3 @@ PROFILE_END("minimap units"); } - -void CMiniMap::CreateTextures() -{ - Destroy(); - - // Create terrain texture - glGenTextures(1, &m_TerrainTexture); - g_Renderer.BindTexture(0, m_TerrainTexture); - - // Initialise texture with solid black, for the areas we don't - // overwrite with glTexSubImage2D later - u32* texData = new u32[m_TextureSize * m_TextureSize]; - for (ssize_t i = 0; i < m_TextureSize * m_TextureSize; ++i) - texData[i] = 0xFF000000; - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_TextureSize, m_TextureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData); - delete[] texData; - - m_TerrainData = new u32[(m_MapSize - 1) * (m_MapSize - 1)]; - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - - // Rebuild and upload both of them - RebuildTerrainTexture(); -} - - -void CMiniMap::RebuildTerrainTexture() -{ - u32 x = 0; - u32 y = 0; - u32 w = m_MapSize - 1; - u32 h = m_MapSize - 1; - m_WaterHeight = g_Renderer.GetWaterManager()->m_WaterHeight; - - m_TerrainDirty = false; - - for (u32 j = 0; j < h; ++j) - { - u32* dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x; - for (u32 i = 0; i < w; ++i) - { - float avgHeight = ( m_Terrain->GetVertexGroundLevel((int)i, (int)j) - + m_Terrain->GetVertexGroundLevel((int)i+1, (int)j) - + m_Terrain->GetVertexGroundLevel((int)i, (int)j+1) - + m_Terrain->GetVertexGroundLevel((int)i+1, (int)j+1) - ) / 4.0f; - - if (avgHeight < m_WaterHeight && avgHeight > m_WaterHeight - m_ShallowPassageHeight) - { - // shallow water - *dataPtr++ = 0xffc09870; - } - else if (avgHeight < m_WaterHeight) - { - // Set water as constant color for consistency on different maps - *dataPtr++ = 0xffa07850; - } - else - { - int hmap = ((int)m_Terrain->GetHeightMap()[(y + j) * m_MapSize + x + i]) >> 8; - int val = (hmap / 3) + 170; - - u32 color = 0xFFFFFFFF; - - CMiniPatch* mp = m_Terrain->GetTile(x + i, y + j); - if (mp) - { - CTerrainTextureEntry* tex = mp->GetTextureEntry(); - if (tex) - { - // If the texture can't be loaded yet, set the dirty flags - // so we'll try regenerating the terrain texture again soon - if(!tex->GetTexture()->TryLoad()) - m_TerrainDirty = true; - - color = tex->GetBaseColor(); - } - } - - *dataPtr++ = ScaleColor(color, float(val) / 255.0f); - } - } - } - - // Upload the texture - g_Renderer.BindTexture(0, m_TerrainTexture); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_MapSize - 1, m_MapSize - 1, GL_RGBA, GL_UNSIGNED_BYTE, m_TerrainData); -} - -void CMiniMap::Destroy() -{ - if (m_TerrainTexture) - { - glDeleteTextures(1, &m_TerrainTexture); - m_TerrainTexture = 0; - } - - SAFE_ARRAY_DELETE(m_TerrainData); -} - -// static -float CMiniMap::GetShallowPassageHeight() -{ - float shallowPassageHeight = 0.0f; - CParamNode externalParamNode; - CParamNode::LoadXML(externalParamNode, L"simulation/data/pathfinder.xml", "pathfinder"); - const CParamNode pathingSettings = externalParamNode.GetChild("Pathfinder").GetChild("PassabilityClasses"); - if (pathingSettings.GetChild("default").IsOk() && pathingSettings.GetChild("default").GetChild("MaxWaterDepth").IsOk()) - shallowPassageHeight = pathingSettings.GetChild("default").GetChild("MaxWaterDepth").ToFloat(); - return shallowPassageHeight; -} Index: source/renderer/Renderer.cpp =================================================================== --- source/renderer/Renderer.cpp +++ source/renderer/Renderer.cpp @@ -45,6 +45,7 @@ #include "graphics/LightEnv.h" #include "graphics/LOSTexture.h" #include "graphics/MaterialManager.h" +#include "graphics/MiniMapTexture.h" #include "graphics/Model.h" #include "graphics/ModelDef.h" #include "graphics/ParticleManager.h" @@ -1241,6 +1242,8 @@ GetScene().GetLOSTexture().InterpolateLOS(); + GetScene().GetMiniMapTexture().Render(); + CShaderDefines context = m->globalContext; int cullGroup = CULL_DEFAULT; Index: source/renderer/Scene.h =================================================================== --- source/renderer/Scene.h +++ source/renderer/Scene.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -35,6 +35,7 @@ class CParticleEmitter; class CPatch; class CLOSTexture; +class CMiniMapTexture; class CTerritoryTexture; struct SOverlayLine; struct SOverlayTexturedLine; @@ -72,6 +73,11 @@ * Return the territory texture to be used for rendering this scene. */ virtual CTerritoryTexture& GetTerritoryTexture() = 0; + + /** + * Return the minimap texture to be used for rendering this scene. + */ + virtual CMiniMapTexture& GetMiniMapTexture() = 0; }; Index: source/renderer/Scene.cpp =================================================================== --- source/renderer/Scene.cpp +++ source/renderer/Scene.cpp @@ -15,21 +15,12 @@ * along with 0 A.D. If not, see . */ -/* - * File : Scene.cpp - * Project : graphics - * Description : This file contains default implementations and utilities - * : to be used together with the Scene interface and related - * : classes. - * - * @note This file would fit just as well into the graphics/ subdirectory. - */ - #include "precompiled.h" +#include "renderer/Scene.h" + #include "graphics/Model.h" #include "graphics/ParticleEmitter.h" -#include "renderer/Scene.h" /////////////////////////////////////////////////////////// // Default implementation traverses the model recursively and uses Index: source/tools/atlas/GameInterface/ActorViewer.cpp =================================================================== --- source/tools/atlas/GameInterface/ActorViewer.cpp +++ source/tools/atlas/GameInterface/ActorViewer.cpp @@ -23,7 +23,7 @@ #include "graphics/ColladaManager.h" #include "graphics/LOSTexture.h" -#include "graphics/Unit.h" +#include "graphics/MiniMapTexture.h" #include "graphics/Model.h" #include "graphics/ModelDef.h" #include "graphics/ObjectManager.h" @@ -34,6 +34,7 @@ #include "graphics/TerrainTextureEntry.h" #include "graphics/TerrainTextureManager.h" #include "graphics/TerritoryTexture.h" +#include "graphics/Unit.h" #include "graphics/UnitManager.h" #include "graphics/Overlay.h" #include "maths/MathUtil.h" @@ -72,7 +73,8 @@ Simulation2(&UnitManager, g_ScriptContext, &Terrain), ObjectManager(MeshManager, SkeletonAnimManager, Simulation2), LOSTexture(Simulation2), - TerritoryTexture(Simulation2) + TerritoryTexture(Simulation2), + MiniMapTexture(Simulation2) { UnitManager.SetObjectManager(ObjectManager); } @@ -107,6 +109,7 @@ CObjectManager ObjectManager; // Keep this after Simulation2 - it needs it for initialisation. CLOSTexture LOSTexture; CTerritoryTexture TerritoryTexture; + CMiniMapTexture MiniMapTexture; SOverlayLine SelectionBoxOverlay; SOverlayLine AxesMarkerOverlays[3]; @@ -208,6 +211,11 @@ return TerritoryTexture; } + virtual CMiniMapTexture& GetMiniMapTexture() + { + return MiniMapTexture; + } + /** * Recursively fetches the props of the currently displayed entity model and its submodels, and stores them for rendering. */ Index: source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -26,11 +26,11 @@ #include "graphics/LOSTexture.h" #include "graphics/MapIO.h" #include "graphics/MapWriter.h" +#include "graphics/MinimapTexture.h" #include "graphics/Patch.h" #include "graphics/Terrain.h" #include "graphics/TerrainTextureEntry.h" #include "graphics/TerrainTextureManager.h" -#include "gui/ObjectTypes/CMiniMap.h" #include "lib/bits.h" #include "lib/file/vfs/vfs_path.h" #include "lib/status.h" @@ -293,7 +293,7 @@ std::vector imageBytes(imageDataSize); - float shallowPassageHeight = CMiniMap::GetShallowPassageHeight(); + float shallowPassageHeight = CMiniMapTexture::GetShallowPassageHeight(); ssize_t w = dimension; ssize_t h = dimension;