-
Notifications
You must be signed in to change notification settings - Fork 44
feat: add configurable StagedPhysicsPlugin #171
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for the contribution :-) Very much appreciated!
I would prefer to add new plugins only without touching the type definition of the old ones. In other words, I'd like to add the feature without breaking the existing API.
I think it should be possible. We can even share logic, if the old plugin can create and invoke the new one when it is installed.
That makes sense, so are you saying to make a new version of the rapier plugin and have the old one just call into it? |
Yes. Conceptualy like this: pub struct PhysicsPlugin; // Same definition as before
pub struct StagedPhysicsPlugin { /* fields */ } // New plugin
impl Plugin for PhysicyPlugin {
// Old plugin implementation reworked to delegate to the new plugin
fn build(&self, app: &mut App) {
app.add_plugin(CorePlugin) // Add the core stages
app.add_plugin(StagedPlugin { /* ... */ }); // Install the "StagedPlugin", using the stages installed by the `CorePlugin`
}
}
impl Plugin for StagedPhysicsPlugin {
fn build(&self, app: &mut App) {
/*
The new setup code, previously in `PhysicsPlugin`.
Here in its modified version, that add the system on the parametrized stages
(either defined manually by the end-user or by the `PhysicsPlugin`)
*/
}
} |
ooo your talking about "root" plugin here https://github.com/JRMurr/heron/blob/2605f414e7536d148f93a8489be5a708d1cb3c05/src/lib.rs#L159 and not the "interal" rapier plugin here https://github.com/JRMurr/heron/blob/2605f414e7536d148f93a8489be5a708d1cb3c05/rapier/src/lib.rs#L52. Yea that should be a simple fix |
mmh... sorry, I forgot about that one. But, I'm talking about both. Actually about all of them (incl. the For instance the // A consumer may write this, and it compiles. So it should continue to compile.
let _ = heron_core::CorePlugin; |
ahhh ok that makes more sense, will do! |
It looks like the tests running |
Thanks for the changes, it looks great. I'll have a deeper look soon (-ish).
It doesn't happen for me locally either. I am on archlinux + rustup, and I tried with with rust 1.57 to be sure using the same rust version as the github action. Let's see... I'll try to look at it too. |
the CI passed now... I don't know, maybe there is a flakyness. But I doubt it was due to your code. When you think you don't have anything else to add, you can mark the PR as ready-for-review, and I'll try to have a deeper look and merge when I find the time (hopefuly during the week). |
@jcornaz I think its good for review, my test here https://github.com/JRMurr/heron/blob/2283b5974385765cb61b4c0b65dd611c32dd5aa0/rapier/tests/resources.rs#L92 is a little cheeky its just checking that https://github.com/JRMurr/heron/blob/2283b5974385765cb61b4c0b65dd611c32dd5aa0/rapier/src/lib.rs#L141 are added. |
If I understand well, your need is to choose in what stage the actual physics step happen (the systems that are currently running on But, do you think it would be feasible to always run the If we could make this (minor) simplification in the API, that would be nice I think. On another topic: maybe the Plugins would be easier to understand/use if they weren't generic. The fields types could be |
Yea for my current implementation i was feeling iffy on the I'll have to think on this some more. Might be a good idea to just have the user be able to kick off the physics tick manually when re-simulating As for the |
It is possible to configure for constant physics rate, via |
Hey, you know what? While talking about our problem in the bevy discrod I got an idea... What if, we only let the user choose in which stage to run the physics step (The one which currently runs in That would means:
I am starting to think that the pros outweight the cons in this case. What do you think @JRMurr? |
Hmm tbh im still a little confused on what each stage actually does. Do these comments describe it mostly correctly? https://github.com/JRMurr/heron/blob/2283b5974385765cb61b4c0b65dd611c32dd5aa0/rapier/src/lib.rs#L73 I think not configuring I understand your goals for making the heron api simple and easy to use so if you feel that this makes it more complex i understand |
Here are what the stages do (in order):
Ah ok. I didn't understand that correctly. So basically you do need to define where all of them run (physics-time update, rapier-update, bevy-update). Is that correct?
Well, I am trying to simplify as much as I can yes. But that doesn't mean I am against a slightly more complex solution. I am just trying to iterate on it, to see if we can improve it. But I think I now understand you do need to define where to run the three stages. I guess if you can just use Thanks for helping me to understand the context :) |
Yea, the idea for rollbacks is you predict what the other players inputs were (usally just repeat what they were doing the last time you got inputs from them) and when you get their next input check if that predicition was correct. If not you re-load the game state and re simulate given that input. So the idea would have a I wonder if we could add a validation step when heron uses the passed labels to make sure the relative ordering makes sense and panic? Ill work on the Thanks again for making this lib, its wonderful to use! |
@JRMurr are you planning to continue working on it? |
@jcornaz But why use |
Because there are not one but three stages. And I feel like having to define three stages via positional generics is error-prone and not very ergonomic. And the "cost" of having it resolved at run-time is completely negligible because it is only resolved at startup and they are ultimately boxed by bevy anyway. EDIT: Not to mention that generic would makes impossible to change the stages without breaking the API |
Got it! But do we need to configure |
Ideally, that's what I would like. I suggested something in this direction in one of my previous comment. But I understood from @JRMurr, that they do need to configure the three stages. |
I'm curious why. Looking forward to his reply. |
.insert_resource(ColliderSet::new()) | ||
.insert_resource(JointSet::new()) | ||
.insert_resource(CCDSolver::new()) | ||
.add_system_set_to_stage(self.post_physics_stage.clone(), step_systems()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this approach will work for something like bevy_ggrs
(yet). That library impl Stage for GGRSStage
, which it uses to handle updating game state with ggrs
, which it adds before CoreStage::Update
. Unfortunately, add_system_set_to_stage
only works for SystemStages. This means, specifically for bevy_ggrs
at least, that bevy function will not find the GGRSStage
and add the desired step systems.
That's not to say this PR doesn't work, just that it will not work with other plugins that implement custom stages (i.e., bevy_ggrs
). (I am guessing bevy_backroll
also falls into this category, but I have not read much, going by this impl Stage
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Not sure if we even can do anything for it until stageless.
Actually, we can do better. Instead of setting user-defined labels we can make heron's stage labels public and add an option to not create actual stages, only put systems at labels. User will just create its own stages with this labels and user will be able to run them in its own exclusive system. No generics or boxes required, just a boolean option. |
Closes: #170
Added the
StagedPhysicsPlugin
which allows you to pass in stage labels for the main physics schedule, the post physics stage, and tick stage.The main physics needs to be a schedule and not just a stage since it uses sub stages. The other two are fine as just stages.
Creating as a draft since I'm not sure the best way to add tests for this. I made an example
custom_schedule.rs
which is basically just the demo example using the new plugin.I'm still somewhat new to bevy/heron so let me know if the comments I added don't make sense