diff --git a/Server.toml b/Server.toml index 08a172e..36d87ae 100644 --- a/Server.toml +++ b/Server.toml @@ -1,4 +1,3 @@ [server] -address = "0.0.0.0" -port = 1234 +address = "0.0.0.0:1234" max_clients = 254 diff --git a/kubi-server/Cargo.toml b/kubi-server/Cargo.toml index 3e4255d..1b5c09a 100644 --- a/kubi-server/Cargo.toml +++ b/kubi-server/Cargo.toml @@ -11,3 +11,8 @@ log = "*" shipyard = "0.6" serde = "1.0" toml = "0.7" +glam = { version = "0.22", features = ["debug-glam-assert", "fast-math"] } + +[features] +default = [] +unstable = ["glam/core-simd"] diff --git a/kubi-server/src/client.rs b/kubi-server/src/client.rs new file mode 100644 index 0000000..a0c57ac --- /dev/null +++ b/kubi-server/src/client.rs @@ -0,0 +1,4 @@ +use shipyard::Component; + +#[derive(Component)] +pub struct Client; diff --git a/kubi-server/src/config.rs b/kubi-server/src/config.rs new file mode 100644 index 0000000..a16dbf2 --- /dev/null +++ b/kubi-server/src/config.rs @@ -0,0 +1,23 @@ +use shipyard::{AllStoragesView, Unique}; +use serde::{Serialize, Deserialize}; +use std::{fs, net::SocketAddr}; + +#[derive(Serialize, Deserialize)] +pub struct ConfigTableServer { + pub address: SocketAddr, + pub max_clients: usize, +} + +#[derive(Unique, Serialize, Deserialize)] +pub struct ConfigTable { + pub server: ConfigTableServer +} + +pub fn read_config( + storages: AllStoragesView, +) { + log::info!("Reading config..."); + let config_str = fs::read_to_string("Server.toml").expect("No config file found"); + let config: ConfigTable = toml::from_str(&config_str).expect("Invalid configuration file"); + storages.add_unique(config); +} diff --git a/kubi-server/src/main.rs b/kubi-server/src/main.rs index ea6bfc4..6c0158e 100644 --- a/kubi-server/src/main.rs +++ b/kubi-server/src/main.rs @@ -1,38 +1,17 @@ -use shipyard::{World, AllStoragesView, Unique, Workload, IntoWorkload, UniqueView, UniqueViewMut}; -use kubi_udp::server::{Server, ServerConfig}; -use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage}; -use std::{thread, time::Duration, net::SocketAddr}; +use shipyard::{World, Workload, IntoWorkload}; +use std::{thread, time::Duration}; -#[derive(Unique)] -#[repr(transparent)] -pub struct ServerAddr(SocketAddr); +pub(crate) mod config; +pub(crate) mod server; +pub(crate) mod client; +pub(crate) mod transform; -#[derive(Unique)] -#[repr(transparent)] -pub struct UdpServer(Server); - -fn bind_server( - storages: AllStoragesView, -) { - log::info!("Creating server..."); - let addr = storages.borrow::>().expect("No server addr found"); - let server: Server = Server::bind( - "0.0.0.0:1234".parse().unwrap(), - ServerConfig::default() - ).unwrap(); - storages.add_unique(UdpServer(server)); -} - -fn update_server( - mut server: UniqueViewMut -) { - if let Err(error) = server.0.update() { - log::error!("Server error: {error:?}") - } -} +use config::read_config; +use server::{bind_server, update_server}; fn initialize() -> Workload { ( + read_config, bind_server, ).into_workload() } diff --git a/kubi-server/src/server.rs b/kubi-server/src/server.rs new file mode 100644 index 0000000..589b160 --- /dev/null +++ b/kubi-server/src/server.rs @@ -0,0 +1,28 @@ +use shipyard::{AllStoragesView, Unique, UniqueView, UniqueViewMut}; +use kubi_udp::server::{Server, ServerConfig}; +use kubi_shared::networking::messages::{ClientToServerMessage, ServerToClientMessage}; +use crate::config::ConfigTable; + +#[derive(Unique)] +#[repr(transparent)] +pub struct UdpServer(Server); + +pub fn bind_server( + storages: AllStoragesView, +) { + log::info!("Creating server..."); + let config = storages.borrow::>().unwrap(); + let server: Server = Server::bind( + config.server.address, + ServerConfig { max_clients: config.server.max_clients } + ).unwrap(); + storages.add_unique(UdpServer(server)); +} + +pub fn update_server( + mut server: UniqueViewMut +) { + if let Err(error) = server.0.update() { + log::error!("Server error: {error:?}") + } +} diff --git a/kubi-server/src/transform.rs b/kubi-server/src/transform.rs new file mode 100644 index 0000000..5087b6c --- /dev/null +++ b/kubi-server/src/transform.rs @@ -0,0 +1,6 @@ +use shipyard::Component; +use glam::Mat4; + +#[derive(Component, Clone, Copy, Debug, Default)] +#[track(All)] +pub struct Transform(pub Mat4); diff --git a/kubi/Cargo.toml b/kubi/Cargo.toml index 50bf39a..c88d405 100644 --- a/kubi/Cargo.toml +++ b/kubi/Cargo.toml @@ -22,3 +22,7 @@ gilrs = { version = "0.10", default_features = false, features = ["xinput"] } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3" } + +[features] +default = [] +unstable = ["glam/core-simd"] diff --git a/kubi/src/rendering/world.rs b/kubi/src/rendering/world.rs index a42136b..9029381 100644 --- a/kubi/src/rendering/world.rs +++ b/kubi/src/rendering/world.rs @@ -35,6 +35,7 @@ use crate::{ use super::{RenderTarget, primitives::cube::CubePrimitive}; #[derive(Clone, Copy)] +#[repr(C)] pub struct ChunkVertex { pub position: [f32; 3], pub normal: [f32; 3],