-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathd_net.c
182 lines (149 loc) · 3.46 KB
/
d_net.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
// Copyright (C) 1993-1996 Id Software, Inc.
// Copyright (C) 2016-2017 Alexey Khokholov (Nuke.YKT)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// DESCRIPTION:
// DOOM Network game communication and protocol,
// all OS independend parts.
//
#include "m_menu.h"
#include "i_system.h"
#include "g_game.h"
#include "doomdef.h"
#include "doomstat.h"
doomcom_t *doomcom;
doomdata_t *netbuffer; // points inside doomcom
//
// NETWORKING
//
// gametic is the tic about to (or currently being) run
// maketic is the tick that hasn't had control made for it yet
// nettics[] has the maketics for all players
//
// a gametic cannot be run until nettics[] > gametic for all players
//
#define PL_DRONE 0x80 // bit flag in doomdata->player
ticcmd_t localcmds[BACKUPTICS];
int nettics;
int maketic;
int skiptics;
void D_ProcessEvents(void);
void G_BuildTiccmd(ticcmd_t *cmd);
void D_DoAdvanceDemo(void);
//
// NetUpdate
// Builds ticcmds for console player,
// sends out a packet
//
int gametime;
void NetUpdate(void)
{
int newtics;
int i, j;
// check time
newtics = ticcount - gametime;
gametime = ticcount;
if (newtics <= 0) // nothing new to update
return;
if (skiptics <= newtics)
{
newtics -= skiptics;
skiptics = 0;
}
else
{
skiptics -= newtics;
newtics = 0;
}
// build new ticcmds for console player
for (i = 0; i < newtics; i++)
{
I_StartTic();
D_ProcessEvents();
if (maketic - gametic >= BACKUPTICS / 2 - 1)
break; // can't hold any more
G_BuildTiccmd(&localcmds[maketic % BACKUPTICS]);
maketic++;
}
if (singletics)
return; // singletic update is syncronous
nettics = maketic;
}
//
// D_CheckNetGame
// Works out player numbers among the net participants
//
void D_CheckNetGame(void)
{
// which tic to start sending
nettics = 0;
// I_InitNetwork sets doomcom and netgame
I_InitNetwork();
printf("startskill %i deathmatch: %i startmap: %i startepisode: %i\n",
startskill, 0, startmap, startepisode);
// read values out of doomcom
playeringame[0] = true;
printf("player %i of %i (%i nodes)\n",
1, 1, 1);
}
//
// TryRunTics
//
int oldnettics;
extern boolean advancedemo;
void TryRunTics(void)
{
int i;
int entertic;
static int oldentertics;
int realtics;
int availabletics;
int counts;
// get real tics
entertic = ticcount;
realtics = entertic - oldentertics;
oldentertics = entertic;
// get available tics
NetUpdate();
availabletics = nettics - gametic;
// decide how many tics to run
if (realtics < availabletics - 1)
counts = realtics + 1;
else if (realtics < availabletics)
counts = realtics;
else
counts = availabletics;
if (counts < 1)
counts = 1;
// wait for new tics if needed
while (nettics < gametic + counts)
{
NetUpdate();
// don't stay in here forever -- give the menu a chance to work
if (ticcount - entertic >= 20)
{
M_Ticker();
return;
}
}
// run the count dics
while (counts--)
{
if (advancedemo)
D_DoAdvanceDemo();
M_Ticker();
G_Ticker();
gametic++;
NetUpdate(); // check for new console commands
}
}