Skip to content

Commit

Permalink
[12817] Improve GetHeightInRange, now we handle the case of two near …
Browse files Browse the repository at this point in the history
…value of vmap and map height in better way.
  • Loading branch information
Cyberium committed Jan 17, 2015
1 parent fdc35fb commit 5376545
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
44 changes: 34 additions & 10 deletions src/game/Map.cpp
Expand Up @@ -2027,28 +2027,52 @@ bool Map::GetHitPosition(float srcX, float srcY, float srcZ, float& destX, float
// Find an height within a reasonable range of provided Z. This method may fail so we have to handle that case.
bool Map::GetHeightInRange(uint32 phasemask, float x, float y, float &z, float maxSearchDist /*= 4.0f*/) const
{
float height;
float height, vmapHeight, mapHeight;
vmapHeight = VMAP_INVALID_HEIGHT_VALUE;

VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
if (!vmgr->isLineOfSightCalcEnabled())
vmgr = NULL;

if (vmgr)
{
height = VMAP_INVALID_HEIGHT_VALUE;

// pure vmap search
height = vmgr->getHeight(i_id, x, y, z + 1.0f, maxSearchDist);
vmapHeight = vmgr->getHeight(i_id, x, y, z + 2.0f, maxSearchDist + 2.0f);
}

if (height < INVALID_HEIGHT || fabs(fabs(z) - fabs(height)) > maxSearchDist)
// find raw height from .map file on X,Y coordinates
if (GridMap* gmap = const_cast<TerrainInfo*>(m_TerrainData)->GetGrid(x, y)) // TODO:: find a way to remove that const_cast
mapHeight = gmap->getHeight(x, y);

This comment has been minimized.

Copy link
@DomGries

DomGries Mar 8, 2015

Contributor

mapHeight can be uninitialized if that check is not valid

This comment has been minimized.

Copy link
@evil-at-wow

evil-at-wow Mar 8, 2015

Contributor

Yeah, I noticed that too when backporting this change. It's in my list of notes to fix.


float diffMaps = fabs(fabs(z) - fabs(mapHeight));
float diffVmaps = fabs(fabs(z) - fabs(vmapHeight));
if (diffVmaps < maxSearchDist)
{
// find raw height from .map file on X,Y coordinates
if (GridMap* gmap = const_cast<TerrainInfo*>(m_TerrainData)->GetGrid(x, y)) // TODO:: find a way to remove that const_cast
height = gmap->getHeight(x, y);
if (diffMaps < maxSearchDist)
{
// here we often have to take vmap value but sometime we have to take map value.
if (vmapHeight > mapHeight || diffMaps > diffVmaps)
height = vmapHeight;
else
height = mapHeight;

if (fabs(fabs(z) - fabs(height)) > maxSearchDist)
return false; // not found any good height
//sLog.outString("vmap %5.4f, map %5.4f, height %5.4f", vmapHeight, mapHeight, height);
}
else
{
//sLog.outString("vmap %5.4f", vmapHeight);
height = vmapHeight;
}
}
else
{
if (diffMaps < maxSearchDist)
{
//sLog.outString("map %5.4f", mapHeight);
height = mapHeight;
}
else
return false;
}

z = std::max<float>(height, m_dyn_tree.getHeight(x, y, height + 1.0f, maxSearchDist, phasemask));
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12816"
#define REVISION_NR "12817"
#endif // __REVISION_NR_H__

0 comments on commit 5376545

Please sign in to comment.