From 7b82d5ca27cd80e3f99eb93f9cc0458f76477a56 Mon Sep 17 00:00:00 2001 From: Saul Rennison Date: Fri, 5 Jul 2013 15:13:35 +0100 Subject: [PATCH] Added navmesh support --- mp/src/game/server/functorutils.h | 12 ++++++++ mp/src/game/server/gameinterface.cpp | 17 +++++++---- mp/src/game/server/nav_area.cpp | 8 ++--- mp/src/game/server/nav_area.h | 12 ++++++++ mp/src/game/server/nav_colors.cpp | 14 ++++----- mp/src/game/server/nav_edit.cpp | 16 +++++----- mp/src/game/server/nav_entities.cpp | 6 ++-- mp/src/game/server/nav_mesh.cpp | 10 +++++-- mp/src/game/server/nav_mesh.vpc | 44 ++++++++++++++++++++++++++++ mp/src/game/server/server_hl2mp.vpc | 1 + 10 files changed, 111 insertions(+), 29 deletions(-) create mode 100644 mp/src/game/server/nav_mesh.vpc diff --git a/mp/src/game/server/functorutils.h b/mp/src/game/server/functorutils.h index 8b4657b2..5c10fc16 100644 --- a/mp/src/game/server/functorutils.h +++ b/mp/src/game/server/functorutils.h @@ -5,8 +5,10 @@ #ifndef _FUNCTOR_UTILS_H_ #define _FUNCTOR_UTILS_H_ +#ifdef NEXT_BOT #include "NextBotInterface.h" #include "NextBotManager.h" +#endif //-------------------------------------------------------------------------------------------------------- /** @@ -321,12 +323,14 @@ inline bool ForEachActor( Functor &func ) if ( !player->IsConnected() ) continue; +#ifdef NEXT_BOT // skip bots - ForEachCombatCharacter will catch them INextBot *bot = player->MyNextBotPointer(); if ( bot ) { continue; } +#endif if ( func( player ) == false ) { @@ -334,8 +338,12 @@ inline bool ForEachActor( Functor &func ) } } +#ifdef NEXT_BOT // iterate all NextBots return TheNextBots().ForEachCombatCharacter( func ); +#else + return true; +#endif } @@ -385,12 +393,14 @@ inline bool ForEachActor( IActorFunctor &func ) if ( !player->IsConnected() ) continue; +#ifdef NEXT_BOT // skip bots - ForEachCombatCharacter will catch them INextBot *bot = dynamic_cast< INextBot * >( player ); if ( bot ) { continue; } +#endif if ( func( player ) == false ) { @@ -399,11 +409,13 @@ inline bool ForEachActor( IActorFunctor &func ) } } +#ifdef NEXT_BOT if ( !isComplete ) { // iterate all NextBots isComplete = TheNextBots().ForEachCombatCharacter( func ); } +#endif func.OnEndIteration( isComplete ); diff --git a/mp/src/game/server/gameinterface.cpp b/mp/src/game/server/gameinterface.cpp index 9f707419..56b26227 100644 --- a/mp/src/game/server/gameinterface.cpp +++ b/mp/src/game/server/gameinterface.cpp @@ -104,8 +104,11 @@ extern ConVar tf_mm_trusted; extern ConVar tf_mm_servermode; #endif -#ifdef NEXT_BOT +#ifdef USE_NAV_MESH #include "nav_mesh.h" +#endif + +#ifdef NEXT_BOT #include "NextBotManager.h" #endif @@ -730,7 +733,7 @@ bool CServerGameDLL::DLLInit( CreateInterfaceFn appSystemFactory, debugoverlay = (IVDebugOverlay *)appSystemFactory( VDEBUG_OVERLAY_INTERFACE_VERSION, NULL ); #ifndef _XBOX -#ifdef NEXT_BOT +#ifdef USE_NAV_MESH // create the Navigation Mesh interface TheNavMesh = NavMeshFactory(); #endif @@ -776,7 +779,7 @@ void CServerGameDLL::DLLShutdown( void ) #endif #ifndef _XBOX -#ifdef NEXT_BOT +#ifdef USE_NAV_MESH // destroy the Navigation Mesh interface if ( TheNavMesh ) { @@ -1125,7 +1128,7 @@ void CServerGameDLL::ServerActivate( edict_t *pEdictList, int edictCount, int cl } #ifndef _XBOX -#ifdef NEXT_BOT +#ifdef USE_NAV_MESH // load the Navigation Mesh for this map TheNavMesh->Load(); TheNavMesh->OnServerActivate(); @@ -1220,9 +1223,11 @@ void CServerGameDLL::GameFrame( bool simulating ) GameStartFrame(); #ifndef _XBOX -#ifdef NEXT_BOT +#ifdef USE_NAV_MESH TheNavMesh->Update(); +#endif +#ifdef NEXT_BOT TheNextBots().Update(); #endif @@ -1388,7 +1393,7 @@ void CServerGameDLL::LevelShutdown( void ) g_nCurrentChapterIndex = -1; #ifndef _XBOX -#ifdef NEXT_BOT +#ifdef USE_NAV_MESH // reset the Navigation Mesh if ( TheNavMesh ) { diff --git a/mp/src/game/server/nav_area.cpp b/mp/src/game/server/nav_area.cpp index b25c4fa3..2ad083b8 100644 --- a/mp/src/game/server/nav_area.cpp +++ b/mp/src/game/server/nav_area.cpp @@ -53,7 +53,7 @@ uint32 CNavArea::s_nCurrVisTestCounter = 0; ConVar nav_coplanar_slope_limit( "nav_coplanar_slope_limit", "0.99", FCVAR_CHEAT ); ConVar nav_coplanar_slope_limit_displacement( "nav_coplanar_slope_limit_displacement", "0.7", FCVAR_CHEAT ); ConVar nav_split_place_on_ground( "nav_split_place_on_ground", "0", FCVAR_CHEAT, "If true, nav areas will be placed flush with the ground when split." ); -ConVar nav_area_bgcolor( "nav_area_bgcolor", "0 0 0 30", FCVAR_CHEAT, "RGBA color to draw as the background color for nav areas while editing." ); +ConVar nav_area_bgcolor( "nav_area_bgcolor", "0 0 0 128", FCVAR_CHEAT, "RGBA color to draw as the background color for nav areas while editing." ); ConVar nav_corner_adjust_adjacent( "nav_corner_adjust_adjacent", "18", FCVAR_CHEAT, "radius used to raise/lower corners in nearby areas when raising/lowering corners." ); ConVar nav_show_light_intensity( "nav_show_light_intensity", "0", FCVAR_CHEAT ); ConVar nav_debug_blocked( "nav_debug_blocked", "0", FCVAR_CHEAT ); @@ -2778,7 +2778,7 @@ void CNavArea::Draw( void ) const NavEditColor color; bool useAttributeColors = true; - const float DebugDuration = NDEBUG_PERSIST_TILL_NEXT_SERVER; + const float DebugDuration = 0; if ( TheNavMesh->IsEditMode( CNavMesh::PLACE_PAINTING ) ) { @@ -3146,7 +3146,7 @@ void CNavArea::DrawFilled( int r, int g, int b, int a, float deltaT, bool noDept //-------------------------------------------------------------------------------------------------------- void CNavArea::DrawSelectedSet( const Vector &shift ) const { - const float deltaT = NDEBUG_PERSIST_TILL_NEXT_SERVER; + const float deltaT = 0; int r = s_selectedSetColor.r(); int g = s_selectedSetColor.g(); int b = s_selectedSetColor.b(); @@ -3173,7 +3173,7 @@ void CNavArea::DrawSelectedSet( const Vector &shift ) const //-------------------------------------------------------------------------------------------------------- void CNavArea::DrawDragSelectionSet( Color &dragSelectionSetColor ) const { - const float deltaT = NDEBUG_PERSIST_TILL_NEXT_SERVER; + const float deltaT = 0; int r = dragSelectionSetColor.r(); int g = dragSelectionSetColor.g(); int b = dragSelectionSetColor.b(); diff --git a/mp/src/game/server/nav_area.h b/mp/src/game/server/nav_area.h index cbabe493..ee539538 100644 --- a/mp/src/game/server/nav_area.h +++ b/mp/src/game/server/nav_area.h @@ -313,10 +313,12 @@ public: bool HasAvoidanceObstacle( float maxObstructionHeight = StepHeight ) const; // is there a large, immobile object obstructing this area float GetAvoidanceObstacleHeight( void ) const; // returns the maximum height of the obstruction above the ground +#ifdef NEXT_BOT bool HasPrerequisite( CBaseCombatCharacter *actor = NULL ) const; // return true if this area has a prerequisite that applies to the given actor const CUtlVector< CHandle< CFuncNavPrerequisite > > &GetPrerequisiteVector( void ) const; // return vector of prerequisites that must be met before this area can be traversed void RemoveAllPrerequisites( void ); void AddPrerequisite( CFuncNavPrerequisite *prereq ); +#endif void ClearAllNavCostEntities( void ); // clear set of func_nav_cost entities that affect this area void AddFuncNavCostEntity( CFuncNavCost *cost ); // add the given func_nav_cost entity to the cost of this area @@ -722,7 +724,9 @@ private: void CalcDebugID(); +#ifdef NEXT_BOT CUtlVector< CHandle< CFuncNavPrerequisite > > m_prerequisiteVector; // list of prerequisites that must be met before this area can be traversed +#endif CNavArea *m_prevHash, *m_nextHash; // for hash table in CNavMesh @@ -765,24 +769,31 @@ extern NavAreaVector TheNavAreas; // //-------------------------------------------------------------------------------------------------------------- +#ifdef NEXT_BOT inline bool CNavArea::HasPrerequisite( CBaseCombatCharacter *actor ) const { return m_prerequisiteVector.Count() > 0; } +#endif //-------------------------------------------------------------------------------------------------------------- +#ifdef NEXT_BOT inline const CUtlVector< CHandle< CFuncNavPrerequisite > > &CNavArea::GetPrerequisiteVector( void ) const { return m_prerequisiteVector; } +#endif //-------------------------------------------------------------------------------------------------------------- +#ifdef NEXT_BOT inline void CNavArea::RemoveAllPrerequisites( void ) { m_prerequisiteVector.RemoveAll(); } +#endif //-------------------------------------------------------------------------------------------------------------- +#ifdef NEXT_BOT inline void CNavArea::AddPrerequisite( CFuncNavPrerequisite *prereq ) { if ( m_prerequisiteVector.Find( prereq ) == m_prerequisiteVector.InvalidIndex() ) @@ -790,6 +801,7 @@ inline void CNavArea::AddPrerequisite( CFuncNavPrerequisite *prereq ) m_prerequisiteVector.AddToTail( prereq ); } } +#endif //-------------------------------------------------------------------------------------------------------------- inline float CNavArea::GetDangerDecayRate( void ) const diff --git a/mp/src/game/server/nav_colors.cpp b/mp/src/game/server/nav_colors.cpp index 8f2035be..cbb313f2 100644 --- a/mp/src/game/server/nav_colors.cpp +++ b/mp/src/game/server/nav_colors.cpp @@ -79,8 +79,8 @@ void NavDrawLine( const Vector& from, const Vector& to, NavEditColor navColor ) const Vector offset( 0, 0, 1 ); Color color = NavColors[navColor]; - NDebugOverlay::Line( from + offset, to + offset, color[0]/2, color[1]/2, color[2]/2, true, 0.1f ); - NDebugOverlay::Line( from + offset, to + offset, color[0], color[1], color[2], false, 0.15f ); + NDebugOverlay::Line( from + offset, to + offset, color[0]/2, color[1]/2, color[2]/2, true, 0 ); + NDebugOverlay::Line( from + offset, to + offset, color[0], color[1], color[2], false, 0 ); } @@ -103,7 +103,7 @@ void NavDrawFilledTriangle( const Vector& point1, const Vector& point2, const Ve color[1] = color[1] / 2; color[2] = color[2] / 2; } - NDebugOverlay::Triangle( point1, point2, point3, color[0], color[1], color[2], 255, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + NDebugOverlay::Triangle( point1, point2, point3, color[0], color[1], color[2], 255, true, 0 ); } @@ -113,8 +113,8 @@ void NavDrawHorizontalArrow( const Vector& from, const Vector& to, float width, const Vector offset( 0, 0, 1 ); Color color = NavColors[navColor]; - NDebugOverlay::HorzArrow( from + offset, to + offset, width, color[0]/2, color[1]/2, color[2]/2, 255, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); - NDebugOverlay::HorzArrow( from + offset, to + offset, width, color[0], color[1], color[2], 255, false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + NDebugOverlay::HorzArrow( from + offset, to + offset, width, color[0]/2, color[1]/2, color[2]/2, 255, true, 0 ); + NDebugOverlay::HorzArrow( from + offset, to + offset, width, color[0], color[1], color[2], 255, false, 0 ); } @@ -142,8 +142,8 @@ void NavDrawDashedLine( const Vector& from, const Vector& to, NavEditColor navCo distance += solidLen + gapLen; - NDebugOverlay::Line( start + offset, end + offset, color[0]/2, color[1]/2, color[2]/2, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); - NDebugOverlay::Line( start + offset, end + offset, color[0], color[1], color[2], false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + NDebugOverlay::Line( start + offset, end + offset, color[0]/2, color[1]/2, color[2]/2, true, 0 ); + NDebugOverlay::Line( start + offset, end + offset, color[0], color[1], color[2], false, 0 ); } } diff --git a/mp/src/game/server/nav_edit.cpp b/mp/src/game/server/nav_edit.cpp index cea4e41d..f2cdf4c7 100644 --- a/mp/src/game/server/nav_edit.cpp +++ b/mp/src/game/server/nav_edit.cpp @@ -732,8 +732,10 @@ void CNavMesh::DrawEditMode( void ) static ConVarRef host_thread_mode( "host_thread_mode" ); host_thread_mode.SetValue( 0 ); +#ifdef TERROR static ConVarRef sb_perf_collect( "sb_perf_collect" ); sb_perf_collect.SetValue( 0 ); +#endif const float maxRange = 1000.0f; // 500 @@ -808,7 +810,7 @@ void CNavMesh::DrawEditMode( void ) if ( m_climbableSurface ) { - NDebugOverlay::Cross3D( m_editCursorPos, cursorSize, 0, 255, 0, true, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + NDebugOverlay::Cross3D( m_editCursorPos, cursorSize, 0, 255, 0, true, 0 ); } else { @@ -823,19 +825,19 @@ void CNavMesh::DrawEditMode( void ) pos = m_editCursorPos; AddDirectionVector( &pos, NORTH, offset ); - NDebugOverlay::Text( pos, "N", false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + NDebugOverlay::Text( pos, "N", false, 0 ); pos = m_editCursorPos; AddDirectionVector( &pos, SOUTH, offset ); - NDebugOverlay::Text( pos, "S", false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + NDebugOverlay::Text( pos, "S", false, 0 ); pos = m_editCursorPos; AddDirectionVector( &pos, EAST, offset ); - NDebugOverlay::Text( pos, "E", false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + NDebugOverlay::Text( pos, "E", false, 0 ); pos = m_editCursorPos; AddDirectionVector( &pos, WEST, offset ); - NDebugOverlay::Text( pos, "W", false, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + NDebugOverlay::Text( pos, "W", false, 0 ); } } @@ -908,7 +910,7 @@ void CNavMesh::DrawEditMode( void ) { V_snprintf( buffer, sizeof( buffer ), "Ladder #%d\n", m_selectedLadder->GetID() ); } - NDebugOverlay::ScreenText( 0.5, 0.53, buffer, 255, 255, 0, 128, nav_show_area_info.GetBool() ? 0.1 : 0.5 ); + NDebugOverlay::ScreenText( 0.5, 0.53, buffer, 255, 255, 0, 128, 0 ); } // draw the ladder we are pointing at and all connected areas @@ -1003,7 +1005,7 @@ void CNavMesh::DrawEditMode( void ) } Q_snprintf( buffer, sizeof( buffer ), "Area #%d %s %s\n", m_selectedArea->GetID(), locName, attrib ); - NDebugOverlay::ScreenText( 0.5, 0.53, buffer, 255, 255, 0, 128, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + NDebugOverlay::ScreenText( 0.5, 0.53, buffer, 255, 255, 0, 128, 0 ); // do "place painting" if ( m_isPlacePainting ) diff --git a/mp/src/game/server/nav_entities.cpp b/mp/src/game/server/nav_entities.cpp index c7abe838..0984a5dc 100644 --- a/mp/src/game/server/nav_entities.cpp +++ b/mp/src/game/server/nav_entities.cpp @@ -380,7 +380,7 @@ int CFuncNavBlocker::DrawDebugTextOverlays( void ) CNavArea *area = collector.m_area[i]; Extent areaExtent; area->GetExtent( &areaExtent ); - debugoverlay->AddBoxOverlay( vec3_origin, areaExtent.lo, areaExtent.hi, vec3_angle, 0, 255, 0, 10, NDEBUG_PERSIST_TILL_NEXT_SERVER ); + debugoverlay->AddBoxOverlay( vec3_origin, areaExtent.lo, areaExtent.hi, vec3_angle, 0, 255, 0, 10, 0 ); } } @@ -614,11 +614,11 @@ int CFuncNavObstruction::DrawDebugTextOverlays( void ) { if ( CanObstructNavAreas() ) { - EntityText( offset++, "Obstructing nav", NDEBUG_PERSIST_TILL_NEXT_SERVER ); + EntityText( offset++, "Obstructing nav", 0 ); } else { - EntityText( offset++, "Not obstructing nav", NDEBUG_PERSIST_TILL_NEXT_SERVER ); + EntityText( offset++, "Not obstructing nav", 0 ); } } diff --git a/mp/src/game/server/nav_mesh.cpp b/mp/src/game/server/nav_mesh.cpp index 095fabb0..1afc3b4c 100644 --- a/mp/src/game/server/nav_mesh.cpp +++ b/mp/src/game/server/nav_mesh.cpp @@ -21,13 +21,15 @@ #endif #include "functorutils.h" +#ifdef NEXT_BOT #include "NextBot/NavMeshEntities/func_nav_prerequisite.h" +#endif // NOTE: This has to be the last file included! #include "tier0/memdbgon.h" -#define DrawLine( from, to, duration, red, green, blue ) NDebugOverlay::Line( from, to, red, green, blue, true, 0.1f ) +#define DrawLine( from, to, duration, red, green, blue ) NDebugOverlay::Line( from, to, red, green, blue, true, 0 ) /** @@ -571,6 +573,7 @@ void CNavMesh::OnServerActivate( void ) //-------------------------------------------------------------------------------------------------------------- +#ifdef NEXT_BOT class CRegisterPrerequisite { public: @@ -587,6 +590,7 @@ public: CFuncNavPrerequisite *m_prereq; }; +#endif //-------------------------------------------------------------------------------------------------------------- /** @@ -609,6 +613,7 @@ void CNavMesh::OnRoundRestart( void ) { m_updateBlockedAreasTimer.Start( 1.0f ); +#ifdef NEXT_BOT FOR_EACH_VEC( TheNavAreas, pit ) { CNavArea *area = TheNavAreas[ pit ]; @@ -626,6 +631,7 @@ void CNavMesh::OnRoundRestart( void ) ForAllAreasOverlappingExtent( apply, prereqExtent ); } +#endif } @@ -1420,7 +1426,7 @@ void CNavMesh::DrawPlayerCounts( void ) const if (area->GetPlayerCount() > 0) { - NDebugOverlay::Text( area->GetCenter(), msg.sprintf( "%d (%d/%d)", area->GetPlayerCount(), area->GetPlayerCount(1), area->GetPlayerCount(2) ), false, 0.1f ); + NDebugOverlay::Text( area->GetCenter(), msg.sprintf( "%d (%d/%d)", area->GetPlayerCount(), area->GetPlayerCount(1), area->GetPlayerCount(2) ), false, 0 ); } } } diff --git a/mp/src/game/server/nav_mesh.vpc b/mp/src/game/server/nav_mesh.vpc new file mode 100644 index 00000000..898db4b6 --- /dev/null +++ b/mp/src/game/server/nav_mesh.vpc @@ -0,0 +1,44 @@ +//----------------------------------------------------------------------------- +// NAV_MESH.VPC +// +// Project script for navigation mesh files (no NextBot files), used by Source +// SDK HL2MP build +//----------------------------------------------------------------------------- + +$Configuration +{ + $Compiler + { + $PreprocessorDefinitions "$BASE;USE_NAV_MESH" + } +} + +$Project +{ + $Folder "Source Files" + { + $Folder "Nav Mesh" + { + $File "nav.h" + $File "nav_area.cpp" + $File "nav_area.h" + $File "nav_colors.cpp" + $File "nav_colors.h" + $File "nav_edit.cpp" + $File "nav_entities.cpp" + $File "nav_entities.h" + $File "nav_file.cpp" + $File "nav_generate.cpp" + $File "nav_ladder.cpp" + $File "nav_ladder.h" + $File "nav_merge.cpp" + $File "nav_mesh.cpp" + $File "nav_mesh.h" + $File "nav_mesh_factory.cpp" + $File "nav_node.cpp" + $File "nav_node.h" + $File "nav_pathfind.h" + $File "nav_simplify.cpp" + } + } +} \ No newline at end of file diff --git a/mp/src/game/server/server_hl2mp.vpc b/mp/src/game/server/server_hl2mp.vpc index 1dfbdbc2..e4002760 100644 --- a/mp/src/game/server/server_hl2mp.vpc +++ b/mp/src/game/server/server_hl2mp.vpc @@ -9,6 +9,7 @@ $Macro GAMENAME "hl2mp" [!$SOURCESDK] $Macro GAMENAME "mod_hl2mp" [$SOURCESDK] $Include "$SRCDIR\game\server\server_base.vpc" +$Include "$SRCDIR\game\server\nav_mesh.vpc" [$SOURCESDK] $Configuration {