},
Online => {
let estimate = updates.pcs.len() + updates.log.len();
- let irc = IsResponseToClientOp::No;
- let mut buf = PrepareUpdatesBuffer::new(g, irc, Some(estimate));
+ let mut buf = PrepareUpdatesBuffer::new(g, None, Some(estimate));
for (upiece, uuop) in updates.pcs {
let lens = TransparentLens { };
buf.piece_update(upiece, uuop, &lens);
use UpdateHandler::*;
match self {
Bulk(bulk) => {
- let irc = IsResponseToClientOp::No;
- let mut buf = PrepareUpdatesBuffer::new(g, irc, None);
+ let mut buf = PrepareUpdatesBuffer::new(g, None, None);
for (upiece, uuop) in bulk.pieces {
let lens = TransparentLens { };
buf.piece_update(upiece, uuop, &lens);
#[derive(Debug)]
pub enum PreparedUpdateEntry {
Piece {
- by_client: IsResponseToClientOp<(ClientId, ClientSequence)>,
+ by_client: IsResponseToClientOp,
piece : VisiblePieceId,
op : PieceUpdateOp<PreparedPieceState>,
},
pub struct PrepareUpdatesBuffer<'r> {
g : &'r mut Instance,
us : Vec<PreparedUpdateEntry>,
- by_client : IsResponseToClientOp<(ClientId, ClientSequence)>,
+ by_client : IsResponseToClientOp,
gen : Option<Generation>,
}
+/// In PROTOCOL.md terms, None is a Server update
+type IsResponseToClientOp = Option<(
+ WhatResponseToClientOp,
+ ClientId,
+ ClientSequence,
+)>;
#[derive(Debug,Copy,Clone)]
-pub enum IsResponseToClientOp<T> {
- /// In PROTOCOL.md terms, a Server update
- No,
+pub enum WhatResponseToClientOp {
/// In PROTOCOL.md terms, a Client update
- Predictable(T),
+ Predictable,
/// In PROTOCOL.md terms, a Client update which also updates
/// the visible piece image (which is just server-controlled).
- UpdateSvg(T),
+ UpdateSvg,
/// In PROTOCOL.md terms, a Client update which results in
/// an immediate Server update. When the client knows this
/// is going to happen it can help the user avoid conflicts.
- Unpredictable(T),
+ Unpredictable,
}
impl<'r> PrepareUpdatesBuffer<'r> {
pub fn new(g: &'r mut Instance,
- by_client: IsResponseToClientOp<(ClientId, ClientSequence)>,
+ by_client: IsResponseToClientOp,
estimate: Option<usize>) -> Self
{
let us = estimate.map_or(vec![], Vec::with_capacity);
}
fn new_for_error(ig: &'r mut Instance) -> Self {
- Self::new(ig, IsResponseToClientOp::No, Some(1))
+ Self::new(ig, None, Some(1))
}
pub fn piece_report_error(ig: &mut Instance,
error: PieceOpError, piece: PieceId,
fn piece_update_fallible(&mut self, piece: PieceId,
update: PieceUpdateOp<()>,
lens: &dyn Lens) -> PreparedUpdateEntry {
- type IRC = IsResponseToClientOp<(ClientId, ClientSequence)>;
+ type WRC = WhatResponseToClientOp;
let gen = self.gen();
let gs = &mut self.g.gs;
gs.max_z.update_max(pc.zlevel.z);
if let Some(new_lastclient) = match self.by_client {
- IRC::Predictable((tclient,_)) |
- IRC::UpdateSvg((tclient,_))
+ Some((WRC::Predictable,tclient,_)) |
+ Some((WRC::UpdateSvg, tclient,_))
=> if tclient == pc.lastclient { None } else { Some(tclient) }
_ => Some(Default::default()),
} {
// ---------- for traansmission ----------
-type IRC = IsResponseToClientOp<(ClientId, ClientSequence)>;
+type WRC = WhatResponseToClientOp;
impl PreparedUpdate {
- fn is_client(by_client: &IsResponseToClientOp<(ClientId, ClientSequence)>,
+ fn is_client(by_client: &IsResponseToClientOp,
ref_client: ClientId) -> Option<ClientSequence> {
- use IsResponseToClientOp::*;
- let &(c,cseq) = match by_client {
- Predictable (x) => x,
- UpdateSvg (x) => x,
- Unpredictable(x) => x,
- No => return None,
- };
- if c == ref_client { Some(cseq) } else { None }
+ match by_client {
+ &Some((_,c,cseq)) if c == ref_client => Some(cseq),
+ _ => None,
+ }
}
pub fn for_transmit(&self, dest : ClientId) -> TransmitUpdate {
Piece,
};
let ftg = if let Some(cseq) = Self::is_client(&by_client, dest) {
- match by_client {
- IRC::Predictable(_) => FTG::Recorded(cseq, None),
- IRC::UpdateSvg(_) => FTG::Recorded(cseq, ns()),
- IRC::Unpredictable(_) => if let Some(ns) = ns() {
+ match by_client.unwrap().0 {
+ WRC::Predictable => FTG::Recorded(cseq, None),
+ WRC::UpdateSvg => FTG::Recorded(cseq, ns()),
+ WRC::Unpredictable => if let Some(ns) = ns() {
FTG::Exactly(TUE::RecordedUnpredictable { piece, cseq, ns })
} else {
error!("internal error: for_transmit PreparedUpdateEntry::Piece with RecordedUnpredictable but PieceOp no NS");
FTG::Piece
}
- _ => unreachable!(),
}
} else {
FTG::Piece