Fix: blocking

This commit is contained in:
Snowiiii committed 2024-10-19 13:53:41 +02:00
1 parent a9f645488d
commit 387da2c8b5
4 files changed
+13 -6

No files matched your search

+2 -2
View File
@@ -6,7 +6,7 @@ use rayon::prelude::*;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use crate::{ use crate::{
chunk::{anvil::AnvilChunkReader, ChunkData, ChunkReader, ChunkReadingError}, chunk::{anvil::AnvilChunkReader, ChunkData, ChunkParsingError, ChunkReader, ChunkReadingError},
world_gen::{get_world_gen, Seed, WorldGenerator}, world_gen::{get_world_gen, Seed, WorldGenerator},
}; };
@@ -96,7 +96,7 @@ impl Level {
let data = match &self.save_file { let data = match &self.save_file {
Some(save_file) => { Some(save_file) => {
match self.chunk_reader.read_chunk(save_file, at) { match self.chunk_reader.read_chunk(save_file, at) {
Err(ChunkReadingError::ChunkNotExist) => { Err(ChunkReadingError::ParsingError(ChunkParsingError::ChunkNotGenerated) | ChunkReadingError::ChunkNotExist) => {
// This chunk was not generated yet. // This chunk was not generated yet.
Ok(self.world_gen.generate_chunk(at)) Ok(self.world_gen.generate_chunk(at))
} }
-1
View File
@@ -83,7 +83,6 @@ const fn convert_logger_filter(level: pumpkin_config::logging::LevelFilter) -> L
async fn main() -> io::Result<()> { async fn main() -> io::Result<()> {
use std::sync::Arc; use std::sync::Arc;
use entity::player::Player;
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG}; use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
use pumpkin_core::text::{color::NamedColor, TextComponent}; use pumpkin_core::text::{color::NamedColor, TextComponent};
use rcon::RCONServer; use rcon::RCONServer;
+9 -1
View File
@@ -240,7 +240,12 @@ impl World {
player_chunker::player_join(self, player.clone()).await; player_chunker::player_join(self, player.clone()).await;
} }
async fn spawn_world_chunks(&self, client: &Client, chunks: Vec<Vector2<i32>>, distance: i32) { async fn spawn_world_chunks(
&self,
client: Arc<Client>,
chunks: Vec<Vector2<i32>>,
distance: i32,
) {
let inst = std::time::Instant::now(); let inst = std::time::Instant::now();
let (sender, mut chunk_receiver) = mpsc::channel(distance as usize); let (sender, mut chunk_receiver) = mpsc::channel(distance as usize);
@@ -252,6 +257,8 @@ impl World {
level.fetch_chunks(&chunks, sender, closed) level.fetch_chunks(&chunks, sender, closed)
}); });
let client = client.clone();
tokio::spawn(async move {
while let Some(chunk_data) = chunk_receiver.recv().await { while let Some(chunk_data) = chunk_receiver.recv().await {
// dbg!(chunk_pos); // dbg!(chunk_pos);
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
@@ -272,6 +279,7 @@ impl World {
} }
} }
dbg!("DONE CHUNKS", inst.elapsed()); dbg!("DONE CHUNKS", inst.elapsed());
});
} }
/// Gets a Player by entity id /// Gets a Player by entity id
+2 -2
View File
@@ -55,7 +55,7 @@ pub async fn player_join(world: &World, player: Arc<Player>) {
); );
if !loading_chunks.is_empty() { if !loading_chunks.is_empty() {
world world
.spawn_world_chunks(&player.client, loading_chunks, view_distance) .spawn_world_chunks(player.client.clone(), loading_chunks, view_distance)
.await; .await;
} }
} }
@@ -98,7 +98,7 @@ pub async fn update_position(entity: &Entity, player: &Player) {
if !loading_chunks.is_empty() { if !loading_chunks.is_empty() {
entity entity
.world .world
.spawn_world_chunks(&player.client, loading_chunks, view_distance) .spawn_world_chunks(player.client.clone(), loading_chunks, view_distance)
.await; .await;
} }
} }