--- ray/src/hd/rhd_x11.c 2003/04/14 16:56:19 3.33 +++ ray/src/hd/rhd_x11.c 2005/01/07 20:33:02 3.38 @@ -1,18 +1,25 @@ #ifndef lint -static const char RCSid[] = "$Id: rhd_x11.c,v 3.33 2003/04/14 16:56:19 greg Exp $"; +static const char RCSid[] = "$Id: rhd_x11.c,v 3.38 2005/01/07 20:33:02 greg Exp $"; #endif /* * X11 driver for holodeck display. * Based on rview driver. */ -#include "standard.h" +#include +#include #include #include #include #include + +#include "platform.h" +#include "rtmath.h" +#include "rterror.h" +#include "plocate.h" +#include "rhdisp.h" #include "rhd_qtree.h" -#include "x11icon.h" +#include "x11icon.h" #ifndef RAYQLEN #define RAYQLEN 50000 /* max. rays to queue before flush */ @@ -47,6 +54,8 @@ static const char RCSid[] = "$Id: rhd_x11.c,v 3.33 200 struct driver odev; /* global device driver structure */ +TMstruct *tmGlobal; /* global tone-mapping structure */ + char odev_args[64]; /* command arguments */ static XEvent currentevent; /* current event */ @@ -68,13 +77,27 @@ static int inpresflags; /* input result flags */ static int headlocked = 0; /* lock vertical motion */ -static int getpixels(), xnewcolr(), freepixels(), resizewindow(), getframe(), - getevent(), getkey(), moveview(), getmove(), fixwindow(); -static unsigned long true_pixel(); +static int mytmflags(void); +static void xnewcolr(int ndx, int r, int g, int b); +static int getpixels(void); +static void freepixels(void); +static unsigned long true_pixel(register BYTE rgb[3]); +static void getevent(void); +static int ilclip(int dp[2][2], FVECT wp[2]); +static void draw3dline(FVECT wp[2]); +static void draw_grids(void); +static int moveview(int dx, int dy, int mov, int orb); +static void getframe(XButtonPressedEvent *ebut); +static void waitabit(void); +static void getmove(XButtonPressedEvent *ebut); +static void getkey(register XKeyPressedEvent *ekey); +static void fixwindow(register XExposeEvent *eexp); +static void resizewindow(register XConfigureEvent *ersz); + static int -mytmflags() /* figure out tone mapping flags */ +mytmflags(void) /* figure out tone mapping flags */ { extern char *progname; register char *cp, *tail; @@ -89,13 +112,15 @@ mytmflags() /* figure out tone mapping flags */ if (cp-tail == 4 && !strncmp(tail, "x11h", 4)) return(TM_F_HUMAN|TM_F_NOSTDERR); error(USER, "illegal driver name"); + return 0; /* pro forma return */ } -dev_open(id) /* initialize X11 driver */ -char *id; +extern void +dev_open( /* initialize X11 driver */ + char *id +) { - extern char *getenv(); static RGBPRIMS myprims = STDPRIMS; char *ev; double gamval = GAMMA; @@ -142,7 +167,8 @@ char *id; &myprims[BLU][CIEX],&myprims[BLU][CIEY], &myprims[WHT][CIEX],&myprims[WHT][CIEY]) >= 6) dpri = myprims; - if (tmInit(mytmflags(), dpri, gamval) == NULL) + tmGlobal = tmInit(mytmflags(), dpri, gamval); + if (tmGlobal == NULL) error(SYSTEM, "not enough memory in dev_open"); /* open window */ ourwinattr.background_pixel = ourblack; @@ -176,7 +202,7 @@ char *id; DisplayWidth(ourdisplay, ourscreen); pheight = (double)DisplayHeightMM(ourdisplay, ourscreen) / DisplayHeight(ourdisplay, ourscreen); - copystruct(&odev.v, &stdview); + odev.v = stdview; odev.v.type = VT_PER; /* map the window and get its size */ XMapWindow(ourdisplay, gwind); @@ -191,7 +217,8 @@ char *id; } -dev_close() /* close our display */ +extern void +dev_close(void) /* close our display */ { freepixels(); XFreeGC(ourdisplay, ourgc); @@ -201,15 +228,15 @@ dev_close() /* close our display */ XCloseDisplay(ourdisplay); ourdisplay = NULL; qtFreeLeaves(); - tmDone(NULL); + tmDone(tmGlobal); odev.v.type = 0; odev.hres = odev.vres = 0; odev.ifd = -1; } - -dev_clear() /* clear our quadtree */ +extern void +dev_clear(void) /* clear our quadtree */ { qtCompost(100); if (ncolors > 0) @@ -218,9 +245,10 @@ dev_clear() /* clear our quadtree */ } -int -dev_view(nv) /* assign new driver view */ -VIEW *nv; +extern int +dev_view( /* assign new driver view */ + VIEW *nv +) { if (nv->type == VT_PAR || /* check view legality */ nv->horiz > 160. || nv->vert > 160.) { @@ -258,32 +286,38 @@ VIEW *nv; XResizeWindow(ourdisplay, gwind, odev.hres, odev.vres); dev_input(); /* wait for resize event */ } - copystruct(&odev.v, nv); + odev.v = *nv; } qtReplant(); return(1); } -dev_section(ofn) /* add octree for geometry rendering */ -char *ofn; +extern void +dev_section( /* add octree for geometry rendering */ + char *ofn +) { /* unimplemented */ } -dev_auxcom(cmd, args) /* process an auxiliary command */ -char *cmd, *args; +extern void +dev_auxcom( /* process an auxiliary command */ + char *cmd, + char *args +) { sprintf(errmsg, "%s: unknown command", cmd); error(COMMAND, errmsg); } -VIEW * -dev_auxview(n, hvres) /* return nth auxiliary view */ -int n; -int hvres[2]; +extern VIEW * +dev_auxview( /* return nth auxiliary view */ + int n, + int hvres[2] +) { if (n) return(NULL); @@ -292,8 +326,8 @@ int hvres[2]; } -int -dev_input() /* get X11 input */ +extern int +dev_input(void) /* get X11 input */ { inpresflags = 0; @@ -308,9 +342,14 @@ dev_input() /* get X11 input */ } -dev_paintr(rgb, xmin, ymin, xmax, ymax) /* fill a rectangle */ -BYTE rgb[3]; -int xmin, ymin, xmax, ymax; +extern void +dev_paintr( /* fill a rectangle */ + BYTE rgb[3], + int xmin, + int ymin, + int xmax, + int ymax +) { unsigned long pixel; @@ -326,8 +365,8 @@ int xmin, ymin, xmax, ymax; } -int -dev_flush() /* flush output */ +extern int +dev_flush(void) /* flush output */ { qtUpdate(); rayqleft = RAYQLEN; @@ -335,10 +374,13 @@ dev_flush() /* flush output */ } -static -xnewcolr(ndx, r, g, b) /* enter a color into hardware table */ -int ndx; -int r, g, b; +static void +xnewcolr( /* enter a color into hardware table */ + int ndx, + int r, + int g, + int b +) { XColor xcolor; @@ -353,7 +395,7 @@ int r, g, b; static int -getpixels() /* get the color map */ +getpixels(void) /* get the color map */ { XColor thiscolor; register int i, j; @@ -404,8 +446,8 @@ loop: } -static -freepixels() /* free our pixels */ +static void +freepixels(void) /* free our pixels */ { if (ncolors == 0) return; @@ -420,8 +462,9 @@ freepixels() /* free our pixels */ static unsigned long -true_pixel(rgb) /* return true pixel value for color */ -register BYTE rgb[3]; +true_pixel( /* return true pixel value for color */ + register BYTE rgb[3] +) { register unsigned long rval; @@ -432,8 +475,8 @@ register BYTE rgb[3]; } -static -getevent() /* get next event */ +static void +getevent(void) /* get next event */ { XNextEvent(ourdisplay, levptr(XEvent)); switch (levptr(XEvent)->type) { @@ -469,10 +512,11 @@ getevent() /* get next event */ } -static -ilclip(dp, wp) /* clip world coordinates to device */ -int dp[2][2]; -FVECT wp[2]; +static int +ilclip( /* clip world coordinates to device */ + int dp[2][2], + FVECT wp[2] +) { static FVECT vmin = {0.,0.,0.}, vmax = {1.-FTINY,1.-FTINY,FHUGE}; FVECT wpc[2], ip[2]; @@ -507,9 +551,10 @@ FVECT wp[2]; } -static -draw3dline(wp) /* draw 3d line in world coordinates */ -FVECT wp[2]; +static void +draw3dline( /* draw 3d line in world coordinates */ + FVECT wp[2] +) { int dp[2][2]; @@ -521,8 +566,8 @@ FVECT wp[2]; } -static -draw_grids() /* draw holodeck section grids */ +static void +draw_grids(void) /* draw holodeck section grids */ { static BYTE gridrgb[3] = {0x0, 0xff, 0xff}; unsigned long pixel; @@ -537,16 +582,20 @@ draw_grids() /* draw holodeck section grids */ } -static -moveview(dx, dy, mov, orb) /* move our view */ -int dx, dy, mov, orb; +static int +moveview( /* move our view */ + int dx, + int dy, + int mov, + int orb +) { VIEW nv; FVECT odir, v1; double d; register int li; /* start with old view */ - copystruct(&nv, &odev.v); + nv = odev.v; /* change view direction */ if (mov | orb) { if ((li = qtFindLeaf(dx, dy)) < 0) @@ -585,9 +634,10 @@ int dx, dy, mov, orb; } -static -getframe(ebut) /* get focus frame */ -XButtonPressedEvent *ebut; +static void +getframe( /* get focus frame */ + XButtonPressedEvent *ebut +) { int startx = ebut->x, starty = ebut->y; int endx, endy; @@ -595,7 +645,7 @@ XButtonPressedEvent *ebut; XMaskEvent(ourdisplay, ButtonReleaseMask, levptr(XEvent)); endx = levptr(XButtonReleasedEvent)->x; endy = levptr(XButtonReleasedEvent)->y; - if (endx == startx | endy == starty) { + if ((endx == startx) | (endy == starty)) { XBell(ourdisplay, 0); return; } @@ -608,19 +658,20 @@ XButtonPressedEvent *ebut; } -static -waitabit() /* pause a moment */ +static void +waitabit(void) /* pause a moment */ { struct timespec ts; ts.tv_sec = 0; - ts.tv_nsec = 50000000; + ts.tv_nsec = 100000000; nanosleep(&ts, NULL); } -static -getmove(ebut) /* get view change */ -XButtonPressedEvent *ebut; +static void +getmove( /* get view change */ + XButtonPressedEvent *ebut +) { int movdir = MOVDIR(ebut->button); int movorb = MOVORB(ebut->state); @@ -659,9 +710,10 @@ XButtonPressedEvent *ebut; } -static -getkey(ekey) /* get input key */ -register XKeyPressedEvent *ekey; +static void +getkey( /* get input key */ + register XKeyPressedEvent *ekey +) { Window rootw, childw; int rootx, rooty, wx, wy; @@ -740,9 +792,10 @@ register XKeyPressedEvent *ekey; } -static -fixwindow(eexp) /* repair damage to window */ -register XExposeEvent *eexp; +static void +fixwindow( /* repair damage to window */ + register XExposeEvent *eexp +) { if (odev.hres == 0 || odev.vres == 0) { /* first exposure */ odev.hres = eexp->width; @@ -753,9 +806,10 @@ register XExposeEvent *eexp; } -static -resizewindow(ersz) /* resize window */ -register XConfigureEvent *ersz; +static void +resizewindow( /* resize window */ + register XConfigureEvent *ersz +) { if (ersz->width == odev.hres && ersz->height == odev.vres) return;