From: Ian Jackson Date: Sun, 28 Jun 2020 19:45:30 +0000 (+0100) Subject: wip X-Git-Tag: otter-0.2.0~1505 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0d62e5649cb1ab1d63d9a1ad1d85d982b884660d;p=otter.git wip --- diff --git a/src/bin/server.rs b/src/bin/server.rs index 3aa291e0..6af71449 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -135,9 +135,9 @@ fn api_grab(form : Json) -> impl response::Responder<'static> { let mut g = iad.i.lock().map_err(|e| anyhow!("lock poison {:?}",&e))?; let client = form.c; let r : Result<(),OpError> = (||{ - let p = decode_visible_pieceid(form.p); + let piece = decode_visible_pieceid(form.p); let gs = &mut g.gs; - let p = gs.pieces.get_mut(p).ok_or(OpError::PieceGone)?; + let p = gs.pieces.get_mut(piece).ok_or(OpError::PieceGone)?; let q_gen = form.g; let u_gen = if client == p.lastclient { p.gen_lastclient } @@ -153,16 +153,16 @@ fn api_grab(form : Json) -> impl response::Responder<'static> { } p.gen_lastclient = gen; for (tplayer, tpl) in g.gs.players { - for (tclient, cl) in g.clients.get(tplayer) { - if tclient == cl { - cl.transmit_update(client, Update { + for (tclient, tcl) in g.clients[tplayer] { + if tclient == client { + tcl.transmit_update(&Update { gen, u : UpdatePayload::ClientSequence(form.s), }); } else { - cl.transmit_update(client, Update { + tcl.transmit_update(&Update { gen, - u : UpdatePayload::PieceUpdate(p, p.update()), + u : UpdatePayload::PieceUpdate(piece, p.mk_update()), }); } } @@ -199,7 +199,7 @@ fn api_move(form : Json) -> impl response::Responder<'static> { } #[derive(Serialize)] -enum Update { +enum XUpdate { TestCounter { value: usize }, } diff --git a/src/gamestate.rs b/src/gamestate.rs index 89cccf50..48471c35 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -53,6 +53,16 @@ pub struct PieceRecord { pub gen_before_lastclient : Counter, } +impl PieceRecord { + pub fn mk_update(&self) -> PieceUpdate { + PieceUpdate { + pos : self.pos, + held : self.held, + // xxx want all piece's stuff in the same def + } + } +} + #[derive(Debug)] pub struct GameState { pub pieces : DenseSlotMap, diff --git a/src/global.rs b/src/global.rs index 43689b97..57de86d6 100644 --- a/src/global.rs +++ b/src/global.rs @@ -19,6 +19,12 @@ impl Borrow for RawToken { pub struct Client { } +impl Client { + pub fn transmit_update(&mut self, u : &Update) { + eprintln!("XXX not transmitting {:?}", &u); + } +} + pub struct Instance { /* game state goes here */ pub gs : GameState, diff --git a/src/updates.rs b/src/updates.rs index 1f7b8c50..b369729c 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -15,10 +15,7 @@ pub struct Update { pub struct PieceUpdate { pub pos : Pos, pub held : Option, - pub svg_piece : String, - pub svg_select : String, - pub svg_x_ids : VisiblePieceIdSvgIds, - pub svg_defs : String, +// pub svgs : Vec; } #[derive(Debug,Serialize)]