Ticket #2908: pathfix_async.patch
File pathfix_async.patch, 13.2 KB (added by , 10 years ago) |
---|
-
binaries/data/config/default.cfg
137 137 view.scroll.speed = 120.0 138 138 view.scroll.speed.modifier = 1.05 ; Multiplier for changing scroll speed 139 139 view.rotate.x.speed = 1.2 140 view.rotate.x.min = 28.0141 view.rotate.x.max = 60.0142 view.rotate.x.default = 35.0140 view.rotate.x.min = 45.0 141 view.rotate.x.max = 45.0 142 view.rotate.x.default = 45.0 143 143 view.rotate.y.speed = 2.0 144 144 view.rotate.y.speed.wheel = 0.45 145 145 view.rotate.y.default = 0.0 … … 147 147 view.drag.speed = 0.5 148 148 view.zoom.speed = 256.0 149 149 view.zoom.speed.wheel = 32.0 150 view.zoom.min = 50.0151 view.zoom.max = 200.0152 view.zoom.default = 1 20.0150 view.zoom.min = 125.0 151 view.zoom.max = 175.0 152 view.zoom.default = 150.0 153 153 view.zoom.speed.modifier = 1.05 ; Multiplier for changing zoom speed 154 154 view.pos.smoothness = 0.1 155 155 view.zoom.smoothness = 0.4 … … 156 156 view.rotate.x.smoothness = 0.5 157 157 view.rotate.y.smoothness = 0.3 158 158 view.near = 2.0 ; Near plane distance 159 view.far = 4096.0 ; Far plane distance160 view.fov = 45.0 ; Field of view (degrees), lower is narrow, higher is wide159 view.far = 2000.0 ; Far plane distance 160 view.fov = 25.0 ; Field of view (degrees), lower is narrow, higher is wide 161 161 view.height.smoothness = 0.5 162 162 view.height.min = 16 163 163 -
source/simulation2/components/CCmpObstructionManager.cpp
431 431 } 432 432 } 433 433 434 virtual bool TestLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_tz1, entity_pos_t r);434 virtual bool TestLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t &x1, entity_pos_t &z1, entity_pos_t r); 435 435 virtual bool TestStaticShape(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, std::vector<entity_id_t>* out); 436 436 virtual bool TestUnitShape(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, std::vector<entity_id_t>* out); 437 437 … … 536 536 537 537 REGISTER_COMPONENT_TYPE(ObstructionManager) 538 538 539 bool CCmpObstructionManager::TestLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_tz1, entity_pos_t r)539 bool CCmpObstructionManager::TestLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t &x1, entity_pos_t &z1, entity_pos_t r) 540 540 { 541 541 PROFILE("TestLine"); 542 542 … … 559 559 560 560 CFixedVector2D center(it->second.x, it->second.z); 561 561 CFixedVector2D halfSize(it->second.r + r, it->second.r + r); 562 if (Geometry::TestRayAASquare(CFixedVector2D(x0, z0) - center, CFixedVector2D(x1, z1) - center, halfSize)) 562 if (Geometry::TestRayAASquare(CFixedVector2D(x0, z0) - center, CFixedVector2D(x1, z1) - center, halfSize)) { 563 x1 = center.X; 564 z1 = center.Y; 563 565 return true; 566 } 567 564 568 } 565 569 566 570 std::vector<entity_id_t> staticShapes; -
source/simulation2/components/CCmpPathfinder.cpp
583 583 } 584 584 } 585 585 586 587 586 588 void CCmpPathfinder::ProcessShortRequests(const std::vector<AsyncShortPathRequest>& shortRequests) 587 589 { 588 590 for (size_t i = 0; i < shortRequests.size(); ++i) -
source/simulation2/components/CCmpPathfinder_Common.h
260 260 261 261 virtual CFixedVector2D GetNearestPointOnGoal(CFixedVector2D pos, const Goal& goal); 262 262 263 virtual bool CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_tz1, entity_pos_t r, pass_class_t passClass);263 virtual bool CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t &x1, entity_pos_t &z1, entity_pos_t r, pass_class_t passClass); 264 264 265 265 virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass); 266 266 -
source/simulation2/components/CCmpPathfinder_Tile.cpp
420 420 421 421 // Hack to avoid spending ages computing giant paths, particularly when 422 422 // the destination is unreachable 423 if (state.steps > 40000)423 if (state.steps > 10000) 424 424 break; 425 425 426 426 // If we ran out of tiles to examine, give up -
source/simulation2/components/CCmpPathfinder_Vertex.cpp
851 851 } 852 852 853 853 bool CCmpPathfinder::CheckMovement(const IObstructionTestFilter& filter, 854 entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_tz1, entity_pos_t r,854 entity_pos_t x0, entity_pos_t z0, entity_pos_t &x1, entity_pos_t &z1, entity_pos_t r, 855 855 pass_class_t passClass) 856 856 { 857 857 CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity()); -
source/simulation2/components/CCmpUnitMotion.cpp
629 629 ControlGroupMovementObstructionFilter GetObstructionFilter(bool forceAvoidMovingUnits = false); 630 630 631 631 /** 632 * Returns an appropriate obstruction filter for use with path requests. 633 */ 634 ControlGroupMovementObstructionFilter GetObstructionFilterNoAvoid(); 635 636 /** 632 637 * Start moving to the given goal, from our current position 'from'. 633 638 * Might go in a straight line immediately, or might start an asynchronous 634 639 * path request. … … 892 897 fixed maxSpeed = basicSpeed.Multiply(terrainSpeed); 893 898 894 899 bool wasObstructed = false; 900 bool wasObstructedTerrain = false; 895 901 896 902 // We want to move (at most) maxSpeed*dt units from pos towards the next waypoint 897 903 898 904 fixed timeLeft = dt; 899 905 fixed zero = fixed::Zero(); 906 907 fixed targetX; 908 fixed targetY; 909 910 fixed maxdist; 900 911 901 912 while (timeLeft > zero) 902 913 { … … 907 918 CFixedVector2D target(m_ShortPath.m_Waypoints.back().x, m_ShortPath.m_Waypoints.back().z); 908 919 CFixedVector2D offset = target - pos; 909 920 921 922 910 923 // Work out how far we can travel in timeLeft 911 fixedmaxdist = maxSpeed.Multiply(timeLeft);924 maxdist = maxSpeed.Multiply(timeLeft); 912 925 913 926 // If the target is close, we can move there directly 914 927 fixed offsetLength = offset.Length(); 915 928 if (offsetLength <= maxdist) 916 929 { 917 if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, target.X, target.Y, m_Radius, m_PassClass)) 930 targetX = target.X; 931 targetY = target.Y; 932 if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, targetX, targetY, m_Radius, m_PassClass)) 918 933 { 919 934 pos = target; 920 935 … … 927 942 else 928 943 { 929 944 // Error - path was obstructed 930 wasObstructed = true; 945 if (target.X != targetX || target.Y != targetY) 946 wasObstructed = true; 947 else 948 wasObstructedTerrain = true; 931 949 break; 932 950 } 933 951 } … … 936 954 // Not close enough, so just move in the right direction 937 955 offset.Normalize(maxdist); 938 956 target = pos + offset; 939 940 if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, target.X, target.Y, m_Radius, m_PassClass)) 957 targetX = target.X; 958 targetY = target.Y; 959 if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, targetX, targetY, m_Radius, m_PassClass)) 941 960 { 942 961 pos = target; 943 962 break; … … 945 964 else 946 965 { 947 966 // Error - path was obstructed 948 wasObstructed = true; 967 if (target.X != targetX || target.Y != targetY) 968 wasObstructed = true; 969 else 970 wasObstructedTerrain = true; 949 971 break; 950 972 } 951 973 } 952 974 } 953 975 976 if (wasObstructed) 977 { 978 // Oops, we hit something (not terrain). 979 // const AsyncLongPathRequest& req = longRequests[i]; 980 981 /* 982 ICmpPathfinder::Path pathf; 983 m_PathState = PATHSTATE_WAITING_REQUESTING_LONG; 984 cmpPathfinder->ComputePath(pos.X, pos.Y, m_FinalGoal, m_PassClass, m_CostClass, pathf); 985 PathResult(m_ExpectedPathTicket,pathf); 986 */ 987 ICmpPathfinder::Goal goal(m_FinalGoal); 988 ICmpPathfinder::Waypoint way; 989 way = m_ShortPath.m_Waypoints.front(); 990 goal.x = way.x; 991 goal.z = way.z; 992 m_PathState = PATHSTATE_WAITING_REQUESTING_SHORT; 993 RequestShortPath(pos, goal,true); 994 995 /* 996 m_PathState = PATHSTATE_FOLLOWING_REQUESTING_SHORT; 997 ICmpPathfinder::Path path; 998 ICmpPathfinder::Goal goal(m_FinalGoal); 999 ICmpPathfinder::Waypoint way; 1000 //if (m_LongPath.m_Waypoints.size() > 0) 1001 // way = m_LongPath.m_Waypoints.back(); 1002 //else 1003 way = m_ShortPath.m_Waypoints.front(); 1004 goal.x = way.x; 1005 goal.z = way.z; 1006 cmpPathfinder->ComputeShortPath(GetObstructionFilter(), pos.X, pos.Y, 1007 m_Radius, SHORT_PATH_SEARCH_RANGE, goal , m_PassClass, path); 1008 PathResult(m_ExpectedPathTicket,path); 1009 */ 1010 1011 /* 1012 CFixedVector2D diffHit(targetX - pos.X,targetY - pos.Y); 1013 diffHit.Normalize(); 1014 1015 fixed pdistance = diffHit.X.Multiply(diffHit.X) + diffHit.Y.Multiply(diffHit.Y) ; 1016 pdistance = pdistance.Sqrt(); 1017 diffHit.X = -diffHit.X; 1018 diffHit.Y = -diffHit.Y; 1019 maxdist = maxdist - pdistance; 1020 diffHit = diffHit.Multiply( maxdist ) + pos; 1021 targetX = diffHit.X; 1022 targetY = diffHit.Y; 1023 if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, targetX, targetY, m_Radius, m_PassClass)) 1024 { 1025 pos = diffHit; 1026 } 1027 */ 1028 } 1029 1030 if (wasObstructedTerrain) 1031 { 1032 m_CurSpeed = zero; 1033 RequestLongPath(pos, m_FinalGoal); 1034 m_PathState = PATHSTATE_WAITING_REQUESTING_LONG; 1035 } 1036 954 1037 // Update the Position component after our movement (if we actually moved anywhere) 955 1038 if (pos != initialPos) 956 1039 { … … 964 1047 m_CurSpeed = cmpPosition->GetDistanceTravelled() / dt; 965 1048 } 966 1049 967 if (wasObstructed) 968 { 969 // Oops, we hit something (very likely another unit). 970 // Stop, and recompute the whole path. 971 // TODO: if the target has UnitMotion and is higher priority, 972 // we should wait a little bit. 973 974 m_CurSpeed = zero; 975 RequestLongPath(pos, m_FinalGoal); 976 m_PathState = PATHSTATE_WAITING_REQUESTING_LONG; 977 978 return; 979 } 980 1050 981 1051 // We successfully moved along our path, until running out of 982 1052 // waypoints or time. 983 1053 … … 1229 1299 return ControlGroupMovementObstructionFilter(forceAvoidMovingUnits || ShouldAvoidMovingUnits(), group); 1230 1300 } 1231 1301 1302 ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilterNoAvoid() 1303 { 1304 entity_id_t group; 1305 if (IsFormationMember()) 1306 group = m_TargetEntity; 1307 else 1308 group = GetEntityId(); 1232 1309 1310 return ControlGroupMovementObstructionFilter(false, group); 1311 } 1233 1312 1313 1314 1234 1315 void CCmpUnitMotion::BeginPathing(CFixedVector2D from, const ICmpPathfinder::Goal& goal) 1235 1316 { 1236 1317 // Cancel any pending path requests -
source/simulation2/components/ICmpObstructionManager.h
171 171 * @param r radius (half width) of line 172 172 * @return true if there is a collision 173 173 */ 174 virtual bool TestLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_tz1, entity_pos_t r) = 0;174 virtual bool TestLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t &x1, entity_pos_t &z1, entity_pos_t r) = 0; 175 175 176 176 /** 177 177 * Collision test a static square shape against the current set of shapes. -
source/simulation2/components/ICmpPathfinder.h
148 148 * or impassable terrain. 149 149 * Returns true if the movement is okay. 150 150 */ 151 virtual bool CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_tz1, entity_pos_t r, pass_class_t passClass) = 0;151 virtual bool CheckMovement(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t &x1, entity_pos_t &z1, entity_pos_t r, pass_class_t passClass) = 0; 152 152 153 153 /** 154 154 * Check whether a unit placed here is valid and doesn't hit any obstructions