Skip to content

Color rails by traffic#53

Merged
lukacslacko merged 1 commit into
black-railsfrom
traffic-colors
Jun 27, 2025
Merged

Color rails by traffic#53
lukacslacko merged 1 commit into
black-railsfrom
traffic-colors

Conversation

@lukacslacko

Copy link
Copy Markdown
Owner

No description provided.

@lukacslacko lukacslacko requested review from Copilot and papjuli June 15, 2025 15:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces traffic-based coloring for rails by tracking and visualizing segment usage.

  • Added a global max_rail_usage counter to State and 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_max together with count.max(...) can be confusing. Consider calling state.max_rail_usage.fetch_max(count, Ordering::Relaxed) first, then loading the updated maximum with state.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));

Comment thread src/ui.rs
.insert((MeshMaterial3d(material.clone()),));
rail_info.entity
} else {
if let std::collections::hash_map::Entry::Vacant(e) = state.rails.rails.entry(rail) {

Copilot AI Jun 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/ui.rs
crate::state::Config::default().perlin_config.seed as u64,
),
create_new_city_next: true,
max_rail_usage: 0.into(),

Copilot AI Jun 15, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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),

Copilot uses AI. Check for mistakes.
@lukacslacko lukacslacko merged commit 05ab285 into black-rails Jun 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants