Color rails by traffic#53
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces traffic-based coloring for rails by tracking and visualizing segment usage.
- Added a global
max_rail_usagecounter toStateand initialized it in the UI setup. - Updated the train update logic to increment per-rail counters, update the global maximum, and compute rail colors based on usage.
- Simplified the UI’s path rendering by removing dynamic start/end coloring and refactoring entity insertion.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/ui.rs | Initialized max_rail_usage, refactored rail entity insertion, and set default path color to white |
| src/train.rs | Incremented per-rail usage, updated global max via fetch_max, and applied heatmap coloring |
| src/state.rs | Added max_rail_usage: AtomicUsize field to the application State |
Comments suppressed due to low confidence (1)
src/train.rs:133
- [nitpick] Using the return value of
fetch_maxtogether withcount.max(...)can be confusing. Consider callingstate.max_rail_usage.fetch_max(count, Ordering::Relaxed)first, then loading the updated maximum withstate.max_rail_usage.load(Ordering::Relaxed)to make the intent clearer.
let max_rail_usage = count.max(state.max_rail_usage.fetch_max(count, Ordering::Relaxed));
| .insert((MeshMaterial3d(material.clone()),)); | ||
| rail_info.entity | ||
| } else { | ||
| if let std::collections::hash_map::Entry::Vacant(e) = state.rails.rails.entry(rail) { |
There was a problem hiding this comment.
Using Entry::Vacant only handles the case where the rail is absent; the occupied case isn’t handled, and entity is unbound outside the block. Consider using match state.rails.rails.entry(rail) to cover both Occupied and Vacant branches and bind entity accordingly.
| crate::state::Config::default().perlin_config.seed as u64, | ||
| ), | ||
| create_new_city_next: true, | ||
| max_rail_usage: 0.into(), |
There was a problem hiding this comment.
[nitpick] Using 0.into() to initialize an AtomicUsize can be unclear. Consider using AtomicUsize::new(0) for explicitness and readability.
Suggested change
| max_rail_usage: 0.into(), | |
| max_rail_usage: AtomicUsize::new(0), |
papjuli
approved these changes
Jun 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.