From 397acd44309d7be52b8acdfd65625b970caadec1 Mon Sep 17 00:00:00 2001 From: Marcus Tomlinson Date: Tue, 2 Jan 2024 12:51:23 +0000 Subject: [PATCH] Don't pause auto-tick unnecessarily in Optimize() --- src/Circuit.cpp | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/Circuit.cpp b/src/Circuit.cpp index 708e221a..1c356c84 100644 --- a/src/Circuit.cpp +++ b/src/Circuit.cpp @@ -242,7 +242,10 @@ int Circuit::GetBufferCount() const void Circuit::Tick() { - p->Optimize(); + if ( p->circuitDirty ) + { + p->Optimize(); + } // process in a single thread if this circuit has no threads // ========================================================= @@ -318,31 +321,32 @@ void Circuit::ResumeAutoTick() void Circuit::Optimize() { - PauseAutoTick(); - p->Optimize(); - ResumeAutoTick(); + if ( p->circuitDirty ) + { + PauseAutoTick(); + p->Optimize(); + ResumeAutoTick(); + } } inline void internal::Circuit::Optimize() { - if ( circuitDirty ) - { - std::vector orderedComponents; - orderedComponents.reserve( components.size() ); + std::vector orderedComponents; + orderedComponents.reserve( components.size() ); - for ( auto& component : components ) - { - component->_Scan( orderedComponents ); - } + // scan for optimal component order + for ( auto& component : components ) + { + component->_Scan( orderedComponents ); + } - // reset all internal components - for ( auto& component : components ) - { - component->_EndScan(); - } + // reset all isScanning flags + for ( auto& component : components ) + { + component->_EndScan(); + } - components = std::move( orderedComponents ); + components = std::move( orderedComponents ); - circuitDirty = false; - } + circuitDirty = false; }