-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
117 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters