mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-22 06:48:43 -06:00
some progress
This commit is contained in:
parent
d77779d720
commit
e89dd07e66
0
src/camera.rs
Normal file
0
src/camera.rs
Normal file
41
src/main.rs
41
src/main.rs
|
@ -1,4 +1,8 @@
|
||||||
use shipyard::{World, Workload, IntoWorkload, View, UniqueView, NonSendSync};
|
use shipyard::{
|
||||||
|
World, Workload, IntoWorkload,
|
||||||
|
UniqueView, UniqueViewMut,
|
||||||
|
NonSendSync, Unique
|
||||||
|
};
|
||||||
use glium::{
|
use glium::{
|
||||||
Surface,
|
Surface,
|
||||||
glutin::{
|
glutin::{
|
||||||
|
@ -6,14 +10,24 @@ use glium::{
|
||||||
event::{Event, WindowEvent}
|
event::{Event, WindowEvent}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
use glam::vec3;
|
||||||
|
use std::time::{Instant, Duration};
|
||||||
|
|
||||||
mod logging;
|
mod logging;
|
||||||
mod rendering;
|
pub(crate) mod rendering;
|
||||||
|
pub(crate) mod player;
|
||||||
|
pub(crate) mod world;
|
||||||
|
|
||||||
use rendering::{Rederer, RenderTarget};
|
use rendering::{Rederer, RenderTarget, BackgroundColor, clear_background};
|
||||||
|
|
||||||
|
#[derive(Unique)]
|
||||||
|
pub(crate) struct DeltaTime(Duration);
|
||||||
|
|
||||||
fn render() -> Workload {
|
fn render() -> Workload {
|
||||||
(||()).into_workload()
|
(
|
||||||
|
clear_background,
|
||||||
|
|
||||||
|
).into_workload()
|
||||||
}
|
}
|
||||||
fn update() -> Workload {
|
fn update() -> Workload {
|
||||||
(||()).into_workload()
|
(||()).into_workload()
|
||||||
|
@ -29,6 +43,8 @@ fn main() {
|
||||||
let world = World::new();
|
let world = World::new();
|
||||||
|
|
||||||
//Add systems and uniques
|
//Add systems and uniques
|
||||||
|
world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.)));
|
||||||
|
world.add_unique(DeltaTime(Duration::default()));
|
||||||
world.add_unique_non_send_sync(
|
world.add_unique_non_send_sync(
|
||||||
Rederer::init(&event_loop)
|
Rederer::init(&event_loop)
|
||||||
);
|
);
|
||||||
|
@ -36,24 +52,41 @@ fn main() {
|
||||||
world.add_workload(render);
|
world.add_workload(render);
|
||||||
|
|
||||||
//Run the event loop
|
//Run the event loop
|
||||||
|
let mut last_update = Instant::now();
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = ControlFlow::Poll;
|
*control_flow = ControlFlow::Poll;
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
|
log::info!("exit requested");
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit;
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
|
//Update delta time (maybe move this into a system?)
|
||||||
|
{
|
||||||
|
let mut dt_view = world.borrow::<UniqueViewMut<DeltaTime>>().unwrap();
|
||||||
|
let now = Instant::now();
|
||||||
|
dt_view.0 = now - last_update;
|
||||||
|
last_update = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Run update workflow
|
||||||
world.run_workload(update).unwrap();
|
world.run_workload(update).unwrap();
|
||||||
|
|
||||||
|
//Start rendering
|
||||||
let mut target = {
|
let mut target = {
|
||||||
let renderer = world.borrow::<NonSendSync<UniqueView<Rederer>>>().unwrap();
|
let renderer = world.borrow::<NonSendSync<UniqueView<Rederer>>>().unwrap();
|
||||||
renderer.display.draw()
|
renderer.display.draw()
|
||||||
};
|
};
|
||||||
target.clear_color_and_depth((0., 0., 0., 1.), 1.);
|
target.clear_color_and_depth((0., 0., 0., 1.), 1.);
|
||||||
world.add_unique_non_send_sync(RenderTarget(target));
|
world.add_unique_non_send_sync(RenderTarget(target));
|
||||||
|
|
||||||
|
//Run render workflow
|
||||||
world.run_workload(render).unwrap();
|
world.run_workload(render).unwrap();
|
||||||
|
|
||||||
|
//Finish rendering
|
||||||
let target = world.remove_unique::<RenderTarget>().unwrap();
|
let target = world.remove_unique::<RenderTarget>().unwrap();
|
||||||
target.0.finish().unwrap();
|
target.0.finish().unwrap();
|
||||||
},
|
},
|
||||||
|
|
1
src/player.rs
Normal file
1
src/player.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub struct Player;
|
0
src/prefabs.rs
Normal file
0
src/prefabs.rs
Normal file
|
@ -1,16 +1,20 @@
|
||||||
use shipyard::Unique;
|
use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut};
|
||||||
use glium::{
|
use glium::{
|
||||||
glutin::{
|
glutin::{
|
||||||
event_loop::EventLoop,
|
event_loop::EventLoop,
|
||||||
window::WindowBuilder,
|
window::WindowBuilder,
|
||||||
ContextBuilder, GlProfile
|
ContextBuilder, GlProfile
|
||||||
},
|
},
|
||||||
Display,
|
Display, Surface,
|
||||||
};
|
};
|
||||||
|
use glam::Vec3;
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
pub struct RenderTarget(pub glium::Frame);
|
pub struct RenderTarget(pub glium::Frame);
|
||||||
|
|
||||||
|
#[derive(Unique)]
|
||||||
|
pub struct BackgroundColor(pub Vec3);
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
pub struct Rederer {
|
pub struct Rederer {
|
||||||
pub display: Display
|
pub display: Display
|
||||||
|
@ -29,3 +33,7 @@ impl Rederer {
|
||||||
Self { display }
|
Self { display }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clear_background(mut target: NonSendSync<UniqueViewMut<RenderTarget>>, color: UniqueView<BackgroundColor>) {
|
||||||
|
target.0.clear_color_srgb_and_depth((color.0.x, color.0.y, color.0.z, 1.), 1.);
|
||||||
|
}
|
||||||
|
|
2
src/world.rs
Normal file
2
src/world.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod chunk;
|
||||||
|
pub mod block;
|
11
src/world/block.rs
Normal file
11
src/world/block.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
use strum::EnumIter;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, EnumIter)]
|
||||||
|
#[repr(u8)]
|
||||||
|
pub enum Block {
|
||||||
|
Air,
|
||||||
|
Stone,
|
||||||
|
Dirt,
|
||||||
|
Grass,
|
||||||
|
Sand,
|
||||||
|
}
|
0
src/world/chunk.rs
Normal file
0
src/world/chunk.rs
Normal file
Loading…
Reference in a new issue