From 35405534e76870f0da0b88927b646c26dd58f5e8 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Tue, 9 Oct 2018 21:33:37 +0200 Subject: [PATCH] Improved function for destroying effects Old version (needlessly) iterates on all vector --- rwengine/src/engine/GameWorld.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rwengine/src/engine/GameWorld.cpp b/rwengine/src/engine/GameWorld.cpp index 28c6d492..cfaeec65 100644 --- a/rwengine/src/engine/GameWorld.cpp +++ b/rwengine/src/engine/GameWorld.cpp @@ -552,10 +552,13 @@ TrailFX& GameWorld::createTrailEffect() { } void GameWorld::destroyEffect(VisualFX& effect) { - effects.erase( - std::remove_if(effects.begin(), effects.end(), - [&effect](auto& ef) { return ef.get() == &effect; }), - effects.end()); + auto found = + std::find_if(effects.begin(), effects.end(), + [&effect](auto& ef) { return ef.get() == &effect; }); + + if (found != effects.end()) { + effects.erase(found); + } } void GameWorld::doWeaponScan(const WeaponScan& scan) {