chiark / gitweb /
hidden: Plumb through Z information
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Mar 2021 19:06:40 +0000 (19:06 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 12 Mar 2021 01:20:39 +0000 (01:20 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/gamestate.rs
src/hand.rs
src/hidden.rs

index 10bbe91ecb70c653937228f1e5bded337256b005..fc69153bd5271196e555a3d5a70a60440ce76540 100644 (file)
@@ -387,8 +387,8 @@ pub struct PieceRenderInstructions {
   pub occulted: PriOcculted,
 }
 
-#[derive(Debug,Clone,Copy)]
-pub enum PriOcculted { Visible, Occulted, Displaced(Pos) }
+#[derive(Debug,Clone)]
+pub enum PriOcculted { Visible, Occulted, Displaced(Pos, ZLevel) }
 
 impl PieceRenderInstructions {
   pub fn new_visible(vpid: VisiblePieceId) -> PieceRenderInstructions {
@@ -400,8 +400,8 @@ impl PieceRenderInstructions {
                  -> Option<&'p dyn OccultedPieceTrait>
   {
     match self.occulted {
-      PriOcculted::Visible                              => None,
-      PriOcculted::Occulted | PriOcculted::Displaced(_) => {
+      PriOcculted::Visible                               => None,
+      PriOcculted::Occulted | PriOcculted::Displaced(..) => {
         Some({
           let occilk = p.occilk.as_ref()
             .ok_or_else(|| internal_logic_error(format!(
@@ -418,8 +418,8 @@ impl PieceRenderInstructions {
 
   pub fn angle(&self, gpc: &GPiece) -> VisiblePieceAngle {
     match self.occulted {
-      PriOcculted::Visible                              => gpc.angle,
-      PriOcculted::Occulted | PriOcculted::Displaced(_) => default(),
+      PriOcculted::Visible                               => gpc.angle,
+      PriOcculted::Occulted | PriOcculted::Displaced(..) => default(),
     }
   }
 
@@ -502,8 +502,8 @@ impl PieceRenderInstructions {
                    -> Vec<UoDescription>
   {
     match self.occulted {
-      PriOcculted::Visible                              => (),
-      PriOcculted::Occulted | PriOcculted::Displaced(_) => return vec![],
+      PriOcculted::Visible                               => (),
+      PriOcculted::Occulted | PriOcculted::Displaced(..) => return vec![],
     };
 
     type WRC = WhatResponseToClientOp;
index 9d4413e8807e6a7fc2addf2bae5eb920db591f74..7153340bbd4811014f4832a6d7d9c7648bb8535c 100644 (file)
@@ -186,7 +186,7 @@ impl PieceTrait for Hand {
           let views = OwnerOccultationView {
             owner: player,
             owner_view: OccK::Visible,
-            defview: OccK::Displaced(region),
+            defview: OccK::Displaced((region, gpc.zlevel.z.clone())),
           }.views()?;
           dbgc!("claiming got region", &region, &views);
           Ok::<_,IE>((region, views))
index db3d8c6f2b6afd059818350652a4c4b0bead8ce3..39f33e213724e1b067dd4456b968246fa565036e 100644 (file)
@@ -21,7 +21,7 @@ pub struct GameOccults {
 // kept in synch with Occultation::pieces
 pub struct PieceOccult {
   active: Option<OccId>, // kept in synch with Occultation::occulter
-  passive: Option<(OccId, Notch)>, // kept in synch with Occultation::pieces
+  passive: Option<(OccId, Notch, Generation)>, // kept in synch with Occultation::pieces
 }
 
 #[derive(Clone,Debug,Serialize,Deserialize)]
@@ -52,7 +52,7 @@ pub enum OccultationKindGeneral<D> {
   Displaced(D),
   Invisible,
 }
-pub type OccultationKind = OccultationKindGeneral<Area>;
+pub type OccultationKind = OccultationKindGeneral<(Area, ZCoord)>;
 
 impl Default for OccultationKind {
   fn default() -> Self { OccK::Visible }
@@ -195,6 +195,10 @@ mod vpid {
     pub struct Notch = NotchNumber;
   }
 
+  impl From<Notch> for u32 {
+    fn from(n: Notch) -> u32 { n.index().try_into().unwrap() }
+  }
+
   type NotchPtr = Option<Notch>;
 
   #[derive(Clone,Copy,Debug,Serialize,Deserialize)]
@@ -499,14 +503,20 @@ fn inner(
 ) -> Option<PieceRenderInstructions>
 {
   let occk = if_chain! {
-    if let Some((occid, notch)) = gpc.occult.passive;
+    if let Some((occid, notch, zg)) = gpc.occult.passive;
     if let Some(occultation) = occults.occults.get(occid);
     then {
       occultation.views.get_kind(player)
-        .map_displaced(|area| {
+        .map_displaced(|(area, z)| {
           let x: Coord = notch.index().try_into().unwrap(); // xxx
-          let pos = area.0[0] + PosC([x*2, 0]); // xxx
-          pos.unwrap()
+          let pos = (area.0[0] + PosC([x*2, 0])).unwrap(); // xxx
+          let z = z.plus_offset(notch.into())
+            .unwrap_or_else(|e| { // eek!
+              error!("z coordinate overflow ({:?}), bodging! {:?} {:?}",
+                     e, piece, &z);
+              z.clone()
+            });
+          (pos, ZLevel { z, zg })
         })
     }
     else {
@@ -514,17 +524,18 @@ fn inner(
     }
   };
 
+  let occk_dbg = occk.map_displaced(|(pos,z)|(*pos,z.zg));
   let occulted = match occk {
     OccKG::Invisible => {
       trace_dbg!("piece_pri", player, piece, occk, gpc);
       return None;
     }
-    OccKG::Visible        => PriOcculted::Visible,
-    OccKG::Scrambled      => PriOcculted::Occulted,
-    OccKG::Displaced(pos) => PriOcculted::Displaced(pos),
+    OccKG::Visible            => PriOcculted::Visible,
+    OccKG::Scrambled          => PriOcculted::Occulted,
+    OccKG::Displaced((pos,z)) => PriOcculted::Displaced(pos, z),
   };
   let vpid = gpl.idmap.fwd_or_insert(piece);
-  trace_dbg!("piece_pri", player, piece, occk, vpid, occulted, gpc);
+  trace_dbg!("piece_pri", player, piece, occk_dbg, vpid, occulted, gpc);
   Some(PieceRenderInstructions { vpid, occulted })
 }
   inner(ioccults, occults, player, gpl, piece, gpc, ipc)
@@ -627,7 +638,7 @@ fn recalculate_occultation_general<
 
     let occulteds = OldNewOcculteds {
       old:
-        gpc.occult.passive.map(|(occid, notch)| Ok::<_,IE>((
+        gpc.occult.passive.map(|(occid, notch, _zg)| Ok::<_,IE>((
           Occulted {
             occid,
             occ: goccults.occults.get(occid).ok_or_else(
@@ -777,9 +788,10 @@ fn recalculate_occultation_general<
         .unwrap()
     };
     let passive = if let Some(occid) = occulteds.new {
+      let zg = gen.next();
       let notch = notches(goccults, occid)
-        .insert(gen.next(), piece);
-      Some((occid, notch))
+        .insert(zg, piece);
+      Some((occid, notch, zg))
     } else {
       None
     };
@@ -883,11 +895,11 @@ use recompute::*;
 #[must_use]
 pub struct NascentOccultation(Occultation);
 
-#[derive(Debug,Copy,Clone)]
+#[derive(Debug,Clone)]
 pub struct UniformOccultationView(
-  pub OccultationKind
+  pub OccultationKind,
 );
-#[derive(Debug,Copy,Clone)]
+#[derive(Debug,Clone)]
 pub struct OwnerOccultationView {
   pub defview: OccultationKind,
   pub owner: PlayerId,