Skip to content
Permalink
Browse files

Combined unit and weapon slow update loops.

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 7ff7596f05d8f3d2002f7798a0e98cf74caf687a
Showing with 1 addition and 23 deletions.
  1. +1 −22 rts/Sim/Units/UnitHandler.cpp
  2. +0 −1 rts/Sim/Units/UnitHandler.h
@@ -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)
@@ -49,7 +48,6 @@ void CUnitHandler::PostLoad()
{
// reset any synced stuff that is not saved
activeSlowUpdateUnit = activeUnits.end();
activeSlowUpdateWeapon = activeUnits.end();
}


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

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

@@ -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) {
@@ -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");

@@ -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

0 comments on commit 7ff7596

Please sign in to comment.
You can’t perform that action at this time.