Browse Source

Fixed EpochTime lexicographical ordering

main
ThePerkinrex 4 years ago
parent
commit
7d240e319b
No known key found for this signature in database GPG Key ID: FD81DE6D75E20917
  1. 23
      server/src/server/game.rs
  2. 11
      server/src/server/time.rs
  3. 4
      unity/Assets/Scripts/Client.cs
  4. 1
      unity/Assets/Scripts/GameLoader.cs

23
server/src/server/game.rs

@ -223,11 +223,20 @@ pub(super) async fn get_cards_images(
.and_then(|x| { .and_then(|x| {
p.as_ref() p.as_ref()
.metadata() .metadata()
.and_then(|x| x.modified()) .map_err(|e| {
log::error!("MetadataError: {}", e);
e
})
.and_then(|x| {
x.modified().map_err(|e| {
log::error!("ModifiedError: {}", e);
e
})
})
.ok() .ok()
.map(|y| (y.into(), x.into())) .map(|y| (y.into(), x.into()))
}) })
.map_or(false, |(x, y): (EpochTime, EpochTime)| x > y) .map_or(true, |(x, y): (EpochTime, EpochTime)| x > y)
} }
if is_newer(&card_kind, &face) { if is_newer(&card_kind, &face) {
@ -261,8 +270,18 @@ pub(super) async fn get_cards_images(
.unwrap(); .unwrap();
} }
} }
// log::info!(
// "Loading {} (face: {}, back: {})",
// card_kind.kind,
// is_newer(&card_kind, &face),
// is_newer(&card_kind, &back)
// )
} }
let mut b = Bytes::from(ar.into_inner().unwrap().finish().into_result().unwrap()); let mut b = Bytes::from(ar.into_inner().unwrap().finish().into_result().unwrap());
log::info!(
"Compressed tar size: {}",
crate::allocator::as_string(b.len())
);
let n = (b.len() / MESSAGE_SIZE) + if b.len() % MESSAGE_SIZE == 0 { 0 } else { 1 }; let n = (b.len() / MESSAGE_SIZE) + if b.len() % MESSAGE_SIZE == 0 { 0 } else { 1 };
socket_mgr socket_mgr
.write( .write(

11
server/src/server/time.rs

@ -18,10 +18,17 @@ impl From<Timestamp> for EpochTime {
impl PartialOrd for EpochTime { impl PartialOrd for EpochTime {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
// log::debug!("{:?} > {:?} = {:?}, {:?}", self, other, self.0.seconds.partial_cmp(&other.0.seconds), self.0.nanos.partial_cmp(&other.0.nanos));
if other.0.seconds == self.0.seconds { if other.0.seconds == self.0.seconds {
self.0.seconds.partial_cmp(&other.0.seconds)
} else {
self.0.nanos.partial_cmp(&other.0.nanos) self.0.nanos.partial_cmp(&other.0.nanos)
} else {
self.0.seconds.partial_cmp(&other.0.seconds)
} }
} }
} }
impl std::fmt::Debug for EpochTime {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}+{}", self.0.seconds, self.0.nanos)
}
}

4
unity/Assets/Scripts/Client.cs

@ -150,6 +150,7 @@ public class Client : MonoBehaviour {
this.currentImagesPacketLength = (int)p.ReturnCardsImages.Setup.Number; this.currentImagesPacketLength = (int)p.ReturnCardsImages.Setup.Number;
this.currentImagesPacketIndex = 0; this.currentImagesPacketIndex = 0;
this.currentImages = new MemoryStream(); this.currentImages = new MemoryStream();
// Debug.Log("Setup received");
} else { } else {
if (p.ReturnCardsImages.DataPacket.Id != this.currentImagesPacketIndex) if (p.ReturnCardsImages.DataPacket.Id != this.currentImagesPacketIndex)
throw new Exception("images packet id doesn't match expected"); throw new Exception("images packet id doesn't match expected");
@ -157,9 +158,12 @@ public class Client : MonoBehaviour {
Debug.Log(this.currentImages.ToArray()[0] + ":" + p.ReturnCardsImages.DataPacket.Data.Span.ToArray()[0]); Debug.Log(this.currentImages.ToArray()[0] + ":" + p.ReturnCardsImages.DataPacket.Data.Span.ToArray()[0]);
this.currentImagesPacketIndex++; this.currentImagesPacketIndex++;
if (this.currentImagesPacketIndex == this.currentImagesPacketLength) { if (this.currentImagesPacketIndex == this.currentImagesPacketLength) {
// Debug.Log("Last packet received");
// Debug.Log("Images tar length: " + this.currentImages.Length); // Debug.Log("Images tar length: " + this.currentImages.Length);
this.currentImages.Seek(0, SeekOrigin.Begin); this.currentImages.Seek(0, SeekOrigin.Begin);
// Debug.Log("Starting decoding");
Images i = new Images(this.currentImages); Images i = new Images(this.currentImages);
// Debug.Log("Finished decoding");
this.currentImagesPacketIndex = 0; this.currentImagesPacketIndex = 0;
var v = new Action<Images>[this.returnCardImagesHandlers.Count]; var v = new Action<Images>[this.returnCardImagesHandlers.Count];
this.returnCardImagesHandlers.Values.CopyTo(v, 0); this.returnCardImagesHandlers.Values.CopyTo(v, 0);

1
unity/Assets/Scripts/GameLoader.cs

@ -169,6 +169,7 @@ public class GameLoader : MonoBehaviour {
// }); // });
// conn.GetCardImage(card.Kind.Kind); // conn.GetCardImage(card.Kind.Kind);
cards.Add(new Client.Card(card.Kind.Kind)); cards.Add(new Client.Card(card.Kind.Kind));
// Debug.Log(card.Kind.Kind);
} }
} }
} }

Loading…
Cancel
Save