crystalorb-bevy-networking-turbulence

Provides a wrapper implementation of crystalorb::network_recource::NetworkResource that allows the bevy_networking_turbulence plugin to be used with CrystalOrb.

For your convenience, a bevy plugin is also provided that performs the necessary setup (such as registering the required message channels in the bevy_networking_turbulence plugin, and registering the Client/Server resources)

Pitfalls

At the moment, you still need to put all your physics and real-time game logic into the CrystalOrb::world::World, but, ideally, it would be great to put them into the bevy ECS instead (since the ECS is probably the reason why you want to use bevy in the first place). In the future, it might be possible to implement CrystalOrb::world::World for a bevy app (contributions welcome!!) so that we can run bevy inside CrystalOrb inside bevy (bevyception? That'll be a cool name if it's not already taken).

Usage

Heres an example client:

```rust use bevy::prelude::*; use crystalorbdemo::{DemoWorld, DemoCommand, PlayerSide, PlayerCommand}; use crystalorbbevynetworkingturbulence::{ WrappedNetworkResource, CrystalOrbClientPlugin, crystalorb::{ Config, client::{ Client, stage::StageMut as ClientStageMut, }, }, CommandChannelSettings, bevynetworkingturbulence::{ NetworkResource, MessageChannelSettings, MessageChannelMode, ReliableChannelSettings }, }; use std::time::Duration;

[derive(Default)]

struct PlayerInputState { jump: bool, }

fn playerinput( mut state: Local, input: Res>, mut client: ResMut>, mut net: ResMut, ) { if let ClientStageMut::Ready(mut readyclient) = client.stage_mut() { let jump = input.pressed(KeyCode::Up);

if jump != state.jump {
  ready_client.issue_command(
    DemoCommand::new(
      PlayerSide::Left,
      PlayerCommand::Jump,
      jump
    ),
    &mut WrappedNetworkResource(&mut *net),
  );

}

state.jump = jump;

} }

fn main() { App::build() // You can optionally override some message channel settings // There is CommandChannelSettings, SnapshotChannelSettings, and ClockSyncChannelSettings // Make sure you apply the same settings for both client and server. .insertresource(CommandChannelSettings( MessageChannelSettings { channel: 0, channelmode: MessageChannelMode::Compressed { reliabilitysettings: ReliableChannelSettings { bandwidth: 4096, recvwindowsize: 1024, sendwindowsize: 1024, burstbandwidth: 1024, initsend: 512, wakeuptime: Duration::frommillis(100), initialrtt: Duration::frommillis(200), maxrtt: Duration::fromsecs(2), rttupdatefactor: 0.1, rttresendfactor: 1.5, }, maxchunklen: 1024, }, messagebuffersize: 64, packetbuffersize: 64, } )) .addplugins(DefaultPlugins) .addplugin(CrystalOrbClientPlugin::::new(Config::default())) .addsystem(player_input.system()) .run(); } ```

Here's an example server:

```rust use bevy::prelude::*; use crystalorbdemo::DemoWorld; use crystalorbbevynetworkingturbulence::{ CrystalOrbServerPlugin, crystalorb::Config, CommandChannelSettings, bevynetworkingturbulence::{ MessageChannelSettings, MessageChannelMode, ReliableChannelSettings }, }; use std::time::Duration;

fn main() { App::build() // You can optionally override some message channel settings // There is CommandChannelSettings, SnapshotChannelSettings, and ClockSyncChannelSettings // Make sure you apply the same settings for both client and server. .insertresource(CommandChannelSettings( MessageChannelSettings { channel: 0, channelmode: MessageChannelMode::Compressed { reliabilitysettings: ReliableChannelSettings { bandwidth: 4096, recvwindowsize: 1024, sendwindowsize: 1024, burstbandwidth: 1024, initsend: 512, wakeuptime: Duration::frommillis(100), initialrtt: Duration::frommillis(200), maxrtt: Duration::fromsecs(2), rttupdatefactor: 0.1, rttresendfactor: 1.5, }, maxchunklen: 1024, }, messagebuffersize: 64, packetbuffersize: 64, } )) .addplugins(DefaultPlugins) .add_plugin(CrystalOrbServerPlugin::::new(Config::default())) .run(); } ```