Add teanet-rust
This commit is contained in:
parent
ecaa5537a2
commit
edc23b3e8c
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,4 +2,5 @@
|
|||||||
godot/.godot/
|
godot/.godot/
|
||||||
godot/android/
|
godot/android/
|
||||||
|
|
||||||
rust/target
|
rust/target
|
||||||
|
target
|
||||||
5
rust/Cargo.lock → Cargo.lock
generated
5
rust/Cargo.lock → Cargo.lock
generated
@ -129,6 +129,7 @@ name = "quakeball"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"godot",
|
"godot",
|
||||||
|
"teanet",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -140,6 +141,10 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "teanet"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.24"
|
version = "1.0.24"
|
||||||
5
Cargo.toml
Normal file
5
Cargo.toml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"rust",
|
||||||
|
"teanet-rust"
|
||||||
|
]
|
||||||
@ -8,4 +8,4 @@ crate-type = ["cdylib"] # Compile this crate to a dynamic C library.
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
godot = "0.5.4"
|
godot = "0.5.4"
|
||||||
|
teanet = { path = "../teanet-rust" }
|
||||||
|
|||||||
@ -1,12 +1,15 @@
|
|||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use godot::{prelude::*, tools::get_autoload_by_name};
|
use godot::{prelude::*, tools::get_autoload_by_name};
|
||||||
|
use teanet::Peer;
|
||||||
|
|
||||||
use crate::ui::cli::{CLI_GLOBAL_NAME, CliColor, CommandLinePanel};
|
use crate::ui::cli::{CLI_GLOBAL_NAME, CliColor, CommandLinePanel};
|
||||||
|
|
||||||
#[derive(GodotClass)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=Node)]
|
#[class(base=Node)]
|
||||||
pub struct NetworkManager {
|
pub struct NetworkManager {
|
||||||
|
peer: Option<PeerKind>,
|
||||||
|
|
||||||
base: Base<Node>,
|
base: Base<Node>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,7 +18,7 @@ pub const NETWORK_SINGLETON_NAME: &str = "NetworkManagerGlob";
|
|||||||
#[godot_api]
|
#[godot_api]
|
||||||
impl INode for NetworkManager {
|
impl INode for NetworkManager {
|
||||||
fn init(base: Base<Node>) -> Self {
|
fn init(base: Base<Node>) -> Self {
|
||||||
NetworkManager { base }
|
NetworkManager { peer: None, base }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ready(&mut self) {
|
fn ready(&mut self) {
|
||||||
@ -34,14 +37,25 @@ impl INode for NetworkManager {
|
|||||||
|
|
||||||
impl NetworkManager {
|
impl NetworkManager {
|
||||||
pub fn host(&mut self, port: u32) {
|
pub fn host(&mut self, port: u32) {
|
||||||
get_autoload_by_name::<CommandLinePanel>(CLI_GLOBAL_NAME)
|
if self.peer.is_none() {
|
||||||
.bind_mut()
|
get_autoload_by_name::<CommandLinePanel>(CLI_GLOBAL_NAME)
|
||||||
.publish_message(format!("Hosting server at {}", port), CliColor::Info);
|
.bind_mut()
|
||||||
|
.publish_message(format!("Hosting server at {}", port), CliColor::Info);
|
||||||
|
self.peer = Some(PeerKind::Server(Peer::default(), port));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn join(&mut self, addr: SocketAddr) {
|
pub fn join(&mut self, addr: SocketAddr) {
|
||||||
get_autoload_by_name::<CommandLinePanel>(CLI_GLOBAL_NAME)
|
if self.peer.is_none() {
|
||||||
.bind_mut()
|
get_autoload_by_name::<CommandLinePanel>(CLI_GLOBAL_NAME)
|
||||||
.publish_message(format!("Joining server at {}", addr), CliColor::Info);
|
.bind_mut()
|
||||||
|
.publish_message(format!("Joining server at {}", addr), CliColor::Info);
|
||||||
|
self.peer = Some(PeerKind::Client(Peer::default(), addr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum PeerKind {
|
||||||
|
Client(Peer, SocketAddr),
|
||||||
|
Server(Peer, u32),
|
||||||
|
}
|
||||||
|
|||||||
1
teanet-rust
Submodule
1
teanet-rust
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit e2960002a23ee61dccaafd6951de16fc17c0ee19
|
||||||
Loading…
Reference in New Issue
Block a user