chiark / gitweb /
fastsplit: Properly occult the left-behind piece
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 20 May 2022 18:04:33 +0000 (19:04 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 20 May 2022 18:24:59 +0000 (19:24 +0100)
When we split, occult the new piece, if appropriate.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/fastsplit.rs
src/hidden.rs

index 5b49269608412c6d90003962098b649a6efe381a..84d4938676658d5683c869484274d3aec58d635e 100644 (file)
@@ -152,6 +152,28 @@ impl InstanceGuard<'_> {
       let npiece = ig.gs.pieces.as_mut(modperm).insert(ngpc);
       ig.ipieces.as_mut(modperm).insert(npiece, nipc);
 
+      // "Recalculate" the occultation of the piece we're leaving behind.
+      let ((), r_unprepared) = ToRecalculate::with(|mut to_permute| {
+        let () = recalculate_occultation_general(
+          &mut ig.gs.gen.unique_gen(),
+          &mut ig.gs.players, &mut ig.gs.pieces,
+          &mut ig.gs.occults, &ig.ipieces, &ig.ioccults,
+          &mut to_permute, npiece,
+          // We are treat this as a new piece, but it's not, semantically.
+          // We don't log anything, since that new piece is not really
+          // supposed to be interesting and the piece implwementation
+          // is supposed to have logged whatever is needed.
+          || (),
+          (),
+          |_old,_new,_desc| (),
+          |_puopp, ()| (),
+        ).unwrap_or_else(|e| {
+          // not good
+          error!("failed to recalculate after piece split! {:?}", &e);
+        });
+        ((), to_permute.implement(ig))
+      });
+
       let n_unprepared = vec![(
         npiece,
         PUOs::Simple(PUO::Insert(())),
@@ -159,6 +181,7 @@ impl InstanceGuard<'_> {
 
       let unprepared = chain!(
         n_unprepared,
+        r_unprepared,
         t_unprepared,
       ).collect();
 
index 3d18d23f127301e37118b8dce89b48b79da3397e..084e5dffca87492b6e8a4adbc00ea582ee606654 100644 (file)
@@ -510,7 +510,7 @@ pub fn vpiece_decode(
 }
 
 #[throws(InternalError)]
-fn recalculate_occultation_general<
+pub fn recalculate_occultation_general<
   RD: Debug,                                          // return data
   LD: Debug,                                          // log data
   VF: FnOnce() -> RD,                                 // ret_vanilla