diff --git a/Cargo.lock b/Cargo.lock index f783dff..f093e97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -505,6 +505,9 @@ name = "glam" version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9" +dependencies = [ + "serde", +] [[package]] name = "glam" @@ -1412,6 +1415,7 @@ dependencies = [ name = "server" version = "0.1.0" dependencies = [ + "glam 0.27.0", "rayon", "serde_json", "shared", diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index d82985f..0f8436b 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -9,6 +9,7 @@ authors.workspace = true workspace = true [dependencies] +glam = "0.27" rayon = "1.12.0" serde_json = "1.0.149" shared = { version = "0.1.0", path = "../shared" } diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 0d49011..69742b5 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -10,7 +10,9 @@ pub mod world_server; use std::fs; +use glam::Vec3; use shared::generator::{VoxelGenerator, WorldGenConfig}; +use shared::world::{ChunkPos, EntityPos}; use tracing::{debug, info}; fn main() { @@ -44,5 +46,8 @@ fn main() { let mut world = world_server::ServerWorld::new(generator); - world.load_around(0.0, 0.0, 0.0, 4); + // Hardcoded spawn stand-in until a real player entity exists; the chunk anchor drives streaming. + let player = EntityPos::new(ChunkPos::new(0, 0, 0), Vec3::ZERO); + + world.load_around(player, 4); } diff --git a/crates/server/src/world_server.rs b/crates/server/src/world_server.rs index c71ef5d..f2fb406 100644 --- a/crates/server/src/world_server.rs +++ b/crates/server/src/world_server.rs @@ -5,7 +5,7 @@ use rayon::prelude::*; use shared::{ generator::VoxelGenerator, - world::{Chunk, ChunkPos}, + world::{Chunk, ChunkPos, EntityPos}, }; use std::collections::HashMap; @@ -33,8 +33,9 @@ impl ServerWorld { } /// Generates and caches all chunks in a cylindrical region around the given position. - pub fn load_around(&mut self, center_x: f64, center_y: f64, center_z: f64, radius: i32) { - let center = ChunkPos::from_world(center_x, center_y, center_z); + pub fn load_around(&mut self, center: EntityPos, radius: i32) { + // The chunk anchor is the exact streaming key; no lossy world-to-chunk conversion is needed. + let center = center.chunk; // Phase 1: collect the positions inside the cylinder that are not yet resident let mut pending = Vec::new();