app: redraw the preview minimap radar only when its inputs change
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
699ac058f5
commit
121f1a6307
+12
-3
@@ -480,6 +480,7 @@ int main(int argc, char** argv) {
|
||||
std::unique_ptr<SDL_Texture, decltype(&SDL_DestroyTexture)> gpu_scene_texture(nullptr, SDL_DestroyTexture);
|
||||
std::unique_ptr<SDL_Surface, decltype(&SDL_DestroySurface)> minimap_surface(nullptr, SDL_DestroySurface);
|
||||
std::unique_ptr<SDL_Texture, decltype(&SDL_DestroyTexture)> minimap_texture(nullptr, SDL_DestroyTexture);
|
||||
std::array<float, 9> 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<float, 9> 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<float>(screen_width - 132), 5.0f, 128.0f, 128.0f };
|
||||
SDL_RenderTexture(renderer.get(), minimap_texture.get(), nullptr, &dst);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user