projectharmonia / bevy_replicon

Server-authoritative networking crate for the Bevy game engine.
https://crates.io/crates/bevy_replicon
Apache License 2.0
352 stars 31 forks source link

Fix buffering for events that have mapped entities. #321

Closed Shatur closed 2 months ago

Shatur commented 2 months ago

Closes #311.

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 64.55696% with 28 lines in your changes missing coverage. Please review.

Project coverage is 89.79%. Comparing base (3d48f5a) to head (b18ee8d). Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/core/event_registry/server_event.rs 48.83% 22 Missing :warning:
src/client/events.rs 87.87% 4 Missing :warning:
src/core/ctx.rs 33.33% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #321 +/- ## ========================================== - Coverage 90.60% 89.79% -0.82% ========================================== Files 37 37 Lines 2300 2293 -7 ========================================== - Hits 2084 2059 -25 - Misses 216 234 +18 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Shatur commented 2 months ago

Fixed the bug reported by @NiseVoid in Discord. Pushed it here since it touches the same code.

After the events refactor I map the event inside the deserialization function. But I need to deserialize the tick first and compare it for buffering. We didn't catch it in the tests because we didn't have a test for the combination of event buffering and entity mapping.

The fix is simple. The event queue is not generic now and stores the event in its serialized form. The resource now initialized inside the ClientPlugin. We deserialize the tick first, do comparsion and push the event to the queue if it's smaller.