From: Ian Jackson Date: Mon, 29 Jun 2020 00:23:42 +0000 (+0100) Subject: wip new updates X-Git-Tag: otter-0.2.0~1496 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=a838b532c2bd9934c52248093f24b5d7d63b7b21;p=otter.git wip new updates --- diff --git a/src/bin/server.rs b/src/bin/server.rs index aaf3878c..0ed61436 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -165,16 +165,12 @@ fn api_grab(form : Json) -> impl response::Responder<'static> { gen, u : UpdatePayload::PieceUpdate(piece, p.mk_update()), }; + let update = Arc::new(update); + // split vie wthing would go here p.gen_lastclient = gen; - for (tclient, tcl) in &mut g.clients { - if tclient == client { - tcl.transmit_update(&Update { - gen, - u : UpdatePayload::ClientSequence(piece, form.s), - }); - } else { - tcl.transmit_update(&update); - } + for (_tplayer, tplupdates) in &mut g.updates { + tplupdates.log.push_back((client, update.clone())); + tplupdates.cv.notify_all(); } Ok(()) })(); @@ -216,6 +212,22 @@ type TestCounter = BufReader; #[derive(Debug)] struct TestCounterInner { next : usize, } impl Read for TestCounterInner { + + + /* + for (tclient, tcl) in &mut g.clients { + if tclient == client { + tcl.transmit_update(&Update { + gen, + u : UpdatePayload::ClientSequence(piece, form.s), + }); + } else { + tcl.transmit_update(&update); + } + } + */ + + fn read(&mut self, buf: &mut [u8]) -> io::Result { thread::sleep(Duration::from_millis(500)); let message = XUpdate::TestCounter { value : self.next }; diff --git a/src/global.rs b/src/global.rs index 50a02a54..f32831c6 100644 --- a/src/global.rs +++ b/src/global.rs @@ -23,9 +23,15 @@ impl Client { } } +pub struct PlayerUpdates { + pub log : VecDeque<(ClientId, Arc)>, + pub cv : Condvar, +} + pub struct Instance { pub gs : GameState, pub clients : DenseSlotMap, + pub updates : SecondarySlotMap, } #[derive(Clone)] @@ -103,6 +109,7 @@ pub fn xxx_global_setup() { let gi = Instance { gs : xxx_gamestate_init(), clients : Default::default(), + updates : Default::default(), }; let g = Arc::new(Mutex::new(gi)); let mut ig = g.lock().unwrap(); diff --git a/src/imports.rs b/src/imports.rs index 1cf8593e..92c69447 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -4,12 +4,13 @@ pub use std::io::{BufReader,Read}; pub use std::fmt::{self,Display,Debug}; pub use std::thread; pub use std::time::Duration; -pub use std::sync::{Arc,Mutex,RwLock}; +pub use std::sync::{Arc,Mutex,RwLock,Condvar}; pub use std::collections::HashMap; pub use std::borrow::Borrow; pub use std::convert::TryFrom; pub use std::str::FromStr; pub use std::iter::repeat_with; +pub use std::collections::VecDeque; pub use thiserror::Error; pub use anyhow::{Context,anyhow};