2
0
mirror of https://github.com/rehlds/rehlds.git synced 2024-12-29 08:05:50 +03:00

Merge pull request #412 from dreamstalker/fixes201703193

Add and use netsrc_s size.
This commit is contained in:
Lev 2017-03-19 22:36:21 +05:00 committed by GitHub
commit a4d2cd722f
2 changed files with 20 additions and 19 deletions

View File

@ -16,12 +16,13 @@
#ifndef ENUMS_H #ifndef ENUMS_H
#define ENUMS_H #define ENUMS_H
// Used as array indexer
typedef enum netsrc_s typedef enum netsrc_s
{ {
NS_CLIENT, NS_CLIENT = 0,
NS_SERVER, NS_SERVER,
NS_MULTICAST // xxxMO NS_MULTICAST, // xxxMO
NS_MAX
} netsrc_t; } netsrc_t;
#endif #endif

View File

@ -35,7 +35,7 @@ CRITICAL_SECTION net_cs;
qboolean net_thread_initialized; qboolean net_thread_initialized;
loopback_t loopbacks[2]; loopback_t loopbacks[2];
packetlag_t g_pLagData[3]; // List of lag structures, if fakelag is set. packetlag_t g_pLagData[NS_MAX]; // List of lag structures, if fakelag is set.
float gFakeLag; float gFakeLag;
int net_configured; int net_configured;
#ifdef _WIN32 #ifdef _WIN32
@ -63,21 +63,21 @@ netadr_t in_from;
#endif #endif
#ifndef HOOK_ENGINE #ifndef HOOK_ENGINE
SOCKET ip_sockets[3] = { INV_SOCK, INV_SOCK, INV_SOCK }; SOCKET ip_sockets[NS_MAX] = { INV_SOCK, INV_SOCK, INV_SOCK };
#else #else
SOCKET ip_sockets[3]; SOCKET ip_sockets[NS_MAX];
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifndef HOOK_ENGINE #ifndef HOOK_ENGINE
SOCKET ipx_sockets[3] = { INV_SOCK, INV_SOCK, INV_SOCK }; SOCKET ipx_sockets[NS_MAX] = { INV_SOCK, INV_SOCK, INV_SOCK };
#else #else
SOCKET ipx_sockets[3]; SOCKET ipx_sockets[NS_MAX];
#endif #endif
#endif // _WIN32 #endif // _WIN32
LONGPACKET gNetSplit; LONGPACKET gNetSplit;
net_messages_t *messages[3]; net_messages_t *messages[NS_MAX];
net_messages_t *normalqueue; net_messages_t *normalqueue;
//void *hNetThread; //void *hNetThread;
//int32 dwNetThreadId; //int32 dwNetThreadId;
@ -775,7 +775,7 @@ qboolean NET_LagPacket(qboolean newdata, netsrc_t sock, netadr_t *from, sizebuf_
packetlag_t *pPacket; packetlag_t *pPacket;
float curtime; float curtime;
int ninterval; int ninterval;
static int losscount[3]; static int losscount[NS_MAX];
if (gFakeLag <= 0.0) if (gFakeLag <= 0.0)
{ {
@ -1087,7 +1087,7 @@ DLL_EXPORT int NET_Sleep_Timeout(void)
{ {
SOCKET number = 0; SOCKET number = 0;
for (int sock = 0; sock < 3; sock++) for (int sock = 0; sock < NS_MAX; sock++)
{ {
SOCKET net_socket = ip_sockets[sock]; SOCKET net_socket = ip_sockets[sock];
if (net_socket != INV_SOCK) if (net_socket != INV_SOCK)
@ -1108,12 +1108,12 @@ DLL_EXPORT int NET_Sleep_Timeout(void)
number = net_socket; number = net_socket;
} }
#endif // _WIN32 #endif // _WIN32
} }
res = select((int)(number + 1), &fdset, 0, 0, &tv); res = select((int)(number + 1), &fdset, NULL, NULL, &tv);
} }
else else
{ {
res = select(0, 0, 0, 0, &tv); res = select(0, NULL, NULL, NULL, &tv);
} }
--numFrames; --numFrames;
return res; return res;
@ -1128,7 +1128,7 @@ int NET_Sleep(void)
FD_ZERO(&fdset); FD_ZERO(&fdset);
number = 0; number = 0;
for (int sock = 0; sock < 3; sock++) for (int sock = 0; sock < NS_MAX; sock++)
{ {
SOCKET net_socket = ip_sockets[sock]; SOCKET net_socket = ip_sockets[sock];
if (net_socket != INV_SOCK) if (net_socket != INV_SOCK)
@ -1154,7 +1154,7 @@ int NET_Sleep(void)
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 20 * 1000; tv.tv_usec = 20 * 1000;
return select((int)(number + 1), &fdset, 0, 0, net_sleepforever == 0 ? &tv : NULL); return select((int)(number + 1), &fdset, NULL, NULL, net_sleepforever == 0 ? &tv : NULL);
} }
void NET_StartThread(void) void NET_StartThread(void)
@ -1306,7 +1306,7 @@ void NET_AllocateQueues(void)
void NET_FlushQueues(void) void NET_FlushQueues(void)
{ {
for (int i = 0; i < 3; i++) for (int i = 0; i < NS_MAX; i++)
{ {
net_messages_t *p = messages[i]; net_messages_t *p = messages[i];
while (p) while (p)
@ -1919,7 +1919,7 @@ void NET_Config(qboolean multiplayer)
{ {
NET_ThreadLock(); NET_ThreadLock();
for (int sock = 0; sock < 3; sock++) for (int sock = 0; sock < NS_MAX; sock++)
{ {
if (ip_sockets[sock] != INV_SOCK) if (ip_sockets[sock] != INV_SOCK)
{ {
@ -2041,7 +2041,7 @@ void NET_Init(void)
in_message.flags = 0; in_message.flags = 0;
in_message.buffername = "in_message"; in_message.buffername = "in_message";
for (int i = 0; i < 3; i++) for (int i = 0; i < NS_MAX; i++)
{ {
g_pLagData[i].pPrev = &g_pLagData[i]; g_pLagData[i].pPrev = &g_pLagData[i];
g_pLagData[i].pNext = &g_pLagData[i]; g_pLagData[i].pNext = &g_pLagData[i];