no clue
This commit is contained in:
@@ -19,7 +19,8 @@ use system::render::add_grid;
|
||||
|
||||
use crate::{
|
||||
common::{ClientMessage, ServerHandle, ServerMessage},
|
||||
server::Server, util::timer::Timer,
|
||||
server::Server,
|
||||
util::timer::Timer,
|
||||
};
|
||||
|
||||
use self::{input::Input, render::Renderer, ClientState};
|
||||
@@ -47,8 +48,6 @@ pub struct Client<'a> {
|
||||
server: ServerHandle,
|
||||
server_id_map: HashMap<Entity, Entity>,
|
||||
systems: ClientSystems,
|
||||
frame_target: Instant,
|
||||
frame_time: Duration,
|
||||
second_target: Instant,
|
||||
the_thing: bool,
|
||||
}
|
||||
@@ -93,8 +92,6 @@ impl Client<'_> {
|
||||
world,
|
||||
server,
|
||||
server_id_map: HashMap::new(),
|
||||
frame_target: Instant::now(),
|
||||
frame_time: FRAME_TIME,
|
||||
second_target: Instant::now(),
|
||||
the_thing: false,
|
||||
}
|
||||
@@ -127,16 +124,6 @@ impl Client<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
if now >= self.frame_target {
|
||||
self.frame_target += self.frame_time;
|
||||
let mut commands = std::mem::take(&mut self.render_commands);
|
||||
let world_cmds = std::mem::take(&mut self.world.resource_mut::<RenderCommands>().0);
|
||||
commands.extend(world_cmds);
|
||||
self.renderer.handle_commands(commands);
|
||||
self.renderer.draw();
|
||||
self.render_timer.add(self.renderer.timer().duration(0));
|
||||
}
|
||||
|
||||
if now >= self.second_target {
|
||||
self.second_target += Duration::from_secs(1);
|
||||
let timer = &self.render_timer;
|
||||
@@ -177,7 +164,15 @@ impl Client<'_> {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => self.exit = true,
|
||||
WindowEvent::Resized(size) => self.renderer.resize(size),
|
||||
// WindowEvent::RedrawRequested => self.renderer.draw(),
|
||||
WindowEvent::RedrawRequested => {
|
||||
let mut commands = std::mem::take(&mut self.render_commands);
|
||||
let world_cmds = std::mem::take(&mut self.world.resource_mut::<RenderCommands>().0);
|
||||
commands.extend(world_cmds);
|
||||
self.renderer.handle_commands(commands);
|
||||
self.renderer.draw();
|
||||
self.render_timer.add(self.renderer.timer().duration(0));
|
||||
self.window.request_redraw();
|
||||
}
|
||||
WindowEvent::CursorLeft { .. } => {
|
||||
self.input.clear();
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ const EPSILON = 0.00000000001;
|
||||
const MAX_ITERS = 10000;
|
||||
// NOTE: CANNOT GO HIGHER THAN 23 due to how floating point
|
||||
// numbers are stored and the bit manipulation used
|
||||
const MAX_SCALE: u32 = 13;
|
||||
const MAX_SCALE: u32 = 23;
|
||||
fn trace_full(pos_view: vec4<f32>, dir_view: vec4<f32>) -> vec4<f32> {
|
||||
if arrayLength(&voxel_data) == 1 {
|
||||
return vec4<f32>(0.0);
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
use crate::{
|
||||
client::camera::Camera,
|
||||
common::component::{ChunkMesh, ChunkPos}, util::oct_tree::OctTree,
|
||||
};
|
||||
|
||||
use super::{voxel::VoxelColor, Renderer};
|
||||
use bevy_ecs::entity::Entity;
|
||||
use nalgebra::{Rotation3, Vector3};
|
||||
use ndarray::Array3;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RenderCommand {
|
||||
CreateVoxelGrid(CreateVoxelGrid),
|
||||
AddChunk(AddChunk),
|
||||
UpdateGridTransform(UpdateGridTransform),
|
||||
ViewUpdate(Camera),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CreateVoxelGrid {
|
||||
pub id: Entity,
|
||||
pub pos: Vector3<f32>,
|
||||
pub orientation: Rotation3<f32>,
|
||||
pub dimensions: Vector3<usize>,
|
||||
pub grid: Array3<VoxelColor>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AddChunk {
|
||||
pub id: Entity,
|
||||
pub pos: ChunkPos,
|
||||
pub mesh: ChunkMesh,
|
||||
pub tree: OctTree,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UpdateGridTransform {
|
||||
pub id: Entity,
|
||||
pub pos: Vector3<f32>,
|
||||
pub orientation: Rotation3<f32>,
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn handle_commands(&mut self, commands: Vec<RenderCommand>) {
|
||||
let mut new_camera = false;
|
||||
for cmd in commands {
|
||||
match cmd {
|
||||
RenderCommand::CreateVoxelGrid(desc) => self.voxel_pipeline.add_group(
|
||||
&self.device,
|
||||
&mut self.encoder,
|
||||
&mut self.staging_belt,
|
||||
desc,
|
||||
),
|
||||
RenderCommand::ViewUpdate(camera) => {
|
||||
new_camera = true;
|
||||
self.camera = camera;
|
||||
}
|
||||
RenderCommand::UpdateGridTransform(update) => self.voxel_pipeline.update_transform(
|
||||
&self.device,
|
||||
&mut self.encoder,
|
||||
&mut self.staging_belt,
|
||||
update,
|
||||
),
|
||||
RenderCommand::AddChunk(desc) => self.voxel_pipeline.add_chunk(
|
||||
&self.device,
|
||||
&mut self.encoder,
|
||||
&mut self.staging_belt,
|
||||
desc,
|
||||
),
|
||||
}
|
||||
}
|
||||
if new_camera {
|
||||
self.voxel_pipeline.update_view(
|
||||
&self.device,
|
||||
&mut self.encoder,
|
||||
&mut self.staging_belt,
|
||||
self.size,
|
||||
&self.camera,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
mod command;
|
||||
pub mod voxel;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use command::*;
|
||||
use vulkano::{
|
||||
device::{Device, DeviceCreateInfo, QueueCreateInfo, QueueFlags}, instance::{Instance, InstanceCreateInfo}, memory::allocator::StandardMemoryAllocator, VulkanLibrary
|
||||
};
|
||||
|
||||
use super::camera::Camera;
|
||||
use crate::client::rsc::CLEAR_COLOR;
|
||||
use nalgebra::Vector2;
|
||||
use voxel::VoxelPipeline;
|
||||
use winit::{dpi::PhysicalSize, window::Window};
|
||||
|
||||
pub struct Renderer {
|
||||
camera: Camera,
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn new(window: Arc<Window>) -> Self {
|
||||
let library = VulkanLibrary::new().expect("no local Vulkan library/DLL");
|
||||
let instance = Instance::new(library, InstanceCreateInfo::default())
|
||||
.expect("failed to create instance");
|
||||
let physical_device = instance
|
||||
.enumerate_physical_devices()
|
||||
.expect("could not enumerate devices")
|
||||
.next()
|
||||
.expect("no devices available");
|
||||
let queue_family_index = physical_device
|
||||
.queue_family_properties()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.position(|(_queue_family_index, queue_family_properties)| {
|
||||
queue_family_properties
|
||||
.queue_flags
|
||||
.contains(QueueFlags::GRAPHICS)
|
||||
})
|
||||
.expect("couldn't find a graphical queue family")
|
||||
as u32;
|
||||
|
||||
let (device, mut queues) = Device::new(
|
||||
physical_device,
|
||||
DeviceCreateInfo {
|
||||
// here we pass the desired queue family to use by index
|
||||
queue_create_infos: vec![QueueCreateInfo {
|
||||
queue_family_index,
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.expect("failed to create device");
|
||||
|
||||
let queue = queues.next().unwrap();
|
||||
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
|
||||
|
||||
Self {
|
||||
camera: Camera::default(),
|
||||
size: Vector2::new(size.width, size.height),
|
||||
voxel_pipeline: VoxelPipeline::new(&device, &config),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_shader(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn update_shader(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn draw(&mut self) {}
|
||||
|
||||
pub fn resize(&mut self, size: PhysicalSize<u32>) {
|
||||
self.size = Vector2::new(size.width, size.height);
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use vulkano::{buffer::{Buffer, BufferCreateInfo, BufferUsage}, memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter}};
|
||||
|
||||
pub struct VoxelPipeline {
|
||||
|
||||
}
|
||||
|
||||
impl VoxelPipeline {
|
||||
pub fn init(memory_allocator: Arc<impl MemoryAllocator>) {
|
||||
let buffer = Buffer::from_data(
|
||||
memory_allocator.clone(),
|
||||
BufferCreateInfo {
|
||||
usage: BufferUsage::UNIFORM_BUFFER,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
|
||||
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
||||
..Default::default()
|
||||
},
|
||||
data,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user