Files
modular-radar/global_data.cpp

150 lines
6.1 KiB
C++

/*
* MIT License
*
* Copyright (c) 2026 Mark Allyn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* global_data.cpp
* Author: Mark Allyn
*
* Definitions of all system-wide global variables.
* Extern declarations live in include/data_structure_and_constants.h.
*/
#include "include/data_structure_and_constants.h"
/* ============================================================
* RADAR MANAGEMENT
* Components: Thread 1 (startup, scope switching), Traffic Cop (Thread 2)
* ============================================================ */
/* radar_management[] is indexed by RADAR_* constants (0-4).
* Slot 0 (RADAR_NONE) is the management/system entry.
* Slots 1-4 are per-radar entries. operatable is set to 1 once a radar is
* fully built. available and selected are set during startup argument parsing.
* Components: Thread 1, Traffic Cop (Thread 2) */
radar_management_structure radar_management[RADAR_COUNT] = {
{ RADAR_NONE, 0, 0, 0 }, // [0] management entry
{ RADAR_CHAIN_HOME, 0, 0, 0 }, // [1] chain_home — not yet built
{ RADAR_MARINE_ASCOPE, 0, 0, 0 }, // [2] marine_ascope — not yet built
{ RADAR_MARINE_TRAFFIC, 0, 0, 0 }, // [3] marine_traffic — not yet built
{ RADAR_POLICE_BOAT, 0, 0, 0 }, // [4] police_boat — not yet built
};
// No radar selected on startup; intro screen is displayed.
// Components: Thread 1, Traffic Cop (Thread 2), all scope renderers
int current_radar = RADAR_NONE;
// Range step indices — 0 = lowest (shortest) range step for each scope.
// Incremented/decremented by the o/p keyboard handler in Thread 1.
// Chain Home is fixed-range; its index exists for consistency but is unused.
// Components: Thread 1 keyboard handler, each scope renderer
int chain_home_range_setting = 0;
int ascope_range_setting = 0;
int traffic_control_range_setting = 0;
int police_boat_range_setting = 0;
/* ============================================================
* THREAD MUTEXES
* Components: all threads as noted per mutex
* ============================================================ */
// Thread 2 -> Thread 1: target data handoff
// Components: Traffic Cop (Thread 2), Thread 1
std::mutex mutex_target_data;
// Thread 3 -> Thread 2: simulator to traffic cop
// Components: Simulator (Thread 3), Traffic Cop (Thread 2)
std::mutex mutex_simulator_to_traffic_cop;
// Thread 4 -> Thread 1: physical control panel data (not yet implemented)
// Components: Physical Controls (Thread 4), Thread 1
std::mutex mutex_control_data_to_shaders;
// Thread 5 -> Thread 2: Raspberry Pi receiver to traffic cop (not yet implemented)
// Components: Raspberry Pi Receiver (Thread 5), Traffic Cop (Thread 2)
std::mutex mutex_raspberry_pi;
/* ============================================================
* SHADER UNIFORM COPIES
* These are set by keyboard callbacks in Thread 1 and pushed to
* GLSL shader uniforms each frame render.
* Initial values are sensible defaults; adjust in include/settings.h
* as components are developed and tested.
* ============================================================ */
// Scope intensity — keyboard 3 (lower) / 4 (higher)
// GLSL uniform: float intensity
// Components: all scopes
float uniform_intensity = 1.0f;
// Receiver sensitivity — keyboard 5 (lower) / 6 (higher)
// GLSL uniform: float sensitivity
// Components: all scopes
float uniform_sensitivity = 1.0f;
// STC sensitivity for close-in targets — keyboard q (lower) / w (higher)
// GLSL uniform: float stc_sensitivity
// Components: all scopes
float uniform_stc_sensitivity = 0.5f;
// STC effective range (normalized 0-1) — keyboard e (lower) / r (higher)
// GLSL uniform: float stc_range
// Components: all scopes
float uniform_stc_range = 0.3f;
// Rain noise filter, PPI scopes only — keyboard t (decrease) / y (increase)
// GLSL uniform: float noise_filter
// Components: PPI scopes (marine traffic control, on-board boat)
float uniform_noise_filter = 0.0f;
// Chain Home radiogoniometer bearing in degrees — keyboard u (left) / i (right)
// GLSL uniform: float radiogoniometer
// Components: Chain Home A-scope
float uniform_radiogoniometer = 0.0f;
/*
* Maximum radar range in nautical miles (NOT normalized).
* Chain Home: fixed at CHAIN_HOME_MAX_RANGE_NM; o/p keys ignored.
* Others: set from the radar's step table when a radar is activated; updated by o/p.
* 0.0 is the placeholder before any radar is selected.
* GLSL uniform: float max_range
* Components: all scope renderers
*/
float uniform_max_range = 0.0f;
// Range cursor position (normalized 0-1) — keyboard a (lower) / s (higher)
// GLSL uniform: float range_cursor
// Components: PPI scopes (marine traffic control, on-board boat)
float uniform_range_cursor = 0.5f;
// Bearing cursor in degrees — keyboard d (CCW) / f (CW)
// GLSL uniform: float bearing_cursor
// Components: PPI scopes (marine traffic control, on-board boat)
float uniform_bearing_cursor = 0.0f;
// Marine A-scope antenna rotation bearing in degrees — keyboard g (CCW) / h (CW)
// GLSL uniform: float marine_a_bearing
// Components: Marine A-scope
float uniform_marine_a_bearing = 0.0f;