Skip to content

Commit

Permalink
convert radar timestamps to new system
Browse files Browse the repository at this point in the history
Also convert true/false variables to boolean.
  • Loading branch information
Goober5000 committed Nov 28, 2023
1 parent 369b90a commit def7528
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 88 deletions.
30 changes: 15 additions & 15 deletions code/radar/radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) {
Expand Down Expand Up @@ -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) ) {
Expand All @@ -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 ) {
Expand Down
67 changes: 35 additions & 32 deletions code/radar/radardradis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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))
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

}
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions code/radar/radardradis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions code/radar/radarorb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) {
Expand Down Expand Up @@ -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) ) {
Expand All @@ -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 ) {
Expand Down
27 changes: 15 additions & 12 deletions code/radar/radarsetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand All @@ -280,6 +280,7 @@ void radar_plot_object( object *objp )
}

b = &Blips[N_blips];
b->rad = 0;
b->flags = 0;

// bright if within range
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<NUM_FLICKER_TIMERS; i++ ) {
Radar_flicker_timer[i]=timestamp(0);
Radar_flicker_on[i]=0;
Radar_flicker_timer[i]=TIMESTAMP::immediate();
Radar_flicker_on[i]=false;
}

HudGauge::initialize();
Expand Down
Loading

0 comments on commit def7528

Please sign in to comment.