2
0
mirror of https://github.com/rehlds/rehlds.git synced 2025-02-27 14:01:18 +03:00

Merge pull request #383 from In-line/FixNetSleep_Timeout

Refactor NET_Sleep_Timeout
This commit is contained in:
theAsmodai 2017-03-02 01:18:32 +03:00 committed by GitHub
commit b9f88c1de8

View File

@ -1053,17 +1053,12 @@ qboolean NET_QueuePacket(netsrc_t sock)
DLL_EXPORT int NET_Sleep_Timeout(void) DLL_EXPORT int NET_Sleep_Timeout(void)
{ {
fd_set fdset;
struct timeval tv;
int number;
int fps;
static int32 lasttime; static int32 lasttime;
static int numFrames; static int numFrames;
static int staggerFrames; static int staggerFrames;
int32 curtime;
fps = (int)sys_ticrate.value; int fps = (int)sys_ticrate.value;
curtime = (int)Sys_FloatTime(); int32 curtime = (int)Sys_FloatTime();
if (lasttime) if (lasttime)
{ {
if (curtime - lasttime > 1) if (curtime - lasttime > 1)
@ -1078,8 +1073,19 @@ DLL_EXPORT int NET_Sleep_Timeout(void)
lasttime = curtime; lasttime = curtime;
} }
fd_set fdset;
FD_ZERO(&fdset); FD_ZERO(&fdset);
number = 0;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = (1000 / fps) * 1000; // TODO: entirely bad code, fix it completely
if (tv.tv_usec <= 0)
tv.tv_usec = 1;
int res;
if (numFrames > 0 && numFrames % staggerFrames)
{
int number = 0;
for (int sock = 0; sock < 3; sock++) for (int sock = 0; sock < 3; sock++)
{ {
@ -1103,15 +1109,6 @@ DLL_EXPORT int NET_Sleep_Timeout(void)
} }
#endif // _WIN32 #endif // _WIN32
} }
tv.tv_sec = 0;
tv.tv_usec = (1000 / fps) * 1000; // entirely bad code, later I will fix it completely
if (tv.tv_usec <= 0)
tv.tv_usec = 1;
int res;
if (numFrames > 0 && numFrames % staggerFrames)
{
res = select(number + 1, &fdset, 0, 0, &tv); res = select(number + 1, &fdset, 0, 0, &tv);
} }
else else