mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-25 21:28:20 -06:00
minor refactor
This commit is contained in:
parent
155e3b1e36
commit
17dbdc2757
12
src/delta_time.rs
Normal file
12
src/delta_time.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use shipyard::{Unique, AllStoragesView};
|
||||||
|
|
||||||
|
#[derive(Unique, Default)]
|
||||||
|
pub(crate) struct DeltaTime(pub Duration);
|
||||||
|
|
||||||
|
pub fn init_delta_time(
|
||||||
|
storages: AllStoragesView
|
||||||
|
) {
|
||||||
|
storages.add_unique(DeltaTime::default())
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
use glam::{Vec3, Mat4, Quat, EulerRot, Vec2};
|
use glam::{Vec3, Mat4, Quat, EulerRot, Vec2};
|
||||||
use shipyard::{Component, View, ViewMut, IntoIter, UniqueView, Workload, IntoWorkload};
|
use shipyard::{Component, View, ViewMut, IntoIter, UniqueView, Workload, IntoWorkload};
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use crate::{transform::Transform, input::Inputs, settings::GameSettings, DeltaTime};
|
use crate::{transform::Transform, input::Inputs, settings::GameSettings, delta_time::DeltaTime};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct FlyController;
|
pub struct FlyController;
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
use shipyard::{
|
use shipyard::{
|
||||||
World, Workload, IntoWorkload,
|
World, Workload, IntoWorkload,
|
||||||
UniqueView, UniqueViewMut,
|
UniqueView, UniqueViewMut,
|
||||||
NonSendSync, Unique
|
NonSendSync
|
||||||
};
|
};
|
||||||
use glium::{
|
use glium::{
|
||||||
glutin::{
|
glutin::{
|
||||||
|
@ -10,7 +10,7 @@ use glium::{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
use glam::vec3;
|
use glam::vec3;
|
||||||
use std::time::{Instant, Duration};
|
use std::time::Instant;
|
||||||
|
|
||||||
mod logging;
|
mod logging;
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ pub(crate) mod events;
|
||||||
pub(crate) mod input;
|
pub(crate) mod input;
|
||||||
pub(crate) mod fly_controller;
|
pub(crate) mod fly_controller;
|
||||||
pub(crate) mod block_placement;
|
pub(crate) mod block_placement;
|
||||||
|
pub(crate) mod delta_time;
|
||||||
|
|
||||||
use rendering::{
|
use rendering::{
|
||||||
Renderer,
|
Renderer,
|
||||||
|
@ -45,17 +46,17 @@ use events::{clear_events, process_glutin_events};
|
||||||
use input::{init_input, process_inputs};
|
use input::{init_input, process_inputs};
|
||||||
use fly_controller::update_controllers;
|
use fly_controller::update_controllers;
|
||||||
use rendering::{
|
use rendering::{
|
||||||
selection_box::render_selection_box,
|
selection_box::{render_selection_box, init_selection_box_buffers},
|
||||||
world::draw_world,
|
world::draw_world,
|
||||||
};
|
};
|
||||||
use block_placement::block_placement_system;
|
use block_placement::block_placement_system;
|
||||||
|
use delta_time::{DeltaTime, init_delta_time};
|
||||||
#[derive(Unique)]
|
|
||||||
pub(crate) struct DeltaTime(Duration);
|
|
||||||
|
|
||||||
fn startup() -> Workload {
|
fn startup() -> Workload {
|
||||||
(
|
(
|
||||||
|
init_delta_time,
|
||||||
load_prefabs,
|
load_prefabs,
|
||||||
|
init_selection_box_buffers,
|
||||||
init_input,
|
init_input,
|
||||||
init_game_world,
|
init_game_world,
|
||||||
spawn_player,
|
spawn_player,
|
||||||
|
@ -96,7 +97,6 @@ fn main() {
|
||||||
//Add systems and uniques, Init and load things
|
//Add systems and uniques, Init and load things
|
||||||
world.add_unique_non_send_sync(Renderer::init(&event_loop));
|
world.add_unique_non_send_sync(Renderer::init(&event_loop));
|
||||||
world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.)));
|
world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.)));
|
||||||
world.add_unique(DeltaTime(Duration::default()));
|
|
||||||
world.add_unique(GameSettings::default());
|
world.add_unique(GameSettings::default());
|
||||||
|
|
||||||
//Register workloads
|
//Register workloads
|
||||||
|
|
0
src/rendering/crosshair.rs
Normal file
0
src/rendering/crosshair.rs
Normal file
|
@ -1,4 +1,4 @@
|
||||||
use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView};
|
use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView, AllStoragesView, Unique};
|
||||||
use glium::{
|
use glium::{
|
||||||
Surface,
|
Surface,
|
||||||
implement_vertex,
|
implement_vertex,
|
||||||
|
@ -43,6 +43,9 @@ const fn box_vertices() -> [SelBoxVertex; CUBE_VERTICES.len() / 3] {
|
||||||
}
|
}
|
||||||
const BOX_VERTICES: &[SelBoxVertex] = &box_vertices();
|
const BOX_VERTICES: &[SelBoxVertex] = &box_vertices();
|
||||||
|
|
||||||
|
#[derive(Unique)]
|
||||||
|
pub struct SelectionBoxBuffers(VertexBuffer<SelBoxVertex>, IndexBuffer<u16>);
|
||||||
|
|
||||||
//wip
|
//wip
|
||||||
pub fn render_selection_box(
|
pub fn render_selection_box(
|
||||||
lookat: View<LookingAtBlock>,
|
lookat: View<LookingAtBlock>,
|
||||||
|
@ -50,27 +53,16 @@ pub fn render_selection_box(
|
||||||
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||||
display: NonSendSync<UniqueView<Renderer>>,
|
display: NonSendSync<UniqueView<Renderer>>,
|
||||||
program: NonSendSync<UniqueView<SelBoxShaderPrefab>>,
|
program: NonSendSync<UniqueView<SelBoxShaderPrefab>>,
|
||||||
|
buffers: NonSendSync<UniqueView<SelectionBoxBuffers>>,
|
||||||
) {
|
) {
|
||||||
let camera = camera.iter().next().unwrap();
|
let camera = camera.iter().next().unwrap();
|
||||||
let Some(lookat) = lookat.iter().next() else { return };
|
let Some(lookat) = lookat.iter().next() else { return };
|
||||||
let Some(lookat) = lookat.0 else { return };
|
let Some(lookat) = lookat.0 else { return };
|
||||||
|
|
||||||
//this may be slow but the amount of vertices is very low
|
|
||||||
let vert = VertexBuffer::new(
|
|
||||||
&display.display,
|
|
||||||
BOX_VERTICES
|
|
||||||
).unwrap();
|
|
||||||
|
|
||||||
let index = IndexBuffer::new(
|
|
||||||
&display.display,
|
|
||||||
PrimitiveType::TrianglesList,
|
|
||||||
CUBE_INDICES
|
|
||||||
).unwrap();
|
|
||||||
|
|
||||||
//Darken block
|
//Darken block
|
||||||
target.0.draw(
|
target.0.draw(
|
||||||
&vert,
|
&buffers.0,
|
||||||
&index,
|
&buffers.1,
|
||||||
&program.0,
|
&program.0,
|
||||||
&uniform! {
|
&uniform! {
|
||||||
u_color: [0., 0., 0., 0.5_f32],
|
u_color: [0., 0., 0., 0.5_f32],
|
||||||
|
@ -89,3 +81,19 @@ pub fn render_selection_box(
|
||||||
}
|
}
|
||||||
).unwrap();
|
).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));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue