12#include <QGraphicsItem>
115 static QHash<QString, GraphicElement *>
buildTxMap(
const QVector<GraphicElement *> &elements);
119 const QVector<GraphicElement *> &elements,
120 const QHash<QString, GraphicElement *> &txMap);
131 const QHash<
GraphicElement *, QVector<GraphicElement *>> &successors);
149 bool updateWithIterativeSettling(
const QVector<GraphicElement *> &elements);
150 void sortSimElements(
const QVector<GraphicElement *> &elements);
153 void pushVisualStatuses(
const QVector<GraphicElement *> &elements,
const QVector<GraphicElement *> &outputs);
158 void collectSequentialElements(
const QVector<GraphicElement *> &elements);
163 QVector<Clock *> m_clocks;
164 QVector<GraphicElement *> m_outputs;
165 QVector<GraphicElementInput *> m_inputs;
173 bool m_initialized =
false;
174 bool m_convergenceWarned =
false;
175 bool m_userMuted =
false;
182 bool m_atFixedPoint =
false;
186 bool m_visualsDirty =
true;
190 int m_visualTickCount = 0;
191 int m_visualTickInterval = 16;
192 bool m_visualThrottleEnabled =
true;
196 QVector<GraphicElement *> m_sortedElements;
200 QVector<GraphicElement *> m_sequentialElements;
201 QHash<const GraphicElement *, int> m_simPriorities;
202 QSet<const GraphicElement *> m_simFeedbackNodes;
203 bool m_simHasFeedbackElements =
false;
Event-driven real-time clock input element.
Abstract base class for all graphical circuit elements in wiRedPanda.
A port that drives a signal (the source end of a wire).
Narrow interface letting Simulation reach its host scene without naming the concrete Scene class.
void update()
Executes one simulation step (used by tests to advance the simulation manually).
static SortResult topologicalSort(const QVector< GraphicElement * > &elements, const QHash< GraphicElement *, QVector< GraphicElement * > > &successors)
Topologically sorts elements using the successor graph, detects feedback loops.
void setVisualThrottleEnabled(bool enabled)
Simulation(SimulationHost *host, QObject *parent=nullptr)
Constructs a Simulation bound to host.
static bool iterativeSettle(const QVector< GraphicElement * > &elements, int maxIterations=kMaxSettleIterations)
static QHash< QString, GraphicElement * > buildTxMap(const QVector< GraphicElement * > &elements)
Builds a label→element map for wireless Tx nodes. First Tx per label wins.
void setUserMuted(bool muted)
Sets whether the user has explicitly muted audio; persists across stop/start cycles.
void simulationWarning(const QString &message)
Emitted (at most once per initialize()) when a feedback circuit fails to converge.
friend class TestDanglingPointer
static void buildConnectionGraph(const QVector< GraphicElement * > &elements)
bool initialize()
Builds the simulation graph from the current scene elements.
static void connectWirelessElements(const QVector< GraphicElement * > &elements)
static QHash< GraphicElement *, QVector< GraphicElement * > > buildSuccessorGraph(const QVector< GraphicElement * > &elements, const QHash< QString, GraphicElement * > &txMap)
Builds a successor adjacency list from connection graph + wireless Tx→Rx edges.
static constexpr int kMaxSettleIterations
void start()
Starts the 1 ms simulation timer.
bool isRunning()
Returns true if the simulation timer is currently running.
~Simulation() override=default
Destructor; stops the simulation timer.
bool isUserMuted() const
Returns true if the user has explicitly muted audio.
bool isInFeedbackLoop(const GraphicElement *element) const
Returns true if element is part of a combinational feedback loop.
void stop()
Stops the simulation timer.
Result of topological sort with feedback detection.
QSet< GraphicElement * > feedbackNodes
Elements in feedback loops.
QVector< GraphicElement * > sorted
Elements in priority order (highest first).
QHash< GraphicElement *, int > priorities
Priority per element.