Skip to content

Commit

Permalink
Don't pause auto-tick unnecessarily in Optimize()
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusTomlinson committed Jan 2, 2024
1 parent 5ef1331 commit 397acd4
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/Circuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
// =========================================================
Expand Down Expand Up @@ -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<DSPatch::Component*> orderedComponents;
orderedComponents.reserve( components.size() );
std::vector<DSPatch::Component*> 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;
}

0 comments on commit 397acd4

Please sign in to comment.