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:
1 parent
7ce412e52e
commit
f4a4d48e3f
2 files changed
+23
-11
No files matched your search
@@ -868,23 +868,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const update = (clock) => {
|
const update = (clock) => {
|
||||||
const elapsed = Cesium.JulianDate.secondsDifference(clock.currentTime, agents[0]?.state.lastTime || start);
|
const rawElapsed = Cesium.JulianDate.secondsDifference(clock.currentTime, agents[0]?.state.lastTime || start);
|
||||||
if (!(elapsed > 0) || elapsed > 2) {
|
if (!(rawElapsed > 0)) return;
|
||||||
for (const agent of agents) Cesium.JulianDate.clone(clock.currentTime, agent.state.lastTime);
|
// Clamp long frames instead of freezing the whole simulation; small
|
||||||
return;
|
// steps keep IDM deceleration clamps effective near stop lines.
|
||||||
}
|
const elapsed = Math.min(rawElapsed, 0.25);
|
||||||
for (const peers of byTemplate.values()) {
|
for (const peers of byTemplate.values()) {
|
||||||
peers.sort((a, b) => a.state.distance - b.state.distance);
|
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 elapsedFromStart = Cesium.JulianDate.secondsDifference(clock.currentTime, start);
|
||||||
|
const trafficElapsed = Math.max(0, elapsedFromStart);
|
||||||
const present = (agent) => agent.state.active && elapsedFromStart >= agent.state.spawnDelay;
|
const present = (agent) => agent.state.active && elapsedFromStart >= agent.state.spawnDelay;
|
||||||
const ordered = [...agents].sort((a, b) => b.state.distance - a.state.distance);
|
const ordered = [...agents].sort((a, b) => b.state.distance - a.state.distance);
|
||||||
for (const agent of ordered) {
|
for (const agent of ordered) {
|
||||||
const state = agent.state;
|
const state = agent.state;
|
||||||
Cesium.JulianDate.clone(clock.currentTime, state.lastTime);
|
Cesium.JulianDate.clone(clock.currentTime, state.lastTime);
|
||||||
const ready = elapsedFromStart >= state.spawnDelay;
|
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 (!ready) continue;
|
||||||
if (state.isMoving && !state.isMoving()) {
|
if (state.isMoving && !state.isMoving()) {
|
||||||
state.speed = 0;
|
state.speed = 0;
|
||||||
@@ -895,7 +895,8 @@
|
|||||||
state.respawnDelay -= elapsed;
|
state.respawnDelay -= elapsed;
|
||||||
if (state.respawnDelay <= 0) {
|
if (state.respawnDelay <= 0) {
|
||||||
const entryBlocked = agents.some((other) => other !== agent && present(other)
|
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);
|
&& other.state.distance < entryDistance(agent) + agent.length + other.length + minimumGapMeters);
|
||||||
if (entryBlocked) continue;
|
if (entryBlocked) continue;
|
||||||
state.active = true;
|
state.active = true;
|
||||||
@@ -983,8 +984,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const queueKey = (agent.template.kind === "pedestrian" || agent.template.kind === "bicycle")
|
const queueKey = (agent.template.kind === "pedestrian" || agent.template.kind === "bicycle")
|
||||||
? (agent.template.crossingId || agent.template)
|
? (agent.template.crossingId || agent.template.id)
|
||||||
: (agent.template.approachLaneId || agent.template.id);
|
: (agent.template.approachLaneId || agent.template.approachRoadId || agent.template.id);
|
||||||
const peers = byTemplate.get(queueKey) || [];
|
const peers = byTemplate.get(queueKey) || [];
|
||||||
let leaderAgent = null;
|
let leaderAgent = null;
|
||||||
const leader = peers.filter((candidate) => candidate !== agent && present(candidate)
|
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 };
|
return { participants: withFleet, diagnostics };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user