Load the world radially
This commit is contained in:
parent
85785c9ebe
commit
5075c97faa
@ -5,3 +5,4 @@ pub const WORLD_Y_START_AT: i32 = -64;
|
||||
pub const DIRECT_PALETTE_BITS: u32 = 15;
|
||||
mod block_registry;
|
||||
mod world;
|
||||
pub mod radial_chunk_iterator;
|
||||
59
pumpkin-world/src/radial_chunk_iterator.rs
Normal file
59
pumpkin-world/src/radial_chunk_iterator.rs
Normal file
@ -0,0 +1,59 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
pub struct RadialIterator {
|
||||
radius: i32,
|
||||
direction: usize,
|
||||
current: (i32, i32),
|
||||
step_size: i32,
|
||||
steps_taken: i32,
|
||||
steps_in_direction: i32,
|
||||
}
|
||||
|
||||
impl RadialIterator {
|
||||
pub fn new(radius: i32) -> Self {
|
||||
RadialIterator {
|
||||
radius,
|
||||
direction: 0,
|
||||
current: (0, 0),
|
||||
step_size: 1,
|
||||
steps_taken: 0,
|
||||
steps_in_direction: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for RadialIterator {
|
||||
type Item = (i32, i32);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.steps_taken >= self.radius * self.radius * 4 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let result = self.current;
|
||||
|
||||
self.steps_in_direction += 1;
|
||||
|
||||
// Move in the current direction
|
||||
match self.direction {
|
||||
0 => self.current.0 += 1, // Right
|
||||
1 => self.current.1 += 1, // Up
|
||||
2 => self.current.0 -= 1, // Left
|
||||
3 => self.current.1 -= 1, // Down
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if self.steps_in_direction >= self.step_size {
|
||||
self.direction = (self.direction + 1) % 4;
|
||||
self.steps_in_direction = 0;
|
||||
|
||||
// Increase step size after completing two directions
|
||||
if self.direction == 0 || self.direction == 2 {
|
||||
self.step_size += 1;
|
||||
}
|
||||
}
|
||||
|
||||
self.steps_taken += 1;
|
||||
Some(result)
|
||||
}
|
||||
}
|
||||
@ -25,7 +25,7 @@ use pumpkin_protocol::{
|
||||
uuid::UUID,
|
||||
ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL,
|
||||
};
|
||||
use pumpkin_world::dimension::Dimension;
|
||||
use pumpkin_world::{dimension::Dimension, radial_chunk_iterator::RadialIterator};
|
||||
|
||||
use pumpkin_registry::Registry;
|
||||
use rsa::{traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey};
|
||||
@ -330,19 +330,12 @@ impl Server {
|
||||
|
||||
// TODO: do this in a world
|
||||
async fn spawn_test_chunk(client: &mut Client) {
|
||||
let mut wanted_chunks = Vec::new();
|
||||
|
||||
for i in -32i32..32 {
|
||||
for j in -32i32..32 {
|
||||
wanted_chunks.push((i, j))
|
||||
}
|
||||
}
|
||||
let chunks = Dimension::OverWorld
|
||||
.into_level(
|
||||
// TODO: load form config
|
||||
"./world".parse().unwrap(),
|
||||
)
|
||||
.read_chunks(wanted_chunks)
|
||||
.read_chunks(RadialIterator::new(32).collect())
|
||||
.await;
|
||||
|
||||
client.send_packet(&CCenterChunk {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user