This commit is contained in:
griffi-gh 2023-02-08 02:29:29 +01:00
parent 3b79f996e2
commit e8d9eec0d4
7 changed files with 49 additions and 19 deletions

View file

@ -5,3 +5,4 @@ edition = "2021"
[dependencies]
kubi-shared = { path = "../kubi-shared" }
kubi-udp = { path = "../kubi-udp" }

View file

@ -12,24 +12,18 @@ pub enum ClientToServerMessage {
password: Option<String>,
},
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,
},

View file

@ -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"] }

22
kubi/src/init.rs Normal file
View file

@ -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<String> = env::args().collect();
if args.len() > 1 {
let address = args[1].parse::<SocketAddr>().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);
}
}

View file

@ -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,7 +155,7 @@ fn main() {
last_update = now;
}
//Run update workflow
//Run update workflows
world.run_workload(update).unwrap();
//Start rendering (maybe use custom views for this?)

12
kubi/src/networking.rs Normal file
View file

@ -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);

View file

@ -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
}