Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpObstructionManager.cpp
Show First 20 Lines • Show All 474 Lines • ▼ Show 20 Lines | public: | ||||
virtual fixed DistanceBetweenShapes(const ObstructionSquare& source, const ObstructionSquare& target) const; | virtual fixed DistanceBetweenShapes(const ObstructionSquare& source, const ObstructionSquare& target) const; | ||||
virtual fixed MaxDistanceBetweenShapes(const ObstructionSquare& source, const ObstructionSquare& target) const; | virtual fixed MaxDistanceBetweenShapes(const ObstructionSquare& source, const ObstructionSquare& target) const; | ||||
virtual bool IsInPointRange(entity_id_t ent, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const; | virtual bool IsInPointRange(entity_id_t ent, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const; | ||||
virtual bool IsInTargetRange(entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const; | virtual bool IsInTargetRange(entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const; | ||||
virtual bool IsPointInPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange) const; | virtual bool IsPointInPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange) const; | ||||
virtual bool AreShapesInRange(const ObstructionSquare& source, const ObstructionSquare& target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const; | virtual bool AreShapesInRange(const ObstructionSquare& source, const ObstructionSquare& target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const; | ||||
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, bool relaxClearanceForUnits = false) const; | virtual bool TestStaticLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r) const; | ||||
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) const; | 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) const; | ||||
virtual bool TestUnitShape(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, std::vector<entity_id_t>* out) const; | virtual bool TestUnitShape(const IObstructionTestFilter& filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, std::vector<entity_id_t>* out) const; | ||||
virtual void Rasterize(Grid<NavcellData>& grid, const std::vector<PathfinderPassability>& passClasses, bool fullUpdate); | virtual void Rasterize(Grid<NavcellData>& grid, const std::vector<PathfinderPassability>& passClasses, bool fullUpdate); | ||||
virtual void GetObstructionsInRange(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector<ObstructionSquare>& squares) const; | virtual void GetObstructionsInRange(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector<ObstructionSquare>& squares) const; | ||||
virtual void GetUnitObstructionsInRange(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector<ObstructionSquare>& squares) const; | virtual void GetUnitObstructionsInRange(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector<ObstructionSquare>& squares) const; | ||||
virtual void GetStaticObstructionsInRange(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector<ObstructionSquare>& squares) const; | virtual void GetStaticObstructionsInRange(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector<ObstructionSquare>& squares) const; | ||||
virtual void GetUnitsOnObstruction(const ObstructionSquare& square, std::vector<entity_id_t>& out, const IObstructionTestFilter& filter, bool strict = false) const; | virtual void GetUnitsOnObstruction(const ObstructionSquare& square, std::vector<entity_id_t>& out, const IObstructionTestFilter& filter, bool strict = false) const; | ||||
▲ Show 20 Lines • Show All 359 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
fixed dist = DistanceBetweenShapes(source, target); | fixed dist = DistanceBetweenShapes(source, target); | ||||
// Treat -1 max range as infinite | // Treat -1 max range as infinite | ||||
return dist != fixed::FromInt(-1) && | return dist != fixed::FromInt(-1) && | ||||
(dist <= (maxRange + fixed::FromFloat(0.0001f)) || maxRange < fixed::Zero()) && | (dist <= (maxRange + fixed::FromFloat(0.0001f)) || maxRange < fixed::Zero()) && | ||||
(opposite ? MaxDistanceBetweenShapes(source, target) : dist) >= minRange - fixed::FromFloat(0.0001f); | (opposite ? MaxDistanceBetweenShapes(source, target) : dist) >= minRange - fixed::FromFloat(0.0001f); | ||||
} | } | ||||
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, bool relaxClearanceForUnits) const | bool CCmpObstructionManager::TestStaticLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r) const | ||||
{ | { | ||||
PROFILE("TestLine"); | PROFILE("TestStaticLine"); | ||||
// Check that both end points are within the world (which means the whole line must be) | // Check that both end points are within the world (which means the whole line must be) | ||||
if (!IsInWorld(x0, z0, r) || !IsInWorld(x1, z1, r)) | if (!IsInWorld(x0, z0, r) || !IsInWorld(x1, z1, r)) | ||||
return true; | return true; | ||||
CFixedVector2D posMin (std::min(x0, x1) - r, std::min(z0, z1) - r); | CFixedVector2D posMin (std::min(x0, x1) - r, std::min(z0, z1) - r); | ||||
CFixedVector2D posMax (std::max(x0, x1) + r, std::max(z0, z1) + r); | CFixedVector2D posMax (std::max(x0, x1) + r, std::max(z0, z1) + r); | ||||
// actual radius used for unit-unit collisions. If relaxClearanceForUnits, will be smaller to allow more overlap. | |||||
entity_pos_t unitUnitRadius = r; | |||||
if (relaxClearanceForUnits) | |||||
unitUnitRadius -= entity_pos_t::FromInt(1)/2; | |||||
std::vector<entity_id_t> unitShapes; | |||||
m_UnitSubdivision.GetInRange(unitShapes, posMin, posMax); | |||||
for (const entity_id_t& shape : unitShapes) | |||||
{ | |||||
std::map<u32, UnitShape>::const_iterator it = m_UnitShapes.find(shape); | |||||
ENSURE(it != m_UnitShapes.end()); | |||||
if (!filter.TestShape(UNIT_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, INVALID_ENTITY)) | |||||
continue; | |||||
CFixedVector2D center(it->second.x, it->second.z); | |||||
CFixedVector2D halfSize(it->second.clearance + unitUnitRadius, it->second.clearance + unitUnitRadius); | |||||
if (Geometry::TestRayAASquare(CFixedVector2D(x0, z0) - center, CFixedVector2D(x1, z1) - center, halfSize)) | |||||
return true; | |||||
} | |||||
std::vector<entity_id_t> staticShapes; | std::vector<entity_id_t> staticShapes; | ||||
m_StaticSubdivision.GetInRange(staticShapes, posMin, posMax); | m_StaticSubdivision.GetInRange(staticShapes, posMin, posMax); | ||||
for (const entity_id_t& shape : staticShapes) | for (const entity_id_t& shape : staticShapes) | ||||
{ | { | ||||
std::map<u32, StaticShape>::const_iterator it = m_StaticShapes.find(shape); | std::map<u32, StaticShape>::const_iterator it = m_StaticShapes.find(shape); | ||||
ENSURE(it != m_StaticShapes.end()); | ENSURE(it != m_StaticShapes.end()); | ||||
if (!filter.TestShape(STATIC_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, it->second.group2)) | if (!filter.TestShape(STATIC_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, it->second.group2)) | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if (Geometry::PointIsInSquare(center1 - center, u, v, CFixedVector2D(halfSize.X + it->second.clearance, halfSize.Y + it->second.clearance))) | ||||
else | else | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
std::vector<entity_id_t> staticShapes; | std::vector<entity_id_t> staticShapes; | ||||
m_StaticSubdivision.GetInRange(staticShapes, posMin, posMax); | m_StaticSubdivision.GetInRange(staticShapes, posMin, posMax); | ||||
for (entity_id_t& shape : staticShapes) | for (entity_id_t& shape : staticShapes) | ||||
{ | { | ||||
elexis: I don't want to talk about implementation until the feature design was finished and reviewed… | |||||
Not Done Inline ActionsOh yeah this is not even used I think, I need to clean this diff a little bit to be honest. wraitii: Oh yeah this is not even used I think, I need to clean this diff a little bit to be honest. | |||||
std::map<u32, StaticShape>::const_iterator it = m_StaticShapes.find(shape); | std::map<u32, StaticShape>::const_iterator it = m_StaticShapes.find(shape); | ||||
ENSURE(it != m_StaticShapes.end()); | ENSURE(it != m_StaticShapes.end()); | ||||
if (!filter.TestShape(STATIC_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, it->second.group2)) | if (!filter.TestShape(STATIC_INDEX_TO_TAG(it->first), it->second.flags, it->second.group, it->second.group2)) | ||||
continue; | continue; | ||||
CFixedVector2D center1(it->second.x, it->second.z); | CFixedVector2D center1(it->second.x, it->second.z); | ||||
CFixedVector2D halfSize1(it->second.hw, it->second.hh); | CFixedVector2D halfSize1(it->second.hw, it->second.hh); | ||||
▲ Show 20 Lines • Show All 375 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I don't want to talk about implementation until the feature design was finished and reviewed, but don't introduce copies.
(The code could be split in a separate commit too in case we weren't focusing on feature design first.)