1
0
forked from 0ad/0ad

Refactor GetEntityCollisions to make it clear what the function actually does since the new pathfinder

This was SVN commit r17992.
This commit is contained in:
sanderd17 2016-04-06 17:36:47 +00:00
parent 9aa829d034
commit 6471a54c9f
5 changed files with 9 additions and 27 deletions

View File

@ -167,7 +167,7 @@ Foundation.prototype.Build = function(builderEnt, work)
var cmpObstruction = Engine.QueryInterface(this.entity, IID_Obstruction);
if (cmpObstruction && cmpObstruction.GetBlockMovementFlag())
{
var collisions = cmpObstruction.GetEntityCollisions(true, true);
var collisions = cmpObstruction.GetUnitCollisions();
if (collisions.length)
{
var cmpFoundationOwnership = Engine.QueryInterface(this.entity, IID_Ownership);

View File

@ -219,7 +219,7 @@ Gate.prototype.CloseGate = function()
return;
// The gate can't be closed if there are entities colliding with it.
var collisions = cmpObstruction.GetEntityCollisions(false, true);
var collisions = cmpObstruction.GetUnitCollisions();
if (collisions.length)
{
if (!this.timer)

View File

@ -597,7 +597,7 @@ public:
return !cmpObstructionManager->TestStaticShape(filter, pos.X, pos.Y, cmpPosition->GetRotation().Y, m_Size0, m_Size1, NULL );
}
virtual std::vector<entity_id_t> GetEntityCollisions(bool checkStructures, bool checkUnits)
virtual std::vector<entity_id_t> GetUnitCollisions()
{
std::vector<entity_id_t> ret;
@ -605,32 +605,15 @@ public:
if (!cmpObstructionManager)
return ret; // error
flags_t flags = 0;
bool invertMatch = false;
// There are four 'block' flags: construction, foundation, movement,
// and pathfinding. Structures have all of these flags, while units
// block only movement and construction.
// The 'block construction' flag is common to both units and structures.
if (checkStructures && checkUnits)
flags = ICmpObstructionManager::FLAG_BLOCK_CONSTRUCTION;
// The 'block foundation' flag is exclusive to structures.
else if (checkStructures)
flags = ICmpObstructionManager::FLAG_BLOCK_FOUNDATION;
else if (checkUnits)
{
// As structures block a superset of what units do, matching units
// but not structures means excluding entities that contain any of
// the structure-specific flags (foundation and pathfinding).
invertMatch = true;
flags = ICmpObstructionManager::FLAG_BLOCK_FOUNDATION | ICmpObstructionManager::FLAG_BLOCK_PATHFINDING;
}
flags_t flags = ICmpObstructionManager::FLAG_BLOCK_CONSTRUCTION;
// Ignore collisions within the same control group, or with other shapes that don't match the filter.
// Note that, since the control group for each entity defaults to the entity's ID, this is typically
// equivalent to only ignoring the entity's own shape and other shapes that don't match the filter.
SkipControlGroupsRequireFlagObstructionFilter filter(invertMatch, m_ControlGroup, m_ControlGroup2, flags);
SkipControlGroupsRequireFlagObstructionFilter filter(false, m_ControlGroup, m_ControlGroup2, flags);
ICmpObstructionManager::ObstructionSquare square;
if (!GetObstructionSquare(square))

View File

@ -49,7 +49,7 @@ BEGIN_INTERFACE_WRAPPER(Obstruction)
DEFINE_INTERFACE_METHOD_0("GetUnitRadius", entity_pos_t, ICmpObstruction, GetUnitRadius)
DEFINE_INTERFACE_METHOD_2("CheckFoundation", std::string, ICmpObstruction, CheckFoundation_wrapper, std::string, bool)
DEFINE_INTERFACE_METHOD_0("CheckDuplicateFoundation", bool, ICmpObstruction, CheckDuplicateFoundation)
DEFINE_INTERFACE_METHOD_2("GetEntityCollisions", std::vector<entity_id_t>, ICmpObstruction, GetEntityCollisions, bool, bool)
DEFINE_INTERFACE_METHOD_0("GetUnitCollisions", std::vector<entity_id_t>, ICmpObstruction, GetUnitCollisions)
DEFINE_INTERFACE_METHOD_1("SetActive", void, ICmpObstruction, SetActive, bool)
DEFINE_INTERFACE_METHOD_3("SetDisableBlockMovementPathfinding", void, ICmpObstruction, SetDisableBlockMovementPathfinding, bool, bool, int32_t)
DEFINE_INTERFACE_METHOD_0("GetBlockMovementFlag", bool, ICmpObstruction, GetBlockMovementFlag)

View File

@ -84,11 +84,10 @@ public:
virtual bool CheckDuplicateFoundation() = 0;
/**
* Returns a list of entities that are colliding with this entity,
* filtered depending on type of entities that are requested.
* @return vector of blocking entities
* Returns a list of units that are colliding with this entity,
* @return vector of blocking units
*/
virtual std::vector<entity_id_t> GetEntityCollisions(bool checkStructures, bool checkUnits) = 0;
virtual std::vector<entity_id_t> GetUnitCollisions() = 0;
/**
* Detects collisions between foundation-blocking entities and