Skip to content

Commit

Permalink
Fixed|Bsp Builder: Prefer non "self-referencing" lines when choosing …
Browse files Browse the repository at this point in the history
…a BSP leaf's sector

Rather than blindly take the sector from the first linedef half-edge,
scan for a non self-referencing line first. Only resort to using a
self-referencing line if no better indicator is available.

This logic greatly reduces the number of map rendering issues around
such constructs.
  • Loading branch information
danij-deng committed Sep 1, 2012
1 parent 4288ae9 commit 3e05dcf
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions doomsday/engine/portable/src/map/bsp/partitioner.cpp
Expand Up @@ -1550,21 +1550,29 @@ struct Partitioner::Instance
/**
* Determine which sector this BSP leaf belongs to.
*/
static Sector* chooseSectorForBspLeaf(BspLeaf* leaf)
Sector* chooseSectorForBspLeaf(BspLeaf* leaf)
{
if(leaf && leaf->hedge)
if(!leaf || !leaf->hedge) return 0;

Sector* selfRefChoice = 0;
HEdge* hedge = leaf->hedge;
do
{
HEdge* hedge = leaf->hedge;
do
LineDef* line = hedge->lineDef;
Sector* sector = line? line->L_sector(hedge->side) : 0;
if(sector)
{
if(hedge->lineDef)
{
Sector* sector = hedge->lineDef->L_sector(hedge->side);
if(sector) return sector;
}
} while((hedge = hedge->next) != leaf->hedge);
}
return 0;
// The first sector from a non self-referencing line is our best choice.
if(!(lineDefInfo(*line).flags & LineDefInfo::SelfRef))
return sector;

// Remember the self-referencing choice in case we've no better option.
if(!selfRefChoice)
selfRefChoice = sector;
}
} while((hedge = hedge->next) != leaf->hedge);

return selfRefChoice;
}

void clockwiseLeaf(BspTreeNode& tree, HEdgeSortBuffer& sortBuffer)
Expand Down

0 comments on commit 3e05dcf

Please sign in to comment.