This commit is contained in:
griffi-gh 2023-07-17 00:52:07 +02:00
parent 37ced81e7b
commit 9532161ed7
5 changed files with 44 additions and 15 deletions

View file

@ -1,7 +1,7 @@
//TODO migrate, this is just some filler code to make the game compile
struct VertexOutput {
@builtin(position) clip_position: vec4<f32>,
@builtin(position) position: vec4<f32>,
};
@vertex
@ -9,9 +9,7 @@ fn vs_main(
@builtin(vertex_index) in_vertex_index: u32,
) -> VertexOutput {
var out: VertexOutput;
let x = f32(1 - i32(in_vertex_index)) * 0.5;
let y = f32(i32(in_vertex_index & 1u) * 2 - 1) * 0.5;
out.clip_position = vec4<f32>(x, y, 0.0, 1.0);
out.position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
return out;
}

View file

@ -37,14 +37,14 @@ impl AssetPaths for BlockTexture {
#[derive(Unique)]
#[repr(transparent)]
pub struct BlockTexturesPrefab(pub wgpu::Texture);
pub struct BlockTexturesAsset(pub wgpu::Texture);
pub fn load_prefabs(
storages: AllStoragesView,
renderer: NonSendSync<UniqueView<Renderer>>
) {
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)
));
}

View file

@ -240,7 +240,7 @@ pub fn kubi_main() {
let renderer = world.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
renderer.begin()
};
world.add_unique_non_send_sync(target);
world.add_unique(target);
//Run render workflow
world.run_workload(render).unwrap();
@ -248,7 +248,7 @@ pub fn kubi_main() {
//Finish rendering
{
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);
}

View file

@ -1,17 +1,18 @@
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::{
camera::Camera,
player::MainPlayer,
transform::Transform,
assets::BlockTexturesPrefab,
assets::BlockTexturesAsset,
world::{
ChunkStorage,
ChunkMeshStorage,
chunk::CHUNK_SIZE,
}, settings::GameSettings,
};
use super::{RenderTarget, primitives::cube::CubePrimitive};
use super::{RenderTarget, shaders::Shaders, Renderer};
#[repr(C, packed)]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
@ -22,15 +23,45 @@ pub struct ChunkVertex {
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)]
pub fn draw_world(
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
chunks: UniqueView<ChunkStorage>,
meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
program: NonSendSync<UniqueView<ChunkShaderPrefab>>,
texture: NonSendSync<UniqueView<BlockTexturesPrefab>>,
texture: NonSendSync<UniqueView<BlockTexturesAsset>>,
camera: View<Camera>,
settings: UniqueView<GameSettings>
) {

View file

@ -102,7 +102,7 @@ impl ChunkMeshStorage {
pub fn init_game_world(
storages: AllStoragesView,
) {
storages.add_unique_non_send_sync(ChunkMeshStorage::new());
storages.add_unique(ChunkMeshStorage::new());
storages.add_unique(ChunkStorage::new());
storages.add_unique(ChunkTaskManager::new());
storages.add_unique(BlockUpdateQueue::new());