Skip to content

Commit da9bc09

Browse files
committed
bug fixes
sound improvements spread improvements
1 parent b4a632d commit da9bc09

File tree

10 files changed

+77
-88
lines changed

10 files changed

+77
-88
lines changed

engine/audio/private/snd_dma.cpp

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static ConVar volume( "volume", "1.0", FCVAR_ARCHIVE | FCVAR_ARCHIVE_XBOX, "Soun
461461
// user configurable music volume
462462
ConVar snd_musicvolume( "snd_musicvolume", "1.0", FCVAR_ARCHIVE | FCVAR_ARCHIVE_XBOX, "Music volume", true, 0.0f, true, 1.0f );
463463

464-
ConVar snd_mixahead( "snd_mixahead", "0.05");
464+
ConVar snd_mixahead( "snd_mixahead", "0.04");
465465
ConVar snd_mix_async( "snd_mix_async", "0" );
466466
#ifdef _DEBUG
467467
static ConCommand snd_mixvol("snd_mixvol", MXR_DebugSetMixGroupVolume, "Set named Mixgroup to mix volume.");
@@ -6547,61 +6547,49 @@ void S_Update_Guts( float mixAheadTime )
65476547
}
65486548

65496549
#if !defined( _X360 )
6550-
#define THREADED_MIX_TIME 7
6550+
#define THREADED_MIX_TIME 0.001
65516551
#else
6552-
#define THREADED_MIX_TIME XMA_POLL_RATE
6552+
#define THREADED_MIX_TIME XMA_POLL_RATE * 0.001
65536553
#endif
6554-
#define THREADED_MIX_TIME_S (THREADED_MIX_TIME) * 0.001f
65556554

65566555
ConVar snd_ShowThreadFrameTime( "snd_ShowThreadFrameTime", "0" );
65576556

65586557
bool g_bMixThreadExit;
65596558
ThreadHandle_t g_hMixThread;
65606559
void S_Update_Thread()
65616560
{
6562-
float frameTime = THREADED_MIX_TIME_S;
6563-
double lastFrameTime = Plat_FloatTime();
6561+
double frameTime = THREADED_MIX_TIME;
65646562

65656563
while ( !g_bMixThreadExit )
65666564
{
6567-
#ifdef _X360
6568-
float t0 = Plat_FloatTime();
6569-
#endif
6565+
const double t0 = Plat_FloatTime();
65706566
S_Update_Guts(frameTime + snd_mixahead.GetFloat());
6571-
#ifdef _X360
6567+
const double tf = Plat_FloatTime();
65726568

6573-
// mixing (for 360) needs to be updated at a steady rate
6574-
// large update times causes the mixer to demand more audio data
6575-
// the 360 decoder has finite latency and cannot fulfill spike requests
6576-
float tf = Plat_FloatTime();
6577-
float dt = tf - t0;
6578-
float nextFrameTime = tf + THREADED_MIX_TIME_S - dt;
6579-
int updateTime = (int)dt * 1000;
6569+
const double dt = tf - t0;
6570+
const double fWaitTime = THREADED_MIX_TIME - dt;
6571+
const double fWaitEnd = tf + fWaitTime;
65806572

65816573
// try to maintain a steadier rate by compensating for fluctuating mix times
6582-
// leave 1 ms for tighter timings in loop
6583-
int sleepTime = THREADED_MIX_TIME - updateTime - 1;
6584-
if ( sleepTime > 0 )
6574+
// leave 2 ms for tighter timings in loop
6575+
const int nSleepMS = (int) ((THREADED_MIX_TIME - dt) * 1000 - 2);
6576+
if ( nSleepMS > 0 )
65856577
{
6586-
ThreadSleep( sleepTime );
6578+
ThreadSleep( nSleepMS );
65876579
}
65886580

6589-
while (Plat_FloatTime() < nextFrameTime)
6581+
while (Plat_FloatTime() < fWaitEnd)
65906582
{
65916583
ThreadSleep();
65926584
}
6593-
#else
6594-
// Give up our time slice
6595-
ThreadSleep();
6596-
#endif
6585+
65976586
// mimic a frametime needed for sound update
6598-
double t1 = Plat_FloatTime();
6599-
frameTime = t1 - lastFrameTime;
6600-
lastFrameTime = t1;
6587+
const double t1 = Plat_FloatTime();
6588+
frameTime = t1 - tf;
66016589

66026590
if ( snd_ShowThreadFrameTime.GetBool() )
66036591
{
6604-
Msg( "S_Update_Thread: frameTime: %d ms\n", (int)( frameTime * 1000.0f ) );
6592+
Msg( "S_Update_Thread: frameTime: %f s\n", frameTime );
66056593
}
66066594
}
66076595
}

engine/audio/private/snd_win.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ IAudioDevice *IAudioDevice::AutoDetectInit( bool waveOnly )
8181
if ( snd_firsttime )
8282
{
8383
pDevice = Audio_CreateDirectSoundDevice();
84+
if (pDevice)
85+
{
86+
S_EnableThreadedMixing(true);
87+
}
8488
}
8589
}
8690

engine/baseclient.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ bool CBaseClient::SendServerInfo( void )
686686

687687
// supporting smaller stack
688688
net_scratchbuffer_t scratch;
689-
690689
bf_write msg( "SV_SendServerinfo->msg", scratch.GetBuffer(), NET_MAX_PAYLOAD );
691690

692691
// Only send this message to developer console, or multiplayer clients.
@@ -752,15 +751,12 @@ bool CBaseClient::SendServerInfo( void )
752751
// send server info as one data block
753752
if ( !m_NetChannel->SendData( msg ) )
754753
{
755-
MemFreeScratch();
756754
Disconnect("Server info data overflow");
757755
return false;
758756
}
759757

760758
COM_TimestampedLog( " CBaseClient::SendServerInfo(finished)" );
761759

762-
MemFreeScratch();
763-
764760
return true;
765761
}
766762

@@ -1151,6 +1147,8 @@ void CBaseClient::TraceNetworkMsg( int nBits, char const *fmt, ... )
11511147
m_Trace.m_Records.AddToTail( t );
11521148
}
11531149

1150+
static ConVar sv_multiplayer_maxtempentities("sv_multiplayer_maxtempentities", "32");
1151+
11541152
void CBaseClient::SendSnapshot( CClientFrame *pFrame )
11551153
{
11561154
// never send the same snapshot twice
@@ -1174,24 +1172,34 @@ void CBaseClient::SendSnapshot( CClientFrame *pFrame )
11741172

11751173
bool bFailedOnce = false;
11761174
write_again:
1177-
bf_write msg( "CBaseClient::SendSnapshot", m_SnapshotScratchBuffer, sizeof( m_SnapshotScratchBuffer ) );
1175+
net_scratchbuffer_t scratch;
1176+
bf_write msg("CBaseClient::SendSnapshot",
1177+
scratch.GetBuffer(), scratch.Size());
11781178

11791179
TRACE_PACKET( ( "SendSnapshot(%d)\n", pFrame->tick_count ) );
11801180

11811181
// now create client snapshot packet
1182-
CClientFrame *deltaFrame = GetDeltaFrame( m_nDeltaTick ); // NULL if delta_tick is not found
1182+
CClientFrame* deltaFrame = m_nDeltaTick < 0 ? NULL : GetDeltaFrame(m_nDeltaTick); // NULL if delta_tick is not found
11831183
if ( !deltaFrame )
11841184
{
11851185
// We need to send a full update and reset the instanced baselines
11861186
OnRequestFullUpdate();
11871187
}
11881188

1189-
// send tick time
1190-
NET_Tick tickmsg( pFrame->tick_count, host_frametime_unbounded, host_frametime_stddeviation );
1191-
1192-
StartTrace( msg );
1189+
if (IsTracing())
1190+
{
1191+
StartTrace(msg);
1192+
}
11931193

1194-
tickmsg.WriteToBuffer( msg );
1194+
// send tick time
1195+
{
1196+
NET_Tick tickmsg(pFrame->tick_count, host_frametime_unbounded, host_frametime_stddeviation);
1197+
if (!tickmsg.WriteToBuffer(msg))
1198+
{
1199+
Disconnect("#GameUI_Disconnect_TickMessage");
1200+
return;
1201+
}
1202+
}
11951203

11961204
if ( IsTracing() )
11971205
{
@@ -1223,8 +1231,8 @@ void CBaseClient::SendSnapshot( CClientFrame *pFrame )
12231231
}
12241232

12251233
// send all unreliable temp entities between last and current frame
1226-
// send max 64 events in multi player, 255 in SP
1227-
int nMaxTempEnts = m_Server->IsMultiplayer() ? 64 : 255;
1234+
// send max 32 events in multi player, 255 in SP
1235+
int nMaxTempEnts = m_Server->IsMultiplayer() ? sv_multiplayer_maxtempentities.GetInt() : 255;
12281236
m_Server->WriteTempEntities( this, pFrame->GetSnapshot(), m_pLastSnapshot.GetObject(), msg, nMaxTempEnts );
12291237

12301238
if ( IsTracing() )

engine/baseclient.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,6 @@ class CBaseClient : public IGameEventListener2, public IClient, public IClientMe
274274
// Default time to wait for next message
275275
float m_fSnapshotInterval;
276276

277-
enum
278-
{
279-
SNAPSHOT_SCRATCH_BUFFER_SIZE = 160000,
280-
};
281-
282-
unsigned int m_SnapshotScratchBuffer[ SNAPSHOT_SCRATCH_BUFFER_SIZE / 4 ];
283-
284277
private:
285278
void StartTrace( bf_write &msg );
286279
void EndTrace( bf_write &msg );

engine/bugreporter.cpp

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,41 +2687,28 @@ void CBugUIPanel::OnKeyCodePressed(KeyCode code)
26872687
// Load game-specific bug reporter defaults as params
26882688
void CBugUIPanel::ParseDefaultParams( void )
26892689
{
2690-
const char *szDefaults = "scripts/bugreporter_defaults.txt";
2691-
2692-
FileHandle_t hLocal = g_pFileSystem->Open( szDefaults, "rb" );
2693-
if ( FILESYSTEM_INVALID_HANDLE == hLocal )
2690+
CUtlBuffer buffer(0, 0, CUtlBuffer::TEXT_BUFFER);
2691+
if (!g_pFileSystem->ReadFile("scripts/bugreporter_defaults.txt", NULL, buffer))
26942692
{
26952693
return;
26962694
}
26972695

2698-
// load file into a null-terminated buffer
2699-
int fileSize = g_pFileSystem->Size(hLocal);
2700-
char *buffer = (char*)MemAllocScratch(fileSize + 1);
2701-
2702-
Assert(buffer);
2703-
2704-
g_pFileSystem->Read(buffer, fileSize, hLocal); // read into local buffer
2705-
buffer[fileSize] = 0; // null terminate file as EOF
2706-
g_pFileSystem->Close( hLocal ); // close file after reading
2707-
2708-
char token[64];
2709-
const char *pfile = COM_ParseFile(buffer, token, sizeof( token ) );
2710-
2711-
while ( pfile )
2696+
char token[256];
2697+
const char* pfile = COM_ParseFile((const char*)buffer.Base(), token, sizeof(token));
2698+
while (pfile)
27122699
{
2713-
bool success = AutoFillToken( token, false );
2714-
if ( !success )
2700+
bool success = AutoFillToken(token, false);
2701+
if (!success)
27152702
{
27162703
// Try partials
2717-
success = AutoFillToken( token, true );
2718-
if ( !success )
2704+
success = AutoFillToken(token, true);
2705+
if (!success)
27192706
{
2720-
Msg( "Unable to determine where to set default bug parameter '%s', ignoring...\n", token );
2707+
Msg("Unable to determine where to set default bug parameter '%s', ignoring...\n", token);
27212708
}
27222709
}
27232710

2724-
pfile = COM_ParseFile(pfile, token, sizeof( token ) );
2711+
pfile = COM_ParseFile(pfile, token, sizeof(token));
27252712
}
27262713
}
27272714

engine/sv_client.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,14 @@ void CGameClient::WriteGameSounds( bf_write &buf )
837837
}
838838
}
839839

840+
static ConVar sv_multiplayer_maxsounds("sv_multiplayer_sounds", "20");
841+
840842
int CGameClient::FillSoundsMessage(SVC_Sounds &msg)
841843
{
842844
int i, count = m_Sounds.Count();
843845

844-
// send max 64 sound in multiplayer per snapshot, 255 in SP
845-
int max = m_Server->IsMultiplayer() ? 32 : 255;
846+
// send max 20 sound in multiplayer per snapshot, 255 in SP
847+
int max = m_Server->IsMultiplayer() ? sv_multiplayer_maxsounds.GetInt() : 255;
846848

847849
// Discard events if we have too many to signal with 8 bits
848850
if ( count > max )
@@ -852,7 +854,7 @@ int CGameClient::FillSoundsMessage(SVC_Sounds &msg)
852854
if ( !count )
853855
return 0;
854856

855-
SoundInfo_t defaultSound; defaultSound.SetDefault();
857+
SoundInfo_t defaultSound;
856858
SoundInfo_t *pDeltaSound = &defaultSound;
857859

858860
msg.m_nNumSounds = count;

engine/sys_engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ void CEngine::Frame( void )
363363
ThreadSleep(nSleepMS);
364364
}
365365

366-
while (Sys_FloatTime() < fWaitEnd)
366+
while (Plat_FloatTime() < fWaitEnd)
367367
{
368368
ThreadSleep();
369369
}

game/client/c_baseentity.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,13 +908,13 @@ C_BaseEntity::C_BaseEntity() :
908908
// but that re-introduces a third-person hitching bug. One possible cause is the abrupt change
909909
// in player size/position that occurs when ducking, and how prediction tries to work through that.
910910
//
911-
AddVar( &m_vecVelocity, &m_iv_vecVelocity, LATCH_SIMULATION_VAR );
911+
//AddVar( &m_vecVelocity, &m_iv_vecVelocity, LATCH_SIMULATION_VAR );
912912

913913
m_DataChangeEventRef = -1;
914914
m_EntClientFlags = 0;
915915

916916
m_iParentAttachment = 0;
917-
m_nRenderFXBlend = 0;
917+
m_nRenderFXBlend = 255;
918918

919919
SetPredictionEligible( false );
920920
m_bPredictable = false;

game/shared/tf/tf_fx_shared.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void FX_FireBullets( CTFWeaponBase *pWpn, int iPlayer, const Vector &vecOrigin,
349349
{
350350
if (bFixedRecoilSpread)
351351
{
352-
iSeed = pWpn->m_iConsecutiveShots;
352+
iSeed = 200 + pWpn->m_iConsecutiveShots;
353353
}
354354
}
355355

@@ -375,7 +375,7 @@ void FX_FireBullets( CTFWeaponBase *pWpn, int iPlayer, const Vector &vecOrigin,
375375
float flScalar;
376376
if (!bSpreadNormal && pWpn)
377377
{
378-
flScalar = clamp(pWpn->m_iConsecutiveShots + 1, 1, 6) * 0.5f;
378+
flScalar = clamp(pWpn->m_iConsecutiveShots + 1, 1, 6) * 0.25f;
379379
}
380380
else
381381
{

public/soundinfo.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
#define SOUND_SEQNUMBER_BITS 10
6464
#define SOUND_SEQNUMBER_MASK ( (1<<SOUND_SEQNUMBER_BITS) - 1 )
6565

66-
// offset sound delay encoding by 60ms since we encode negative sound delays with less precision
67-
// This means any negative sound delay greater than -100ms will get encoded at full precision
68-
#define SOUND_DELAY_OFFSET (0.100f)
66+
// offset sound delay encoding by 15ms since we encode negative sound delays with less precision
67+
// This means any negative sound delay greater than -15ms will get encoded at full precision
68+
#define SOUND_DELAY_OFFSET (0.015f)
6969

7070
#pragma pack(4)
7171
//-----------------------------------------------------------------------------
@@ -91,10 +91,17 @@ struct SoundInfo_t
9191
int nSpeakerEntity;
9292

9393
//---------------------------------
94-
95-
SoundInfo_t()
94+
enum SoundInfoInit_t
95+
{
96+
SOUNDINFO_SETDEFAULT,
97+
SOUNDINFO_NO_SETDEFAULT,
98+
};
99+
SoundInfo_t(SoundInfoInit_t Init = SOUNDINFO_SETDEFAULT )
96100
{
97-
SetDefault();
101+
if (Init == SOUNDINFO_SETDEFAULT)
102+
{
103+
SetDefault();
104+
}
98105
}
99106

100107
void Set(int newEntity, int newChannel, const char *pszNewName, const Vector &newOrigin, const Vector& newDirection,

0 commit comments

Comments
 (0)