Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client-prediction tracking ("Client-mapped entities") #78

Merged
merged 33 commits into from
Oct 5, 2023

Conversation

RJ
Copy link
Contributor

@RJ RJ commented Oct 4, 2023

This is working fine, in the test and in my game (which has a misprediction cleanup system similar to the new docs describe).

I'm currently sending Entity::PLACEHOLDER where there is no prediction, so still need to decide on the packet format.
EDIT: pushed a change to encode compactly now

With a bit more code complexity, like a shared config between client and server, we can make it totally opt-in and zero cost if the feature isn't used, otherwise I think i can make it cost 1 bit per entity to mark if there's a predicted entity too.

This is to fix #67

@RJ
Copy link
Contributor Author

RJ commented Oct 4, 2023

i haven't added any sort of special way for the client to tell the server about predictions, imo that should be part of the game's existing custom protocol. all the game server needs to do is detect that, and update the prediction tracker.

@RJ
Copy link
Contributor Author

RJ commented Oct 4, 2023

If we made a new shared config struct that the client and server plugins take, this kind of feature can be opt in depending on the style of game. (perhaps we init_resource::<RepliconConfiguration>() and let consumers replace it if they dont like the defaults, so no other API changes for now)

how about something like:

#[derive(Default)]
struct RepliconConfiguration {
    // Makes the `PredictionTracker` available on the server, 
    // and supports client-predicted entity mapping.
    pub client_predictions: bool,
}

Another option might be to not insert the PredictionTracker resource by default, and make the user insert the resource on both client and server if they want to enable the feature (even though the client doesn't need it)

@codecov-commenter
Copy link

codecov-commenter commented Oct 4, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (4dbe6f1) 96.16% compared to head (3fedfb4) 95.53%.
Report is 1 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #78      +/-   ##
==========================================
- Coverage   96.16%   95.53%   -0.63%     
==========================================
  Files          13       13              
  Lines         834      874      +40     
==========================================
+ Hits          802      835      +33     
- Misses         32       39       +7     
Files Coverage Δ
src/lib.rs 100.00% <ø> (ø)
src/server/replication_buffer.rs 99.12% <100.00%> (+0.07%) ⬆️
src/server.rs 95.92% <80.00%> (-1.18%) ⬇️
src/client.rs 88.27% <78.94%> (-1.57%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RJ
Copy link
Contributor Author

RJ commented Oct 4, 2023

reverted the entity encoding commit and added a currently-failing test showing the edge case @Shatur pointed out relating to mapped components referencing the predicted entity.

"include additional array with entity to entity mappings instead. This array should come first and will be processed before replication and it just updates mappings on client. So additional callback won't be required. "

also noted there's no need for the prediction hit callback, since successful prediction means the predicted entity will receive (at least) the Replication component, so hits can be detected with a Query<Entity, <With<Prediction>, Added<Replication>>>

i will change it to using an entity mapping array as discussed.

@RJ RJ changed the title Client-prediction tracking Client-prediction tracking ("Client-mapped entities") Oct 5, 2023
@RJ RJ force-pushed the prediction branch 2 times, most recently from 8bf6b61 to d12971a Compare October 5, 2023 10:20
RJ and others added 6 commits October 5, 2023 11:25
We already have `to_client`, it's even shorter.
I think we should either move all readings there or nothing. But I don't
think that reading should be a part of `ReplicationBuffer`, I would prefer
to see them as free functions or as a part of some reader-like struct.
Also saves us from `Vec<(Entity, Entity)>` allocation.
Shatur added 7 commits October 5, 2023 21:31
- Use a dedicated struct instead of aliases.
- Provide more detalied example
- Remove filtering acknowledged ticks (acknowledged ticks are cleaned up).
- Use more consistent API inside `ReplicationBuffer` related to
  mappings.
Private functions do not need to be marked as inline,
they are inlined automatically.
See this awesome article:
https://matklad.github.io/2021/07/09/inline-in-rust.html
I prefer to avoid them. It's obvious what is going on from the function
name.
@Shatur Shatur requested a review from UkoeHB October 5, 2023 19:46
@Shatur Shatur marked this pull request as ready for review October 5, 2023 19:47
Copy link
Collaborator

@UkoeHB UkoeHB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason server.rs contains duplicate code from client_entity_map.rs. I am not going to transfer all my comments over to the correct file.

src/client.rs Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
src/server.rs Outdated Show resolved Hide resolved
Shatur and others added 5 commits October 6, 2023 01:05
These ones I applied almost as is, but instead of writing
(`client_entity`, `server_entity`) I referenced the argument in one
place and the type in general documentation.
For consistency with Rust docs.
@Shatur Shatur enabled auto-merge (squash) October 5, 2023 22:35
@Shatur Shatur merged commit 7fc85f2 into projectharmonia:master Oct 5, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support client predicted entities
4 participants