3D优化
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#undef interface
|
||||
|
||||
std::string default_config_path;
|
||||
@@ -49,6 +50,59 @@ static Psc::JSON write_string_array(std::string_view key, const std::vector<std:
|
||||
}
|
||||
return Psc::JSON(key, array);
|
||||
}
|
||||
static const std::pair<std::string_view, std::string_view> kDefaultAircraftModelUrls[] = {
|
||||
{"no_category_information", "/ui/model/aircraft-no-category-information.glb"},
|
||||
{"surface_emergency_vehicle", "/ui/model/aircraft-surface-emergency-vehicle.glb"},
|
||||
{"surface_service_vehicle", "/ui/model/aircraft-surface-service-vehicle.glb"},
|
||||
{"ground_obstruction_4", "/ui/model/aircraft-ground-obstruction-4.glb"},
|
||||
{"ground_obstruction_5", "/ui/model/aircraft-ground-obstruction-5.glb"},
|
||||
{"ground_obstruction_6", "/ui/model/aircraft-ground-obstruction-6.glb"},
|
||||
{"ground_obstruction_7", "/ui/model/aircraft-ground-obstruction-7.glb"},
|
||||
{"glider", "/ui/model/aircraft-glider.glb"},
|
||||
{"lighter_than_air", "/ui/model/aircraft-lighter-than-air.glb"},
|
||||
{"parachutist", "/ui/model/aircraft-parachutist.glb"},
|
||||
{"ultralight_hangglider_paraglider", "/ui/model/aircraft-ultralight-hangglider-paraglider.glb"},
|
||||
{"reserved_3_5", "/ui/model/aircraft-reserved-3-5.glb"},
|
||||
{"unmanned_aerial_vehicle", "/ui/model/aircraft-unmanned-aerial-vehicle.glb"},
|
||||
{"space_transatmospheric_vehicle", "/ui/model/aircraft-space-transatmospheric-vehicle.glb"},
|
||||
{"light_aircraft", "/ui/model/aircraft-light-aircraft.glb"},
|
||||
{"medium_1_aircraft", "/ui/model/aircraft-medium-1-aircraft.glb"},
|
||||
{"medium_2_aircraft", "/ui/model/aircraft-medium-2-aircraft.glb"},
|
||||
{"high_vortex_aircraft", "/ui/model/aircraft-high-vortex-aircraft.glb"},
|
||||
{"heavy_aircraft", "/ui/model/aircraft-heavy-aircraft.glb"},
|
||||
{"high_performance_aircraft", "/ui/model/aircraft-high-performance-aircraft.glb"},
|
||||
{"rotorcraft", "/ui/model/aircraft-rotorcraft.glb"}
|
||||
};
|
||||
static std::map<std::string, Map_Model_Item_Config> make_default_aircraft_models() {
|
||||
std::map<std::string, Map_Model_Item_Config> ret;
|
||||
for (const auto& item : kDefaultAircraftModelUrls) {
|
||||
ret.emplace(std::string(item.first), Map_Model_Item_Config{std::string(item.second), 50.0, -90.0, 0.0, 0.0});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
static std::map<std::string, Map_Model_Item_Config> read_optional_model_object_field(const Psc::JSON* json, std::string_view key, std::map<std::string, Map_Model_Item_Config> fallback) {
|
||||
auto field = json->get(key);
|
||||
if (field == nullptr) {
|
||||
return fallback;
|
||||
}
|
||||
if (field->valueType != Psc::Object) {
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), std::string(key));
|
||||
}
|
||||
for (const auto& child : field->children) {
|
||||
if (child.valueType != Psc::Object) {
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), std::string(key));
|
||||
}
|
||||
fallback[child.key].from_base_json(&child);
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
static Psc::JSON write_model_object(std::string_view key, const std::map<std::string, Map_Model_Item_Config>& values) {
|
||||
auto object = Psc::JSON::object();
|
||||
for (const auto& item : values) {
|
||||
object.append({item.first, item.second.to_base_json()});
|
||||
}
|
||||
return Psc::JSON(key, object);
|
||||
}
|
||||
static std::string read_string_field(const Psc::JSON* json, std::string_view key) {
|
||||
auto field = json->get(key);
|
||||
if (field == nullptr || field->valueType != Psc::String) {
|
||||
@@ -242,6 +296,31 @@ Psc::JSON Map_Camera_Config::to_base_json() const {
|
||||
bool Map_View_Config::is_scene_mode(std::string_view mode) {
|
||||
return mode == "2d" || mode == "2.5d" || mode == "3d";
|
||||
}
|
||||
bool Map_Tile_View_Config::is_tile_zoom_mode(std::string_view mode) {
|
||||
return mode == "native" || mode == "upscale" || mode == "both";
|
||||
}
|
||||
void Map_Tile_View_Config::from_base_json(const Psc::JSON* that_json) {
|
||||
if (that_json == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (that_json->valueType != Psc::Object) {
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "map_tile_view");
|
||||
}
|
||||
current_imagery_key = read_optional_string_field(that_json, "current_imagery_key", current_imagery_key);
|
||||
auto next_tile_zoom_mode = read_optional_string_field(that_json, "tile_zoom_mode", tile_zoom_mode);
|
||||
if (!is_tile_zoom_mode(next_tile_zoom_mode)) {
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "tile_zoom_mode");
|
||||
}
|
||||
tile_zoom_mode = next_tile_zoom_mode;
|
||||
tile_display_maximum_level = std::clamp(read_optional_uint32_field(that_json, "tile_display_maximum_level", tile_display_maximum_level), 0u, 24u);
|
||||
}
|
||||
Psc::JSON Map_Tile_View_Config::to_base_json() const {
|
||||
auto ret = Psc::JSON::object();
|
||||
ret.append({"current_imagery_key", current_imagery_key});
|
||||
ret.append({"tile_zoom_mode", tile_zoom_mode});
|
||||
ret.append({"tile_display_maximum_level", tile_display_maximum_level});
|
||||
return ret;
|
||||
}
|
||||
void Map_View_Config::from_base_json(const Psc::JSON* that_json) {
|
||||
if (that_json == nullptr) {
|
||||
return;
|
||||
@@ -254,11 +333,15 @@ void Map_View_Config::from_base_json(const Psc::JSON* that_json) {
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "scene_mode");
|
||||
}
|
||||
scene_mode = next_scene_mode;
|
||||
map2d.from_base_json(that_json->get("map2d"));
|
||||
map3d.from_base_json(that_json->get("map3d"));
|
||||
camera.from_base_json(that_json->get("camera"));
|
||||
}
|
||||
Psc::JSON Map_View_Config::to_base_json() const {
|
||||
auto ret = Psc::JSON::object();
|
||||
ret.append({"scene_mode", scene_mode});
|
||||
ret.append({"map2d", map2d.to_base_json()});
|
||||
ret.append({"map3d", map3d.to_base_json()});
|
||||
ret.append({"camera", camera.to_base_json()});
|
||||
return ret;
|
||||
}
|
||||
@@ -279,7 +362,7 @@ void Cesium_Graphics_Config::from_base_json(const Psc::JSON* that_json) {
|
||||
enable_lighting = read_optional_bool_field(that_json, "enable_lighting", enable_lighting);
|
||||
maximum_screen_space_error = std::clamp(read_optional_uint32_field(that_json, "maximum_screen_space_error", maximum_screen_space_error), 1u, 16u);
|
||||
terrain_enabled_in_3d = read_optional_bool_field(that_json, "terrain_enabled_in_3d", terrain_enabled_in_3d);
|
||||
terrain_exaggeration = std::clamp(read_optional_double_field(that_json, "terrain_exaggeration", terrain_exaggeration), 0.0, 5.0);
|
||||
terrain_exaggeration = read_optional_double_field(that_json, "terrain_exaggeration", terrain_exaggeration);
|
||||
terrain_limit_maximum_level = read_optional_bool_field(that_json, "terrain_limit_maximum_level", terrain_limit_maximum_level);
|
||||
terrain_maximum_level = std::clamp(read_optional_uint32_field(that_json, "terrain_maximum_level", terrain_maximum_level), 0u, 24u);
|
||||
terrain_cache_tiles = std::clamp(read_optional_uint32_field(that_json, "terrain_cache_tiles", terrain_cache_tiles), 16u, 2048u);
|
||||
@@ -302,6 +385,49 @@ Psc::JSON Cesium_Graphics_Config::to_base_json() const {
|
||||
ret.append({"terrain_cache_tiles", terrain_cache_tiles});
|
||||
return ret;
|
||||
}
|
||||
Map_Model_Item_Config::Map_Model_Item_Config(std::string url)
|
||||
: url(std::move(url)) {}
|
||||
Map_Model_Item_Config::Map_Model_Item_Config(std::string url, double built_in_size, double heading, double pitch, double roll)
|
||||
: url(std::move(url)), built_in_size(built_in_size), heading_offset_degrees(heading), pitch_offset_degrees(pitch), roll_offset_degrees(roll) {}
|
||||
void Map_Model_Item_Config::from_base_json(const Psc::JSON* that_json) {
|
||||
if (that_json == nullptr || that_json->valueType != Psc::Object) {
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "map_model_item");
|
||||
}
|
||||
url = read_optional_string_field(that_json, "url", url);
|
||||
built_in_size = read_optional_double_field(that_json, "built_in_size", built_in_size);
|
||||
heading_offset_degrees = read_optional_double_field(that_json, "heading_offset_degrees", heading_offset_degrees);
|
||||
pitch_offset_degrees = read_optional_double_field(that_json, "pitch_offset_degrees", pitch_offset_degrees);
|
||||
roll_offset_degrees = read_optional_double_field(that_json, "roll_offset_degrees", roll_offset_degrees);
|
||||
}
|
||||
Psc::JSON Map_Model_Item_Config::to_base_json() const {
|
||||
auto ret = Psc::JSON::object();
|
||||
ret.append({"url", url});
|
||||
ret.append({"built_in_size", built_in_size});
|
||||
ret.append({"heading_offset_degrees", heading_offset_degrees});
|
||||
ret.append({"pitch_offset_degrees", pitch_offset_degrees});
|
||||
ret.append({"roll_offset_degrees", roll_offset_degrees});
|
||||
return ret;
|
||||
}
|
||||
Map_Model_Config::Map_Model_Config()
|
||||
: aircraft_models(make_default_aircraft_models()) {}
|
||||
void Map_Model_Config::from_base_json(const Psc::JSON* that_json) {
|
||||
if (that_json == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (that_json->valueType != Psc::Object) {
|
||||
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "map_models");
|
||||
}
|
||||
aircraft_model.from_base_json(that_json->get("aircraft_model"));
|
||||
aircraft_models = read_optional_model_object_field(that_json, "aircraft_models", make_default_aircraft_models());
|
||||
base_station_model.from_base_json(that_json->get("base_station_model"));
|
||||
}
|
||||
Psc::JSON Map_Model_Config::to_base_json() const {
|
||||
auto ret = Psc::JSON::object();
|
||||
ret.append({"aircraft_model", aircraft_model.to_base_json()});
|
||||
ret.append(write_model_object("aircraft_models", aircraft_models));
|
||||
ret.append({"base_station_model", base_station_model.to_base_json()});
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Mode_ACS_Config::server(Global *g) {
|
||||
auto &svr = g->svr;
|
||||
@@ -318,6 +444,19 @@ void Mode_ACS_Config::server(Global *g) {
|
||||
CHECK_JSON_PARAM
|
||||
auto &j = o_params.value();
|
||||
init_base_json(&j);
|
||||
if (auto min_points = j.try_get_number<std::size_t>("aircraft_change_list_min_position_points")) {
|
||||
aircraft_change_list_min_position_points = min_points.value();
|
||||
}
|
||||
if (auto range_filter = j.try_get_bool("aircraft_change_list_adsb_range_filter")) {
|
||||
aircraft_change_list_adsb_range_filter = range_filter.value();
|
||||
}
|
||||
if (auto range_factor = j.try_get_number<double>("aircraft_change_list_adsb_range_factor")) {
|
||||
aircraft_change_list_adsb_range_factor = range_factor.value();
|
||||
}
|
||||
if (auto target_altitude = j.try_get_number<double>("adsb_theoretical_target_altitude_meters")) {
|
||||
adsb_theoretical_target_altitude_meters = target_altitude.value();
|
||||
}
|
||||
Global::save();
|
||||
res->setBody(warp(to_base_json()).to_json_string());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user