Skip to content

Commit 24b58db

Browse files
committed
Merge pull request #479 from SamuelCho/hud_lock_fix_for_issue_456
My attempt to fix the HUD lock scoping issues raised by issue #456.
2 parents 7e9a798 + 2ddee36 commit 24b58db

File tree

2 files changed

+32
-59
lines changed

2 files changed

+32
-59
lines changed

code/hud/hudlock.cpp

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
vec3d lock_world_pos;
3636

3737
static float Lock_start_dist;
38-
static int Rotate_time_id = 1; // timer id for controlling how often to rotate triangles around lock indicator
3938

4039
int Missile_track_loop = -1;
4140
int Missile_lock_loop = -1;
@@ -68,9 +67,6 @@ int Lock_gauge_half_h[GR_NUM_RESOLUTIONS] = {
6867
25
6968
};
7069

71-
int Lock_gauge_loaded = 0;
72-
int Lock_gauge_draw = 0;
73-
int Lock_gauge_draw_stamp = -1;
7470
#define LOCK_GAUGE_BLINK_RATE 5 // blinks/sec
7571

7672
int Lockspin_half_w[NUM_HUD_RETICLE_STYLES][GR_NUM_RESOLUTIONS] = {
@@ -106,43 +102,6 @@ void hud_init_missile_lock()
106102
Player_ai->current_target_is_locked = 0;
107103

108104
Player_ai->last_secondary_index = -1;
109-
110-
Rotate_time_id = 1;
111-
112-
// Load in the frames need for the lead indicator
113-
//if (!Lock_gauge_loaded) {
114-
//Commented out due to changes in HUD loading behaviour. These checks are no longer needed at this point.
115-
116-
Lock_gauge_loaded = 1;
117-
118-
Lock_gauge_draw_stamp = -1;
119-
Lock_gauge_draw = 0;
120-
//}
121-
}
122-
123-
void hud_draw_diamond(int x, int y, int width, int height)
124-
{
125-
Assert(height>0);
126-
Assert(width>0);
127-
128-
int x1,x2,x3,x4,y1,y2,y3,y4;
129-
130-
x1=x;
131-
y1=y-height/2;
132-
133-
x2=x+width/2;
134-
y2=y;
135-
136-
x3=x;
137-
y3=y+height/2;
138-
139-
x4=x-width/2;
140-
y4=y;
141-
142-
gr_line(x1,y1,x2,y2);
143-
gr_line(x2,y2,x3,y3);
144-
gr_line(x3,y3,x4,y4);
145-
gr_line(x4,y4,x1,y1);
146105
}
147106

148107
HudGaugeLock::HudGaugeLock():
@@ -197,6 +156,10 @@ void HudGaugeLock::initialize()
197156
Lock_gauge_draw_stamp = -1;
198157
Lock_gauge_draw = 0;
199158
Rotate_time_id = 1;
159+
Last_lock_status = false;
160+
161+
Lock_anim.time_elapsed = 0.0f;
162+
Lock_gauge.time_elapsed = 0.0f;
200163

201164
HudGauge::initialize();
202165
}
@@ -211,6 +174,15 @@ void HudGaugeLock::render(float frametime)
211174
object *targetp;
212175
vertex lock_point;
213176

177+
bool locked = Player_ai->current_target_is_locked ? true : false;
178+
bool reset_timers = false;
179+
180+
if ( locked != Last_lock_status ) {
181+
// check if player lock status has changed since the last frame.
182+
reset_timers = true;
183+
Last_lock_status = locked;
184+
}
185+
214186
if (Player_ai->target_objnum == -1) {
215187
return;
216188
}
@@ -264,26 +236,27 @@ void HudGaugeLock::render(float frametime)
264236

265237
// show the rotating triangles if target is locked
266238
renderLockTriangles(sx, sy, frametime);
239+
240+
if ( reset_timers ) {
241+
Lock_gauge.time_elapsed = 0.0f;
242+
}
267243
} else {
268244
const float scaling_factor = (gr_screen.clip_center_x < gr_screen.clip_center_y) ? (gr_screen.clip_center_x / VIRTUAL_FRAME_HALF_WIDTH) : (gr_screen.clip_center_y / VIRTUAL_FRAME_HALF_HEIGHT);
269245
sx = fl2i(lock_point.screen.xyw.x) - fl2i(i2fl(Player->current_target_sx - Players[Player_num].lock_indicator_x) * scaling_factor);
270246
sy = fl2i(lock_point.screen.xyw.y) - fl2i(i2fl(Player->current_target_sy - Players[Player_num].lock_indicator_y) * scaling_factor);
271247
gr_unsize_screen_pos(&sx, &sy);
272-
}
273248

274-
// show locked indicator
275-
/*
276-
if ( Lock_gauge.first_frame >= 0 ) {
277-
gr_set_bitmap(Lock_gauge.first_frame);
278-
gr_aabitmap(sx - Lock_gauge_half_w[gr_screen.res], sy - Lock_gauge_half_h[gr_screen.res]);
279-
} else {
280-
hud_draw_diamond(sx, sy, Lock_target_box_width[gr_screen.res], Lock_target_box_height[gr_screen.res]);
249+
if ( reset_timers ) {
250+
Lock_gauge_draw_stamp = -1;
251+
Lock_gauge_draw = 0;
252+
Lock_anim.time_elapsed = 0.0f;
253+
}
281254
}
282-
*/
255+
283256
Lock_gauge.sx = sx - Lock_gauge_half_w;
284257
Lock_gauge.sy = sy - Lock_gauge_half_h;
285-
if(Player_ai->current_target_is_locked){
286-
Lock_gauge.time_elapsed = 0.0f;
258+
259+
if (Player_ai->current_target_is_locked) {
287260
hud_anim_render(&Lock_gauge, 0.0f, 1);
288261
} else {
289262
hud_anim_render(&Lock_gauge, frametime, 1);
@@ -320,12 +293,6 @@ void hud_lock_reset(float lock_time_scale)
320293
Player->locking_on_center=0;
321294
Player->locking_subsys_parent=-1;
322295
hud_stop_looped_locking_sounds();
323-
324-
Lock_gauge_draw_stamp = -1;
325-
Lock_gauge_draw = 0;
326-
327-
// reset the lock anim time elapsed
328-
// Lock_anim.time_elapsed = 0.0f;
329296
}
330297

331298
// Determine if the locking code has a point to track
@@ -727,7 +694,11 @@ void HudGaugeLock::renderLockTriangles(int center_x, int center_y, float frameti
727694
// maybe draw the anim
728695
Lock_gauge.time_elapsed = 0.0f;
729696
if(Lock_gauge_draw){
730-
hud_anim_render(&Lock_anim, frametime, 1, 0, 1);
697+
if ( loop_locked_anim ) {
698+
hud_anim_render(&Lock_anim, frametime, 1, 1, 0);
699+
} else {
700+
hud_anim_render(&Lock_anim, frametime, 1, 0, 1);
701+
}
731702
}
732703
}
733704
}

code/hud/hudlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class HudGaugeLock: public HudGauge
4343
int Rotate_time_id;
4444
int Lock_gauge_draw_stamp;
4545
int Lock_gauge_draw;
46+
47+
bool Last_lock_status;
4648
public:
4749
HudGaugeLock();
4850
void initBitmaps(char *lock_gauge_fname, char *lock_anim_fname);

0 commit comments

Comments
 (0)