From 80960c2ea9ed26f6196817436d97391dea67a3b1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 11 Mar 2021 19:06:40 +0000 Subject: [PATCH] hidden: Plumb through Z information Signed-off-by: Ian Jackson --- src/gamestate.rs | 16 ++++++++-------- src/hand.rs | 2 +- src/hidden.rs | 44 ++++++++++++++++++++++++++++---------------- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/gamestate.rs b/src/gamestate.rs index 10bbe91e..fc69153b 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -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 { match self.occulted { - PriOcculted::Visible => (), - PriOcculted::Occulted | PriOcculted::Displaced(_) => return vec![], + PriOcculted::Visible => (), + PriOcculted::Occulted | PriOcculted::Displaced(..) => return vec![], }; type WRC = WhatResponseToClientOp; diff --git a/src/hand.rs b/src/hand.rs index 9d4413e8..7153340b 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -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", ®ion, &views); Ok::<_,IE>((region, views)) diff --git a/src/hidden.rs b/src/hidden.rs index db3d8c6f..39f33e21 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -21,7 +21,7 @@ pub struct GameOccults { // kept in synch with Occultation::pieces pub struct PieceOccult { active: Option, // 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 { Displaced(D), Invisible, } -pub type OccultationKind = OccultationKindGeneral; +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 for u32 { + fn from(n: Notch) -> u32 { n.index().try_into().unwrap() } + } + type NotchPtr = Option; #[derive(Clone,Copy,Debug,Serialize,Deserialize)] @@ -499,14 +503,20 @@ fn inner( ) -> Option { 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, -- 2.30.2