mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-10 01:28:41 -06:00
move box to primitives
This commit is contained in:
parent
e00af1cefb
commit
0b4363ef88
|
@ -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,
|
||||
|
|
|
@ -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<PositionOnlyVertex>, pub IndexBuffer<u16>);
|
||||
|
||||
pub fn init_simple_box_buffers(
|
||||
storages: AllStoragesView,
|
||||
display: NonSendSync<UniqueView<Renderer>>
|
||||
) {
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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<SelBoxVertex>, IndexBuffer<u16>);
|
||||
|
||||
//wip
|
||||
pub fn render_selection_box(
|
||||
lookat: View<LookingAtBlock>,
|
||||
camera: View<Camera>,
|
||||
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
program: NonSendSync<UniqueView<SelBoxShaderPrefab>>,
|
||||
buffers: NonSendSync<UniqueView<SelectionBoxBuffers>>,
|
||||
buffers: NonSendSync<UniqueView<SimpleBoxBuffers>>,
|
||||
) {
|
||||
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<UniqueView<Renderer>>
|
||||
) {
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue