From 70a2f8b43eba504e72c1e8e547bf5196992c9ca1 Mon Sep 17 00:00:00 2001 From: Aleksa Pavlovic Date: Thu, 14 Dec 2023 23:14:40 +0100 Subject: [PATCH] use seahash instead of bevy's AHash --- Cargo.toml | 5 +++-- src/snapshot/component_checksum.rs | 2 +- src/snapshot/mod.rs | 14 ++++++-------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0bd7682..c31bcfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,12 @@ wasm-bindgen = ["instant/wasm-bindgen", "ggrs/wasm-bindgen"] [dependencies] bevy = { version = "0.12", default-features = false } -bytemuck = { version = "1.7", features=["derive"]} +bytemuck = { version = "1.7", features = ["derive"] } instant = { version = "0.1", optional = true } log = "0.4" #ggrs = { version= "0.10.0", features=["sync-send"]} -ggrs = { git = "https://github.com/gschup/ggrs", features=["sync-send"]} +ggrs = { git = "https://github.com/gschup/ggrs", features = ["sync-send"] } +seahash = "4.1" [dev-dependencies] bevy = { version = "0.12", default-features = true } diff --git a/src/snapshot/component_checksum.rs b/src/snapshot/component_checksum.rs index e7efa4a..1ea63ce 100644 --- a/src/snapshot/component_checksum.rs +++ b/src/snapshot/component_checksum.rs @@ -71,7 +71,7 @@ where let mut result = 0; for (&rollback, component) in components.iter() { - let mut hasher = hasher.clone(); + let mut hasher = hasher; // Hashing the rollback index ensures this hash is unique and stable rollback_ordered.order(rollback).hash(&mut hasher); diff --git a/src/snapshot/mod.rs b/src/snapshot/mod.rs index f2b8c82..8d228ba 100644 --- a/src/snapshot/mod.rs +++ b/src/snapshot/mod.rs @@ -1,9 +1,7 @@ use crate::{ConfirmedFrameCount, Rollback, DEFAULT_FPS}; -use bevy::{ - prelude::*, - utils::{AHasher, FixedState, HashMap}, -}; -use std::{collections::VecDeque, hash::BuildHasher, marker::PhantomData}; +use bevy::{prelude::*, utils::HashMap}; +use seahash::SeaHasher; +use std::{collections::VecDeque, marker::PhantomData}; mod checksum; mod component_checksum; @@ -242,7 +240,7 @@ impl GgrsComponentSnapshot { } } -/// Returns a hasher built using Bevy's [FixedState] appropriate for creating checksums -pub fn checksum_hasher() -> AHasher { - FixedState.build_hasher() +/// Returns a hasher built using the `seahash` library appropriate for creating portable checksums. +pub fn checksum_hasher() -> SeaHasher { + SeaHasher::new() }