diff --git a/Core/GameEngine/Include/GameClient/View.h b/Core/GameEngine/Include/GameClient/View.h index d60010da63c..22ddec7f3c5 100644 --- a/Core/GameEngine/Include/GameClient/View.h +++ b/Core/GameEngine/Include/GameClient/View.h @@ -197,7 +197,7 @@ class View : public Snapshot void setPosition( const Coord3D &pos ) { m_pos = pos; } void setPosition2D( const Coord2D &pos ) { m_pos.x = pos.x; m_pos.y = pos.y; } const Coord3D &getPosition() const { return m_pos; } ///< Returns position camera is looking at - Coord2D getPosition2D() const { Coord2D c = { m_pos.x, m_pos.y }; return c; } ///< Returns position camera is looking at + Coord2D getPosition2D() const { return m_pos.asCoord2D(); } ///< Returns position camera is looking at virtual Coord3D get3DCameraPosition() const { Coord3D c={0,0,0}; return c; } ///< Returns the actual camera position virtual Coord3D get3DCameraDirection() const { Coord3D c={0,0,0}; return c; } ///< Returns the actual camera view direction diff --git a/Core/GameEngine/Source/GameClient/GUI/GameWindow.cpp b/Core/GameEngine/Source/GameClient/GUI/GameWindow.cpp index 84dc88726cc..526f8bb52cf 100644 --- a/Core/GameEngine/Source/GameClient/GUI/GameWindow.cpp +++ b/Core/GameEngine/Source/GameClient/GUI/GameWindow.cpp @@ -180,26 +180,11 @@ void GameWindow::unlinkFromTransitionWindows() //============================================================================= void GameWindow::normalizeWindowRegion() { - Int temp; - - if( m_region.lo.x > m_region.hi.x) - { - - temp = m_region.lo.x; - m_region.lo.x = m_region.hi.x; - m_region.hi.x = temp; - - } + if( m_region.lo.x > m_region.hi.x ) + std::swap( m_region.lo.x, m_region.hi.x ); if( m_region.lo.y > m_region.hi.y ) - { - - temp = m_region.lo.y; - m_region.lo.y = m_region.hi.y; - m_region.hi.y = temp; - - } - + std::swap( m_region.lo.y, m_region.hi.y ); } // GameWindow::findFirstLeaf ================================================== diff --git a/Core/GameEngine/Source/GameClient/Line2D.cpp b/Core/GameEngine/Source/GameClient/Line2D.cpp index 19267f6204a..00b2cf5fdc7 100644 --- a/Core/GameEngine/Source/GameClient/Line2D.cpp +++ b/Core/GameEngine/Source/GameClient/Line2D.cpp @@ -289,17 +289,12 @@ Bool PointInsideRect3D(const Coord3D *bl, const Coord3D *tl, const Coord3D *br, const Coord3D *inputPoint) { Coord2D bl2d, tl2d, br2d, tr2d, pt; - bl2d.x = bl->x; - bl2d.y = bl->y; - tl2d.x = tl->x; - tl2d.y = tl->y; - br2d.x = br->x; - br2d.y = br->y; - tr2d.x = tr->x; - tr2d.y = tr->y; - - pt.x = inputPoint->x; - pt.y = inputPoint->y; + bl2d = bl->asCoord2D(); + tl2d = tl->asCoord2D(); + br2d = br->asCoord2D(); + tr2d = tr->asCoord2D(); + + pt = inputPoint->asCoord2D(); return PointInsideRect2D(&bl2d, &br2d, &tl2d, &tr2d, &pt); } @@ -322,14 +317,11 @@ Bool PointInsideArea2D( const Coord3D *ptToTest, const Coord3D *area, Int numPoi { int numIntersections = 0; Coord2D pt2D, area2D1, area2D2; - pt2D.x = ptToTest->x; - pt2D.y = ptToTest->y; + pt2D = ptToTest->asCoord2D(); for (int i = 0; i < numPointsInArea; ++i) { - area2D1.x = area[i].x; - area2D1.y = area[i].y; - area2D2.x = area[(i + 1) % numPointsInArea].x; - area2D2.y = area[(i + 1) % numPointsInArea].y; + area2D1 = area[i].asCoord2D(); + area2D2 = area[(i + 1) % numPointsInArea].asCoord2D(); if (IntersectLine2D(&pt2D, &reallyFarPoint, &area2D1, &area2D2)) { ++numIntersections; } diff --git a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index ae79ca14249..60d1add770b 100644 --- a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -2726,12 +2726,7 @@ void PathfindZoneManager::calculateZones( PathfindCell **map, PathfindLayer laye bounds.lo.y = globalBounds.lo.y + yBlock*ZONE_BLOCK_SIZE; bounds.hi.x = bounds.lo.x + ZONE_BLOCK_SIZE - 1; // bounds are inclusive. bounds.hi.y = bounds.lo.y + ZONE_BLOCK_SIZE - 1; // bounds are inclusive. - if (bounds.hi.x > globalBounds.hi.x) { - bounds.hi.x = globalBounds.hi.x; - } - if (bounds.hi.y > globalBounds.hi.y) { - bounds.hi.y = globalBounds.hi.y; - } + bounds.hi.updateMin(globalBounds.hi); #if RTS_GENERALS && RETAIL_COMPATIBLE_PATHFINDING if (bounds.lo.x>bounds.hi.x || bounds.lo.y>bounds.hi.y) { DEBUG_CRASH(("Incorrect bounds calculation. Logic error, fix me. jba.")); @@ -2828,11 +2823,7 @@ void PathfindZoneManager::calculateZones( PathfindCell **map, PathfindLayer laye bounds.hi.x = bounds.lo.x + ZONE_BLOCK_SIZE - 1; // bounds are inclusive. bounds.hi.y = bounds.lo.y + ZONE_BLOCK_SIZE - 1; // bounds are inclusive. - if (bounds.hi.x > globalBounds.hi.x) - bounds.hi.x = globalBounds.hi.x; - - if (bounds.hi.y > globalBounds.hi.y) - bounds.hi.y = globalBounds.hi.y; + bounds.hi.updateMin(globalBounds.hi); #if RTS_GENERALS && RETAIL_COMPATIBLE_PATHFINDING if (bounds.lo.x>bounds.hi.x || bounds.lo.y>bounds.hi.y) { DEBUG_CRASH(("Incorrect bounds calculation. Logic error, fix me. jba.")); @@ -3051,12 +3042,7 @@ void PathfindZoneManager::updateZonesForModify(PathfindCell **map, PathfindLayer IRegion2D bounds = structureBounds; bounds.hi.x++; bounds.hi.y++; - if (bounds.hi.x > globalBounds.hi.x) { - bounds.hi.x = globalBounds.hi.x; - } - if (bounds.hi.y > globalBounds.hi.y) { - bounds.hi.y = globalBounds.hi.y; - } + bounds.hi.updateMin(globalBounds.hi); Int xBlock, yBlock; for (xBlock = 0; xBlock bounds.hi.x) { - blockBounds.hi.x = bounds.hi.x; - } - if (blockBounds.hi.y > bounds.hi.y) { - blockBounds.hi.y = bounds.hi.y; - } - if (blockBounds.lo.x < bounds.lo.x) { - blockBounds.lo.x = bounds.lo.x; - } - if (blockBounds.lo.y < bounds.lo.y) { - blockBounds.lo.y = bounds.lo.y; - } + blockBounds.intersectWith(bounds); if (blockBounds.lo.x>blockBounds.hi.x || blockBounds.lo.y>blockBounds.hi.y) { continue; } @@ -3616,10 +3591,7 @@ void PathfindLayer::allocateCellsForWallLayer(const IRegion2D *extent, ObjectID bridgeBounds = objBounds; first = false; } else { - if (bridgeBounds.lo.x>objBounds.lo.x) bridgeBounds.lo.x = objBounds.lo.x; - if (bridgeBounds.lo.y>objBounds.lo.y) bridgeBounds.lo.y = objBounds.lo.y; - if (bridgeBounds.hi.xisCellOnEnd(&cellBounds)) { @@ -4607,21 +4577,7 @@ void Pathfinder::internal_classifyObjectFootprint( Object *obj, Bool insert ) Int i, j; - if (cellBounds.lo.x < m_extent.lo.x) { - cellBounds.lo.x = m_extent.lo.x; - } - if (cellBounds.lo.y < m_extent.lo.y) { - cellBounds.lo.y = m_extent.lo.y; - } - if (cellBounds.lo.y < m_extent.lo.y) { - cellBounds.lo.y = m_extent.lo.y; - } - if (cellBounds.hi.x > m_extent.hi.x) { - cellBounds.hi.x = m_extent.hi.x; - } - if (cellBounds.hi.y > m_extent.hi.y) { - cellBounds.hi.y = m_extent.hi.y; - } + cellBounds.intersectWith(m_extent); if (!insert) { for( j=cellBounds.lo.y; j<=cellBounds.hi.y; j++ ) @@ -10484,10 +10440,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj, for( node = pathToAvoid->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) { Coord2D start, end; - start.x = node->getPosition()->x; - start.y = node->getPosition()->y; - end.x = node->getNextOptimized()->getPosition()->x; - end.y = node->getNextOptimized()->getPosition()->y; + start = node->getPosition()->asCoord2D(); + end = node->getNextOptimized()->getPosition()->asCoord2D(); if (LineInRegion(&start, &end, &bounds)) { overlap = true; break; @@ -10497,10 +10451,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj, if (!overlap && pathToAvoid2) { for( node = pathToAvoid2->getFirstNode(); node && node->getNextOptimized(); node = node->getNextOptimized() ) { Coord2D start, end; - start.x = node->getPosition()->x; - start.y = node->getPosition()->y; - end.x = node->getNextOptimized()->getPosition()->x; - end.y = node->getNextOptimized()->getPosition()->y; + start = node->getPosition()->asCoord2D(); + end = node->getNextOptimized()->getPosition()->asCoord2D(); if (LineInRegion(&start, &end, &bounds)) { overlap = true; break; diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp index b2d54ac0b7e..91ad7d39152 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp @@ -2625,8 +2625,7 @@ void W3DView::lookAt( const Coord3D *o ) } } - Coord2D pos2D = { pos.x, pos.y }; - setPosition2D(pos2D); + setPosition2D(pos.asCoord2D()); resetPivotToGround(); diff --git a/Core/Libraries/Include/Lib/BaseType.h b/Core/Libraries/Include/Lib/BaseType.h index 8b5e760aff4..91a50112aee 100644 --- a/Core/Libraries/Include/Lib/BaseType.h +++ b/Core/Libraries/Include/Lib/BaseType.h @@ -331,6 +331,24 @@ struct Coord2D x = ax; y = ay; } + + void updateMin( const Coord2D &other ) + { + if (x > other.x) + x = other.x; + + if (y > other.y) + y = other.y; + } + + void updateMax( const Coord2D &other ) + { + if (x < other.x) + x = other.x; + + if (y < other.y) + y = other.y; + } }; inline Coord2D operator+( const Coord2D &a, const Coord2D &b ) @@ -458,6 +476,24 @@ struct ICoord2D x = ax; y = ay; } + + void updateMin( const ICoord2D &other ) + { + if (x > other.x) + x = other.x; + + if (y > other.y) + y = other.y; + } + + void updateMax( const ICoord2D &other ) + { + if (x < other.x) + x = other.x; + + if (y < other.y) + y = other.y; + } }; inline ICoord2D operator+( const ICoord2D &a, const ICoord2D &b ) @@ -478,6 +514,27 @@ struct Region2D { Coord2D lo, hi; // bounds of 2D rectangular region + // Keep only the overlapping portion of both regions. + void intersectWith( const Region2D &other ) + { + lo.updateMax(other.lo); + hi.updateMin(other.hi); + } + + // Expand to include the other region. + void uniteWith( const Region2D &other ) + { + lo.updateMin(other.lo); + hi.updateMax(other.hi); + } + + // Expand to include the point. + void uniteWith( const Coord2D &point ) + { + lo.updateMin(point); + hi.updateMax(point); + } + void zero() { lo.zero(); @@ -498,6 +555,27 @@ struct IRegion2D { ICoord2D lo, hi; // bounds of 2D rectangular region + // Keep only the overlapping portion of both regions. + void intersectWith( const IRegion2D &other ) + { + lo.updateMax(other.lo); + hi.updateMin(other.hi); + } + + // Expand to include the other region. + void uniteWith( const IRegion2D &other ) + { + lo.updateMin(other.lo); + hi.updateMax(other.hi); + } + + // Expand to include the point. + void uniteWith( const ICoord2D &point ) + { + lo.updateMin(point); + hi.updateMax(point); + } + void zero() { lo.zero(); @@ -519,6 +597,12 @@ struct Coord3D { Real x, y, z; + Coord2D asCoord2D() const + { + const Coord2D xy = { x, y }; + return xy; + } + Real length() const { return (Real)sqrt( x*x + y*y + z*z ); } Real lengthSqr() const { return ( x*x + y*y + z*z ); } @@ -611,6 +695,30 @@ struct Coord3D y == r.y && z == r.z); } + + void updateMin( const Coord3D &other ) + { + if (x > other.x) + x = other.x; + + if (y > other.y) + y = other.y; + + if (z > other.z) + z = other.z; + } + + void updateMax( const Coord3D &other ) + { + if (x < other.x) + x = other.x; + + if (y < other.y) + y = other.y; + + if (z < other.z) + z = other.z; + } }; inline Coord3D operator+( const Coord3D &a, const Coord3D &b ) @@ -631,6 +739,12 @@ struct ICoord3D { Int x, y, z; + ICoord2D asICoord2D() const + { + const ICoord2D xy = { x, y }; + return xy; + } + Int length() const { return (Int)sqrt( (double)(x*x + y*y + z*z) ); } Int lengthSqr() const { return x*x + y*y + z*z; } @@ -683,6 +797,30 @@ struct ICoord3D y = ay; z = az; } + + void updateMin( const ICoord3D &other ) + { + if (x > other.x) + x = other.x; + + if (y > other.y) + y = other.y; + + if (z > other.z) + z = other.z; + } + + void updateMax( const ICoord3D &other ) + { + if (x < other.x) + x = other.x; + + if (y < other.y) + y = other.y; + + if (z < other.z) + z = other.z; + } }; inline ICoord3D operator+( const ICoord3D &a, const ICoord3D &b ) @@ -704,6 +842,27 @@ struct Region3D { Coord3D lo, hi; // axis-aligned bounding box + // Keep only the overlapping portion of both regions. + void intersectWith( const Region3D &other ) + { + lo.updateMax(other.lo); + hi.updateMin(other.hi); + } + + // Expand to include the other region. + void uniteWith( const Region3D &other ) + { + lo.updateMin(other.lo); + hi.updateMax(other.hi); + } + + // Expand to include the point. + void uniteWith( const Coord3D &point ) + { + lo.updateMin(point); + hi.updateMax(point); + } + Real width() const { return hi.x - lo.x; } Real height() const { return hi.y - lo.y; } Real depth() const { return hi.z - lo.z; } @@ -750,18 +909,7 @@ struct Region3D hi = points[0]; for (Int i = 1; i < count; ++i) { - if (points[i].x < lo.x) - lo.x = points[i].x; - if (points[i].y < lo.y) - lo.y = points[i].y; - if (points[i].z < lo.z) - lo.z = points[i].z; - if (points[i].x > hi.x) - hi.x = points[i].x; - if (points[i].y > hi.y) - hi.y = points[i].y; - if (points[i].z > hi.z) - hi.z = points[i].z; + uniteWith(points[i]); } } @@ -783,6 +931,27 @@ struct IRegion3D { ICoord3D lo, hi; // axis-aligned bounding box + // Keep only the overlapping portion of both regions. + void intersectWith( const IRegion3D &other ) + { + lo.updateMax(other.lo); + hi.updateMin(other.hi); + } + + // Expand to include the other region. + void uniteWith( const IRegion3D &other ) + { + lo.updateMin(other.lo); + hi.updateMax(other.hi); + } + + // Expand to include the point. + void uniteWith( const ICoord3D &point ) + { + lo.updateMin(point); + hi.updateMax(point); + } + void zero() { lo.zero(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 2472c2ffefc..fc9385a7b68 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -3496,20 +3496,14 @@ void AIPlayer::getPlayerStructureBounds(Region2D *bounds, Int playerNdx ) objBounds.lo.y = objBounds.hi.y = pos.y; firstObject = false; } else { - if (objBounds.lo.x>pos.x) objBounds.lo.x = pos.x; - if (objBounds.lo.y>pos.y) objBounds.lo.y = pos.y; - if (objBounds.hi.xlo.x = bounds->hi.x = pos.x; bounds->lo.y = bounds->hi.y = pos.y; firstStructure = false; } else { - if (bounds->lo.x>pos.x) bounds->lo.x = pos.x; - if (bounds->lo.y>pos.y) bounds->lo.y = pos.y; - if (bounds->hi.xhi.x = pos.x; - if (bounds->hi.yhi.y = pos.y; + bounds->uniteWith(pos.asCoord2D()); } } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 6cea7c6227a..53547241570 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -261,10 +261,7 @@ void PolygonTrigger::updateBounds() const m_bounds.hi.x = m_bounds.hi.y = -BIG_INT; Int i; for (i=0; i m_bounds.hi.x) m_bounds.hi.x = m_points[i].x; - if (m_points[i].y > m_bounds.hi.y) m_bounds.hi.y = m_points[i].y; + m_bounds.uniteWith(m_points[i].asICoord2D()); } m_boundsNeedsUpdate = 0; Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index 00386047267..c00d3096810 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -221,21 +221,11 @@ m_bridgeInfo(theInfo) m_templateName = bridgeTemplateName; //Coord3D fromLeft, fromRight, toLeft, toRight; /// The 4 corners of the rectangle that the bridge covers. - m_bounds.lo.x = m_bridgeInfo.fromLeft.x; - m_bounds.lo.y = m_bridgeInfo.fromLeft.y; + m_bounds.lo = m_bridgeInfo.fromLeft.asCoord2D(); m_bounds.hi = m_bounds.lo; - if (m_bounds.lo.x > m_bridgeInfo.fromRight.x) m_bounds.lo.x = m_bridgeInfo.fromRight.x; - if (m_bounds.lo.y > m_bridgeInfo.fromRight.y) m_bounds.lo.y = m_bridgeInfo.fromRight.y; - if (m_bounds.hi.x < m_bridgeInfo.fromRight.x) m_bounds.hi.x = m_bridgeInfo.fromRight.x; - if (m_bounds.hi.y < m_bridgeInfo.fromRight.y) m_bounds.hi.y = m_bridgeInfo.fromRight.y; - if (m_bounds.lo.x > m_bridgeInfo.toLeft.x) m_bounds.lo.x = m_bridgeInfo.toLeft.x; - if (m_bounds.lo.y > m_bridgeInfo.toLeft.y) m_bounds.lo.y = m_bridgeInfo.toLeft.y; - if (m_bounds.hi.x < m_bridgeInfo.toLeft.x) m_bounds.hi.x = m_bridgeInfo.toLeft.x; - if (m_bounds.hi.y < m_bridgeInfo.toLeft.y) m_bounds.hi.y = m_bridgeInfo.toLeft.y; - if (m_bounds.lo.x > m_bridgeInfo.toRight.x) m_bounds.lo.x = m_bridgeInfo.toRight.x; - if (m_bounds.lo.y > m_bridgeInfo.toRight.y) m_bounds.lo.y = m_bridgeInfo.toRight.y; - if (m_bounds.hi.x < m_bridgeInfo.toRight.x) m_bounds.hi.x = m_bridgeInfo.toRight.x; - if (m_bounds.hi.y < m_bridgeInfo.toRight.y) m_bounds.hi.y = m_bridgeInfo.toRight.y; + m_bounds.uniteWith(m_bridgeInfo.fromRight.asCoord2D()); + m_bounds.uniteWith(m_bridgeInfo.toLeft.asCoord2D()); + m_bounds.uniteWith(m_bridgeInfo.toRight.asCoord2D()); m_bridgeInfo.curDamageState = BODY_PRISTINE; @@ -357,21 +347,11 @@ Bridge::Bridge(Object *bridgeObj) m_bridgeInfo.to.z = (m_bridgeInfo.toLeft.z + m_bridgeInfo.toRight.z)/2.0f; //Coord3D fromLeft, fromRight, toLeft, toRight; /// The 4 corners of the rectangle that the bridge covers. - m_bounds.lo.x = m_bridgeInfo.fromLeft.x; - m_bounds.lo.y = m_bridgeInfo.fromLeft.y; + m_bounds.lo = m_bridgeInfo.fromLeft.asCoord2D(); m_bounds.hi = m_bounds.lo; - if (m_bounds.lo.x > m_bridgeInfo.fromRight.x) m_bounds.lo.x = m_bridgeInfo.fromRight.x; - if (m_bounds.lo.y > m_bridgeInfo.fromRight.y) m_bounds.lo.y = m_bridgeInfo.fromRight.y; - if (m_bounds.hi.x < m_bridgeInfo.fromRight.x) m_bounds.hi.x = m_bridgeInfo.fromRight.x; - if (m_bounds.hi.y < m_bridgeInfo.fromRight.y) m_bounds.hi.y = m_bridgeInfo.fromRight.y; - if (m_bounds.lo.x > m_bridgeInfo.toLeft.x) m_bounds.lo.x = m_bridgeInfo.toLeft.x; - if (m_bounds.lo.y > m_bridgeInfo.toLeft.y) m_bounds.lo.y = m_bridgeInfo.toLeft.y; - if (m_bounds.hi.x < m_bridgeInfo.toLeft.x) m_bounds.hi.x = m_bridgeInfo.toLeft.x; - if (m_bounds.hi.y < m_bridgeInfo.toLeft.y) m_bounds.hi.y = m_bridgeInfo.toLeft.y; - if (m_bounds.lo.x > m_bridgeInfo.toRight.x) m_bounds.lo.x = m_bridgeInfo.toRight.x; - if (m_bounds.lo.y > m_bridgeInfo.toRight.y) m_bounds.lo.y = m_bridgeInfo.toRight.y; - if (m_bounds.hi.x < m_bridgeInfo.toRight.x) m_bounds.hi.x = m_bridgeInfo.toRight.x; - if (m_bounds.hi.y < m_bridgeInfo.toRight.y) m_bounds.hi.y = m_bridgeInfo.toRight.y; + m_bounds.uniteWith(m_bridgeInfo.fromRight.asCoord2D()); + m_bounds.uniteWith(m_bridgeInfo.toLeft.asCoord2D()); + m_bounds.uniteWith(m_bridgeInfo.toRight.asCoord2D()); m_bridgeInfo.curDamageState = BODY_PRISTINE; @@ -673,17 +653,13 @@ Bool Bridge::isCellOnEnd(const Region2D *cell) if (PointInRegion2D(&toLeft, cell)) return false; if (PointInRegion2D(&toRight, cell)) return false; */ Coord2D line1, line2; - line1.x = fromLeft.x; - line1.y = fromLeft.y; - line2.x = fromRight.x; - line2.y = fromRight.y; + line1 = fromLeft.asCoord2D(); + line2 = fromRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } - line1.x = toLeft.x; - line1.y = toLeft.y; - line2.x = toRight.x; - line2.y = toRight.y; + line1 = toLeft.asCoord2D(); + line2 = toRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } @@ -721,17 +697,13 @@ Bool Bridge::isCellOnSide(const Region2D *cell) toRight.y += endVector.y; Coord2D line1, line2; - line1.x = fromLeft.x; - line1.y = fromLeft.y; - line2.x = toLeft.x; - line2.y = toLeft.y; + line1 = fromLeft.asCoord2D(); + line2 = toLeft.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } - line1.x = fromRight.x; - line1.y = fromRight.y; - line2.x = toRight.x; - line2.y = toRight.y; + line1 = fromRight.asCoord2D(); + line2 = toRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } @@ -747,17 +719,13 @@ Bool Bridge::isCellOnSide(const Region2D *cell) toRight.x += endVector.x; toRight.y += endVector.y; - line1.x = fromLeft.x; - line1.y = fromLeft.y; - line2.x = toLeft.x; - line2.y = toLeft.y; + line1 = fromLeft.asCoord2D(); + line2 = toLeft.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } - line1.x = fromRight.x; - line1.y = fromRight.y; - line2.x = toRight.x; - line2.y = toRight.y; + line1 = fromRight.asCoord2D(); + line2 = toRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } @@ -816,17 +784,13 @@ Bool Bridge::isCellEntryPoint(const Region2D *cell) if (PointInRegion2D(&toRight, cell)) return false; */ Coord2D line1, line2; - line1.x = fromLeft.x; - line1.y = fromLeft.y; - line2.x = fromRight.x; - line2.y = fromRight.y; + line1 = fromLeft.asCoord2D(); + line2 = fromRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } - line1.x = toLeft.x; - line1.y = toLeft.y; - line2.x = toRight.x; - line2.y = toRight.y; + line1 = toLeft.asCoord2D(); + line2 = toRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } @@ -1781,8 +1745,7 @@ Bool TerrainLogic::objectInteractsWithBridgeLayer(Object *obj, Int layer, Bool c Real radius = obj->getGeometryInfo().getMinorRadius(); radius += PATHFIND_CELL_SIZE_F/2.0f; Region2D bounds; - bounds.lo.x = obj->getPosition()->x; - bounds.lo.y = obj->getPosition()->y; + bounds.lo = obj->getPosition()->asCoord2D(); bounds.hi = bounds.lo; bounds.lo.x -= radius; bounds.lo.y -= radius; @@ -1830,8 +1793,7 @@ Bool TerrainLogic::objectInteractsWithBridgeEnd(Object *obj, Int layer) const Real radius = obj->getGeometryInfo().getMinorRadius(); radius += PATHFIND_CELL_SIZE_F/2.0f; Region2D bounds; - bounds.lo.x = obj->getPosition()->x; - bounds.lo.y = obj->getPosition()->y; + bounds.lo = obj->getPosition()->asCoord2D(); bounds.hi = bounds.lo; bounds.lo.x -= radius; bounds.lo.y -= radius; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/PrisonBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/PrisonBehavior.cpp index 92ce422a6b0..50a0deece37 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/PrisonBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/PrisonBehavior.cpp @@ -237,21 +237,12 @@ void PrisonBehavior::pickVisualLocation( Coord3D *pos ) // find the bounding region of the yard area Region2D yardRegion; - yardRegion.lo.x = yardPositions[ 0 ].x; - yardRegion.lo.y = yardPositions[ 0 ].y; - yardRegion.hi.x = yardPositions[ 0 ].x; - yardRegion.hi.y = yardPositions[ 0 ].y; + yardRegion.lo = yardPositions[ 0 ].asCoord2D(); + yardRegion.hi = yardPositions[ 0 ].asCoord2D(); for( i = 1; i < yardBones; i++ ) { - if( yardPositions[ i ].x < yardRegion.lo.x ) - yardRegion.lo.x = yardPositions[ i ].x; - if( yardPositions[ i ].y < yardRegion.lo.y ) - yardRegion.lo.y = yardPositions[ i ].y; - if( yardPositions[ i ].x > yardRegion.hi.x ) - yardRegion.hi.x = yardPositions[ i ].x; - if( yardPositions[ i ].y > yardRegion.hi.y ) - yardRegion.hi.y = yardPositions[ i ].y; + yardRegion.uniteWith(yardPositions[ i ].asCoord2D()); } diff --git a/Generals/Code/Tools/WorldBuilder/src/RampTool.cpp b/Generals/Code/Tools/WorldBuilder/src/RampTool.cpp index 572684b34c6..71fc30840dd 100644 --- a/Generals/Code/Tools/WorldBuilder/src/RampTool.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/RampTool.cpp @@ -159,9 +159,9 @@ void RampTool::applyRamp(CWorldBuilderDoc* pDoc) pDoc->getCoordFromCellIndex(indices[i], &pt); Real uVal; - Coord2D start = { mStartPoint.x, mStartPoint.y }; - Coord2D end = { mEndPoint.x, mEndPoint.y }; - Coord2D pt2D = { pt.x, pt.y }; + Coord2D start = mStartPoint.asCoord2D(); + Coord2D end = mEndPoint.asCoord2D(); + Coord2D pt2D = pt.asCoord2D(); ShortestDistancePointToSegment2D(&start, &end, &pt2D, nullptr, nullptr, &uVal); Real height = mStartPoint.z + uVal * (mEndPoint.z - mStartPoint.z); diff --git a/Generals/Code/Tools/WorldBuilder/src/RoadTool.cpp b/Generals/Code/Tools/WorldBuilder/src/RoadTool.cpp index e5d9d1dfc69..c2dbc0e32e3 100644 --- a/Generals/Code/Tools/WorldBuilder/src/RoadTool.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/RoadTool.cpp @@ -67,12 +67,9 @@ MapObject* RoadTool::findSegment(const Coord3D *pLoc, Coord3D *outLoc) if (!pMapObj2->getFlag(FLAG_ROAD_POINT2)) continue; Coord2D start, end, loc, snapLoc; - start.x = pMapObj->getLocation()->x; - start.y = pMapObj->getLocation()->y; - end.x = pMapObj2->getLocation()->x; - end.y = pMapObj2->getLocation()->y; - loc.x = pLoc->x; - loc.y = pLoc->y; + start = pMapObj->getLocation()->asCoord2D(); + end = pMapObj2->getLocation()->asCoord2D(); + loc = pLoc->asCoord2D(); Real dist; Real u; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 330969a65ed..10e5faa96af 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -3848,10 +3848,7 @@ void AIPlayer::getPlayerStructureBounds( Region2D *bounds, Int playerNdx, Bool c } else { - if (objBounds.lo.x>pos.x) objBounds.lo.x = pos.x; - if (objBounds.lo.y>pos.y) objBounds.lo.y = pos.y; - if (objBounds.hi.xlo.x>pos.x) bounds->lo.x = pos.x; - if (bounds->lo.y>pos.y) bounds->lo.y = pos.y; - if (bounds->hi.xhi.x = pos.x; - if (bounds->hi.yhi.y = pos.y; + bounds->uniteWith(pos.asCoord2D()); } } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 4f19ee9cfc2..6f45a4cc4b9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -277,10 +277,7 @@ void PolygonTrigger::updateBounds() const m_bounds.hi.x = m_bounds.hi.y = -BIG_INT; Int i; for (i=0; i m_bounds.hi.x) m_bounds.hi.x = m_points[i].x; - if (m_points[i].y > m_bounds.hi.y) m_bounds.hi.y = m_points[i].y; + m_bounds.uniteWith(m_points[i].asICoord2D()); } m_boundsNeedsUpdate = 0; Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index 5a3d16f86ae..f2173b15e4b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -221,21 +221,11 @@ m_bridgeInfo(theInfo) m_templateName = bridgeTemplateName; //Coord3D fromLeft, fromRight, toLeft, toRight; /// The 4 corners of the rectangle that the bridge covers. - m_bounds.lo.x = m_bridgeInfo.fromLeft.x; - m_bounds.lo.y = m_bridgeInfo.fromLeft.y; + m_bounds.lo = m_bridgeInfo.fromLeft.asCoord2D(); m_bounds.hi = m_bounds.lo; - if (m_bounds.lo.x > m_bridgeInfo.fromRight.x) m_bounds.lo.x = m_bridgeInfo.fromRight.x; - if (m_bounds.lo.y > m_bridgeInfo.fromRight.y) m_bounds.lo.y = m_bridgeInfo.fromRight.y; - if (m_bounds.hi.x < m_bridgeInfo.fromRight.x) m_bounds.hi.x = m_bridgeInfo.fromRight.x; - if (m_bounds.hi.y < m_bridgeInfo.fromRight.y) m_bounds.hi.y = m_bridgeInfo.fromRight.y; - if (m_bounds.lo.x > m_bridgeInfo.toLeft.x) m_bounds.lo.x = m_bridgeInfo.toLeft.x; - if (m_bounds.lo.y > m_bridgeInfo.toLeft.y) m_bounds.lo.y = m_bridgeInfo.toLeft.y; - if (m_bounds.hi.x < m_bridgeInfo.toLeft.x) m_bounds.hi.x = m_bridgeInfo.toLeft.x; - if (m_bounds.hi.y < m_bridgeInfo.toLeft.y) m_bounds.hi.y = m_bridgeInfo.toLeft.y; - if (m_bounds.lo.x > m_bridgeInfo.toRight.x) m_bounds.lo.x = m_bridgeInfo.toRight.x; - if (m_bounds.lo.y > m_bridgeInfo.toRight.y) m_bounds.lo.y = m_bridgeInfo.toRight.y; - if (m_bounds.hi.x < m_bridgeInfo.toRight.x) m_bounds.hi.x = m_bridgeInfo.toRight.x; - if (m_bounds.hi.y < m_bridgeInfo.toRight.y) m_bounds.hi.y = m_bridgeInfo.toRight.y; + m_bounds.uniteWith(m_bridgeInfo.fromRight.asCoord2D()); + m_bounds.uniteWith(m_bridgeInfo.toLeft.asCoord2D()); + m_bounds.uniteWith(m_bridgeInfo.toRight.asCoord2D()); m_bridgeInfo.curDamageState = BODY_PRISTINE; @@ -357,21 +347,11 @@ Bridge::Bridge(Object *bridgeObj) m_bridgeInfo.to.z = (m_bridgeInfo.toLeft.z + m_bridgeInfo.toRight.z)/2.0f; //Coord3D fromLeft, fromRight, toLeft, toRight; /// The 4 corners of the rectangle that the bridge covers. - m_bounds.lo.x = m_bridgeInfo.fromLeft.x; - m_bounds.lo.y = m_bridgeInfo.fromLeft.y; + m_bounds.lo = m_bridgeInfo.fromLeft.asCoord2D(); m_bounds.hi = m_bounds.lo; - if (m_bounds.lo.x > m_bridgeInfo.fromRight.x) m_bounds.lo.x = m_bridgeInfo.fromRight.x; - if (m_bounds.lo.y > m_bridgeInfo.fromRight.y) m_bounds.lo.y = m_bridgeInfo.fromRight.y; - if (m_bounds.hi.x < m_bridgeInfo.fromRight.x) m_bounds.hi.x = m_bridgeInfo.fromRight.x; - if (m_bounds.hi.y < m_bridgeInfo.fromRight.y) m_bounds.hi.y = m_bridgeInfo.fromRight.y; - if (m_bounds.lo.x > m_bridgeInfo.toLeft.x) m_bounds.lo.x = m_bridgeInfo.toLeft.x; - if (m_bounds.lo.y > m_bridgeInfo.toLeft.y) m_bounds.lo.y = m_bridgeInfo.toLeft.y; - if (m_bounds.hi.x < m_bridgeInfo.toLeft.x) m_bounds.hi.x = m_bridgeInfo.toLeft.x; - if (m_bounds.hi.y < m_bridgeInfo.toLeft.y) m_bounds.hi.y = m_bridgeInfo.toLeft.y; - if (m_bounds.lo.x > m_bridgeInfo.toRight.x) m_bounds.lo.x = m_bridgeInfo.toRight.x; - if (m_bounds.lo.y > m_bridgeInfo.toRight.y) m_bounds.lo.y = m_bridgeInfo.toRight.y; - if (m_bounds.hi.x < m_bridgeInfo.toRight.x) m_bounds.hi.x = m_bridgeInfo.toRight.x; - if (m_bounds.hi.y < m_bridgeInfo.toRight.y) m_bounds.hi.y = m_bridgeInfo.toRight.y; + m_bounds.uniteWith(m_bridgeInfo.fromRight.asCoord2D()); + m_bounds.uniteWith(m_bridgeInfo.toLeft.asCoord2D()); + m_bounds.uniteWith(m_bridgeInfo.toRight.asCoord2D()); m_bridgeInfo.curDamageState = BODY_PRISTINE; @@ -673,17 +653,13 @@ Bool Bridge::isCellOnEnd(const Region2D *cell) if (PointInRegion2D(&toLeft, cell)) return false; if (PointInRegion2D(&toRight, cell)) return false; */ Coord2D line1, line2; - line1.x = fromLeft.x; - line1.y = fromLeft.y; - line2.x = fromRight.x; - line2.y = fromRight.y; + line1 = fromLeft.asCoord2D(); + line2 = fromRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } - line1.x = toLeft.x; - line1.y = toLeft.y; - line2.x = toRight.x; - line2.y = toRight.y; + line1 = toLeft.asCoord2D(); + line2 = toRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } @@ -721,17 +697,13 @@ Bool Bridge::isCellOnSide(const Region2D *cell) toRight.y += endVector.y; Coord2D line1, line2; - line1.x = fromLeft.x; - line1.y = fromLeft.y; - line2.x = toLeft.x; - line2.y = toLeft.y; + line1 = fromLeft.asCoord2D(); + line2 = toLeft.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } - line1.x = fromRight.x; - line1.y = fromRight.y; - line2.x = toRight.x; - line2.y = toRight.y; + line1 = fromRight.asCoord2D(); + line2 = toRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } @@ -747,17 +719,13 @@ Bool Bridge::isCellOnSide(const Region2D *cell) toRight.x += endVector.x; toRight.y += endVector.y; - line1.x = fromLeft.x; - line1.y = fromLeft.y; - line2.x = toLeft.x; - line2.y = toLeft.y; + line1 = fromLeft.asCoord2D(); + line2 = toLeft.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } - line1.x = fromRight.x; - line1.y = fromRight.y; - line2.x = toRight.x; - line2.y = toRight.y; + line1 = fromRight.asCoord2D(); + line2 = toRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } @@ -816,17 +784,13 @@ Bool Bridge::isCellEntryPoint(const Region2D *cell) if (PointInRegion2D(&toRight, cell)) return false; */ Coord2D line1, line2; - line1.x = fromLeft.x; - line1.y = fromLeft.y; - line2.x = fromRight.x; - line2.y = fromRight.y; + line1 = fromLeft.asCoord2D(); + line2 = fromRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } - line1.x = toLeft.x; - line1.y = toLeft.y; - line2.x = toRight.x; - line2.y = toRight.y; + line1 = toLeft.asCoord2D(); + line2 = toRight.asCoord2D(); if (LineInRegion(&line1, &line2, cell)) { return true; } @@ -1781,8 +1745,7 @@ Bool TerrainLogic::objectInteractsWithBridgeLayer(Object *obj, Int layer, Bool c Real radius = obj->getGeometryInfo().getMinorRadius(); radius += PATHFIND_CELL_SIZE_F/2.0f; Region2D bounds; - bounds.lo.x = obj->getPosition()->x; - bounds.lo.y = obj->getPosition()->y; + bounds.lo = obj->getPosition()->asCoord2D(); bounds.hi = bounds.lo; bounds.lo.x -= radius; bounds.lo.y -= radius; @@ -1830,8 +1793,7 @@ Bool TerrainLogic::objectInteractsWithBridgeEnd(Object *obj, Int layer) const Real radius = obj->getGeometryInfo().getMinorRadius(); radius += PATHFIND_CELL_SIZE_F/2.0f; Region2D bounds; - bounds.lo.x = obj->getPosition()->x; - bounds.lo.y = obj->getPosition()->y; + bounds.lo = obj->getPosition()->asCoord2D(); bounds.hi = bounds.lo; bounds.lo.x -= radius; bounds.lo.y -= radius; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/PrisonBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/PrisonBehavior.cpp index ccffe16691f..a021b9f8045 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/PrisonBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/PrisonBehavior.cpp @@ -237,21 +237,12 @@ void PrisonBehavior::pickVisualLocation( Coord3D *pos ) // find the bounding region of the yard area Region2D yardRegion; - yardRegion.lo.x = yardPositions[ 0 ].x; - yardRegion.lo.y = yardPositions[ 0 ].y; - yardRegion.hi.x = yardPositions[ 0 ].x; - yardRegion.hi.y = yardPositions[ 0 ].y; + yardRegion.lo = yardPositions[ 0 ].asCoord2D(); + yardRegion.hi = yardPositions[ 0 ].asCoord2D(); for( i = 1; i < yardBones; i++ ) { - if( yardPositions[ i ].x < yardRegion.lo.x ) - yardRegion.lo.x = yardPositions[ i ].x; - if( yardPositions[ i ].y < yardRegion.lo.y ) - yardRegion.lo.y = yardPositions[ i ].y; - if( yardPositions[ i ].x > yardRegion.hi.x ) - yardRegion.hi.x = yardPositions[ i ].x; - if( yardPositions[ i ].y > yardRegion.hi.y ) - yardRegion.hi.y = yardPositions[ i ].y; + yardRegion.uniteWith(yardPositions[ i ].asCoord2D()); } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/RampTool.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/RampTool.cpp index 4e2cf875af8..e1fbf328a6f 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/RampTool.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/RampTool.cpp @@ -161,9 +161,9 @@ void RampTool::applyRamp(CWorldBuilderDoc* pDoc) pDoc->getCoordFromCellIndex(indices[i], &pt); Real uVal; - Coord2D start = { mStartPoint.x, mStartPoint.y }; - Coord2D end = { mEndPoint.x, mEndPoint.y }; - Coord2D pt2D = { pt.x, pt.y }; + Coord2D start = mStartPoint.asCoord2D(); + Coord2D end = mEndPoint.asCoord2D(); + Coord2D pt2D = pt.asCoord2D(); ShortestDistancePointToSegment2D(&start, &end, &pt2D, nullptr, nullptr, &uVal); Real height = mStartPoint.z + uVal * (mEndPoint.z - mStartPoint.z); diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/RoadTool.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/RoadTool.cpp index 39ea5558efd..dc367be288c 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/RoadTool.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/RoadTool.cpp @@ -67,12 +67,9 @@ MapObject* RoadTool::findSegment(const Coord3D *pLoc, Coord3D *outLoc) if (!pMapObj2->getFlag(FLAG_ROAD_POINT2)) continue; Coord2D start, end, loc, snapLoc; - start.x = pMapObj->getLocation()->x; - start.y = pMapObj->getLocation()->y; - end.x = pMapObj2->getLocation()->x; - end.y = pMapObj2->getLocation()->y; - loc.x = pLoc->x; - loc.y = pLoc->y; + start = pMapObj->getLocation()->asCoord2D(); + end = pMapObj2->getLocation()->asCoord2D(); + loc = pLoc->asCoord2D(); Real dist; Real u;