Skip to content

Commit

Permalink
World|Map: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 7, 2013
1 parent 7c502c0 commit 9ad97ec
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -145,9 +145,8 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound)
QScopedPointer<Blockmap> bspLeafBlockmap;

#ifdef __CLIENT__
struct ContactBlockmap
struct ContactBlockmap : public Blockmap
{
Blockmap blockmap;
QBitArray spreadBlocks; ///< Used to prevent repeat processing.

/**
Expand All @@ -157,28 +156,33 @@ DENG2_OBSERVES(bsp::Partitioner, UnclosedSectorFound)
* @param blockSize Size of each block.
*/
ContactBlockmap(AABoxd const &bounds, uint blockSize = 128)
: blockmap(bounds, Vector2ui(blockSize, blockSize)),
spreadBlocks(blockmap.width() * blockmap.height())
: Blockmap(bounds, Vector2ui(blockSize, blockSize)),
spreadBlocks(width() * height())
{}

void clear()
{
spreadBlocks.fill(false);
unlinkAll();
}

/**
* @param contact Contact to be linked. Note that if the object's origin
* lies outside the blockmap it will not be linked!
*/
void link(Contact &contact)
{
bool outside;
BlockmapCell cell = blockmap.toCell(contact.objectOrigin(), &outside);
BlockmapCell cell = toCell(contact.objectOrigin(), &outside);
if(!outside)
{
blockmap.link(cell, &contact);
Blockmap::link(cell, &contact);
}
}

void clear()
void spread(AABoxd const &region)
{
spreadBlocks.fill(false);
blockmap.unlinkAll();
spreadContacts(*this, region, &spreadBlocks);
}
};
QScopedPointer<ContactBlockmap> mobjContactBlockmap; /// @todo Redundant?
Expand Down Expand Up @@ -1425,15 +1429,13 @@ void Map::initContactBlockmaps()
void Map::spreadAllContacts(AABoxd const &region)
{
// Expand the region according by the maxium radius of each contact type.
spreadContacts(d->mobjContactBlockmap->blockmap,
AABoxd(region.minX - DDMOBJ_RADIUS_MAX, region.minY - DDMOBJ_RADIUS_MAX,
region.maxX + DDMOBJ_RADIUS_MAX, region.maxY + DDMOBJ_RADIUS_MAX),
&d->mobjContactBlockmap->spreadBlocks);

spreadContacts(d->lumobjContactBlockmap->blockmap,
AABoxd(region.minX - Lumobj::radiusMax(), region.minY - Lumobj::radiusMax(),
region.maxX + Lumobj::radiusMax(), region.maxY + Lumobj::radiusMax()),
&d->lumobjContactBlockmap->spreadBlocks);
d->mobjContactBlockmap->
spread(AABoxd(region.minX - DDMOBJ_RADIUS_MAX, region.minY - DDMOBJ_RADIUS_MAX,
region.maxX + DDMOBJ_RADIUS_MAX, region.maxY + DDMOBJ_RADIUS_MAX));

d->lumobjContactBlockmap->
spread(AABoxd(region.minX - Lumobj::radiusMax(), region.minY - Lumobj::radiusMax(),
region.maxX + Lumobj::radiusMax(), region.maxY + Lumobj::radiusMax()));
}

#endif // __CLIENT__
Expand Down

0 comments on commit 9ad97ec

Please sign in to comment.