-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathportals.c
1111 lines (912 loc) · 23.4 KB
/
portals.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -------------------------------------------------------------------------------
Copyright (C) 1999-2006 Id Software, Inc. and contributors.
For a list of contributors, see the accompanying CONTRIBUTORS file.
This file is part of GtkRadiant.
GtkRadiant is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GtkRadiant is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GtkRadiant; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
----------------------------------------------------------------------------------
This code has been altered significantly from its original form, to support
several games based on the Quake III Arena engine, in the form of "Q3Map2."
------------------------------------------------------------------------------- */
/* marker */
#define PORTALS_C
/* dependencies */
//#include "q3map2.h"
#include "kmap2.h" //add hypov8
/* ydnar: to fix broken portal windings */
extern qboolean FixWinding(winding_t * w);
int c_active_portals;
int c_peak_portals;
int c_boundary;
int c_boundary_sides;
/*
===========
AllocPortal
===========
*/
portal_t *AllocPortal(void)
{
portal_t *p;
if(numthreads == 1)
c_active_portals++;
if(c_active_portals > c_peak_portals)
c_peak_portals = c_active_portals;
p = safe_malloc(sizeof(portal_t));
memset(p, 0, sizeof(portal_t));
return p;
}
void FreePortal(portal_t * p)
{
if(p->winding)
FreeWinding(p->winding);
if(numthreads == 1)
c_active_portals--;
free(p);
}
/*
PortalPassable
returns true if the portal has non-opaque leafs on both sides
*/
qboolean PortalPassable(portal_t * p)
{
/* is this to global outside leaf? */
if(!p->onnode)
return qfalse;
/* this should never happen */
if(p->nodes[0]->planenum != PLANENUM_LEAF || p->nodes[1]->planenum != PLANENUM_LEAF)
Error("Portal_EntityFlood: not a leaf");
/* ydnar: added antiportal to supress portal generation for visibility blocking */
if(p->compileFlags & C_ANTIPORTAL)
return qfalse;
/* both leaves on either side of the portal must be passable */
if(p->nodes[0]->opaque == qfalse && p->nodes[1]->opaque == qfalse)
return qtrue;
/* otherwise this isn't a passable portal */
return qfalse;
}
int c_tinyportals;
int c_badportals; /* ydnar */
/*
=============
AddPortalToNodes
=============
*/
void AddPortalToNodes(portal_t * p, node_t * front, node_t * back)
{
if(p->nodes[0] || p->nodes[1])
Error("AddPortalToNode: allready included");
p->nodes[0] = front;
p->next[0] = front->portals;
front->portals = p;
p->nodes[1] = back;
p->next[1] = back->portals;
back->portals = p;
}
/*
=============
RemovePortalFromNode
=============
*/
void RemovePortalFromNode(portal_t * portal, node_t * l)
{
portal_t **pp, *t;
// remove reference to the current portal
pp = &l->portals;
while(1)
{
t = *pp;
if(!t)
Error("RemovePortalFromNode: portal not in leaf");
if(t == portal)
break;
if(t->nodes[0] == l)
pp = &t->next[0];
else if(t->nodes[1] == l)
pp = &t->next[1];
else
Error("RemovePortalFromNode: portal not bounding leaf");
}
if(portal->nodes[0] == l)
{
*pp = portal->next[0];
portal->nodes[0] = NULL;
}
else if(portal->nodes[1] == l)
{
*pp = portal->next[1];
portal->nodes[1] = NULL;
}
}
//============================================================================
void PrintPortal(portal_t * p)
{
int i;
winding_t *w;
w = p->winding;
for(i = 0; i < w->numpoints; i++)
Sys_Printf("(%5.0f,%5.0f,%5.0f)\n", w->p[i][0], w->p[i][1], w->p[i][2]);
}
/*
================
MakeHeadnodePortals
The created portals will face the global outside_node
================
*/
#define SIDESPACE 8
void MakeHeadnodePortals(tree_t * tree)
{
vec3_t bounds[2];
int i, j, n;
portal_t *p, *portals[6];
plane_t bplanes[6], *pl;
node_t *node;
node = tree->headnode;
// pad with some space so there will never be null volume leafs
for(i = 0; i < 3; i++)
{
bounds[0][i] = tree->mins[i] - SIDESPACE;
bounds[1][i] = tree->maxs[i] + SIDESPACE;
if(bounds[0][i] >= bounds[1][i])
{
Error("Backwards tree volume");
}
}
tree->outside_node.planenum = PLANENUM_LEAF;
tree->outside_node.brushlist = NULL;
tree->outside_node.portals = NULL;
tree->outside_node.opaque = qfalse;
for(i = 0; i < 3; i++)
for(j = 0; j < 2; j++)
{
n = j * 3 + i;
p = AllocPortal();
portals[n] = p;
pl = &bplanes[n];
memset(pl, 0, sizeof(*pl));
if(j)
{
pl->normal[i] = -1;
pl->dist = -bounds[j][i];
}
else
{
pl->normal[i] = 1;
pl->dist = bounds[j][i];
}
p->plane = *pl;
p->winding = BaseWindingForPlane(pl->normal, pl->dist);
AddPortalToNodes(p, node, &tree->outside_node);
}
// clip the basewindings by all the other planes
for(i = 0; i < 6; i++)
{
for(j = 0; j < 6; j++)
{
if(j == i)
continue;
ChopWindingInPlace(&portals[i]->winding, bplanes[j].normal, bplanes[j].dist, ON_EPSILON);
}
}
}
//===================================================
/*
================
BaseWindingForNode
================
*/
#define BASE_WINDING_EPSILON 0.001
#define SPLIT_WINDING_EPSILON 0.001
winding_t *BaseWindingForNode(node_t * node)
{
winding_t *w;
node_t *n;
plane_t *plane;
vec3_t normal;
vec_t dist;
w = BaseWindingForPlane(mapplanes[node->planenum].normal, mapplanes[node->planenum].dist);
// clip by all the parents
for(n = node->parent; n && w;)
{
plane = &mapplanes[n->planenum];
if(n->children[0] == node)
{ // take front
ChopWindingInPlace(&w, plane->normal, plane->dist, BASE_WINDING_EPSILON);
}
else
{ // take back
VectorSubtract(vec3_origin, plane->normal, normal);
dist = -plane->dist;
ChopWindingInPlace(&w, normal, dist, BASE_WINDING_EPSILON);
}
node = n;
n = n->parent;
}
return w;
}
//============================================================
/*
==================
MakeNodePortal
create the new portal by taking the full plane winding for the cutting plane
and clipping it by all of parents of this node
==================
*/
void MakeNodePortal(node_t * node)
{
portal_t *new_portal, *p;
winding_t *w;
vec3_t normal;
float dist;
int side;
w = BaseWindingForNode(node);
// clip the portal by all the other portals in the node
for(p = node->portals; p && w; p = p->next[side])
{
if(p->nodes[0] == node)
{
side = 0;
VectorCopy(p->plane.normal, normal);
dist = p->plane.dist;
}
else if(p->nodes[1] == node)
{
side = 1;
VectorSubtract(vec3_origin, p->plane.normal, normal);
dist = -p->plane.dist;
}
else
Error("CutNodePortals_r: mislinked portal");
ChopWindingInPlace(&w, normal, dist, CLIP_EPSILON);
}
if(!w)
{
return;
}
/* ydnar: adding this here to fix degenerate windings */
#if 0
if(FixWinding(w) == qfalse)
{
c_badportals++;
FreeWinding(w);
return;
}
#endif
if(WindingIsTiny(w))
{
c_tinyportals++;
FreeWinding(w);
return;
}
new_portal = AllocPortal();
new_portal->plane = mapplanes[node->planenum];
new_portal->onnode = node;
new_portal->winding = w;
new_portal->compileFlags = node->compileFlags;
AddPortalToNodes(new_portal, node->children[0], node->children[1]);
}
/*
==============
SplitNodePortals
Move or split the portals that bound node so that the node's
children have portals instead of node.
==============
*/
void SplitNodePortals(node_t * node)
{
portal_t *p, *next_portal, *new_portal;
node_t *f, *b, *other_node;
int side;
plane_t *plane;
winding_t *frontwinding, *backwinding;
plane = &mapplanes[node->planenum];
f = node->children[0];
b = node->children[1];
for(p = node->portals; p; p = next_portal)
{
if(p->nodes[0] == node)
side = 0;
else if(p->nodes[1] == node)
side = 1;
else
Error("SplitNodePortals: mislinked portal");
next_portal = p->next[side];
other_node = p->nodes[!side];
RemovePortalFromNode(p, p->nodes[0]);
RemovePortalFromNode(p, p->nodes[1]);
//
// cut the portal into two portals, one on each side of the cut plane
//
ClipWindingEpsilon(p->winding, plane->normal, plane->dist, SPLIT_WINDING_EPSILON, &frontwinding, &backwinding);
if(frontwinding && WindingIsTiny(frontwinding))
{
if(!f->tinyportals)
VectorCopy(frontwinding->p[0], f->referencepoint);
f->tinyportals++;
if(!other_node->tinyportals)
VectorCopy(frontwinding->p[0], other_node->referencepoint);
other_node->tinyportals++;
FreeWinding(frontwinding);
frontwinding = NULL;
c_tinyportals++;
}
if(backwinding && WindingIsTiny(backwinding))
{
if(!b->tinyportals)
VectorCopy(backwinding->p[0], b->referencepoint);
b->tinyportals++;
if(!other_node->tinyportals)
VectorCopy(backwinding->p[0], other_node->referencepoint);
other_node->tinyportals++;
FreeWinding(backwinding);
backwinding = NULL;
c_tinyportals++;
}
if(!frontwinding && !backwinding)
{ // tiny windings on both sides
continue;
}
if(!frontwinding)
{
FreeWinding(backwinding);
if(side == 0)
AddPortalToNodes(p, b, other_node);
else
AddPortalToNodes(p, other_node, b);
continue;
}
if(!backwinding)
{
FreeWinding(frontwinding);
if(side == 0)
AddPortalToNodes(p, f, other_node);
else
AddPortalToNodes(p, other_node, f);
continue;
}
// the winding is split
new_portal = AllocPortal();
*new_portal = *p;
new_portal->winding = backwinding;
FreeWinding(p->winding);
p->winding = frontwinding;
if(side == 0)
{
AddPortalToNodes(p, f, other_node);
AddPortalToNodes(new_portal, b, other_node);
}
else
{
AddPortalToNodes(p, other_node, f);
AddPortalToNodes(new_portal, other_node, b);
}
}
node->portals = NULL;
}
/*
================
CalcNodeBounds
================
*/
void CalcNodeBounds(node_t * node)
{
portal_t *p;
int s;
int i;
// calc mins/maxs for both leafs and nodes
ClearBounds(node->mins, node->maxs);
for(p = node->portals; p; p = p->next[s])
{
s = (p->nodes[1] == node);
for(i = 0; i < p->winding->numpoints; i++)
AddPointToBounds(p->winding->p[i], node->mins, node->maxs);
}
}
//============================================================
static int PortalVisibleSides(portal_t * p)
{
int fcon, bcon;
if(!p->onnode)
return 0; // outside
fcon = p->nodes[0]->opaque;
bcon = p->nodes[1]->opaque;
// same contents never create a face
if(fcon == bcon)
return 0;
if(!fcon)
return 1;
if(!bcon)
return 2;
return 0;
}
static void DrawPortal(portal_t * p, qboolean areaportal)
{
winding_t *w;
int sides;
sides = PortalVisibleSides(p);
//if(!sides)
// return;
w = p->winding;
if(sides == 2) // back side
w = ReverseWinding(w);
if(areaportal)
{
Draw_Winding(w, 1, 0, 0, 0.3);
}
else
{
Draw_Winding(w, 0, 0, 1, 0.3);
}
if(sides == 2)
FreeWinding(w);
}
static void DrawTreePortals_r(node_t * node)
{
int s;
portal_t *p;
winding_t *w;
if(node->planenum != PLANENUM_LEAF)
{
DrawTreePortals_r(node->children[0]);
DrawTreePortals_r(node->children[1]);
return;
}
// draw all the portals
for(p = node->portals; p; p = p->next[s])
{
w = p->winding;
s = (p->nodes[1] == node);
if(w) // && p->nodes[0] == node)
{
//if(PortalPassable(p))
// continue;
DrawPortal(p, node->areaportal);
}
}
}
static void DrawTreeNodes_r(node_t * node)
{
//int s;
//portal_t *p, *nextp;
//winding_t *w;
vec4_t nodeColor = {1, 1, 0, 0.3};
vec4_t leafColor = {0, 0, 1, 0.3};
if(!node)
return;
if(node->planenum == PLANENUM_LEAF)
{
//Draw_AABB(vec3_origin, node->mins, node->maxs, leafColor);
return;
}
Draw_AABB(vec3_origin, node->mins, node->maxs, nodeColor);
DrawTreeNodes_r(node->children[0]);
DrawTreeNodes_r(node->children[1]);
}
static tree_t *drawTree = NULL;
static int drawTreeNodesNum;
static void DrawTreePortals(void)
{
DrawTreePortals_r(drawTree->headnode);
DrawTreeNodes_r(drawTree->headnode);
}
//============================================================
/*
==================
MakeTreePortals_r
==================
*/
void MakeTreePortals_r(node_t * node)
{
int i;
CalcNodeBounds(node);
if(node->mins[0] >= node->maxs[0])
{
Sys_Printf("WARNING: node without a volume\n");
Sys_Printf("node has %d tiny portals\n", node->tinyportals);
Sys_Printf("node reference point %1.2f %1.2f %1.2f\n", node->referencepoint[0],
node->referencepoint[1], node->referencepoint[2]);
}
for(i = 0; i < 3; i++)
{
if(node->mins[i] < MIN_WORLD_COORD || node->maxs[i] > MAX_WORLD_COORD)
{
if(node->portals && node->portals->winding)
{
#if defined(USE_XML)
xml_Winding("WARNING: Node With Unbounded Volume", node->portals->winding->p, node->portals->winding->numpoints,
qfalse);
#else
Sys_Printf("WARNING: node with unbounded volume\n");
#endif
}
break;
}
}
if(node->planenum == PLANENUM_LEAF)
return;
MakeNodePortal(node);
SplitNodePortals(node);
#if 0
if(drawBSP)
{
Draw_Scene(DrawTreePortals);
}
#endif
MakeTreePortals_r(node->children[0]);
MakeTreePortals_r(node->children[1]);
}
/*
==================
MakeTreePortals
==================
*/
void MakeTreePortals(tree_t * tree)
{
Sys_FPrintf(SYS_VRB, "--- MakeTreePortals ---\n");
#if 1
if(drawBSP)
{
drawTree = tree;
}
#endif
MakeHeadnodePortals(tree);
MakeTreePortals_r(tree->headnode);
Sys_FPrintf(SYS_VRB, "%9d tiny portals\n", c_tinyportals);
Sys_FPrintf(SYS_VRB, "%9d bad portals\n", c_badportals); /* ydnar */
#if 0
if(drawBSP)
{
Draw_Scene(DrawTreePortals);
}
#endif
}
/*
=========================================================
FLOOD ENTITIES
=========================================================
*/
int c_floodedleafs;
/*
=============
FloodPortals_r
=============
*/
void FloodPortals_r(node_t * node, int dist, qboolean skybox)
{
int s;
portal_t *p;
if(skybox)
node->skybox = skybox;
if(node->occupied || node->opaque)
return;
c_floodedleafs++;
node->occupied = dist;
for(p = node->portals; p; p = p->next[s])
{
s = (p->nodes[1] == node);
FloodPortals_r(p->nodes[!s], dist + 1, skybox);
}
}
/*
=============
PlaceOccupant
=============
*/
qboolean PlaceOccupant(node_t * headnode, vec3_t origin, entity_t * occupant, qboolean skybox)
{
vec_t d;
node_t *node;
plane_t *plane;
// find the leaf to start in
node = headnode;
while(node->planenum != PLANENUM_LEAF)
{
plane = &mapplanes[node->planenum];
d = DotProduct(origin, plane->normal) - plane->dist;
if(d >= 0)
node = node->children[0];
else
node = node->children[1];
}
if(node->opaque)
return qfalse;
node->occupant = occupant;
node->skybox = skybox;
FloodPortals_r(node, 1, skybox);
return qtrue;
}
/*
=============
FloodEntities
Marks all nodes that can be reached by entites
=============
*/
qboolean FloodEntities(tree_t * tree)
{
int i, s;
vec3_t origin, offset, scale, angles;
qboolean r, inside, tripped, skybox;
node_t *headnode;
entity_t *e;
const char *value;
matrix_t rotation;
headnode = tree->headnode;
Sys_FPrintf(SYS_VRB, "--- FloodEntities ---\n");
inside = qfalse;
tree->outside_node.occupied = 0;
tripped = qfalse;
c_floodedleafs = 0;
for(i = 1; i < numEntities; i++)
{
/* get entity */
e = &entities[i];
/* get origin */
GetVectorForKey(e, "origin", origin);
/* as a special case, allow origin-less entities */
if(VectorCompare(origin, vec3_origin))
continue;
// Tr3B - some entities may have this epair
if(!strcmp("1", ValueForKey(&entities[i], "noflood")))
continue;
/* handle skybox entities */
value = ValueForKey(e, "classname");
if(!Q_stricmp(value, "_skybox"))
{
skybox = qtrue;
skyboxPresent = qtrue;
/* invert origin */
VectorScale(origin, -1.0f, offset);
/* get "angle" (yaw) or "angles" (pitch yaw roll) */
MatrixIdentity(rotation);
VectorClear(angles);
angles[2] = FloatForKey(e, "angle");
value = ValueForKey(e, "angles");
if(value[0] != '\0')
sscanf(value, "%f %f %f", &angles[1], &angles[2], &angles[0]);
MatrixFromAngles(rotation, angles[PITCH], angles[YAW], angles[ROLL]);
value = ValueForKey(e, "rotation");
if(value[0] != '\0')
{
sscanf(value, "%f %f %f %f %f %f %f %f %f", &rotation[0], &rotation[1], &rotation[2],
&rotation[4], &rotation[5], &rotation[6], &rotation[8], &rotation[9], &rotation[10]);
}
/* get scale */
VectorSet(scale, 64.0f, 64.0f, 64.0f);
value = ValueForKey(e, "_scale");
if(value[0] != '\0')
{
s = sscanf(value, "%f %f %f", &scale[0], &scale[1], &scale[2]);
if(s == 1)
{
scale[1] = scale[0];
scale[2] = scale[0];
}
MatrixMultiplyScale(rotation, scale[0], scale[1], scale[2]);
}
/* set transform matrix */
MatrixIdentity(skyboxTransform);
MatrixSetupTransformFromRotation(skyboxTransform, rotation, origin);
//% m4x4_pivoted_transform_by_vec3(skyboxTransform, offset, angles, eXYZ, scale, origin);
}
else
{
skybox = qfalse;
}
/* nudge off floor */
origin[2] += 1;
/* debugging code */
//% if( i == 1 )
//% origin[ 2 ] += 4096;
/* find leaf */
r = PlaceOccupant(headnode, origin, e, skybox);
if(r)
inside = qtrue;
if((!r || tree->outside_node.occupied) && !tripped)
{
#if defined(USE_XML)
xml_Select("Entity leaked", e->mapEntityNum, 0, qfalse);
#else
Sys_Printf("Entity leaked: %i\n", e->mapEntityNum);
#endif
tripped = qtrue;
}
}
Sys_FPrintf(SYS_VRB, "%9d flooded leafs\n", c_floodedleafs);
if(!inside)
Sys_FPrintf(SYS_VRB, "no entities in open -- no filling\n");
else if(tree->outside_node.occupied)
Sys_FPrintf(SYS_VRB, "entity reached from outside -- no filling\n");
return (qboolean) (inside && !tree->outside_node.occupied);
}
/*
=========================================================
FLOOD AREAS
=========================================================
*/
int c_areas;
/*
FloodAreas_r()
floods through leaf portals to tag leafs with an area
*/
void FloodAreas_r(node_t * node)
{
int s;
portal_t *p;
brush_t *b;
if(node->areaportal)
{
if(node->area == -1)
node->area = c_areas;
/* this node is part of an area portal brush */
b = node->brushlist->original;
/* if the current area has already touched this portal, we are done */
if(b->portalareas[0] == c_areas || b->portalareas[1] == c_areas)
return;
// note the current area as bounding the portal
if(b->portalareas[1] != -1)
{
Sys_Printf("WARNING: areaportal brush %i touches > 2 areas\n", b->brushNum);
return;
}
if(b->portalareas[0] != -1)
b->portalareas[1] = c_areas;
else
b->portalareas[0] = c_areas;
return;
}
if(node->area != -1)
return;
if(node->cluster == -1)
return;
node->area = c_areas;
/* ydnar: skybox nodes set the skybox area */
if(node->skybox)
skyboxArea = c_areas;
for(p = node->portals; p; p = p->next[s])
{
s = (p->nodes[1] == node);
/* ydnar: allow areaportal portals to block area flow */
if(p->compileFlags & C_AREAPORTAL)
continue;
if(!PortalPassable(p))
continue;
FloodAreas_r(p->nodes[!s]);
}
}
/*
=============
FindAreas_r
Just decend the tree, and for each node that hasn't had an
area set, flood fill out from there
=============
*/
void FindAreas_r(node_t * node)
{
if(node->planenum != PLANENUM_LEAF)
{
FindAreas_r(node->children[0]);
FindAreas_r(node->children[1]);
return;
}
if(node->opaque || node->areaportal || node->area != -1)
return;
FloodAreas_r(node);
c_areas++;
}
/*
=============
CheckAreas_r
=============
*/
void CheckAreas_r(node_t * node)
{
brush_t *b;
if(node->planenum != PLANENUM_LEAF)
{
CheckAreas_r(node->children[0]);
CheckAreas_r(node->children[1]);
return;
}
if(node->opaque)
return;
if(node->cluster != -1)
if(node->area == -1)
Sys_Printf("WARNING: cluster %d has area set to -1\n", node->cluster);
if(node->areaportal)
{
b = node->brushlist->original;
// check if the areaportal touches two areas