Permalink
Browse files

ROAM: fix cracks

  • Loading branch information...
1 parent 9d508e6 commit 1512e7a69801cf106579b187c66647c0b11d55e4 jK committed Jun 3, 2012
Showing with 11 additions and 8 deletions.
  1. +11 −8 rts/Map/SMF/ROAM/RoamMeshDrawer.cpp
@@ -356,22 +356,25 @@ void CRoamMeshDrawer::Tessellate(const float3& campos, int viewradius)
//
void CRoamMeshDrawer::UnsyncedHeightMapUpdate(const SRectangle& rect)
{
+ const int margin = 2;
+ const float INV_PATCH_SIZE = 1.0f / PATCH_SIZE;
+
// hint: the -+1 are cause Patches share 1 pixel border (no vertex holes!)
- const int xstart = std::max(0, (int)floor((rect.x1 - 1.0f) / PATCH_SIZE));
- const int xend = std::min(numPatchesX, (int)ceil( (rect.x2 + 1.0f) / PATCH_SIZE));
- const int zstart = std::max(0, (int)floor((rect.z1 - 1.0f) / PATCH_SIZE));
- const int zend = std::min(numPatchesY, (int)ceil( (rect.z2 + 1.0f) / PATCH_SIZE));
+ const int xstart = std::max(0, (int)floor((rect.x1 - margin) * INV_PATCH_SIZE));
+ const int xend = std::min(numPatchesX, (int)ceil( (rect.x2 + margin) * INV_PATCH_SIZE));
+ const int zstart = std::max(0, (int)floor((rect.z1 - margin) * INV_PATCH_SIZE));
+ const int zend = std::min(numPatchesY, (int)ceil( (rect.z2 + margin) * INV_PATCH_SIZE));
for (int z = zstart; z < zend; ++z) {
for (int x = xstart; x < xend; ++x) {
Patch& p = m_Patches[z * numPatchesX + x];
// clamp the update rect to the patch constraints
SRectangle prect(
- std::max(rect.x1 - 1 - p.m_WorldX, 0),
- std::max(rect.z1 - 1 - p.m_WorldY, 0),
- std::min(rect.x2 + 1 - p.m_WorldX, PATCH_SIZE),
- std::min(rect.z2 + 1 - p.m_WorldY, PATCH_SIZE)
+ std::max(rect.x1 - margin - p.m_WorldX, 0),
+ std::max(rect.z1 - margin - p.m_WorldY, 0),
+ std::min(rect.x2 + margin - p.m_WorldX, PATCH_SIZE),
+ std::min(rect.z2 + margin - p.m_WorldY, PATCH_SIZE)
);
p.UpdateHeightMap(prect);

0 comments on commit 1512e7a

Please sign in to comment.