UkoeHB / renet2

Server/Client network library for multiplayer games with authentication and connection management made with Rust. Forked from renet.
Apache License 2.0
18 stars 3 forks source link

RenetChannelsExt doesn't seem to be implemented for RepliconChannels #18

Closed mirsella closed 2 months ago

mirsella commented 2 months ago

hello

i was trying to use bevy_replicon_renet2, but i didnt manage to call the RenetChannelsExt method:

error[E0599]: no method named `get_server_configs` found for struct `bevy::prelude::Res<'_, bevy_replicon::prelude::RepliconChannels>` in the current scope
  --> src/main.rs:66:55
   |
66 |                 let server_channels_config = channels.get_server_configs();
   |                                                       ^^^^^^^^^^^^^^^^^^ method not found in `Res<'_, RepliconChannels>`

error[E0599]: no method named `get_client_configs` found for struct `bevy::prelude::Res<'_, bevy_replicon::prelude::RepliconChannels>` in the current scope
  --> src/main.rs:67:55
   |
67 |                 let client_channels_config = channels.get_client_configs();
   |                                                       ^^^^^^^^^^^^^^^^^^ method not found in `Res<'_, RepliconChannels>`

error[E0599]: no method named `get_server_configs` found for struct `bevy::prelude::Res<'_, bevy_replicon::prelude::RepliconChannels>` in the current scope
   --> src/main.rs:101:55
    |
101 |                 let server_channels_config = channels.get_server_configs();
    |                                                       ^^^^^^^^^^^^^^^^^^ method not found in `Res<'_, RepliconChannels>`

error[E0599]: no method named `get_client_configs` found for struct `bevy::prelude::Res<'_, bevy_replicon::prelude::RepliconChannels>` in the current scope
   --> src/main.rs:102:55
    |
102 |                 let client_channels_config = channels.get_client_configs();
    |                                                       ^^^^^^^^^^^^^^^^^^ method not found in `Res<'_, RepliconChannels>`

warning: unused import: `RenetChannelsExt`
  --> src/main.rs:23:5
   |
23 |     RenetChannelsExt, RepliconRenetPlugins,
   |     ^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

you can replicate this issue by doing this: cargo new a cargo.toml:

[package]
name = "a"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.14.2"
bevy_replicon = "0.28.3"
bevy_replicon_renet2 = { git = "https://github.com/UkoeHB/renet2", tag = "0.0.5", features = [
  "wt_server_transport",
  "wt_client_transport",
  "native_transport",
] }
clap = { version = "4.5.18", features = ["derive"] }
serde = "1.0.210"

And copy the examples/simple_box.rs to main.rs. and that's it.

In the example, it probably works because it's the same crate or something like that

thanks !

mirsella commented 2 months ago

i was thinking its because its a Res, but no, even with a pure RepliconChannels it doesn't work. also, it work in the example with a Res so the issue is not that. i think its just being no another crate, the RenetChannelsExt for RepliconChannels might to apply correctly ?

mirsella commented 2 months ago

it seems that bevy_replicon_renet is working, and surprisingly, the code for this trait is the same between the two crates bevy_replicon_renet and bevy_replicon_renet2:

/// External trait for [`RepliconChannels`] to provide convenient conversion into renet channel configs.
pub trait RenetChannelsExt {
    /// Returns server channel configs that can be used to create [`ConnectionConfig`](renet2::ConnectionConfig).
    fn get_server_configs(&self) -> Vec<ChannelConfig>;

    /// Same as [`RenetChannelsExt::get_server_configs`], but for clients.
    fn get_client_configs(&self) -> Vec<ChannelConfig>;
}

impl RenetChannelsExt for RepliconChannels {
    fn get_server_configs(&self) -> Vec<ChannelConfig> {
        create_configs(self.server_channels(), self.default_max_bytes)
    }

    fn get_client_configs(&self) -> Vec<ChannelConfig> {
        create_configs(self.client_channels(), self.default_max_bytes)
    }
}
mirsella commented 2 months ago

Oh, it works on main, but not with the tag 0.0.5. do you know which commit fix it ? im curious

UkoeHB commented 2 months ago

Oh, it works on main, but not with the tag 0.0.5.

Oh hey, sorry about this. I updated the bevy_replicon dependency but didn't make a new tag yet. You got that error due to bevy_replicon_renet2 using a different version than your project (essentially a linker error). I will make a new tag now!

mirsella commented 2 months ago

ohh thats why... thanks !

UkoeHB commented 2 months ago

@mirsella tag 0.0.6 has been pushed.