12 |
|
#include "rhdisp.h" |
13 |
|
#include "rhdriver.h" |
14 |
|
#include "selcall.h" |
15 |
+ |
#include <ctype.h> |
16 |
|
|
17 |
+ |
#ifndef VIEWHISTLEN |
18 |
+ |
#define VIEWHISTLEN 2 /* 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(); |
49 |
< |
} |
50 |
< |
if (inp & DEV_WAIT) |
63 |
> |
if (inp & DFL(DC_GETVIEW)) |
64 |
> |
printview(); |
65 |
> |
if (inp & DFL(DC_LASTVIEW)) |
66 |
> |
new_view(NULL); |
67 |
> |
if (inp & DFL(DC_PAUSE)) |
68 |
|
pause = 1; |
69 |
< |
if (inp & DEV_RESUME) { |
69 |
> |
if (inp & DFL(DC_RESUME)) { |
70 |
|
serv_request(DR_NOOP, 0, NULL); |
71 |
|
pause = 0; |
72 |
|
} |
73 |
+ |
if (inp & DFL(DC_REDRAW)) |
74 |
+ |
imm_mode = beam_sync() > 0; |
75 |
+ |
if (inp & DFL(DC_QUIT)) |
76 |
+ |
serv_request(DR_SHUTDOWN, 0, NULL); |
77 |
|
} |
78 |
< |
if (rdy & RDY_SRV) { /* get server result */ |
78 |
> |
if (rdy & RDY_SIN) /* user input from sstdin */ |
79 |
> |
switch (usr_input()) { |
80 |
> |
case DC_PAUSE: |
81 |
> |
pause = 1; |
82 |
> |
break; |
83 |
> |
case DC_RESUME: |
84 |
> |
serv_request(DR_NOOP, 0, NULL); |
85 |
> |
pause = 0; |
86 |
> |
break; |
87 |
> |
} |
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); |
110 |
|
/* see if we can avoid select call */ |
111 |
|
if (imm_mode || stdin->_cnt > 0) |
112 |
|
return(RDY_SRV); |
113 |
+ |
if (sstdin != NULL && sstdin->_cnt > 0) |
114 |
+ |
return(RDY_SIN); |
115 |
|
if (dev_flush()) |
116 |
|
return(RDY_DEV); |
117 |
|
/* make the call */ |
120 |
|
FD_SET(0, &errset); |
121 |
|
FD_SET(odev.ifd, &readset); |
122 |
|
FD_SET(odev.ifd, &errset); |
123 |
< |
n = odev.ifd + 1; |
123 |
> |
n = odev.ifd+1; |
124 |
> |
if (sstdin != NULL) { |
125 |
> |
FD_SET(fileno(sstdin), &readset); |
126 |
> |
if (fileno(sstdin) >= n) |
127 |
> |
n = fileno(sstdin) + 1; |
128 |
> |
} |
129 |
|
n = select(n, &readset, NULL, &errset, NULL); |
130 |
|
if (n < 0) { |
131 |
|
if (errno == EINTR) |
137 |
|
flgs |= RDY_SRV; |
138 |
|
if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset)) |
139 |
|
flgs |= RDY_DEV; |
140 |
+ |
if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset)) |
141 |
+ |
flgs |= RDY_SIN; |
142 |
|
return(flgs); |
143 |
|
} |
144 |
|
|
188 |
|
hdray(ro, rd, hdlist[p->hd], gc, packra(p)[i].r); |
189 |
|
d = hddepth(hdlist[p->hd], packra(p)[i].d); |
190 |
|
VSUM(wp, ro, rd, d); /* might be behind viewpoint */ |
191 |
< |
dev_value(packra(p)[i].v, wp); |
191 |
> |
dev_value(packra(p)[i].v, wp, rd); |
192 |
|
} |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
new_view(v) /* change view parameters */ |
197 |
< |
VIEW *v; |
197 |
> |
register VIEW *v; |
198 |
|
{ |
199 |
+ |
static VIEW viewhist[VIEWHISTLEN]; |
200 |
+ |
static unsigned nhist; |
201 |
|
char *err; |
202 |
+ |
/* restore previous view? */ |
203 |
+ |
if (v == NULL) { |
204 |
+ |
if (nhist < 2) { |
205 |
+ |
error(COMMAND, "no previous view"); |
206 |
+ |
return; |
207 |
+ |
} |
208 |
+ |
nhist--; /* get one before last setting */ |
209 |
+ |
v = viewhist + ((nhist-1)%VIEWHISTLEN); |
210 |
+ |
} else if ((err = setview(v)) != NULL) { |
211 |
+ |
error(COMMAND, err); |
212 |
+ |
return; |
213 |
+ |
} |
214 |
+ |
again: |
215 |
+ |
if (v->type == VT_PAR) { |
216 |
+ |
error(COMMAND, "cannot handle parallel views"); |
217 |
+ |
return; |
218 |
+ |
} |
219 |
+ |
if (!dev_view(v)) /* update display driver */ |
220 |
+ |
goto again; |
221 |
+ |
dev_flush(); /* update screen */ |
222 |
+ |
if (!beam_view(v)) /* update beam list */ |
223 |
+ |
goto again; |
224 |
+ |
/* record new view */ |
225 |
+ |
if (v < viewhist || v >= viewhist+VIEWHISTLEN) { |
226 |
+ |
copystruct(viewhist + (nhist%VIEWHISTLEN), v); |
227 |
+ |
nhist++; |
228 |
+ |
} |
229 |
+ |
} |
230 |
|
|
231 |
< |
if ((err = setview(v)) != NULL) |
232 |
< |
error(INTERNAL, err); |
233 |
< |
dev_view(v); /* update display driver */ |
234 |
< |
dev_flush(); /* update screen */ |
235 |
< |
beam_view(v); /* update beam list */ |
231 |
> |
|
232 |
> |
int |
233 |
> |
usr_input() /* get user input and process it */ |
234 |
> |
{ |
235 |
> |
VIEW vparams; |
236 |
> |
char cmd[128]; |
237 |
> |
register char *args; |
238 |
> |
register int i; |
239 |
> |
|
240 |
> |
if (fgets(cmd, sizeof(cmd), sstdin) == NULL) |
241 |
> |
return(DC_QUIT); |
242 |
> |
for (args = cmd; *args && !isspace(*args); args++) |
243 |
> |
; |
244 |
> |
while (isspace(*args)) |
245 |
> |
*args++ = '\0'; |
246 |
> |
if (!*cmd) |
247 |
> |
return(DC_RESUME); |
248 |
> |
if (*args && args[i=strlen(args)-1] == '\n') |
249 |
> |
args[i] = '\0'; |
250 |
> |
for (i = 0; i < DC_NCMDS; i++) |
251 |
> |
if (!strcmp(cmd, cmdlist[i])) |
252 |
> |
break; |
253 |
> |
if (i >= DC_NCMDS) { |
254 |
> |
sprintf(errmsg, "unknown command: %s", cmd); |
255 |
> |
error(COMMAND, errmsg); |
256 |
> |
return(-1); |
257 |
> |
} |
258 |
> |
switch (i) { |
259 |
> |
case DC_SETVIEW: /* set the view */ |
260 |
> |
copystruct(&vparams, &odev.v); |
261 |
> |
if (!sscanview(&vparams, args)) |
262 |
> |
error(COMMAND, "missing view options"); |
263 |
> |
else |
264 |
> |
new_view(&vparams); |
265 |
> |
break; |
266 |
> |
case DC_GETVIEW: /* print the current view */ |
267 |
> |
printview(); |
268 |
> |
break; |
269 |
> |
case DC_LASTVIEW: /* restore previous view */ |
270 |
> |
new_view(NULL); |
271 |
> |
break; |
272 |
> |
case DC_PAUSE: /* pause the current calculation */ |
273 |
> |
case DC_RESUME: /* resume the calculation */ |
274 |
> |
/* handled in main() */ |
275 |
> |
break; |
276 |
> |
case DC_REDRAW: /* redraw from server */ |
277 |
> |
imm_mode = beam_sync() > 0; |
278 |
> |
break; |
279 |
> |
case DC_QUIT: /* quit request */ |
280 |
> |
serv_request(DR_SHUTDOWN, 0, NULL); |
281 |
> |
break; |
282 |
> |
default: |
283 |
> |
error(CONSISTENCY, "bad command id in usr_input"); |
284 |
> |
} |
285 |
> |
return(i); |
286 |
|
} |
287 |
|
|
288 |
|
|
289 |
+ |
printview() /* print our current view to server stdout */ |
290 |
+ |
{ |
291 |
+ |
fputs(VIEWSTR, sstdout); |
292 |
+ |
fprintview(&odev.v, sstdout); |
293 |
+ |
fputc('\n', sstdout); |
294 |
+ |
fflush(sstdout); |
295 |
+ |
} |
296 |
+ |
|
297 |
+ |
|
298 |
|
int |
299 |
|
serv_result() /* get next server result and process it */ |
300 |
|
{ |
332 |
|
case DS_STARTIMM: |
333 |
|
case DS_ENDIMM: |
334 |
|
imm_mode = msg.type==DS_STARTIMM; |
335 |
+ |
if (msg.type == DS_ENDIMM) |
336 |
+ |
dev_flush(); /* update display NOW */ |
337 |
|
/* fall through */ |
338 |
|
case DS_ACKNOW: |
339 |
|
case DS_SHUTDOWN: |