fix: correct participant simulation timing and queue key fallbacks

- Align signal phase evaluation with the Cesium simulation clock so speed
  control multipliers keep vehicles and traffic lights in sync
- Clamp long frame gaps instead of freezing all participants; short steps
  keep IDM deceleration clamps effective near stop lines
- Fall back to approachRoadId for lane grouping when movement.fromLaneId
  is missing, preventing side-by-side vehicle overlap on shared lanes
- Guard against a missing toggleVehicles DOM element inside the tick loop
- Use template.id as the pedestrian queue key for consistent Map lookups
- Report participant_route_too_short diagnostics instead of silently
  dropping pedestrian and bicycle templates shorter than 5 m
This commit is contained in:
que01 committed 2026-10-10 16:07:53 +08:00
1 parent 7ce412e52e
commit f4a4d48e3f
2 files changed
+23 -11

No files matched your search

+11 -10
View File
@@ -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)
@@ -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 };
}