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:
Jose Luis
2026-03-20 03:19:28 +01:00
parent f0f3516efa
commit d78b45841c

View File

@@ -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
state.timeStep += state.simSpeed;
// 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] = [];