Ticket #3410: revert_16998.patch

File revert_16998.patch, 13.3 KB (added by elexis, 9 years ago)

Patch by wraitii.

  • source/simulation2/MessageTypes.h

     
    538538    }
    539539};
    540540
    541 /**
    542  * Sent when the pathfinder's passability map is modified on update
    543  */
    544 class CMessagePassabilityMapChanged : public CMessage
    545 {
    546 public:
    547     DEFAULT_MESSAGE_IMPL(PassabilityMapChanged)
    548 
    549     CMessagePassabilityMapChanged()
    550     {
    551     }
    552 };
    553 
    554541#endif // INCLUDED_MESSAGETYPES
  • source/simulation2/TypeList.h

     
    5757MESSAGE(TemplateModification)
    5858MESSAGE(VisionRangeChanged)
    5959MESSAGE(MinimapPing)
    60 MESSAGE(PassabilityMapChanged)
    6160
    6261// TemplateManager must come before all other (non-test) components,
    6362// so that it is the first to be (de)serialized
  • source/simulation2/components/CCmpUnitMotion.cpp

     
    135135        componentManager.SubscribeToMessageType(MT_PathResult);
    136136        componentManager.SubscribeToMessageType(MT_ValueModification);
    137137        componentManager.SubscribeToMessageType(MT_Deserialized);
    138         componentManager.SubscribeToMessageType(MT_PassabilityMapChanged);
    139138    }
    140139
    141140    DEFAULT_COMPONENT_ALLOCATOR(UnitMotion)
     
    255254    WaypointPath m_LongPath;
    256255    WaypointPath m_ShortPath;
    257256
    258     // When the passability map has changed, we cannot fully trust the path computed by the
    259     // pathfinder before that change.
    260     bool m_PassabilityMapChangedRecently;
    261 
    262257    // Motion planning
    263258    SUnitMotionPlanning m_Planning;
    264259
     
    331326
    332327        m_ExpectedPathTicket = 0;
    333328
    334         m_PassabilityMapChangedRecently = false;
    335 
    336329        m_TargetEntity = INVALID_ENTITY;
    337330
    338331        m_FinalGoal.type = PathGoal::POINT;
     
    369362
    370363        SerializeVector<SerializeWaypoint>()(serialize, "long path", m_LongPath.m_Waypoints);
    371364        SerializeVector<SerializeWaypoint>()(serialize, "short path", m_ShortPath.m_Waypoints);
    372         serialize.Bool("passability map changed recently", m_PassabilityMapChangedRecently);
    373365
    374366        SerializeUnitMotionPlanning()(serialize, "planning", m_Planning);
    375367
     
    453445            m_RunSpeed = newRunSpeed;
    454446            break;
    455447        }
    456         case MT_PassabilityMapChanged:
    457             m_PassabilityMapChangedRecently = true;
    458             break;
    459448        }
    460449    }
    461450
     
    668657    /**
    669658     * Returns an appropriate obstruction filter for use with path requests.
    670659     */
    671     ControlGroupMovementObstructionFilter GetObstructionFilter(bool avoidPathfindingShapes) const;
     660    ControlGroupMovementObstructionFilter GetObstructionFilter(bool forceAvoidMovingUnits = false) const;
    672661
    673662    /**
    674      * Checks our movement towards the next path waypoint.
    675      * Pathfinding-blocking shapes are assumed to be taken into account during the path computation
    676      * and this will only be used to avoid moving units.
    677      */
    678     bool CheckMovement(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1) const;
    679 
    680     /**
    681663     * Start moving to the given goal, from our current position 'from'.
    682664     * Might go in a straight line immediately, or might start an asynchronous
    683665     * path request.
     
    735717
    736718    if (m_PathState == PATHSTATE_WAITING_REQUESTING_LONG || m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG)
    737719    {
    738         m_PassabilityMapChangedRecently = false;
    739 
    740720        m_LongPath = path;
    741721
    742722        // If we are following a path, leave the old m_ShortPath so we can carry on following it
     
    852832        // Maybe we should split the updates into multiple phases to minimise
    853833        // that problem.
    854834
     835        CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity());
     836        if (!cmpPathfinder)
     837            return;
     838
    855839        CmpPtr<ICmpPosition> cmpPosition(GetEntityHandle());
    856840        if (!cmpPosition || !cmpPosition->IsInWorld())
    857841            return;
     
    911895            fixed offsetLength = offset.Length();
    912896            if (offsetLength <= maxdist)
    913897            {
    914                 if (CheckMovement(pos.X, pos.Y, target.X, target.Y))
     898                if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, target.X, target.Y, m_Clearance, m_PassClass))
    915899                {
    916900                    pos = target;
    917901
     
    941925                offset.Normalize(maxdist);
    942926                target = pos + offset;
    943927
    944                 if (CheckMovement(pos.X, pos.Y, target.X, target.Y))
     928                if (cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, target.X, target.Y, m_Clearance, m_PassClass))
    945929                {
    946930                    pos = target;
    947931                    break;
     
    970954       
    971955        if (wasObstructed)
    972956        {
    973             // Oops, we hit something (very likely another unit, or a new obstruction).
     957            // Oops, we hit something (very likely another unit).
    974958            // Stop, and recompute the whole path.
    975959            // TODO: if the target has UnitMotion and is higher priority,
    976960            // we should wait a little bit.
    977961
    978962            // Recompute our path
    979             // If we are following a long path and it is still valid
    980             if (!m_LongPath.m_Waypoints.empty() && !m_PassabilityMapChangedRecently)
     963            // If we are following a long path
     964            if (!m_LongPath.m_Waypoints.empty())
    981965            {
    982966                PathGoal goal = { PathGoal::POINT, m_LongPath.m_Waypoints.back().x, m_LongPath.m_Waypoints.back().z };
    983967                RequestShortPath(pos, goal, true);
     
    10501034    if (m_LongPath.m_Waypoints.empty())
    10511035        return;
    10521036
     1037    CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity());
    10531038
    10541039    const Waypoint& nextPoint = m_LongPath.m_Waypoints.back();
    10551040
    10561041    // The next step was obstructed the last time we checked; also check that
    10571042    // the step is still obstructed (maybe the units in our way moved in the meantime)
    1058     if (!m_Planning.nextStepClean && CheckMovement(pos.X, pos.Y, nextPoint.x, nextPoint.z))
     1043    if (!m_Planning.nextStepClean &&
     1044        !cmpPathfinder->CheckMovement(GetObstructionFilter(), pos.X, pos.Y, nextPoint.x, nextPoint.z, m_Clearance, m_PassClass))
    10591045    {
    10601046        // If the short path computation is over, use it, else just forget about it
    10611047        if (!m_Planning.nextStepShortPath.m_Waypoints.empty())
     
    10711057        return;
    10721058
    10731059    const Waypoint& followingPoint = m_LongPath.m_Waypoints.rbegin()[1]; // penultimate element
    1074     m_Planning.nextStepClean = CheckMovement(nextPoint.x, nextPoint.z, followingPoint.x, followingPoint.z);
     1060    m_Planning.nextStepClean = cmpPathfinder->CheckMovement(
     1061        GetObstructionFilter(), nextPoint.x, nextPoint.z, followingPoint.x, followingPoint.z, m_Clearance, m_PassClass);
    10751062    if (!m_Planning.nextStepClean)
    10761063    {
    1077         CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity());
    1078         if (!cmpPathfinder)
    1079             return;
    1080 
    10811064        PathGoal goal = { PathGoal::POINT, followingPoint.x, followingPoint.z };
    10821065        m_Planning.expectedPathTicket = cmpPathfinder->ComputeShortPathAsync(
    10831066            nextPoint.x, nextPoint.z, m_Clearance, SHORT_PATH_SEARCH_RANGE, goal, m_PassClass, false, m_TargetEntity, GetEntityId());
     
    11241107        return false;
    11251108
    11261109    // Check if there's any collisions on that route
    1127     if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))
     1110    if (!cmpPathfinder->CheckMovement(GetObstructionFilter(), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))
    11281111        return false;
    11291112
    11301113    // That route is okay, so update our path
     
    11601143    CFixedVector2D goalPos = goal.NearestPointOnGoal(from);
    11611144
    11621145    // Check if there's any collisions on that route
    1163     if (!cmpPathfinder->CheckMovement(GetObstructionFilter(true), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))
     1146    if (!cmpPathfinder->CheckMovement(GetObstructionFilter(), from.X, from.Y, goalPos.X, goalPos.Y, m_Clearance, m_PassClass))
    11641147        return false;
    11651148
    11661149    // That route is okay, so update our path
     
    12681251    }
    12691252}
    12701253
    1271 ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilter(bool avoidPathfindingShapes) const
     1254ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilter(bool forceAvoidMovingUnits) const
    12721255{
    12731256    entity_id_t group;
    12741257    if (IsFormationMember())
     
    12761259    else
    12771260        group = GetEntityId();
    12781261
    1279     return ControlGroupMovementObstructionFilter(avoidPathfindingShapes, ShouldAvoidMovingUnits(), group);
     1262    return ControlGroupMovementObstructionFilter(forceAvoidMovingUnits || ShouldAvoidMovingUnits(), group);
    12801263}
    12811264
    1282 bool CCmpUnitMotion::CheckMovement(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1) const
    1283 {
    1284     // If the passability map has changed, we have to check everything in our way until we compute a new path.
    1285     if (m_PassabilityMapChangedRecently)
    1286     {
    1287         CmpPtr<ICmpPathfinder> cmpPathfinder(GetSystemEntity());
    1288         return cmpPathfinder && cmpPathfinder->CheckMovement(GetObstructionFilter(true), x0, z0, x1, z1, m_Clearance, m_PassClass);
    1289     }
    12901265
    1291     // If an obstruction blocks tile-based pathfinding, it will be handled during the path computation
    1292     // and doesn't need to be matched by this filter for the movement.
    1293     ControlGroupMovementObstructionFilter filter = GetObstructionFilter(false);
    12941266
    1295     CmpPtr<ICmpObstructionManager> cmpObstructionManager(GetSystemEntity());
    1296     return cmpObstructionManager && !cmpObstructionManager->TestLine(filter, x0, z0, x1, z1, m_Clearance);
    1297 }
    1298 
    1299 
    13001267void CCmpUnitMotion::BeginPathing(const CFixedVector2D& from, const PathGoal& goal)
    13011268{
    13021269    // Cancel any pending path requests
     
    13101277    if (cmpObstruction)
    13111278        cmpObstruction->SetMovingFlag(true);
    13121279
    1313     // We are going to recompute our path, so we will use the most recent passability grid
    1314     m_PassabilityMapChangedRecently = false;
    1315 
    13161280#if DISABLE_PATHFINDER
    13171281    {
    13181282        CmpPtr<ICmpPathfinder> cmpPathfinder (GetSimContext(), SYSTEM_ENTITY);
  • source/simulation2/components/ICmpObstructionManager.h

     
    323323 */
    324324class ControlGroupMovementObstructionFilter : public IObstructionTestFilter
    325325{
    326     bool m_AvoidPathfindingShapes;
    327326    bool m_AvoidMoving;
    328327    entity_id_t m_Group;
    329328
    330329public:
    331     ControlGroupMovementObstructionFilter(bool avoidPathfindingShapes, bool avoidMoving, entity_id_t group) :
    332         m_AvoidPathfindingShapes(avoidPathfindingShapes), m_AvoidMoving(avoidMoving), m_Group(group)
     330    ControlGroupMovementObstructionFilter(bool avoidMoving, entity_id_t group) :
     331        m_AvoidMoving(avoidMoving), m_Group(group)
    333332    {}
    334333
    335334    virtual bool TestShape(tag_t UNUSED(tag), flags_t flags, entity_id_t group, entity_id_t group2) const
     
    337336        if (group == m_Group || (group2 != INVALID_ENTITY && group2 == m_Group))
    338337            return false;
    339338
    340         if ((flags & ICmpObstructionManager::FLAG_BLOCK_PATHFINDING) && !m_AvoidPathfindingShapes)
    341             return false;
    342 
    343339        if (!(flags & ICmpObstructionManager::FLAG_BLOCK_MOVEMENT))
    344340            return false;
    345341
  • source/simulation2/components/CCmpPathfinder.cpp

     
    522522    }
    523523    else
    524524        m_LongPathfinder.Update(m_Grid, m_ObstructionsDirty.dirtinessGrid);
    525 
    526     // Notify the units that their current paths can be invalid now.
    527     // The passability map will be globally dirty after init, or rejoining, loading a saved game, etc.
    528     // In those situations the paths can't be invalid.
    529     if (!m_ObstructionsDirty.globallyDirty)
    530     {
    531         CMessagePassabilityMapChanged msg;
    532         GetSimContext().GetComponentManager().BroadcastMessage(msg);
    533525    }
    534 }
    535526
    536527void CCmpPathfinder::MinimalTerrainUpdate()
    537528{
     
    727718    {
    728719        const AsyncShortPathRequest& req = shortRequests[i];
    729720        WaypointPath path;
    730         ControlGroupMovementObstructionFilter filter(true, req.avoidMovingUnits, req.group);
     721        ControlGroupMovementObstructionFilter filter(req.avoidMovingUnits, req.group);
    731722        ComputeShortPath(filter, req.x0, req.z0, req.clearance, req.range, req.goal, req.passClass, path);
    732723        CMessagePathResult msg(req.ticket, path);
    733724        GetSimContext().GetComponentManager().PostMessage(req.notify, msg);
  • source/simulation2/scripting/MessageTypeConversions.cpp

     
    1 /* Copyright (C) 2015 Wildfire Games.
     1/* Copyright (C) 2014 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    470470    return new CMessageMinimapPing();
    471471}
    472472
    473 ////////////////////////////////
    474 
    475 JS::Value CMessagePassabilityMapChanged::ToJSVal(ScriptInterface& scriptInterface) const
    476 {
    477     TOJSVAL_SETUP();
    478     return JS::ObjectValue(*obj);
    479 }
    480 
    481 CMessage* CMessagePassabilityMapChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), JS::HandleValue UNUSED(val))
    482 {
    483     return new CMessagePassabilityMapChanged();
    484 }
    485 
    486473////////////////////////////////////////////////////////////////
    487474
    488475CMessage* CMessageFromJSVal(int mtid, ScriptInterface& scriptingInterface, JS::HandleValue val)