Ticket #2908: pathfix.patch

File pathfix.patch, 13.0 KB (added by ickylevel, 10 years ago)
  • binaries/data/config/default.cfg

     
    137137view.scroll.speed = 120.0
    138138view.scroll.speed.modifier = 1.05           ; Multiplier for changing scroll speed
    139139view.rotate.x.speed = 1.2
    140 view.rotate.x.min = 28.0
    141 view.rotate.x.max = 60.0
    142 view.rotate.x.default = 35.0
     140view.rotate.x.min = 45.0
     141view.rotate.x.max = 45.0
     142view.rotate.x.default = 45.0
    143143view.rotate.y.speed = 2.0
    144144view.rotate.y.speed.wheel = 0.45
    145145view.rotate.y.default = 0.0
     
    147147view.drag.speed = 0.5
    148148view.zoom.speed = 256.0
    149149view.zoom.speed.wheel = 32.0
    150 view.zoom.min = 50.0
    151 view.zoom.max = 200.0
    152 view.zoom.default = 120.0
     150view.zoom.min = 125.0
     151view.zoom.max = 175.0
     152view.zoom.default = 150.0
    153153view.zoom.speed.modifier = 1.05             ; Multiplier for changing zoom speed
    154154view.pos.smoothness = 0.1
    155155view.zoom.smoothness = 0.4
     
    156156view.rotate.x.smoothness = 0.5
    157157view.rotate.y.smoothness = 0.3
    158158view.near = 2.0                             ; Near plane distance
    159 view.far = 4096.0                           ; Far plane distance
    160 view.fov = 45.0                             ; Field of view (degrees), lower is narrow, higher is wide
     159view.far = 2000.0                           ; Far plane distance
     160view.fov = 25.0                             ; Field of view (degrees), lower is narrow, higher is wide
    161161view.height.smoothness = 0.5
    162162view.height.min = 16
    163163
  • source/simulation2/components/CCmpObstructionManager.cpp

     
    431431        }
    432432    }
    433433
    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);
     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);
    435435    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);
    436436    virtual bool TestUnitShape(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, std::vector<entity_id_t>* out);
    437437
     
    536536
    537537REGISTER_COMPONENT_TYPE(ObstructionManager)
    538538
    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)
     539bool 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)
    540540{
    541541    PROFILE("TestLine");
    542542
     
    559559
    560560        CFixedVector2D center(it->second.x, it->second.z);
    561561        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;
    563565            return true;
     566        }
     567           
    564568    }
    565569
    566570    std::vector<entity_id_t> staticShapes;
  • source/simulation2/components/CCmpPathfinder.cpp

     
    583583    }
    584584}
    585585
     586
     587
    586588void CCmpPathfinder::ProcessShortRequests(const std::vector<AsyncShortPathRequest>& shortRequests)
    587589{
    588590    for (size_t i = 0; i < shortRequests.size(); ++i)
  • source/simulation2/components/CCmpPathfinder_Common.h

     
    260260
    261261    virtual CFixedVector2D GetNearestPointOnGoal(CFixedVector2D pos, const Goal& goal);
    262262
    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);
     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);
    264264
    265265    virtual ICmpObstruction::EFoundationCheck CheckUnitPlacement(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, pass_class_t passClass);
    266266
  • source/simulation2/components/CCmpPathfinder_Tile.cpp

     
    420420
    421421        // Hack to avoid spending ages computing giant paths, particularly when
    422422        // the destination is unreachable
    423         if (state.steps > 40000)
     423        if (state.steps > 10000)
    424424            break;
    425425
    426426        // If we ran out of tiles to examine, give up
  • source/simulation2/components/CCmpPathfinder_Vertex.cpp

     
    851851}
    852852
    853853bool CCmpPathfinder::CheckMovement(const IObstructionTestFilter& filter,
    854     entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, 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,
    855855    pass_class_t passClass)
    856856{
    857857    CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity());
  • source/simulation2/components/CCmpUnitMotion.cpp

     
    629629    ControlGroupMovementObstructionFilter GetObstructionFilter(bool forceAvoidMovingUnits = false);
    630630
    631631    /**
     632     * Returns an appropriate obstruction filter for use with path requests.
     633     */
     634    ControlGroupMovementObstructionFilter GetObstructionFilterNoAvoid();
     635
     636    /**
    632637     * Start moving to the given goal, from our current position 'from'.
    633638     * Might go in a straight line immediately, or might start an asynchronous
    634639     * path request.
     
    892897        fixed maxSpeed = basicSpeed.Multiply(terrainSpeed);
    893898
    894899        bool wasObstructed = false;
     900        bool wasObstructedTerrain = false;
    895901
    896902        // We want to move (at most) maxSpeed*dt units from pos towards the next waypoint
    897903
    898904        fixed timeLeft = dt;
    899905        fixed zero = fixed::Zero();
     906
     907        fixed targetX;
     908        fixed targetY;
     909
     910        fixed maxdist;
    900911       
    901912        while (timeLeft > zero)
    902913        {
     
    907918            CFixedVector2D target(m_ShortPath.m_Waypoints.back().x, m_ShortPath.m_Waypoints.back().z);
    908919            CFixedVector2D offset = target - pos;
    909920
     921           
     922
    910923            // Work out how far we can travel in timeLeft
    911             fixed maxdist = maxSpeed.Multiply(timeLeft);
     924            maxdist = maxSpeed.Multiply(timeLeft);
    912925
    913926            // If the target is close, we can move there directly
    914927            fixed offsetLength = offset.Length();
    915928            if (offsetLength <= maxdist)
    916929            {
    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))
    918933                {
    919934                    pos = target;
    920935
     
    927942                else
    928943                {
    929944                    // Error - path was obstructed
    930                     wasObstructed = true;
     945                    if (target.X != targetX || target.Y != targetY)
     946                        wasObstructed = true;
     947                    else
     948                        wasObstructedTerrain = true;
    931949                    break;
    932950                }
    933951            }
     
    936954                // Not close enough, so just move in the right direction
    937955                offset.Normalize(maxdist);
    938956                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))
    941960                {
    942961                    pos = target;
    943962                    break;
     
    945964                else
    946965                {
    947966                    // Error - path was obstructed
    948                     wasObstructed = true;
     967                    if (target.X != targetX || target.Y != targetY)
     968                        wasObstructed = true;
     969                    else
     970                        wasObstructedTerrain = true;
    949971                    break;
    950972                }
    951973            }
    952974        }
    953975
     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
     988            m_PathState = PATHSTATE_FOLLOWING_REQUESTING_SHORT;
     989            ICmpPathfinder::Path path;
     990            ICmpPathfinder::Goal goal(m_FinalGoal);
     991            ICmpPathfinder::Waypoint way;
     992            //if (m_LongPath.m_Waypoints.size() > 0)
     993            //  way = m_LongPath.m_Waypoints.back();
     994            //else
     995                way = m_ShortPath.m_Waypoints.front();
     996            goal.x = way.x;
     997            goal.z = way.z;
     998            cmpPathfinder->ComputeShortPath(GetObstructionFilter(), pos.X, pos.Y,
     999                m_Radius, SHORT_PATH_SEARCH_RANGE, goal , m_PassClass, path);
     1000            PathResult(m_ExpectedPathTicket,path);
     1001   
     1002
     1003            /*
     1004            CFixedVector2D diffHit(targetX - pos.X,targetY - pos.Y);
     1005            diffHit.Normalize();
     1006
     1007            fixed pdistance = diffHit.X.Multiply(diffHit.X) + diffHit.Y.Multiply(diffHit.Y)  ;
     1008            pdistance = pdistance.Sqrt();
     1009            diffHit.X = -diffHit.X;
     1010            diffHit.Y = -diffHit.Y;
     1011            maxdist  = maxdist - pdistance;
     1012            diffHit = diffHit.Multiply( maxdist ) + pos;
     1013            targetX = diffHit.X;
     1014            targetY = diffHit.Y;
     1015            if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, targetX, targetY, m_Radius, m_PassClass))
     1016            {
     1017                pos = diffHit;
     1018            }
     1019            */
     1020        }
     1021
     1022        if (wasObstructedTerrain)
     1023        {
     1024            m_CurSpeed = zero;
     1025            RequestLongPath(pos, m_FinalGoal);
     1026            m_PathState = PATHSTATE_WAITING_REQUESTING_LONG;
     1027        }
     1028
    9541029        // Update the Position component after our movement (if we actually moved anywhere)
    9551030        if (pos != initialPos)
    9561031        {
     
    9641039            m_CurSpeed = cmpPosition->GetDistanceTravelled() / dt;
    9651040        }
    9661041       
    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 
     1042       
    9811043        // We successfully moved along our path, until running out of
    9821044        // waypoints or time.
    9831045
     
    12291291    return ControlGroupMovementObstructionFilter(forceAvoidMovingUnits || ShouldAvoidMovingUnits(), group);
    12301292}
    12311293
     1294ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilterNoAvoid()
     1295{
     1296    entity_id_t group;
     1297    if (IsFormationMember())
     1298        group = m_TargetEntity;
     1299    else
     1300        group = GetEntityId();
    12321301
     1302    return ControlGroupMovementObstructionFilter(false, group);
     1303}
    12331304
     1305
     1306
    12341307void CCmpUnitMotion::BeginPathing(CFixedVector2D from, const ICmpPathfinder::Goal& goal)
    12351308{
    12361309    // Cancel any pending path requests
  • source/simulation2/components/ICmpObstructionManager.h

     
    171171     * @param r radius (half width) of line
    172172     * @return true if there is a collision
    173173     */
    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;
     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;
    175175
    176176    /**
    177177     * Collision test a static square shape against the current set of shapes.
  • source/simulation2/components/ICmpPathfinder.h

     
    148148     * or impassable terrain.
    149149     * Returns true if the movement is okay.
    150150     */
    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;
     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;
    152152
    153153    /**
    154154     * Check whether a unit placed here is valid and doesn't hit any obstructions