use super::*; // we are otter::updates::movehist
-pub const MOVEHIST_LENS: &[usize] = &[ 0, 1, 3, 10 ];
-pub const MOVEHIST_LEN_MAX: usize = 10;
-pub const MOVEHIST_LEN_DEF_I: usize = 1;
-pub const MOVEHIST_MIN_DIST: f64 = 7.5;
+pub const LENS: &[usize] = &[ 0, 1, 3, 10 ];
+pub const LEN_MAX: usize = 10;
+pub const LEN_DEF_I: usize = 1;
+pub const MIN_DIST: f64 = 7.5;
#[test]
fn movehist_lens() {
assert_eq!(
- MOVEHIST_LENS.iter().max(),
- Some(&MOVEHIST_LEN_MAX),
+ LENS.iter().max(),
+ Some(&LEN_MAX),
);
- assert!( MOVEHIST_LENS.get(MOVEHIST_LEN_DEF_I).is_some() );
- assert_eq!( MOVEHIST_LENS.iter().cloned().fold(None, |b, i| {
+ assert!( LENS.get(LEN_DEF_I).is_some() );
+ assert_eq!( LENS.iter().cloned().fold(None, |b, i| {
let i = Some(i);
assert!(i > b);
i
}),
- Some(MOVEHIST_LEN_MAX) );
+ Some(LEN_MAX) );
}
#[derive(Debug,Copy,Clone,Serialize,Deserialize)]
-pub struct MoveHistPosx { // usual variable: posx
+pub struct Posx { // usual variable: posx
pub pos: Pos,
pub angle: CompassAngle,
pub facehint: Option<FaceId>,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
-pub struct MoveHistEnt {
+pub struct Ent {
pub held: PlayerId,
- pub posx: OldNew<MoveHistPosx>,
- pub diff: MoveHistDiffToShow,
+ pub posx: OldNew<Posx>,
+ pub diff: DiffToShow,
}
#[derive(Debug,Copy,Clone,Serialize,Deserialize)]
-pub enum MoveHistDiffToShow {
+pub enum DiffToShow {
Moved { d: f64 },
}
#[derive(Debug,Clone,Serialize,Deserialize)]
-pub struct GMoveHist {
- pub hist: VecDeque<MoveHistEnt>,
+pub struct PlHist {
+ pub hist: VecDeque<Ent>,
}
// ---------- non-public structs ----------
#[derive(Debug,Clone,Serialize,Deserialize,Default)]
-pub struct GMoveHeld {
- held: SparseSecondaryMap<VisiblePieceId, GMoveHistLast>,
+pub struct PlHeld {
+ held: SparseSecondaryMap<VisiblePieceId, PlHistLast>,
}
#[derive(Debug,Copy,Clone,Serialize,Deserialize)]
-struct GMoveHistLast {
+struct PlHistLast {
held: PlayerId,
- posx: MoveHistPosx,
+ posx: Posx,
}
-impl Default for GMoveHist {
- fn default() -> GMoveHist { GMoveHist {
- hist: VecDeque::with_capacity(MOVEHIST_LEN_MAX),
+impl Default for PlHist {
+ fn default() -> PlHist { PlHist {
+ hist: VecDeque::with_capacity(LEN_MAX),
} }
}
-impl MoveHistPosx {
- fn differs_significantly(&self, other: &MoveHistPosx)
- -> Option<MoveHistDiffToShow> {
- use MoveHistDiffToShow as D;
+impl Posx {
+ fn differs_significantly(&self, other: &Posx)
+ -> Option<DiffToShow> {
+ use DiffToShow as D;
match (|| Ok::<_,CoordinateOverflow> ({
(self.pos - other.pos)?.len()?
}))() {
- Ok(d) if d >= MOVEHIST_MIN_DIST as f64 => return Some(D::Moved{ d }),
+ Ok(d) if d >= MIN_DIST as f64 => return Some(D::Moved{ d }),
_ => {},
}
if let Some(gpl) = wants!( gs.players.get_mut(player), ?player);
if let Some(mut ent) = wants!( gpl.moveheld.held.entry(piece), ?piece);
let &PreparedPieceState { pos, angle, facehint, .. } = ns;
- let new_posx = MoveHistPosx { pos, angle, facehint };
+ let new_posx = Posx { pos, angle, facehint };
then {
if let slotmap::sparse_secondary::Entry::Occupied(ref mut oe) = ent {
if let Some(diff) = new_posx.differs_significantly(&last.posx) {
// Generate an update
- let histent = MoveHistEnt {
+ let histent = Ent {
held: last.held,
posx: OldNew::from([last.posx, new_posx]),
diff,
};
- if gpl.movehist.hist.len() == MOVEHIST_LEN_MAX {
+ if gpl.movehist.hist.len() == LEN_MAX {
gpl.movehist.hist.pop_front();
}
gpl.movehist.hist.push_back(histent.clone());
}
if let Some(held) = ns.held {
- ent.insert(GMoveHistLast { held: held, posx: new_posx });
+ ent.insert(PlHistLast { held: held, posx: new_posx });
} else {
ent.remove();
}