From 428578abde8fc0c8326c10e136867b0ae4225d40 Mon Sep 17 00:00:00 2001 From: FlyBs1 Date: Tue, 3 Nov 2026 23:28:13 -0500 Subject: [PATCH] Add low Mach contact filtering --- resources/config/defaults.toml | 1 + src/draw/imgui_radar_labels_renderer.py | 14 ++++++++++-- src/game_object.py | 6 +++++- src/render_data_arrays.py | 25 ++++++++++++++++++++++ src/tests/test_render_data_arrays_fixed.py | 13 +++++++++++ src/ui/imgui_ui.py | 10 +++++++++ 6 files changed, 66 insertions(+), 3 deletions(-) diff --git a/resources/config/defaults.toml b/resources/config/defaults.toml index 1a89ee1..a5a9077 100644 --- a/resources/config/defaults.toml +++ b/resources/config/defaults.toml @@ -38,6 +38,7 @@ contact_stroke = 2 # Stroke width of the track in pixels contact_font_scale = 40 # Font size of the track labels contact_label_padding = 5 # Additional padding for track labels in pixels center_point_size = 3.0 # Size of the center point quad in pixels +hide_contacts_below_0_2m = true # Hide air contacts below Mach 0.2 when enabled bullseye_num_rings = 6 # Number of concentric rings in the bullseye display bullseye_ring_distance = 20 # Distance between bullseye rings in nautical miles diff --git a/src/draw/imgui_radar_labels_renderer.py b/src/draw/imgui_radar_labels_renderer.py index fec9756..333b366 100644 --- a/src/draw/imgui_radar_labels_renderer.py +++ b/src/draw/imgui_radar_labels_renderer.py @@ -16,7 +16,7 @@ from imgui_bundle import imgui from draw.scene import Scene from game_object import GameObject -from game_object_types import get_layer_key +from game_object_types import GameObjectType, get_layer_key from game_state import GameState from sensor_tracks import Track from util.track_labels import (TrackLabelLocation, TrackLabels, get_labels_for_class_type, evaluate_input_format) @@ -251,6 +251,12 @@ def draw_all_ac_labels(self, gamestate: GameState): total_offset = offset + label_padding font_scale = config.app_config.get_float("radar", "contact_font_scale") / 100.0 # Convert to ImGui scale + # Collect IDs for objects actually present in the icon render arrays. + # Only render labels on objects that are visible on the radar (i.e., have icons). + visible_icon_object_ids = set() + for icon_data in gamestate.render_arrays.icon_data.values(): + visible_icon_object_ids.update(icon_data.id_to_index.keys()) + for object_type, objects_by_id in gamestate.objects.items(): if not objects_by_id: continue @@ -265,7 +271,11 @@ def draw_all_ac_labels(self, gamestate: GameState): if labels is None or not labels.labels: continue - objs = list(objects_by_id.values()) + # Only if there are visible objects of this type do we proceed to render labels + objs = [obj for obj in objects_by_id.values() if obj.object_id in visible_icon_object_ids] + if not objs: + continue + world_positions = np.array([(obj.U, obj.V) for obj in objs], dtype=np.float64) screen_positions = self.scene.world_to_screen_batch(world_positions).tolist() diff --git a/src/game_object.py b/src/game_object.py index 13a32dc..f6f9792 100644 --- a/src/game_object.py +++ b/src/game_object.py @@ -149,7 +149,7 @@ def __init__(self, object_id: str, object_type: GameObjectType, initial: ACMIObj self.bull_x = 0.0 self.bull_y = 0.0 self.magnetic_variation = 0.0 - + logger.debug(f"Creating GameObject {object_id} of type {object_type}") # Initialize all ACMI numeric fields to 0.0 @@ -264,6 +264,10 @@ def get_display_name(self) -> str: def get_pos(self) -> tuple[float, float]: return (self.U, self.V) + def get_mach(self) -> float: + """Get the Mach number for this object.""" + return self.Mach + def change_name(self, name: str): self.override_name = name diff --git a/src/render_data_arrays.py b/src/render_data_arrays.py index 0a169ee..f5d629a 100644 --- a/src/render_data_arrays.py +++ b/src/render_data_arrays.py @@ -561,6 +561,22 @@ def __init__(self, initial_capacity: int = 1024 * 8): self.velocity_vectors = VelocityVectorRenderData(initial_capacity // 2) self.lock_lines = LockLineRenderData(initial_capacity // 2) + def _should_render_object_mach(self, game_obj: GameObject) -> bool: + """Check if an object should be rendered based on Mach threshold and user preference.""" + if not game_obj.is_air_unit(): + return True + + if game_obj.Pilot not in (None, ""): + return True + + if not config.app_config.get_bool("radar", "hide_contacts_below_0_2m"): + return True + + if game_obj.Mach >= 0.2: + return True + + return False + def _should_render_object_type(self, obj_type) -> bool: """Check if an object type should be rendered based on layer configuration.""" # Bullseye has a layer key, but its visibility is handled separately in @@ -581,6 +597,10 @@ def add_object(self, game_obj: GameObject): if not self._should_render_object_type(game_obj.object_type): return + # Check if this object should be rendered based on Mach number (for air units) //bs1 + if not self._should_render_object_mach(game_obj): + return + # Add to icon array (Most objects have icons) shape_id = game_obj.icon shape = Shapes.from_idx(shape_id) if shape_id is not None else None @@ -619,6 +639,11 @@ def update_object(self, game_obj: GameObject): self.remove_object(game_obj) return + # Check if this object shoudl be rendered based on Mach number (for air units) //bs1 + if not self._should_render_object_mach(game_obj): + self.remove_object(game_obj) + return + # Object should be rendered - update or add it # Update icon data (all objects have icons) shape_id = game_obj.icon diff --git a/src/tests/test_render_data_arrays_fixed.py b/src/tests/test_render_data_arrays_fixed.py index 18e7f9d..adbe96b 100644 --- a/src/tests/test_render_data_arrays_fixed.py +++ b/src/tests/test_render_data_arrays_fixed.py @@ -886,6 +886,19 @@ def test_initialization(self): assert isinstance(render_arrays.lock_lines, LockLineRenderData) assert render_arrays.lock_lines.capacity == 50 # initial_capacity // 2 + def test_hide_contacts_below_mach_threshold_toggle(self): + """Test that the new radar toggle can disable the below-0.2 Mach filter.""" + render_arrays = TrackRenderDataArrays(100) + aircraft_obj = self.create_mock_game_object("aircraft1", GameObjectType.FIXEDWING, icon=1, cas=50.0) + aircraft_obj.Mach = 0.1 + aircraft_obj.Pilot = "" + + config.app_config.set("radar", "hide_contacts_below_0_2m", True) + assert not render_arrays._should_render_object_mach(aircraft_obj) + + config.app_config.set("radar", "hide_contacts_below_0_2m", False) + assert render_arrays._should_render_object_mach(aircraft_obj) + def test_add_aircraft_object(self): """Test adding an aircraft object (should add to icon and velocity arrays).""" render_arrays = TrackRenderDataArrays(100) diff --git a/src/ui/imgui_ui.py b/src/ui/imgui_ui.py index 58ef661..68056d4 100644 --- a/src/ui/imgui_ui.py +++ b/src/ui/imgui_ui.py @@ -1059,6 +1059,7 @@ def settings_tab_radar(self): font_scale = config.app_config.get_int("radar", "contact_font_scale") label_padding = config.app_config.get_int("radar", "contact_label_padding") center_point_size = config.app_config.get_float("radar", "center_point_size") + hide_contacts_below_0_2m = config.app_config.get_bool("radar", "hide_contacts_below_0_2m") update_interval = config.app_config.get_float("radar", "update_interval") bullseye_num_rings = config.app_config.get_int("radar", "bullseye_num_rings") bullseye_ring_distance = config.app_config.get_int("radar", "bullseye_ring_distance") @@ -1083,6 +1084,15 @@ def settings_tab_radar(self): if center_changed: changed = True + hide_contacts_changed, _ = create_checkbox( + "Hide Contacts <0.2M", + hide_contacts_below_0_2m, + "radar", + "hide_contacts_below_0_2m" + ) + if hide_contacts_changed: + changed = True + imgui.separator() create_slider_float("Radar Update Interval", update_interval, 0.0, 5.0, "radar", "update_interval") imgui.separator()