diff options
author | Dave Chapman <dave@dchapman.com> | 2006-03-28 15:44:01 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2006-03-28 15:44:01 +0000 |
commit | 47f4a458d636a889e955e68f896708f1276febc0 (patch) | |
tree | 99f770c02ef606f0abbdcd332ac39e69830d8007 /apps/plugins/doom/d_net.c | |
parent | fff7d6157d56f233cad5c2003475e47a5ff809a7 (diff) | |
download | rockbox-47f4a458d636a889e955e68f896708f1276febc0.tar.gz rockbox-47f4a458d636a889e955e68f896708f1276febc0.zip |
Patch #2969 - Doom! Currently only working on the H300.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9312 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/doom/d_net.c')
-rw-r--r-- | apps/plugins/doom/d_net.c | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/apps/plugins/doom/d_net.c b/apps/plugins/doom/d_net.c new file mode 100644 index 0000000000..f70c4435a6 --- /dev/null +++ b/apps/plugins/doom/d_net.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* Emacs style mode select -*- C++ -*- | ||
2 | *----------------------------------------------------------------------------- | ||
3 | * | ||
4 | * | ||
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 | ||
11 | * | ||
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. | ||
16 | * | ||
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. | ||
21 | * | ||
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. | ||
26 | * | ||
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. | ||
33 | * | ||
34 | *----------------------------------------------------------------------------- | ||
35 | */ | ||
36 | |||
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" | ||
44 | |||
45 | #include "rockmacros.h" | ||
46 | |||
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 | ||
52 | |||
53 | |||
54 | doomcom_t* doomcom; | ||
55 | |||
56 | static boolean server=0; | ||
57 | static int remotetic; // Tic expected from the remote | ||
58 | static int remotesend; // Tic expected by the remote | ||
59 | |||
60 | // | ||
61 | // NETWORKING | ||
62 | // | ||
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 | ||
66 | // | ||
67 | // a gametic cannot be run until nettics[] > gametic for all players | ||
68 | // | ||
69 | |||
70 | static ticcmd_t* localcmds; | ||
71 | |||
72 | ticcmd_t netcmds[MAXPLAYERS][BACKUPTICS]; | ||
73 | |||
74 | int maketic; | ||
75 | int ticdup=1; | ||
76 | |||
77 | void G_BuildTiccmd (ticcmd_t *cmd); | ||
78 | void D_DoAdvanceDemo (void); | ||
79 | |||
80 | void D_InitNetGame (void) | ||
81 | { | ||
82 | int i; | ||
83 | |||
84 | doomcom = Z_Malloc(sizeof *doomcom, PU_STATIC, NULL); | ||
85 | doomcom->consoleplayer = 0; | ||
86 | doomcom->numnodes = 0; doomcom->numplayers = 1; | ||
87 | localcmds = netcmds[consoleplayer]; | ||
88 | |||
89 | for (i=0; i<doomcom->numplayers; i++) | ||
90 | playeringame[i] = true; | ||
91 | for (; i<MAXPLAYERS; i++) | ||
92 | playeringame[i] = false; | ||
93 | |||
94 | consoleplayer = displayplayer = doomcom->consoleplayer; | ||
95 | } | ||
96 | |||
97 | void D_BuildNewTiccmds() | ||
98 | { | ||
99 | static int lastmadetic; | ||
100 | int newtics = I_GetTime() - lastmadetic; | ||
101 | lastmadetic += newtics; | ||
102 | while (newtics--) | ||
103 | { | ||
104 | I_StartTic(); | ||
105 | if (maketic - gametic > BACKUPTICS/2) break; | ||
106 | G_BuildTiccmd(&localcmds[maketic%BACKUPTICS]); | ||
107 | maketic++; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | // | ||
112 | // TryRunTics | ||
113 | // | ||
114 | extern boolean advancedemo; | ||
115 | |||
116 | void TryRunTics (void) | ||
117 | { | ||
118 | int runtics; | ||
119 | int entertime = I_GetTime(); | ||
120 | |||
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; | ||
138 | } | ||
139 | } else break; | ||
140 | } | ||
141 | |||
142 | while (runtics--) { | ||
143 | if (advancedemo) | ||
144 | D_DoAdvanceDemo (); | ||
145 | M_Ticker (); | ||
146 | G_Ticker (); | ||
147 | gametic++; | ||
148 | } | ||
149 | } | ||