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

Add component to control frequency of sent entity movement packets. #440

Open
rj00a opened this issue Aug 4, 2023 · 2 comments
Open

Add component to control frequency of sent entity movement packets. #440

rj00a opened this issue Aug 4, 2023 · 2 comments
Labels
enhancement New feature or request needs research research is needed to make progress

Comments

@rj00a
Copy link
Member

rj00a commented Aug 4, 2023

Describe the problem related to your feature request.

The vanilla server does not send entity update packets every tick. It intentionally spaces them out to reduce network activity. I don't know what the exact number is off the top of my head, but it's something like every third tick. (I suspect this is why entities can feel laggy in vanilla).

It could be useful if valence also had this feature for situations with lots of entities.

What solution would you like?

Add a new component for entities called MovementUpdateDelay(pub u32) which defaults to 0. To check if it's time to send movement packets, do current_tick % (movement_update_delay + 1) == 0.

The OldPosition for entities will change to be the last synced position rather than the position from the previous tick. (Might be better to make a separate component for this, but I haven't thought about it enough).

What alternative(s) have you considered?

We could just not do this. The additional complexity and potential bugs might not be worth it.

@rj00a rj00a added the enhancement New feature or request label Aug 4, 2023
@Bafbi
Copy link
Contributor

Bafbi commented Aug 8, 2023

Add a new component for entities called MovementUpdateDelay(pub u32) which defaults to 0. To check if it's time to send movement packets, do current_tick % (movement_update_delay + 1) == 0.

The OldPosition for entities will change to be the last synced position rather than the position from the previous tick. (Might be better to make a separate component for this, but I haven't thought about it enough).

Wouldn't it be better to just do this method every x ticks ?

https://github.com/valence-rs/valence/blob/8759a2163210403821c64a9e18f248a44ad71034/crates/valence_layer/src/entity.rs#L487C42-L490

As well as the one that update the old position.

@Bafbi Bafbi mentioned this issue Aug 9, 2023
@rj00a
Copy link
Member Author

rj00a commented Aug 10, 2023

We can't just run that whole system every X ticks because there are some things unrelated to movement in there. I also think it would be best to configure this per-entity because I can imagine a server wanting player entities to have as little latency as possible, but all other entities with higher intervals.

I'm looking through Vanilla's and Minestom's source code right now, but I'm having trouble identifying exactly where all this is happening. So I might be completely misinformed.

@rj00a rj00a added low priority Other issues are more important needs research research is needed to make progress and removed low priority Other issues are more important labels Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs research research is needed to make progress
Projects
None yet
Development

No branches or pull requests

2 participants