Bump version numbers for 3.13
[maemo-rb.git] / apps / plugins / doom / d_net.c
blobf70c4435a6d9a2c364b1f4d4540cb90baf5ded7f
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
25 * 02111-1307, USA.
27 * DESCRIPTION:
28 * Network client. Passes information to/from server, staying
29 * synchronised.
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 *-----------------------------------------------------------------------------
37 #include "m_menu.h"
38 #include "i_system.h"
39 #include "i_video.h"
40 #include "i_sound.h"
41 #include "g_game.h"
42 #include "doomdef.h"
43 #include "doomstat.h"
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
54 doomcom_t* doomcom;
56 static boolean server=0;
57 static int remotetic; // Tic expected from the remote
58 static int remotesend; // Tic expected by the remote
61 // NETWORKING
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];
74 int maketic;
75 int ticdup=1;
77 void G_BuildTiccmd (ticcmd_t *cmd);
78 void D_DoAdvanceDemo (void);
80 void D_InitNetGame (void)
82 int i;
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;
102 while (newtics--)
104 I_StartTic();
105 if (maketic - gametic > BACKUPTICS/2) break;
106 G_BuildTiccmd(&localcmds[maketic%BACKUPTICS]);
107 maketic++;
112 // TryRunTics
114 extern boolean advancedemo;
116 void TryRunTics (void)
118 int runtics;
119 int entertime = I_GetTime();
121 // Wait for tics to run
122 while (1) {
123 D_BuildNewTiccmds();
124 runtics = (server ? remotetic : maketic) - gametic;
125 if (!runtics) {
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) {
130 remotesend--;
131 // {
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);
136 // }
137 M_Ticker(); return;
139 } else break;
142 while (runtics--) {
143 if (advancedemo)
144 D_DoAdvanceDemo ();
145 M_Ticker ();
146 G_Ticker ();
147 gametic++;