From: Ian Jackson Date: Fri, 31 Jul 2020 21:20:13 +0000 (+0100) Subject: game destroy compiles X-Git-Tag: otter-0.2.0~1219 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a99e96ab437da728f5fb79accda48426562f858c;p=otter.git game destroy compiles --- diff --git a/src/global.rs b/src/global.rs index b02e52b6..4a376ce4 100644 --- a/src/global.rs +++ b/src/global.rs @@ -341,22 +341,23 @@ impl InstanceGuard<'_> { pieces : Default::default(), }; + let mut updated_pieces = vec![]; + + // drop order is reverse of creation order, so create undo + // after all the things it will reference let mut undo : Vec> = vec![]; // Arrange gs.pieces - let mut updated_pieces = vec![]; for (piece,p) in &mut self.c.g.gs.pieces { if p.held == Some(oldplayer) { p.held = None; updated_pieces.push(piece); } } - undo.push(Box::new(|ig| for piece in updated_pieces { + undo.push(Box::new(|ig| for &piece in &updated_pieces { ig.c.g.gs.pieces[piece].held = Some(oldplayer) })); - // xxx send updates for pieces - // Handle gs.log: // Installs gs as the new game state, stealing the log let mut swap_things = |ig: &mut InstanceGuard| { @@ -378,6 +379,18 @@ impl InstanceGuard<'_> { mem::drop(undo); (||{ + for &piece in &updated_pieces { + self.c.g.gs.pieces[piece].gen = self.c.g.gs.gen; + } + + let lens = TransparentLens { }; + let estimate = updated_pieces.len() + 1; + let mut buf = PrepareUpdatesBuffer::new(self, None, Some(estimate)); + for &piece in &updated_pieces { + buf.piece_update(piece, PieceUpdateOp::Modify(()), &lens); + } + buf.finish(); + let mut clients_to_remove = HashSet::new(); self.clients.retain(|k,v| { let remove = v.player == oldplayer; diff --git a/src/updates.rs b/src/updates.rs index a5f4070f..367a838f 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -252,6 +252,8 @@ impl<'r> PrepareUpdatesBuffer<'r> { self.us.push(PreparedUpdateEntry::Log(logentry)); } } + + pub fn finish(self) { } } impl<'r> Drop for PrepareUpdatesBuffer<'r> {