chiark / gitweb /
Plumb to_permute through, rather than making new ones
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Mar 2021 21:54:10 +0000 (21:54 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Mar 2021 21:54:10 +0000 (21:54 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/gamestate.rs
src/hand.rs
src/hidden.rs

index ee52fd998575c997a2a3a9ffd01f0af2fb76465e..19d4faefd54ab70cf838e4fe86e3bcd624bfc3a6 100644 (file)
@@ -105,7 +105,7 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
   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<O: op::Complex>(form: Json<ApiPiece<O>>)
     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))?;
index bf9ba072547dbe3cb9b3671737bd78d1fcbe5d65..aa5c86d14ab9a3dbd7f3df308968393836c2e2e1 100644 (file)
@@ -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,
index 7153340bbd4811014f4832a6d7d9c7648bb8535c..8454dd2d274fcec98596227bebd4b4c0b7ea32cb 100644 (file)
@@ -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);
index 3d31a4dc9e8ec3dfd43c4a0ba73120c2316c9b8d..03223394e945ddd7d1cc610af1ee18f5d451d9f6 100644 (file)
@@ -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<PieceId> = 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()?;