chore(simulation): cargo fmt atlas modules

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-03 09:46:16 +02:00
co-authored by Claude Opus 4.6
parent 64a873fc1a
commit f1278f88fd
10 changed files with 247 additions and 137 deletions
+56 -33
View File
@@ -55,7 +55,10 @@ pub enum GenWorkItem {
/// Generate a Phase 1 DistrictSkeleton for this city.
GenerateSkeleton { city_id: u64 },
/// Pre-fill a chunk in an existing district.
FillChunk { district_id: u64, block_pos: (u32, u32) },
FillChunk {
district_id: u64,
block_pos: (u32, u32),
},
}
impl GenWorkItem {
@@ -75,11 +78,21 @@ impl GenWorkItem {
/// Sent back to the main thread when a work item finishes (D-206).
#[derive(Debug)]
pub enum GenCompletion {
BodyAnalyzed { body_id: String },
SkeletonGenerated { city_id: u64 },
ChunkFilled { district_id: u64, block_pos: (u32, u32) },
BodyAnalyzed {
body_id: String,
},
SkeletonGenerated {
city_id: u64,
},
ChunkFilled {
district_id: u64,
block_pos: (u32, u32),
},
/// Work item failed — body_id or city_id for logging.
Failed { item: GenWorkItem, reason: String },
Failed {
item: GenWorkItem,
reason: String,
},
}
// ---------------------------------------------------------------------------
@@ -114,11 +127,7 @@ pub struct GenerationQueue {
impl std::fmt::Debug for GenerationQueue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let pending_len = self
.pending
.lock()
.map(|p| p.len())
.unwrap_or(0);
let pending_len = self.pending.lock().map(|p| p.len()).unwrap_or(0);
f.debug_struct("GenerationQueue")
.field("pending_count", &pending_len)
.finish()
@@ -168,9 +177,7 @@ impl GenerationQueue {
drop(in_flight);
// Check pending list.
let pending = self.pending.lock().unwrap();
if pending.iter().any(|q| {
q.item.body_id() == Some(body_id)
}) {
if pending.iter().any(|q| q.item.body_id() == Some(body_id)) {
return;
}
drop(pending);
@@ -216,10 +223,7 @@ impl GenerationQueue {
// Mark body as in-flight.
if let Some(body_id) = item.body_id() {
self.in_flight
.lock()
.unwrap()
.insert(body_id.to_string());
self.in_flight.lock().unwrap().insert(body_id.to_string());
}
let tx = self.completion_tx.clone();
@@ -261,18 +265,19 @@ impl Default for GenerationQueue {
/// immediate success to allow the queue infrastructure to be tested independently.
fn run_work_item(item: &GenWorkItem) -> GenCompletion {
match item {
GenWorkItem::AnalyzeBody { body_id } => {
GenCompletion::BodyAnalyzed { body_id: body_id.clone() }
}
GenWorkItem::AnalyzeBody { body_id } => GenCompletion::BodyAnalyzed {
body_id: body_id.clone(),
},
GenWorkItem::GenerateSkeleton { city_id } => {
GenCompletion::SkeletonGenerated { city_id: *city_id }
}
GenWorkItem::FillChunk { district_id, block_pos } => {
GenCompletion::ChunkFilled {
district_id: *district_id,
block_pos: *block_pos,
}
}
GenWorkItem::FillChunk {
district_id,
block_pos,
} => GenCompletion::ChunkFilled {
district_id: *district_id,
block_pos: *block_pos,
},
}
}
@@ -293,7 +298,9 @@ mod tests {
fn submit_and_drain() {
let q = make_queue();
q.submit(
GenWorkItem::AnalyzeBody { body_id: "TestBody".to_string() },
GenWorkItem::AnalyzeBody {
body_id: "TestBody".to_string(),
},
GenPriority::Medium,
);
// Give Rayon time to complete the (stub) task.
@@ -311,11 +318,15 @@ mod tests {
let q = make_queue();
// Submit the same body twice before it can complete.
q.submit(
GenWorkItem::AnalyzeBody { body_id: "Dup".to_string() },
GenWorkItem::AnalyzeBody {
body_id: "Dup".to_string(),
},
GenPriority::Low,
);
q.submit(
GenWorkItem::AnalyzeBody { body_id: "Dup".to_string() },
GenWorkItem::AnalyzeBody {
body_id: "Dup".to_string(),
},
GenPriority::Low,
);
std::thread::sleep(Duration::from_millis(50));
@@ -329,9 +340,18 @@ mod tests {
// Submit three items rapidly; Immediate should be dispatched first.
let q = make_queue();
// Using GenerateSkeleton (no dedup logic) to test ordering directly.
q.submit(GenWorkItem::GenerateSkeleton { city_id: 1 }, GenPriority::Low);
q.submit(GenWorkItem::GenerateSkeleton { city_id: 2 }, GenPriority::Immediate);
q.submit(GenWorkItem::GenerateSkeleton { city_id: 3 }, GenPriority::Medium);
q.submit(
GenWorkItem::GenerateSkeleton { city_id: 1 },
GenPriority::Low,
);
q.submit(
GenWorkItem::GenerateSkeleton { city_id: 2 },
GenPriority::Immediate,
);
q.submit(
GenWorkItem::GenerateSkeleton { city_id: 3 },
GenPriority::Medium,
);
std::thread::sleep(Duration::from_millis(100));
let completions = q.drain_completions();
assert_eq!(completions.len(), 3);
@@ -348,7 +368,10 @@ mod tests {
fn pending_count_decreases_after_completion() {
let q = make_queue();
q.submit(
GenWorkItem::FillChunk { district_id: 99, block_pos: (0, 0) },
GenWorkItem::FillChunk {
district_id: 99,
block_pos: (0, 0),
},
GenPriority::High,
);
std::thread::sleep(Duration::from_millis(50));