Skip to content

Commit e76ec1a

Browse files
committed
fix crash
fix threading ownership errors fix packet timings
1 parent 527df23 commit e76ec1a

File tree

6 files changed

+33
-24
lines changed

6 files changed

+33
-24
lines changed

engine/cl_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,13 +2243,13 @@ void CL_Move(float accumulated_extra_samples, bool bFinalTick )
22432243
// use full update rate when active
22442244
float commandInterval = cl_cmdinterval->GetFloat();
22452245
float maxDelta = min ( host_state.interval_per_tick, commandInterval );
2246-
float delta = clamp( (float)(net_time - cl.m_flNextCmdTime), 0.0f, maxDelta );
2246+
double delta = clamp<double>( net_time - cl.m_flNextCmdTime, 0.0, (double)maxDelta );
22472247
cl.m_flNextCmdTime = net_time + commandInterval - delta;
22482248
}
22492249
else
22502250
{
22512251
// during signon process send only 5 packets/second
2252-
cl.m_flNextCmdTime = net_time + ( 1.0f / 5.0f );
2252+
cl.m_flNextCmdTime = net_time + ( 1.0 / 5.0 );
22532253
}
22542254

22552255
}

engine/net_chan.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ bool CNetChan::CanPacket () const
769769
return false;
770770
}
771771

772-
return m_fClearTime < net_time;
772+
return m_fClearTime - net_time < 0.001;
773773
}
774774

775775
bool CNetChan::IsPlayback( void ) const
@@ -1833,15 +1833,22 @@ int CNetChan::SendDatagram(bf_write *datagram)
18331833
FlowNewPacket( FLOW_OUTGOING, m_nOutSequenceNr, m_nInSequenceNr, m_nChokedPackets, 0, nTotalSize );
18341834

18351835
FlowUpdate( FLOW_OUTGOING, nTotalSize );
1836-
1836+
1837+
// UNDONE(mastercoms): clear time should be in wall time
1838+
#if 0
18371839
if ( m_fClearTime < net_time )
18381840
{
18391841
m_fClearTime = net_time;
18401842
}
1843+
#endif
18411844

18421845
// calculate net_time when channel will be ready for next packet (throttling)
1843-
// TODO: This doesn't exactly match size sent when packet is a "split" packet (actual bytes sent is higher, etc.)
1844-
double fAddTime = (float)nTotalSize / (float)m_Rate;
1846+
const std::size_t nMaxRoutableSize = GetMaxRoutablePayloadSize();
1847+
const std::size_t nSplitPacketSize = sizeof(SPLITPACKET);
1848+
const std::size_t nPacketSize = (std::size_t)nTotalSize;
1849+
const std::size_t nSplitPackets = nPacketSize > nMaxRoutableSize ? nPacketSize / (nMaxRoutableSize - nSplitPacketSize) : 0;
1850+
1851+
double fAddTime = ((double)nTotalSize + (double)nSplitPacketSize * (double)nSplitPackets) / m_Rate;
18451852

18461853
m_fClearTime += fAddTime;
18471854

engine/net_ws.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,6 @@ typedef struct
134134
char buffer[ NET_MAX_MESSAGE ]; // This has to be big enough to hold the largest message
135135
} LONGPACKET;
136136

137-
// Use this to pick apart the network stream, must be packed
138-
#pragma pack(1)
139-
typedef struct
140-
{
141-
int netID;
142-
int sequenceNumber;
143-
int packetID : 16;
144-
int nSplitSize : 16;
145-
} SPLITPACKET;
146-
#pragma pack()
147-
148137
#define MIN_USER_MAXROUTABLE_SIZE 576 // ( X.25 Networks )
149138
#define MAX_USER_MAXROUTABLE_SIZE MAX_ROUTABLE_PAYLOAD
150139

@@ -2324,7 +2313,7 @@ static int NET_SendLong( INetChannel *chan, int sock, SOCKET s, const char FAR *
23242313

23252314
Q_memcpy( packet + sizeof(SPLITPACKET), sendbuf + (nPacketNumber * nSplitSizeMinusHeader), size );
23262315

2327-
int ret = 0;
2316+
int ret;
23282317

23292318
// Setting net_queued_packet_thread to NET_QUEUED_PACKET_THREAD_DEBUG_VALUE goes into a mode where all packets are queued.. can be used to stress-test it.
23302319
// Linux threads aren't prioritized well enough for this to work well (i.e. the queued packet thread doesn't get enough

engine/net_ws_headers.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ typedef int SOCKET;
8282
#include "cl_rcon.h"
8383
#endif
8484

85+
// Use this to pick apart the network stream, must be packed
86+
#pragma pack(1)
87+
typedef struct
88+
{
89+
int netID;
90+
int sequenceNumber;
91+
int packetID : 16;
92+
int nSplitSize : 16;
93+
} SPLITPACKET;
94+
#pragma pack()
95+
8596
#if defined( _X360 )
8697
#include "xbox/xbox_win32stubs.h"
8798
#endif

game/shared/tf/tf_player_shared.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10470,7 +10470,7 @@ float CTFPlayer::TeamFortress_CalculateMaxSpeed( bool bIgnoreSpecialAbility /*=
1047010470
CALL_ATTRIB_HOOK_FLOAT( maxfbspeed, mult_player_movespeed_shieldrequired );
1047110471
}
1047210472

10473-
if ( m_Shared.GetActiveTFWeapon()->GetLastDeployTime() <= gpGlobals->curtime )
10473+
if ( m_Shared.GetActiveTFWeapon() && m_Shared.GetActiveTFWeapon()->GetLastDeployTime() <= gpGlobals->curtime )
1047410474
{
1047510475
CALL_ATTRIB_HOOK_FLOAT(maxfbspeed, mult_player_movespeed_active);
1047610476
}

public/tier0/threadtools.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ class PLATFORM_CLASS CThreadMutex
671671
#ifdef _WIN32
672672
std::atomic<unsigned long> m_ownerID{0};
673673
#else
674-
std::atomic<uint> m_ownerID{ 0 };
674+
std::atomic<uint> m_ownerID{0};
675675
#endif
676676
};
677677

@@ -1543,12 +1543,14 @@ template<class T> class CMessageQueue
15431543

15441544
inline bool CThreadMutex::TryLock()
15451545
{
1546-
if (!AssertOwnedByCurrentThread() && m_Mutex.try_lock())
1546+
if (!AssertOwnedByCurrentThread())
15471547
{
1548-
m_ownerID = ThreadGetCurrentId();
1549-
return true;
1548+
if (m_Mutex.try_lock())
1549+
{
1550+
m_ownerID = ThreadGetCurrentId();
1551+
return true;
1552+
}
15501553
}
1551-
DebuggerBreak();
15521554
return false;
15531555
}
15541556

0 commit comments

Comments
 (0)