mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 20:08:20 -06:00
meow
This commit is contained in:
parent
a39ad3b2dd
commit
cc08456b39
|
@ -20,6 +20,7 @@ pub(crate) mod world;
|
|||
pub(crate) mod prefabs;
|
||||
|
||||
use rendering::{Rederer, RenderTarget, BackgroundColor, clear_background};
|
||||
use world::GameWorld;
|
||||
use prefabs::load_prefabs;
|
||||
|
||||
#[derive(Unique)]
|
||||
|
@ -44,13 +45,14 @@ fn main() {
|
|||
//Create a shipyard world
|
||||
let world = World::new();
|
||||
|
||||
//Init and load things
|
||||
//Add systems and uniques, Init and load things
|
||||
world.add_unique_non_send_sync(
|
||||
Rederer::init(&event_loop)
|
||||
);
|
||||
load_prefabs(&world);
|
||||
|
||||
//Add systems and uniques
|
||||
world.add_unique_non_send_sync(
|
||||
GameWorld::new()
|
||||
);
|
||||
world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.)));
|
||||
world.add_unique(DeltaTime(Duration::default()));
|
||||
world.add_workload(update);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use shipyard::{World, NonSendSync, UniqueView, Unique};
|
||||
use strum::{EnumIter, IntoEnumIterator};
|
||||
use glium::{texture::{SrgbTexture2dArray, RawImage2d}, backend::Facade, Program};
|
||||
use glium::{texture::SrgbTexture2dArray, Program};
|
||||
use strum::EnumIter;
|
||||
use crate::rendering::Rederer;
|
||||
|
||||
mod texture;
|
||||
|
@ -50,8 +50,6 @@ impl AssetPaths for BlockTextures {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Unique)]
|
||||
pub struct BlockTexturesPrefab(SrgbTexture2dArray);
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use glium::{Program, backend::Facade};
|
||||
|
||||
|
||||
macro_rules! include_shader_prefab {
|
||||
($vert: literal, $frag: literal, $geom: literal, $facade: expr) => {
|
||||
{
|
||||
use ::glium::Program;
|
||||
log::info!("↓↓↓ compiling shader prefab ↓↓↓");
|
||||
log::info!("{} {} {}", $vert, $frag, $geom);
|
||||
Program::from_source(
|
||||
|
@ -15,6 +16,7 @@ macro_rules! include_shader_prefab {
|
|||
};
|
||||
($vert: literal, $frag: literal, $facade: expr) => {
|
||||
{
|
||||
use ::glium::Program;
|
||||
log::info!("↓↓↓ compiling shader prefab ↓↓↓");
|
||||
log::info!("{} {}", $vert, $frag);
|
||||
Program::from_source(
|
||||
|
|
|
@ -4,7 +4,10 @@ use std::{fs::File, path::PathBuf, io::BufReader};
|
|||
use glium::{texture::{SrgbTexture2dArray, RawImage2d}, backend::Facade};
|
||||
use super::AssetPaths;
|
||||
|
||||
pub fn load_texture2darray_prefab<T: AssetPaths + IntoEnumIterator, E: Facade>(
|
||||
pub fn load_texture2darray_prefab<
|
||||
T: AssetPaths + IntoEnumIterator,
|
||||
E: Facade
|
||||
>(
|
||||
directory: PathBuf,
|
||||
facade: &E
|
||||
) -> SrgbTexture2dArray {
|
||||
|
|
99
src/world.rs
99
src/world.rs
|
@ -1,4 +1,5 @@
|
|||
use glam::IVec2;
|
||||
use shipyard::Unique;
|
||||
use glam::{IVec3, ivec3};
|
||||
use hashbrown::HashMap;
|
||||
|
||||
pub mod chunk;
|
||||
|
@ -7,6 +8,98 @@ pub mod render;
|
|||
|
||||
use chunk::Chunk;
|
||||
|
||||
pub struct World {
|
||||
pub chunks: HashMap<IVec2, 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,
|
||||
pub bottom: &'a Chunk,
|
||||
pub left: &'a Chunk,
|
||||
pub right: &'a Chunk,
|
||||
pub front: &'a Chunk,
|
||||
pub back: &'a Chunk,
|
||||
}
|
||||
pub struct AllChunksNeighborsMut<'a> {
|
||||
pub center: &'a mut Chunk,
|
||||
pub top: &'a mut Chunk,
|
||||
pub bottom: &'a mut Chunk,
|
||||
pub left: &'a mut Chunk,
|
||||
pub right: &'a mut Chunk,
|
||||
pub front: &'a mut Chunk,
|
||||
pub back: &'a mut Chunk,
|
||||
}
|
||||
pub struct ChunksNeighbors<'a> {
|
||||
pub center: Option<&'a Chunk>,
|
||||
pub top: Option<&'a Chunk>,
|
||||
pub bottom: Option<&'a Chunk>,
|
||||
pub left: Option<&'a Chunk>,
|
||||
pub right: Option<&'a Chunk>,
|
||||
pub front: Option<&'a Chunk>,
|
||||
pub back: Option<&'a Chunk>,
|
||||
}
|
||||
impl<'a> ChunksNeighbors<'a> {
|
||||
pub fn all(&self) -> Option<AllChunksNeighbors<'a>> {
|
||||
Some(AllChunksNeighbors {
|
||||
center: self.center?,
|
||||
top: self.top?,
|
||||
bottom: self.bottom?,
|
||||
left: self.left?,
|
||||
right: self.right?,
|
||||
front: self.front?,
|
||||
back: self.back?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Unique)]
|
||||
pub struct GameWorld {
|
||||
pub chunks: HashMap<IVec3, Chunk>
|
||||
}
|
||||
impl GameWorld {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
pub fn neighbors(&self, coords: IVec3) -> ChunksNeighbors {
|
||||
ChunksNeighbors {
|
||||
center: self.chunks.get(&coords),
|
||||
top: self.chunks.get(&(coords - ivec3(0, 1, 0))),
|
||||
bottom: self.chunks.get(&(coords + ivec3(0, 1, 0))),
|
||||
left: self.chunks.get(&(coords - ivec3(1, 0, 0))),
|
||||
right: self.chunks.get(&(coords + ivec3(1, 0, 0))),
|
||||
front: self.chunks.get(&(coords - ivec3(0, 0, 1))),
|
||||
back: self.chunks.get(&(coords + ivec3(0, 0, 1))),
|
||||
}
|
||||
}
|
||||
pub fn neighbors_all(&self, coords: IVec3) -> Option<AllChunksNeighbors> {
|
||||
self.neighbors(coords).all()
|
||||
}
|
||||
pub fn neighbors_all_mut(&mut self, coords: IVec3) -> Option<AllChunksNeighborsMut> {
|
||||
let mut refs = self.chunks.get_many_mut([
|
||||
&coords,
|
||||
&(coords - ivec3(0, 1, 0)),
|
||||
&(coords + ivec3(0, 1, 0)),
|
||||
&(coords - ivec3(1, 0, 0)),
|
||||
&(coords + ivec3(1, 0, 0)),
|
||||
&(coords - ivec3(0, 0, 1)),
|
||||
&(coords + ivec3(0, 0, 1)),
|
||||
])?.map(Some);
|
||||
Some(AllChunksNeighborsMut {
|
||||
center: std::mem::take(&mut refs[0]).unwrap(),
|
||||
top: std::mem::take(&mut refs[1]).unwrap(),
|
||||
bottom: std::mem::take(&mut refs[2]).unwrap(),
|
||||
left: std::mem::take(&mut refs[3]).unwrap(),
|
||||
right: std::mem::take(&mut refs[4]).unwrap(),
|
||||
front: std::mem::take(&mut refs[5]).unwrap(),
|
||||
back: std::mem::take(&mut refs[6]).unwrap(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn update_world(
|
||||
|
||||
) {
|
||||
|
||||
}
|
||||
|
|
0
src/world/mesh.rs
Normal file
0
src/world/mesh.rs
Normal file
Loading…
Reference in a new issue