From: Ian Jackson Date: Sat, 13 Mar 2021 21:54:10 +0000 (+0000) Subject: Plumb to_permute through, rather than making new ones X-Git-Tag: otter-0.4.0~86 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=f9c0dd92ae405b380041706b51841cd825c6ada6;p=otter.git Plumb to_permute through, rather than making new ones Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index ee52fd99..19d4faef 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -105,7 +105,7 @@ fn api_piece_op(form: Json>) let mut ig = iad.gref.lock()?; ig.save_game_later(); - ToPermute::with(move |to_permute| { + ToPermute::with(move |mut to_permute| { let r = (||{ let g = &mut *ig; @@ -139,6 +139,7 @@ fn api_piece_op(form: Json>) let update = form.op.op_complex(ApiPieceOpArgs { ioccults, gs, player, piece, ipieces, ipc, + to_permute: &mut to_permute, })?; Ok::<_,ApiPieceOpError>(update) })() { @@ -312,7 +313,9 @@ api_route!{ as: #[throws(ApiPieceOpError)] fn op(&self, a: ApiPieceOpArgs) -> PieceUpdate { - let ApiPieceOpArgs { gs,ioccults,player,piece,ipc,ipieces, .. } = a; + let ApiPieceOpArgs { + gs,ioccults,player,piece,ipc,ipieces,to_permute, .. + } = a; let gpl = gs.players.byid_mut(player).unwrap(); let gpc = gs.pieces.byid_mut(piece).unwrap(); @@ -335,6 +338,7 @@ api_route!{ gs, who_by, ipieces, + to_permute, piece, vanilla, ).map_err(|e| OnlineError::from(e))?; diff --git a/src/gamestate.rs b/src/gamestate.rs index bf9ba072..aa5c86d1 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -174,6 +174,7 @@ pub struct ApiPieceOpArgs<'a> { pub gs: &'a mut GameState, pub ipieces: &'a IPieces, pub ioccults: &'a IOccults, + pub to_permute: &'a mut ToPermute, pub player: PlayerId, pub piece: PieceId, pub ipc: &'a IPiece, diff --git a/src/hand.rs b/src/hand.rs index 7153340b..8454dd2d 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -140,7 +140,7 @@ impl PieceTrait for Hand { fn ui_operation(&self, a: ApiPieceOpArgs<'_>, opname: &str, wrc: WhatResponseToClientOp) -> UpdateFromOpComplex { - let ApiPieceOpArgs { gs,player,piece,ipieces,.. } = a; + let ApiPieceOpArgs { gs,player,piece,ipieces,to_permute,.. } = a; let gen = &mut gs.gen; let gplayers = &mut gs.players; let gpieces = &mut gs.pieces; @@ -197,6 +197,7 @@ impl PieceTrait for Hand { let xupdates = create_occultation(&mut gen.unique_gen(), gplayers, gpieces, goccults, ipieces, + to_permute, region, piece, views)?; dbgc!("creating occ done", &new_owner, &xupdates); diff --git a/src/hidden.rs b/src/hidden.rs index 3d31a4dc..03223394 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -862,15 +862,15 @@ pub fn recalculate_occultation_piece( gs: &mut GameState, who_by: Html, ipieces: &IPieces, + to_permute: &mut ToPermute, piece: PieceId, (vanilla_wrc, vanilla_op, vanilla_log): PUFOS, ) -> PieceUpdate { - ToPermute::with(|mut to_permute| ( recalculate_occultation_general( &mut gs.gen.unique_gen(), - &gs.players, &mut gs.pieces, &mut gs.occults, ipieces, &mut to_permute, + &gs.players, &mut gs.pieces, &mut gs.occults, ipieces, to_permute, piece, vanilla_log, |log| (vanilla_wrc, vanilla_op, log).into(), |old, new, show| vec![ LogEntry { html: Html(format!( @@ -884,11 +884,7 @@ pub fn recalculate_occultation_piece( ops: PieceUpdateOps::PerPlayer(puos), log } - ), - to_permute.implement(&mut gs.players, - &mut gs.pieces, &mut gs.occults, - ipieces), - ))? + )? } #[throws(IE)] @@ -994,6 +990,7 @@ pub fn create_occultation( gpieces: &mut GPieces, goccults: &mut GameOccults, ipieces: &IPieces, + to_permute: &mut ToPermute, region: Area, occulter: PieceId, views: OccultationViews, @@ -1033,7 +1030,7 @@ pub fn create_occultation( let occid = goccults.occults.insert(occultation); let mut updates = vec![]; - ToPermute::with(|mut to_permute| ( + (|| ( (||{ let ogpc = gpieces.get_mut(occulter).ok_or_else( ||internal_logic_error("occulter vanished"))?; @@ -1042,7 +1039,7 @@ pub fn create_occultation( for &ppiece in &recalc { recalculate_occultation_ofmany(gen, gplayers, gpieces, goccults, ipieces, - &mut to_permute, + to_permute, ppiece, &mut updates)?; } @@ -1056,9 +1053,8 @@ pub fn create_occultation( ogpc.occult.active = None; goccults.occults.remove(occid).expect("inserted this earlier"); e - }), - to_permute.implement(gplayers, gpieces, goccults, ipieces), - ))?; + }) + ))()?; dbgc!(&updates); updates @@ -1071,6 +1067,7 @@ pub fn remove_occultation( gpieces: &mut GPieces, goccults: &mut GameOccults, ipieces: &IPieces, + to_permute: &mut ToPermute, occulter: PieceId, ) -> Vec<(PieceId, PieceUpdateOps)> { let mut aggerr = AggregatedIE::new(); @@ -1100,7 +1097,6 @@ pub fn remove_occultation( let mut updates = vec![]; - ToPermute::with(|mut to_permute| ({ let pieces: Vec = if let Some(o) = &occultation { o.notches.iter().collect() } else { @@ -1117,7 +1113,7 @@ pub fn remove_occultation( for &ppiece in pieces.iter() { recalculate_occultation_ofmany(gen, gplayers, gpieces, goccults, ipieces, - &mut to_permute, + to_permute, ppiece, &mut updates) .unwrap_or_else(|e| { aggerr.record(e); @@ -1132,9 +1128,6 @@ pub fn remove_occultation( } else { aggerr.record(internal_logic_error("removing occultation of non-piece")); } - }, - to_permute.implement(gplayers, gpieces, goccults, ipieces), - )); aggerr.ok()?;