gschup / bevy_ggrs

Bevy plugin for the GGRS P2P rollback networking library.
Other
294 stars 41 forks source link

[Question] How to sync elapsed time since startup among peers? #100

Closed claudijo closed 7 months ago

claudijo commented 7 months ago

I'm writing a multiplayer game with ships that are positioned on an ocean with rolling waves. The shape of the waves in turn is dependent on time.elapsed_seconds().

So in order to have a consistent game state, I need to sync the elapsed time since startup among peers. Is that possible using bevy_ggrs (and matchbox), and if so how would you go about doing that? Thanks!

johanhelsing commented 7 months ago

Bevy ggrs already manages its own Time, so you can just use Res<Time> within the rollback schedule.

claudijo commented 7 months ago

Bevy ggrs already manages its own Time, so you can just use Res<Time> within the rollback schedule.

Thanks Johan. Currently following your excellent tutorial on https://johanhelsing.studio/posts/extreme-bevy.

A follow up question...

Do you know if there is a (convenient) way to make the GgrsSchedule Time available in shader code as well? I have a shader that renders the ocean waves and typically accesses the same elapsed time as game logic code, via bevy_pbr::mesh_view_bindings::globals::time. The idea is to sync the rocking of ships (handled by normal game logic) and the rendering of ocean waves (handled by shader code).

Cheers!

johanhelsing commented 7 months ago

It's a good topic for another blog post, and likely something I want for my game as well.

I don't remember the details, but what you want to do is probably set another uniform to Time<GgrsTime> and write a custom shader.

claudijo commented 7 months ago

Thanks Johan. Yeah, that's what I ended up doing.