mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-25 16:28:42 -06:00
wip
This commit is contained in:
parent
37ced81e7b
commit
9532161ed7
|
@ -1,7 +1,7 @@
|
||||||
//TODO migrate, this is just some filler code to make the game compile
|
//TODO migrate, this is just some filler code to make the game compile
|
||||||
|
|
||||||
struct VertexOutput {
|
struct VertexOutput {
|
||||||
@builtin(position) clip_position: vec4<f32>,
|
@builtin(position) position: vec4<f32>,
|
||||||
};
|
};
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
|
@ -9,9 +9,7 @@ fn vs_main(
|
||||||
@builtin(vertex_index) in_vertex_index: u32,
|
@builtin(vertex_index) in_vertex_index: u32,
|
||||||
) -> VertexOutput {
|
) -> VertexOutput {
|
||||||
var out: VertexOutput;
|
var out: VertexOutput;
|
||||||
let x = f32(1 - i32(in_vertex_index)) * 0.5;
|
out.position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
|
||||||
let y = f32(i32(in_vertex_index & 1u) * 2 - 1) * 0.5;
|
|
||||||
out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,14 +37,14 @@ impl AssetPaths for BlockTexture {
|
||||||
|
|
||||||
#[derive(Unique)]
|
#[derive(Unique)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct BlockTexturesPrefab(pub wgpu::Texture);
|
pub struct BlockTexturesAsset(pub wgpu::Texture);
|
||||||
|
|
||||||
pub fn load_prefabs(
|
pub fn load_prefabs(
|
||||||
storages: AllStoragesView,
|
storages: AllStoragesView,
|
||||||
renderer: NonSendSync<UniqueView<Renderer>>
|
renderer: NonSendSync<UniqueView<Renderer>>
|
||||||
) {
|
) {
|
||||||
log::info!("Loading textures...");
|
log::info!("Loading textures...");
|
||||||
storages.add_unique_non_send_sync(BlockTexturesPrefab(
|
storages.add_unique_non_send_sync(BlockTexturesAsset(
|
||||||
load_asset_texture_array::<BlockTexture>("blocks".into(), &renderer)
|
load_asset_texture_array::<BlockTexture>("blocks".into(), &renderer)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,7 +240,7 @@ pub fn kubi_main() {
|
||||||
let renderer = world.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
|
let renderer = world.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
|
||||||
renderer.begin()
|
renderer.begin()
|
||||||
};
|
};
|
||||||
world.add_unique_non_send_sync(target);
|
world.add_unique(target);
|
||||||
|
|
||||||
//Run render workflow
|
//Run render workflow
|
||||||
world.run_workload(render).unwrap();
|
world.run_workload(render).unwrap();
|
||||||
|
@ -248,7 +248,7 @@ pub fn kubi_main() {
|
||||||
//Finish rendering
|
//Finish rendering
|
||||||
{
|
{
|
||||||
let target = world.remove_unique::<RenderTarget>().unwrap();
|
let target = world.remove_unique::<RenderTarget>().unwrap();
|
||||||
let renderer = world.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
|
let renderer = world.borrow::<UniqueView<Renderer>>().unwrap();
|
||||||
renderer.end(target);
|
renderer.end(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
use glam::{Vec3, Mat4, Quat, ivec3};
|
use glam::{Vec3, Mat4, Quat, ivec3};
|
||||||
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, track};
|
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, track, Unique};
|
||||||
|
use wgpu::util::DeviceExt;
|
||||||
use crate::{
|
use crate::{
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
player::MainPlayer,
|
player::MainPlayer,
|
||||||
transform::Transform,
|
transform::Transform,
|
||||||
assets::BlockTexturesPrefab,
|
assets::BlockTexturesAsset,
|
||||||
world::{
|
world::{
|
||||||
ChunkStorage,
|
ChunkStorage,
|
||||||
ChunkMeshStorage,
|
ChunkMeshStorage,
|
||||||
chunk::CHUNK_SIZE,
|
chunk::CHUNK_SIZE,
|
||||||
}, settings::GameSettings,
|
}, settings::GameSettings,
|
||||||
};
|
};
|
||||||
use super::{RenderTarget, primitives::cube::CubePrimitive};
|
use super::{RenderTarget, shaders::Shaders, Renderer};
|
||||||
|
|
||||||
#[repr(C, packed)]
|
#[repr(C, packed)]
|
||||||
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
||||||
|
@ -22,7 +23,37 @@ pub struct ChunkVertex {
|
||||||
pub tex_index: u8,
|
pub tex_index: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_world() {}
|
#[repr(C, packed)]
|
||||||
|
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
|
||||||
|
struct WorldUniform {
|
||||||
|
position_offset: [f32; 3],
|
||||||
|
view: [[f32; 4]; 4],
|
||||||
|
perspective: [[f32; 4]; 4],
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn draw_world(
|
||||||
|
renderer: UniqueView<Renderer>,
|
||||||
|
mut target: UniqueViewMut<RenderTarget>,
|
||||||
|
chunks: UniqueView<ChunkStorage>,
|
||||||
|
meshes: UniqueView<ChunkMeshStorage>,
|
||||||
|
shaders: UniqueView<Shaders>,
|
||||||
|
texture: UniqueView<BlockTexturesAsset>,
|
||||||
|
camera: View<Camera>,
|
||||||
|
settings: UniqueView<GameSettings>
|
||||||
|
) {
|
||||||
|
let camera = camera.iter().next().expect("No cameras in the scene");
|
||||||
|
for (&position, chunk) in &chunks.chunks {
|
||||||
|
if let Some(key) = chunk.mesh_index {
|
||||||
|
let mesh = meshes.get(key).expect("Mesh index pointing to nothing");
|
||||||
|
let world_position = position.as_vec3() * CHUNK_SIZE as f32;
|
||||||
|
|
||||||
|
//TODO culling
|
||||||
|
|
||||||
|
//Draw chunk mesh
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(fuck)]
|
#[cfg(fuck)]
|
||||||
pub fn draw_world(
|
pub fn draw_world(
|
||||||
|
@ -30,7 +61,7 @@ pub fn draw_world(
|
||||||
chunks: UniqueView<ChunkStorage>,
|
chunks: UniqueView<ChunkStorage>,
|
||||||
meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
|
meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
|
||||||
program: NonSendSync<UniqueView<ChunkShaderPrefab>>,
|
program: NonSendSync<UniqueView<ChunkShaderPrefab>>,
|
||||||
texture: NonSendSync<UniqueView<BlockTexturesPrefab>>,
|
texture: NonSendSync<UniqueView<BlockTexturesAsset>>,
|
||||||
camera: View<Camera>,
|
camera: View<Camera>,
|
||||||
settings: UniqueView<GameSettings>
|
settings: UniqueView<GameSettings>
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -102,7 +102,7 @@ impl ChunkMeshStorage {
|
||||||
pub fn init_game_world(
|
pub fn init_game_world(
|
||||||
storages: AllStoragesView,
|
storages: AllStoragesView,
|
||||||
) {
|
) {
|
||||||
storages.add_unique_non_send_sync(ChunkMeshStorage::new());
|
storages.add_unique(ChunkMeshStorage::new());
|
||||||
storages.add_unique(ChunkStorage::new());
|
storages.add_unique(ChunkStorage::new());
|
||||||
storages.add_unique(ChunkTaskManager::new());
|
storages.add_unique(ChunkTaskManager::new());
|
||||||
storages.add_unique(BlockUpdateQueue::new());
|
storages.add_unique(BlockUpdateQueue::new());
|
||||||
|
|
Loading…
Reference in a new issue