chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Jun 2020 19:45:30 +0000 (20:45 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Jun 2020 19:45:30 +0000 (20:45 +0100)
src/bin/server.rs
src/gamestate.rs
src/global.rs
src/updates.rs

index 3aa291e0006b7f7c3df27882a1d5f6cc889ab2a5..6af71449b5a7f57f32f3a2d3ba370dd0e11e6548 100644 (file)
@@ -135,9 +135,9 @@ fn api_grab(form : Json<ApiGrab>) -> 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<ApiGrab>) -> 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<ApiMove>) -> impl response::Responder<'static> {
 }
 
 #[derive(Serialize)]
-enum Update {
+enum XUpdate {
   TestCounter { value: usize },
 }
 
index 89cccf507ed6ffc1a52ab20af189e040ef3b3f9f..48471c35a6cbe9db7b1c4fa146bc5b824fcfb4d9 100644 (file)
@@ -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<PieceId,PieceRecord>,
index 43689b97bd6b0024aa950bdbf40660e7fabdc8a2..57de86d6b9ad0208d297711edcfa01d3309f0f3d 100644 (file)
@@ -19,6 +19,12 @@ impl Borrow<str> 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,
index 1f7b8c50c18e1700b7a52c0e6042dd81b3280824..b369729c62c128ae36a47c0216bd3049a3446c01 100644 (file)
@@ -15,10 +15,7 @@ pub struct Update {
 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)]