16 |
|
#include <GL/glu.h> |
17 |
|
#include <glut.h> |
18 |
|
#endif |
19 |
– |
#include "object.h" |
19 |
|
#include "sm_list.h" |
20 |
|
#include "sm_geom.h" |
21 |
|
#include "sm.h" |
40 |
|
QTRAVG av; /* node average */ |
41 |
|
} QT_LUENT; /* lookup table entry */ |
42 |
|
|
43 |
< |
static QT_LUENT *qt_htbl = NULL; /* quadtree hash table */ |
44 |
< |
static int qt_hsiz = 0; /* quadtree hash table size */ |
43 |
> |
static QT_LUENT *qt_htbl = NULL; /* quadtree cache */ |
44 |
> |
static int qt_hsiz = 0; /* quadtree cache size */ |
45 |
|
|
46 |
|
|
47 |
|
int |
48 |
|
mark_active_tris(qtptr,arg) |
49 |
|
QUADTREE *qtptr; |
50 |
< |
char *arg; |
50 |
> |
int *arg; |
51 |
|
{ |
52 |
|
QUADTREE qt = *qtptr; |
53 |
< |
OBJECT os[QT_MAX_SET+1],*optr; |
53 |
> |
OBJECT *os,*optr; |
54 |
|
register int i,t_id; |
55 |
|
|
56 |
|
if (!QT_IS_LEAF(qt)) |
57 |
|
return(TRUE); |
58 |
|
/* For each triangle in the set, set the which flag*/ |
59 |
< |
qtgetset(os,qt); |
59 |
> |
os = qtqueryset(qt); |
60 |
|
|
61 |
|
for (i = QT_SET_CNT(os), optr = QT_SET_PTR(os); i > 0; i--) |
62 |
|
{ |
65 |
|
if(SM_IS_NTH_T_BASE(smMesh,t_id)) |
66 |
|
continue; |
67 |
|
SM_SET_NTH_T_ACTIVE(smMesh,t_id); |
68 |
< |
/* FOR NOW:Also set the LRU clock bit: MAY WANT TO CHANGE: */ |
68 |
> |
/* NOTE:Also set the LRU clock bit: MAY WANT TO CHANGE: */ |
69 |
|
SM_SET_NTH_T_LRU(smMesh,t_id); |
70 |
|
} |
71 |
|
return(TRUE); |
139 |
|
} |
140 |
|
|
141 |
|
int |
142 |
< |
qtHash_init(nel) /* initialize for at least nel elements */ |
142 |
> |
qtCache_init(nel) /* initialize for at least nel elements */ |
143 |
|
int nel; |
144 |
|
{ |
145 |
|
static int hsiztab[] = { |
170 |
|
} |
171 |
|
|
172 |
|
QT_LUENT * |
173 |
< |
qtHash_find(qt) /* find a quadtree table entry */ |
173 |
> |
qtCache_find(qt) /* find a quadtree table entry */ |
174 |
|
QUADTREE qt; |
175 |
|
{ |
176 |
|
int i, n; |
177 |
|
register int ndx; |
178 |
|
register QT_LUENT *le; |
179 |
|
|
180 |
< |
if (qt_hsiz == 0) |
181 |
< |
qtHash_init(1); |
180 |
> |
if (qt_hsiz == 0 && !qtCache_init(1)) |
181 |
> |
return(NULL); |
182 |
|
tryagain: /* hash table lookup */ |
183 |
|
ndx = (unsigned long)qt % qt_hsiz; |
184 |
|
for (i = 0, n = 1; i < qt_hsiz; i++, n += 2) { |
191 |
|
/* table is full, reallocate */ |
192 |
|
le = qt_htbl; |
193 |
|
ndx = qt_hsiz; |
194 |
< |
if (!qtHash_init(ndx+1)) { /* no more memory! */ |
194 |
> |
if (!qtCache_init(ndx+1)) { /* no more memory! */ |
195 |
|
qt_htbl = le; |
196 |
|
qt_hsiz = ndx; |
197 |
|
return(NULL); |
198 |
|
} |
199 |
< |
if (!ndx) |
201 |
< |
goto tryagain; |
202 |
< |
/* copy old table to new */ |
199 |
> |
/* copy old table to new and free */ |
200 |
|
while (ndx--) |
201 |
|
if (!QT_IS_EMPTY(le[ndx].qt)) |
202 |
< |
copystruct(qtHash_find(le[ndx].qt), &le[ndx]); |
202 |
> |
copystruct(qtCache_find(le[ndx].qt), &le[ndx]); |
203 |
|
free((char *)le); |
204 |
|
goto tryagain; /* should happen only once! */ |
205 |
|
} |
239 |
|
if (QT_IS_TREE(qt) && !QT_IS_FLAG(qt)) /* not in our frustum */ |
240 |
|
return(NULL); |
241 |
|
/* else look up node */ |
242 |
< |
if ((le = qtHash_find(qt)) == NULL) |
242 |
> |
if ((le = qtCache_find(qt)) == NULL) |
243 |
|
error(SYSTEM, "out of memory in qtRender_level"); |
244 |
|
if (QT_IS_TREE(qt) && (QT_IS_EMPTY(le->qt) || lvl > 0)) |
245 |
|
{ /* compute children */ |
268 |
|
} |
269 |
|
else |
270 |
|
{ /* from triangle set */ |
271 |
< |
OBJECT os[QT_MAX_SET+1]; |
271 |
> |
OBJECT *os; |
272 |
|
int s0, s1, s2; |
273 |
|
|
274 |
< |
qtgetset(os,qt); |
274 |
> |
os = qtqueryset(qt); |
275 |
|
for (n = os[0]; n; n--) |
276 |
|
{ |
277 |
|
qtTri_from_id(os[n],a,b,c,NULL,NULL,NULL,&s0,&s1,&s2); |
581 |
|
continue; |
582 |
|
} |
583 |
|
tri = SM_NTH_TRI(sm,t_id); |
584 |
+ |
#ifdef DEBUG |
585 |
+ |
if(i >= smNew_tri_cnt) |
586 |
+ |
{ |
587 |
+ |
eputs("smDepth_sort_tris():More tris than reported by smNew_tri_cnt\n"); |
588 |
+ |
break; |
589 |
+ |
} |
590 |
+ |
#endif |
591 |
|
td[i].tri = t_id; |
592 |
|
min_d = -1; |
593 |
|
for(j=0;j < 3;j++) |
650 |
|
smRender_bg_tri(sm,pop_list(&bglist),vp,d,clr); |
651 |
|
glEnd(); |
652 |
|
|
653 |
< |
glEnable(GL_DEPTH_TEST); |
653 |
> |
|
654 |
|
glBegin(GL_TRIANGLES); |
655 |
|
i=0; |
656 |
|
while(td[i].tri != -1) |
756 |
|
{ |
757 |
|
smClean_notify = FALSE; |
758 |
|
smNew_tri_cnt = 0; |
759 |
< |
qtHash_init(0); |
759 |
> |
smClear_flags(smMesh,T_NEW_FLAG); |
760 |
> |
qtCache_init(0); |
761 |
|
} |
762 |
|
|
763 |
|
} |