--- ray/src/common/rglinst.c 1998/06/09 11:18:35 3.1 +++ ray/src/common/rglinst.c 2003/06/05 19:29:34 3.9 @@ -1,16 +1,18 @@ -/* Copyright (c) 1998 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rglinst.c,v 3.9 2003/06/05 19:29:34 schorsch Exp $"; #endif - /* * Routines for reading instances and converting to OpenGL. */ +#include "copyright.h" + #include "radogl.h" #include "octree.h" +#include "platform.h" +#define MAXLEVEL 16 /* maximum instance hierarchy level */ + typedef struct { int listid; /* our list id */ short localmatl; /* uses local material only */ @@ -18,14 +20,12 @@ typedef struct { char octfile[256]; /* octree file path */ } OCTINST; /* octree to instantiate */ -OBJECT nobjects; /* number of objects loaded so far */ - -extern int free(); - static double ogetflt(); static long ogetint(); static char *ogetstr(); -static int loadobj(), octerror(), skiptree(); +static int loadobj(); +static void skiptree(); +static void octerror(); static OCTINST *getoct(); static char *infn; /* input file name */ @@ -33,12 +33,13 @@ static FILE *infp; /* input file stream */ static int objsize; /* size of stored OBJECT's */ static short otypmap[NUMOTYPE+8]; /* object type map */ -static long imhash(mod) char *mod; {return((long)mod);} +static unsigned long imhash(mod) char *mod; {return((unsigned long)mod);} static LUTAB imtab = {imhash,NULL,NULL,NULL,0,NULL,0}; static LUTAB ottab = LU_SINIT(free,free); +int o_instance(o) /* convert instance to list call */ register OBJREC *o; { @@ -67,15 +68,17 @@ register OBJREC *o; } ot = getoct(o->oargs.sarg[0]); /* get octree reference */ if (ot->localmatl &= o->os != NULL) /* set material */ - setmaterial(o->os, ot->cent, 0); + setmaterial((MATREC *)o->os, ot->cent, 0); /* call the assigned list */ glCallList(ot->listid); if (o->oargs.nsargs > 1) { /* end transform */ + glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); } rgl_checkerr("creating instance"); + return(0); } @@ -101,10 +104,13 @@ LUENT *lp; int loadoctrees() /* load octrees we've saved up */ { + int levelsleft = MAXLEVEL; int nocts = 0; LUTAB looptab; /* loop through new octree references */ while (ottab.tsiz) { + if (!levelsleft--) + error(USER, "too many octree levels -- instance loop?"); copystruct(&looptab, &ottab); ottab.tsiz = 0; nocts += lu_doall(&looptab, buildoctlist); @@ -118,7 +124,6 @@ static OCTINST * getoct(name) /* get/assign octree list id */ char *name; { - extern char *getpath(), *getlibpath(); char *path; register LUENT *lp; register OCTINST *op; @@ -132,7 +137,7 @@ char *name; strcpy(lp->key, name); } if ((op = (OCTINST *)lp->data) == NULL) { - path = getpath(name, getlibpath(), R_OK); + path = getpath(name, getrlibpath(), R_OK); if (path == NULL) { sprintf(errmsg, "cannot find octree \"%s\"", name); error(USER, errmsg); @@ -164,9 +169,7 @@ FVECT cent; sprintf(errmsg, "cannot open octree file \"%s\"", fname); error(SYSTEM, errmsg); } -#ifdef MSDOS - setmode(fileno(infp), O_BINARY); -#endif + SET_FILE_BINARY(infp); /* get header */ if (checkheader(infp, OCTFMT, NULL) < 0) octerror(USER, "not an octree"); @@ -191,6 +194,7 @@ FVECT cent; } +int loadoct(fname) /* read in objects from octree */ char *fname; { @@ -202,9 +206,7 @@ char *fname; infn = fname; infp = fopen(fname, "r"); /* assume already checked */ -#ifdef MSDOS - setmode(fileno(infp), O_BINARY); -#endif + SET_FILE_BINARY(infp); /* skip header */ getheader(infp, NULL, NULL); /* get format */ @@ -280,7 +282,7 @@ ogetflt() /* get a floating point number */ } -static +static void skiptree() /* skip octree on input */ { register int i; @@ -305,7 +307,7 @@ skiptree() /* skip octree on input */ } -static +static int loadobj() /* get next object */ { static OBJREC ob; @@ -378,7 +380,7 @@ memerr: } -static +static void octerror(etyp, msg) /* octree error */ int etyp; char *msg;