clean up d_net
This commit is contained in:
1 parent
89856bf5b2
commit
f8515f697e
2 files changed
+16
-66
No files matched your search
+13
-63
@@ -213,10 +213,9 @@ FUNCMATH static inline INT32 cmpack(UINT8 a, UINT8 b)
|
||||
/** Sets freeack to a free acknum and copies the netbuffer in the ackpak table
|
||||
*
|
||||
* \param freeack The address to store the free acknum at
|
||||
* \param lowtimer ???
|
||||
* \return True if a free acknum was found
|
||||
*/
|
||||
static boolean GetFreeAcknum(UINT8 *freeack, boolean lowtimer)
|
||||
static boolean GetFreeAcknum(UINT8 *freeack)
|
||||
{
|
||||
node_t *node = &nodes[doomcom->remotenode];
|
||||
INT32 i, numfreeslot = 0;
|
||||
@@ -245,17 +244,8 @@ static boolean GetFreeAcknum(UINT8 *freeack, boolean lowtimer)
|
||||
node->nextacknum++;
|
||||
ackpak[i].destinationnode = (UINT8)(node - nodes);
|
||||
ackpak[i].length = doomcom->datalength;
|
||||
if (lowtimer)
|
||||
{
|
||||
// Lowtime means can't be sent now so try it as soon as possible
|
||||
ackpak[i].senttime = 0;
|
||||
ackpak[i].resentnum = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ackpak[i].senttime = I_GetTime();
|
||||
ackpak[i].resentnum = 0;
|
||||
}
|
||||
ackpak[i].senttime = I_GetTime();
|
||||
ackpak[i].resentnum = 0;
|
||||
M_Memcpy(ackpak[i].pak.raw, netbuffer, ackpak[i].length);
|
||||
|
||||
*freeack = ackpak[i].acknum;
|
||||
@@ -272,38 +262,6 @@ static boolean GetFreeAcknum(UINT8 *freeack, boolean lowtimer)
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Counts how many acks are free
|
||||
*
|
||||
* \param urgent True if the type of the packet meant to
|
||||
* use an ack is lower than PT_CANFAIL
|
||||
* If for some reason you don't want use it
|
||||
* for any packet type in particular,
|
||||
* just set to false
|
||||
* \return The number of free acks
|
||||
*
|
||||
*/
|
||||
INT32 Net_GetFreeAcks(boolean urgent)
|
||||
{
|
||||
INT32 i, numfreeslot = 0;
|
||||
INT32 n = 0; // Number of free acks found
|
||||
|
||||
for (i = 0; i < MAXACKPACKETS; i++)
|
||||
if (!ackpak[i].acknum)
|
||||
{
|
||||
// For low priority packets, make sure to let freeslots so urgent packets can be sent
|
||||
if (!urgent)
|
||||
{
|
||||
numfreeslot++;
|
||||
if (numfreeslot <= URGENTFREESLOTNUM)
|
||||
continue;
|
||||
}
|
||||
|
||||
n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// Get a ack to send in the queue of this node
|
||||
static UINT8 GetAcktosend(INT32 node)
|
||||
{
|
||||
@@ -321,10 +279,10 @@ static void RemoveAck(INT32 i)
|
||||
}
|
||||
|
||||
// We have got a packet, proceed the ack request and ack return
|
||||
static int Processackpak(void)
|
||||
static boolean Processackpak(void)
|
||||
{
|
||||
INT32 i;
|
||||
int goodpacket = 0;
|
||||
boolean goodpacket = true;
|
||||
node_t *node = &nodes[doomcom->remotenode];
|
||||
|
||||
// Received an ack return, so remove the ack in the list
|
||||
@@ -333,7 +291,7 @@ static int Processackpak(void)
|
||||
node->remotefirstack = netbuffer->ackreturn;
|
||||
// Search the ackbuffer and free it
|
||||
for (i = 0; i < MAXACKPACKETS; i++)
|
||||
if (ackpak[i].acknum && ackpak[i].destinationnode == node - nodes
|
||||
if (ackpak[i].acknum && ackpak[i].destinationnode == doomcom->remotenode
|
||||
&& cmpack(ackpak[i].acknum, netbuffer->ackreturn) <= 0)
|
||||
{
|
||||
RemoveAck(i);
|
||||
@@ -349,7 +307,7 @@ static int Processackpak(void)
|
||||
{
|
||||
DEBFILE(va("Discard(1) ack %d (duplicated)\n", ack));
|
||||
duppacket++;
|
||||
goodpacket = 1; // Discard packet (duplicate)
|
||||
goodpacket = false; // Discard packet (duplicate)
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -359,10 +317,10 @@ static int Processackpak(void)
|
||||
{
|
||||
DEBFILE(va("Discard(2) ack %d (duplicated)\n", ack));
|
||||
duppacket++;
|
||||
goodpacket = 1; // Discard packet (duplicate)
|
||||
goodpacket = false; // Discard packet (duplicate)
|
||||
break;
|
||||
}
|
||||
if (goodpacket == 0)
|
||||
if (goodpacket)
|
||||
{
|
||||
// Is a good packet so increment the acknowledge number,
|
||||
// Then search for a "hole" in the queue
|
||||
@@ -423,13 +381,13 @@ static int Processackpak(void)
|
||||
else // Buffer full discard packet, sender will resend it
|
||||
{ // We can admit the packet but we will not detect the duplication after :(
|
||||
DEBFILE("no more freeackret\n");
|
||||
goodpacket = 2;
|
||||
goodpacket = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// return values: 0 = ok, 1 = duplicate, 2 = out of order
|
||||
|
||||
return goodpacket;
|
||||
}
|
||||
#endif
|
||||
@@ -1083,7 +1041,7 @@ boolean HSendPacket(INT32 node, boolean reliable, UINT8 acknum, size_t packetlen
|
||||
netbuffer->ackreturn = 0;
|
||||
if (reliable)
|
||||
{
|
||||
if (!GetFreeAcknum(&netbuffer->ack, false))
|
||||
if (!GetFreeAcknum(&netbuffer->ack))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -1156,7 +1114,6 @@ boolean HGetPacket(void)
|
||||
while(true)
|
||||
{
|
||||
//nodejustjoined = I_NetGet();
|
||||
int goodpacket;
|
||||
I_NetGet();
|
||||
|
||||
if (doomcom->remotenode == -1) // No packet received
|
||||
@@ -1201,15 +1158,8 @@ boolean HGetPacket(void)
|
||||
}*/
|
||||
|
||||
// Proceed the ack and ackreturn field
|
||||
goodpacket = Processackpak();
|
||||
if (goodpacket != 0)
|
||||
{
|
||||
// resend the ACK in case the previous ACK didn't reach the client.
|
||||
// prevents the client's netbuffer from locking up.
|
||||
if (goodpacket == 1)
|
||||
Net_SendAcks(doomcom->remotenode);
|
||||
if (!Processackpak())
|
||||
continue; // discarded (duplicated)
|
||||
}
|
||||
|
||||
// A packet with just ackreturn
|
||||
if (netbuffer->packettype == PT_NOTHING)
|
||||
|
||||
+3
-3
@@ -18,6 +18,8 @@
|
||||
#ifndef __D_NET__
|
||||
#define __D_NET__
|
||||
|
||||
#include "doomtype.h"
|
||||
|
||||
// Max computers in a game
|
||||
// 127 is probably as high as this can go, because
|
||||
// SINT8 is used for nodes sometimes >:(
|
||||
@@ -45,12 +47,10 @@ extern boolean nodeingame[MAXNETNODES]; // Set false as nodes leave game
|
||||
|
||||
extern boolean serverrunning;
|
||||
|
||||
INT32 Net_GetFreeAcks(boolean urgent);
|
||||
void Net_AckTicker(void);
|
||||
|
||||
// If reliable return true if packet sent, 0 else
|
||||
boolean HSendPacket(INT32 node, boolean reliable, UINT8 acknum,
|
||||
size_t packetlength);
|
||||
boolean HSendPacket(INT32 node, boolean reliable, UINT8 acknum, size_t packetlength);
|
||||
boolean HGetPacket(void);
|
||||
void D_SetDoomcom(void);
|
||||
#ifndef NONET
|
||||
|
||||
Reference in new issue
Block a user