mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 20:08:20 -06:00
minor refactor
This commit is contained in:
parent
be8a0a4816
commit
04e4b246fe
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 shipyard::{Component, View, ViewMut, IntoIter, UniqueView, Workload, IntoWorkload};
|
||||
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)]
|
||||
pub struct FlyController;
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,7 +1,7 @@
|
|||
use shipyard::{
|
||||
World, Workload, IntoWorkload,
|
||||
UniqueView, UniqueViewMut,
|
||||
NonSendSync, Unique
|
||||
NonSendSync
|
||||
};
|
||||
use glium::{
|
||||
glutin::{
|
||||
|
@ -10,7 +10,7 @@ use glium::{
|
|||
}
|
||||
};
|
||||
use glam::vec3;
|
||||
use std::time::{Instant, Duration};
|
||||
use std::time::Instant;
|
||||
|
||||
mod logging;
|
||||
|
||||
|
@ -25,6 +25,7 @@ pub(crate) mod events;
|
|||
pub(crate) mod input;
|
||||
pub(crate) mod fly_controller;
|
||||
pub(crate) mod block_placement;
|
||||
pub(crate) mod delta_time;
|
||||
|
||||
use rendering::{
|
||||
Renderer,
|
||||
|
@ -45,17 +46,17 @@ use events::{clear_events, process_glutin_events};
|
|||
use input::{init_input, process_inputs};
|
||||
use fly_controller::update_controllers;
|
||||
use rendering::{
|
||||
selection_box::render_selection_box,
|
||||
selection_box::{render_selection_box, init_selection_box_buffers},
|
||||
world::draw_world,
|
||||
};
|
||||
use block_placement::block_placement_system;
|
||||
|
||||
#[derive(Unique)]
|
||||
pub(crate) struct DeltaTime(Duration);
|
||||
use delta_time::{DeltaTime, init_delta_time};
|
||||
|
||||
fn startup() -> Workload {
|
||||
(
|
||||
init_delta_time,
|
||||
load_prefabs,
|
||||
init_selection_box_buffers,
|
||||
init_input,
|
||||
init_game_world,
|
||||
spawn_player,
|
||||
|
@ -96,7 +97,6 @@ fn main() {
|
|||
//Add systems and uniques, Init and load things
|
||||
world.add_unique_non_send_sync(Renderer::init(&event_loop));
|
||||
world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.)));
|
||||
world.add_unique(DeltaTime(Duration::default()));
|
||||
world.add_unique(GameSettings::default());
|
||||
|
||||
//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::{
|
||||
Surface,
|
||||
implement_vertex,
|
||||
|
@ -43,6 +43,9 @@ const fn box_vertices() -> [SelBoxVertex; CUBE_VERTICES.len() / 3] {
|
|||
}
|
||||
const BOX_VERTICES: &[SelBoxVertex] = &box_vertices();
|
||||
|
||||
#[derive(Unique)]
|
||||
pub struct SelectionBoxBuffers(VertexBuffer<SelBoxVertex>, IndexBuffer<u16>);
|
||||
|
||||
//wip
|
||||
pub fn render_selection_box(
|
||||
lookat: View<LookingAtBlock>,
|
||||
|
@ -50,27 +53,16 @@ pub fn render_selection_box(
|
|||
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||
display: NonSendSync<UniqueView<Renderer>>,
|
||||
program: NonSendSync<UniqueView<SelBoxShaderPrefab>>,
|
||||
buffers: NonSendSync<UniqueView<SelectionBoxBuffers>>,
|
||||
) {
|
||||
let camera = camera.iter().next().unwrap();
|
||||
let Some(lookat) = lookat.iter().next() 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
|
||||
target.0.draw(
|
||||
&vert,
|
||||
&index,
|
||||
&buffers.0,
|
||||
&buffers.1,
|
||||
&program.0,
|
||||
&uniform! {
|
||||
u_color: [0., 0., 0., 0.5_f32],
|
||||
|
@ -89,3 +81,19 @@ 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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue