@ -3,6 +3,7 @@
# include <components/detournavigator/navigatorimpl.hpp>
# include <components/detournavigator/navigatorimpl.hpp>
# include <components/detournavigator/exceptions.hpp>
# include <components/detournavigator/exceptions.hpp>
# include <components/misc/rng.hpp>
# include <components/misc/rng.hpp>
# include <components/loadinglistener/loadinglistener.hpp>
# include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
# include <BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h>
# include <BulletCollision/CollisionShapes/btBoxShape.h>
# include <BulletCollision/CollisionShapes/btBoxShape.h>
@ -35,6 +36,7 @@ namespace
std : : back_insert_iterator < std : : deque < osg : : Vec3f > > mOut ;
std : : back_insert_iterator < std : : deque < osg : : Vec3f > > mOut ;
float mStepSize ;
float mStepSize ;
AreaCosts mAreaCosts ;
AreaCosts mAreaCosts ;
Loading : : Listener mListener ;
DetourNavigatorNavigatorTest ( )
DetourNavigatorNavigatorTest ( )
: mPlayerPosition ( 0 , 0 , 0 )
: mPlayerPosition ( 0 , 0 , 0 )
@ -124,7 +126,7 @@ namespace
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
@ -174,7 +176,7 @@ namespace
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addObject ( ObjectId ( & heightfieldShape ) , heightfieldShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & heightfieldShape ) , heightfieldShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
@ -206,7 +208,7 @@ namespace
mNavigator - > addObject ( ObjectId ( & compoundShape ) , compoundShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & compoundShape ) , compoundShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
mPath . clear ( ) ;
mPath . clear ( ) ;
mOut = std : : back_inserter ( mPath ) ;
mOut = std : : back_inserter ( mPath ) ;
@ -259,7 +261,7 @@ namespace
mNavigator - > addObject ( ObjectId ( & heightfieldShape ) , heightfieldShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & heightfieldShape ) , heightfieldShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & compoundShape ) , compoundShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & compoundShape ) , compoundShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
@ -293,7 +295,7 @@ namespace
mNavigator - > updateObject ( ObjectId ( & compoundShape ) , compoundShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > updateObject ( ObjectId ( & compoundShape ) , compoundShape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
mPath . clear ( ) ;
mPath . clear ( ) ;
mOut = std : : back_inserter ( mPath ) ;
mOut = std : : back_inserter ( mPath ) ;
@ -352,7 +354,7 @@ namespace
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape2 ) , shape2 , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape2 ) , shape2 , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
@ -408,7 +410,7 @@ namespace
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , ObjectShapes { shape , & shapeAvoid } , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , ObjectShapes { shape , & shapeAvoid } , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
@ -456,7 +458,7 @@ namespace
mNavigator - > addWater ( osg : : Vec2i ( 0 , 0 ) , 128 * 4 , 300 , btTransform : : getIdentity ( ) ) ;
mNavigator - > addWater ( osg : : Vec2i ( 0 , 0 ) , 128 * 4 , 300 , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
mStart . x ( ) = 0 ;
mStart . x ( ) = 0 ;
mStart . z ( ) = 300 ;
mStart . z ( ) = 300 ;
@ -504,7 +506,7 @@ namespace
mNavigator - > addWater ( osg : : Vec2i ( 0 , 0 ) , 128 * 4 , - 25 , btTransform : : getIdentity ( ) ) ;
mNavigator - > addWater ( osg : : Vec2i ( 0 , 0 ) , 128 * 4 , - 25 , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
mStart . x ( ) = 0 ;
mStart . x ( ) = 0 ;
mEnd . x ( ) = 0 ;
mEnd . x ( ) = 0 ;
@ -551,7 +553,7 @@ namespace
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addWater ( osg : : Vec2i ( 0 , 0 ) , std : : numeric_limits < int > : : max ( ) , - 25 , btTransform : : getIdentity ( ) ) ;
mNavigator - > addWater ( osg : : Vec2i ( 0 , 0 ) , std : : numeric_limits < int > : : max ( ) , - 25 , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
mStart . x ( ) = 0 ;
mStart . x ( ) = 0 ;
mEnd . x ( ) = 0 ;
mEnd . x ( ) = 0 ;
@ -598,7 +600,7 @@ namespace
mNavigator - > addWater ( osg : : Vec2i ( 0 , 0 ) , 128 * 4 , - 25 , btTransform : : getIdentity ( ) ) ;
mNavigator - > addWater ( osg : : Vec2i ( 0 , 0 ) , 128 * 4 , - 25 , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
mStart . x ( ) = 0 ;
mStart . x ( ) = 0 ;
mEnd . x ( ) = 0 ;
mEnd . x ( ) = 0 ;
@ -642,15 +644,15 @@ namespace
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
mNavigator - > removeObject ( ObjectId ( & shape ) ) ;
mNavigator - > removeObject ( ObjectId ( & shape ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
@ -696,7 +698,7 @@ namespace
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
Misc : : Rng : : init ( 42 ) ;
Misc : : Rng : : init ( 42 ) ;
@ -745,7 +747,7 @@ namespace
}
}
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
EXPECT_EQ ( mNavigator - > findPath ( mAgentHalfExtents , mStepSize , mStart , mEnd , Flag_walk , mAreaCosts , mOut ) , Status : : Success ) ;
@ -788,7 +790,7 @@ namespace
mNavigator - > addObject ( ObjectId ( & shapes [ i ] ) , shapes [ i ] , transform ) ;
mNavigator - > addObject ( ObjectId ( & shapes [ i ] ) , shapes [ i ] , transform ) ;
}
}
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
const auto start = std : : chrono : : steady_clock : : now ( ) ;
const auto start = std : : chrono : : steady_clock : : now ( ) ;
for ( std : : size_t i = 0 ; i < shapes . size ( ) ; + + i )
for ( std : : size_t i = 0 ; i < shapes . size ( ) ; + + i )
@ -797,7 +799,7 @@ namespace
mNavigator - > updateObject ( ObjectId ( & shapes [ i ] ) , shapes [ i ] , transform ) ;
mNavigator - > updateObject ( ObjectId ( & shapes [ i ] ) , shapes [ i ] , transform ) ;
}
}
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
for ( std : : size_t i = 0 ; i < shapes . size ( ) ; + + i )
for ( std : : size_t i = 0 ; i < shapes . size ( ) ; + + i )
{
{
@ -805,7 +807,7 @@ namespace
mNavigator - > updateObject ( ObjectId ( & shapes [ i ] ) , shapes [ i ] , transform ) ;
mNavigator - > updateObject ( ObjectId ( & shapes [ i ] ) , shapes [ i ] , transform ) ;
}
}
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
const auto duration = std : : chrono : : steady_clock : : now ( ) - start ;
const auto duration = std : : chrono : : steady_clock : : now ( ) - start ;
@ -828,7 +830,7 @@ namespace
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addAgent ( mAgentHalfExtents ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > addObject ( ObjectId ( & shape ) , shape , btTransform : : getIdentity ( ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
const auto result = mNavigator - > raycast ( mAgentHalfExtents , mStart , mEnd , Flag_walk ) ;
const auto result = mNavigator - > raycast ( mAgentHalfExtents , mStart , mEnd , Flag_walk ) ;
@ -859,7 +861,7 @@ namespace
mNavigator - > addObject ( ObjectId ( & boderBoxShape ) , boderBoxShape ,
mNavigator - > addObject ( ObjectId ( & boderBoxShape ) , boderBoxShape ,
btTransform ( btMatrix3x3 : : getIdentity ( ) , oscillatingBoxShapePosition + btVector3 ( 0 , 0 , 200 ) ) ) ;
btTransform ( btMatrix3x3 : : getIdentity ( ) , oscillatingBoxShapePosition + btVector3 ( 0 , 0 , 200 ) ) ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
const auto navMeshes = mNavigator - > getNavMeshes ( ) ;
const auto navMeshes = mNavigator - > getNavMeshes ( ) ;
ASSERT_EQ ( navMeshes . size ( ) , 1 ) ;
ASSERT_EQ ( navMeshes . size ( ) , 1 ) ;
@ -875,7 +877,7 @@ namespace
oscillatingBoxShapePosition ) ;
oscillatingBoxShapePosition ) ;
mNavigator - > updateObject ( ObjectId ( & oscillatingBoxShape ) , oscillatingBoxShape , transform ) ;
mNavigator - > updateObject ( ObjectId ( & oscillatingBoxShape ) , oscillatingBoxShape , transform ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > update ( mPlayerPosition ) ;
mNavigator - > wait ( ) ;
mNavigator - > wait ( mListener ) ;
}
}
ASSERT_EQ ( navMeshes . size ( ) , 1 ) ;
ASSERT_EQ ( navMeshes . size ( ) , 1 ) ;