chiark / gitweb /
rename GPlayer and GPiece
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Feb 2021 13:30:41 +0000 (13:30 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Feb 2021 13:30:41 +0000 (13:30 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
daemon/cmdlistener.rs
src/bin/otterlib.rs
src/gamestate.rs
src/global.rs
src/hand.rs
src/hidden.rs
src/pieces.rs
src/shapelib.rs
src/spec.rs
src/updates.rs

index ef892f3c0ce390f319bff9f09444ad66fea376c5..f9f99d6500fa0b7bd5eeeb65d47b1748e53a3a31 100644 (file)
@@ -46,7 +46,7 @@ trait ApiPieceOp: Debug {
   }
 
   #[throws(OnlineError)]
-  fn check_held(&self, pc: &PieceState, player: PlayerId) {
+  fn check_held(&self, pc: &GPiece, player: PlayerId) {
     if pc.held != None && pc.held != Some(player) {
       throw!(OnlineError::PieceHeld)
     }
@@ -231,7 +231,7 @@ api_route!{
   struct ApiPieceWrest {
   }
   #[throws(OnlineError)]
-  fn check_held(&self, _pc: &PieceState, _player: PlayerId) { }
+  fn check_held(&self, _pc: &GPiece, _player: PlayerId) { }
 
   #[throws(ApiPieceOpError)]
   fn op(&self, a: ApiPieceOpArgs) -> PieceUpdate {
@@ -320,7 +320,7 @@ api_route!{
   struct ApiPieceMove(Pos);
 
   #[throws(OnlineError)]
-  fn check_held(&self, pc: &PieceState, player: PlayerId) {
+  fn check_held(&self, pc: &GPiece, player: PlayerId) {
     // This will ensure that occultations are (in general) properly
     // updated, because the player will (have to) release the thing
     // again
index 4e4e3cb7dd8d21a6adb4c6ee5499dea24fab465e..31a8621f880fbaba9a942573984e51747d55603a 100644 (file)
@@ -340,7 +340,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
       };
       let timezone = &arecord.timezone;
       let tz = tz_from_str(&timezone);
-      let gpl = GPlayerState {
+      let gpl = GPlayer {
         nick: nick.to_string(),
         layout: arecord.layout,
         idmap: default(),
@@ -377,7 +377,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
     MGI::ListPieces => readonly(cs,ag,ig, &[TP::ViewNotSecret], |ig|{
       let pieces = ig.gs.pieces.iter().filter_map(
         |(piece,p)| (|| Ok::<_,MgmtError>(if_chain!{
-          let &PieceState { pos, face, .. } = p;
+          let &GPiece { pos, face, .. } = p;
           if let Some(pinfo) = ig.ipieces.get(piece);
           let desc_html = pinfo.describe_html_infallible(None, p);
           let itemname = pinfo.itemname().to_string();
@@ -606,7 +606,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
         if p.nfaces() <= face.into() {
           throw!(SpecError::FaceNotFound);
         }
-        let pc = PieceState {
+        let pc = GPiece {
           held: None,
           zlevel: ZLevel { z: z.increment()?, zg: gs.gen },
           lastclient: default(),
index 708189f22780d3decd11e8f50991df8ceab5427f..9364de0626771738a2453ac2fad5c236b0d077e5 100644 (file)
@@ -93,7 +93,7 @@ fn preview(items: Vec<ItemForOutput>) {
     (||{
       let pc = spec.clone().load().context("load")?;
       let mut uos = vec![];
-      let gpc_dummy = PieceState::dummy();
+      let gpc_dummy = GPiece::dummy();
       pc.add_ui_operations(&mut uos, &gpc_dummy).context("add uos")?;
       let uos = uos.into_iter().map(|uo| uo.opname).collect::<Vec<_>>();
       let spec = spec.clone();
@@ -120,7 +120,7 @@ fn preview(items: Vec<ItemForOutput>) {
   let max_facecols = pieces.iter().map(|s| s.face_cols()).max().unwrap_or(1);
   let max_uos = pieces.iter().map(|s| s.uos.len()).max().unwrap_or(0);
 
-  let gpc_dummy = PieceState::dummy();
+  let gpc_dummy = GPiece::dummy();
 
   println!("{}", &HTML_PRELUDE);
   println!(r#"<table rules="all">"#);
index 9bf15cb0ec61ccf8a83ea40864f7f4bdd9bab0e6..8c6e651c213fc3ceda7d0d736520ae17184a10a5 100644 (file)
@@ -61,17 +61,17 @@ pub struct GameState {
   pub occults: GameOccults,
 }
 
-pub type GPlayers = DenseSlotMap<PlayerId, GPlayerState>;
+pub type GPlayers = DenseSlotMap<PlayerId, GPlayer>;
 
 #[derive(Debug,Serialize,Deserialize,Clone)]
-pub struct GPlayerState {
+pub struct GPlayer {
   pub nick: String,
   pub layout: PresentationLayout,
   pub idmap: PerPlayerIdMap,
 }
 
 #[derive(Debug,Serialize,Deserialize)]
-pub struct PieceState {
+pub struct GPiece {
   pub pos: Pos,
   pub face: FaceId,
   pub held: Option<PlayerId>,
@@ -145,7 +145,7 @@ pub trait Piece: Outline + Send + Debug {
 
   #[throws(InternalError)]
   fn add_ui_operations(&self, _upd: &mut Vec<UoDescription>,
-                       _gpc: &PieceState) { }
+                       _gpc: &GPiece) { }
 
   fn ui_operation(&self, _a: ApiPieceOpArgs<'_>,
                   _opname: &str, _wrc: WhatResponseToClientOp)
@@ -154,13 +154,13 @@ pub trait Piece: Outline + Send + Debug {
   }
 
   // #[throws] doesn't work here - fehler #todo
-  fn svg_piece(&self, f: &mut Html, gpc: &PieceState,
+  fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
                pri: &PieceRenderInstructions) -> Result<(),IE>;
 
-  fn describe_html(&self, face: Option<FaceId>, gpc: &PieceState)
+  fn describe_html(&self, face: Option<FaceId>, gpc: &GPiece)
                    -> Result<Html,IE>;
 
-  fn delete_hook(&self, _p: &PieceState, _gs: &mut GameState)
+  fn delete_hook(&self, _p: &GPiece, _gs: &mut GameState)
                  -> ExecuteGameChangeUpdates { 
     ExecuteGameChangeUpdates{ pcs: vec![], log: vec![], raw: None }
   }
@@ -279,7 +279,7 @@ impl VisiblePieceAngle {
 
 // ---------- game state - rendering etc. ----------
 
-impl PieceState {
+impl GPiece {
   #[throws(IE)]
   pub fn prep_piecestate(&self, p: &dyn Piece, pri: &PieceRenderInstructions)
                      -> PreparedPieceState {
@@ -306,7 +306,7 @@ impl PieceState {
 
   pub fn dummy() -> Self {
     let gen_dummy = Generation(1);
-    PieceState {
+    GPiece {
       pos: PosC([0,0]),
       face: default(),
       held: None,
@@ -364,18 +364,18 @@ impl PieceXDataExt for PieceXDataState {
 }
 
 pub trait PieceExt {
-  fn make_defs(&self, gpc: &PieceState, pri: &PieceRenderInstructions)
+  fn make_defs(&self, gpc: &GPiece, pri: &PieceRenderInstructions)
                -> Result<Html, IE>;
-  fn describe_html_infallible(&self, face: Option<FaceId>, gpc: &PieceState)
+  fn describe_html_infallible(&self, face: Option<FaceId>, gpc: &GPiece)
                               -> Html;
-  fn describe_pri(&self, gpc: &PieceState, pri: &PieceRenderInstructions)
+  fn describe_pri(&self, gpc: &GPiece, pri: &PieceRenderInstructions)
                   -> Html;
-  fn ui_operations(&self, gpc: &PieceState) -> Result<Vec<UoDescription>, IE>;
+  fn ui_operations(&self, gpc: &GPiece) -> Result<Vec<UoDescription>, IE>;
 }
 
 impl<T> PieceExt for T where T: Piece + ?Sized {
   #[throws(IE)]
-  fn make_defs(&self,  gpc: &PieceState, pri: &PieceRenderInstructions)
+  fn make_defs(&self,  gpc: &GPiece, pri: &PieceRenderInstructions)
                -> Html {
     let mut defs = Html(String::new());
     let dragraise = match self.thresh_dragraise(pri)? {
@@ -395,7 +395,7 @@ impl<T> PieceExt for T where T: Piece + ?Sized {
     defs
   }
 
-  fn describe_html_infallible(&self, face: Option<FaceId>, gpc: &PieceState)
+  fn describe_html_infallible(&self, face: Option<FaceId>, gpc: &GPiece)
                               -> Html {
     self.describe_html(face, gpc)
       .unwrap_or_else(|e| {
@@ -404,13 +404,13 @@ impl<T> PieceExt for T where T: Piece + ?Sized {
       })
   }
 
-  fn describe_pri(&self, gpc: &PieceState, pri: &PieceRenderInstructions)
+  fn describe_pri(&self, gpc: &GPiece, pri: &PieceRenderInstructions)
                   -> Html {
     self.describe_html_infallible(Some(pri.face), gpc)
   }
 
   #[throws(InternalError)]
-  fn ui_operations(&self, gpc: &PieceState) -> Vec<UoDescription> {
+  fn ui_operations(&self, gpc: &GPiece) -> Vec<UoDescription> {
     type WRC = WhatResponseToClientOp;
 
     let mut out = vec![];
index 5159df2cbbc5435995500d37afcb0b5dcff3d736..0aa5beaee8328c7f5628f18d0fa9a7a97b3b2090 100644 (file)
@@ -77,7 +77,7 @@ pub struct ModifyingPieces(());
 #[derive(Debug,Serialize,Deserialize,Default)]
 #[serde(transparent)]
 pub struct GPieces(pub(in crate::global) ActualGPieces);
-type ActualGPieces = DenseSlotMap<PieceId, PieceState>;
+type ActualGPieces = DenseSlotMap<PieceId, GPiece>;
 
 #[derive(Debug)]
 pub struct Client {
@@ -519,7 +519,7 @@ impl<'ig> InstanceGuard<'ig> {
   /// caller is responsible for logging; threading it through
   /// proves the caller has a log entry.
   #[throws(MgmtError)]
-  pub fn player_new(&mut self, gnew: GPlayerState, inew: IPlayerState,
+  pub fn player_new(&mut self, gnew: GPlayer, inew: IPlayerState,
                     account: Arc<AccountName>, logentry: LogEntry)
                     -> (PlayerId, PreparedUpdateEntry, LogEntry) {
     // saving is fallible, but we can't attempt to save unless
@@ -595,7 +595,7 @@ impl<'ig> InstanceGuard<'ig> {
   pub fn players_remove(&mut self, old_players_set: &HashSet<PlayerId>)
                         ->
     Result<Vec<
-        (Option<GPlayerState>, Option<IPlayerState>, PreparedUpdateEntry)
+        (Option<GPlayer>, Option<IPlayerState>, PreparedUpdateEntry)
         >, InternalError>
   {
     // We have to filter this player out of everything
@@ -623,7 +623,7 @@ impl<'ig> InstanceGuard<'ig> {
       occults: default(),
     };
 
-    let held_by_old = |p: &PieceState| if_chain! {
+    let held_by_old = |p: &GPiece| if_chain! {
       if let Some(held) = p.held;
       if old_players_set.contains(&held);
       then { true }
@@ -1262,10 +1262,10 @@ impl IPieces {
 deref_to_field!{GPieces, ActualGPieces, 0}
 
 impl GPieces {
-  pub fn get_mut(&mut self, piece: PieceId) -> Option<&mut PieceState> {
+  pub fn get_mut(&mut self, piece: PieceId) -> Option<&mut GPiece> {
     self.0.get_mut(piece)
   }
-  pub fn values_mut(&mut self) -> sm::ValuesMut<PieceId, PieceState> {
+  pub fn values_mut(&mut self) -> sm::ValuesMut<PieceId, GPiece> {
     self.0.values_mut()
   }
   pub fn as_mut(&mut self, _: ModifyingPieces) -> &mut ActualGPieces {
@@ -1275,14 +1275,14 @@ impl GPieces {
 
 impl ById for GPieces {
   type Id = PieceId;
-  type Entry = PieceState;
+  type Entry = GPiece;
   type Error = OnlineError;
   #[throws(OE)]
-  fn byid(&self, piece: PieceId) -> &PieceState {
+  fn byid(&self, piece: PieceId) -> &GPiece {
     self.get(piece).ok_or(OE::PieceGone)?
   }
   #[throws(OE)]
-  fn byid_mut(&mut self, piece: PieceId) -> &mut PieceState {
+  fn byid_mut(&mut self, piece: PieceId) -> &mut GPiece {
     self.get_mut(piece).ok_or(OE::PieceGone)?
   }
 }
@@ -1293,8 +1293,8 @@ impl ById for GPieces {
   fn into_iter(self) -> Self::IntoIter { (&self.0).into_iter() }
 }*/
 impl<'p> IntoIterator for &'p mut GPieces {
-  type Item = (PieceId, &'p mut PieceState);
-  type IntoIter = sm::IterMut<'p, PieceId, PieceState>;
+  type Item = (PieceId, &'p mut GPiece);
+  type IntoIter = sm::IterMut<'p, PieceId, GPiece>;
   fn into_iter(self) -> Self::IntoIter { (&mut self.0).into_iter() }
 }
 
index 12601914f192fcbe83d452498c6074097b9a632d..9148c3f7379e2796aa01cfbf1a04e8d13c611197 100644 (file)
@@ -79,7 +79,7 @@ impl Hand {
 impl Piece for Hand {
   fn nfaces(&self) -> RawFaceId { 1 }
   #[throws(IE)]
-  fn svg_piece(&self, f: &mut Html, gpc: &PieceState,
+  fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
                pri: &PieceRenderInstructions) {
     self.shape.svg_piece_raw(f, pri, &mut |f: &mut String| {
       if_chain!{
@@ -93,7 +93,7 @@ impl Piece for Hand {
   }
 
   #[throws(IE)]
-  fn describe_html(&self, _face: Option<FaceId>, gpc: &PieceState) -> Html {
+  fn describe_html(&self, _face: Option<FaceId>, gpc: &GPiece) -> Html {
     let xdata = gpc.xdata.get()?;
     self.describe_html_inner(xdata)
   }
@@ -106,7 +106,7 @@ impl Piece for Hand {
 
   #[throws(InternalError)]
   fn add_ui_operations(&self, upd: &mut Vec<UoDescription>,
-                       gpc: &PieceState) {
+                       gpc: &GPiece) {
     upd.push(if_chain! {
       if let Some(xdata) = gpc.xdata.get::<HandState>()?;
       if let Some(_owner) = &xdata.owner;
index 66712bdd761d0df1eeedad1c63976315c7d5def7..b25b8c8551c5d37848af3e6f2ce613defa9cd9bd 100644 (file)
@@ -176,9 +176,9 @@ impl PerPlayerIdMap {
 pub fn piece_pri(
   _occults: &GameOccults, // xxx
   player: PlayerId,
-  gpl: &mut GPlayerState,
+  gpl: &mut GPlayer,
   piece: PieceId,
-  pc: &PieceState,
+  pc: &GPiece,
 ) -> PieceRenderInstructions {
   let vpiece = gpl.idmap.fwd_or_insert(piece);
   let angle = VisiblePieceAngle(pc.angle);
@@ -198,7 +198,7 @@ pub fn piece_at_all_occluded(
 pub fn vpiece_decode(
   _gs: &GameState, // xxx
   player: PlayerId,
-  gpl: &GPlayerState,
+  gpl: &GPlayer,
   vis: VisiblePieceId
 ) -> Option<PieceId> {
   let piece = gpl.idmap.rev(vis);
index b7f99a2bbf4885e46bdf91922a3d364ee2ed1bdb..b3803cc549931df883ae0bdeeddccf2f2b90a8f9 100644 (file)
@@ -130,12 +130,12 @@ impl<Desc, Outl> Outline for GenericSimpleShape<Desc, Outl>
 #[typetag::serde]
 impl Piece for SimpleShape {
   #[throws(IE)]
-  fn svg_piece(&self, f: &mut Html, _gpc: &PieceState,
+  fn svg_piece(&self, f: &mut Html, _gpc: &GPiece,
                pri: &PieceRenderInstructions) {
     self.svg_piece_raw(f, pri, &mut |_|Ok(()))?;
   }
   #[throws(IE)]
-  fn describe_html(&self, face: Option<FaceId>, _gpc: &PieceState) -> Html {
+  fn describe_html(&self, face: Option<FaceId>, _gpc: &GPiece) -> Html {
     Html(if_chain! {
       if let Some(face) = face;
       if let Some(colour) = self.colours.get(face);
index 6f193e697f07d717f4f88b4928a83f56733bf584..98146f69cfceceae81b4423164d8c2aa9adc952b 100644 (file)
@@ -155,7 +155,7 @@ impl Piece for Item {
   fn nfaces(&self) -> RawFaceId { self.faces.len().try_into().unwrap() }
 
   #[throws(IE)]
-  fn svg_piece(&self, f: &mut Html, _gpc: &PieceState,
+  fn svg_piece(&self, f: &mut Html, _gpc: &GPiece,
                pri: &PieceRenderInstructions) {
     let face = &self.faces[pri.face];
     let svgd = &self.svgs[face.svg];
@@ -165,7 +165,7 @@ impl Piece for Item {
            svgd.0)?;
   }
   #[throws(IE)]
-  fn describe_html(&self, face: Option<FaceId>, _gpc: &PieceState) -> Html {
+  fn describe_html(&self, face: Option<FaceId>, _gpc: &GPiece) -> Html {
     self.descs[ match face {
       Some(face) => self.faces[face].desc,
       None => self.desc_hidden,
@@ -266,7 +266,7 @@ impl Contents {
       let ier = ItemEnquiryData {
         itemname: k.clone(),
         f0bbox,
-        f0desc: loaded.describe_html(Some(default()), &PieceState::dummy())?,
+        f0desc: loaded.describe_html(Some(default()), &GPiece::dummy())?,
       };
       out.push(ier);
     }
index 89f3e18ddb185fd3f28512ca84235588eb91be29..5cc24f7f674f1280f07127ac4c3ab65b78d62a83 100644 (file)
@@ -469,7 +469,7 @@ pub mod implementation {
     fn deliver(&self,
                ag: &AccountsGuard,
                g: &Instance,
-               gpl: &GPlayerState,
+               gpl: &GPlayer,
                ipl: &IPlayerState,
                token: AccessTokenInfo)
                -> Result<AccessTokenReport, TDE>;
@@ -485,7 +485,7 @@ pub mod implementation {
     fn deliver(&self,
                _ag: &AccountsGuard,
                _g: &Instance,
-               _gpl: &GPlayerState,
+               _gpl: &GPlayer,
                _ipl: &IPlayerState,
                _token: AccessTokenInfo) -> AccessTokenReport {
       AccessTokenReport { lines: vec![
@@ -508,7 +508,7 @@ pub mod implementation {
     fn deliver(&self,
                _ag: &AccountsGuard,
                _g: &Instance,
-               _gpl: &GPlayerState,
+               _gpl: &GPlayer,
                _ipl: &IPlayerState,
                _token: AccessTokenInfo) -> AccessTokenReport {
       AccessTokenReport { lines: vec![ "Fixed access token".to_string() ] }
@@ -521,7 +521,7 @@ pub mod implementation {
     fn deliver<'t>(&self,
                    _ag: &AccountsGuard,
                    _g: &Instance,
-                   _gpl: &GPlayerState,
+                   _gpl: &GPlayer,
                    _ipl: &IPlayerState,
                    token: AccessTokenInfo)
                    -> AccessTokenReport {
@@ -535,7 +535,7 @@ pub mod implementation {
     fn deliver<'t>(&self,
                    ag: &AccountsGuard,
                    g: &Instance,
-                   gpl: &GPlayerState,
+                   gpl: &GPlayer,
                    ipl: &IPlayerState,
                    token: AccessTokenInfo)
                    -> AccessTokenReport {
index 7774153ef3164aabff2dbdbe24530bf18577d4f3..946c69bad01a6feea074e520be1c762fd29dd2c2 100644 (file)
@@ -199,8 +199,8 @@ struct FormattedLogEntry<'u> {
 pub fn log_did_to_piece_whoby(
   occults: &GameOccults,
   player: PlayerId,
-  gpl: &mut GPlayerState,
-  piece: PieceId, pc: &PieceState, p: &dyn Piece,
+  gpl: &mut GPlayer,
+  piece: PieceId, pc: &GPiece, p: &dyn Piece,
   did: &str,
 ) -> (Vec<LogEntry>, Html) {
   let who_by = Html(htmlescape::encode_minimal(&gpl.nick));
@@ -217,8 +217,8 @@ pub fn log_did_to_piece_whoby(
 pub fn log_did_to_piece(
   occults: &GameOccults,
   player: PlayerId,
-  gpl: &mut GPlayerState,
-  piece: PieceId, pc: &PieceState, p: &dyn Piece,
+  gpl: &mut GPlayer,
+  piece: PieceId, pc: &GPiece, p: &dyn Piece,
   did: &str,
 ) -> Vec<LogEntry> {
   log_did_to_piece_whoby(occults,player,gpl,piece,pc,p,did).0
@@ -485,7 +485,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
 
   #[throws(InternalError)]
   fn piece_update_player(max_z: &mut ZCoord,
-                         pc: &mut PieceState,
+                         pc: &mut GPiece,
                          p: &Box<dyn Piece>,
                          op: PieceUpdateOp<(),()>,
                          pri: &PieceRenderInstructions)
@@ -516,7 +516,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
                                 ops: PieceUpdateOps,
                                 gen_update: GUF)
                                 -> PreparedUpdateEntry_Piece
-    where GUF: FnOnce(&mut PieceState, Generation, &IsResponseToClientOp)
+    where GUF: FnOnce(&mut GPiece, Generation, &IsResponseToClientOp)
   {
     let gen = self.gen();
     let gs = &mut self.g.gs;