From 770c7ca6316a8e97490ea9c0cb43bc09bffc6357 Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Wed, 5 Aug 2026 16:30:59 +0200 Subject: [PATCH] AUTOSCALE! --- src/main.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a52e385..7f31ef9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,27 +1,31 @@ #include "../res/station.h" #include "core/color.h" #include "core/config.hpp" -#include "core/const.hpp" #include "core/units.hpp" #include "hal/draw.hpp" #include "hal/hal.hpp" #include "hal/net.hpp" #include "nlohmann/json_fwd.hpp" #include -#include #include #include #include "core/global.hpp" #include "core/geo.hpp" #include "core/gfx.hpp" +#ifdef AUTOSCALE +uint16_t max_range = 500; +#endif + int main() { if (hal::init() != 0) { return 1; } const auto [screen_w, screen_h] = hal::get_screen_size(); - - const float pixels_per_km = + #ifndef AUTOSCALE + const + #endif + float pixels_per_km = static_cast(screen_h > screen_w ? screen_w : screen_h) / (max_range * 2); bool odd_even = true; @@ -74,6 +78,12 @@ int main() { } } + #ifdef AUTOSCALE + { + // fardest aircraft in km + uint16_t fardest_aircraft_distance_linear = 0; + #endif + { // draw planes nlohmann::json aircraft = net::http_get_json(std::format("{}/aircraft.json", base_url)); if (aircraft!= nullptr) { @@ -96,6 +106,14 @@ int main() { draw::color_t color= get_altitude_color(altitude); try { const auto [x_offset,y_offset] = get_offset_from_station(craft["lat"].get(), craft["lon"].get()); + #ifdef AUTOSCALE + if(std::abs(x_offset)/1000 > fardest_aircraft_distance_linear) { + fardest_aircraft_distance_linear = std::abs(x_offset)/1000; + } + if(std::abs(y_offset)/1000 > fardest_aircraft_distance_linear) { + fardest_aircraft_distance_linear = std::abs(y_offset)/1000; + } + #endif const uint16_t x_center = middle_x+((x_offset/1000)*pixels_per_km); const uint16_t y_center = middle_y+((y_offset/1000)*pixels_per_km); draw::pixel(x_center, y_center, color); @@ -110,6 +128,20 @@ int main() { std::cerr << RED"[ERROR]" RESET " failed to get aircraft\n"; } } + #ifdef AUTOSCALE + if (fardest_aircraft_distance_linear > 0) { + for(uint16_t i = first_ring_distance; i < UINT16_MAX; i*=2) { + if (i+(range_padding/2) >= fardest_aircraft_distance_linear) { + max_range = i+range_padding; + pixels_per_km = + static_cast(screen_h > screen_w ? screen_w : screen_h) / + (max_range * 2); + break; + } + } + } + } + #endif hal::end_frame(); }