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