From 121f1a6307df1a560b8d9d48ba9c23e88853e613 Mon Sep 17 00:00:00 2001 From: shenlei Date: Mon, 12 Oct 2026 16:45:17 +0900 Subject: [PATCH] app: redraw the preview minimap radar only when its inputs change Co-Authored-By: Claude Opus 5.5 --- src/app/main.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index 30020d34..b61afe6e 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -480,6 +480,7 @@ int main(int argc, char** argv) { std::unique_ptr gpu_scene_texture(nullptr, SDL_DestroyTexture); std::unique_ptr minimap_surface(nullptr, SDL_DestroySurface); std::unique_ptr minimap_texture(nullptr, SDL_DestroyTexture); + std::array minimap_last_radar{};bool minimap_radar_valid = false; // redraw only when inputs move ava2::TerrainHeightmap outdoor_terrain; std::string raw_path = "map/metin2_map_a1/001003/height.raw"; @@ -2229,14 +2230,22 @@ const auto profileActiveStart = std::chrono::steady_clock::now(); if (!minimap_surface) { minimap_surface.reset(SDL_CreateSurface(128, 128, SDL_PIXELFORMAT_ARGB8888)); minimap_texture.reset(SDL_CreateTexture(renderer.get(), SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 128, 128)); + minimap_radar_valid = false; if (minimap_texture) { SDL_SetTextureBlendMode(minimap_texture.get(), SDL_BLENDMODE_BLEND); } } if (minimap_surface && minimap_texture) { - SDL_FillSurfaceRect(minimap_surface.get(), nullptr, 0x00000000); - minimap_mgr.RenderRadar(minimap_surface.get(), 0, 0, 128, player_world_x, player_world_z, player_world_yaw); - SDL_UpdateTexture(minimap_texture.get(), nullptr, minimap_surface->pixels, minimap_surface->pitch); + // Redraw/upload only when the radar inputs move; a standing player re-presents the texture. + const std::array radar{player_world_x, player_world_z, player_world_yaw, + mob_dog.GetX(), mob_dog.GetZ(), mob_dog.IsDead() ? 1.f : 0.f, + mob_metin.GetX(), mob_metin.GetZ(), mob_metin.IsDead() ? 1.f : 0.f}; + if (!minimap_radar_valid || radar != minimap_last_radar) { + SDL_FillSurfaceRect(minimap_surface.get(), nullptr, 0x00000000); + minimap_mgr.RenderRadar(minimap_surface.get(), 0, 0, 128, player_world_x, player_world_z, player_world_yaw); + SDL_UpdateTexture(minimap_texture.get(), nullptr, minimap_surface->pixels, minimap_surface->pitch); + minimap_last_radar = radar;minimap_radar_valid = true; + } SDL_FRect dst = { static_cast(screen_width - 132), 5.0f, 128.0f, 128.0f }; SDL_RenderTexture(renderer.get(), minimap_texture.get(), nullptr, &dst); }