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 a RollbackEventHook Trait #33

Closed
wants to merge 1 commit into from
Closed

Conversation

zicklag
Copy link
Contributor

@zicklag zicklag commented Nov 13, 2022

This allows you to register functions that will be called in response to GGRS messages.

I think I'm going to need this or something like it for my game, but I haven't tested it yet, so it's pending evaluation. I just wanted to get it up so you could look at it and give your thoughts on the idea.

@zicklag zicklag force-pushed the event-hook branch 3 times, most recently from bfdfbc1 to 739acc2 Compare November 13, 2022 21:26
@zicklag
Copy link
Contributor Author

zicklag commented Nov 14, 2022

Just tested this out and it appears to be working! I did this really quick without a lot of thought on the names, so it could probably use some more careful thought, which I'll try to put in later.

Another thing that might need re-visiting is the reasoning behind passing in the frame and the max_prediction values. My use was to figure out which snapshot slot to put save/load the data from, just like bevy_ggrs does internally.

Maybe it should just return a slot_id instead, so that I'm not doing the modulo on the two values myself.


Anyway, I used this to hook the JS/TS scripting engine in with the rollback in Jumpy, so that now both the Rust, and the JS code can both rollback and restore seamlessly.

It turned out pretty neat. :D I can't wait to really get the game working with GGRS.

@gschup
Copy link
Owner

gschup commented Nov 14, 2022

I like the idea in general! Let's think about the API for such hooks.

Looking at the commits, it seems like some entity mapping commits snuck into this PR. This needs to be cleaned up.

This allows you to register functions that will be called in response
to GGRS messages.
@zicklag
Copy link
Contributor Author

zicklag commented Nov 14, 2022

Just did a on main now that entity mapping is merged.

Let's think about the API for such hooks.

The specifics of what I ended up needing in my use-case was:

  • The pre_save hook ( post_save would have worked too ), to give my scripts a chance to snapshot their state. The only input I needed here was the "slot" to store my snapshot in, but I calculated that from the frame % max_snapshots.
  • The post_load hook, to give my scripts a chance to restore the state. In this case I needed the "slot" for the snapshot, same as before, and additionally the EntityMap so I could map any entities that I stored in the JS scope.

I figured I'd add the other hooks too, because they could be useful in different circumstances.

Later today, if I get the chance, I'll do a more careful pass over the code to see if there's anything I can obviously improve.

@gschup gschup mentioned this pull request Mar 12, 2023
3 tasks
@gschup
Copy link
Owner

gschup commented Mar 30, 2023

With bevy 0.10, these should be implemented as schedules for users to insert systems into. I will eventually get around to do this, but this current implementation is to cumbersome with the new bevy tools we got to use.

@gschup gschup closed this Mar 30, 2023
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.

None yet

2 participants