some things

This commit is contained in:
griffi-gh 2023-01-20 21:55:02 +01:00
parent 10faee215f
commit 3d7083dc42
5 changed files with 60 additions and 13 deletions

View file

@ -21,20 +21,27 @@ pub(crate) mod prefabs;
pub(crate) mod transform;
use rendering::{Rederer, RenderTarget, BackgroundColor, clear_background};
use world::GameWorld;
use player::spawn_player;
use world::{GameWorld, loading::load_world_around_player};
use prefabs::load_prefabs;
#[derive(Unique)]
pub(crate) struct DeltaTime(Duration);
fn render() -> Workload {
fn startup() -> Workload {
(
clear_background,
spawn_player,
).into_workload()
}
fn update() -> Workload {
(||()).into_workload()
(
load_world_around_player
).into_workload()
}
fn render() -> Workload {
(
clear_background,
).into_workload()
}
fn main() {
@ -56,9 +63,15 @@ fn main() {
);
world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.)));
world.add_unique(DeltaTime(Duration::default()));
//Register workloads
world.add_workload(startup);
world.add_workload(update);
world.add_workload(render);
//Run startup systems
world.run_workload(startup).unwrap();
//Run the event loop
let mut last_update = Instant::now();
event_loop.run(move |event, _, control_flow| {

View file

@ -1 +1,25 @@
use glam::Mat4;
use shipyard::{Component, EntitiesViewMut, ViewMut};
use crate::transform::Transform;
#[derive(Component)]
pub struct Player;
pub fn spawn_player (
mut entities: EntitiesViewMut,
mut vm_player: ViewMut<Player>,
mut vm_transform: ViewMut<Transform>
) {
log::info!("spawning player");
entities.add_entity(
(
&mut vm_player,
&mut vm_transform
),
(
Player,
Transform(Mat4::default())
)
);
}

View file

@ -1,3 +1,6 @@
use shipyard::Component;
use glam::Mat4;
pub struct Transform(Mat4);
#[derive(Component, Clone, Copy, Debug, Default)]
#[track(All)]
pub struct Transform(pub Mat4);

View file

@ -6,13 +6,13 @@ pub mod chunk;
pub mod block;
pub mod render;
pub mod tasks;
pub mod loading;
use chunk::Chunk;
//TODO separate world struct for render data
// because this is not send-sync
pub struct AllChunksNeighbors<'a> {
pub center: &'a Chunk,
pub top: &'a Chunk,
@ -97,9 +97,3 @@ impl GameWorld {
})
}
}
fn update_world(
) {
}

13
src/world/loading.rs Normal file
View file

@ -0,0 +1,13 @@
use shipyard::{View, UniqueViewMut, NonSendSync, IntoIter};
use crate::{player::Player, transform::Transform};
use super::GameWorld;
pub fn load_world_around_player(
v_player: View<Player>,
v_transform: View<Transform>,
vm_world: NonSendSync<UniqueViewMut<GameWorld>>,
) {
for (player, transform) in (&v_player, v_transform.inserted_or_modified()).iter() {
}
}