annotate recorder.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
1 /* $Id: recorder.c,v 1.1.1.1 1997/12/06 05:41:30 darius Exp $ */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
2
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
3 #ifdef RECORDER
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
4
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
5 #include <stdio.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
6 #include <sys/types.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
7 #include <sys/file.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
8 #include <sys/stat.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
9 #include <sys/select.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
10 #include <fcntl.h>
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
11
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
12 #include "Wlib.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
13 #include "defs.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
14 #include "struct.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
15 #include "data.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
16 #include "proto.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
17 #include "packets.h"
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
18
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
19 int record_total;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
20 int lastTeamReq = -1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
21 int recfp = -1, playfp = -1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
22
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
23 void pb_skip P((int frames));
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
24
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
25 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
26 startRecorder()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
27 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
28 if (recordGame = booleanDefault("recordGame", recordGame)) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
29 recordFile = stringDefault("recordFile", "/tmp/netrek.record");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
30 recordFile = expandFilename(recordFile);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
31 maxRecord = intDefault("maxRecord", maxRecord);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
32 recfp = open(recordFile, O_WRONLY | O_TRUNC | O_APPEND | O_CREAT, S_IRWXU);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
33 if (recfp >= 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
34 printf("Game being recorded to %s. Max size is %d\n", recordFile, maxRecord);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
35 else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
36 perror("startRecorder");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
37 printf("Can't open file %s for recording\n", recordFile);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
38 recordGame = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
39 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
40 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
41 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
42
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
43 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
44 stopRecorder()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
45 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
46 char buf[80];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
47
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
48 close(recfp);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
49 recfp = -1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
50 recordGame = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
51 sprintf(buf, "Recording stopped, %d bytes (%d updates) written to %s\n",
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
52 record_total, udcounter, (recordFile==NULL) ? "Nothing" : recordFile);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
53 warning(buf);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
54 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
55
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
56 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
57 recordPacket(data, len)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
58 char *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
59 int len;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
60 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
61 int res;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
62
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
63 if (recfp >= 0 && len > 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
64 switch (*data) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
65 case SP_PICKOK: /* playback needs to know what team! */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
66 data[2] = (char) lastTeamReq;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
67 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
68 case SP_RSA_KEY:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
69 case SP_MOTD:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
70 case SP_MOTD_PIC:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
71 case SP_NEW_MOTD:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
72 return;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
73 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
74 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
75 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
76 res = write(recfp, data, len);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
77 record_total += res;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
78 if ((maxRecord && (record_total > maxRecord)) || (res <= 0))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
79 stopRecorder();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
80 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
81 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
82
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
83 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
84 writeUpdateMarker()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
85 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
86 unsigned char update_buf[4];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
87
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
88 update_buf[0] = REC_UPDATE;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
89 /*
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
90 record stuff not normally sent by server. Otherwise tractors and lock
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
91 markers don't work during playback
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
92 */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
93 update_buf[1] = (unsigned char) me->p_tractor;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
94 update_buf[2] = (unsigned char) ((me->p_flags & PFPLOCK) ? me->p_playerl : me->p_planet);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
95 /* one more byte here, any ideas? */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
96 record_total += write(recfp, update_buf, 4);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
97 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
98
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
99 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
100 startPlayback()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
101 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
102 if (playback || (playback = booleanDefault("playback", 0))) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
103 if (!playFile)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
104 playFile = stringDefault("playFile", "/tmp/netrek.record");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
105 playFile = expandFilename(playFile);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
106
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
107 playfp = open(playFile, O_RDONLY, 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
108 if (playfp < 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
109 perror("startPlayback");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
110 printf("Couldn't open playback file %s\n", playFile);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
111 exit(0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
112 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
113 printf("Replaying %s\n", playFile);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
114 return 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
115 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
116 return 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
117 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
118
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
119 int
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
120 readRecorded(fp, data, len)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
121 int fp, len;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
122 char *data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
123 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
124 int ret;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
125
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
126 if (!playback || len < 0 || playfp < 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
127 return -1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
128 if (len > 4) /* make sure we don't skip updates */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
129 len = 4;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
130 ret = read(playfp, data, len);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
131 if (ret <= 0)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
132 EXIT(0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
133 return ret;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
134 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
135
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
136 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
137 pb_dokey(event)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
138 W_Event *event;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
139 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
140 switch (event->key&0xff) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
141 case 'p':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
142 case 'P':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
143 paused = !paused;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
144 pb_scan=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
145 if (paused)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
146 pb_advance = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
147 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
148 case 'r':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
149 case 'R':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
150 pb_advance = PB_REDALERT;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
151 paused = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
152 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
153 case 'y':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
154 case 'Y':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
155 pb_advance = PB_YELLOWALERT;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
156 paused = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
157 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
158 case 'd':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
159 case 'D':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
160 pb_advance = PB_DEATH;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
161 paused = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
162 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
163 case ' ':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
164 if(paused) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
165 if(pb_scan)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
166 pb_skip(pb_advance);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
167 else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
168 pb_advance=1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
169 paused=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
170 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
171 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
172 paused = 1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
173 pb_advance=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
174 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
175 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
176 case 'f':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
177 case 'F': /* fast forward */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
178 pb_scan=!pb_scan;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
179 if(pb_scan) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
180 pb_advance=10;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
181 pb_slow=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
182 paused=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
183 warning("1-9: set speed. P-Pause, F-Fast Fwd off");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
184 } else {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
185 pb_advance=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
186 pb_slow=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
187 paused=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
188 warning("Playback mode, keys: P)ause R)ed Y)ellow D)eath F)ast Q)uit");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
189 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
190 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
191 case 's': /* Slow mode */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
192 case 'S':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
193 if(pb_scan || paused || !pb_slow)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
194 pb_slow=1;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
195 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
196 pb_slow=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
197 pb_scan=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
198 paused=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
199 pb_advance=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
200 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
201 case '1':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
202 case '2':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
203 case '3':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
204 case '4':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
205 case '5':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
206 case '6':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
207 case '7':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
208 case '8':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
209 case '9':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
210 if(!pb_scan)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
211 pb_advance += (event->key - '0') * 10;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
212 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
213 pb_advance = (event->key - '0') * 10;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
214 paused = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
215 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
216 case 'q':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
217 case 'Q':
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
218 exit(0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
219 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
220 warning("Playback mode, keys: P)ause R)ed Y)ellow D)eath F)ast Q)uit");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
221 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
222 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
223
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
224 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
225 pb_skip(frames)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
226 int frames;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
227 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
228 while(frames) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
229 pb_update=0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
230 readFromServer();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
231 frames-=pb_update;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
232 udcounter+=pb_update;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
233 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
234 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
235
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
236 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
237 pb_framectr(xloc, yloc)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
238 int xloc, yloc;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
239 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
240 char buf[20];
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
241
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
242 if(paused)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
243 strcpy(buf,"PAU");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
244 else if(pb_scan)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
245 strcpy(buf,"FFW");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
246 else if(pb_advance) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
247 switch(pb_advance) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
248 case PB_REDALERT:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
249 strcpy(buf,"RED");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
250 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
251 case PB_YELLOWALERT:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
252 strcpy(buf,"YLW");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
253 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
254 case PB_DEATH:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
255 strcpy(buf,"DTH");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
256 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
257 default:
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
258 buf[0]='+';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
259 buf[1]=(pb_advance / 10) + '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
260 buf[2]=(pb_advance % 10) + '0';
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
261 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
262 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
263 } else if(pb_slow)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
264 strcpy(buf,"SLW");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
265 else
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
266 strcpy(buf,"NRM");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
267
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
268 sprintf((buf+3),":%8d",udcounter);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
269
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
270 W_WriteText(tstatw, xloc, yloc, textColor, buf, 12, W_RegularFont);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
271 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
272
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
273 void
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
274 pb_input()
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
275 {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
276 W_Event data;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
277 fd_set readfds;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
278 int wsock = W_Socket();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
279
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
280 struct timeval timeout;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
281
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
282 timeout.tv_sec = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
283 timeout.tv_usec = 200000;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
284
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
285 intrupt(); /* draws the first frame */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
286
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
287 while (me->p_status == PALIVE ||
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
288 me->p_status == PEXPLODE ||
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
289 me->p_status == PDEAD ||
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
290 me->p_status == POBSERVE) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
291
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
292 if (keepInfo > 0) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
293 if (infowin_up >= 0 &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
294 --infowin_up == -1 &&
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
295 infomapped) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
296 destroyInfo();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
297 infowin_up = -2;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
298 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
299 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
300 exitInputLoop = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
301 while (W_EventsPending() && !exitInputLoop) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
302 fastQuit = 0; /* any event cancel fastquit */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
303 W_NextEvent(&data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
304 dispatch_W_event(&data);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
305 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
306 if (!paradise) /* stars are ok, it's just a recording.
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
307 zoom doesn't make sense. */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
308 blk_zoom = 0;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
309
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
310 #ifndef AMIGA
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
311 FD_ZERO(&readfds);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
312 FD_SET(wsock, &readfds);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
313 if (paused) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
314 select(32, &readfds, (fd_set *) 0, (fd_set *) 0, 0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
315 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
316 } else if(pb_slow && !pb_scan)
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
317 select(32, &readfds, (fd_set *) 0, (fd_set *) 0,&timeout);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
318
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
319 /* otherwise, in full blast mode, don't wait on anything. */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
320
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
321 #else /* AMIGA */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
322 if (paused) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
323 sigsPending = Wait(wsock | SIGBREAKF_CTRL_C);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
324 continue;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
325 } else if(pb_slow && !pb_scan) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
326 StartTimer(0,200000);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
327 while(1) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
328 sigsPending = Wait(wsock | portmask | SIGBREAKF_CTRL_C);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
329 if((sigsPending & (wsock | SIGBREAKF_CTRL_C)) ||
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
330 CheckIO(&(ior->tr_node)))
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
331 break;
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
332 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
333
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
334 StopTimer();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
335 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
336
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
337 if (sigsPending & SIGBREAKF_CTRL_C) {
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
338 printf("User break, Ctrl-C, exiting!\n");
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
339 exit(0);
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
340 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
341 #endif /* AMIGA */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
342 /* at this point, we're sure it's time for at least one frame. */
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
343 intrupt();
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
344 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
345 }
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
346
5a977ccbc7a9 Empty changelog
darius
parents:
diff changeset
347 #endif