"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 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;

View file

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

View file

@ -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<BlockData>,
pub subscriptions: HashSet<ClientId, BuildNoHashHasher<ClientId>>,
}
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<BlockData>,
pub subscriptions: HashSet<ClientId, BuildNoHashHasher<ClientId>>,
}
impl Chunk {
pub fn new() -> Self {
Self {
state: ChunkState::Nothing,
blocks: None,
subscriptions: HashSet::with_capacity_and_hasher(4, BuildNoHashHasher::default()),
}
}
}

View file

@ -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<std::cmp::Ordering> {
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<std::cmp::Ordering> {
// self.current.partial_cmp(&other.current)
// }
// }
// impl Ord for Health {
// 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 glam::{ivec3, FloatExt, IVec3};
use glam::ivec3;
use crate::{block::Block, chunk::CHUNK_SIZE};
use super::super::{SeedThingy, WorldGenStep, WorldGenerator};

View file

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

View file

@ -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<WorldSaveFile> {
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<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(ServerAddress(address));
all_storages.borrow::<UniqueViewMut<NextState>>().unwrap().0 = Some(GameState::Connecting);
} else {
all_storages.add_unique(GameType::Singleplayer);
all_storages.borrow::<UniqueViewMut<NextState>>().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<WorldSaveFile> {
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<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(ServerAddress(address));
all_storages.borrow::<UniqueViewMut<NextState>>().unwrap().0 = Some(GameState::Connecting);
} else {
all_storages.add_unique(GameType::Singleplayer);
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::{
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 winit::event_loop::ControlFlow;
use std::net::SocketAddr;
use uflow::{
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 kubi_shared::networking::{
messages::{ClientToServerMessage, ServerToClientMessage, ServerToClientMessageType},

View file

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

View file

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