refactor(server): pass EntityPos to load_around
This commit is contained in:
parent
bf55c91e91
commit
9b4cfccd43
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -505,6 +505,9 @@ name = "glam"
|
||||||
version = "0.27.0"
|
version = "0.27.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9"
|
checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glam"
|
name = "glam"
|
||||||
|
|
@ -1412,6 +1415,7 @@ dependencies = [
|
||||||
name = "server"
|
name = "server"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"glam 0.27.0",
|
||||||
"rayon",
|
"rayon",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"shared",
|
"shared",
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ authors.workspace = true
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
glam = "0.27"
|
||||||
rayon = "1.12.0"
|
rayon = "1.12.0"
|
||||||
serde_json = "1.0.149"
|
serde_json = "1.0.149"
|
||||||
shared = { version = "0.1.0", path = "../shared" }
|
shared = { version = "0.1.0", path = "../shared" }
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ pub mod world_server;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
use glam::Vec3;
|
||||||
use shared::generator::{VoxelGenerator, WorldGenConfig};
|
use shared::generator::{VoxelGenerator, WorldGenConfig};
|
||||||
|
use shared::world::{ChunkPos, EntityPos};
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
@ -44,5 +46,8 @@ fn main() {
|
||||||
|
|
||||||
let mut world = world_server::ServerWorld::new(generator);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use shared::{
|
use shared::{
|
||||||
generator::VoxelGenerator,
|
generator::VoxelGenerator,
|
||||||
world::{Chunk, ChunkPos},
|
world::{Chunk, ChunkPos, EntityPos},
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|
@ -33,8 +33,9 @@ impl ServerWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates and caches all chunks in a cylindrical region around the given position.
|
/// 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) {
|
pub fn load_around(&mut self, center: EntityPos, radius: i32) {
|
||||||
let center = ChunkPos::from_world(center_x, center_y, center_z);
|
// 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
|
// Phase 1: collect the positions inside the cylinder that are not yet resident
|
||||||
let mut pending = Vec::new();
|
let mut pending = Vec::new();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue