diff --git a/scripts/lib/cesium-preview.js b/scripts/lib/cesium-preview.js index a06d3bb..64bd051 100644 --- a/scripts/lib/cesium-preview.js +++ b/scripts/lib/cesium-preview.js @@ -868,23 +868,23 @@ } const update = (clock) => { - const elapsed = Cesium.JulianDate.secondsDifference(clock.currentTime, agents[0]?.state.lastTime || start); - if (!(elapsed > 0) || elapsed > 2) { - for (const agent of agents) Cesium.JulianDate.clone(clock.currentTime, agent.state.lastTime); - return; - } + const rawElapsed = Cesium.JulianDate.secondsDifference(clock.currentTime, agents[0]?.state.lastTime || start); + if (!(rawElapsed > 0)) return; + // Clamp long frames instead of freezing the whole simulation; small + // steps keep IDM deceleration clamps effective near stop lines. + const elapsed = Math.min(rawElapsed, 0.25); for (const peers of byTemplate.values()) { peers.sort((a, b) => a.state.distance - b.state.distance); } - const trafficElapsed = Math.max(0, (performance.now() - trafficEpochMs) / 1000); const elapsedFromStart = Cesium.JulianDate.secondsDifference(clock.currentTime, start); + const trafficElapsed = Math.max(0, elapsedFromStart); const present = (agent) => agent.state.active && elapsedFromStart >= agent.state.spawnDelay; const ordered = [...agents].sort((a, b) => b.state.distance - a.state.distance); for (const agent of ordered) { const state = agent.state; Cesium.JulianDate.clone(clock.currentTime, state.lastTime); const ready = elapsedFromStart >= state.spawnDelay; - if (agent.entity) agent.entity.show = state.active && ready && toggleVehicles.checked; + if (agent.entity) agent.entity.show = state.active && ready && toggleVehicles?.checked !== false; if (!ready) continue; if (state.isMoving && !state.isMoving()) { state.speed = 0; @@ -895,7 +895,8 @@ state.respawnDelay -= elapsed; if (state.respawnDelay <= 0) { const entryBlocked = agents.some((other) => other !== agent && present(other) - && (other.template.approachLaneId || other.template.crossingId) === (agent.template.approachLaneId || agent.template.crossingId) + && (other.template.approachLaneId || other.template.crossingId || other.template.approachRoadId) + === (agent.template.approachLaneId || agent.template.crossingId || agent.template.approachRoadId) && other.state.distance < entryDistance(agent) + agent.length + other.length + minimumGapMeters); if (entryBlocked) continue; state.active = true; @@ -983,8 +984,8 @@ } const queueKey = (agent.template.kind === "pedestrian" || agent.template.kind === "bicycle") - ? (agent.template.crossingId || agent.template) - : (agent.template.approachLaneId || agent.template.id); + ? (agent.template.crossingId || agent.template.id) + : (agent.template.approachLaneId || agent.template.approachRoadId || agent.template.id); const peers = byTemplate.get(queueKey) || []; let leaderAgent = null; const leader = peers.filter((candidate) => candidate !== agent && present(candidate) diff --git a/scripts/lib/native-preview-traffic-simulation.js b/scripts/lib/native-preview-traffic-simulation.js index 9787637..c7353ca 100644 --- a/scripts/lib/native-preview-traffic-simulation.js +++ b/scripts/lib/native-preview-traffic-simulation.js @@ -339,7 +339,18 @@ function buildParticipants({ compiled, connectorCollection, laneCenterlines, sto } } - const withFleet = participants.filter((participant) => participant.fleet > 0 && participant.lengthMeters > 5); + const withFleet = participants.filter((participant) => { + if (participant.fleet <= 0) return false; + if (participant.lengthMeters > 5) return true; + diagnostics.push({ + severity: "warning", + reason: "participant_route_too_short", + message: `${participant.id} route is ${round(participant.lengthMeters)} m; participants need > 5 m to schedule.`, + participantId: participant.id, + routeLengthMeters: participant.lengthMeters, + }); + return false; + }); return { participants: withFleet, diagnostics }; }