chiark / gitweb /
wip new updates
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 29 Jun 2020 00:23:42 +0000 (01:23 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 29 Jun 2020 00:23:42 +0000 (01:23 +0100)
src/bin/server.rs
src/global.rs
src/imports.rs

index aaf3878ca1810c14a68b058877d655e5ef38fba7..0ed614364294b19218a02f5cb19cf4e21514491b 100644 (file)
@@ -165,16 +165,12 @@ fn api_grab(form : Json<ApiGrab>) -> 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<TestCounterInner>;
 #[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<usize> {
     thread::sleep(Duration::from_millis(500));
     let message = XUpdate::TestCounter { value : self.next };
index 50a02a54b5b29967fe08c4280b2dd15178607d79..f32831c63284c024e6b60c6cf2da99845bab4ef6 100644 (file)
@@ -23,9 +23,15 @@ impl Client {
   }
 }
 
+pub struct PlayerUpdates {
+  pub log : VecDeque<(ClientId, Arc<Update>)>,
+  pub cv : Condvar,
+}
+
 pub struct Instance {
   pub gs : GameState,
   pub clients : DenseSlotMap<ClientId,Client>,
+  pub updates : SecondarySlotMap<PlayerId, PlayerUpdates>,
 }
 
 #[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();
index 1cf8593e12523e36590bbcccf8c9f8ca0b75e9c2..92c6944794848a6169d47e75dd124eb23691cb52 100644 (file)
@@ -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};