Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
fix threading ownership errors
fix packet timings
  • Loading branch information
mastercoms committed Oct 12, 2020
1 parent 527df23 commit e76ec1a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
4 changes: 2 additions & 2 deletions engine/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2243,13 +2243,13 @@ void CL_Move(float accumulated_extra_samples, bool bFinalTick )
// use full update rate when active
float commandInterval = cl_cmdinterval->GetFloat();
float maxDelta = min ( host_state.interval_per_tick, commandInterval );
float delta = clamp( (float)(net_time - cl.m_flNextCmdTime), 0.0f, maxDelta );
double delta = clamp<double>( net_time - cl.m_flNextCmdTime, 0.0, (double)maxDelta );
cl.m_flNextCmdTime = net_time + commandInterval - delta;
}
else
{
// during signon process send only 5 packets/second
cl.m_flNextCmdTime = net_time + ( 1.0f / 5.0f );
cl.m_flNextCmdTime = net_time + ( 1.0 / 5.0 );
}

}
Expand Down
15 changes: 11 additions & 4 deletions engine/net_chan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ bool CNetChan::CanPacket () const
return false;
}

return m_fClearTime < net_time;
return m_fClearTime - net_time < 0.001;
}

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

FlowUpdate( FLOW_OUTGOING, nTotalSize );


// UNDONE(mastercoms): clear time should be in wall time
#if 0
if ( m_fClearTime < net_time )
{
m_fClearTime = net_time;
}
#endif

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

double fAddTime = ((double)nTotalSize + (double)nSplitPacketSize * (double)nSplitPackets) / m_Rate;

m_fClearTime += fAddTime;

Expand Down
13 changes: 1 addition & 12 deletions engine/net_ws.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,6 @@ typedef struct
char buffer[ NET_MAX_MESSAGE ]; // This has to be big enough to hold the largest message
} LONGPACKET;

// Use this to pick apart the network stream, must be packed
#pragma pack(1)
typedef struct
{
int netID;
int sequenceNumber;
int packetID : 16;
int nSplitSize : 16;
} SPLITPACKET;
#pragma pack()

#define MIN_USER_MAXROUTABLE_SIZE 576 // ( X.25 Networks )
#define MAX_USER_MAXROUTABLE_SIZE MAX_ROUTABLE_PAYLOAD

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

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

int ret = 0;
int ret;

// 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.
// Linux threads aren't prioritized well enough for this to work well (i.e. the queued packet thread doesn't get enough
Expand Down
11 changes: 11 additions & 0 deletions engine/net_ws_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ typedef int SOCKET;
#include "cl_rcon.h"
#endif

// Use this to pick apart the network stream, must be packed
#pragma pack(1)
typedef struct
{
int netID;
int sequenceNumber;
int packetID : 16;
int nSplitSize : 16;
} SPLITPACKET;
#pragma pack()

#if defined( _X360 )
#include "xbox/xbox_win32stubs.h"
#endif
Expand Down
2 changes: 1 addition & 1 deletion game/shared/tf/tf_player_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10470,7 +10470,7 @@ float CTFPlayer::TeamFortress_CalculateMaxSpeed( bool bIgnoreSpecialAbility /*=
CALL_ATTRIB_HOOK_FLOAT( maxfbspeed, mult_player_movespeed_shieldrequired );
}

if ( m_Shared.GetActiveTFWeapon()->GetLastDeployTime() <= gpGlobals->curtime )
if ( m_Shared.GetActiveTFWeapon() && m_Shared.GetActiveTFWeapon()->GetLastDeployTime() <= gpGlobals->curtime )
{
CALL_ATTRIB_HOOK_FLOAT(maxfbspeed, mult_player_movespeed_active);
}
Expand Down
12 changes: 7 additions & 5 deletions public/tier0/threadtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ class PLATFORM_CLASS CThreadMutex
#ifdef _WIN32
std::atomic<unsigned long> m_ownerID{0};
#else
std::atomic<uint> m_ownerID{ 0 };
std::atomic<uint> m_ownerID{0};
#endif
};

Expand Down Expand Up @@ -1543,12 +1543,14 @@ template<class T> class CMessageQueue

inline bool CThreadMutex::TryLock()
{
if (!AssertOwnedByCurrentThread() && m_Mutex.try_lock())
if (!AssertOwnedByCurrentThread())
{
m_ownerID = ThreadGetCurrentId();
return true;
if (m_Mutex.try_lock())
{
m_ownerID = ThreadGetCurrentId();
return true;
}
}
DebuggerBreak();
return false;
}

Expand Down

0 comments on commit e76ec1a

Please sign in to comment.