constants at the top of vvlib/mod.rs for easier stress-test-fun

This commit is contained in:
Lillian Vixe 2024-04-03 18:10:22 -07:00
parent f8f4a04638
commit 3934b6a87f
2 changed files with 26 additions and 12 deletions

View file

@ -34,6 +34,12 @@ pub mod intersections;
pub mod obb;
pub mod octtree;
pub const RANDOM_SPACE: f32 = 25.; // size of the random possibility space.
pub const INTERVAL: f32 = 0.3; // how often to add ^ that many and remove ^ that many random locations
pub const SCALE_OF_FIELD: f32 = 0.05; // how big to make the oct-tree render
pub const ADDITION_THROTTLE: usize = 5; // divided by total to edit to nerf addition so there are a notable amount of empty spaces (makes the shape more interesting, higher it is)
pub const TOTAL_TO_EDIT: usize = 100_000; // how many to initialize with, how many to add and how many to remove every interval
pub mod constants {
use bevy::math::Vec3;
pub const CORNER_3D: f32 = 0.866025;
@ -525,9 +531,9 @@ pub fn iterate_voxels(
for (mut model, mut counter) in &mut query {
let mut rng = rand::thread_rng();
while counter.count > 0 {
let x: f32 = rng.gen_range(-10.0..10.0);
let y: f32 = rng.gen_range(-10.0..10.0);
let z: f32 = rng.gen_range(-10.0..10.0);
let x: f32 = rng.gen_range(-RANDOM_SPACE..RANDOM_SPACE);
let y: f32 = rng.gen_range(-RANDOM_SPACE..RANDOM_SPACE);
let z: f32 = rng.gen_range(-RANDOM_SPACE..RANDOM_SPACE);
let vec = Vec3::new(x.round(), y.round(), z.round());
let r: f32 = rng.gen_range(0.0..1.0);
let g: f32 = rng.gen_range(0.0..1.0);
@ -547,22 +553,27 @@ pub fn occasional_change(
time: Res<Time>,
mut query: Query<(&mut OctTreeModelComponent, &mut ChangeOnTimerRandomized)>,
) {
const INTERVAL: f32 = 4.;
for (mut model, mut timer) in &mut query {
//
timer.timer += time.delta_seconds();
if timer.timer > INTERVAL {
let mut rng = rand::thread_rng();
for _ in 0..100000 {
let x: f32 = rng.gen_range(-10.0..10.0);
let y: f32 = rng.gen_range(-10.0..10.0);
let z: f32 = rng.gen_range(-10.0..10.0);
for _ in 0..(TOTAL_TO_EDIT / ADDITION_THROTTLE) {
let x: f32 = rng.gen_range(-RANDOM_SPACE..RANDOM_SPACE);
let y: f32 = rng.gen_range(-RANDOM_SPACE..RANDOM_SPACE);
let z: f32 = rng.gen_range(-RANDOM_SPACE..RANDOM_SPACE);
let vec = Vec3::new(x.round(), y.round(), z.round());
let r: f32 = rng.gen_range(0.0..1.0);
let g: f32 = rng.gen_range(0.0..1.0);
let b: f32 = rng.gen_range(0.0..1.0);
model.model.set_voxel_at_location(vec, Color::rgb(r, g, b));
}
for _ in 0..TOTAL_TO_EDIT {
let x: f32 = rng.gen_range(-RANDOM_SPACE..RANDOM_SPACE);
let y: f32 = rng.gen_range(-RANDOM_SPACE..RANDOM_SPACE);
let z: f32 = rng.gen_range(-RANDOM_SPACE..RANDOM_SPACE);
let vec = Vec3::new(x.round(), y.round(), z.round());
model.model.remove_voxel(vec);
}
timer.timer -= INTERVAL;
}
}

View file

@ -1,11 +1,12 @@
pub mod mesh_plugin {
use crate::vvlib::SCALE_OF_FIELD;
use bevy::prelude::*;
use crate::{
orbit_camera::orbit_camera::*,
vvlib::{
iterate_voxels, occasional_change, oct_tree_edit_task_catcher, octtree::OctTree,
ChangeOnTimerRandomized, OctTreeModelComponent, VoxelIterativeBuildTest,
ChangeOnTimerRandomized, OctTreeModelComponent, VoxelIterativeBuildTest, TOTAL_TO_EDIT,
},
};
@ -26,7 +27,7 @@ pub mod mesh_plugin {
let parent = commands
.spawn(TransformBundle {
local: Transform::from_scale(Vec3::splat(0.0125)),
local: Transform::from_scale(Vec3::splat(SCALE_OF_FIELD)),
..Default::default()
})
.id();
@ -38,7 +39,9 @@ pub mod mesh_plugin {
..default()
},
model_oct,
VoxelIterativeBuildTest { count: 100 },
VoxelIterativeBuildTest {
count: TOTAL_TO_EDIT,
},
ChangeOnTimerRandomized { timer: 0. },
))
.id();