Henauxg / bevy_quinnet

A Client/Server game networking plugin using QUIC, for the Bevy game engine.
Apache License 2.0
251 stars 16 forks source link

Make systems used in initialization of this Plugin public #8

Closed tomaspecl closed 1 year ago

tomaspecl commented 1 year ago

It is often useful to create custom Stages or SystemSets but your Plugin does not allow for putting the systems into custom Stages or SystemSets. I need to be able to insert and delete Client and Server resource at runtime and run their systems when appropriate. Simply using the following is not flexible enough:

app
.add_plugin(QuinnetClientPlugin::default())
.add_plugin(QuinnetServerPlugin::default());

I need the controll so that I can manage when the Client and Server resource is created and manage when the systems run.

So make these pub please:

bevy_quinnet::client::create_client bevy_quinnet::client::update_sync_client bevy_quinnet::client::update_sync_client bevy_quinnet::server::update_sync_server and maybe also AsyncRuntime?

Henauxg commented 1 year ago

Thanks for your input, I will have a look at it tonight as I may want to modify some bits about the Client and Server resources if I come to expose create_... as public.

Could you tell me a bit more about your specific use case, needing to modify the plugin scheduling ? In particular, I'm curious about Resource deletion.

tomaspecl commented 1 year ago

So first: yes I need to (want to) be able to change the app scheduling / when the updates happen. I have an app which contains both the Client and the Server and which one gets used (connected to other instance) is determined at runtime. Currently I have to add both ClientPlugin and ServerPlugin and then at runtime setup (connect) one of them. Now why should there even exist a Client/Server instance (Resource) and why should its corresponding update system run when it is not in use?

And then lets say that inside my app I start running the Client and after some time I want to stop the Client and start running the Server. Then I could just remove the Client resource and insert the Server resource. And have all my custom systems set up to only run when the Client/Server resource exists.

If you want you can take a look at my work in progress game: https://github.com/tomaspecl/gravishot

Henauxg commented 1 year ago

I made some changes to help with these needs. You can find them in a bevy-0.10.0 branch here.

I will wait for Bevy 0.10.0 (which should happen in a week or so) before releasing these changes as it directly relates to the bevy scheduling which is modified by the stageless RFC going live with the 0.10.0 release.

[*] Events & Systems scheduling: you still need to provide Bevy with events and systems to be scheduled at initialization time as bevy schedule is not dynamic (events modify the schedule too by adding their own systems).

Note that, even in the current version, server and client update systems won't do any work and just return if respectively, the server endpoint is closed, the client connections are all closed. With the above changes, the client & server systems simply won't get called instead of returning. This is also the difference between Bevy 0.9 and 0.10 with_run_criteria (return early from a system) versus run_if (before entering a system)

Henauxg commented 1 year ago

Now part of main, released in 0.4.0