mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-21 22:38:41 -06:00
Compare commits
4 commits
9affee68c3
...
7ba5d739e7
Author | SHA1 | Date | |
---|---|---|---|
griffi-gh | 7ba5d739e7 | ||
griffi-gh | 9bdc38ccf0 | ||
griffi-gh | e40e394bd8 | ||
griffi-gh | 2cdc79cb18 |
82
Cargo.lock
generated
82
Cargo.lock
generated
|
@ -120,6 +120,15 @@ dependencies = [
|
|||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
|
@ -170,9 +179,9 @@ checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
|
|||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.13.1"
|
||||
version = "1.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea"
|
||||
checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
|
@ -553,14 +562,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "flume"
|
||||
version = "0.10.14"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577"
|
||||
checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"nanorand",
|
||||
"pin-project",
|
||||
"spin",
|
||||
]
|
||||
|
||||
|
@ -826,6 +834,7 @@ checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
|||
dependencies = [
|
||||
"ahash 0.8.3",
|
||||
"allocator-api2",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -988,6 +997,10 @@ dependencies = [
|
|||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kubi-pool"
|
||||
version = "0.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "kubi-server"
|
||||
version = "0.0.0"
|
||||
|
@ -1015,6 +1028,7 @@ name = "kubi-shared"
|
|||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bincode",
|
||||
"bracket-noise",
|
||||
"glam",
|
||||
"hashbrown 0.14.0",
|
||||
|
@ -1444,26 +1458,6 @@ version = "2.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842"
|
||||
dependencies = [
|
||||
"pin-project-internal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-internal"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.27"
|
||||
|
@ -1507,7 +1501,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"toml_edit",
|
||||
"toml_edit 0.19.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1775,9 +1769,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "0.6.3"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186"
|
||||
checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
@ -2017,21 +2011,21 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.7.6"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c17e963a819c331dcacd7ab957d80bc2b9a9c1e71c804826d2f283dd65306542"
|
||||
checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_edit",
|
||||
"toml_edit 0.21.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.3"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
|
||||
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
@ -2041,12 +2035,23 @@ name = "toml_edit"
|
|||
version = "0.19.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c500344a19072298cd05a7224b3c0c629348b78692bf48466c5238656e315a78"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime",
|
||||
"winnow 0.4.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
"winnow 0.5.19",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2417,6 +2422,15 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.5.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wio"
|
||||
version = "0.2.2"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[workspace]
|
||||
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging"]
|
||||
members = ["kubi", "kubi-server", "kubi-shared", "kubi-logging", "kubi-pool"]
|
||||
resolver = "2"
|
||||
|
||||
[profile.release-with-debug]
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
name = "kubi-logging"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
|
|
7
kubi-pool/Cargo.toml
Normal file
7
kubi-pool/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "kubi-pool"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
33
kubi-pool/src/lib.rs
Normal file
33
kubi-pool/src/lib.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use std::{thread::JoinHandle, collections::VecDeque};
|
||||
|
||||
pub struct KubiPool<T, R> {
|
||||
callback: fn(T) -> R,
|
||||
threads: Vec<JoinHandle<()>>,
|
||||
}
|
||||
|
||||
struct Task<T> {
|
||||
priority: u8,
|
||||
data: T,
|
||||
}
|
||||
|
||||
fn task_loop<T, R>() {
|
||||
let tasks = VecDeque::<Task<T>>::new();
|
||||
loop {
|
||||
//todo
|
||||
};
|
||||
}
|
||||
|
||||
impl<T: 'static, R: 'static> KubiPool<T, R> {
|
||||
pub fn new(threads: usize, callback: fn(T) -> R) -> Self {
|
||||
Self {
|
||||
callback,
|
||||
threads: (0..threads).map(|_| {
|
||||
std::thread::spawn(task_loop::<T, R>)
|
||||
}).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, threads: usize) {
|
||||
|
||||
}
|
||||
}
|
|
@ -10,13 +10,13 @@ kubi-logging = { path = "../kubi-logging" }
|
|||
log = "0.4"
|
||||
shipyard = { git = "https://github.com/leudz/shipyard", rev = "0934b426eb9a8", default-features = false, features = ["std", "proc", "thread_local"] }
|
||||
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
|
||||
toml = "0.7"
|
||||
toml = "0.8"
|
||||
glam = { version = "0.24", features = ["debug-glam-assert", "fast-math"] }
|
||||
hashbrown = "0.14"
|
||||
nohash-hasher = "0.2"
|
||||
anyhow = "1.0"
|
||||
rayon = "1.7"
|
||||
flume = "0.10"
|
||||
flume = "0.11"
|
||||
rand = "0.8"
|
||||
uflow = "0.7"
|
||||
postcard = { version = "1.0", features = ["alloc"] }
|
||||
|
|
|
@ -10,13 +10,17 @@ shipyard = { git = "https://github.com/leudz/shipyard", rev = "0934b426eb9a8", d
|
|||
strum = { version = "0.25", features = ["derive"] }
|
||||
postcard = { version = "1.0", features = ["alloc"] }
|
||||
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
|
||||
bincode = "1.3"
|
||||
anyhow = "1.0"
|
||||
bracket-noise = "0.8"
|
||||
rand = { version = "0.8", default_features = false, features = ["std", "min_const_gen"] }
|
||||
rand_xoshiro = "0.6"
|
||||
hashbrown = "0.14"
|
||||
hashbrown = { version = "0.14", features = ["serde"] }
|
||||
nohash-hasher = "0.2"
|
||||
|
||||
#bytemuck = { version = "1.14", features = ["derive"] }
|
||||
#static_assertions = "1.1"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
nightly = ["hashbrown/nightly", "rand/nightly", "rand/simd_support", "glam/core-simd"]
|
||||
|
|
|
@ -2,3 +2,4 @@ use crate::block::Block;
|
|||
|
||||
pub const CHUNK_SIZE: usize = 32;
|
||||
pub type BlockData = Box<[[[Block; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]>;
|
||||
pub type BlockDataRef = [[[Block; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE];
|
||||
|
|
111
kubi-shared/src/data.rs
Normal file
111
kubi-shared/src/data.rs
Normal file
|
@ -0,0 +1,111 @@
|
|||
use std::{
|
||||
fs::File,
|
||||
mem::size_of,
|
||||
io::{Read, Seek, SeekFrom, Write},
|
||||
borrow::Cow
|
||||
};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use glam::IVec2;
|
||||
use hashbrown::HashMap;
|
||||
use anyhow::Result;
|
||||
use crate::{block::Block, chunk::{CHUNK_SIZE, BlockDataRef}};
|
||||
|
||||
const SECTOR_SIZE: usize = CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE * size_of::<Block>();
|
||||
const RESERVED_SIZE: usize = 1048576; //~1mb (16 sectors assuming 32x32x32 world of 1byte blocks)
|
||||
const RESERVED_SECTOR_COUNT: usize = RESERVED_SIZE / SECTOR_SIZE;
|
||||
|
||||
//magic = "KUBI" + IDENTITY (4 bytes)
|
||||
const HEADER_MAGIC_SIZE: usize = 8;
|
||||
const HEADER_MAGIC_STR: [u8; 4] = *b"KUBI";
|
||||
const HEADER_MAGIC_IDENTITY: u32 = 1;
|
||||
|
||||
// #[repr(transparent)]
|
||||
// struct IVec2Hash(IVec2);
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct WorldSaveDataHeader {
|
||||
pub name: Cow<'static, str>,
|
||||
pub seed: u64,
|
||||
sector_count: u32,
|
||||
chunk_map: HashMap<IVec2, u32>,
|
||||
}
|
||||
|
||||
impl Default for WorldSaveDataHeader {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: "World".into(),
|
||||
seed: 0,
|
||||
sector_count: RESERVED_SECTOR_COUNT as u32,
|
||||
chunk_map: HashMap::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct WorldSaveFile {
|
||||
pub file: File,
|
||||
pub header: WorldSaveDataHeader,
|
||||
}
|
||||
|
||||
impl WorldSaveFile {
|
||||
pub fn new(file: File) -> Self {
|
||||
WorldSaveFile {
|
||||
file,
|
||||
header: WorldSaveDataHeader::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn read_header(&mut self) -> Result<()> {
|
||||
self.file.rewind()?;
|
||||
|
||||
let mut subheader = [0u8; HEADER_MAGIC_SIZE];
|
||||
self.file.read_exact(&mut subheader)?;
|
||||
if subheader[0..4] != HEADER_MAGIC_STR {
|
||||
return Err(anyhow::anyhow!("invalid file header"));
|
||||
}
|
||||
if subheader[4..8] != HEADER_MAGIC_IDENTITY.to_be_bytes() {
|
||||
return Err(anyhow::anyhow!("this save file cannot be loaded by this version of the game"));
|
||||
}
|
||||
|
||||
let limit = (RESERVED_SIZE - HEADER_MAGIC_SIZE) as u64;
|
||||
self.header = bincode::deserialize_from((&self.file).take(limit))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_header(&mut self) -> Result<()> {
|
||||
self.file.rewind()?;
|
||||
self.file.write_all(&HEADER_MAGIC_STR)?;
|
||||
self.file.write_all(&HEADER_MAGIC_IDENTITY.to_be_bytes())?;
|
||||
//XXX: this can cause the header to destroy chunk data (if it's WAY too long)
|
||||
// read has checks against this, but write doesn't
|
||||
// 1mb is pretty generous tho, so it's not a *big* deal
|
||||
bincode::serialize_into(&self.file, &self.header)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn allocate_sector(&mut self) -> u32 {
|
||||
let value = self.header.sector_count + 1;
|
||||
self.header.sector_count += 1;
|
||||
value
|
||||
}
|
||||
|
||||
pub fn save_chunk(&mut self, position: IVec2, data: &BlockDataRef) -> Result<()> {
|
||||
let mut header_modified = false;
|
||||
let sector = self.header.chunk_map.get(&position).copied().unwrap_or_else(|| {
|
||||
header_modified = true;
|
||||
self.allocate_sector()
|
||||
});
|
||||
|
||||
let offset = sector as u64 * SECTOR_SIZE as u64;
|
||||
//SAFETY: *nuzzles* t-t-twust me pwease OwO
|
||||
let data: &[u8; SECTOR_SIZE] = unsafe { std::mem::transmute(data) };
|
||||
|
||||
self.file.seek(SeekFrom::Start(offset))?;
|
||||
self.file.write_all(data)?;
|
||||
|
||||
if header_modified {
|
||||
self.write_header()?;
|
||||
}
|
||||
self.file.sync_data()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -6,3 +6,4 @@ pub mod transform;
|
|||
pub mod entity;
|
||||
pub mod player;
|
||||
pub mod queue;
|
||||
pub mod data;
|
||||
|
|
|
@ -20,7 +20,7 @@ nohash-hasher = "0.2"
|
|||
rayon = "1.7"
|
||||
shipyard = { git = "https://github.com/leudz/shipyard", rev = "0934b426eb9a8", default-features = false, features = ["std", "proc", "thread_local"] }
|
||||
anyhow = "1.0"
|
||||
flume = "0.10"
|
||||
flume = "0.11"
|
||||
gilrs = { version = "0.10", default_features = false, features = ["xinput"] }
|
||||
uflow = "0.7"
|
||||
postcard = { version = "1.0", features = ["alloc"] }
|
||||
|
|
Loading…
Reference in a new issue