chiark / gitweb /
movehist: Abbreviate many names
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 21:54:40 +0000 (22:54 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 2 Apr 2021 23:04:52 +0000 (00:04 +0100)
Now this is a module, this is nicer.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/main.rs
daemon/session.rs
src/gamestate.rs
src/movehist.rs
src/prelude.rs
src/updates.rs

index e5b831aa8c8113cb8fe1e0618ba0bc20b8609111..84c46ca89cac04b6bbce96809ecca347ca6f53e2 100644 (file)
@@ -124,9 +124,9 @@ fn loading(layout: Option<PresentationLayout>, ia: PlayerQueryString)
       game: g.name.to_string(),
       ptoken: &ia.raw_token,
       debug_js_inject: config().debug_js_inject.clone(),
-      movehist_lens: JsonString(MOVEHIST_LENS),
-      movehist_len_i: MOVEHIST_LEN_DEF_I,
-      movehist_len_max: MOVEHIST_LEN_MAX,
+      movehist_lens: JsonString(movehist::LENS),
+      movehist_len_i: movehist::LEN_DEF_I,
+      movehist_len_max: movehist::LEN_MAX,
       layout,
     };
     Template::render("loading", &c)
index 38223588dee8ee11127e8788e5c7392bb58a096e..29af633697e03a068be24f87fc9462ff062d6f9c 100644 (file)
@@ -24,7 +24,7 @@ struct SessionRenderContext {
   links: Html,
   player_info_pane: Html,
   fake_rng: bool,
-  movehist: GMoveHist,
+  movehist: movehist::PlHist,
 }
 
 #[derive(Debug,Serialize)]
index 5a0aabec50bd7cddcddd3b89e8735d115f364cc5..f58c83ff1e3cfb5c0f8e602e56910588e372b9bd 100644 (file)
@@ -55,8 +55,8 @@ pub struct GPlayer { // usual variable: gpl
   pub nick: String,
   pub layout: PresentationLayout,
   pub idmap: PerPlayerIdMap,
-  #[serde(default)] pub moveheld: GMoveHeld,
-  #[serde(default)] pub movehist: GMoveHist,
+  #[serde(default)] pub movehist: movehist::PlHist,
+  #[serde(default)] pub moveheld: movehist::PlHeld,
 }
 
 #[derive(Debug,Serialize,Deserialize)]
index 75e2c7cd1ff23180cdd48a8bc08f1ba735914ecc..77dfe2c2910267742dbc13e823e13aff90ab0b7f 100644 (file)
@@ -4,78 +4,78 @@
 
 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 }),
       _ => {},
     }
 
@@ -96,7 +96,7 @@ pub fn peek_prep_update(gs: &mut GameState, peek: &PreparedUpdateEntry)
     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 {
@@ -105,12 +105,12 @@ pub fn peek_prep_update(gs: &mut GameState, peek: &PreparedUpdateEntry)
 
         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());
@@ -119,7 +119,7 @@ pub fn peek_prep_update(gs: &mut GameState, peek: &PreparedUpdateEntry)
       }
 
       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();
       }
index 784fba5c8f51c02f513e0848272fd680d3bab06e..caeeaf04d52119ce02514ca9e14f7da27a3f4206 100644 (file)
@@ -145,9 +145,6 @@ pub use crate::sse;
 pub use crate::toml_de;
 pub use crate::tz::*;
 pub use crate::updates::*;
-pub use crate::updates::movehist::{self, GMoveHeld, GMoveHist, MoveHistEnt};
-pub use crate::updates::movehist::{MOVEHIST_LENS, MOVEHIST_LEN_MAX};
-pub use crate::updates::movehist::{MOVEHIST_LEN_DEF_I};
 pub use crate::utils::*;
 pub use crate::ui::*;
 
index e939268bb5fcf838a81560f6a53e8ddc19a62d30..828e14c74f301761f3a9cfbfa57327d845d0719f 100644 (file)
@@ -56,7 +56,7 @@ pub struct PreparedUpdate {
 pub enum PreparedUpdateEntry {
   Piece(PreparedUpdateEntry_Piece),
   Image(PreparedUpdateEntry_Image),
-  MoveHistEnt(SecondarySlotMap<PlayerId, MoveHistEnt>),
+  MoveHistEnt(SecondarySlotMap<PlayerId, movehist::Ent>),
   SetTableSize(Pos),
   SetTableColour(Colour),
   SetLinks(Arc<LinksTable>),
@@ -223,7 +223,7 @@ enum TransmitUpdateEntry<'u> {
   },
   Piece(TransmitUpdateEntry_Piece<'u>),
   Image(TransmitUpdateEntry_Image<'u>),
-  MoveHistEnt(&'u MoveHistEnt),
+  MoveHistEnt(&'u movehist::Ent),
   RecordedUnpredictable {
     piece: VisiblePieceId,
     cseq: ClientSequence,