From def75287ebca682ed66147e05260efac2c850ad7 Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Mon, 27 Nov 2023 23:15:45 -0500 Subject: [PATCH] convert radar timestamps to new system Also convert true/false variables to boolean. --- code/radar/radar.cpp | 30 ++++++++--------- code/radar/radardradis.cpp | 67 ++++++++++++++++++++------------------ code/radar/radardradis.h | 8 ++--- code/radar/radarorb.cpp | 30 ++++++++--------- code/radar/radarsetup.cpp | 27 ++++++++------- code/radar/radarsetup.h | 18 +++++----- 6 files changed, 92 insertions(+), 88 deletions(-) diff --git a/code/radar/radar.cpp b/code/radar/radar.cpp index 8df57ab5012..344260c1230 100644 --- a/code/radar/radar.cpp +++ b/code/radar/radar.cpp @@ -81,8 +81,8 @@ void HudGaugeRadarStd::blipDrawFlicker(blip *b, int x, int y) } if ( timestamp_elapsed(Radar_flicker_timer[flicker_index]) ) { - Radar_flicker_timer[flicker_index] = timestamp_rand(50,1000); - Radar_flicker_on[flicker_index] ^= 1; + Radar_flicker_timer[flicker_index] = _timestamp_rand(50,1000); + Radar_flicker_on[flicker_index] = !Radar_flicker_on[flicker_index]; } if ( !Radar_flicker_on[flicker_index] ) { @@ -299,20 +299,20 @@ void HudGaugeRadarStd::render(float /*frametime*/) // note that on lowest skill level, there is no radar effects due to sensors damage if ( ((Game_skill_level == 0) || (sensors_str > SENSOR_STR_RADAR_NO_EFFECTS)) && !Sensor_static_forced ) { - Radar_static_playing = 0; - Radar_static_next = 0; - Radar_death_timer = 0; - Radar_avail_prev_frame = 1; + Radar_static_playing = false; + Radar_static_next = TIMESTAMP::never(); + Radar_death_timer = TIMESTAMP::never(); + Radar_avail_prev_frame = true; } else if ( sensors_str < MIN_SENSOR_STR_TO_RADAR ) { if ( Radar_avail_prev_frame ) { - Radar_death_timer = timestamp(2000); - Radar_static_next = 1; + Radar_death_timer = _timestamp(2000); + Radar_static_next = TIMESTAMP::immediate(); } - Radar_avail_prev_frame = 0; + Radar_avail_prev_frame = false; } else { - Radar_death_timer = 0; - if ( Radar_static_next == 0 ) - Radar_static_next = 1; + Radar_death_timer = TIMESTAMP::never(); + if ( Radar_static_next.isNever() ) + Radar_static_next = TIMESTAMP::immediate(); } if ( timestamp_elapsed(Radar_death_timer) ) { @@ -324,13 +324,13 @@ void HudGaugeRadarStd::render(float /*frametime*/) drawRange(); if ( timestamp_elapsed(Radar_static_next) ) { - Radar_static_playing ^= 1; - Radar_static_next = timestamp_rand(50, 750); + Radar_static_playing = !Radar_static_playing; + Radar_static_next = _timestamp_rand(50, 750); } // if the emp effect is active, always draw the radar wackily if(emp_active_local()){ - Radar_static_playing = 1; + Radar_static_playing = true; } if ( ok_to_blit_radar ) { diff --git a/code/radar/radardradis.cpp b/code/radar/radardradis.cpp index e8ba12cb305..50b3dda1e83 100644 --- a/code/radar/radardradis.cpp +++ b/code/radar/radardradis.cpp @@ -130,16 +130,19 @@ void HudGaugeRadarDradis::plotBlip(blip* b, vec3d *pos, float *alpha) } } - b->time_since_update += flFrametime; // If the blip has been pinged by the local x-axis sweep, update if (std::abs(vm_vec_dot(&sweep_normal_x, pos)) < 0.01f) { - b->time_since_update = 0.0f; + b->last_update = _timestamp(); } - *alpha = ((sweep_duration - b->time_since_update)/sweep_duration)*fade_multi/2.0f; - - if (*alpha < 0.0f) { + if (b->last_update.isNever()) { *alpha = 0.0f; + } else { + *alpha = ((sweep_duration - timestamp_since(b->last_update)) / sweep_duration) * fade_multi / 2.0f; + + if (*alpha < 0.0f) { + *alpha = 0.0f; + } } } @@ -234,8 +237,8 @@ void HudGaugeRadarDradis::blipDrawFlicker(blip *b, vec3d *pos, float alpha) if (timestamp_elapsed(Radar_flicker_timer[flicker_index])) { - Radar_flicker_timer[flicker_index] = timestamp_rand(50,1000); - Radar_flicker_on[flicker_index] ^= 1; + Radar_flicker_timer[flicker_index] = _timestamp_rand(50,1000); + Radar_flicker_on[flicker_index] = !Radar_flicker_on[flicker_index]; } if (!Radar_flicker_on[flicker_index]) @@ -499,28 +502,28 @@ void HudGaugeRadarDradis::render(float /*frametime*/) // note that on lowest skill level, there is no radar effects due to sensors damage if ( ((Game_skill_level == 0) || (sensors_str > SENSOR_STR_RADAR_NO_EFFECTS)) && !Sensor_static_forced ) { - Radar_static_playing = 0; - Radar_static_next = 0; - Radar_death_timer = 0; - Radar_avail_prev_frame = 1; + Radar_static_playing = false; + Radar_static_next = TIMESTAMP::never(); + Radar_death_timer = TIMESTAMP::never(); + Radar_avail_prev_frame = true; } else if (sensors_str < MIN_SENSOR_STR_TO_RADAR) { if (Radar_avail_prev_frame) { - Radar_death_timer = timestamp(2000); - Radar_static_next = 1; + Radar_death_timer = _timestamp(2000); + Radar_static_next = TIMESTAMP::immediate(); } - Radar_avail_prev_frame = 0; + Radar_avail_prev_frame = false; } else { - Radar_death_timer = 0; + Radar_death_timer = TIMESTAMP::never(); - if (Radar_static_next == 0) - Radar_static_next = 1; + if (Radar_static_next.isNever()) + Radar_static_next = TIMESTAMP::immediate(); } if (timestamp_elapsed(Radar_death_timer)) @@ -537,13 +540,13 @@ void HudGaugeRadarDradis::render(float /*frametime*/) if (timestamp_elapsed(Radar_static_next)) { - Radar_static_playing ^= 1; - Radar_static_next = timestamp_rand(50, 750); + Radar_static_playing = !Radar_static_playing; + Radar_static_next = _timestamp_rand(50, 750); } // if the emp effect is active, always draw the radar wackily if (emp_active_local()) - Radar_static_playing = 1; + Radar_static_playing = true; if (ok_to_blit_radar) { @@ -620,7 +623,7 @@ void HudGaugeRadarDradis::doBeeps() if (!arrival_beep_snd.isValid() && !departure_beep_snd.isValid() && - !m_stealth_arrival_snd.isValid() && + !stealth_arrival_snd.isValid() && !stealth_departure_snd.isValid()) { return; @@ -672,13 +675,13 @@ void HudGaugeRadarDradis::doBeeps() { snd_play(gamesnd_get_game_sound(arrival_beep_snd)); - arrival_beep_next_check = timestamp(arrival_beep_delay); + arrival_beep_next_check = _timestamp(arrival_beep_delay); } - else if (m_stealth_arrival_snd.isValid() && stealth_arrival_happened) + else if (stealth_arrival_snd.isValid() && stealth_arrival_happened) { - snd_play(gamesnd_get_game_sound(m_stealth_arrival_snd)); + snd_play(gamesnd_get_game_sound(stealth_arrival_snd)); - arrival_beep_next_check = timestamp(arrival_beep_delay); + arrival_beep_next_check = _timestamp(arrival_beep_delay); } } @@ -689,18 +692,18 @@ void HudGaugeRadarDradis::doBeeps() { snd_play(gamesnd_get_game_sound(departure_beep_snd)); - departure_beep_next_check = timestamp(departure_beep_delay); + departure_beep_next_check = _timestamp(departure_beep_delay); } else if (stealth_departure_snd.isValid() && stealth_departure_happened) { snd_play(gamesnd_get_game_sound(stealth_departure_snd)); - departure_beep_next_check = timestamp(departure_beep_delay); + departure_beep_next_check = _timestamp(departure_beep_delay); } } } -void HudGaugeRadarDradis::initSound(gamesnd_id loop_snd, float _loop_snd_volume, gamesnd_id arrival_snd, gamesnd_id departure_snd, gamesnd_id stealth_arrival_snd, gamesnd_id stealth_departue_snd, float arrival_delay, float departure_delay) +void HudGaugeRadarDradis::initSound(gamesnd_id loop_snd, float _loop_snd_volume, gamesnd_id arrival_snd, gamesnd_id departure_snd, gamesnd_id _stealth_arrival_snd, gamesnd_id _stealth_departure_snd, float arrival_delay, float departure_delay) { this->m_loop_snd = loop_snd; this->loop_sound_handle = sound_handle::invalid(); @@ -709,8 +712,8 @@ void HudGaugeRadarDradis::initSound(gamesnd_id loop_snd, float _loop_snd_volume, this->arrival_beep_snd = arrival_snd; this->departure_beep_snd = departure_snd; - this->m_stealth_arrival_snd = stealth_arrival_snd; - this->stealth_departure_snd = stealth_departue_snd; + this->stealth_arrival_snd = _stealth_arrival_snd; + this->stealth_departure_snd = _stealth_departure_snd; this->arrival_beep_delay = fl2i(arrival_delay * 1000.0f); this->departure_beep_delay = fl2i(departure_delay * 1000.0f); @@ -729,8 +732,8 @@ void HudGaugeRadarDradis::initialize() { HudGaugeRadar::initialize(); - this->arrival_beep_next_check = timestamp(); - this->departure_beep_next_check = timestamp(); + this->arrival_beep_next_check = _timestamp(); + this->departure_beep_next_check = _timestamp(); } bool HudGaugeRadarDradis::shouldDoSounds() diff --git a/code/radar/radardradis.h b/code/radar/radardradis.h index c2deea81589..831793dce6b 100644 --- a/code/radar/radardradis.h +++ b/code/radar/radardradis.h @@ -55,20 +55,20 @@ class HudGaugeRadarDradis: public HudGaugeRadar gamesnd_id arrival_beep_snd; gamesnd_id departure_beep_snd; - gamesnd_id m_stealth_arrival_snd; + gamesnd_id stealth_arrival_snd; gamesnd_id stealth_departure_snd; int arrival_beep_delay; int departure_beep_delay; - int arrival_beep_next_check; - int departure_beep_next_check; + TIMESTAMP arrival_beep_next_check; + TIMESTAMP departure_beep_next_check; protected: bool shouldDoSounds(); public: HudGaugeRadarDradis(); void initBitmaps(char* fname_xy, char* fname_xz_yz, char* fname_sweep, char* fname_target_brackets, char* fname_unknown); - void initSound(gamesnd_id loop_snd, float _loop_sound_volume, gamesnd_id arrival_snd, gamesnd_id departue_snd, gamesnd_id stealth_arrival_snd, gamesnd_id stealth_departue_snd, float arrival_delay, float departure_delay); + void initSound(gamesnd_id loop_snd, float _loop_sound_volume, gamesnd_id arrival_snd, gamesnd_id departure_snd, gamesnd_id _stealth_arrival_snd, gamesnd_id _stealth_departure_snd, float arrival_delay, float departure_delay); void blipDrawDistorted(blip *b, vec3d *pos, float alpha); void blipDrawFlicker(blip *b, vec3d *pos, float alpha); diff --git a/code/radar/radarorb.cpp b/code/radar/radarorb.cpp index ebc8163883b..ec708ad6b94 100644 --- a/code/radar/radarorb.cpp +++ b/code/radar/radarorb.cpp @@ -209,8 +209,8 @@ void HudGaugeRadarOrb::blipDrawFlicker(blip *b, vec3d *pos) } if ( timestamp_elapsed(Radar_flicker_timer[flicker_index]) ) { - Radar_flicker_timer[flicker_index] = timestamp_rand(50,1000); - Radar_flicker_on[flicker_index] ^= 1; + Radar_flicker_timer[flicker_index] = _timestamp_rand(50,1000); + Radar_flicker_on[flicker_index] = !Radar_flicker_on[flicker_index]; } if ( !Radar_flicker_on[flicker_index] ) { @@ -400,20 +400,20 @@ void HudGaugeRadarOrb::render(float /*frametime*/) // note that on lowest skill level, there is no radar effects due to sensors damage if (((Game_skill_level == 0) || (sensors_str > SENSOR_STR_RADAR_NO_EFFECTS)) && !Sensor_static_forced) { - Radar_static_playing = 0; - Radar_static_next = 0; - Radar_death_timer = 0; - Radar_avail_prev_frame = 1; + Radar_static_playing = false; + Radar_static_next = TIMESTAMP::never(); + Radar_death_timer = TIMESTAMP::never(); + Radar_avail_prev_frame = true; } else if ( sensors_str < MIN_SENSOR_STR_TO_RADAR ) { if ( Radar_avail_prev_frame ) { - Radar_death_timer = timestamp(2000); - Radar_static_next = 1; + Radar_death_timer = _timestamp(2000); + Radar_static_next = TIMESTAMP::immediate(); } - Radar_avail_prev_frame = 0; + Radar_avail_prev_frame = false; } else { - Radar_death_timer = 0; - if ( Radar_static_next == 0 ) - Radar_static_next = 1; + Radar_death_timer = TIMESTAMP::never(); + if ( Radar_static_next.isNever() ) + Radar_static_next = TIMESTAMP::immediate(); } if ( timestamp_elapsed(Radar_death_timer) ) { @@ -428,13 +428,13 @@ void HudGaugeRadarOrb::render(float /*frametime*/) drawOutlinesHtl(); if ( timestamp_elapsed(Radar_static_next) ) { - Radar_static_playing ^= 1; - Radar_static_next = timestamp_rand(50, 750); + Radar_static_playing = !Radar_static_playing; + Radar_static_next = _timestamp_rand(50, 750); } // if the emp effect is active, always draw the radar wackily if(emp_active_local()){ - Radar_static_playing = 1; + Radar_static_playing = true; } if ( ok_to_blit_radar ) { diff --git a/code/radar/radarsetup.cpp b/code/radar/radarsetup.cpp index 9bbdc1df869..3c324e18890 100644 --- a/code/radar/radarsetup.cpp +++ b/code/radar/radarsetup.cpp @@ -78,7 +78,7 @@ blip Blips[MAX_BLIPS]; // blips pool int N_blips; // next blip index to take from pool float Radar_bright_range; // range at which we start dimming the radar blips -int Radar_calc_bright_dist_timer; // timestamp at which we recalc Radar_bright_range +TIMESTAMP Radar_calc_bright_dist_timer; // timestamp at which we recalc Radar_bright_range extern int radar_iff_color[5][2][4]; @@ -264,7 +264,7 @@ void radar_plot_object( object *objp ) // determine the range within which the radar blip is bright if (timestamp_elapsed(Radar_calc_bright_dist_timer)) { - Radar_calc_bright_dist_timer = timestamp(1000); + Radar_calc_bright_dist_timer = _timestamp(1000); Radar_bright_range = player_farthest_weapon_range(); if (Radar_bright_range <= 0) Radar_bright_range = 1500.0f; @@ -280,6 +280,7 @@ void radar_plot_object( object *objp ) } b = &Blips[N_blips]; + b->rad = 0; b->flags = 0; // bright if within range @@ -300,12 +301,14 @@ void radar_plot_object( object *objp ) list_append(&Blip_dim_list[blip_type], b); b->position = pos; - b->dist = dist; - b->objp = objp; b->radar_image_2d = -1; b->radar_color_image_2d = -1; b->radar_image_size = -1; b->radar_projection_size = 1.0f; + b->last_update = TIMESTAMP::never(); + b->dist = dist; + b->objp = objp; + // see if blip should be drawn distorted // also determine if alternate image was defined for this ship @@ -353,7 +356,7 @@ void radar_mission_init() } } - Radar_calc_bright_dist_timer = timestamp(0); + Radar_calc_bright_dist_timer = TIMESTAMP::immediate(); } void radar_null_nblips() @@ -437,15 +440,15 @@ void HudGaugeRadar::initialize() { int i; - Radar_death_timer = 0; - Radar_static_playing = 0; - Radar_static_next = 0; - Radar_avail_prev_frame = 1; - Radar_calc_bright_dist_timer = timestamp(0); + Radar_death_timer = TIMESTAMP::never(); + Radar_static_playing = false; + Radar_static_next = TIMESTAMP::never(); + Radar_avail_prev_frame = true; + Radar_calc_bright_dist_timer = TIMESTAMP::immediate(); for ( i=0; i