From: Ian Jackson Date: Sat, 20 Mar 2021 16:09:46 +0000 (+0000) Subject: updates: Provide piece_update_image X-Git-Tag: otter-0.5.0~669 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=56ab0f93fbe02c667082cfe4dace4d83e28584ff;p=otter.git updates: Provide piece_update_image This is the actual entrypoint Signed-off-by: Ian Jackson --- diff --git a/src/pcrender.rs b/src/pcrender.rs index 86978638..ed961ca3 100644 --- a/src/pcrender.rs +++ b/src/pcrender.rs @@ -129,6 +129,19 @@ impl PieceRenderInstructions { r } + #[throws(IE)] + pub fn prep_pieceimage(&self, ioccults: &IOccults, gs: &GameState, + gpc: &GPiece, ipc: &IPiece) + -> PreparedPieceImage { + let pri = self; + let r = PreparedPieceImage { + svg : pri.make_defs(ioccults, gs, gpc, ipc)?, + uos : pri.ui_operations(gpc, ipc)?, + }; + dbgc!(pri, ipc, gpc, r); + r + } + pub fn angle(&self, gpc: &GPiece) -> VisiblePieceAngle { match self.occulted { PriOcculted::Visible(_) => gpc.angle, diff --git a/src/updates.rs b/src/updates.rs index 78bacdef..d6513a72 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -727,6 +727,26 @@ impl<'r> PrepareUpdatesBuffer<'r> { self.us.push(update); } + #[throws(InternalError)] + pub fn piece_update_image(&mut self, piece: PieceId) { + // Use this only for updates which do not change the set of valid UOs + // or other operations or move the piece etc. + let ims = self.piece_update_fallible_players( + piece, |_,_,_|(), |_,_|(), + + |ioccults,gs,gpc,ipc,_player,pri| { + let im = pri.as_ref().map(|pri| { + let im = pri.prep_pieceimage(ioccults,gs,gpc,ipc)?; + Ok::<_,IE>(PreparedPieceUpdateGeneral { piece: pri.vpid, op: im }) + }).transpose()?; + Ok::<_,IE>(im) + }, + + |_gpl| None, + )?; + PreparedUpdateEntry_Image { ims } + } + pub fn piece_updates(&mut self, updates: Vec<(PieceId, PieceUpdateOps)>) { for (piece, ops) in updates { self.piece_update(piece, ops);