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 }
}
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()),
});
}
}
}
#[derive(Serialize)]
-enum Update {
+enum XUpdate {
TestCounter { value: usize },
}
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<PieceId,PieceRecord>,
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,
pub struct PieceUpdate {
pub pos : Pos,
pub held : Option<PlayerId>,
- pub svg_piece : String,
- pub svg_select : String,
- pub svg_x_ids : VisiblePieceIdSvgIds,
- pub svg_defs : String,
+// pub svgs : Vec<String,String>;
}
#[derive(Debug,Serialize)]