From 01476b98364adef832623a6d8bdc2f5337d247f3 Mon Sep 17 00:00:00 2001 From: Vantha Date: Sun, 4 Jan 2026 10:56:29 +0100 Subject: [PATCH] Only render the minimap texture if it'll be displayed This patch implements a way for minimap-type GUI objects to request the rendering of the minimap texture each frame. If it wasn't requested the minimap texture isn't rendered at all and the objects only request it while they are being displayed. This saves unnecessary work and fixes a bug where the minimap briefly showed the revealed map after a cinema path ended playing, since it isn't updated every frame (only 2x per second). --- source/graphics/MiniMapTexture.cpp | 10 +++++++++- source/graphics/MiniMapTexture.h | 6 +++++- source/gui/ObjectTypes/CMiniMap.cpp | 7 ++++++- source/gui/ObjectTypes/CMiniMap.h | 4 +++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/source/graphics/MiniMapTexture.cpp b/source/graphics/MiniMapTexture.cpp index 8779a57e5d..c248aa0297 100644 --- a/source/graphics/MiniMapTexture.cpp +++ b/source/graphics/MiniMapTexture.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -354,6 +354,11 @@ CMiniMapTexture::~CMiniMapTexture() DestroyTextures(); } +void CMiniMapTexture::RequestRendering() +{ + m_RenderingRequested = true; +} + void CMiniMapTexture::Update(const float /*deltaRealTime*/) { if (m_WaterHeight != g_Renderer.GetSceneRenderer().GetWaterManager().m_WaterHeight) @@ -367,6 +372,9 @@ void CMiniMapTexture::Render( Renderer::Backend::IDeviceCommandContext* deviceCommandContext, CLOSTexture& losTexture, CTerritoryTexture& territoryTexture) { + if (!std::exchange(m_RenderingRequested, false)) + return; + const CTerrain& terrain = g_Game->GetWorld()->GetTerrain(); if (!m_TerrainTexture) CreateTextures(deviceCommandContext, terrain); diff --git a/source/graphics/MiniMapTexture.h b/source/graphics/MiniMapTexture.h index 085ef4dfc2..183d12b25f 100644 --- a/source/graphics/MiniMapTexture.h +++ b/source/graphics/MiniMapTexture.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -50,6 +50,8 @@ public: CMiniMapTexture(Renderer::Backend::IDevice* device, CSimulation2& simulation); ~CMiniMapTexture(); + void RequestRendering(); + /** * Marks the texture as dirty if it's old enough to redraw it on Render. */ @@ -101,6 +103,8 @@ private: CSimulation2& m_Simulation; + bool m_RenderingRequested = false; + bool m_TerrainTextureDirty = true; bool m_FinalTextureDirty = true; double m_LastFinalTextureUpdate = 0.0; diff --git a/source/gui/ObjectTypes/CMiniMap.cpp b/source/gui/ObjectTypes/CMiniMap.cpp index f45981f98a..132c4a9c70 100644 --- a/source/gui/ObjectTypes/CMiniMap.cpp +++ b/source/gui/ObjectTypes/CMiniMap.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -119,6 +119,11 @@ CMiniMap::CMiniMap(CGUI& pGUI) : m_MouseHovering = false; } +void CMiniMap::Tick() +{ + g_Game->GetView()->GetMiniMapTexture().RequestRendering(); +} + void CMiniMap::HandleMessage(SGUIMessage& Message) { IGUIObject::HandleMessage(Message); diff --git a/source/gui/ObjectTypes/CMiniMap.h b/source/gui/ObjectTypes/CMiniMap.h index b9e96ab63d..2805cbe0c6 100644 --- a/source/gui/ObjectTypes/CMiniMap.h +++ b/source/gui/ObjectTypes/CMiniMap.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -52,6 +52,8 @@ protected: double time; }; + virtual void Tick(); + virtual void Draw(CCanvas2D& canvas); virtual void CreateJSObject();