"fix" some warnings

This commit is contained in:
griffi-gh 2024-05-03 01:39:47 +02:00
parent 00b8a253bb
commit 656f124549
12 changed files with 117 additions and 118 deletions

View file

@ -1,5 +1,5 @@
use glam::Mat4; 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 hashbrown::HashMap;
use uflow::{server::Event, SendMode}; use uflow::{server::Event, SendMode};
use std::net::SocketAddr; use std::net::SocketAddr;
@ -95,7 +95,8 @@ pub fn on_client_disconnect(
for event in &events.0 { for event in &events.0 {
if let Event::Disconnect(addr) = event { 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 { let Some(&entity_id) = addr_map.0.get(addr) else {
log::error!("Disconnected client not authenticated, moving on"); log::error!("Disconnected client not authenticated, moving on");
continue; continue;

View file

@ -102,7 +102,7 @@ fn process_chunk_requests(
).unwrap(); ).unwrap();
} }
} else { } else {
let mut chunk = Chunk::new(chunk_position); let mut chunk = Chunk::new();
chunk.state = ChunkState::Loading; chunk.state = ChunkState::Loading;
chunk.subscriptions.insert(message.client_id); chunk.subscriptions.insert(message.client_id);
chunk_manager.chunks.insert(chunk_position, chunk); chunk_manager.chunks.insert(chunk_position, chunk);

View file

@ -1,31 +1,28 @@
use glam::IVec3; use hashbrown::HashSet;
use hashbrown::HashSet; use nohash_hasher::BuildNoHashHasher;
use nohash_hasher::BuildNoHashHasher; use kubi_shared::{
use kubi_shared::{ chunk::BlockData,
chunk::BlockData, networking::client::ClientId
networking::client::ClientId };
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum ChunkState {
pub enum ChunkState { Nothing,
Nothing, Loading,
Loading, Loaded,
Loaded, }
}
pub struct Chunk {
pub struct Chunk { pub state: ChunkState,
pub position: IVec3, pub blocks: Option<BlockData>,
pub state: ChunkState, pub subscriptions: HashSet<ClientId, BuildNoHashHasher<ClientId>>,
pub blocks: Option<BlockData>, }
pub subscriptions: HashSet<ClientId, BuildNoHashHasher<ClientId>>, impl Chunk {
} pub fn new() -> Self {
impl Chunk { Self {
pub fn new(position: IVec3) -> Self { state: ChunkState::Nothing,
Self { blocks: None,
position, subscriptions: HashSet::with_capacity_and_hasher(4, BuildNoHashHasher::default()),
state: ChunkState::Nothing, }
blocks: None, }
subscriptions: HashSet::with_capacity_and_hasher(4, BuildNoHashHasher::default()), }
}
}
}

View file

@ -1,35 +1,36 @@
use shipyard::Component; use shipyard::Component;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
#[derive(Component)] #[derive(Component)]
pub struct Entity; pub struct Entity;
#[derive(Component, Serialize, Deserialize, Clone, Copy, Debug)] #[derive(Component, Serialize, Deserialize, Clone, Copy, Debug)]
pub struct Health { pub struct Health {
pub current: u8, pub current: u8,
pub max: u8, pub max: u8,
} }
impl Health { impl Health {
pub fn new(health: u8) -> Self { pub fn new(health: u8) -> Self {
Self { Self {
current: health, current: health,
max: health max: health
} }
} }
} }
impl PartialEq for Health {
fn eq(&self, other: &Self) -> bool { // impl PartialEq for Health {
self.current == other.current // fn eq(&self, other: &Self) -> bool {
} // self.current == other.current
} // }
impl Eq for Health {} // }
impl PartialOrd for Health { // impl Eq for Health {}
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { // impl PartialOrd for Health {
self.current.partial_cmp(&other.current) // fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
} // self.current.partial_cmp(&other.current)
} // }
impl Ord for Health { // }
fn cmp(&self, other: &Self) -> std::cmp::Ordering { // impl Ord for Health {
self.current.cmp(&other.current) // fn cmp(&self, other: &Self) -> std::cmp::Ordering {
} // self.current.cmp(&other.current)
} // }
// }

View file

@ -1,5 +1,5 @@
use fastnoise_lite::{FastNoiseLite, FractalType}; use fastnoise_lite::{FastNoiseLite, FractalType};
use glam::{ivec3, FloatExt, IVec3}; use glam::ivec3;
use crate::{block::Block, chunk::CHUNK_SIZE}; use crate::{block::Block, chunk::CHUNK_SIZE};
use super::super::{SeedThingy, WorldGenStep, WorldGenerator}; use super::super::{SeedThingy, WorldGenStep, WorldGenerator};

View file

@ -1,7 +1,6 @@
use bincode::de;
use fastnoise_lite::{FastNoiseLite, NoiseType}; use fastnoise_lite::{FastNoiseLite, NoiseType};
use glam::ivec3; 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 super::_02_water::WATER_LEVEL;
use crate::worldgen::{ use crate::worldgen::{
WorldGenStep, WorldGenerator, WorldGenStep, WorldGenerator,

View file

@ -1,38 +1,38 @@
use shipyard::{AllStoragesView, UniqueViewMut}; use shipyard::{AllStoragesView, UniqueViewMut};
use std::{env, net::SocketAddr, fs::OpenOptions, path::{Path, PathBuf}, str::FromStr, sync::{Arc, RwLock}}; use std::{env, net::SocketAddr, fs::OpenOptions, path::Path};
use anyhow::Result; use anyhow::Result;
use crate::{ use crate::{
networking::{GameType, ServerAddress}, networking::{GameType, ServerAddress},
state::{GameState, NextState} state::{GameState, NextState}
}; };
use kubi_shared::data::{WorldSaveFile, SharedSaveFile}; use kubi_shared::data::WorldSaveFile;
fn open_local_save_file(path: &Path) -> Result<WorldSaveFile> { fn open_local_save_file(path: &Path) -> Result<WorldSaveFile> {
let mut save_file = WorldSaveFile::new({ let mut save_file = WorldSaveFile::new({
OpenOptions::new() OpenOptions::new()
.read(true) .read(true)
.write(true) .write(true)
.open("world.kbi")? .open("world.kbi")?
}); });
if save_file.file.metadata().unwrap().len() == 0 { if save_file.file.metadata().unwrap().len() == 0 {
save_file.initialize()?; save_file.initialize()?;
} else { } else {
save_file.load_data()?; save_file.load_data()?;
} }
Ok(save_file) Ok(save_file)
} }
pub fn initialize_from_args( pub fn initialize_from_args(
all_storages: AllStoragesView, all_storages: AllStoragesView,
) { ) {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() > 1 { if args.len() > 1 {
let address = args[1].parse::<SocketAddr>().expect("invalid address"); let address = args[1].parse::<SocketAddr>().expect("invalid address");
all_storages.add_unique(GameType::Muliplayer); all_storages.add_unique(GameType::Muliplayer);
all_storages.add_unique(ServerAddress(address)); all_storages.add_unique(ServerAddress(address));
all_storages.borrow::<UniqueViewMut<NextState>>().unwrap().0 = Some(GameState::Connecting); all_storages.borrow::<UniqueViewMut<NextState>>().unwrap().0 = Some(GameState::Connecting);
} else { } else {
all_storages.add_unique(GameType::Singleplayer); all_storages.add_unique(GameType::Singleplayer);
all_storages.borrow::<UniqueViewMut<NextState>>().unwrap().0 = Some(GameState::LoadingWorld); all_storages.borrow::<UniqueViewMut<NextState>>().unwrap().0 = Some(GameState::LoadingWorld);
} }
} }

View file

@ -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::{ use shipyard::{
World, Workload, IntoWorkload, World, Workload, IntoWorkload,

View file

@ -1,5 +1,4 @@
use shipyard::{Unique, AllStoragesView, UniqueView, UniqueViewMut, Workload, IntoWorkload, EntitiesViewMut, Component, ViewMut, SystemModificator, View, IntoIter, WorkloadModificator}; 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 std::net::SocketAddr;
use uflow::{ use uflow::{
client::{Client, Config as ClientConfig, Event as ClientEvent}, client::{Client, Config as ClientConfig, Event as ClientEvent},

View file

@ -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 uflow::{client::Event as ClientEvent, SendMode};
use kubi_shared::networking::{ use kubi_shared::networking::{
messages::{ClientToServerMessage, ServerToClientMessage, ServerToClientMessageType}, messages::{ClientToServerMessage, ServerToClientMessage, ServerToClientMessageType},

View file

@ -1,9 +1,7 @@
use std::f32::consts::PI; use glam::uvec2;
use glam::{uvec2, Vec2};
use hui::{ use hui::{
draw::{ImageHandle, TextureFormat}, draw::{ImageHandle, TextureFormat},
element::{container::Container, image::Image, transformer::ElementTransformExt, UiElementExt}, element::{container::Container, image::Image, UiElementExt},
layout::Alignment, layout::Alignment,
size size
}; };

View file

@ -1,6 +1,6 @@
use glam::{IVec3, ivec3}; use glam::{IVec3, ivec3};
use strum::IntoEnumIterator; 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::world::chunk::CHUNK_SIZE;
use crate::rendering::world::ChunkVertex; use crate::rendering::world::ChunkVertex;