gschup / ggrs

GGRS is a reimagination of GGPO, enabling P2P rollback networking in Rust. Rollback to the future!
Other
507 stars 25 forks source link

Custom input prediction function? #69

Open johanhelsing opened 9 months ago

johanhelsing commented 9 months ago

Is your feature request related to a problem? Please describe.

In some cases, it would be convenient to be able to send one-off events as part of the input struct:

struct Input {
    fire_just_pressed: bool,
    jump_held: bool,
}

However, when predicting, we would then get fire_just_presed == true repeatedly when predicting.

Describe the solution you'd like

Instead of just copying the input struct, perhaps it would make sense to be able to inject a prediction function?

session_builder.with_input_prediction(|input| {
    Input { fire_just_pressed: false, ..input }
})

https://github.com/gschup/ggrs/blob/48aec70c45e5c18c5d95398c9c7623547492021b/src/input_queue.rs#L144

Describe alternatives you've considered

Handling just_pressed logic inside the ggrs advance frame step works as a workaround, but sometimes the events you get from game engines are one-offs (bevy ui button press events etc.), so it generates a lot of boilerplate

Additional context

https://discord.com/channels/844211600009199626/844211600009199629/1175361006717898763

aleksa2808 commented 9 months ago

I was just about to make an issue about this, awesome timing!

This functionality would be very helpful in my game as the current ggrs behavior causes a lot of mispredictions in the mentioned cases of one-off events (every input in my game). Currently I'm just using a patched version of ggrs where I always assume the inputs are inactive.

gschup commented 9 months ago

I think that optionally providing a function for input predictions sounds great.