From fddf2cabab581e71bf04f0f91d468cd1384de345 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 5 Jun 2020 18:06:45 +0200 Subject: [PATCH] Rework ScriptIterator to jump to first value on reset. --- .../ScriptHandling/ScriptAggregator.hpp | 47 +++++++++++-------- src/Battling/ScriptHandling/ScriptSet.hpp | 2 +- src/Battling/ScriptHandling/ScriptWrapper.hpp | 13 +++-- .../ScriptTests/ScriptAggregatorTests.cpp | 17 ++++--- .../ScriptTests/ScriptSourceTest.cpp | 9 ++-- 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/Battling/ScriptHandling/ScriptAggregator.hpp b/src/Battling/ScriptHandling/ScriptAggregator.hpp index 7910b41..da329ac 100644 --- a/src/Battling/ScriptHandling/ScriptAggregator.hpp +++ b/src/Battling/ScriptHandling/ScriptAggregator.hpp @@ -14,6 +14,25 @@ namespace CreatureLib::Battling { size_t _index = 0; size_t _setIndex = 0; + inline void IncrementToNextNotNull(bool initialIncrement = true) { + if (_scripts[_index].IsSet()) { + _setIndex++; + if (_setIndex >= _scripts[_index].GetScriptSet()->Count()) { + _setIndex = 0; + } else { + return; + } + } + if (initialIncrement) + _index++; + while (HasNext()) { + if (_scripts[_index].HasValue()) { + return; + } + _index++; + } + } + public: ScriptAggregator(){}; explicit ScriptAggregator(const ArbUt::List& scripts) @@ -21,11 +40,12 @@ namespace CreatureLib::Battling { inline void Reset() { _index = 0; - _setIndex = 0; + _setIndex = -1; + IncrementToNextNotNull(false); } inline bool HasNext() { return _index < _size; } - Script* GetNextNotNull() { + ArbUt::BorrowedPtr