moved renderer to separate thread, add evenio and start structure, make it so you can add stuff

This commit is contained in:
2024-06-11 01:47:05 -04:00
parent 7d48ac5a9c
commit 149c5a2659
35 changed files with 1125 additions and 487 deletions
+1
View File
@@ -0,0 +1 @@
pub mod voxel_grid;
+49
View File
@@ -0,0 +1,49 @@
use evenio::{
event::{EventMut, GlobalEvent, Insert, ReceiverMut, Sender, Spawn},
fetch::Single,
};
use nalgebra::{Rotation3, Vector3};
use ndarray::Axis;
use crate::{
client::{
component::RenderComponent,
render::{CreateVoxelGrid, RenderMessage},
},
world::component::{Orientation, Pos, VoxelGrid},
};
#[derive(GlobalEvent)]
pub struct SpawnVoxelGrid {
pub pos: Vector3<f32>,
pub orientation: Rotation3<f32>,
pub grid: VoxelGrid,
}
pub fn handle_create_grid(
r: ReceiverMut<SpawnVoxelGrid>,
renderer: Single<&RenderComponent>,
mut s: Sender<(Spawn, Insert<Pos>, Insert<Orientation>, Insert<VoxelGrid>)>,
) {
let SpawnVoxelGrid {
pos,
orientation,
grid,
} = EventMut::take(r.event);
renderer
.send(RenderMessage::CreateVoxelGrid(CreateVoxelGrid {
pos,
orientation,
dimensions: Vector3::new(
grid.len_of(Axis(0)),
grid.len_of(Axis(1)),
grid.len_of(Axis(2)),
),
grid: grid.iter().cloned().collect(),
}))
.expect("render broke");
let e = s.spawn();
s.insert(e, Pos(pos));
s.insert(e, Orientation(orientation));
s.insert(e, grid);
}