Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STJr
SRB2
Commits
9291416a
Commit
9291416a
authored
2 years ago
by
LJ Sonic
Browse files
Options
Downloads
Patches
Plain Diff
Split SV_SendTics into functions
parent
530a03cc
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1920
Delete netcode
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/netcode/net_command.c
+21
-0
21 additions, 0 deletions
src/netcode/net_command.c
src/netcode/net_command.h
+1
-0
1 addition, 0 deletions
src/netcode/net_command.h
src/netcode/tic_command.c
+44
-51
44 additions, 51 deletions
src/netcode/tic_command.c
with
66 additions
and
51 deletions
src/netcode/net_command.c
+
21
−
0
View file @
9291416a
...
...
@@ -304,6 +304,27 @@ void PT_TextCmd(SINT8 node, INT32 netconsole)
}
}
void
SV_WriteNetCommandsForTic
(
tic_t
tic
,
UINT8
**
buf
)
{
UINT8
*
numcmds
;
numcmds
=
(
*
buf
)
++
;
*
numcmds
=
0
;
for
(
INT32
i
=
0
;
i
<
MAXPLAYERS
;
i
++
)
{
UINT8
*
cmd
=
D_GetExistingTextcmd
(
tic
,
i
);
INT32
size
=
cmd
?
cmd
[
0
]
:
0
;
if
((
!
i
||
playeringame
[
i
])
&&
size
)
{
(
*
numcmds
)
++
;
WRITEUINT8
(
*
buf
,
i
);
M_Memcpy
(
*
buf
,
cmd
,
size
+
1
);
*
buf
+=
size
+
1
;
}
}
}
void
CL_CopyNetCommandsFromServerPacket
(
tic_t
tic
)
{
servertics_pak
*
packet
=
&
netbuffer
->
u
.
serverpak
;
...
...
This diff is collapsed.
Click to expand it.
src/netcode/net_command.h
+
1
−
0
View file @
9291416a
...
...
@@ -57,6 +57,7 @@ void ExtraDataTicker(void);
size_t
TotalTextCmdPerTic
(
tic_t
tic
);
void
PT_TextCmd
(
SINT8
node
,
INT32
netconsole
);
void
SV_WriteNetCommandsForTic
(
tic_t
tic
,
UINT8
**
buf
);
void
CL_CopyNetCommandsFromServerPacket
(
tic_t
tic
);
void
CL_SendNetCommands
(
void
);
void
SendKick
(
UINT8
playernum
,
UINT8
msg
);
...
...
This diff is collapsed.
Click to expand it.
src/netcode/tic_command.c
+
44
−
51
View file @
9291416a
...
...
@@ -298,16 +298,56 @@ void CL_SendClientCmd(void)
CL_SendNetCommands
();
}
// PT_SERVERTICS packets can grow too large for a single UDP packet,
// So this checks how many tics worth of data can be sent in one packet.
// The rest can be sent later, usually the next tic.
static
tic_t
SV_CalculateNumTicsForPacket
(
SINT8
nodenum
,
tic_t
firsttic
,
tic_t
lasttic
)
{
size_t
size
=
BASESERVERTICSSIZE
;
tic_t
tic
;
for
(
tic
=
firsttic
;
tic
<
lasttic
;
tic
++
)
{
size
+=
sizeof
(
ticcmd_t
)
*
doomcom
->
numslots
;
size
+=
TotalTextCmdPerTic
(
tic
);
if
(
size
>
software_MAXPACKETLENGTH
)
{
DEBFILE
(
va
(
"packet too large (%s) at tic %d (should be from %d to %d)
\n
"
,
sizeu1
(
size
),
tic
,
firsttic
,
lasttic
));
lasttic
=
tic
;
// too bad: too much player have send extradata and there is too
// much data in one tic.
// To avoid it put the data on the next tic. (see getpacket
// textcmd case) but when numplayer changes the computation can be different
if
(
lasttic
==
firsttic
)
{
if
(
size
>
MAXPACKETLENGTH
)
I_Error
(
"Too many players: can't send %s data for %d players to node %d
\n
"
"Well sorry nobody is perfect....
\n
"
,
sizeu1
(
size
),
doomcom
->
numslots
,
nodenum
);
else
{
lasttic
++
;
// send it anyway!
DEBFILE
(
"sending it anyway
\n
"
);
}
}
break
;
}
}
return
lasttic
-
firsttic
;
}
// send the server packet
// send tic from firstticstosend to maketic-1
void
SV_SendTics
(
void
)
{
tic_t
realfirsttic
,
lasttictosend
,
i
;
UINT32
n
;
INT32
j
;
size_t
packsize
;
UINT8
*
bufpos
;
UINT8
*
ntextcmd
;
// send to all client but not to me
// for each node create a packet with x tics and send it
...
...
@@ -336,38 +376,7 @@ void SV_SendTics(void)
if
(
realfirsttic
<
firstticstosend
)
realfirsttic
=
firstticstosend
;
// compute the length of the packet and cut it if too large
packsize
=
BASESERVERTICSSIZE
;
for
(
i
=
realfirsttic
;
i
<
lasttictosend
;
i
++
)
{
packsize
+=
sizeof
(
ticcmd_t
)
*
doomcom
->
numslots
;
packsize
+=
TotalTextCmdPerTic
(
i
);
if
(
packsize
>
software_MAXPACKETLENGTH
)
{
DEBFILE
(
va
(
"packet too large (%s) at tic %d (should be from %d to %d)
\n
"
,
sizeu1
(
packsize
),
i
,
realfirsttic
,
lasttictosend
));
lasttictosend
=
i
;
// too bad: too much player have send extradata and there is too
// much data in one tic.
// To avoid it put the data on the next tic. (see getpacket
// textcmd case) but when numplayer changes the computation can be different
if
(
lasttictosend
==
realfirsttic
)
{
if
(
packsize
>
MAXPACKETLENGTH
)
I_Error
(
"Too many players: can't send %s data for %d players to node %d
\n
"
"Well sorry nobody is perfect....
\n
"
,
sizeu1
(
packsize
),
doomcom
->
numslots
,
n
);
else
{
lasttictosend
++
;
// send it anyway!
DEBFILE
(
"sending it anyway
\n
"
);
}
}
break
;
}
}
lasttictosend
=
realfirsttic
+
SV_CalculateNumTicsForPacket
(
n
,
realfirsttic
,
lasttictosend
);
// Send the tics
netbuffer
->
packettype
=
PT_SERVERTICS
;
...
...
@@ -383,23 +392,7 @@ void SV_SendTics(void)
// add textcmds
for
(
i
=
realfirsttic
;
i
<
lasttictosend
;
i
++
)
{
ntextcmd
=
bufpos
++
;
*
ntextcmd
=
0
;
for
(
j
=
0
;
j
<
MAXPLAYERS
;
j
++
)
{
UINT8
*
textcmd
=
D_GetExistingTextcmd
(
i
,
j
);
INT32
size
=
textcmd
?
textcmd
[
0
]
:
0
;
if
((
!
j
||
playeringame
[
j
])
&&
size
)
{
(
*
ntextcmd
)
++
;
WRITEUINT8
(
bufpos
,
j
);
M_Memcpy
(
bufpos
,
textcmd
,
size
+
1
);
bufpos
+=
size
+
1
;
}
}
}
SV_WriteNetCommandsForTic
();
packsize
=
bufpos
-
(
UINT8
*
)
&
(
netbuffer
->
u
);
HSendPacket
(
n
,
false
,
0
,
packsize
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment