Skip to content

Commit

Permalink
"fix" some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
griffi-gh committed May 2, 2024
1 parent 00b8a25 commit 656f124
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 118 deletions.
5 changes: 3 additions & 2 deletions kubi-server/src/client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion kubi-server/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
59 changes: 28 additions & 31 deletions kubi-server/src/world/chunk.rs
Original file line number Diff line number Diff line change
@@ -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()),
}
}
}
71 changes: 36 additions & 35 deletions kubi-shared/src/entity.rs
Original file line number Diff line number Diff line change
@@ -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)
// }
// }
2 changes: 1 addition & 1 deletion kubi-shared/src/worldgen/steps/_03_caves.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
3 changes: 1 addition & 2 deletions kubi-shared/src/worldgen/steps/_06_trees.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
76 changes: 38 additions & 38 deletions kubi/src/init.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 5 additions & 1 deletion kubi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 0 additions & 1 deletion kubi/src/networking.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
2 changes: 1 addition & 1 deletion kubi/src/networking/handshake.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
6 changes: 2 additions & 4 deletions kubi/src/ui/crosshair_ui.rs
Original file line number Diff line number Diff line change
@@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion kubi/src/world/mesh.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down

0 comments on commit 656f124

Please sign in to comment.