3 个不稳定版本
0.3.0 | 2021 年 12 月 7 日 |
---|---|
0.2.1 | 2021 年 6 月 11 日 |
0.2.0 | 2021 年 6 月 8 日 |
199 在 模拟 中排名
每月 25 次下载
8MB
3K SLoC
crystalorb-bevy-networking-turbulence
提供 crystalorb::network_recource::NetworkResource
的包装实现,允许 bevy_networking_turbulence
插件与 CrystalOrb
一起使用。
为了方便,还提供了一个 bevy 插件,该插件执行必要的设置(例如在 bevy_networking_turbulence
插件中注册所需的消息通道,以及注册 Client/
Server
资源)
陷阱
目前,您仍然需要将所有物理和实时游戏逻辑放入 CrystalOrb::world::World
,但理想情况下,将它们放入 bevy ECS 中会更好(因为 ECS 可能是您最初选择 bevy 的原因)。将来,可能会实现 CrystalOrb::world::World
以用于 bevy 应用程序(欢迎贡献!!)这样我们就可以在 bevy 中运行 CrystalOrb,在 bevy 中运行 bevy(bevyception?如果这个名字还没被占用,那会是个酷名字)。
用法
- 将
CrystalOrbClientPlugin
bevy 插件 添加到您的客户端 bevy 应用程序中。 - 将
CrystalOrbServerPlugin
bevy 插件 添加到您的服务器 bevy 应用程序中。 - 将您的客户端应用程序中的
CrystalOrb::Client
作为 bevy 资源 访问。 - 在您的服务器应用中,将
CrystalOrb::Server
作为 bevy 资源 访问。
以下是一个示例客户端
use bevy::prelude::*;
use crystalorb_demo::{DemoWorld, DemoCommand, PlayerSide, PlayerCommand};
use crystalorb_bevy_networking_turbulence::{
WrappedNetworkResource,
CrystalOrbClientPlugin,
crystalorb::{
Config,
client::{
Client,
stage::StageMut as ClientStageMut,
},
},
CommandChannelSettings,
bevy_networking_turbulence::{
NetworkResource,
MessageChannelSettings,
MessageChannelMode,
ReliableChannelSettings
},
};
use std::time::Duration;
#[derive(Default)]
struct PlayerInputState {
jump: bool,
}
fn player_input(
mut state: Local<PlayerInputState>,
input: Res<Input<KeyCode>>,
mut client: ResMut<Client<DemoWorld>>,
mut net: ResMut<NetworkResource>,
) {
if let ClientStageMut::Ready(mut ready_client) = 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.
.insert_resource(CommandChannelSettings(
MessageChannelSettings {
channel: 0,
channel_mode: MessageChannelMode::Compressed {
reliability_settings: ReliableChannelSettings {
bandwidth: 4096,
recv_window_size: 1024,
send_window_size: 1024,
burst_bandwidth: 1024,
init_send: 512,
wakeup_time: Duration::from_millis(100),
initial_rtt: Duration::from_millis(200),
max_rtt: Duration::from_secs(2),
rtt_update_factor: 0.1,
rtt_resend_factor: 1.5,
},
max_chunk_len: 1024,
},
message_buffer_size: 64,
packet_buffer_size: 64,
}
))
.add_plugins(DefaultPlugins)
.add_plugin(CrystalOrbClientPlugin::<DemoWorld>::new(Config::default()))
.add_system(player_input.system())
.run();
}
以下是一个示例服务器
use bevy::prelude::*;
use crystalorb_demo::DemoWorld;
use crystalorb_bevy_networking_turbulence::{
CrystalOrbServerPlugin,
crystalorb::Config,
CommandChannelSettings,
bevy_networking_turbulence::{
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.
.insert_resource(CommandChannelSettings(
MessageChannelSettings {
channel: 0,
channel_mode: MessageChannelMode::Compressed {
reliability_settings: ReliableChannelSettings {
bandwidth: 4096,
recv_window_size: 1024,
send_window_size: 1024,
burst_bandwidth: 1024,
init_send: 512,
wakeup_time: Duration::from_millis(100),
initial_rtt: Duration::from_millis(200),
max_rtt: Duration::from_secs(2),
rtt_update_factor: 0.1,
rtt_resend_factor: 1.5,
},
max_chunk_len: 1024,
},
message_buffer_size: 64,
packet_buffer_size: 64,
}
))
.add_plugins(DefaultPlugins)
.add_plugin(CrystalOrbServerPlugin::<DemoWorld>::new(Config::default()))
.run();
}
依赖项
约16-32MB
约493K SLoC