12 |
|
#include "rhdisp.h" |
13 |
|
#include "rhdriver.h" |
14 |
|
#include "selcall.h" |
15 |
+ |
#include <ctype.h> |
16 |
|
|
17 |
+ |
#ifndef VIEWHISTLEN |
18 |
+ |
#define VIEWHISTLEN 4 /* number of remembered views */ |
19 |
+ |
#endif |
20 |
+ |
|
21 |
|
HOLO *hdlist[HDMAX+1]; /* global holodeck list */ |
22 |
|
|
23 |
+ |
char cmdlist[DC_NCMDS][8] = DC_INIT; |
24 |
+ |
|
25 |
|
int imm_mode = 0; /* bundles are being delivered immediately */ |
26 |
|
|
27 |
|
char *progname; /* global argv[0] */ |
28 |
|
|
29 |
< |
#define RDY_SRV 01 |
23 |
< |
#define RDY_DEV 02 |
29 |
> |
FILE *sstdin, *sstdout; /* server's standard input and output */ |
30 |
|
|
31 |
+ |
#define RDY_SRV 01 |
32 |
+ |
#define RDY_DEV 02 |
33 |
+ |
#define RDY_SIN 04 |
34 |
|
|
35 |
+ |
|
36 |
|
main(argc, argv) |
37 |
|
int argc; |
38 |
|
char *argv[]; |
39 |
|
{ |
40 |
+ |
extern int eputs(); |
41 |
|
int rdy, inp, res = 0, pause = 0; |
42 |
|
|
43 |
|
progname = argv[0]; |
44 |
< |
if (argc != 2) |
44 |
> |
if (argc < 3) |
45 |
|
error(USER, "bad command line arguments"); |
46 |
|
/* open our device */ |
47 |
|
dev_open(argv[1]); |
48 |
+ |
/* open server process i/o */ |
49 |
+ |
sstdout = fdopen(atoi(argv[2]), "w"); |
50 |
+ |
if (argc < 4 || (inp = atoi(argv[3])) < 0) |
51 |
+ |
sstdin = NULL; |
52 |
+ |
else |
53 |
+ |
sstdin = fdopen(inp, "r"); |
54 |
+ |
/* set command error vector */ |
55 |
+ |
erract[COMMAND].pf = eputs; |
56 |
|
/* enter main loop */ |
57 |
|
do { |
58 |
|
rdy = disp_wait(); |
59 |
< |
if (rdy & RDY_DEV) { /* get user input */ |
59 |
> |
if (rdy & RDY_DEV) { /* user input from driver */ |
60 |
|
inp = dev_input(); |
61 |
< |
if (inp & DEV_NEWVIEW) |
61 |
> |
if (inp & DFL(DC_SETVIEW)) |
62 |
|
new_view(&odev.v); |
63 |
< |
if (inp & DEV_SHUTDOWN) |
64 |
< |
serv_request(DR_SHUTDOWN, 0, NULL); |
65 |
< |
if (inp & DEV_REDRAW) { |
66 |
< |
imm_mode = 1; /* preempt updates */ |
67 |
< |
beam_sync(); |
63 |
> |
if (inp & DFL(DC_GETVIEW)) |
64 |
> |
printview(); |
65 |
> |
if (inp & DFL(DC_LASTVIEW)) |
66 |
> |
new_view(NULL); |
67 |
> |
if (inp & DFL(DC_RESUME)) { |
68 |
> |
serv_request(DR_NOOP, 0, NULL); |
69 |
> |
pause = 0; |
70 |
|
} |
71 |
< |
if (inp & DEV_WAIT) |
71 |
> |
if (inp & DFL(DC_PAUSE)) |
72 |
|
pause = 1; |
73 |
< |
if (inp & DEV_RESUME) { |
74 |
< |
serv_request(DR_NOOP, 0, NULL); |
73 |
> |
if (inp & DFL(DC_REDRAW)) |
74 |
> |
imm_mode = beam_sync() > 0; |
75 |
> |
if (inp & DFL(DC_KILL)) { |
76 |
> |
serv_request(DR_KILL, 0, NULL); |
77 |
|
pause = 0; |
78 |
|
} |
79 |
+ |
if (inp & DFL(DC_CLOBBER)) |
80 |
+ |
serv_request(DR_CLOBBER, 0, NULL); |
81 |
+ |
if (inp & DFL(DC_RESTART)) { |
82 |
+ |
serv_request(DR_RESTART, 0, NULL); |
83 |
+ |
pause = 0; |
84 |
+ |
} |
85 |
+ |
if (inp & DFL(DC_QUIT)) |
86 |
+ |
serv_request(DR_SHUTDOWN, 0, NULL); |
87 |
|
} |
88 |
< |
if (rdy & RDY_SRV) { /* get server result */ |
88 |
> |
if (rdy & RDY_SIN) /* user input from sstdin */ |
89 |
> |
switch (usr_input()) { |
90 |
> |
case DC_PAUSE: |
91 |
> |
pause = 1; |
92 |
> |
break; |
93 |
> |
case DC_RESUME: |
94 |
> |
serv_request(DR_NOOP, 0, NULL); |
95 |
> |
/* fall through */ |
96 |
> |
case DC_KILL: |
97 |
> |
case DC_RESTART: |
98 |
> |
pause = 0; |
99 |
> |
break; |
100 |
> |
} |
101 |
> |
if (rdy & RDY_SRV) { /* process server result */ |
102 |
|
res = serv_result(); |
103 |
|
if (pause && res != DS_SHUTDOWN) { |
104 |
|
serv_request(DR_ATTEN, 0, NULL); |
123 |
|
/* see if we can avoid select call */ |
124 |
|
if (imm_mode || stdin->_cnt > 0) |
125 |
|
return(RDY_SRV); |
126 |
+ |
if (sstdin != NULL && sstdin->_cnt > 0) |
127 |
+ |
return(RDY_SIN); |
128 |
|
if (dev_flush()) |
129 |
|
return(RDY_DEV); |
130 |
|
/* make the call */ |
133 |
|
FD_SET(0, &errset); |
134 |
|
FD_SET(odev.ifd, &readset); |
135 |
|
FD_SET(odev.ifd, &errset); |
136 |
< |
n = odev.ifd + 1; |
136 |
> |
n = odev.ifd+1; |
137 |
> |
if (sstdin != NULL) { |
138 |
> |
FD_SET(fileno(sstdin), &readset); |
139 |
> |
if (fileno(sstdin) >= n) |
140 |
> |
n = fileno(sstdin) + 1; |
141 |
> |
} |
142 |
|
n = select(n, &readset, NULL, &errset, NULL); |
143 |
|
if (n < 0) { |
144 |
|
if (errno == EINTR) |
150 |
|
flgs |= RDY_SRV; |
151 |
|
if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset)) |
152 |
|
flgs |= RDY_DEV; |
153 |
+ |
if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset)) |
154 |
+ |
flgs |= RDY_SIN; |
155 |
|
return(flgs); |
156 |
|
} |
157 |
|
|
201 |
|
hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r); |
202 |
|
d = hddepth(hdlist[p->hd], packra(p)[i].d); |
203 |
|
VSUM(wp, ro, rd, d); /* might be behind viewpoint */ |
204 |
< |
dev_value(packra(p)[i].v, wp); |
204 |
> |
dev_value(packra(p)[i].v, wp, rd); |
205 |
|
} |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
new_view(v) /* change view parameters */ |
210 |
< |
VIEW *v; |
210 |
> |
register VIEW *v; |
211 |
|
{ |
212 |
+ |
static VIEW viewhist[VIEWHISTLEN]; |
213 |
+ |
static unsigned nhist; |
214 |
|
char *err; |
215 |
+ |
/* restore previous view? */ |
216 |
+ |
if (v == NULL) { |
217 |
+ |
if (nhist > 1) /* get one before last setting */ |
218 |
+ |
nhist--; |
219 |
+ |
else /* else go to end of list */ |
220 |
+ |
while (nhist < VIEWHISTLEN && viewhist[nhist].type) |
221 |
+ |
nhist++; |
222 |
+ |
v = viewhist + ((nhist-1)%VIEWHISTLEN); |
223 |
+ |
} else |
224 |
+ |
again: |
225 |
+ |
if ((err = setview(v)) != NULL) { |
226 |
+ |
error(COMMAND, err); |
227 |
+ |
return; |
228 |
+ |
} |
229 |
+ |
if (v->type == VT_PAR) { |
230 |
+ |
error(COMMAND, "cannot handle parallel views"); |
231 |
+ |
return; |
232 |
+ |
} |
233 |
+ |
if (!dev_view(v)) /* update display driver */ |
234 |
+ |
goto again; |
235 |
+ |
dev_flush(); /* update screen */ |
236 |
+ |
if (!beam_view(v)) /* update beam list */ |
237 |
+ |
goto again; |
238 |
+ |
/* record new view */ |
239 |
+ |
if (v < viewhist || v >= viewhist+VIEWHISTLEN) { |
240 |
+ |
copystruct(viewhist + (nhist%VIEWHISTLEN), v); |
241 |
+ |
nhist++; |
242 |
+ |
} |
243 |
+ |
} |
244 |
|
|
245 |
< |
if ((err = setview(v)) != NULL) |
246 |
< |
error(INTERNAL, err); |
247 |
< |
dev_view(v); /* update display driver */ |
248 |
< |
dev_flush(); /* update screen */ |
249 |
< |
beam_view(v); /* update beam list */ |
245 |
> |
|
246 |
> |
int |
247 |
> |
usr_input() /* get user input and process it */ |
248 |
> |
{ |
249 |
> |
VIEW vparams; |
250 |
> |
char cmd[128]; |
251 |
> |
register char *args; |
252 |
> |
register int i; |
253 |
> |
|
254 |
> |
if (fgets(cmd, sizeof(cmd), sstdin) == NULL) |
255 |
> |
return(DC_QUIT); |
256 |
> |
for (args = cmd; *args && !isspace(*args); args++) |
257 |
> |
; |
258 |
> |
while (isspace(*args)) |
259 |
> |
*args++ = '\0'; |
260 |
> |
if (!*cmd) |
261 |
> |
return(DC_RESUME); |
262 |
> |
if (*args && args[i=strlen(args)-1] == '\n') |
263 |
> |
args[i] = '\0'; |
264 |
> |
for (i = 0; i < DC_NCMDS; i++) |
265 |
> |
if (!strcmp(cmd, cmdlist[i])) |
266 |
> |
break; |
267 |
> |
if (i >= DC_NCMDS) { |
268 |
> |
sprintf(errmsg, "unknown command: %s", cmd); |
269 |
> |
error(COMMAND, errmsg); |
270 |
> |
return(-1); |
271 |
> |
} |
272 |
> |
switch (i) { |
273 |
> |
case DC_SETVIEW: /* set the view */ |
274 |
> |
copystruct(&vparams, &odev.v); |
275 |
> |
if (!sscanview(&vparams, args)) |
276 |
> |
error(COMMAND, "missing view options"); |
277 |
> |
else |
278 |
> |
new_view(&vparams); |
279 |
> |
break; |
280 |
> |
case DC_GETVIEW: /* print the current view */ |
281 |
> |
printview(); |
282 |
> |
break; |
283 |
> |
case DC_LASTVIEW: /* restore previous view */ |
284 |
> |
new_view(NULL); |
285 |
> |
break; |
286 |
> |
case DC_PAUSE: /* pause the current calculation */ |
287 |
> |
case DC_RESUME: /* resume the calculation */ |
288 |
> |
/* handled in main() */ |
289 |
> |
break; |
290 |
> |
case DC_REDRAW: /* redraw from server */ |
291 |
> |
imm_mode = beam_sync() > 0; |
292 |
> |
break; |
293 |
> |
case DC_KILL: /* kill rtrace process(es) */ |
294 |
> |
serv_request(DR_KILL, 0, NULL); |
295 |
> |
break; |
296 |
> |
case DC_CLOBBER: /* clobber holodeck */ |
297 |
> |
serv_request(DR_CLOBBER, 0, NULL); |
298 |
> |
break; |
299 |
> |
case DC_RESTART: /* restart rtrace */ |
300 |
> |
serv_request(DR_RESTART, 0, NULL); |
301 |
> |
break; |
302 |
> |
case DC_QUIT: /* quit request */ |
303 |
> |
serv_request(DR_SHUTDOWN, 0, NULL); |
304 |
> |
break; |
305 |
> |
default: |
306 |
> |
error(CONSISTENCY, "bad command id in usr_input"); |
307 |
> |
} |
308 |
> |
return(i); |
309 |
|
} |
310 |
|
|
311 |
|
|
312 |
+ |
printview() /* print our current view to server stdout */ |
313 |
+ |
{ |
314 |
+ |
fputs(VIEWSTR, sstdout); |
315 |
+ |
fprintview(&odev.v, sstdout); |
316 |
+ |
fputc('\n', sstdout); |
317 |
+ |
fflush(sstdout); |
318 |
+ |
} |
319 |
+ |
|
320 |
+ |
|
321 |
|
int |
322 |
|
serv_result() /* get next server result and process it */ |
323 |
|
{ |
355 |
|
case DS_STARTIMM: |
356 |
|
case DS_ENDIMM: |
357 |
|
imm_mode = msg.type==DS_STARTIMM; |
358 |
+ |
if (msg.type == DS_ENDIMM) |
359 |
+ |
dev_flush(); /* update display NOW */ |
360 |
|
/* fall through */ |
361 |
|
case DS_ACKNOW: |
362 |
|
case DS_SHUTDOWN: |