bugfix erase_border

This commit is contained in:
Enno Rehling 2004-02-07 12:10:24 +00:00
parent 72f99f8b18
commit 7eaad89b31
1 changed files with 26 additions and 13 deletions

View File

@ -107,12 +107,12 @@ read_borders(FILE * f)
type = find_bordertype(zText); type = find_bordertype(zText);
assert(type || !"border type not registered"); assert(type || !"border type not registered");
from = findregion(fx, fy); from = findregion(fx, fy);
if (!from) { if (from==NULL) {
log_error(("border for unknown region %d,%d\n", fx, fy)); log_error(("border for unknown region %d,%d\n", fx, fy));
from = new_region(fx, fy); from = new_region(fx, fy);
} }
to = findregion(tx, ty); to = findregion(tx, ty);
if (!to) { if (to==NULL) {
log_error(("border for unknown region %d,%d\n", tx, ty)); log_error(("border for unknown region %d,%d\n", tx, ty));
to = new_region(tx, ty); to = new_region(tx, ty);
} }
@ -140,7 +140,14 @@ new_border(border_type * type, region * from, region * to)
key = min(k2, key) % BMAXHASH; key = min(k2, key) % BMAXHASH;
bp = &borders[key]; bp = &borders[key];
while (*bp && !(((*bp)->from==from && (*bp)->to==to) || ((*bp)->from==to && (*bp)->to==from))) bp = &(*bp)->nexthash;
/* find the first border across the same edge, so we can insert before it.
* if there's no border here yet, add the border to the end (this way, the
* b->next pointer will point to *bp, which is NULL).
*/
while (*bp && ((*bp)->from!=from || (*bp)->to!=to)) {
bp = &(*bp)->nexthash;
}
b = calloc(1, sizeof(struct border)); b = calloc(1, sizeof(struct border));
b->type = type; b->type = type;
b->nexthash = *bp; b->nexthash = *bp;
@ -149,25 +156,29 @@ new_border(border_type * type, region * from, region * to)
b->to = to; b->to = to;
b->id = ++nextborder; b->id = ++nextborder;
*bp = b; *bp = b;
if (type->init) type->init(b);
if (type->init) type->init(b);
return b; return b;
} }
void void
erase_border(border * b) erase_border(border * b)
{ {
border ** np, ** hp; border ** np = NULL, ** hp;
int key = region_hashkey(b->from); int key = region_hashkey(b->from);
int k2 = region_hashkey(b->to); int k2 = region_hashkey(b->to);
attrib ** ap = &b->attribs; attrib ** ap = &b->attribs;
while (*ap) a_remove(ap, *ap); while (*ap) a_remove(ap, *ap);
key = min(k2, key) % BMAXHASH; key = min(k2, key) % BMAXHASH;
hp = np = &borders[key]; hp = &borders[key];
while (*np && *np != b) np = &(*np)->next; while (*hp && *hp != b) {
while (*hp && *hp != b) hp = &(*hp)->nexthash; border * bp = *hp;
if (bp->next==b) np = &bp->next;
hp = &(*hp)->nexthash;
}
assert((*np && *hp) || !"error: border is not registered"); assert((*np && *hp) || !"error: border is not registered");
*np = b->next; if (np!=NULL) *np = b->next;
*hp = b->nexthash; *hp = b->nexthash;
if (b->type->destroy) b->type->destroy(b); if (b->type->destroy) b->type->destroy(b);
free(b); free(b);
@ -248,9 +259,9 @@ age_borders(void)
while (*bp) { while (*bp) {
border * b = *bp; border * b = *bp;
attrib ** ap = &b->attribs; attrib ** ap = &b->attribs;
while(*ap) { while (*ap) {
attrib * a = *ap; attrib * a = *ap;
if(a->type->age && a->type->age(a)==0) { if (a->type->age && a->type->age(a)==0) {
if (a->type == &at_countdown) { if (a->type == &at_countdown) {
erase_border(b); erase_border(b);
b = NULL; b = NULL;
@ -262,8 +273,10 @@ age_borders(void)
} }
else ap=&a->next; else ap=&a->next;
} }
if (!b) continue; /* bei löschung bp nicht vorziehen */ if (b!=NULL) {
bp=&b->nexthash; /* bei löschung zeigt bp bereits auf den nächsten */
bp=&b->nexthash;
}
} }
} }
} }