diff --git a/kubi-server/src/client.rs b/kubi-server/src/client.rs index 4836c8c..2b60bf6 100644 --- a/kubi-server/src/client.rs +++ b/kubi-server/src/client.rs @@ -1,5 +1,5 @@ use glam::Mat4; -use shipyard::{AllStoragesView, AllStoragesViewMut, Component, EntitiesViewMut, EntityId, Get, IntoIter, NonSendSync, Remove, Unique, UniqueView, UniqueViewMut, View, ViewMut}; +use shipyard::{AllStoragesView, AllStoragesViewMut, Component, EntityId, Get, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View, ViewMut}; use hashbrown::HashMap; use uflow::{server::Event, SendMode}; use std::net::SocketAddr; @@ -95,7 +95,8 @@ pub fn on_client_disconnect( for event in &events.0 { if let Event::Disconnect(addr) = event { - let net_client = server.0.client(addr).unwrap(); + //XXX: do sth with this: + //let net_client = server.0.client(addr).unwrap(); let Some(&entity_id) = addr_map.0.get(addr) else { log::error!("Disconnected client not authenticated, moving on"); continue; diff --git a/kubi-server/src/world.rs b/kubi-server/src/world.rs index 9719822..0ae5592 100644 --- a/kubi-server/src/world.rs +++ b/kubi-server/src/world.rs @@ -102,7 +102,7 @@ fn process_chunk_requests( ).unwrap(); } } else { - let mut chunk = Chunk::new(chunk_position); + let mut chunk = Chunk::new(); chunk.state = ChunkState::Loading; chunk.subscriptions.insert(message.client_id); chunk_manager.chunks.insert(chunk_position, chunk); diff --git a/kubi-server/src/world/chunk.rs b/kubi-server/src/world/chunk.rs index 91eed17..7287d19 100644 --- a/kubi-server/src/world/chunk.rs +++ b/kubi-server/src/world/chunk.rs @@ -1,31 +1,28 @@ -use glam::IVec3; -use hashbrown::HashSet; -use nohash_hasher::BuildNoHashHasher; -use kubi_shared::{ - chunk::BlockData, - networking::client::ClientId -}; - -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum ChunkState { - Nothing, - Loading, - Loaded, -} - -pub struct Chunk { - pub position: IVec3, - pub state: ChunkState, - pub blocks: Option, - pub subscriptions: HashSet>, -} -impl Chunk { - pub fn new(position: IVec3) -> Self { - Self { - position, - state: ChunkState::Nothing, - blocks: None, - subscriptions: HashSet::with_capacity_and_hasher(4, BuildNoHashHasher::default()), - } - } -} +use hashbrown::HashSet; +use nohash_hasher::BuildNoHashHasher; +use kubi_shared::{ + chunk::BlockData, + networking::client::ClientId +}; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ChunkState { + Nothing, + Loading, + Loaded, +} + +pub struct Chunk { + pub state: ChunkState, + pub blocks: Option, + pub subscriptions: HashSet>, +} +impl Chunk { + pub fn new() -> Self { + Self { + state: ChunkState::Nothing, + blocks: None, + subscriptions: HashSet::with_capacity_and_hasher(4, BuildNoHashHasher::default()), + } + } +} diff --git a/kubi-shared/src/entity.rs b/kubi-shared/src/entity.rs index 37c973a..abc923b 100644 --- a/kubi-shared/src/entity.rs +++ b/kubi-shared/src/entity.rs @@ -1,35 +1,36 @@ -use shipyard::Component; -use serde::{Serialize, Deserialize}; - -#[derive(Component)] -pub struct Entity; - -#[derive(Component, Serialize, Deserialize, Clone, Copy, Debug)] -pub struct Health { - pub current: u8, - pub max: u8, -} -impl Health { - pub fn new(health: u8) -> Self { - Self { - current: health, - max: health - } - } -} -impl PartialEq for Health { - fn eq(&self, other: &Self) -> bool { - self.current == other.current - } -} -impl Eq for Health {} -impl PartialOrd for Health { - fn partial_cmp(&self, other: &Self) -> Option { - self.current.partial_cmp(&other.current) - } -} -impl Ord for Health { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.current.cmp(&other.current) - } -} +use shipyard::Component; +use serde::{Serialize, Deserialize}; + +#[derive(Component)] +pub struct Entity; + +#[derive(Component, Serialize, Deserialize, Clone, Copy, Debug)] +pub struct Health { + pub current: u8, + pub max: u8, +} +impl Health { + pub fn new(health: u8) -> Self { + Self { + current: health, + max: health + } + } +} + +// impl PartialEq for Health { +// fn eq(&self, other: &Self) -> bool { +// self.current == other.current +// } +// } +// impl Eq for Health {} +// impl PartialOrd for Health { +// fn partial_cmp(&self, other: &Self) -> Option { +// self.current.partial_cmp(&other.current) +// } +// } +// impl Ord for Health { +// fn cmp(&self, other: &Self) -> std::cmp::Ordering { +// self.current.cmp(&other.current) +// } +// } diff --git a/kubi-shared/src/worldgen/steps/_03_caves.rs b/kubi-shared/src/worldgen/steps/_03_caves.rs index 41d0be2..ed3540f 100644 --- a/kubi-shared/src/worldgen/steps/_03_caves.rs +++ b/kubi-shared/src/worldgen/steps/_03_caves.rs @@ -1,5 +1,5 @@ use fastnoise_lite::{FastNoiseLite, FractalType}; -use glam::{ivec3, FloatExt, IVec3}; +use glam::ivec3; use crate::{block::Block, chunk::CHUNK_SIZE}; use super::super::{SeedThingy, WorldGenStep, WorldGenerator}; diff --git a/kubi-shared/src/worldgen/steps/_06_trees.rs b/kubi-shared/src/worldgen/steps/_06_trees.rs index 08b547b..4b0a969 100644 --- a/kubi-shared/src/worldgen/steps/_06_trees.rs +++ b/kubi-shared/src/worldgen/steps/_06_trees.rs @@ -1,7 +1,6 @@ -use bincode::de; use fastnoise_lite::{FastNoiseLite, NoiseType}; use glam::ivec3; -use crate::{block::Block, chunk::CHUNK_SIZE, worldgen::SeedThingy}; +use crate::{chunk::CHUNK_SIZE, worldgen::SeedThingy}; use super::_02_water::WATER_LEVEL; use crate::worldgen::{ WorldGenStep, WorldGenerator, diff --git a/kubi/src/init.rs b/kubi/src/init.rs index a542a0e..0dfb513 100644 --- a/kubi/src/init.rs +++ b/kubi/src/init.rs @@ -1,38 +1,38 @@ -use shipyard::{AllStoragesView, UniqueViewMut}; -use std::{env, net::SocketAddr, fs::OpenOptions, path::{Path, PathBuf}, str::FromStr, sync::{Arc, RwLock}}; -use anyhow::Result; -use crate::{ - networking::{GameType, ServerAddress}, - state::{GameState, NextState} -}; -use kubi_shared::data::{WorldSaveFile, SharedSaveFile}; - -fn open_local_save_file(path: &Path) -> Result { - let mut save_file = WorldSaveFile::new({ - OpenOptions::new() - .read(true) - .write(true) - .open("world.kbi")? - }); - if save_file.file.metadata().unwrap().len() == 0 { - save_file.initialize()?; - } else { - save_file.load_data()?; - } - Ok(save_file) -} - -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(ServerAddress(address)); - all_storages.borrow::>().unwrap().0 = Some(GameState::Connecting); - } else { - all_storages.add_unique(GameType::Singleplayer); - all_storages.borrow::>().unwrap().0 = Some(GameState::LoadingWorld); - } -} +use shipyard::{AllStoragesView, UniqueViewMut}; +use std::{env, net::SocketAddr, fs::OpenOptions, path::Path}; +use anyhow::Result; +use crate::{ + networking::{GameType, ServerAddress}, + state::{GameState, NextState} +}; +use kubi_shared::data::WorldSaveFile; + +fn open_local_save_file(path: &Path) -> Result { + let mut save_file = WorldSaveFile::new({ + OpenOptions::new() + .read(true) + .write(true) + .open("world.kbi")? + }); + if save_file.file.metadata().unwrap().len() == 0 { + save_file.initialize()?; + } else { + save_file.load_data()?; + } + Ok(save_file) +} + +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(ServerAddress(address)); + all_storages.borrow::>().unwrap().0 = Some(GameState::Connecting); + } else { + all_storages.add_unique(GameType::Singleplayer); + all_storages.borrow::>().unwrap().0 = Some(GameState::LoadingWorld); + } +} diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index 849a8dd..77fce89 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -1,4 +1,8 @@ -#![allow(clippy::too_many_arguments)] // allowed because systems often need a lot of arguments +#![allow( + clippy::too_many_arguments, // allowed because systems often need a lot of argumentss + clippy::enum_variant_names, + clippy::type_complexity +)] use shipyard::{ World, Workload, IntoWorkload, diff --git a/kubi/src/networking.rs b/kubi/src/networking.rs index 15a44e3..56f5fde 100644 --- a/kubi/src/networking.rs +++ b/kubi/src/networking.rs @@ -1,5 +1,4 @@ use shipyard::{Unique, AllStoragesView, UniqueView, UniqueViewMut, Workload, IntoWorkload, EntitiesViewMut, Component, ViewMut, SystemModificator, View, IntoIter, WorkloadModificator}; -use winit::event_loop::ControlFlow; use std::net::SocketAddr; use uflow::{ client::{Client, Config as ClientConfig, Event as ClientEvent}, diff --git a/kubi/src/networking/handshake.rs b/kubi/src/networking/handshake.rs index c83d50a..fb3b699 100644 --- a/kubi/src/networking/handshake.rs +++ b/kubi/src/networking/handshake.rs @@ -1,4 +1,4 @@ -use shipyard::{AllStoragesView, AllStoragesViewMut, IntoIter, Unique, UniqueView, UniqueViewMut, View}; +use shipyard::{AllStoragesView, AllStoragesViewMut, IntoIter, Unique, UniqueViewMut, View}; use uflow::{client::Event as ClientEvent, SendMode}; use kubi_shared::networking::{ messages::{ClientToServerMessage, ServerToClientMessage, ServerToClientMessageType}, diff --git a/kubi/src/ui/crosshair_ui.rs b/kubi/src/ui/crosshair_ui.rs index c7ff756..353429e 100644 --- a/kubi/src/ui/crosshair_ui.rs +++ b/kubi/src/ui/crosshair_ui.rs @@ -1,9 +1,7 @@ -use std::f32::consts::PI; - -use glam::{uvec2, Vec2}; +use glam::uvec2; use hui::{ draw::{ImageHandle, TextureFormat}, - element::{container::Container, image::Image, transformer::ElementTransformExt, UiElementExt}, + element::{container::Container, image::Image, UiElementExt}, layout::Alignment, size }; diff --git a/kubi/src/world/mesh.rs b/kubi/src/world/mesh.rs index 6e1b411..24e2f2d 100644 --- a/kubi/src/world/mesh.rs +++ b/kubi/src/world/mesh.rs @@ -1,6 +1,6 @@ use glam::{IVec3, ivec3}; use strum::IntoEnumIterator; -use kubi_shared::block::{Block, BlockTexture, RenderType, Transparency}; +use kubi_shared::block::{Block, RenderType, Transparency}; use crate::world::chunk::CHUNK_SIZE; use crate::rendering::world::ChunkVertex;