From 88a0e4b8d409c21ee704cbb22301f56ea46f1648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 11 Jan 2024 17:34:32 +0200 Subject: [PATCH] Apply review suggestions, remove redundant comment --- src/openrct2/scripting/ScriptEngine.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index aa57a2c176..10e8a7bd97 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -1597,16 +1597,10 @@ void ScriptEngine::SetParkStorageFromJSON(std::string_view value) IntervalHandle ScriptEngine::AllocateHandle() { - auto res = _nextIntervalHandle; - _nextIntervalHandle++; - // In case of overflow start from 1 again - if (_nextIntervalHandle == 0) - { - _nextIntervalHandle = 1; - } + _nextIntervalHandle = std::max(_nextIntervalHandle++, 1U); - return res; + return _nextIntervalHandle; } IntervalHandle ScriptEngine::AddInterval(const std::shared_ptr& plugin, int32_t delay, bool repeat, DukValue&& callback) @@ -1657,7 +1651,6 @@ void ScriptEngine::UpdateIntervals() } _lastIntervalTimestamp = timestamp; - // This loop needs to account for removal and insertions during iteration. for (auto it = _intervals.begin(), itNext = it; it != _intervals.end(); it = itNext) { itNext++; @@ -1686,10 +1679,11 @@ void ScriptEngine::RemoveIntervals(const std::shared_ptr& plugin) if (interval.Owner == plugin) { it = _intervals.erase(it); - continue; } - - it++; + else + { + it++; + } } }