From: Ian Jackson Date: Sun, 28 Feb 2021 20:30:10 +0000 (+0000) Subject: hidden: Change type of Occultation::pieces to contain Index X-Git-Tag: otter-0.4.0~266 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=97d536cba692b1f0030262c168a4ec875ac1b749;p=otter.git hidden: Change type of Occultation::pieces to contain Index Currently this is always zero. Signed-off-by: Ian Jackson --- diff --git a/src/hidden.rs b/src/hidden.rs index 388aef19..a4e18bcb 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -24,11 +24,15 @@ pub struct PieceOccult { passive: Option, // kept in synch with Occultation::pieces } +pub type DisplacementIndex = usize; + #[derive(Clone,Debug,Serialize,Deserialize)] pub struct Occultation { region: Area, // automatically affect pieces here occulter: PieceId, // kept in synch with PieceOccult::active - pieces: BTreeSet, // kept in synch with PieceOccult::passive + // kept synch with PO::passive. indices are either 0 or dense, 0..len() + // except after recalculate_occultation_general and before xxx tbd + pieces: BTreeMap, #[serde(flatten)] views: OccultationViews, } @@ -386,7 +390,7 @@ fn recalculate_occultation_general< } }; update_pieces(ONI::Old, &|opcs|{ opcs.remove(&piece); }); - update_pieces(ONI::New, &|opcs|{ opcs.insert(piece); }); + update_pieces(ONI::New, &|opcs|{ opcs.insert(piece,0); }); gpieces.byid_mut(piece).unwrap().occult.passive = *occids.new(); })(); // <- no ?, infallible commitment @@ -584,14 +588,14 @@ pub fn remove_occultation( pieces_fallback_buf = gpieces .iter() .filter_map(|(ppiece, pgpc)| { - if pgpc.occult.passive == Some(occid) { Some(ppiece) } + if pgpc.occult.passive == Some(occid) { Some((ppiece,0)) } else { None } }) .collect(); &pieces_fallback_buf }; - for &ppiece in pieces.iter() { + for (&ppiece,_) in pieces.iter() { recalculate_occultation_ofmany(gplayers, gpieces, goccults, ipieces, ppiece, &mut updates) .unwrap_or_else(|e| { diff --git a/src/prelude.rs b/src/prelude.rs index 17d4d232..25c67022 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -11,7 +11,7 @@ pub use std::borrow::Borrow; pub use std::borrow::Cow; pub use std::cmp::{self, max, min, Ordering}; pub use std::collections::VecDeque; -pub use std::collections::{btree_set, BTreeSet}; +pub use std::collections::{btree_map, btree_set, BTreeMap, BTreeSet}; pub use std::collections::{hash_map, HashMap, HashSet}; pub use std::convert::{Infallible, TryFrom, TryInto}; pub use std::env;