| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include "vis.h" |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
int CountBits (byte *bits, int numbits) |
| 44 |
{ |
| 45 |
int i; |
| 46 |
int c; |
| 47 |
|
| 48 |
c = 0; |
| 49 |
for (i=0 ; i<numbits ; i++) |
| 50 |
if (bits[i>>3] & (1<<(i&7)) ) |
| 51 |
c++; |
| 52 |
|
| 53 |
return c; |
| 54 |
} |
| 55 |
|
| 56 |
int c_fullskip; |
| 57 |
int c_portalskip, c_leafskip; |
| 58 |
int c_vistest, c_mighttest; |
| 59 |
|
| 60 |
int c_chop, c_nochop; |
| 61 |
|
| 62 |
int active; |
| 63 |
|
| 64 |
void CheckStack (leaf_t *leaf, threaddata_t *thread) |
| 65 |
{ |
| 66 |
pstack_t *p, *p2; |
| 67 |
|
| 68 |
for (p=thread->pstack_head.next ; p ; p=p->next) |
| 69 |
{ |
| 70 |
|
| 71 |
if (p->leaf == leaf) |
| 72 |
Error ("CheckStack: leaf recursion"); |
| 73 |
for (p2=thread->pstack_head.next ; p2 != p ; p2=p2->next) |
| 74 |
if (p2->leaf == p->leaf) |
| 75 |
Error ("CheckStack: late leaf recursion"); |
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
winding_t *AllocStackWinding (pstack_t *stack) |
| 82 |
{ |
| 83 |
int i; |
| 84 |
|
| 85 |
for (i=0 ; i<3 ; i++) |
| 86 |
{ |
| 87 |
if (stack->freewindings[i]) |
| 88 |
{ |
| 89 |
stack->freewindings[i] = 0; |
| 90 |
return &stack->windings[i]; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
Error ("AllocStackWinding: failed"); |
| 95 |
|
| 96 |
return NULL; |
| 97 |
} |
| 98 |
|
| 99 |
void FreeStackWinding (winding_t *w, pstack_t *stack) |
| 100 |
{ |
| 101 |
int i; |
| 102 |
|
| 103 |
i = w - stack->windings; |
| 104 |
|
| 105 |
if (i<0 || i>2) |
| 106 |
return; |
| 107 |
|
| 108 |
if (stack->freewindings[i]) |
| 109 |
Error ("FreeStackWinding: allready free"); |
| 110 |
stack->freewindings[i] = 1; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
winding_t *ChopWinding (winding_t *in, pstack_t *stack, plane_t *split) |
| 120 |
{ |
| 121 |
vec_t dists[128]; |
| 122 |
int sides[128]; |
| 123 |
int counts[3]; |
| 124 |
vec_t dot; |
| 125 |
int i, j; |
| 126 |
vec_t *p1, *p2; |
| 127 |
vec3_t mid; |
| 128 |
winding_t *neww; |
| 129 |
|
| 130 |
counts[0] = counts[1] = counts[2] = 0; |
| 131 |
|
| 132 |
|
| 133 |
for (i=0 ; i<in->numpoints ; i++) |
| 134 |
{ |
| 135 |
dot = DotProduct (in->points[i], split->normal); |
| 136 |
dot -= split->dist; |
| 137 |
dists[i] = dot; |
| 138 |
if (dot > ON_EPSILON) |
| 139 |
sides[i] = SIDE_FRONT; |
| 140 |
else if (dot < -ON_EPSILON) |
| 141 |
sides[i] = SIDE_BACK; |
| 142 |
else |
| 143 |
{ |
| 144 |
sides[i] = SIDE_ON; |
| 145 |
} |
| 146 |
counts[sides[i]]++; |
| 147 |
} |
| 148 |
|
| 149 |
if (!counts[1]) |
| 150 |
return in; |
| 151 |
|
| 152 |
if (!counts[0]) |
| 153 |
{ |
| 154 |
FreeStackWinding (in, stack); |
| 155 |
return NULL; |
| 156 |
} |
| 157 |
|
| 158 |
sides[i] = sides[0]; |
| 159 |
dists[i] = dists[0]; |
| 160 |
|
| 161 |
neww = AllocStackWinding (stack); |
| 162 |
|
| 163 |
neww->numpoints = 0; |
| 164 |
|
| 165 |
for (i=0 ; i<in->numpoints ; i++) |
| 166 |
{ |
| 167 |
p1 = in->points[i]; |
| 168 |
|
| 169 |
if (neww->numpoints == MAX_POINTS_ON_FIXED_WINDING) |
| 170 |
{ |
| 171 |
FreeStackWinding (neww, stack); |
| 172 |
return in; |
| 173 |
} |
| 174 |
|
| 175 |
if (sides[i] == SIDE_ON) |
| 176 |
{ |
| 177 |
VectorCopy (p1, neww->points[neww->numpoints]); |
| 178 |
neww->numpoints++; |
| 179 |
continue; |
| 180 |
} |
| 181 |
|
| 182 |
if (sides[i] == SIDE_FRONT) |
| 183 |
{ |
| 184 |
VectorCopy (p1, neww->points[neww->numpoints]); |
| 185 |
neww->numpoints++; |
| 186 |
} |
| 187 |
|
| 188 |
if (sides[i+1] == SIDE_ON || sides[i+1] == sides[i]) |
| 189 |
continue; |
| 190 |
|
| 191 |
if (neww->numpoints == MAX_POINTS_ON_FIXED_WINDING) |
| 192 |
{ |
| 193 |
FreeStackWinding (neww, stack); |
| 194 |
return in; |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
p2 = in->points[(i+1)%in->numpoints]; |
| 199 |
|
| 200 |
dot = dists[i] / (dists[i]-dists[i+1]); |
| 201 |
for (j=0 ; j<3 ; j++) |
| 202 |
{ |
| 203 |
if (split->normal[j] == 1) |
| 204 |
mid[j] = split->dist; |
| 205 |
else if (split->normal[j] == -1) |
| 206 |
mid[j] = -split->dist; |
| 207 |
else |
| 208 |
mid[j] = p1[j] + dot*(p2[j]-p1[j]); |
| 209 |
} |
| 210 |
|
| 211 |
VectorCopy (mid, neww->points[neww->numpoints]); |
| 212 |
neww->numpoints++; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
FreeStackWinding (in, stack); |
| 217 |
|
| 218 |
return neww; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
winding_t *ClipToSeperators (winding_t *source, winding_t *pass, winding_t *target, qboolean flipclip, pstack_t *stack) |
| 239 |
{ |
| 240 |
int i, j, k, l; |
| 241 |
plane_t plane; |
| 242 |
vec3_t v1, v2; |
| 243 |
float d; |
| 244 |
vec_t length; |
| 245 |
int counts[3]; |
| 246 |
qboolean fliptest; |
| 247 |
|
| 248 |
|
| 249 |
for (i=0 ; i<source->numpoints ; i++) |
| 250 |
{ |
| 251 |
l = (i+1)%source->numpoints; |
| 252 |
VectorSubtract (source->points[l] , source->points[i], v1); |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
for (j=0 ; j<pass->numpoints ; j++) |
| 258 |
{ |
| 259 |
VectorSubtract (pass->points[j], source->points[i], v2); |
| 260 |
|
| 261 |
plane.normal[0] = v1[1]*v2[2] - v1[2]*v2[1]; |
| 262 |
plane.normal[1] = v1[2]*v2[0] - v1[0]*v2[2]; |
| 263 |
plane.normal[2] = v1[0]*v2[1] - v1[1]*v2[0]; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
length = plane.normal[0] * plane.normal[0] |
| 268 |
+ plane.normal[1] * plane.normal[1] |
| 269 |
+ plane.normal[2] * plane.normal[2]; |
| 270 |
|
| 271 |
if (length < ON_EPSILON) |
| 272 |
continue; |
| 273 |
|
| 274 |
length = 1/sqrt(length); |
| 275 |
|
| 276 |
plane.normal[0] *= length; |
| 277 |
plane.normal[1] *= length; |
| 278 |
plane.normal[2] *= length; |
| 279 |
|
| 280 |
plane.dist = DotProduct (pass->points[j], plane.normal); |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
#if 1 |
| 287 |
fliptest = false; |
| 288 |
for (k=0 ; k<source->numpoints ; k++) |
| 289 |
{ |
| 290 |
if (k == i || k == l) |
| 291 |
continue; |
| 292 |
d = DotProduct (source->points[k], plane.normal) - plane.dist; |
| 293 |
if (d < -ON_EPSILON) |
| 294 |
{ |
| 295 |
|
| 296 |
fliptest = false; |
| 297 |
break; |
| 298 |
} |
| 299 |
else if (d > ON_EPSILON) |
| 300 |
{ |
| 301 |
|
| 302 |
fliptest = true; |
| 303 |
break; |
| 304 |
} |
| 305 |
} |
| 306 |
if (k == source->numpoints) |
| 307 |
continue; |
| 308 |
#else |
| 309 |
fliptest = flipclip; |
| 310 |
#endif |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
if (fliptest) |
| 315 |
{ |
| 316 |
VectorSubtract (vec3_origin, plane.normal, plane.normal); |
| 317 |
plane.dist = -plane.dist; |
| 318 |
} |
| 319 |
#if 1 |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
counts[0] = counts[1] = counts[2] = 0; |
| 325 |
for (k=0 ; k<pass->numpoints ; k++) |
| 326 |
{ |
| 327 |
if (k==j) |
| 328 |
continue; |
| 329 |
d = DotProduct (pass->points[k], plane.normal) - plane.dist; |
| 330 |
if (d < -ON_EPSILON) |
| 331 |
break; |
| 332 |
else if (d > ON_EPSILON) |
| 333 |
counts[0]++; |
| 334 |
else |
| 335 |
counts[2]++; |
| 336 |
} |
| 337 |
if (k != pass->numpoints) |
| 338 |
continue; |
| 339 |
|
| 340 |
if (!counts[0]) |
| 341 |
continue; |
| 342 |
#else |
| 343 |
k = (j+1)%pass->numpoints; |
| 344 |
d = DotProduct (pass->points[k], plane.normal) - plane.dist; |
| 345 |
if (d < -ON_EPSILON) |
| 346 |
continue; |
| 347 |
k = (j+pass->numpoints-1)%pass->numpoints; |
| 348 |
d = DotProduct (pass->points[k], plane.normal) - plane.dist; |
| 349 |
if (d < -ON_EPSILON) |
| 350 |
continue; |
| 351 |
#endif |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
if (flipclip) |
| 356 |
{ |
| 357 |
VectorSubtract (vec3_origin, plane.normal, plane.normal); |
| 358 |
plane.dist = -plane.dist; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
target = ChopWinding (target, stack, &plane); |
| 365 |
if (!target) |
| 366 |
return NULL; |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
return target; |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
void RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack) |
| 384 |
{ |
| 385 |
pstack_t stack; |
| 386 |
portal_t *p; |
| 387 |
plane_t backplane; |
| 388 |
leaf_t *leaf; |
| 389 |
int i, j; |
| 390 |
long *test, *might, *vis, more; |
| 391 |
int pnum; |
| 392 |
|
| 393 |
thread->c_chains++; |
| 394 |
|
| 395 |
leaf = &leafs[leafnum]; |
| 396 |
|
| 397 |
|
| 398 |
prevstack->next = &stack; |
| 399 |
|
| 400 |
stack.next = NULL; |
| 401 |
stack.leaf = leaf; |
| 402 |
stack.portal = NULL; |
| 403 |
|
| 404 |
might = (long *)stack.mightsee; |
| 405 |
vis = (long *)thread->base->portalvis; |
| 406 |
|
| 407 |
|
| 408 |
for (i=0 ; i<leaf->numportals ; i++) |
| 409 |
{ |
| 410 |
p = leaf->portals[i]; |
| 411 |
pnum = p - portals; |
| 412 |
|
| 413 |
if ( ! (prevstack->mightsee[pnum >> 3] & (1<<(pnum&7)) ) ) |
| 414 |
{ |
| 415 |
continue; |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
if (p->status == stat_done) |
| 420 |
{ |
| 421 |
test = (long *)p->portalvis; |
| 422 |
} |
| 423 |
else |
| 424 |
{ |
| 425 |
test = (long *)p->portalflood; |
| 426 |
} |
| 427 |
|
| 428 |
more = 0; |
| 429 |
for (j=0 ; j<portallongs ; j++) |
| 430 |
{ |
| 431 |
might[j] = ((long *)prevstack->mightsee)[j] & test[j]; |
| 432 |
more |= (might[j] & ~vis[j]); |
| 433 |
} |
| 434 |
|
| 435 |
if (!more && |
| 436 |
(thread->base->portalvis[pnum>>3] & (1<<(pnum&7))) ) |
| 437 |
{ |
| 438 |
continue; |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
stack.portalplane = p->plane; |
| 443 |
VectorSubtract (vec3_origin, p->plane.normal, backplane.normal); |
| 444 |
backplane.dist = -p->plane.dist; |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
stack.portal = p; |
| 449 |
stack.next = NULL; |
| 450 |
stack.freewindings[0] = 1; |
| 451 |
stack.freewindings[1] = 1; |
| 452 |
stack.freewindings[2] = 1; |
| 453 |
|
| 454 |
#if 1 |
| 455 |
{ |
| 456 |
float d; |
| 457 |
|
| 458 |
d = DotProduct (p->origin, thread->pstack_head.portalplane.normal); |
| 459 |
d -= thread->pstack_head.portalplane.dist; |
| 460 |
if (d < -p->radius) |
| 461 |
{ |
| 462 |
continue; |
| 463 |
} |
| 464 |
else if (d > p->radius) |
| 465 |
{ |
| 466 |
stack.pass = p->winding; |
| 467 |
} |
| 468 |
else |
| 469 |
{ |
| 470 |
stack.pass = ChopWinding (p->winding, &stack, &thread->pstack_head.portalplane); |
| 471 |
if (!stack.pass) |
| 472 |
continue; |
| 473 |
} |
| 474 |
} |
| 475 |
#else |
| 476 |
stack.pass = ChopWinding (p->winding, &stack, &thread->pstack_head.portalplane); |
| 477 |
if (!stack.pass) |
| 478 |
continue; |
| 479 |
#endif |
| 480 |
|
| 481 |
|
| 482 |
#if 1 |
| 483 |
{ |
| 484 |
float d; |
| 485 |
|
| 486 |
d = DotProduct (thread->base->origin, p->plane.normal); |
| 487 |
d -= p->plane.dist; |
| 488 |
if (d > p->radius) |
| 489 |
{ |
| 490 |
continue; |
| 491 |
} |
| 492 |
else if (d < -p->radius) |
| 493 |
{ |
| 494 |
stack.source = prevstack->source; |
| 495 |
} |
| 496 |
else |
| 497 |
{ |
| 498 |
stack.source = ChopWinding (prevstack->source, &stack, &backplane); |
| 499 |
if (!stack.source) |
| 500 |
continue; |
| 501 |
} |
| 502 |
} |
| 503 |
#else |
| 504 |
stack.source = ChopWinding (prevstack->source, &stack, &backplane); |
| 505 |
if (!stack.source) |
| 506 |
continue; |
| 507 |
#endif |
| 508 |
|
| 509 |
if (!prevstack->pass) |
| 510 |
{ |
| 511 |
|
| 512 |
|
| 513 |
thread->base->portalvis[pnum>>3] |= (1<<(pnum&7)); |
| 514 |
|
| 515 |
RecursiveLeafFlow (p->leaf, thread, &stack); |
| 516 |
continue; |
| 517 |
} |
| 518 |
|
| 519 |
stack.pass = ClipToSeperators (stack.source, prevstack->pass, stack.pass, false, &stack); |
| 520 |
if (!stack.pass) |
| 521 |
continue; |
| 522 |
|
| 523 |
stack.pass = ClipToSeperators (prevstack->pass, stack.source, stack.pass, true, &stack); |
| 524 |
if (!stack.pass) |
| 525 |
continue; |
| 526 |
|
| 527 |
|
| 528 |
thread->base->portalvis[pnum>>3] |= (1<<(pnum&7)); |
| 529 |
|
| 530 |
|
| 531 |
RecursiveLeafFlow (p->leaf, thread, &stack); |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
void PortalFlow (int portalnum) |
| 544 |
{ |
| 545 |
threaddata_t data; |
| 546 |
int i; |
| 547 |
portal_t *p; |
| 548 |
int c_might, c_can; |
| 549 |
|
| 550 |
p = sorted_portals[portalnum]; |
| 551 |
p->status = stat_working; |
| 552 |
|
| 553 |
c_might = CountBits (p->portalflood, numportals*2); |
| 554 |
|
| 555 |
memset (&data, 0, sizeof(data)); |
| 556 |
data.base = p; |
| 557 |
|
| 558 |
data.pstack_head.portal = p; |
| 559 |
data.pstack_head.source = p->winding; |
| 560 |
data.pstack_head.portalplane = p->plane; |
| 561 |
for (i=0 ; i<portallongs ; i++) |
| 562 |
((long *)data.pstack_head.mightsee)[i] = ((long *)p->portalflood)[i]; |
| 563 |
RecursiveLeafFlow (p->leaf, &data, &data.pstack_head); |
| 564 |
|
| 565 |
p->status = stat_done; |
| 566 |
|
| 567 |
c_can = CountBits (p->portalvis, numportals*2); |
| 568 |
|
| 569 |
qprintf ("portal:%4i mightsee:%4i cansee:%4i (%i chains)\n", |
| 570 |
(int)(p - portals), c_might, c_can, data.c_chains); |
| 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 |
int c_flood, c_vis; |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
void SimpleFlood (portal_t *srcportal, int leafnum) |
| 626 |
{ |
| 627 |
int i; |
| 628 |
leaf_t *leaf; |
| 629 |
portal_t *p; |
| 630 |
int pnum; |
| 631 |
|
| 632 |
leaf = &leafs[leafnum]; |
| 633 |
|
| 634 |
for (i=0 ; i<leaf->numportals ; i++) |
| 635 |
{ |
| 636 |
p = leaf->portals[i]; |
| 637 |
pnum = p - portals; |
| 638 |
if ( ! (srcportal->portalfront[pnum>>3] & (1<<(pnum&7)) ) ) |
| 639 |
continue; |
| 640 |
|
| 641 |
if (srcportal->portalflood[pnum>>3] & (1<<(pnum&7)) ) |
| 642 |
continue; |
| 643 |
|
| 644 |
srcportal->portalflood[pnum>>3] |= (1<<(pnum&7)); |
| 645 |
|
| 646 |
SimpleFlood (srcportal, p->leaf); |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
void BasePortalVis (int portalnum) |
| 656 |
{ |
| 657 |
int j, k; |
| 658 |
portal_t *tp, *p; |
| 659 |
float d; |
| 660 |
winding_t *w; |
| 661 |
|
| 662 |
p = portals+portalnum; |
| 663 |
|
| 664 |
p->portalfront = malloc (portalbytes); |
| 665 |
memset (p->portalfront, 0, portalbytes); |
| 666 |
|
| 667 |
p->portalflood = malloc (portalbytes); |
| 668 |
memset (p->portalflood, 0, portalbytes); |
| 669 |
|
| 670 |
p->portalvis = malloc (portalbytes); |
| 671 |
memset (p->portalvis, 0, portalbytes); |
| 672 |
|
| 673 |
for (j=0, tp = portals ; j<numportals*2 ; j++, tp++) |
| 674 |
{ |
| 675 |
if (j == portalnum) |
| 676 |
continue; |
| 677 |
w = tp->winding; |
| 678 |
for (k=0 ; k<w->numpoints ; k++) |
| 679 |
{ |
| 680 |
d = DotProduct (w->points[k], p->plane.normal) |
| 681 |
- p->plane.dist; |
| 682 |
if (d > ON_EPSILON) |
| 683 |
break; |
| 684 |
} |
| 685 |
if (k == w->numpoints) |
| 686 |
continue; |
| 687 |
|
| 688 |
w = p->winding; |
| 689 |
for (k=0 ; k<w->numpoints ; k++) |
| 690 |
{ |
| 691 |
d = DotProduct (w->points[k], tp->plane.normal) |
| 692 |
- tp->plane.dist; |
| 693 |
if (d < -ON_EPSILON) |
| 694 |
break; |
| 695 |
} |
| 696 |
if (k == w->numpoints) |
| 697 |
continue; |
| 698 |
|
| 699 |
p->portalfront[j>>3] |= (1<<(j&7)); |
| 700 |
} |
| 701 |
|
| 702 |
SimpleFlood (p, p->leaf); |
| 703 |
|
| 704 |
p->nummightsee = CountBits (p->portalflood, numportals*2); |
| 705 |
|
| 706 |
c_flood += p->nummightsee; |
| 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 |
void RecursiveLeafBitFlow (int leafnum, byte *mightsee, byte *cansee) |
| 732 |
{ |
| 733 |
portal_t *p; |
| 734 |
leaf_t *leaf; |
| 735 |
int i, j; |
| 736 |
long more; |
| 737 |
int pnum; |
| 738 |
byte newmight[MAX_PORTALS/8]; |
| 739 |
|
| 740 |
leaf = &leafs[leafnum]; |
| 741 |
|
| 742 |
|
| 743 |
for (i=0 ; i<leaf->numportals ; i++) |
| 744 |
{ |
| 745 |
p = leaf->portals[i]; |
| 746 |
pnum = p - portals; |
| 747 |
|
| 748 |
|
| 749 |
if (! (mightsee[pnum>>3] & (1<<(pnum&7)) ) ) |
| 750 |
continue; |
| 751 |
|
| 752 |
|
| 753 |
more = 0; |
| 754 |
for (j=0 ; j<portallongs ; j++) |
| 755 |
{ |
| 756 |
((long *)newmight)[j] = ((long *)mightsee)[j] |
| 757 |
& ((long *)p->portalflood)[j]; |
| 758 |
more |= ((long *)newmight)[j] & ~((long *)cansee)[j]; |
| 759 |
} |
| 760 |
|
| 761 |
if (!more) |
| 762 |
continue; |
| 763 |
|
| 764 |
cansee[pnum>>3] |= (1<<(pnum&7)); |
| 765 |
|
| 766 |
RecursiveLeafBitFlow (p->leaf, newmight, cansee); |
| 767 |
} |
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
void BetterPortalVis (int portalnum) |
| 776 |
{ |
| 777 |
portal_t *p; |
| 778 |
|
| 779 |
p = portals+portalnum; |
| 780 |
|
| 781 |
RecursiveLeafBitFlow (p->leaf, p->portalflood, p->portalvis); |
| 782 |
|
| 783 |
|
| 784 |
p->nummightsee = CountBits (p->portalvis, numportals*2); |
| 785 |
c_vis += p->nummightsee; |
| 786 |
} |
| 787 |
|
| 788 |
|