Skip to content

Commit 8303f93

Browse files
author
newby
committed
Ensure negative offsets can't be emitted.
Small inconsistencies between client time and server time can result in minute negative offsets that can stop the sound from playing.
1 parent d32c186 commit 8303f93

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

csqc/csextradefs.qc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,17 +449,16 @@ class CsGrenTimer {
449449
float primed_at_;
450450
float expires_at_;
451451
float flags_;
452-
float channel_;
453452
float grentype_;
454453

455454
nonvirtual float() active { return expires_at_ > time; };
456455
nonvirtual float() expiry { return expires_at_; };
457456
nonvirtual float() grentype { return grentype_; };
458457
nonvirtual void() set_thrown { flags_ |= FL_GT_THROWN; };
459458
nonvirtual float() is_thrown { return flags_ & FL_GT_THROWN; };
460-
nonvirtual float() channel { return channel_; };
461459
nonvirtual float() sound_offset {
462-
return 3.8 - (expires_at_ - time);
460+
float offset = max(3.8 - (expires_at_ - time), 0);
461+
return offset;
463462
};
464463

465464
nonvirtual void(float primed_at, float expires_at,
@@ -470,11 +469,8 @@ class CsGrenTimer {
470469
static CsGrenTimer last_;
471470

472471
static void() Init {
473-
float num_gren_sound = CHAN_GREN_END - CHAN_GREN_START + 1;
474472
for (float i = 0; i < grentimers.length; i++)
475-
grentimers[i] = spawn(CsGrenTimer,
476-
entnum: 10000 + i,
477-
channel_: CHAN_GREN_START + (i % num_gren_sound));
473+
grentimers[i] = spawn(CsGrenTimer);
478474
};
479475

480476
static void() StopAll {

csqc/events.qc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ void ParseGrenPrimed(float grentype, float primed_at, float explodes_at) {
420420
float expires_new = timer.expiry();
421421
float expires_ideal = explodes_at - ping/2;
422422

423-
print(sprintf("primed_at=%0.2f explodes_at=%0.2f fuse=%0.2f new_s=%d\n",
423+
print(sprintf("primed_at=%0.2f explodes_at=%0.2f fuse=%0.2f new=%d\n",
424424
primed_at, explodes_at, explodes_at - primed_at,
425425
debug_use_new_sound));
426426
print(sprintf("ideal=%0.2f new=%0.2f old=%0.2f\n",

0 commit comments

Comments
 (0)