feat(simulation): ban HashMap via clippy disallowed_types, fix violations (#343)
Adds server/.clippy.toml with disallowed-types for std::collections::HashMap and std::collections::HashSet. HashMap iteration order is non-deterministic and breaks deterministic simulation replay (D-030). Changes: - server/.clippy.toml: disallow HashMap and HashSet crate-wide - simulation/movement.rs: WalkabilityMap.chunks and occupied map → BTreeMap; add PartialOrd+Ord to ChunkCoord, TilePosition, TilePresence - simulation/monologue.rs: MonologueState.shown_ids → BTreeSet (simulation state) - perception/shadowcast.rs: #![allow] — per-frame FOV scratch, iteration irrelevant - perception/interpretation.rs: #![allow] — per-frame lookup table, key-only access - perception/query.rs: #![allow] — sector_lookup is a per-frame read-only cache Also applies cargo fmt to pre-existing format drift in contraband.rs, dialogue.rs, test_world/mod.rs, and several integration tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -80,7 +80,10 @@ impl ScanEventBuffer {
|
||||
pub fn check_contraband_scan(
|
||||
time: Res<SimulationTime>,
|
||||
registry: Res<EntityRegistry>,
|
||||
mut npc_query: Query<(Entity, &TilePosition, &mut KnowledgeGraph), (With<Npc>, With<ScanAuthority>)>,
|
||||
mut npc_query: Query<
|
||||
(Entity, &TilePosition, &mut KnowledgeGraph),
|
||||
(With<Npc>, With<ScanAuthority>),
|
||||
>,
|
||||
mut player_query: Query<(Entity, &TilePosition, &mut ScanEventBuffer), With<PlayerCharacter>>,
|
||||
items_query: Query<(&CarriedBy, Option<&Contraband>)>,
|
||||
) {
|
||||
@@ -423,7 +426,10 @@ mod tests {
|
||||
|
||||
let mut buffer = world.get_mut::<ScanEventBuffer>(player).unwrap();
|
||||
let events = buffer.take();
|
||||
assert!(events.is_empty(), "NPC without ScanAuthority should not scan");
|
||||
assert!(
|
||||
events.is_empty(),
|
||||
"NPC without ScanAuthority should not scan"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -461,12 +467,7 @@ mod tests {
|
||||
);
|
||||
|
||||
let npc = world
|
||||
.spawn((
|
||||
Npc,
|
||||
TilePosition::new(5, 6, 0),
|
||||
npc_kg,
|
||||
ScanAuthority,
|
||||
))
|
||||
.spawn((Npc, TilePosition::new(5, 6, 0), npc_kg, ScanAuthority))
|
||||
.id();
|
||||
world.resource_mut::<EntityRegistry>().register(npc);
|
||||
|
||||
@@ -477,12 +478,19 @@ mod tests {
|
||||
// NPC already knew — KG should not be re-written (fact tick stays 0)
|
||||
let npc_kg = world.get::<KnowledgeGraph>(npc).unwrap();
|
||||
let fact = npc_kg.facts.get(&fact_id).unwrap();
|
||||
assert_eq!(fact.acquired_tick, 0, "should not overwrite existing knowledge");
|
||||
assert_eq!(
|
||||
fact.acquired_tick, 0,
|
||||
"should not overwrite existing knowledge"
|
||||
);
|
||||
|
||||
// Scan event should still fire even though NPC already knew
|
||||
let mut buffer = world.get_mut::<ScanEventBuffer>(player).unwrap();
|
||||
let events = buffer.take();
|
||||
assert_eq!(events.len(), 1, "scan event should emit even for already-known contraband");
|
||||
assert_eq!(
|
||||
events.len(),
|
||||
1,
|
||||
"scan event should emit even for already-known contraband"
|
||||
);
|
||||
assert!(events[0].detected_contraband);
|
||||
}
|
||||
|
||||
@@ -542,7 +550,11 @@ mod tests {
|
||||
// Both should emit separate scan events
|
||||
let mut buffer = world.get_mut::<ScanEventBuffer>(player).unwrap();
|
||||
let events = buffer.take();
|
||||
assert_eq!(events.len(), 2, "each ScanAuthority NPC should emit a scan event");
|
||||
assert_eq!(
|
||||
events.len(),
|
||||
2,
|
||||
"each ScanAuthority NPC should emit a scan event"
|
||||
);
|
||||
assert!(events.iter().all(|e| e.detected_contraband));
|
||||
}
|
||||
|
||||
|
||||
@@ -179,6 +179,7 @@ pub fn available_access_tiers(relationship: RelationshipState) -> Vec<AccessTier
|
||||
/// - Secret: Friendly + KnowsDetails+ (deep rapport + actionable knowledge)
|
||||
/// - Real: (Friendly or Known) + KnowsOf+ (rapport + substantive knowledge)
|
||||
/// - Surface: everything else (baseline, always available)
|
||||
///
|
||||
/// Map relationship + knowledge confidence to trust tier (D-075).
|
||||
///
|
||||
/// Trust tier gates which dialogue lines are available. The layered gate
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// When sprinting past a Contradicted entity, a delayed "double-take" monologue
|
||||
// fires retroactively. Detection in observer pipeline, processing here.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use bevy_ecs::prelude::*;
|
||||
use rand::Rng;
|
||||
@@ -77,7 +77,7 @@ pub struct MonologueState {
|
||||
/// Whether the enter_location monologue has fired this session.
|
||||
pub entered: bool,
|
||||
/// IDs of lines already shown (dedup within session).
|
||||
pub shown_ids: HashSet<String>,
|
||||
pub shown_ids: BTreeSet<String>,
|
||||
/// Character type for pool filtering. v0.1: always "detective".
|
||||
pub character: String,
|
||||
}
|
||||
@@ -89,7 +89,7 @@ impl Default for MonologueState {
|
||||
last_position: None,
|
||||
idle_ticks: 0,
|
||||
entered: false,
|
||||
shown_ids: HashSet::new(),
|
||||
shown_ids: BTreeSet::new(),
|
||||
// v0.1: default to detective; character selection sets this
|
||||
character: "detective".to_string(),
|
||||
}
|
||||
|
||||
@@ -23,7 +23,17 @@ pub struct PlayerCharacter;
|
||||
/// Examples: a Standing character can walk past a Seated NPC at a console,
|
||||
/// a Fixture (terminal) shares a tile with someone Seated at it.
|
||||
#[derive(
|
||||
Component, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize,
|
||||
Component,
|
||||
Debug,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Hash,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Default,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
pub enum TilePresence {
|
||||
@@ -42,7 +52,9 @@ pub enum TilePresence {
|
||||
/// Tile position component for grid-based movement.
|
||||
/// Discrete integer coordinates used in simulation; converted to f32
|
||||
/// at the bridge boundary for VisibleEntity wire format.
|
||||
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
#[derive(
|
||||
Component, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize,
|
||||
)]
|
||||
pub struct TilePosition {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
|
||||
Reference in New Issue
Block a user