Skip to content

Commit

Permalink
Combined unit and weapon slow update loops.
Browse files Browse the repository at this point in the history
Fix #4862
If a unit was inserted during the unit slowUpdate process, between
activeSlowUpdateWeapon and activeSlowUpdateUnit, it caused them to diverge
(because the new unit had its weapons slowupdated instead of another
unit).
Then when the activeSlowUpdateWeapon was deleted, the iterator wasn't
advanced (since the test only checks activeSlowUpdateUnit).
  • Loading branch information
ashdnazg committed Jun 30, 2015
1 parent bdc2662 commit 7ff7596
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
23 changes: 1 addition & 22 deletions rts/Sim/Units/UnitHandler.cpp
Expand Up @@ -37,7 +37,6 @@ CR_REG_METADATA(CUnitHandler, (
CR_MEMBER(idPool),
CR_MEMBER(unitsToBeRemoved),
CR_IGNORED(activeSlowUpdateUnit),
CR_IGNORED(activeSlowUpdateWeapon),
CR_MEMBER(maxUnits),
CR_MEMBER(maxUnitRadius),
CR_POSTLOAD(PostLoad)
Expand All @@ -49,7 +48,6 @@ void CUnitHandler::PostLoad()
{
// reset any synced stuff that is not saved
activeSlowUpdateUnit = activeUnits.end();
activeSlowUpdateWeapon = activeUnits.end();
}


Expand Down Expand Up @@ -77,7 +75,6 @@ CUnitHandler::CUnitHandler()
idPool.Expand(0, units.size());

activeSlowUpdateUnit = activeUnits.end();
activeSlowUpdateWeapon = activeUnits.end();
airBaseHandler = new CAirBaseHandler();
}

Expand Down Expand Up @@ -142,7 +139,6 @@ void CUnitHandler::DeleteUnitNow(CUnit* delUnit)
{
if (activeSlowUpdateUnit != activeUnits.end() && delUnit == *activeSlowUpdateUnit) {
++activeSlowUpdateUnit;
++activeSlowUpdateWeapon;
}

for (auto usi = activeUnits.begin(); usi != activeUnits.end(); ++usi) {
Expand Down Expand Up @@ -273,30 +269,13 @@ void CUnitHandler::Update()

UNIT_SANITY_CHECK(unit);
unit->SlowUpdate();
unit->SlowUpdateWeapons();
UNIT_SANITY_CHECK(unit);

n--;
}
}

{
SCOPED_TIMER("Unit::Weapon::SlowUpdate");

// reset the iterator every <UNIT_SLOWUPDATE_RATE> frames
if ((gs->frameNum % UNIT_SLOWUPDATE_RATE) == 0) {
activeSlowUpdateWeapon = activeUnits.begin();
}

// stagger the SlowUpdate's
unsigned int n = (activeUnits.size() / UNIT_SLOWUPDATE_RATE) + 1;

for (; activeSlowUpdateWeapon != activeUnits.end() && n != 0; ++activeSlowUpdateWeapon) {
CUnit* unit = *activeSlowUpdateWeapon;
unit->SlowUpdateWeapons();
n--;
}
}

{
SCOPED_TIMER("Unit::Update");

Expand Down
1 change: 0 additions & 1 deletion rts/Sim/Units/UnitHandler.h
Expand Up @@ -66,7 +66,6 @@ class CUnitHandler

std::vector<CUnit*> unitsToBeRemoved; ///< units that will be removed at start of next update
std::list<CUnit*>::iterator activeSlowUpdateUnit; ///< first unit of batch that will be SlowUpdate'd this frame
std::list<CUnit*>::iterator activeSlowUpdateWeapon;

///< global unit-limit (derived from the per-team limit)
///< units.size() is equal to this and constant at runtime
Expand Down

0 comments on commit 7ff7596

Please sign in to comment.