added IS_LOOP_DRIVER macro and made the confusing loop driver checks

more readable. from uhexen2.

git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@488 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2011-09-20 18:05:51 +00:00
parent 0da8a9c5aa
commit 5fac2b24de
2 changed files with 25 additions and 18 deletions

View file

@ -217,6 +217,9 @@ typedef struct
extern net_driver_t net_drivers[MAX_NET_DRIVERS];
extern int net_numdrivers;
/* Loop driver must always be registered the first */
#define IS_LOOP_DRIVER(p) ((p) == 0)
extern int net_driverlevel;
extern int messagesSent;

View file

@ -68,13 +68,6 @@ cvar_t hostname = {"hostname", "UNNAMED"};
#define sfunc net_drivers[sock->driver]
#define dfunc net_drivers[net_driverlevel]
/* NOTE: several sock->driver checks in the code serve the
purpose of ignoring local connections, because the loop
driver always takes number 0: it is the first member in
the net_drivers[] array. If you ever change that, such
as by removing the loop driver, you must re-visit those
checks and adjust them properly!. */
int net_driverlevel;
double net_time;
@ -311,7 +304,7 @@ static void Slist_Send (void *unused)
{
for (net_driverlevel = 0; net_driverlevel < net_numdrivers; net_driverlevel++)
{
if (!slistLocal && net_driverlevel == 0)
if (!slistLocal && IS_LOOP_DRIVER(net_driverlevel))
continue;
if (net_drivers[net_driverlevel].initialized == false)
continue;
@ -327,7 +320,7 @@ static void Slist_Poll (void *unused)
{
for (net_driverlevel = 0; net_driverlevel < net_numdrivers; net_driverlevel++)
{
if (!slistLocal && net_driverlevel == 0)
if (!slistLocal && IS_LOOP_DRIVER(net_driverlevel))
continue;
if (net_drivers[net_driverlevel].initialized == false)
continue;
@ -455,7 +448,7 @@ qsocket_t *NET_CheckNewConnections (void)
{
if (net_drivers[net_driverlevel].initialized == false)
continue;
if (net_driverlevel && listening == false)
if (!IS_LOOP_DRIVER(net_driverlevel) && listening == false)
continue;
ret = dfunc.CheckNewConnections ();
if (ret)
@ -518,7 +511,7 @@ int NET_GetMessage (qsocket_t *sock)
ret = sfunc.QGetMessage(sock);
// see if this connection has timed out
if (ret == 0 && sock->driver)
if (ret == 0 && !IS_LOOP_DRIVER(sock->driver))
{
if (net_time - sock->lastMessageTime > net_messagetimeout.value)
{
@ -529,7 +522,7 @@ int NET_GetMessage (qsocket_t *sock)
if (ret > 0)
{
if (sock->driver)
if (!IS_LOOP_DRIVER(sock->driver))
{
sock->lastMessageTime = net_time;
if (ret == 1)
@ -569,7 +562,7 @@ int NET_SendMessage (qsocket_t *sock, sizebuf_t *data)
SetNetTime();
r = sfunc.QSendMessage(sock, data);
if (r == 1 && sock->driver)
if (r == 1 && !IS_LOOP_DRIVER(sock->driver))
messagesSent++;
return r;
@ -591,7 +584,7 @@ int NET_SendUnreliableMessage (qsocket_t *sock, sizebuf_t *data)
SetNetTime();
r = sfunc.SendUnreliableMessage(sock, data);
if (r == 1 && sock->driver)
if (r == 1 && !IS_LOOP_DRIVER(sock->driver))
unreliableMessagesSent++;
return r;
@ -637,7 +630,7 @@ int NET_SendToAll (sizebuf_t *data, double blocktime)
*/
if (host_client->netconnection && host_client->active)
{
if (host_client->netconnection->driver == 0) /* Loop */
if (IS_LOOP_DRIVER(host_client->netconnection->driver))
{
NET_SendMessage(host_client->netconnection, data);
msg_init[i] = true;
@ -715,6 +708,7 @@ void NET_Init (void)
i = COM_CheckParm ("-udpport");
if (!i)
i = COM_CheckParm ("-ipxport");
if (i)
{
if (i < com_argc-1)
@ -724,11 +718,11 @@ void NET_Init (void)
}
net_hostport = DEFAULTnet_hostport;
if (COM_CheckParm("-listen") || cls.state == ca_dedicated)
listening = true;
net_numsockets = svs.maxclientslimit;
if (cls.state != ca_dedicated)
net_numsockets++;
if (COM_CheckParm("-listen") || cls.state == ca_dedicated)
listening = true;
SetNetTime();
@ -762,13 +756,23 @@ void NET_Init (void)
net_drivers[net_driverlevel].Listen (true);
}
if (i == 0 && cls.state == ca_dedicated)
/* Loop_Init() returns -1 for dedicated server case,
* therefore the i == 0 check is correct */
if (i == 0
&& cls.state == ca_dedicated
)
{
Sys_Error("Network not available!");
}
if (*my_ipx_address)
{
Con_DPrintf("IPX address %s\n", my_ipx_address);
}
if (*my_tcpip_address)
{
Con_DPrintf("TCP/IP address %s\n", my_tcpip_address);
}
}
/*