AUTOSCALE!
This commit is contained in:
+36
-4
@@ -1,27 +1,31 @@
|
|||||||
#include "../res/station.h"
|
#include "../res/station.h"
|
||||||
#include "core/color.h"
|
#include "core/color.h"
|
||||||
#include "core/config.hpp"
|
#include "core/config.hpp"
|
||||||
#include "core/const.hpp"
|
|
||||||
#include "core/units.hpp"
|
#include "core/units.hpp"
|
||||||
#include "hal/draw.hpp"
|
#include "hal/draw.hpp"
|
||||||
#include "hal/hal.hpp"
|
#include "hal/hal.hpp"
|
||||||
#include "hal/net.hpp"
|
#include "hal/net.hpp"
|
||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "core/global.hpp"
|
#include "core/global.hpp"
|
||||||
#include "core/geo.hpp"
|
#include "core/geo.hpp"
|
||||||
#include "core/gfx.hpp"
|
#include "core/gfx.hpp"
|
||||||
|
|
||||||
|
#ifdef AUTOSCALE
|
||||||
|
uint16_t max_range = 500;
|
||||||
|
#endif
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
if (hal::init() != 0) {
|
if (hal::init() != 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
const auto [screen_w, screen_h] = hal::get_screen_size();
|
const auto [screen_w, screen_h] = hal::get_screen_size();
|
||||||
|
#ifndef AUTOSCALE
|
||||||
const float pixels_per_km =
|
const
|
||||||
|
#endif
|
||||||
|
float pixels_per_km =
|
||||||
static_cast<float>(screen_h > screen_w ? screen_w : screen_h) /
|
static_cast<float>(screen_h > screen_w ? screen_w : screen_h) /
|
||||||
(max_range * 2);
|
(max_range * 2);
|
||||||
bool odd_even = true;
|
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
|
{ // draw planes
|
||||||
nlohmann::json aircraft = net::http_get_json(std::format("{}/aircraft.json", base_url));
|
nlohmann::json aircraft = net::http_get_json(std::format("{}/aircraft.json", base_url));
|
||||||
if (aircraft!= nullptr) {
|
if (aircraft!= nullptr) {
|
||||||
@@ -96,6 +106,14 @@ int main() {
|
|||||||
draw::color_t color= get_altitude_color(altitude);
|
draw::color_t color= get_altitude_color(altitude);
|
||||||
try {
|
try {
|
||||||
const auto [x_offset,y_offset] = get_offset_from_station(craft["lat"].get<double>(), craft["lon"].get<double>());
|
const auto [x_offset,y_offset] = get_offset_from_station(craft["lat"].get<double>(), craft["lon"].get<double>());
|
||||||
|
#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 x_center = middle_x+((x_offset/1000)*pixels_per_km);
|
||||||
const uint16_t y_center = middle_y+((y_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);
|
draw::pixel(x_center, y_center, color);
|
||||||
@@ -110,6 +128,20 @@ int main() {
|
|||||||
std::cerr << RED"[ERROR]" RESET " failed to get aircraft\n";
|
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<float>(screen_h > screen_w ? screen_w : screen_h) /
|
||||||
|
(max_range * 2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
hal::end_frame();
|
hal::end_frame();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user