| 1 |
#ifndef lint |
| 2 |
static const char RCSid[] = "$Id: preload.c,v 2.7 2003/02/25 02:47:23 greg Exp $"; |
| 3 |
#endif |
| 4 |
/* |
| 5 |
* Preload associated object structures to maximize memory sharing. |
| 6 |
* |
| 7 |
* External symbols declared in ray.h |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "copyright.h" |
| 11 |
|
| 12 |
#include "standard.h" |
| 13 |
#include "octree.h" |
| 14 |
#include "object.h" |
| 15 |
#include "otypes.h" |
| 16 |
#include "face.h" |
| 17 |
#include "cone.h" |
| 18 |
#include "instance.h" |
| 19 |
#include "color.h" |
| 20 |
#include "data.h" |
| 21 |
#include "func.h" |
| 22 |
#include "ray.h" |
| 23 |
|
| 24 |
|
| 25 |
/* KEEP THIS ROUTINE CONSISTENT WITH THE DIFFERENT OBJECT FUNCTIONS! */ |
| 26 |
|
| 27 |
|
| 28 |
extern int |
| 29 |
load_os( /* load associated data for object */ |
| 30 |
register OBJREC *op |
| 31 |
) |
| 32 |
{ |
| 33 |
DATARRAY *dp; |
| 34 |
|
| 35 |
switch (op->otype) { |
| 36 |
case OBJ_FACE: /* polygon */ |
| 37 |
getface(op); |
| 38 |
return(1); |
| 39 |
case OBJ_CONE: /* cone */ |
| 40 |
case OBJ_RING: /* disk */ |
| 41 |
case OBJ_CYLINDER: /* cylinder */ |
| 42 |
case OBJ_CUP: /* inverted cone */ |
| 43 |
case OBJ_TUBE: /* inverted cylinder */ |
| 44 |
getcone(op, 1); |
| 45 |
return(1); |
| 46 |
case OBJ_INSTANCE: /* octree instance */ |
| 47 |
getinstance(op, IO_ALL); |
| 48 |
return(1); |
| 49 |
case PAT_CPICT: /* color picture */ |
| 50 |
if (op->oargs.nsargs < 4) |
| 51 |
goto sargerr; |
| 52 |
getpict(op->oargs.sarg[3]); |
| 53 |
getfunc(op, 4, 0x3<<5, 0); |
| 54 |
return(1); |
| 55 |
case PAT_CDATA: /* color data */ |
| 56 |
dp = getdata(op->oargs.sarg[3]); |
| 57 |
getdata(op->oargs.sarg[4]); |
| 58 |
getdata(op->oargs.sarg[5]); |
| 59 |
getfunc(op, 6, ((1<<dp->nd)-1)<<7, 0); |
| 60 |
return(1); |
| 61 |
case PAT_BDATA: /* brightness data */ |
| 62 |
if (op->oargs.nsargs < 2) |
| 63 |
goto sargerr; |
| 64 |
dp = getdata(op->oargs.sarg[1]); |
| 65 |
getfunc(op, 2, ((1<<dp->nd)-1)<<3, 0); |
| 66 |
return(1); |
| 67 |
case PAT_BFUNC: /* brightness function */ |
| 68 |
getfunc(op, 1, 0x1, 0); |
| 69 |
return(1); |
| 70 |
case PAT_CFUNC: /* color function */ |
| 71 |
getfunc(op, 3, 0x7, 0); |
| 72 |
return(1); |
| 73 |
case TEX_DATA: /* texture data */ |
| 74 |
if (op->oargs.nsargs < 6) |
| 75 |
goto sargerr; |
| 76 |
dp = getdata(op->oargs.sarg[3]); |
| 77 |
getdata(op->oargs.sarg[4]); |
| 78 |
getdata(op->oargs.sarg[5]); |
| 79 |
getfunc(op, 6, ((1<<dp->nd)-1)<<7, 1); |
| 80 |
return(1); |
| 81 |
case TEX_FUNC: /* texture function */ |
| 82 |
getfunc(op, 3, 0x7, 1); |
| 83 |
return(1); |
| 84 |
case MIX_DATA: /* mixture data */ |
| 85 |
dp = getdata(op->oargs.sarg[3]); |
| 86 |
getfunc(op, 4, ((1<<dp->nd)-1)<<5, 0); |
| 87 |
return(1); |
| 88 |
case MIX_PICT: /* mixture picture */ |
| 89 |
getpict(op->oargs.sarg[3]); |
| 90 |
getfunc(op, 4, 0x3<<5, 0); |
| 91 |
return(1); |
| 92 |
case MIX_FUNC: /* mixture function */ |
| 93 |
getfunc(op, 3, 0x4, 0); |
| 94 |
return(1); |
| 95 |
case MAT_PLASTIC2: /* anisotropic plastic */ |
| 96 |
case MAT_METAL2: /* anisotropic metal */ |
| 97 |
getfunc(op, 3, 0x7, 1); |
| 98 |
return(1); |
| 99 |
case MAT_BRTDF: /* BRDTfunc material */ |
| 100 |
getfunc(op, 9, 0x3f, 0); |
| 101 |
return(1); |
| 102 |
case MAT_PDATA: /* plastic BRDF data */ |
| 103 |
case MAT_MDATA: /* metal BRDF data */ |
| 104 |
case MAT_TDATA: /* trans BRDF data */ |
| 105 |
if (op->oargs.nsargs < 2) |
| 106 |
goto sargerr; |
| 107 |
getdata(op->oargs.sarg[1]); |
| 108 |
getfunc(op, 2, 0, 0); |
| 109 |
return(1); |
| 110 |
case MAT_PFUNC: /* plastic BRDF func */ |
| 111 |
case MAT_MFUNC: /* metal BRDF func */ |
| 112 |
case MAT_TFUNC: /* trans BRDF func */ |
| 113 |
getfunc(op, 1, 0, 0); |
| 114 |
return(1); |
| 115 |
case MAT_DIRECT1: /* prism1 material */ |
| 116 |
getfunc(op, 4, 0xf, 1); |
| 117 |
return(1); |
| 118 |
case MAT_DIRECT2: /* prism2 material */ |
| 119 |
getfunc(op, 8, 0xff, 1); |
| 120 |
return(1); |
| 121 |
} |
| 122 |
/* nothing to load for the remaining types */ |
| 123 |
return(0); |
| 124 |
sargerr: |
| 125 |
objerror(op, USER, "too few string arguments"); |
| 126 |
return 0; /* pro forma return */ |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
extern void |
| 131 |
preload_objs(void) /* preload object data structures */ |
| 132 |
{ |
| 133 |
register OBJECT on; |
| 134 |
/* note that nobjects may change during loop */ |
| 135 |
for (on = 0; on < nobjects; on++) |
| 136 |
load_os(objptr(on)); |
| 137 |
} |