| 1 |
gregl |
3.1 |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 2 |
|
|
|
| 3 |
|
|
/* SCCSid "$SunId$ SGI" */ |
| 4 |
|
|
|
| 5 |
|
|
/* |
| 6 |
|
|
* Header file for holodeck programs |
| 7 |
|
|
* |
| 8 |
|
|
* 9/29/97 GWLarson |
| 9 |
|
|
*/ |
| 10 |
|
|
|
| 11 |
|
|
#include "standard.h" |
| 12 |
|
|
#include "color.h" |
| 13 |
|
|
|
| 14 |
|
|
#ifndef HDMAX |
| 15 |
|
|
#define HDMAX 128 /* maximum active holodeck sections */ |
| 16 |
|
|
#endif |
| 17 |
|
|
#ifndef int2 |
| 18 |
|
|
#define int2 short |
| 19 |
|
|
#endif |
| 20 |
|
|
#ifndef int4 |
| 21 |
|
|
#define int4 long |
| 22 |
|
|
#endif |
| 23 |
|
|
|
| 24 |
|
|
#define DCINF (unsigned)((1L<<16)-1) /* special value for infinity */ |
| 25 |
|
|
#define DCLIN (unsigned)(1L<<11) /* linear depth limit */ |
| 26 |
|
|
|
| 27 |
|
|
typedef struct { |
| 28 |
|
|
BYTE r[2][2]; /* ray direction index */ |
| 29 |
|
|
COLR v; /* value */ |
| 30 |
|
|
unsigned int2 d; /* depth code */ |
| 31 |
|
|
} RAYVAL; /* ray value (from second wall) */ |
| 32 |
|
|
|
| 33 |
|
|
/* |
| 34 |
|
|
* Walls are ordered: X0 X1 X2 WN |
| 35 |
|
|
* 0 ? ? 0 |
| 36 |
|
|
* 1 ? ? 1 |
| 37 |
|
|
* ? 0 ? 2 |
| 38 |
|
|
* ? 1 ? 3 |
| 39 |
|
|
* ? ? 0 4 |
| 40 |
|
|
* ? ? 1 5 |
| 41 |
|
|
* |
| 42 |
|
|
* Grid on wall WN corresponds to X(WN/2+1)%3 and X(WN/2+2)%3, resp. |
| 43 |
|
|
*/ |
| 44 |
|
|
|
| 45 |
|
|
typedef struct { |
| 46 |
|
|
short w; /* wall number */ |
| 47 |
|
|
short i[2]; /* index on wall grid */ |
| 48 |
gregl |
3.2 |
} GCOORD; /* grid coordinates (two for beam) */ |
| 49 |
gregl |
3.1 |
|
| 50 |
|
|
typedef struct { |
| 51 |
|
|
unsigned int4 nrd; /* number of beam rays bundled on disk */ |
| 52 |
|
|
long fo; /* position in file */ |
| 53 |
|
|
} BEAMI; /* beam index */ |
| 54 |
|
|
|
| 55 |
|
|
typedef struct { |
| 56 |
|
|
unsigned int4 nrm; /* number of beam rays bundled in memory */ |
| 57 |
|
|
unsigned long tick; /* clock tick for LRU replacement */ |
| 58 |
|
|
} BEAM; /* followed by nrm RAYVAL's */ |
| 59 |
|
|
|
| 60 |
gregl |
3.3 |
#define hdbray(bp) ((RAYVAL *)((bp)+1)) |
| 61 |
gregl |
3.1 |
#define hdbsiz(nr) (sizeof(BEAM)+(nr)*sizeof(RAYVAL)) |
| 62 |
|
|
|
| 63 |
|
|
typedef struct { |
| 64 |
|
|
FVECT orig; /* prism origin (first) */ |
| 65 |
|
|
FVECT xv[3]; /* side vectors (second) */ |
| 66 |
|
|
int2 grid[3]; /* grid resolution (third) */ |
| 67 |
|
|
} HDGRID; /* holodeck section grid (must match HOLO struct) */ |
| 68 |
|
|
|
| 69 |
|
|
typedef struct holo { |
| 70 |
|
|
FVECT orig; /* prism origin (first) */ |
| 71 |
|
|
FVECT xv[3]; /* side vectors (second) */ |
| 72 |
|
|
int2 grid[3]; /* grid resolution (third) */ |
| 73 |
|
|
int fd; /* file descriptor */ |
| 74 |
|
|
short dirty; /* beam index needs update to file */ |
| 75 |
|
|
double tlin; /* linear range for depth encoding */ |
| 76 |
|
|
FVECT wn[3]; /* wall normals (derived) */ |
| 77 |
gregl |
3.5 |
double wg[3]; /* wall grid multipliers (derived) */ |
| 78 |
gregl |
3.1 |
double wo[6]; /* wall offsets (derived) */ |
| 79 |
|
|
int wi[6]; /* wall super-indices (derived) */ |
| 80 |
|
|
char *priv; /* pointer to private client data */ |
| 81 |
|
|
BEAM **bl; /* beam pointers (memory cache) */ |
| 82 |
|
|
BEAMI bi[1]; /* beam index (extends struct) */ |
| 83 |
|
|
} HOLO; /* holodeck section */ |
| 84 |
|
|
|
| 85 |
|
|
#define nbeams(hp) (2*((hp)->wi[5]-1)) |
| 86 |
|
|
#define biglob(hp) ((hp)->bi) |
| 87 |
|
|
#define blglob(hp) (*(hp)->bl) |
| 88 |
|
|
|
| 89 |
|
|
#define bnrays(hp,i) ((hp)->bl[i]!=NULL ? (hp)->bl[i]->nrm : (hp)->bi[i].nrd) |
| 90 |
|
|
|
| 91 |
gregl |
3.7 |
#define hdflush(hp) (hdfreebeam(hp,0) && hdsync(hp,0)) |
| 92 |
|
|
#define hdclobber(hp) (hdkillbeam(hp,0) && hdsync(hp,0)) |
| 93 |
gregl |
3.1 |
|
| 94 |
gregl |
3.4 |
extern HOLO *hdinit(), *hdalloc(); |
| 95 |
gregl |
3.1 |
extern BEAM *hdgetbeam(); |
| 96 |
|
|
extern RAYVAL *hdnewrays(); |
| 97 |
gregl |
3.8 |
extern long hdmemuse(), hdfiluse(), hdfilen(); |
| 98 |
gregl |
3.1 |
extern double hdray(), hdinter(); |
| 99 |
|
|
extern unsigned hdcode(); |
| 100 |
|
|
|
| 101 |
|
|
extern int hdcachesize; /* target cache size (bytes) */ |
| 102 |
|
|
extern unsigned long hdclock; /* holodeck system clock */ |
| 103 |
|
|
extern HOLO *hdlist[HDMAX+1]; /* holodeck pointers (NULL term.) */ |
| 104 |
|
|
|
| 105 |
|
|
extern float hd_depthmap[]; /* depth conversion map */ |
| 106 |
|
|
|
| 107 |
|
|
#define hddepth(hp,dc) ( (dc) >= DCINF ? FHUGE : \ |
| 108 |
|
|
(hp)->tlin * ( (dc) >= DCLIN ? \ |
| 109 |
|
|
hd_depthmap[(dc)-DCLIN] : \ |
| 110 |
|
|
((dc)+.5)/DCLIN ) ) |
| 111 |
|
|
|
| 112 |
|
|
#define HOLOFMT "Holodeck" /* file format identifier */ |
| 113 |
|
|
#define HOLOVERS 0 /* file format version number */ |
| 114 |
|
|
#define HOLOMAGIC (327+HOLOVERS) /* file magic number */ |
| 115 |
|
|
|
| 116 |
|
|
/* |
| 117 |
|
|
* A holodeck file consists of an information header terminated by a |
| 118 |
|
|
* blank line, with "FORMAT=Holodeck" somewhere in it. |
| 119 |
|
|
* The first integer after the information header is the |
| 120 |
|
|
* above magic number, which includes the file format version number. |
| 121 |
gregl |
3.6 |
* The first longword after the magic number is a pointer to the pointer |
| 122 |
|
|
* just before the SECOND holodeck section, or 0 if there is only one. |
| 123 |
gregl |
3.1 |
* This longword is immediately followed by the first holodeck |
| 124 |
|
|
* section header and directory. |
| 125 |
|
|
* Similarly, every holodeck section in the file is preceeded by |
| 126 |
|
|
* a pointer to the following section, or 0 for the final section. |
| 127 |
|
|
* Since holodeck files consist of directly written C data structures, |
| 128 |
|
|
* they are not generally portable between different machine architectures. |
| 129 |
|
|
* In particular, different floating point formats or bit/byte ordering |
| 130 |
|
|
* will make the data unusable. This is unfortunate, and may be changed |
| 131 |
|
|
* in future versions, but we thought this would be best for paging speed |
| 132 |
|
|
* in our initial implementation. |
| 133 |
|
|
*/ |