From 7ff7596f05d8f3d2002f7798a0e98cf74caf687a Mon Sep 17 00:00:00 2001 From: Eshed Date: Tue, 30 Jun 2015 17:55:12 +0300 Subject: [PATCH] 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). --- rts/Sim/Units/UnitHandler.cpp | 23 +---------------------- rts/Sim/Units/UnitHandler.h | 1 - 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/rts/Sim/Units/UnitHandler.cpp b/rts/Sim/Units/UnitHandler.cpp index 161f2578a8b..516544c9aa6 100644 --- a/rts/Sim/Units/UnitHandler.cpp +++ b/rts/Sim/Units/UnitHandler.cpp @@ -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 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"); diff --git a/rts/Sim/Units/UnitHandler.h b/rts/Sim/Units/UnitHandler.h index c7e375dd39b..9aaf80c6203 100644 --- a/rts/Sim/Units/UnitHandler.h +++ b/rts/Sim/Units/UnitHandler.h @@ -66,7 +66,6 @@ class CUnitHandler std::vector unitsToBeRemoved; ///< units that will be removed at start of next update std::list::iterator activeSlowUpdateUnit; ///< first unit of batch that will be SlowUpdate'd this frame - std::list::iterator activeSlowUpdateWeapon; ///< global unit-limit (derived from the per-team limit) ///< units.size() is equal to this and constant at runtime