d_net.c -> d_net.cpp

This commit is contained in:
Eidolon 2024-11-16 22:47:33 -06:00
parent 6cffe744e6
commit 6ffdeb6c44
2 changed files with 12 additions and 10 deletions

View file

@ -6,7 +6,7 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32
string.c string.c
d_main.cpp d_main.cpp
d_clisrv.c d_clisrv.c
d_net.c d_net.cpp
d_netfil.c d_netfil.c
d_netcmd.c d_netcmd.c
dehacked.c dehacked.c

View file

@ -9,7 +9,7 @@
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details. // See the 'LICENSE' file for more details.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// \file d_net.c /// \file d_net.cpp
/// \brief SRB2 network game communication and protocol, all OS independent parts. /// \brief SRB2 network game communication and protocol, all OS independent parts.
// //
/// Implement a Sliding window protocol without receiver window /// Implement a Sliding window protocol without receiver window
@ -17,6 +17,8 @@
/// This protocol uses a mix of "goback n" and "selective repeat" implementation /// This protocol uses a mix of "goback n" and "selective repeat" implementation
/// The NOTHING packet is sent when connection is idle to acknowledge packets /// The NOTHING packet is sent when connection is idle to acknowledge packets
#include <algorithm>
#include "doomdef.h" #include "doomdef.h"
#include "g_game.h" #include "g_game.h"
#include "i_time.h" #include "i_time.h"
@ -200,7 +202,7 @@ static netnode_t nodes[MAXNETNODES];
// mnemonic: to use it compare to 0: cmpack(a,b)<0 is "a < b" ... // mnemonic: to use it compare to 0: cmpack(a,b)<0 is "a < b" ...
FUNCMATH static INT32 cmpack(UINT8 a, UINT8 b) FUNCMATH static INT32 cmpack(UINT8 a, UINT8 b)
{ {
register INT32 d = a - b; INT32 d = a - b;
if (d >= 127 || d < -128) if (d >= 127 || d < -128)
return -d; return -d;
@ -757,7 +759,7 @@ static void fprintfstring(char *s, size_t len)
for (i = 0; i < len; i += 16) for (i = 0; i < len; i += 16)
{ {
fprintf(debugfile, "%10s: ", sizeu1(i)); fprintf(debugfile, "%10s: ", sizeu1(i));
fprintfline(&s[i], min(len - i, 16)); fprintfline(&s[i], std::min<size_t>(len - i, 16));
} }
} }
@ -919,7 +921,7 @@ static void DebugPrintpacket(const char *header)
fprintf(debugfile, " reason %s\n", netbuffer->u.serverrefuse.reason); fprintf(debugfile, " reason %s\n", netbuffer->u.serverrefuse.reason);
break; break;
case PT_FILEFRAGMENT: { case PT_FILEFRAGMENT: {
filetx_pak *pak = (void*)&netbuffer->u.filetxpak; filetx_pak *pak = (filetx_pak*)&netbuffer->u.filetxpak;
fprintf(debugfile, " fileid %d datasize %d position %u\n", fprintf(debugfile, " fileid %d datasize %d position %u\n",
pak->fileid, (UINT16)SHORT(pak->size), pak->fileid, (UINT16)SHORT(pak->size),
(UINT32)LONG(pak->position)); (UINT32)LONG(pak->position));
@ -1308,7 +1310,7 @@ SINT8 I_NetMakeNode(const char *hostname)
void D_SetDoomcom(void) void D_SetDoomcom(void)
{ {
if (doomcom) return; if (doomcom) return;
doomcom = Z_Calloc(sizeof (doomcom_t), PU_STATIC, NULL); doomcom = (doomcom_t*)Z_Calloc(sizeof (doomcom_t), PU_STATIC, NULL);
doomcom->id = DOOMCOM_ID; doomcom->id = DOOMCOM_ID;
doomcom->numslots = doomcom->numnodes = 1; doomcom->numslots = doomcom->numnodes = 1;
doomcom->gametype = 0; doomcom->gametype = 0;
@ -1445,8 +1447,8 @@ struct pingcell
static int pingcellcmp(const void *va, const void *vb) static int pingcellcmp(const void *va, const void *vb)
{ {
const struct pingcell *a, *b; const struct pingcell *a, *b;
a = va; a = (struct pingcell*)va;
b = vb; b = (struct pingcell*)vb;
return ( a->ms - b->ms ); return ( a->ms - b->ms );
} }