1 /* Emacs style mode select -*- C++ -*-
2 *-----------------------------------------------------------------------------
5 * PrBoom a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 * Network client. Passes information to/from server, staying
30 * Contains the main wait loop, waiting for network input or
31 * time before doing the next tic.
32 * Rewritten for LxDoom, but based around bits of the old code.
34 *-----------------------------------------------------------------------------
45 #include "rockmacros.h"
47 #define NCMD_EXIT 0x80000000
48 #define NCMD_RETRANSMIT 0x40000000
49 #define NCMD_SETUP 0x20000000
50 #define NCMD_KILL 0x10000000 // kill game
51 #define NCMD_CHECKSUM 0x0fffffff
56 static boolean server
=0;
57 static int remotetic
; // Tic expected from the remote
58 static int remotesend
; // Tic expected by the remote
63 // gametic is the tic about to (or currently being) run
64 // maketic is the tick that hasn't had control made for it yet
65 // nettics[] has the maketics for all players
67 // a gametic cannot be run until nettics[] > gametic for all players
70 static ticcmd_t
* localcmds
;
72 ticcmd_t netcmds
[MAXPLAYERS
][BACKUPTICS
];
77 void G_BuildTiccmd (ticcmd_t
*cmd
);
78 void D_DoAdvanceDemo (void);
80 void D_InitNetGame (void)
84 doomcom
= Z_Malloc(sizeof *doomcom
, PU_STATIC
, NULL
);
85 doomcom
->consoleplayer
= 0;
86 doomcom
->numnodes
= 0; doomcom
->numplayers
= 1;
87 localcmds
= netcmds
[consoleplayer
];
89 for (i
=0; i
<doomcom
->numplayers
; i
++)
90 playeringame
[i
] = true;
91 for (; i
<MAXPLAYERS
; i
++)
92 playeringame
[i
] = false;
94 consoleplayer
= displayplayer
= doomcom
->consoleplayer
;
97 void D_BuildNewTiccmds()
99 static int lastmadetic
;
100 int newtics
= I_GetTime() - lastmadetic
;
101 lastmadetic
+= newtics
;
105 if (maketic
- gametic
> BACKUPTICS
/2) break;
106 G_BuildTiccmd(&localcmds
[maketic
%BACKUPTICS
]);
114 extern boolean advancedemo
;
116 void TryRunTics (void)
119 int entertime
= I_GetTime();
121 // Wait for tics to run
124 runtics
= (server
? remotetic
: maketic
) - gametic
;
126 // if (server) I_WaitForPacket(ms_to_next_tick);
127 // else I_uSleep(ms_to_next_tick*1000);
128 // rb->sleep(ms_to_next_tick);
129 if (I_GetTime() - entertime
> 10) {
132 // char buf[sizeof(packet_header_t)+1];
133 // packet_set((packet_header_t *)buf, PKT_RETRANS, remotetic);
134 // buf[sizeof(buf)-1] = consoleplayer;
135 // I_SendPacket((packet_header_t *)buf, sizeof buf);