From 74cc64c56807d95e2b5bb010ccdf073ca820ce08 Mon Sep 17 00:00:00 2001 From: malek Date: Sat, 30 Jul 2022 02:28:17 -0700 Subject: [PATCH] feat(README): added plugin guidelines --- README.md | 3 +++ client/src/networking/networking_plugin.rs | 0 client/src/networking/plugin.rs | 28 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) delete mode 100644 client/src/networking/networking_plugin.rs create mode 100644 client/src/networking/plugin.rs diff --git a/README.md b/README.md index 8920140..122dc89 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,6 @@ Second, all structs that are passed as events should not be naked if they contai Third, you must put events and resources within their own local files `event` and `resource` and you should also only refer to them using the `event::EVENT` or `resource::RESOURCE` syntax. You should not import the full namespace down to `event` or `resource`, at maximum you can only import to the level before that. This helps to keep events and resources and other structs distinct. +### Plugins + +The `plugin` is a very important concept in `bevy` for modularity, and reusability. As such many pieces of `nexus` are split into multiple plugins. As plugins are once again structs given extra behavior they follow the rules above, placed in their own local `plugin` folder, however plugins are likely to be used outside of `nexus` so having `plugin` as part of the name, such as `struct PayloadPlugin` is not only permissible, but required, `Plugin` must be postfixed to the end of any `plugin` struct. \ No newline at end of file diff --git a/client/src/networking/networking_plugin.rs b/client/src/networking/networking_plugin.rs deleted file mode 100644 index e69de29..0000000 diff --git a/client/src/networking/plugin.rs b/client/src/networking/plugin.rs new file mode 100644 index 0000000..bcabc3c --- /dev/null +++ b/client/src/networking/plugin.rs @@ -0,0 +1,28 @@ +use std::net::SocketAddr; +use bevy::app::{App, Plugin}; +use bevy::prelude::{Commands, EventReader, ResMut}; +use bytes::Bytes; +use crossbeam_channel::{Receiver, Sender}; +use qp2p::{Config, Endpoint}; +use tokio::runtime::Runtime; +use bevy_add_events_macro::add_events; +use crate::networking::{event, resource}; + +pub struct NetworkingPlugin; + +impl Plugin for NetworkingPlugin { + fn build(&self, app: &mut App) { + add_events!(app, ServerConnection, ServerSocketAddr); + app.add_startup_system(setup_networking_runtime()); + } +} + +pub fn setup_networking_runtime(mut commands: Commands) { + commands.insert_resource(resource::NetworkingRuntime(Runtime::new().expect("networking runtime needs to be init'd to work!"))); +} + +pub fn connection_added(mut commands: Commands, mut socket_addr: EventReader, mut networking_runtime: ResMut) { + let mut config = Config::default(); + config.idle_timeout = None; + let endpoint = Endpoint::new_client(SocketAddr::from) +} \ No newline at end of file