| 1 | 
greg | 
2.1 | 
#ifndef lint | 
| 2 | 
schorsch | 
2.8 | 
static const char       RCSid[] = "$Id: preload.c,v 2.7 2003/02/25 02:47:23 greg Exp $"; | 
| 3 | 
greg | 
2.1 | 
#endif | 
| 4 | 
  | 
  | 
/* | 
| 5 | 
  | 
  | 
 * Preload associated object structures to maximize memory sharing. | 
| 6 | 
greg | 
2.6 | 
 * | 
| 7 | 
  | 
  | 
 *  External symbols declared in ray.h | 
| 8 | 
  | 
  | 
 */ | 
| 9 | 
  | 
  | 
 | 
| 10 | 
greg | 
2.7 | 
#include "copyright.h" | 
| 11 | 
greg | 
2.1 | 
 | 
| 12 | 
  | 
  | 
#include "standard.h" | 
| 13 | 
greg | 
2.6 | 
#include "octree.h" | 
| 14 | 
greg | 
2.1 | 
#include "object.h" | 
| 15 | 
  | 
  | 
#include "otypes.h" | 
| 16 | 
  | 
  | 
#include "face.h" | 
| 17 | 
  | 
  | 
#include "cone.h" | 
| 18 | 
greg | 
2.2 | 
#include "instance.h" | 
| 19 | 
greg | 
2.5 | 
#include "color.h" | 
| 20 | 
  | 
  | 
#include "data.h" | 
| 21 | 
schorsch | 
2.8 | 
#include "func.h" | 
| 22 | 
  | 
  | 
#include "ray.h" | 
| 23 | 
greg | 
2.1 | 
 | 
| 24 | 
  | 
  | 
 | 
| 25 | 
greg | 
2.6 | 
/* KEEP THIS ROUTINE CONSISTENT WITH THE DIFFERENT OBJECT FUNCTIONS! */ | 
| 26 | 
  | 
  | 
 | 
| 27 | 
  | 
  | 
 | 
| 28 | 
schorsch | 
2.8 | 
extern int | 
| 29 | 
  | 
  | 
load_os(                        /* load associated data for object */ | 
| 30 | 
  | 
  | 
        register OBJREC *op | 
| 31 | 
  | 
  | 
) | 
| 32 | 
greg | 
2.1 | 
{ | 
| 33 | 
greg | 
2.6 | 
        DATARRAY  *dp; | 
| 34 | 
  | 
  | 
 | 
| 35 | 
greg | 
2.1 | 
        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 | 
greg | 
2.5 | 
        case PAT_CPICT:         /* color picture */ | 
| 50 | 
  | 
  | 
                if (op->oargs.nsargs < 4) | 
| 51 | 
  | 
  | 
                        goto sargerr; | 
| 52 | 
  | 
  | 
                getpict(op->oargs.sarg[3]); | 
| 53 | 
greg | 
2.6 | 
                getfunc(op, 4, 0x3<<5, 0); | 
| 54 | 
greg | 
2.5 | 
                return(1); | 
| 55 | 
  | 
  | 
        case PAT_CDATA:         /* color data */ | 
| 56 | 
greg | 
2.6 | 
                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 | 
greg | 
2.5 | 
        case TEX_DATA:          /* texture data */ | 
| 74 | 
  | 
  | 
                if (op->oargs.nsargs < 6) | 
| 75 | 
  | 
  | 
                        goto sargerr; | 
| 76 | 
greg | 
2.6 | 
                dp = getdata(op->oargs.sarg[3]); | 
| 77 | 
greg | 
2.5 | 
                getdata(op->oargs.sarg[4]); | 
| 78 | 
  | 
  | 
                getdata(op->oargs.sarg[5]); | 
| 79 | 
greg | 
2.6 | 
                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 | 
greg | 
2.5 | 
                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 | 
greg | 
2.6 | 
                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 | 
greg | 
2.5 | 
                return(1); | 
| 121 | 
greg | 
2.1 | 
        } | 
| 122 | 
greg | 
2.6 | 
                        /* nothing to load for the remaining types */ | 
| 123 | 
greg | 
2.2 | 
        return(0); | 
| 124 | 
greg | 
2.5 | 
sargerr: | 
| 125 | 
  | 
  | 
        objerror(op, USER, "too few string arguments"); | 
| 126 | 
schorsch | 
2.8 | 
        return 0; /* pro forma return */ | 
| 127 | 
greg | 
2.1 | 
} | 
| 128 | 
  | 
  | 
 | 
| 129 | 
  | 
  | 
 | 
| 130 | 
schorsch | 
2.8 | 
extern void | 
| 131 | 
  | 
  | 
preload_objs(void)              /* preload object data structures */ | 
| 132 | 
greg | 
2.1 | 
{ | 
| 133 | 
  | 
  | 
        register OBJECT on; | 
| 134 | 
greg | 
2.3 | 
                                /* note that nobjects may change during loop */ | 
| 135 | 
greg | 
2.1 | 
        for (on = 0; on < nobjects; on++) | 
| 136 | 
  | 
  | 
                load_os(objptr(on)); | 
| 137 | 
greg | 
2.3 | 
} |