diff --git a/src/main.rs b/src/main.rs index 791393c..33d15ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,7 +54,8 @@ use events::{ use input::{init_input, process_inputs}; use fly_controller::update_controllers; use rendering::{ - selection_box::{render_selection_box, init_selection_box_buffers}, + primitives::init_simple_box_buffers, + selection_box::render_selection_box, world::draw_world, }; use block_placement::block_placement_system; @@ -66,7 +67,7 @@ fn startup() -> Workload { ( load_settings, load_prefabs, - init_selection_box_buffers, + init_simple_box_buffers, insert_lock_state, lock_cursor_now, init_input, diff --git a/src/rendering/primitives.rs b/src/rendering/primitives.rs index 7efa2e5..ce05f83 100644 --- a/src/rendering/primitives.rs +++ b/src/rendering/primitives.rs @@ -1,3 +1,7 @@ +use glium::{implement_vertex, VertexBuffer, IndexBuffer, index::PrimitiveType}; +use shipyard::{NonSendSync, UniqueView, AllStoragesView, Unique}; +use super::Renderer; + pub const CUBE_VERTICES: &[f32] = &[ // front 0.0, 0.0, 1.0, @@ -30,3 +34,47 @@ pub const CUBE_INDICES: &[u16] = &[ 3, 2, 6, 6, 7, 3 ]; + +#[derive(Clone, Copy, Default)] +pub struct PositionOnlyVertex { + pub position: [f32; 3], +} +implement_vertex!(PositionOnlyVertex, position); + +const fn box_vertices() -> [PositionOnlyVertex; CUBE_VERTICES.len() / 3] { + let mut arr = [PositionOnlyVertex { position: [0., 0., 0.] }; CUBE_VERTICES.len() / 3]; + let mut ptr = 0; + loop { + arr[ptr] = PositionOnlyVertex { + position: [ + CUBE_VERTICES[ptr * 3], + CUBE_VERTICES[(ptr * 3) + 1], + CUBE_VERTICES[(ptr * 3) + 2] + ] + }; + ptr += 1; + if ptr >= CUBE_VERTICES.len() / 3 { + return arr + } + } +} +const BOX_VERTICES: &[PositionOnlyVertex] = &box_vertices(); + +#[derive(Unique)] +pub struct SimpleBoxBuffers(pub VertexBuffer, pub IndexBuffer); + +pub fn init_simple_box_buffers( + storages: AllStoragesView, + display: NonSendSync> +) { + let vert = VertexBuffer::new( + &display.display, + BOX_VERTICES + ).unwrap(); + let index = IndexBuffer::new( + &display.display, + PrimitiveType::TrianglesList, + CUBE_INDICES + ).unwrap(); + storages.add_unique_non_send_sync(SimpleBoxBuffers(vert, index)); +} diff --git a/src/rendering/selection_box.rs b/src/rendering/selection_box.rs index 21858d5..1cbe8cf 100644 --- a/src/rendering/selection_box.rs +++ b/src/rendering/selection_box.rs @@ -1,13 +1,10 @@ -use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView, AllStoragesView, Unique}; +use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView}; use glium::{ Surface, - implement_vertex, - IndexBuffer, - index::PrimitiveType, - VertexBuffer, uniform, DrawParameters, BackfaceCullingMode, Blend, Depth, DepthTest, + uniform, }; use crate::{ world::raycast::LookingAtBlock, @@ -15,44 +12,15 @@ use crate::{ }; use super::{ RenderTarget, - primitives::{CUBE_INDICES, CUBE_VERTICES}, Renderer + primitives::SimpleBoxBuffers, }; -#[derive(Clone, Copy, Default)] -pub struct SelBoxVertex { - pub position: [f32; 3], -} -implement_vertex!(SelBoxVertex, position); - -const fn box_vertices() -> [SelBoxVertex; CUBE_VERTICES.len() / 3] { - let mut arr = [SelBoxVertex { position: [0., 0., 0.] }; CUBE_VERTICES.len() / 3]; - let mut ptr = 0; - loop { - arr[ptr] = SelBoxVertex { - position: [ - CUBE_VERTICES[ptr * 3], - CUBE_VERTICES[(ptr * 3) + 1], - CUBE_VERTICES[(ptr * 3) + 2] - ] - }; - ptr += 1; - if ptr >= CUBE_VERTICES.len() / 3 { - return arr - } - } -} -const BOX_VERTICES: &[SelBoxVertex] = &box_vertices(); - -#[derive(Unique)] -pub struct SelectionBoxBuffers(VertexBuffer, IndexBuffer); - -//wip pub fn render_selection_box( lookat: View, camera: View, mut target: NonSendSync>, program: NonSendSync>, - buffers: NonSendSync>, + buffers: NonSendSync>, ) { let camera = camera.iter().next().unwrap(); let Some(lookat) = lookat.iter().next() else { return }; @@ -80,19 +48,3 @@ pub fn render_selection_box( } ).unwrap(); } - -pub fn init_selection_box_buffers( - storages: AllStoragesView, - display: NonSendSync> -) { - let vert = VertexBuffer::new( - &display.display, - BOX_VERTICES - ).unwrap(); - let index = IndexBuffer::new( - &display.display, - PrimitiveType::TrianglesList, - CUBE_INDICES - ).unwrap(); - storages.add_unique_non_send_sync(SelectionBoxBuffers(vert, index)); -} diff --git a/src/settings.rs b/src/settings.rs index ceff83c..dee58eb 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -2,15 +2,17 @@ use shipyard::{Unique, AllStoragesView}; #[derive(Unique)] pub struct GameSettings { - //there's a 1 chunk border of loaded but invisible around this + /// there's a 1 chunk border of loaded but invisible around this pub render_distance: u8, pub mouse_sensitivity: f32, + pub debug_draw_chunk_border: bool, } impl Default for GameSettings { fn default() -> Self { Self { render_distance: 5, mouse_sensitivity: 1., + debug_draw_chunk_border: cfg!(debug_assertions), } } }