| 1 | 
– | 
/* Copyright (c) 1998 Silicon Graphics, Inc. */ | 
| 2 | 
– | 
 | 
| 1 | 
  | 
#ifndef lint | 
| 2 | 
< | 
static char SCCSid[] = "$SunId$ SGI"; | 
| 2 | 
> | 
static const char       RCSid[] = "$Id$"; | 
| 3 | 
  | 
#endif | 
| 6 | 
– | 
 | 
| 4 | 
  | 
/* | 
| 5 | 
  | 
 * Holodeck display process. | 
| 6 | 
  | 
 */ | 
| 7 | 
  | 
 | 
| 8 | 
+ | 
#include <string.h> | 
| 9 | 
+ | 
#include <ctype.h> | 
| 10 | 
+ | 
 | 
| 11 | 
+ | 
#include "rterror.h" | 
| 12 | 
  | 
#include "rholo.h" | 
| 13 | 
  | 
#include "rhdisp.h" | 
| 14 | 
  | 
#include "rhdriver.h" | 
| 15 | 
  | 
#include "selcall.h" | 
| 15 | 
– | 
#include <ctype.h> | 
| 16 | 
  | 
 | 
| 17 | 
  | 
#ifndef VIEWHISTLEN | 
| 18 | 
  | 
#define VIEWHISTLEN     4       /* number of remembered views */ | 
| 22 | 
  | 
#define FSIZDEF         0.125   /* default focus frame size */ | 
| 23 | 
  | 
#endif | 
| 24 | 
  | 
 | 
| 25 | 
+ | 
#if defined(freebsd) | 
| 26 | 
+ | 
#define fbufcnt(f)      ((f)->_r) | 
| 27 | 
+ | 
#elif defined(__GNUC__) | 
| 28 | 
+ | 
#define fbufcnt(f)      ((f)->_IO_read_end - (f)->_IO_read_ptr) | 
| 29 | 
+ | 
#else | 
| 30 | 
+ | 
#define fbufcnt(f)      ((f)->_cnt) | 
| 31 | 
+ | 
#endif | 
| 32 | 
+ | 
 | 
| 33 | 
  | 
HOLO    *hdlist[HDMAX+1];       /* global holodeck list */ | 
| 34 | 
  | 
 | 
| 35 | 
  | 
char    *hdgfn[HDMAX];          /* holodeck section geometry list */ | 
| 48 | 
  | 
FILE    *sstdin, *sstdout;      /* server's standard input and output */ | 
| 49 | 
  | 
 | 
| 50 | 
  | 
#ifdef DEBUG | 
| 43 | 
– | 
#include <sys/types.h> | 
| 51 | 
  | 
extern time_t   time(); | 
| 52 | 
  | 
static time_t   tmodesw; | 
| 53 | 
  | 
static time_t   timm, tadd; | 
| 58 | 
  | 
#define RDY_DEV         02 | 
| 59 | 
  | 
#define RDY_SIN         04 | 
| 60 | 
  | 
 | 
| 61 | 
+ | 
static int disp_wait(void); | 
| 62 | 
+ | 
static void add_holo(HDGRID *hdg, char *gfn, char *pfn); | 
| 63 | 
+ | 
static void disp_bundle(PACKHEAD *p); | 
| 64 | 
+ | 
static void new_view(register VIEW *v); | 
| 65 | 
+ | 
static void set_focus(char *args); | 
| 66 | 
+ | 
static int usr_input(void); | 
| 67 | 
+ | 
static void printview(void); | 
| 68 | 
  | 
 | 
| 69 | 
< | 
main(argc, argv) | 
| 70 | 
< | 
int     argc; | 
| 71 | 
< | 
char    *argv[]; | 
| 69 | 
> | 
 | 
| 70 | 
> | 
int | 
| 71 | 
> | 
main( | 
| 72 | 
> | 
        int     argc, | 
| 73 | 
> | 
        char    *argv[] | 
| 74 | 
> | 
) | 
| 75 | 
  | 
{ | 
| 59 | 
– | 
        extern int      eputs(); | 
| 76 | 
  | 
        int     rdy, inp, res = 0, pause = 0; | 
| 77 | 
  | 
 | 
| 78 | 
  | 
        progname = argv[0]; | 
| 160 | 
  | 
#endif | 
| 161 | 
  | 
                                        /* all done */ | 
| 162 | 
  | 
        quit(0); | 
| 163 | 
+ | 
        return 0; /* pro forma return */ | 
| 164 | 
  | 
} | 
| 165 | 
  | 
 | 
| 166 | 
  | 
 | 
| 167 | 
< | 
int | 
| 168 | 
< | 
disp_wait()                     /* wait for more input */ | 
| 167 | 
> | 
static int | 
| 168 | 
> | 
disp_wait(void)                 /* wait for more input */ | 
| 169 | 
  | 
{ | 
| 170 | 
  | 
        fd_set  readset, errset; | 
| 171 | 
  | 
        int     flgs; | 
| 172 | 
  | 
        int     n; | 
| 156 | 
– | 
        register int    i; | 
| 173 | 
  | 
                                /* see if we can avoid select call */ | 
| 174 | 
+ | 
        if (hdlist[0] == NULL) | 
| 175 | 
+ | 
                return(RDY_SRV);        /* initialize first */ | 
| 176 | 
  | 
        flgs = 0;               /* flag what's ready already */ | 
| 177 | 
< | 
        if (imm_mode || stdin->_cnt > 0) | 
| 177 | 
> | 
        if (imm_mode || fbufcnt(stdin) > 0) | 
| 178 | 
  | 
                flgs |= RDY_SRV; | 
| 179 | 
< | 
        if (sstdin != NULL && sstdin->_cnt > 0) | 
| 179 | 
> | 
        if (sstdin != NULL && fbufcnt(sstdin) > 0) | 
| 180 | 
  | 
                flgs |= RDY_SIN; | 
| 181 | 
  | 
        if (odev.inpready) | 
| 182 | 
  | 
                flgs |= RDY_DEV; | 
| 214 | 
  | 
} | 
| 215 | 
  | 
 | 
| 216 | 
  | 
 | 
| 217 | 
< | 
add_holo(hdg, gfn, pfn)         /* register a new holodeck section */ | 
| 218 | 
< | 
HDGRID  *hdg; | 
| 219 | 
< | 
char    *gfn, *pfn; | 
| 217 | 
> | 
static void | 
| 218 | 
> | 
add_holo(               /* register a new holodeck section */ | 
| 219 | 
> | 
        HDGRID  *hdg, | 
| 220 | 
> | 
        char    *gfn, | 
| 221 | 
> | 
        char    *pfn | 
| 222 | 
> | 
) | 
| 223 | 
  | 
{ | 
| 224 | 
  | 
        VIEW    nv; | 
| 225 | 
  | 
        double  d; | 
| 232 | 
  | 
        hdlist[hd] = (HOLO *)malloc(sizeof(HOLO)); | 
| 233 | 
  | 
        if (hdlist[hd] == NULL) | 
| 234 | 
  | 
                error(SYSTEM, "out of memory in add_holo"); | 
| 235 | 
< | 
        bcopy((char *)hdg, (char *)hdlist[hd], sizeof(HDGRID)); | 
| 235 | 
> | 
        memcpy((void *)hdlist[hd], (void *)hdg, sizeof(HDGRID)); | 
| 236 | 
  | 
        hdcompgrid(hdlist[hd]); | 
| 237 | 
  | 
        hdgfn[hd] = savestr(gfn); | 
| 238 | 
  | 
        hdpfn[hd] = pfn && *pfn ? savestr(pfn) : (char *)NULL; | 
| 239 | 
  | 
        if (hd) | 
| 240 | 
  | 
                return; | 
| 241 | 
  | 
                                        /* set initial viewpoint */ | 
| 242 | 
< | 
        copystruct(&nv, &odev.v); | 
| 242 | 
> | 
        nv = odev.v; | 
| 243 | 
  | 
        VSUM(nv.vp, hdlist[0]->orig, hdlist[0]->xv[0], 0.5); | 
| 244 | 
  | 
        VSUM(nv.vp, nv.vp, hdlist[0]->xv[1], 0.5); | 
| 245 | 
  | 
        VSUM(nv.vp, nv.vp, hdlist[0]->xv[2], 0.5); | 
| 255 | 
  | 
} | 
| 256 | 
  | 
 | 
| 257 | 
  | 
 | 
| 258 | 
< | 
disp_bundle(p)                  /* display a ray bundle */ | 
| 259 | 
< | 
register PACKHEAD       *p; | 
| 258 | 
> | 
static void | 
| 259 | 
> | 
disp_bundle(                    /* display a ray bundle */ | 
| 260 | 
> | 
        register PACKHEAD       *p | 
| 261 | 
> | 
) | 
| 262 | 
  | 
{ | 
| 263 | 
  | 
        GCOORD  gc[2]; | 
| 264 | 
  | 
        FVECT   ro, rd, wp; | 
| 265 | 
  | 
        double  d; | 
| 266 | 
  | 
        register int    i; | 
| 267 | 
  | 
                                        /* get beam coordinates */ | 
| 268 | 
< | 
        if (p->hd < 0 | p->hd >= HDMAX || hdlist[p->hd] == NULL) | 
| 268 | 
> | 
        if ((p->hd < 0) | (p->hd >= HDMAX) || hdlist[p->hd] == NULL) | 
| 269 | 
  | 
                error(INTERNAL, "bad holodeck number in disp_bundle"); | 
| 270 | 
  | 
        if (!hdbcoord(gc, hdlist[p->hd], p->bi)) | 
| 271 | 
  | 
                error(INTERNAL, "bad beam index in disp_bundle"); | 
| 286 | 
  | 
} | 
| 287 | 
  | 
 | 
| 288 | 
  | 
 | 
| 289 | 
< | 
new_view(v)                     /* change view parameters */ | 
| 290 | 
< | 
register VIEW   *v; | 
| 289 | 
> | 
static void | 
| 290 | 
> | 
new_view(                       /* change view parameters */ | 
| 291 | 
> | 
        register VIEW   *v | 
| 292 | 
> | 
) | 
| 293 | 
  | 
{ | 
| 294 | 
  | 
        static VIEW     viewhist[VIEWHISTLEN]; | 
| 295 | 
  | 
        static unsigned nhist; | 
| 296 | 
  | 
        VIEW    *dv; | 
| 297 | 
< | 
        int     i, res[2], *slist; | 
| 297 | 
> | 
        int     i, res[2]; | 
| 298 | 
> | 
        int16   *slist; | 
| 299 | 
  | 
        char    *err; | 
| 300 | 
  | 
                                /* restore previous view? */ | 
| 301 | 
  | 
        if (v == NULL) { | 
| 324 | 
  | 
                                error(COMMAND, "invalid starting view"); | 
| 325 | 
  | 
                                return; | 
| 326 | 
  | 
                        } | 
| 327 | 
< | 
                        copystruct(v, viewhist + ((nhist-1)%VIEWHISTLEN)); | 
| 328 | 
< | 
                        goto again;     /* poss. overloading dev_section()? */ | 
| 327 | 
> | 
                        *v = *(viewhist + ((nhist-1)%VIEWHISTLEN)); | 
| 328 | 
> | 
                        goto again;     /* XXX overloading dev_section()? */ | 
| 329 | 
  | 
                } | 
| 330 | 
  | 
                DCHECK(*slist < 0, WARNING, "no visible sections in new_view"); | 
| 331 | 
  | 
                for ( ; *slist >= 0; slist++) | 
| 337 | 
  | 
        imm_mode = beam_sync(odev.firstuse) > 0; | 
| 338 | 
  | 
                                /* record new view */ | 
| 339 | 
  | 
        if (v < viewhist || v >= viewhist+VIEWHISTLEN) { | 
| 340 | 
< | 
                copystruct(viewhist + (nhist%VIEWHISTLEN), v); | 
| 340 | 
> | 
                *(viewhist + (nhist%VIEWHISTLEN)) = *v; | 
| 341 | 
  | 
                nhist++; | 
| 342 | 
  | 
        } | 
| 343 | 
  | 
} | 
| 344 | 
  | 
 | 
| 345 | 
  | 
 | 
| 346 | 
< | 
set_focus(args)                 /* set focus frame */ | 
| 347 | 
< | 
char    *args; | 
| 346 | 
> | 
static void | 
| 347 | 
> | 
set_focus(                      /* set focus frame */ | 
| 348 | 
> | 
        char    *args | 
| 349 | 
> | 
) | 
| 350 | 
  | 
{ | 
| 351 | 
  | 
        double  hcent, vcent, hsiz, vsiz; | 
| 352 | 
  | 
        VIEW    *dv, vwfocus; | 
| 369 | 
  | 
        beam_init(0);                                   /* add basic views */ | 
| 370 | 
  | 
        for (i = 0; (dv = dev_auxview(i, res)) != NULL; i++) | 
| 371 | 
  | 
                beam_view(dv, res[0]>>4, res[1]>>4); | 
| 372 | 
< | 
        copystruct(&vwfocus, &odev.v);                  /* add focus view */ | 
| 372 | 
> | 
        vwfocus = odev.v;                       /* add focus view */ | 
| 373 | 
  | 
        switch (odev.v.type) { | 
| 374 | 
  | 
        case VT_PER: | 
| 375 | 
  | 
                vwfocus.horiz = 2.*180./PI*atan( | 
| 405 | 
  | 
} | 
| 406 | 
  | 
 | 
| 407 | 
  | 
 | 
| 408 | 
< | 
int | 
| 409 | 
< | 
usr_input()                     /* get user input and process it */ | 
| 408 | 
> | 
static int | 
| 409 | 
> | 
usr_input(void)                 /* get user input and process it */ | 
| 410 | 
  | 
{ | 
| 411 | 
  | 
        VIEW    vparams; | 
| 412 | 
  | 
        char    cmd[256]; | 
| 435 | 
  | 
        } | 
| 436 | 
  | 
        switch (i) { | 
| 437 | 
  | 
        case DC_SETVIEW:                /* set the view */ | 
| 438 | 
< | 
                copystruct(&vparams, &odev.v); | 
| 438 | 
> | 
                vparams = odev.v; | 
| 439 | 
  | 
                if (!sscanview(&vparams, args)) | 
| 440 | 
  | 
                        error(COMMAND, "missing view options"); | 
| 441 | 
  | 
                else | 
| 477 | 
  | 
} | 
| 478 | 
  | 
 | 
| 479 | 
  | 
 | 
| 480 | 
< | 
printview()                     /* print our current view to server stdout */ | 
| 480 | 
> | 
static void | 
| 481 | 
> | 
printview(void)                 /* print our current view to server stdout */ | 
| 482 | 
  | 
{ | 
| 483 | 
  | 
        fputs(VIEWSTR, sstdout); | 
| 484 | 
  | 
        fprintview(&odev.v, sstdout); | 
| 487 | 
  | 
} | 
| 488 | 
  | 
 | 
| 489 | 
  | 
 | 
| 490 | 
< | 
int | 
| 491 | 
< | 
serv_result()                   /* get next server result and process it */ | 
| 490 | 
> | 
extern int | 
| 491 | 
> | 
serv_result(void)                       /* get next server result and process it */ | 
| 492 | 
  | 
{ | 
| 493 | 
  | 
        static char     *buf = NULL; | 
| 494 | 
  | 
        static int      bufsiz = 0; | 
| 495 | 
  | 
        MSGHEAD msg; | 
| 467 | 
– | 
        int     n; | 
| 496 | 
  | 
                                        /* read message header */ | 
| 497 | 
  | 
        if (fread((char *)&msg, sizeof(MSGHEAD), 1, stdin) != 1) | 
| 498 | 
  | 
                goto readerr; | 
| 501 | 
  | 
                        if (buf == NULL) | 
| 502 | 
  | 
                                buf = (char *)malloc(bufsiz=msg.nbytes); | 
| 503 | 
  | 
                        else | 
| 504 | 
< | 
                                buf = (char *)realloc(buf, bufsiz=msg.nbytes); | 
| 504 | 
> | 
                                buf = (char *)realloc((void *)buf, | 
| 505 | 
> | 
                                                bufsiz=msg.nbytes); | 
| 506 | 
  | 
                        if (buf == NULL) | 
| 507 | 
  | 
                                error(SYSTEM, "out of memory in serv_result"); | 
| 508 | 
  | 
                } | 
| 560 | 
  | 
        if (feof(stdin)) | 
| 561 | 
  | 
                error(SYSTEM, "server process died"); | 
| 562 | 
  | 
        error(SYSTEM, "error reading from server process"); | 
| 563 | 
+ | 
        return -1;   | 
| 564 | 
  | 
} | 
| 565 | 
  | 
 | 
| 566 | 
  | 
 | 
| 567 | 
< | 
serv_request(type, nbytes, p)   /* send a request to the server process */ | 
| 568 | 
< | 
int     type, nbytes; | 
| 569 | 
< | 
char    *p; | 
| 567 | 
> | 
extern void | 
| 568 | 
> | 
serv_request(   /* send a request to the server process */ | 
| 569 | 
> | 
        int     type, | 
| 570 | 
> | 
        int     nbytes, | 
| 571 | 
> | 
        char    *p | 
| 572 | 
> | 
) | 
| 573 | 
  | 
{ | 
| 574 | 
  | 
        MSGHEAD msg; | 
| 575 | 
  | 
        int     m; | 
| 593 | 
  | 
} | 
| 594 | 
  | 
 | 
| 595 | 
  | 
 | 
| 596 | 
< | 
eputs(s)                        /* put error message to stderr */ | 
| 597 | 
< | 
register char  *s; | 
| 596 | 
> | 
void | 
| 597 | 
> | 
eputs(                  /* put error message to stderr */ | 
| 598 | 
> | 
        register char  *s | 
| 599 | 
> | 
) | 
| 600 | 
  | 
{ | 
| 601 | 
  | 
        static int  midline = 0; | 
| 602 | 
  | 
 | 
| 614 | 
  | 
} | 
| 615 | 
  | 
 | 
| 616 | 
  | 
 | 
| 617 | 
< | 
quit(code)                      /* clean up and exit */ | 
| 618 | 
< | 
int     code; | 
| 617 | 
> | 
void | 
| 618 | 
> | 
quit(                   /* clean up and exit */ | 
| 619 | 
> | 
        int     code | 
| 620 | 
> | 
) | 
| 621 | 
  | 
{ | 
| 622 | 
  | 
        if (code) | 
| 623 | 
  | 
                exit(code); |