15 |
|
#include <ctype.h> |
16 |
|
|
17 |
|
#ifndef VIEWHISTLEN |
18 |
< |
#define VIEWHISTLEN 2 /* number of remembered views */ |
18 |
> |
#define VIEWHISTLEN 4 /* number of remembered views */ |
19 |
|
#endif |
20 |
|
|
21 |
|
HOLO *hdlist[HDMAX+1]; /* global holodeck list */ |
24 |
|
|
25 |
|
int imm_mode = 0; /* bundles are being delivered immediately */ |
26 |
|
|
27 |
+ |
int do_outside = 0; /* render from outside sections */ |
28 |
+ |
|
29 |
|
char *progname; /* global argv[0] */ |
30 |
|
|
31 |
|
FILE *sstdin, *sstdout; /* server's standard input and output */ |
32 |
|
|
33 |
+ |
#ifdef DEBUG |
34 |
+ |
#include <sys/types.h> |
35 |
+ |
extern time_t time(); |
36 |
+ |
static time_t tmodesw; |
37 |
+ |
static time_t timm, tadd; |
38 |
+ |
static long nimmrays, naddrays; |
39 |
+ |
#endif |
40 |
+ |
|
41 |
|
#define RDY_SRV 01 |
42 |
|
#define RDY_DEV 02 |
43 |
|
#define RDY_SIN 04 |
63 |
|
sstdin = fdopen(inp, "r"); |
64 |
|
/* set command error vector */ |
65 |
|
erract[COMMAND].pf = eputs; |
66 |
+ |
#ifdef DEBUG |
67 |
+ |
tmodesw = time(NULL); |
68 |
+ |
#endif |
69 |
|
/* enter main loop */ |
70 |
|
do { |
71 |
|
rdy = disp_wait(); |
72 |
+ |
if (rdy & RDY_SRV) { /* process server result */ |
73 |
+ |
res = serv_result(); |
74 |
+ |
if (pause && res != DS_SHUTDOWN) { |
75 |
+ |
serv_request(DR_ATTEN, 0, NULL); |
76 |
+ |
while ((res = serv_result()) != DS_ACKNOW && |
77 |
+ |
res != DS_SHUTDOWN) |
78 |
+ |
; |
79 |
+ |
} |
80 |
+ |
} |
81 |
|
if (rdy & RDY_DEV) { /* user input from driver */ |
82 |
|
inp = dev_input(); |
83 |
|
if (inp & DFL(DC_SETVIEW)) |
86 |
|
printview(); |
87 |
|
if (inp & DFL(DC_LASTVIEW)) |
88 |
|
new_view(NULL); |
67 |
– |
if (inp & DFL(DC_PAUSE)) |
68 |
– |
pause = 1; |
89 |
|
if (inp & DFL(DC_RESUME)) { |
90 |
|
serv_request(DR_NOOP, 0, NULL); |
91 |
|
pause = 0; |
92 |
|
} |
93 |
+ |
if (inp & DFL(DC_PAUSE)) |
94 |
+ |
pause = 1; |
95 |
|
if (inp & DFL(DC_REDRAW)) |
96 |
|
imm_mode = beam_sync() > 0; |
97 |
+ |
if (inp & DFL(DC_KILL)) { |
98 |
+ |
serv_request(DR_KILL, 0, NULL); |
99 |
+ |
pause = 0; |
100 |
+ |
} |
101 |
+ |
if (inp & DFL(DC_CLOBBER)) |
102 |
+ |
serv_request(DR_CLOBBER, 0, NULL); |
103 |
+ |
if (inp & DFL(DC_RESTART)) { |
104 |
+ |
serv_request(DR_RESTART, 0, NULL); |
105 |
+ |
pause = 0; |
106 |
+ |
} |
107 |
|
if (inp & DFL(DC_QUIT)) |
108 |
|
serv_request(DR_SHUTDOWN, 0, NULL); |
109 |
|
} |
114 |
|
break; |
115 |
|
case DC_RESUME: |
116 |
|
serv_request(DR_NOOP, 0, NULL); |
117 |
+ |
/* fall through */ |
118 |
+ |
case DC_KILL: |
119 |
+ |
case DC_RESTART: |
120 |
|
pause = 0; |
121 |
|
break; |
122 |
|
} |
88 |
– |
if (rdy & RDY_SRV) { /* process server result */ |
89 |
– |
res = serv_result(); |
90 |
– |
if (pause && res != DS_SHUTDOWN) { |
91 |
– |
serv_request(DR_ATTEN, 0, NULL); |
92 |
– |
while ((res = serv_result()) != DS_ACKNOW && |
93 |
– |
res != DS_SHUTDOWN) |
94 |
– |
; |
95 |
– |
} |
96 |
– |
} |
123 |
|
} while (res != DS_SHUTDOWN); |
124 |
+ |
#ifdef DEBUG |
125 |
+ |
if (timm && nimmrays) |
126 |
+ |
fprintf(stderr, |
127 |
+ |
"%s: %.1f rays recalled/second (%ld rays total)\n", |
128 |
+ |
progname, (double)nimmrays/timm, nimmrays); |
129 |
+ |
if (tadd && naddrays) |
130 |
+ |
fprintf(stderr, |
131 |
+ |
"%s: %.1f rays calculated/second (%ld rays total)\n", |
132 |
+ |
progname, (double)naddrays/tadd, naddrays); |
133 |
+ |
#endif |
134 |
|
/* all done */ |
135 |
|
quit(0); |
136 |
|
} |
183 |
|
HDGRID *hdg; |
184 |
|
{ |
185 |
|
VIEW nv; |
186 |
+ |
double d; |
187 |
|
register int hd; |
188 |
|
|
189 |
|
for (hd = 0; hd < HDMAX && hdlist[hd] != NULL; hd++) |
204 |
|
VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5); |
205 |
|
fcross(nv.vdir, hdlist[0]->xv[1], hdlist[0]->xv[2]); |
206 |
|
VCOPY(nv.vup, hdlist[0]->xv[2]); |
207 |
+ |
if (do_outside) { |
208 |
+ |
normalize(nv.vdir); |
209 |
+ |
d = VLEN(hdlist[0]->xv[1]); |
210 |
+ |
d += VLEN(hdlist[0]->xv[2]); |
211 |
+ |
VSUM(nv.vp, nv.vp, nv.vdir, -d); |
212 |
+ |
} |
213 |
|
new_view(&nv); |
214 |
|
} |
215 |
|
|
233 |
|
VSUM(wp, ro, rd, d); /* might be behind viewpoint */ |
234 |
|
dev_value(packra(p)[i].v, wp, rd); |
235 |
|
} |
236 |
+ |
#ifdef DEBUG |
237 |
+ |
if (imm_mode) nimmrays += p->nr; |
238 |
+ |
else naddrays += p->nr; |
239 |
+ |
#endif |
240 |
|
} |
241 |
|
|
242 |
|
|
248 |
|
char *err; |
249 |
|
/* restore previous view? */ |
250 |
|
if (v == NULL) { |
251 |
< |
if (nhist < 2) { |
252 |
< |
error(COMMAND, "no previous view"); |
253 |
< |
return; |
254 |
< |
} |
255 |
< |
nhist--; /* get one before last setting */ |
251 |
> |
if (nhist > 1) /* get one before last setting */ |
252 |
> |
nhist--; |
253 |
> |
else /* else go to end of list */ |
254 |
> |
while (nhist < VIEWHISTLEN && viewhist[nhist].type) |
255 |
> |
nhist++; |
256 |
|
v = viewhist + ((nhist-1)%VIEWHISTLEN); |
257 |
< |
} else if ((err = setview(v)) != NULL) { |
257 |
> |
} else |
258 |
> |
again: |
259 |
> |
if ((err = setview(v)) != NULL) { |
260 |
|
error(COMMAND, err); |
261 |
|
return; |
262 |
|
} |
214 |
– |
again: |
263 |
|
if (v->type == VT_PAR) { |
264 |
|
error(COMMAND, "cannot handle parallel views"); |
265 |
|
return; |
323 |
|
break; |
324 |
|
case DC_REDRAW: /* redraw from server */ |
325 |
|
imm_mode = beam_sync() > 0; |
326 |
+ |
dev_clear(); |
327 |
|
break; |
328 |
+ |
case DC_KILL: /* kill rtrace process(es) */ |
329 |
+ |
serv_request(DR_KILL, 0, NULL); |
330 |
+ |
break; |
331 |
+ |
case DC_CLOBBER: /* clobber holodeck */ |
332 |
+ |
serv_request(DR_CLOBBER, 0, NULL); |
333 |
+ |
break; |
334 |
+ |
case DC_RESTART: /* restart rtrace */ |
335 |
+ |
serv_request(DR_RESTART, 0, NULL); |
336 |
+ |
break; |
337 |
|
case DC_QUIT: /* quit request */ |
338 |
|
serv_request(DR_SHUTDOWN, 0, NULL); |
339 |
|
break; |
387 |
|
error(INTERNAL, "bad holodeck record from server"); |
388 |
|
add_holo((HDGRID *)buf); |
389 |
|
break; |
390 |
+ |
case DS_OUTSECT: |
391 |
+ |
do_outside = 1; |
392 |
+ |
break; |
393 |
|
case DS_STARTIMM: |
394 |
|
case DS_ENDIMM: |
395 |
+ |
#ifdef DEBUG |
396 |
+ |
if (imm_mode != (msg.type==DS_STARTIMM)) { |
397 |
+ |
time_t tnow = time(NULL); |
398 |
+ |
if (imm_mode) timm += tnow - tmodesw; |
399 |
+ |
else tadd += tnow - tmodesw; |
400 |
+ |
tmodesw = tnow; |
401 |
+ |
} |
402 |
+ |
#endif |
403 |
|
imm_mode = msg.type==DS_STARTIMM; |
335 |
– |
if (msg.type == DS_ENDIMM) |
336 |
– |
dev_flush(); /* update display NOW */ |
404 |
|
/* fall through */ |
405 |
|
case DS_ACKNOW: |
406 |
|
case DS_SHUTDOWN: |