Skip to content

Commit 48054ec

Browse files
authored
perf(behavior): Optimize loops in ParkingPlaceBehavior (#1618)
1 parent 5a9a526 commit 48054ec

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,13 @@ Bool ParkingPlaceBehavior::reserveSpace(ObjectID id, Real parkingOffset, Parking
352352

353353
for (std::vector<RunwayInfo>::iterator it = m_runways.begin(); it != m_runways.end(); ++it)
354354
{
355-
if (it->m_inUseBy == id && it->m_wasInLine)
355+
if (it->m_inUseBy == id)
356356
{
357-
info->runwayStart = info->runwayPrep;
357+
if (it->m_wasInLine)
358+
{
359+
info->runwayStart = info->runwayPrep;
360+
}
361+
break;
358362
}
359363
}
360364

@@ -383,6 +387,7 @@ void ParkingPlaceBehavior::releaseSpace(ObjectID id)
383387
it->m_postponedRunwayReservationForTakeoff = false;
384388
if (pu)
385389
pu->setHoldDoorOpen(it->m_door, false);
390+
break;
386391
}
387392
}
388393
}
@@ -402,11 +407,15 @@ void ParkingPlaceBehavior::transferRunwayReservationToNextInLineForTakeoff(Objec
402407
purgeDead();
403408
for (std::vector<RunwayInfo>::iterator it = m_runways.begin(); it != m_runways.end(); ++it)
404409
{
405-
if (it->m_inUseBy == id && it->m_nextInLineForTakeoff != INVALID_ID)
410+
if (it->m_inUseBy == id)
406411
{
407-
it->m_inUseBy = it->m_nextInLineForTakeoff;
408-
it->m_wasInLine = true;
409-
it->m_nextInLineForTakeoff = INVALID_ID;
412+
if (it->m_nextInLineForTakeoff != INVALID_ID)
413+
{
414+
it->m_inUseBy = it->m_nextInLineForTakeoff;
415+
it->m_wasInLine = true;
416+
it->m_nextInLineForTakeoff = INVALID_ID;
417+
}
418+
break;
410419
}
411420
}
412421
}

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ void FlightDeckBehavior::calcPPInfo( ObjectID id, PPInfo *info )
569569
if (it->m_inUseByForTakeoff == id )
570570
{
571571
info->runwayStart = info->runwayPrep;
572+
break;
572573
}
573574
}
574575
}
@@ -586,6 +587,7 @@ void FlightDeckBehavior::releaseSpace(ObjectID id)
586587
if (it->m_objectInSpace == id)
587588
{
588589
it->m_objectInSpace = INVALID_ID;
590+
break;
589591
}
590592
}
591593

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,13 @@ void ParkingPlaceBehavior::calcPPInfo( ObjectID id, PPInfo *info )
410410

411411
for (std::vector<RunwayInfo>::iterator it = m_runways.begin(); it != m_runways.end(); ++it)
412412
{
413-
if (it->m_inUseBy == id && it->m_wasInLine)
413+
if (it->m_inUseBy == id)
414414
{
415-
info->runwayStart = info->runwayPrep;
415+
if (it->m_wasInLine)
416+
{
417+
info->runwayStart = info->runwayPrep;
418+
}
419+
break;
416420
}
417421
}
418422
}
@@ -434,6 +438,7 @@ void ParkingPlaceBehavior::releaseSpace(ObjectID id)
434438
it->m_postponedRunwayReservationForTakeoff = false;
435439
if (pu)
436440
pu->setHoldDoorOpen(it->m_door, false);
441+
break;
437442
}
438443
}
439444

@@ -461,11 +466,15 @@ void ParkingPlaceBehavior::transferRunwayReservationToNextInLineForTakeoff(Objec
461466
purgeDead();
462467
for (std::vector<RunwayInfo>::iterator it = m_runways.begin(); it != m_runways.end(); ++it)
463468
{
464-
if (it->m_inUseBy == id && it->m_nextInLineForTakeoff != INVALID_ID)
469+
if (it->m_inUseBy == id)
465470
{
466-
it->m_inUseBy = it->m_nextInLineForTakeoff;
467-
it->m_wasInLine = true;
468-
it->m_nextInLineForTakeoff = INVALID_ID;
471+
if (it->m_nextInLineForTakeoff != INVALID_ID)
472+
{
473+
it->m_inUseBy = it->m_nextInLineForTakeoff;
474+
it->m_wasInLine = true;
475+
it->m_nextInLineForTakeoff = INVALID_ID;
476+
}
477+
break;
469478
}
470479
}
471480
}

0 commit comments

Comments
 (0)