---
tags:
- CAGE_dev_log
- CAGE
- rust
- bevy
- game_dev
- road_system
---
# CAGE Dev Log - Day 5

Today I implemented the path locking system allowing car merging into one lane without crashing into each other.
Each car needs to propose its *intent*, and a *god* (temporarily called `schedule_intents`) will review each intent, and approve, trim, or reject them.
This implementation is a little bit naive and only scheduling by priorities.
Here's the simplied psuedocode for those systems:
### schedule_intents
```rust=
pub fn schedule_intents(
mut intents: Vec<PathLocks>
) {
for intent in intents.iter_mut() {
// for each segments
for lock in intent.locks {
for other_lock in other_already_locks {
if collision(lock, other_lock) {
// try to trim lock
if trim_lock(&mut lock) {
intent.path_locks.truncate(j + 1);
} else {
// lock with `lock_together` cannot be trim
// since some path needs to be lock together
// e.g. paths in the junction.
intent.path_locks.truncate(j);
pop_locks_until_no_group(&mut intent.path_locks);
}
break;
}
}
}
for other_lock in other_new_locks {
// trim lock or other_lock which has lower priority.
}
}
}
```
We should create a index to speedup the collision query later.