From: Ian Jackson Date: Sat, 27 Feb 2021 13:30:41 +0000 (+0000) Subject: rename GPlayer and GPiece X-Git-Tag: otter-0.4.0~320 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=6d0450452c3e64efca6fe8bd7856d7b0099fd471;p=otter.git rename GPlayer and GPiece Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index ef892f3c..f9f99d65 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -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 diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 4e4e3cb7..31a8621f 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -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(), diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index 708189f2..9364de06 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -93,7 +93,7 @@ fn preview(items: Vec) { (||{ 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::>(); let spec = spec.clone(); @@ -120,7 +120,7 @@ fn preview(items: Vec) { 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#""#); diff --git a/src/gamestate.rs b/src/gamestate.rs index 9bf15cb0..8c6e651c 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -61,17 +61,17 @@ pub struct GameState { pub occults: GameOccults, } -pub type GPlayers = DenseSlotMap; +pub type GPlayers = DenseSlotMap; #[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, @@ -145,7 +145,7 @@ pub trait Piece: Outline + Send + Debug { #[throws(InternalError)] fn add_ui_operations(&self, _upd: &mut Vec, - _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, gpc: &PieceState) + fn describe_html(&self, face: Option, gpc: &GPiece) -> Result; - 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; - fn describe_html_infallible(&self, face: Option, gpc: &PieceState) + fn describe_html_infallible(&self, face: Option, 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, IE>; + fn ui_operations(&self, gpc: &GPiece) -> Result, IE>; } impl 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 PieceExt for T where T: Piece + ?Sized { defs } - fn describe_html_infallible(&self, face: Option, gpc: &PieceState) + fn describe_html_infallible(&self, face: Option, gpc: &GPiece) -> Html { self.describe_html(face, gpc) .unwrap_or_else(|e| { @@ -404,13 +404,13 @@ impl 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 { + fn ui_operations(&self, gpc: &GPiece) -> Vec { type WRC = WhatResponseToClientOp; let mut out = vec![]; diff --git a/src/global.rs b/src/global.rs index 5159df2c..0aa5beae 100644 --- a/src/global.rs +++ b/src/global.rs @@ -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; +type ActualGPieces = DenseSlotMap; #[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, 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) -> Result, Option, PreparedUpdateEntry) + (Option, Option, 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 { + pub fn values_mut(&mut self) -> sm::ValuesMut { 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() } } diff --git a/src/hand.rs b/src/hand.rs index 12601914..9148c3f7 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -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, gpc: &PieceState) -> Html { + fn describe_html(&self, _face: Option, 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, - gpc: &PieceState) { + gpc: &GPiece) { upd.push(if_chain! { if let Some(xdata) = gpc.xdata.get::()?; if let Some(_owner) = &xdata.owner; diff --git a/src/hidden.rs b/src/hidden.rs index 66712bdd..b25b8c85 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -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 { let piece = gpl.idmap.rev(vis); diff --git a/src/pieces.rs b/src/pieces.rs index b7f99a2b..b3803cc5 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -130,12 +130,12 @@ impl Outline for GenericSimpleShape #[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, _gpc: &PieceState) -> Html { + fn describe_html(&self, face: Option, _gpc: &GPiece) -> Html { Html(if_chain! { if let Some(face) = face; if let Some(colour) = self.colours.get(face); diff --git a/src/shapelib.rs b/src/shapelib.rs index 6f193e69..98146f69 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -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, _gpc: &PieceState) -> Html { + fn describe_html(&self, face: Option, _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); } diff --git a/src/spec.rs b/src/spec.rs index 89f3e18d..5cc24f7f 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -469,7 +469,7 @@ pub mod implementation { fn deliver(&self, ag: &AccountsGuard, g: &Instance, - gpl: &GPlayerState, + gpl: &GPlayer, ipl: &IPlayerState, token: AccessTokenInfo) -> Result; @@ -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 { diff --git a/src/updates.rs b/src/updates.rs index 7774153e..946c69ba 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -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, 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 { 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, 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;