fix: INPUT toggle no longer disrupts CLK timing in waveform
recordSample() (triggered by user INPUT toggle) now only advances timeStep when the simulation is stopped. When sim is running, it records at the current timeStep without advancing it, so the clock's regular tick cadence is never stolen by manual interactions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,11 @@ export function getGateLabel(gate) {
|
||||
return `${gate.type}_${idx}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a sample triggered by user interaction (INPUT toggle).
|
||||
* When sim is running, records at current timeStep WITHOUT advancing it.
|
||||
* When sim is stopped, advances timeStep first.
|
||||
*/
|
||||
export function recordSample() {
|
||||
const { gates, waveData } = state;
|
||||
|
||||
@@ -31,8 +36,11 @@ export function recordSample() {
|
||||
|
||||
if (!changed && state.timeStep > 0) return;
|
||||
|
||||
// Manual toggles advance by simSpeed too for consistency
|
||||
// Only advance time if sim is NOT running (manual mode)
|
||||
if (!state.simRunning) {
|
||||
state.timeStep += state.simSpeed;
|
||||
}
|
||||
|
||||
gates.forEach(g => {
|
||||
if (!waveData[g.id]) waveData[g.id] = [];
|
||||
const arr = waveData[g.id];
|
||||
@@ -43,8 +51,11 @@ export function recordSample() {
|
||||
updateWaveInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a sample from the simulation tick.
|
||||
* Always advances timeStep — this is the ONLY source of time when sim is running.
|
||||
*/
|
||||
export function forceRecordSample() {
|
||||
// Advance time by the current simSpeed (in ms) to reflect real time
|
||||
state.timeStep += state.simSpeed;
|
||||
state.gates.forEach(g => {
|
||||
if (!state.waveData[g.id]) state.waveData[g.id] = [];
|
||||
|
||||
Reference in New Issue
Block a user