From 5dbe51d871ae6cadb4bac67f819b980724d8706a Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Sat, 1 Nov 2025 11:34:46 +0100 Subject: [PATCH 1/2] fix bug: initialization output events were not properly routed to the plant --- src/statecharts/interpreter.ts | 1 - src/statecharts/timed_reactive.ts | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/statecharts/interpreter.ts b/src/statecharts/interpreter.ts index 389c0ec..94cab86 100644 --- a/src/statecharts/interpreter.ts +++ b/src/statecharts/interpreter.ts @@ -394,7 +394,6 @@ export function fire(simtime: number, t: Transition, ts: Map"), label); for (const action of label.actions) { - console.log('environment after adding event param:', environment); ({environment, history, ...rest} = execAction(action, {environment, history, ...rest}, [t.uid])); } environment = environment.dropScope(); diff --git a/src/statecharts/timed_reactive.ts b/src/statecharts/timed_reactive.ts index c842059..57f4b29 100644 --- a/src/statecharts/timed_reactive.ts +++ b/src/statecharts/timed_reactive.ts @@ -115,6 +115,7 @@ export function coupledExecution(models: {[name if (events.length > 0) { const [event, ...rest] = events; const destination = conns[model+'.'+event.name]; + console.log(model, '.', event, destination); if (destination === undefined) { // ignore console.log(`${model}.${event.name} goes nowhere`); @@ -160,11 +161,13 @@ export function coupledExecution(models: {[name // @ts-ignore state[modelName] = modelState; } + console.log('all outputs:', allOutputs); // 2. handle all output events (models' outputs may be inputs for each other) let finalOutputs = []; - for (const [modelName, outputEvents] of allOutputs) { + for (const [modelName, outputEvent] of allOutputs) { + console.log('what about', modelName, outputEvent); let newOutputs; - [newOutputs, state] = processOutputs(0, outputEvents, modelName, state); + [newOutputs, state] = processOutputs(0, [outputEvent], modelName, state); finalOutputs.push(...newOutputs); } return [finalOutputs, state]; From 254dbaf2fd03244882d1778cbd7b065ce5b4d56e Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Sat, 1 Nov 2025 11:36:18 +0100 Subject: [PATCH 2/2] traffic light: every color has its own buzz sound volume --- src/App/Plant/TrafficLight/TrafficLight.tsx | 22 +++++++++++---------- src/App/useAudioContext.ts | 9 ++++++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/App/Plant/TrafficLight/TrafficLight.tsx b/src/App/Plant/TrafficLight/TrafficLight.tsx index 8ffd4da..b014573 100644 --- a/src/App/Plant/TrafficLight/TrafficLight.tsx +++ b/src/App/Plant/TrafficLight/TrafficLight.tsx @@ -40,21 +40,23 @@ export const TrafficLight = memo(function TrafficLight({state, speed, raiseUIEve // preloadAudio(sndAtmosphere); - // the traffic light makes sound too: + // play wind useEffect(() => { const stopPlaying = playURL(sndAtmosphere, true); return () => stopPlaying(); }, []); - useEffect(() => { - if (redOn || yellowOn || greenOn) { - const stopPlaying = playURL(sndBuzz, true); - return () => { - stopPlaying(); - }; - } - else return () => {}; - }, [redOn || yellowOn || greenOn]) + // for added realism, every light color has its own buzzing noise volume + for (const [color, gain] of [[redOn, 0.5], [yellowOn, 1], [greenOn, 0.3]] as [boolean, number][]) { + useEffect(() => { + if (color) { + const stopPlaying = playURL(sndBuzz, true, gain); + return () => { + stopPlaying(); + }; + } + }, [color]); + } return <>