| 392 |
|
int netchange = 0; |
| 393 |
|
struct cellact oca, nca; |
| 394 |
|
int ocnt, ncnt; |
| 395 |
< |
int c; |
| 395 |
> |
int nmatch = 0; |
| 396 |
|
GCOORD *ogcl, *ngcl; |
| 397 |
+ |
register int c; |
| 398 |
|
register GCOORD *ogcp, *ngcp; |
| 399 |
|
/* get old and new cell lists */ |
| 400 |
|
ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); |
| 406 |
|
ocnt = -ocnt; |
| 407 |
|
if ((nca.rev = ncnt < 0)) |
| 408 |
|
ncnt = -ncnt; |
| 409 |
< |
if (nca.rev == oca.rev) /* add and delete cells in order */ |
| 410 |
< |
while (ocnt > 0 & ncnt > 0) |
| 411 |
< |
if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ |
| 412 |
< |
netchange += docell(ngcp++, &nca); |
| 413 |
< |
ncnt--; |
| 414 |
< |
} else if (c < 0) { /* old cell */ |
| 415 |
< |
netchange -= docell(ogcp++, &oca); |
| 416 |
< |
ocnt--; |
| 417 |
< |
} else { /* same cell */ |
| 418 |
< |
ogcp++; ocnt--; |
| 419 |
< |
ngcp++; ncnt--; |
| 409 |
> |
if (oca.rev == nca.rev) { /* count matches */ |
| 410 |
> |
int oc = ocnt, nc = ncnt; |
| 411 |
> |
while (oc > 0 & nc > 0) { |
| 412 |
> |
c = cellcmp(ogcp, ngcp); |
| 413 |
> |
if (c >= 0) { ngcp++; nc--; } |
| 414 |
> |
if (c <= 0) { ogcp++; oc--; } |
| 415 |
> |
nmatch += c==0; |
| 416 |
> |
} |
| 417 |
> |
ogcp = ogcl; ngcp = ngcl; |
| 418 |
> |
} |
| 419 |
> |
if (nmatch < ocnt>>1) { /* faster to just delete old cells? */ |
| 420 |
> |
for (c = ncbeams; c--; ) |
| 421 |
> |
if (cbeam[c].wants & 1<<voxi) { |
| 422 |
> |
cbeam[c].wants &= ~(1<<voxi); |
| 423 |
> |
netchange--; |
| 424 |
|
} |
| 425 |
+ |
free((char *)ogcl); |
| 426 |
+ |
ogcl = NULL; ocnt = 0; |
| 427 |
+ |
} |
| 428 |
+ |
/* add and delete cells in order */ |
| 429 |
+ |
while (ocnt > 0 & ncnt > 0) |
| 430 |
+ |
if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ |
| 431 |
+ |
netchange += docell(ngcp++, &nca); |
| 432 |
+ |
ncnt--; |
| 433 |
+ |
} else if (c < 0) { /* old cell */ |
| 434 |
+ |
netchange -= docell(ogcp++, &oca); |
| 435 |
+ |
ocnt--; |
| 436 |
+ |
} else { /* same cell */ |
| 437 |
+ |
ogcp++; ocnt--; |
| 438 |
+ |
ngcp++; ncnt--; |
| 439 |
+ |
} |
| 440 |
|
/* take care of list tails */ |
| 441 |
|
for ( ; ncnt > 0; ncnt--) |
| 442 |
|
netchange += docell(ngcp++, &nca); |