Skip to content

Commit

Permalink
fix: simulation skip if chunks are not loaded yet
Browse files Browse the repository at this point in the history
  • Loading branch information
AudranTourneur committed Jan 27, 2025
1 parent 8250f58 commit 4728b4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
7 changes: 2 additions & 5 deletions client/src/world/rendering/meshing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::f32::consts::PI;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::{collections::HashMap, time::Instant};

use crate::world::{ClientChunk, ClientWorldMap};
Expand Down Expand Up @@ -155,8 +154,7 @@ pub(crate) fn generate_chunk_mesh(

let should_return_solid = !solid_mesh_creator.vertices.is_empty();
if should_return_solid {
debug!("Attempting to generate tangents for the mesh SOLID",);
if let Err(e) = catch_unwind(AssertUnwindSafe(|| solid_mesh.generate_tangents())) {
if let Err(e) = solid_mesh.generate_tangents() {
warn!(
"Error while generating tangents for the mesh SOLID : {:?} | {:?}",
e, solid_mesh
Expand All @@ -166,8 +164,7 @@ pub(crate) fn generate_chunk_mesh(

let should_return_liquid = !liquid_mesh_creator.vertices.is_empty();
if should_return_liquid {
debug!("Attempting to generate tangents for the mesh LIQUID",);
if let Err(e) = catch_unwind(AssertUnwindSafe(|| liquid_mesh.generate_tangents())) {
if let Err(e) = liquid_mesh.generate_tangents() {
warn!(
"Error while generating tangents for the mesh LIQUID : {:?} | {:?}",
e, liquid_mesh
Expand Down
20 changes: 8 additions & 12 deletions shared/src/players/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ use bevy::prelude::*;

use super::Player;

#[allow(clippy::let_and_return)]
pub fn simulate_player_movement(
player: &mut Player,
world_map: &(impl WorldMap + Clone),
action: &PlayerFrameInput,
) {
// let's check if the 9 chunks around the player are loaded
let chunks = world_map.get_surrounding_chunks(player.position, 1);
if chunks.len() < 9 {
debug!("Not enough chunks loaded, skipping movement simulation");
return;
}

// TODO: Ridiculous performance issue, clone should be avoided
let world_clone = world_map.clone();

let delta = action.delta_ms as f32 / 1000.0;

// let initial_pos = player.position;
// let initial_rot = player.camera_transform.rotation;

let mut is_jumping = false;

let mut direction = Vec3::ZERO;
Expand Down Expand Up @@ -89,7 +92,7 @@ pub fn simulate_player_movement(
if !player.is_flying {
if check_player_collision(new_vec, player, &world_clone) {
player.on_ground = true;
player.velocity.y = 0.0; // Réinitialiser la vélocité verticale si le joueur est au sol
player.velocity.y = 0.0;
} else {
player.position.y = new_y;
player.on_ground = false;
Expand Down Expand Up @@ -119,13 +122,6 @@ pub fn simulate_player_movement(
player.position = Vec3::new(0.0, 100.0, 0.0);
player.velocity.y = 0.0;
}

// let has_moved = player.position != initial_pos;
// let has_rotated = player.camera_transform.rotation != initial_rot;

// let requires_network_broadcast = has_moved || has_rotated;

// requires_network_broadcast
}

trait IsPressed {
Expand Down

0 comments on commit 4728b4b

Please sign in to comment.