diff --git a/kubi-server/Cargo.toml b/kubi-server/Cargo.toml index efed5a4..5dc3fc5 100644 --- a/kubi-server/Cargo.toml +++ b/kubi-server/Cargo.toml @@ -5,3 +5,4 @@ edition = "2021" [dependencies] kubi-shared = { path = "../kubi-shared" } +kubi-udp = { path = "../kubi-udp" } diff --git a/kubi-shared/src/networking/messages.rs b/kubi-shared/src/networking/messages.rs index 2e2609b..9a84abf 100644 --- a/kubi-shared/src/networking/messages.rs +++ b/kubi-shared/src/networking/messages.rs @@ -12,24 +12,18 @@ pub enum ClientToServerMessage { password: Option, }, PositionChanged { - client_id: u8, - secret: u32, position: Vec3Arr, + velocity: Vec3Arr, direction: QuatArr, }, ChunkRequest { - client_id: u8, - secret: u32, chunk: IVec3Arr, }, } #[derive(Encode, Decode)] pub enum ServerToClientMessage { - ServerHello { - client_id: u8, - secret: u32, - }, + ServerHello, ServerFuckOff { reason: String, }, diff --git a/kubi/Cargo.toml b/kubi/Cargo.toml index 099fa92..ace8bc5 100644 --- a/kubi/Cargo.toml +++ b/kubi/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] kubi-shared = { path = "../kubi-shared" } +kubi-udp = { path = "../kubi-udp", optional = true } glium = "0.32" glam = { version = "0.22", features = ["debug-glam-assert", "fast-math"] } image = { version = "0.24", default_features = false, features = ["png"] } diff --git a/kubi/src/init.rs b/kubi/src/init.rs new file mode 100644 index 0000000..4f96843 --- /dev/null +++ b/kubi/src/init.rs @@ -0,0 +1,22 @@ +use std::net::SocketAddr; +use shipyard::AllStoragesView; +use std::env; +use crate::{ + networking::{GameType, ServerAddress}, + state::GameState +}; + +pub fn initialize_from_args( + all_storages: AllStoragesView, +) { + let args: Vec = env::args().collect(); + if args.len() > 1 { + let address = args[1].parse::().expect("invalid address"); + all_storages.add_unique(GameType::Muliplayer); + all_storages.add_unique(GameState::Connecting); + all_storages.add_unique(ServerAddress(address)); + } else { + all_storages.add_unique(GameType::Singleplayer); + all_storages.add_unique(GameState::LoadingWorld); + } +} diff --git a/kubi/src/main.rs b/kubi/src/main.rs index 5acfab8..cdf9bca 100644 --- a/kubi/src/main.rs +++ b/kubi/src/main.rs @@ -13,10 +13,10 @@ use glium::{ } }; use glam::vec3; +use state::GameState; use std::time::Instant; mod logging; - pub(crate) mod rendering; pub(crate) mod world; pub(crate) mod player; @@ -33,6 +33,8 @@ pub(crate) mod cursor_lock; pub(crate) mod control_flow; pub(crate) mod state; pub(crate) mod gui; +pub(crate) mod networking; +pub(crate) mod init; use world::{ init_game_world, @@ -63,6 +65,7 @@ use block_placement::block_placement_system; use delta_time::{DeltaTime, init_delta_time}; use cursor_lock::{insert_lock_state, update_cursor_lock_state, lock_cursor_now}; use control_flow::{exit_on_esc, insert_control_flow_unique, SetControlFlow}; +use init::initialize_from_args; fn startup() -> Workload { ( @@ -70,6 +73,7 @@ fn startup() -> Workload { load_prefabs, init_simple_box_buffers, insert_lock_state, + initialize_from_args, lock_cursor_now, init_input, init_game_world, @@ -151,9 +155,9 @@ fn main() { last_update = now; } - //Run update workflow + //Run update workflows world.run_workload(update).unwrap(); - + //Start rendering (maybe use custom views for this?) let target = { let renderer = world.borrow::>>().unwrap(); diff --git a/kubi/src/networking.rs b/kubi/src/networking.rs new file mode 100644 index 0000000..3a3bea4 --- /dev/null +++ b/kubi/src/networking.rs @@ -0,0 +1,12 @@ +use std::net::SocketAddr; + +use shipyard::Unique; + +#[derive(Unique, Clone, Copy, PartialEq, Eq)] +pub enum GameType { + Singleplayer, + Muliplayer +} + +#[derive(Unique, Clone, Copy, PartialEq, Eq)] +pub struct ServerAddress(pub SocketAddr); diff --git a/kubi/src/state.rs b/kubi/src/state.rs index 642ea78..9319256 100644 --- a/kubi/src/state.rs +++ b/kubi/src/state.rs @@ -1,14 +1,10 @@ +use strum::EnumIter; use shipyard::Unique; -#[derive(Unique)] +#[derive(Unique, EnumIter)] +#[track(All)] pub enum GameState { Connecting, LoadingWorld, - InGame, -} - -fn insert_default_state( - -) { - + InGame }