Tracing and Performance improvements
tracing chunk rebuild testing speed up world gen by moving collider creation to thread pool
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use bevy_rapier3d::{pipeline::QueryFilter, plugin::RapierContext};
|
||||
use world_generation::{hex_utils::HexCoord, prelude::Map};
|
||||
|
||||
use crate::camera_system::components::PhosCamera;
|
||||
use crate::{camera_system::components::PhosCamera, prelude::PhosChunkRegistry};
|
||||
|
||||
use super::chunk_rebuild::ChunkRebuildQueue;
|
||||
|
||||
@@ -15,23 +15,52 @@ impl Plugin for TerraFormingTestPlugin {
|
||||
}
|
||||
|
||||
fn deform(
|
||||
cam: Query<&Transform, With<PhosCamera>>,
|
||||
keyboard: Res<ButtonInput<KeyCode>>,
|
||||
cam_query: Query<(&GlobalTransform, &Camera), With<PhosCamera>>,
|
||||
window: Query<&Window, With<PrimaryWindow>>,
|
||||
keyboard: Res<ButtonInput<MouseButton>>,
|
||||
rapier_context: Res<RapierContext>,
|
||||
mut heightmap: ResMut<Map>,
|
||||
mut rebuild: ResMut<ChunkRebuildQueue>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
if !keyboard.pressed(KeyCode::KeyF) {
|
||||
if !keyboard.just_pressed(MouseButton::Left) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cam_transform = cam.single();
|
||||
let fwd: Vec3 = cam_transform.forward().into();
|
||||
let win = window.single();
|
||||
let (cam_transform, camera) = cam_query.single();
|
||||
let Some(cursor_pos) = win.cursor_position() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let collision = rapier_context.cast_ray(cam_transform.translation, fwd, 100., true, QueryFilter::only_fixed());
|
||||
let Some(cam_ray) = camera.viewport_to_world(cam_transform, cursor_pos) else {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some((entity, dist)) = collision {
|
||||
let contact_point = cam_transform.translation + (fwd * dist);
|
||||
let collision = rapier_context.cast_ray(
|
||||
cam_ray.origin,
|
||||
cam_ray.direction.into(),
|
||||
100.,
|
||||
true,
|
||||
QueryFilter::only_fixed(),
|
||||
);
|
||||
|
||||
if let Some((_, dist)) = collision {
|
||||
let contact_point = cam_ray.get_point(dist);
|
||||
let contact_coord = HexCoord::from_world_pos(contact_point);
|
||||
let cur_height = heightmap.sample_height(&contact_coord);
|
||||
heightmap.set_height(&contact_coord, cur_height + 1.);
|
||||
let cur_chunk = contact_coord.to_chunk_index(heightmap.width);
|
||||
|
||||
if contact_coord.is_on_chunk_edge() {
|
||||
let neighbors = contact_coord.get_neighbors();
|
||||
let mut other_chunks: Vec<_> = neighbors
|
||||
.iter()
|
||||
.map(|c| c.to_chunk_index(heightmap.width))
|
||||
.filter(|c| c != &cur_chunk)
|
||||
.collect();
|
||||
rebuild.queue.append(&mut other_chunks);
|
||||
}
|
||||
rebuild.queue.push(cur_chunk);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user