Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/config/defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 12 additions & 2 deletions src/draw/imgui_radar_labels_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down
6 changes: 5 additions & 1 deletion src/game_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions src/render_data_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/tests/test_render_data_arrays_fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/ui/imgui_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand Down