Add a simple 'pushing' logic to unit motion to improve movement.
This implements a form of crowd movement that I've generally called
'unit pushing' in the last few years.
Essentially, any two units will push each other away when they're too
close. This makes it possible to ignore unit-unit obstructions, and thus
makes movement much smoother in crowds.
This first iteration of this system only allows pushing between idle
units and between moving units (i.e. a moving unit does not affect an
idle one).
This is because the unitMotion logic to detect it is stuck & needs to
use the pathfinders starts breaking: units can fail to move because they
are pushed away from their intended movement, and the current logic
fails to handle this gracefully.
Thankfully, the most value of this patch in terms of player experience
is found in the improvements to group movements and shuttling.
Other impacts:
- As the short pathfinder is called less often, we can increase the
starting search range & reduce the # of max turns, both improving
collision recovery.
- The performance of idle units is slightly worsened, as they must be
checked for idle-idle collisions. If needed a 'sleeping' system, as used
in physics engine, could be implemented.
- In general, however, expect slight performance improvements, as fewer
short paths are computed.
- Gathering efficiency should increase slightly, since shuttling times
are likely reduced slightly.
- As a sanity change to improve some edge cases (units that say they're
moving, i.e. pushable, but don't actually move), the 'going straight'
logic is turned off if a short path has been computed. This requires a
few cascading changes to work correctly.
Technical notes:
- To reduce the cost of the n^2 comparisons that pushing requires, units
are only compared within a small square on a grid which is lazily
reconstructed each turn. The overhead seems rather small, and this is
much simpler than keeping an up-to-date grid.
- The design is intended to be parallelisable if needed someday.
- The pathfinder's CheckMovement ignores moving units in UnitMotion, as
that is now the spec. Idle units are not ignored, which is required for
the 'collision' detection to work correctly (see above).
Refs #3442 (not fixed - idle units are not pushed by moving units).
Fixes #5084 (the overlap can still happen, but units will push each
other away).
Differential Revision: https://code.wildfiregames.com/D1490
This was SVN commit r25182.
2021-04-02 09:30:59 -07:00
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2010-01-29 13:13:18 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-01-29 13:13:18 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-01-29 13:13:18 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-29 13:13:18 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "ICmpObstruction.h"
|
|
|
|
|
|
|
|
|
|
#include "simulation2/system/InterfaceScripted.h"
|
|
|
|
|
|
2013-02-23 16:12:41 -08:00
|
|
|
#include "simulation2/system/SimContext.h"
|
|
|
|
|
|
2017-01-19 18:25:19 -08:00
|
|
|
std::string ICmpObstruction::CheckFoundation_wrapper(const std::string& className, bool onlyCenterPoint) const
|
2013-02-23 16:12:41 -08:00
|
|
|
{
|
2013-07-07 15:44:47 -07:00
|
|
|
EFoundationCheck check = CheckFoundation(className, onlyCenterPoint);
|
2013-02-23 16:12:41 -08:00
|
|
|
|
|
|
|
|
switch (check)
|
|
|
|
|
{
|
|
|
|
|
case FOUNDATION_CHECK_SUCCESS:
|
|
|
|
|
return "success";
|
|
|
|
|
case FOUNDATION_CHECK_FAIL_ERROR:
|
|
|
|
|
return "fail_error";
|
|
|
|
|
case FOUNDATION_CHECK_FAIL_NO_OBSTRUCTION:
|
|
|
|
|
return "fail_no_obstruction";
|
|
|
|
|
case FOUNDATION_CHECK_FAIL_OBSTRUCTS_FOUNDATION:
|
|
|
|
|
return "fail_obstructs_foundation";
|
|
|
|
|
case FOUNDATION_CHECK_FAIL_TERRAIN_CLASS:
|
|
|
|
|
return "fail_terrain_class";
|
|
|
|
|
default:
|
|
|
|
|
debug_warn(L"Unexpected result from CheckFoundation");
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-29 13:13:18 -08:00
|
|
|
BEGIN_INTERFACE_WRAPPER(Obstruction)
|
2021-05-01 01:01:30 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("GetSize", ICmpObstruction, GetSize)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("CheckShorePlacement", ICmpObstruction, CheckShorePlacement)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("CheckFoundation", ICmpObstruction, CheckFoundation_wrapper)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("CheckDuplicateFoundation", ICmpObstruction, CheckDuplicateFoundation)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetEntitiesBlockingMovement", ICmpObstruction, GetEntitiesBlockingMovement)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetEntitiesBlockingConstruction", ICmpObstruction, GetEntitiesBlockingConstruction)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetEntitiesDeletedUponConstruction", ICmpObstruction, GetEntitiesDeletedUponConstruction)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("SetActive", ICmpObstruction, SetActive)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("SetDisableBlockMovementPathfinding", ICmpObstruction, SetDisableBlockMovementPathfinding)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetBlockMovementFlag", ICmpObstruction, GetBlockMovementFlag)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("SetControlGroup", ICmpObstruction, SetControlGroup)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetControlGroup", ICmpObstruction, GetControlGroup)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("SetControlGroup2", ICmpObstruction, SetControlGroup2)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetControlGroup2", ICmpObstruction, GetControlGroup2)
|
2010-01-29 13:13:18 -08:00
|
|
|
END_INTERFACE_WRAPPER(Obstruction)
|