| 1 | 
< | 
/* Copyright (c) 1997 Silicon Graphics, Inc. */ | 
| 1 | 
> | 
/* Copyright (c) 1998 Silicon Graphics, Inc. */ | 
| 2 | 
  | 
 | 
| 3 | 
  | 
#ifndef lint | 
| 4 | 
  | 
static char SCCSid[] = "$SunId$ SGI"; | 
| 24 | 
  | 
 | 
| 25 | 
  | 
int     imm_mode = 0;           /* bundles are being delivered immediately */ | 
| 26 | 
  | 
 | 
| 27 | 
+ | 
int     do_outside = 0;         /* render from outside sections */ | 
| 28 | 
+ | 
 | 
| 29 | 
+ | 
double  eyesepdist = 1;         /* eye separation distance */ | 
| 30 | 
+ | 
 | 
| 31 | 
  | 
char    *progname;              /* global argv[0] */ | 
| 32 | 
  | 
 | 
| 33 | 
  | 
FILE    *sstdin, *sstdout;      /* server's standard input and output */ | 
| 34 | 
  | 
 | 
| 35 | 
+ | 
#ifdef DEBUG | 
| 36 | 
+ | 
#include <sys/types.h> | 
| 37 | 
+ | 
extern time_t   time(); | 
| 38 | 
+ | 
static time_t   tmodesw; | 
| 39 | 
+ | 
static time_t   timm, tadd; | 
| 40 | 
+ | 
static long     nimmrays, naddrays; | 
| 41 | 
+ | 
#endif | 
| 42 | 
+ | 
 | 
| 43 | 
  | 
#define RDY_SRV         01 | 
| 44 | 
  | 
#define RDY_DEV         02 | 
| 45 | 
  | 
#define RDY_SIN         04 | 
| 65 | 
  | 
                sstdin = fdopen(inp, "r"); | 
| 66 | 
  | 
                                        /* set command error vector */ | 
| 67 | 
  | 
        erract[COMMAND].pf = eputs; | 
| 68 | 
+ | 
#ifdef DEBUG | 
| 69 | 
+ | 
        tmodesw = time(NULL); | 
| 70 | 
+ | 
#endif | 
| 71 | 
  | 
                                        /* enter main loop */ | 
| 72 | 
  | 
        do { | 
| 73 | 
  | 
                rdy = disp_wait(); | 
| 95 | 
  | 
                        if (inp & DFL(DC_PAUSE)) | 
| 96 | 
  | 
                                pause = 1; | 
| 97 | 
  | 
                        if (inp & DFL(DC_REDRAW)) | 
| 98 | 
< | 
                                imm_mode = beam_sync() > 0; | 
| 98 | 
> | 
                                imm_mode = beam_sync(1) > 0; | 
| 99 | 
  | 
                        if (inp & DFL(DC_KILL)) { | 
| 100 | 
  | 
                                serv_request(DR_KILL, 0, NULL); | 
| 101 | 
  | 
                                pause = 0; | 
| 123 | 
  | 
                                break; | 
| 124 | 
  | 
                        } | 
| 125 | 
  | 
        } while (res != DS_SHUTDOWN); | 
| 126 | 
+ | 
#ifdef DEBUG | 
| 127 | 
+ | 
        if (timm && nimmrays) | 
| 128 | 
+ | 
                fprintf(stderr, | 
| 129 | 
+ | 
                        "%s: %.1f rays recalled/second (%ld rays total)\n", | 
| 130 | 
+ | 
                                progname, (double)nimmrays/timm, nimmrays); | 
| 131 | 
+ | 
        if (tadd && naddrays) | 
| 132 | 
+ | 
                fprintf(stderr, | 
| 133 | 
+ | 
                        "%s: %.1f rays calculated/second (%ld rays total)\n", | 
| 134 | 
+ | 
                                progname, (double)naddrays/tadd, naddrays); | 
| 135 | 
+ | 
#endif | 
| 136 | 
  | 
                                        /* all done */ | 
| 137 | 
  | 
        quit(0); | 
| 138 | 
  | 
} | 
| 161 | 
  | 
        n = odev.ifd+1; | 
| 162 | 
  | 
        if (sstdin != NULL) { | 
| 163 | 
  | 
                FD_SET(fileno(sstdin), &readset); | 
| 164 | 
+ | 
                FD_SET(fileno(sstdin), &errset); | 
| 165 | 
  | 
                if (fileno(sstdin) >= n) | 
| 166 | 
  | 
                        n = fileno(sstdin) + 1; | 
| 167 | 
  | 
        } | 
| 176 | 
  | 
                flgs |= RDY_SRV; | 
| 177 | 
  | 
        if (FD_ISSET(odev.ifd, &readset) || FD_ISSET(odev.ifd, &errset)) | 
| 178 | 
  | 
                flgs |= RDY_DEV; | 
| 179 | 
< | 
        if (sstdin != NULL && FD_ISSET(fileno(sstdin), &readset)) | 
| 179 | 
> | 
        if (sstdin != NULL && (FD_ISSET(fileno(sstdin), &readset) || | 
| 180 | 
> | 
                                FD_ISSET(fileno(sstdin), &errset))) | 
| 181 | 
  | 
                flgs |= RDY_SIN; | 
| 182 | 
  | 
        return(flgs); | 
| 183 | 
  | 
} | 
| 187 | 
  | 
HDGRID  *hdg; | 
| 188 | 
  | 
{ | 
| 189 | 
  | 
        VIEW    nv; | 
| 190 | 
+ | 
        double  d; | 
| 191 | 
  | 
        register int    hd; | 
| 192 | 
  | 
 | 
| 193 | 
  | 
        for (hd = 0; hd < HDMAX && hdlist[hd] != NULL; hd++) | 
| 208 | 
  | 
        VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5); | 
| 209 | 
  | 
        fcross(nv.vdir, hdlist[0]->xv[1], hdlist[0]->xv[2]); | 
| 210 | 
  | 
        VCOPY(nv.vup, hdlist[0]->xv[2]); | 
| 211 | 
+ | 
        if (do_outside) { | 
| 212 | 
+ | 
                normalize(nv.vdir); | 
| 213 | 
+ | 
                d = VLEN(hdlist[0]->xv[1]); | 
| 214 | 
+ | 
                d += VLEN(hdlist[0]->xv[2]); | 
| 215 | 
+ | 
                VSUM(nv.vp, nv.vp, nv.vdir, -d); | 
| 216 | 
+ | 
        } | 
| 217 | 
  | 
        new_view(&nv); | 
| 218 | 
  | 
} | 
| 219 | 
  | 
 | 
| 237 | 
  | 
                VSUM(wp, ro, rd, d);            /* might be behind viewpoint */ | 
| 238 | 
  | 
                dev_value(packra(p)[i].v, wp, rd); | 
| 239 | 
  | 
        } | 
| 240 | 
+ | 
#ifdef DEBUG | 
| 241 | 
+ | 
        if (imm_mode) nimmrays += p->nr; | 
| 242 | 
+ | 
        else naddrays += p->nr; | 
| 243 | 
+ | 
#endif | 
| 244 | 
  | 
} | 
| 245 | 
  | 
 | 
| 246 | 
  | 
 | 
| 249 | 
  | 
{ | 
| 250 | 
  | 
        static VIEW     viewhist[VIEWHISTLEN]; | 
| 251 | 
  | 
        static unsigned nhist; | 
| 252 | 
+ | 
        VIEW    *dv; | 
| 253 | 
+ | 
        int     i, res[2]; | 
| 254 | 
  | 
        char    *err; | 
| 255 | 
  | 
                                /* restore previous view? */ | 
| 256 | 
  | 
        if (v == NULL) { | 
| 270 | 
  | 
                error(COMMAND, "cannot handle parallel views"); | 
| 271 | 
  | 
                return; | 
| 272 | 
  | 
        } | 
| 273 | 
< | 
        if (!dev_view(v))       /* update display driver */ | 
| 273 | 
> | 
        if (!dev_view(v))       /* notify display driver */ | 
| 274 | 
  | 
                goto again; | 
| 275 | 
  | 
        dev_flush();            /* update screen */ | 
| 276 | 
< | 
        if (!beam_view(v))      /* update beam list */ | 
| 277 | 
< | 
                goto again; | 
| 276 | 
> | 
        beam_init();            /* compute new beam set */ | 
| 277 | 
> | 
        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) | 
| 278 | 
> | 
                if (!beam_view(dv, res[0], res[1])) { | 
| 279 | 
> | 
                        if (!nhist) { | 
| 280 | 
> | 
                                error(COMMAND, "invalid starting view"); | 
| 281 | 
> | 
                                return; | 
| 282 | 
> | 
                        } | 
| 283 | 
> | 
                        copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN)); | 
| 284 | 
> | 
                        goto again; | 
| 285 | 
> | 
                } | 
| 286 | 
> | 
        beam_sync(0);           /* update server */ | 
| 287 | 
  | 
                                /* record new view */ | 
| 288 | 
  | 
        if (v < viewhist || v >= viewhist+VIEWHISTLEN) { | 
| 289 | 
  | 
                copystruct(viewhist + (nhist%VIEWHISTLEN), v); | 
| 296 | 
  | 
usr_input()                     /* get user input and process it */ | 
| 297 | 
  | 
{ | 
| 298 | 
  | 
        VIEW    vparams; | 
| 299 | 
< | 
        char    cmd[128]; | 
| 299 | 
> | 
        char    cmd[256]; | 
| 300 | 
  | 
        register char   *args; | 
| 301 | 
  | 
        register int    i; | 
| 302 | 
  | 
 | 
| 303 | 
< | 
        if (fgets(cmd, sizeof(cmd), sstdin) == NULL) | 
| 304 | 
< | 
                return(DC_QUIT); | 
| 303 | 
> | 
        if (fgets(cmd, sizeof(cmd), sstdin) == NULL) { | 
| 304 | 
> | 
                fclose(sstdin); | 
| 305 | 
> | 
                sstdin = NULL; | 
| 306 | 
> | 
                return(0); | 
| 307 | 
> | 
        } | 
| 308 | 
  | 
        for (args = cmd; *args && !isspace(*args); args++) | 
| 309 | 
  | 
                ; | 
| 310 | 
  | 
        while (isspace(*args)) | 
| 340 | 
  | 
                /* handled in main() */ | 
| 341 | 
  | 
                break; | 
| 342 | 
  | 
        case DC_REDRAW:                 /* redraw from server */ | 
| 343 | 
< | 
                imm_mode = beam_sync() > 0; | 
| 343 | 
> | 
                imm_mode = beam_sync(1) > 0; | 
| 344 | 
> | 
                dev_clear(); | 
| 345 | 
  | 
                break; | 
| 346 | 
  | 
        case DC_KILL:                   /* kill rtrace process(es) */ | 
| 347 | 
  | 
                serv_request(DR_KILL, 0, NULL); | 
| 405 | 
  | 
                        error(INTERNAL, "bad holodeck record from server"); | 
| 406 | 
  | 
                add_holo((HDGRID *)buf); | 
| 407 | 
  | 
                break; | 
| 408 | 
+ | 
        case DS_OUTSECT: | 
| 409 | 
+ | 
                do_outside = 1; | 
| 410 | 
+ | 
                break; | 
| 411 | 
+ | 
        case DS_EYESEP: | 
| 412 | 
+ | 
                if (msg.nbytes <= 1 || (eyesepdist = atof(buf)) <= FTINY) | 
| 413 | 
+ | 
                        error(INTERNAL, "bad eye separation from server"); | 
| 414 | 
+ | 
                break; | 
| 415 | 
  | 
        case DS_STARTIMM: | 
| 416 | 
  | 
        case DS_ENDIMM: | 
| 417 | 
+ | 
#ifdef DEBUG | 
| 418 | 
+ | 
                if (imm_mode != (msg.type==DS_STARTIMM)) { | 
| 419 | 
+ | 
                        time_t  tnow = time(NULL); | 
| 420 | 
+ | 
                        if (imm_mode) timm += tnow - tmodesw; | 
| 421 | 
+ | 
                        else tadd += tnow - tmodesw; | 
| 422 | 
+ | 
                        tmodesw = tnow; | 
| 423 | 
+ | 
                } | 
| 424 | 
+ | 
#endif | 
| 425 | 
  | 
                imm_mode = msg.type==DS_STARTIMM; | 
| 426 | 
  | 
                /* fall through */ | 
| 427 | 
  | 
        case DS_ACKNOW: |