"fehler",
"index_vec",
"lazy_static",
+ "num-traits",
"rand",
"rocket",
"rocket_contrib",
index_vec = "0.1.1"
+num-traits = "0.2"
+
rocket = "0.4"
rocket_contrib = { version = "0.4", default-features=false, features=["tera_templates","helmet","json"] }
#[derive(Debug)]
struct UpdateReader {
- playerid : PlayerId,
+ player : PlayerId,
client : ClientId,
to_send : UpdateCounter, // xxx race for setting this initially
- ami : Arc<Mutex<Instance>>>,
+ ami : Arc<Mutex<Instance>>,
}
impl Read for UpdateReader {
let amig = self.ami.lock()?;
let orig_wanted = buf.len();
- let pu = &mut amig.updates.get(playerid)
+ let pu = &mut amig.updates.get(self.player)
.ok_or_else(|| io::Error::new
- (ErrorKind::Other, anyhow!("player gonee")))?;
+ (io::ErrorKind::Other, anyhow!("player gonee")))?;
loop {
let next = match pu.log.get(self.to_send) {
Some(next) => next, None => { break }
let generated = orig_wanted - buf.len();
if generated > 0 { return generated }
- (amig,_) = cv.wait_timeout(amig, UPDATE_KEEPALIVE)?;
+ amig = self.cv.wait_timeout(amig, UPDATE_KEEPALIVE)?.0;
write!(buf,r#"
: keepalive
"#);
}
}
*/
-
+/*
thread::sleep(Duration::from_millis(500));
let message = XUpdate::TestCounter { value : self.next };
buf[0..data.len()].copy_from_slice(data.as_bytes());
Ok(buf.len())
}
-}
+}*/
/*
#[derive(Deserialize)]
pub struct PreparedUpdate {
gen : Counter,
client : ClientId,
- piece : PieceId;
+ piece : PieceId,
client_seq : ClientSequence,
json : String,
}
pub struct PlayerUpdates {
- pub log : StableIndexVecDeque<UpdateCounter,PreparedUpdate>,
+ pub log : StableIndexVecDeque<PreparedUpdate,UpdateCounter>,
pub cv : Condvar,
}
nick : nick.to_string(),
};
let player = ig.gs.players.insert(np);
- let ia = InstanceAccessDetails { g : g.clone(), ident : player };
+ let ia = InstanceAccessDetails { g : amu.clone(), ident : player };
GLOBAL.players.write().unwrap().insert(
RawToken(token.to_string()), ia
);
pub type SecondarySlotMap<K,V> = slotmap::secondary::SecondaryMap<K,V>;
pub use index_vec::{define_index_type,index_vec,IndexVec};
+pub use vecdeque_stableix::StableIndexVecDeque;
+
pub use crate::global::*;
pub use crate::gamestate::*;
pub use crate::pieces::*;
pub use crate::keydata::*;
pub use crate::updates::*;
+pub use crate::sse::*;
pub type E = anyhow::Error;
pub type AE = anyhow::Error;
pub mod gamestate;
pub mod keydata;
pub mod updates;
+pub mod sse;
--- /dev/null
+
+use crate::imports::*;
+
+#[derive(Copy,Clone,Debug,Eq,PartialEq,Ord,PartialOrd)]
+#[derive(Serialize,Deserialize)]
+#[serde(transparent)]
+pub struct UpdateCounter (i64);
+
+use vecdeque_stableix::StableIndexOffset;
+use std::ops::Neg;
+
+impl Neg for UpdateCounter {
+ type Output = Self;
+ fn neg(self) -> Self { UpdateCounter(-self.0) }
+}
+
+impl StableIndexOffset for UpdateCounter {
+ fn try_increment(&mut self) -> Option<()> { self.0.try_increment() }
+ fn try_decrement(&mut self) -> Option<()> { self.0.try_decrement() }
+ fn index_input(&self, input: Self) -> Option<usize> {
+ self.0.index_input(input.0)
+ }
+ fn index_output(&self, inner: usize) -> Option<Self> {
+ self.0.index_output(inner).map(|v| UpdateCounter(v))
+ }
+ fn zero() -> Self { UpdateCounter(0) }
+}