Compare commits

...

2 commits

Author SHA1 Message Date
griffi-gh 7620717368 drop kubi-pool 2024-05-02 11:14:47 +02:00
griffi-gh f157e2dab3 add overlay when submerged 2024-05-02 11:03:38 +02:00
14 changed files with 151 additions and 78 deletions

4
Cargo.lock generated
View file

@ -1190,10 +1190,6 @@ dependencies = [
"log",
]
[[package]]
name = "kubi-pool"
version = "0.0.0"
[[package]]
name = "kubi-server"
version = "0.0.0"

View file

@ -4,7 +4,6 @@ members = [
"kubi-server",
"kubi-shared",
"kubi-logging",
"kubi-pool"
]
default-members = ["kubi"]
resolver = "2"

View file

@ -118,15 +118,12 @@ name = "Kubi Server" # server name
<h2>"In-house" libraries</h2>
- [`hui`](https://github.com/griffi-gh/hui): semi-imm.mode backend-agnostic ui system\
mostly ready to use, it has already replaced the Kubi legacy ui
- [`kubi-ui-glium`](kubi-ui-glium) Glium-based backend for `kubi-ui`
- [`kubi-pool`](kubi-pool): very early work-in-progress work-stealing threadpool system\
aiming to replace `rayon` threadpool that's currently used inside the kubi client (for more control over task priority)
- [`hui`, `hui-glium`, `hui-winit`](https://github.com/griffi-gh/hui): semi-imm.mode backend-agnostic ui system\
- [`kubi-logging`](kubi-logging) fancy-ass custom formatter for `env-logger`
deprecated:
~~`kubi-udp`~~ was a huge pita to work with and eventually got replaced by `uflow` (https://github.com/lowquark/uflow) in #5
- ~~`kubi-udp`~~ eventually got replaced by `uflow` (https://github.com/lowquark/uflow) in #5
- ~~`kubi-pool`~~ decided there's no need to replace rayon for now
<h6 align="right"><i>~ uwu</i></h6>

View file

@ -1,7 +0,0 @@
[package]
name = "kubi-pool"
version = "0.0.0"
edition = "2021"
publish = false
[dependencies]

View file

@ -1,33 +0,0 @@
use std::{thread::JoinHandle, collections::VecDeque};
pub struct KubiPool<T, R> {
callback: fn(T) -> R,
threads: Vec<JoinHandle<()>>,
}
struct Task<T> {
priority: u8,
data: T,
}
fn task_loop<T, R>() {
let tasks = VecDeque::<Task<T>>::new();
loop {
};
}
impl<T: 'static, R: 'static> KubiPool<T, R> {
pub fn new(threads: usize, callback: fn(T) -> R) -> Self {
Self {
callback,
threads: (0..threads).map(|_| {
std::thread::spawn(move || task_loop::<T, R>())
}).collect(),
}
}
pub fn resize(&mut self, threads: usize) {
}
}

View file

@ -1,3 +1,4 @@
use glam::{vec4, Vec4};
use serde::{Serialize, Deserialize};
use strum::EnumIter;
use num_enum::TryFromPrimitive;
@ -53,6 +54,7 @@ impl Block {
collision: CollisionType::None,
raycast_collision: false,
drops: None,
submerge: None,
},
Self::Marker => BlockDescriptor {
name: "marker",
@ -60,6 +62,7 @@ impl Block {
collision: CollisionType::None,
raycast_collision: false,
drops: None,
submerge: None,
},
Self::Stone => BlockDescriptor {
name: "stone",
@ -70,6 +73,7 @@ impl Block {
collision: CollisionType::Solid,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::Dirt => BlockDescriptor {
name: "dirt",
@ -80,6 +84,7 @@ impl Block {
collision: CollisionType::Solid,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::Grass => BlockDescriptor {
name: "grass",
@ -94,6 +99,7 @@ impl Block {
collision: CollisionType::Solid,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::Sand => BlockDescriptor {
name: "sand",
@ -104,6 +110,7 @@ impl Block {
collision: CollisionType::Solid,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::Cobblestone => BlockDescriptor {
name: "cobblestone",
@ -114,6 +121,7 @@ impl Block {
collision: CollisionType::Solid,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::TallGrass => BlockDescriptor {
name: "tall grass",
@ -121,6 +129,7 @@ impl Block {
collision: CollisionType::None,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::Planks => BlockDescriptor {
name: "planks",
@ -131,6 +140,7 @@ impl Block {
collision: CollisionType::Solid,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::Torch => BlockDescriptor {
name: "torch",
@ -138,6 +148,7 @@ impl Block {
collision: CollisionType::None,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::Wood => BlockDescriptor {
name: "leaf",
@ -148,6 +159,7 @@ impl Block {
collision: CollisionType::Solid,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::Leaf => BlockDescriptor {
name: "leaf",
@ -158,6 +170,7 @@ impl Block {
collision: CollisionType::Solid,
raycast_collision: true,
drops: None,
submerge: None,
},
Self::Water => BlockDescriptor {
name: "water",
@ -168,6 +181,7 @@ impl Block {
collision: CollisionType::None,
raycast_collision: true,
drops: None,
submerge: Some(vec4(0., 0., 0.25, 0.75)),
},
}
}
@ -180,6 +194,7 @@ pub struct BlockDescriptor {
pub collision: CollisionType,
pub raycast_collision: bool,
pub drops: Option<Item>,
pub submerge: Option<Vec4>,
}
#[derive(Clone, Copy, Debug)]

View file

@ -0,0 +1,10 @@
#version 300 es
precision highp float;
out vec4 out_color;
uniform vec4 color;
void main() {
out_color = color;
}

View file

@ -0,0 +1,9 @@
#version 300 es
precision highp float;
in vec2 position;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
}

View file

@ -76,6 +76,7 @@ use rendering::{
world::{draw_world, draw_current_chunk_border},
selection_box::render_selection_box,
entities::render_entities,
sumberge::render_submerged_view,
};
use block_placement::update_block_placement;
use delta_time::{DeltaTime, init_delta_time};
@ -178,6 +179,7 @@ fn render() -> Workload {
draw_current_chunk_border,
render_selection_box,
render_entities,
render_submerged_view,
).into_sequential_workload().run_if(is_ingame),
kubi_ui_draw,
).into_sequential_workload()

View file

@ -51,6 +51,10 @@ pub struct ChunkShaderPrefab(pub Program);
#[repr(transparent)]
pub struct ColoredShaderPrefab(pub Program);
#[derive(Unique)]
#[repr(transparent)]
pub struct Colored2ShaderPrefab(pub Program);
#[derive(Unique)]
#[repr(transparent)]
pub struct UiFontPrefab(pub FontHandle);
@ -98,6 +102,14 @@ pub fn load_prefabs(
&renderer.display
)
));
storages.add_unique_non_send_sync(Colored2ShaderPrefab(
include_shader_prefab!(
"colored",
"../shaders/colored2.vert",
"../shaders/colored2.frag",
&renderer.display
)
));
log::info!("releasing shader compiler");

View file

@ -22,6 +22,7 @@ pub mod primitives;
pub mod world;
pub mod selection_box;
pub mod entities;
pub mod sumberge;
#[derive(Unique)]
#[repr(transparent)]

View file

@ -1,27 +1,30 @@
use shipyard::{Workload, IntoWorkload};
use glium::implement_vertex;
pub mod cube;
pub mod rect;
use cube::init_cube_primitive;
use rect::init_rect_primitive;
#[derive(Clone, Copy, Default)]
pub struct PositionOnlyVertex {
pub position: [f32; 3],
}
implement_vertex!(PositionOnlyVertex, position);
#[derive(Clone, Copy, Default)]
pub struct PositionOnlyVertex2d {
pub position: [f32; 2],
}
implement_vertex!(PositionOnlyVertex2d, position);
pub fn init_primitives() -> Workload {
(
init_cube_primitive,
init_rect_primitive,
).into_sequential_workload()
}
use shipyard::{Workload, IntoWorkload};
use glium::implement_vertex;
pub mod cube;
pub mod rect;
pub mod stri;
use cube::init_cube_primitive;
use rect::init_rect_primitive;
use stri::init_stri_primitive;
#[derive(Clone, Copy, Default)]
pub struct PositionOnlyVertex {
pub position: [f32; 3],
}
implement_vertex!(PositionOnlyVertex, position);
#[derive(Clone, Copy, Default)]
pub struct PositionOnlyVertex2d {
pub position: [f32; 2],
}
implement_vertex!(PositionOnlyVertex2d, position);
pub fn init_primitives() -> Workload {
(
init_cube_primitive,
init_rect_primitive,
init_stri_primitive,
).into_workload()
}

View file

@ -0,0 +1,30 @@
use shipyard::{Unique, AllStoragesView, NonSendSync, UniqueView};
use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType};
use crate::rendering::Renderer;
use super::PositionOnlyVertex2d;
#[derive(Unique)]
pub struct STriPrimitive(pub VertexBuffer<PositionOnlyVertex2d>, pub IndexBuffer<u16>);
const STRI_VERTEX: &[PositionOnlyVertex2d] = &[
PositionOnlyVertex2d { position: [-1., -1.] },
PositionOnlyVertex2d { position: [ 3., -1.] },
PositionOnlyVertex2d { position: [-1., 3.] },
];
const STRI_INDEX: &[u16] = &[0, 1, 2];
pub(super) fn init_stri_primitive(
storages: AllStoragesView,
display: NonSendSync<UniqueView<Renderer>>
) {
let vert = VertexBuffer::immutable(
&display.display,
STRI_VERTEX
).unwrap();
let index = IndexBuffer::immutable(
&display.display,
PrimitiveType::TrianglesList,
STRI_INDEX
).unwrap();
storages.add_unique_non_send_sync(STriPrimitive(vert, index));
}

View file

@ -0,0 +1,39 @@
use glium::{uniform, Blend, DrawParameters, Surface};
use kubi_shared::transform::Transform;
use shipyard::{IntoIter, NonSendSync, UniqueView, UniqueViewMut, View};
use crate::{
player::MainPlayer,
prefabs::Colored2ShaderPrefab,
rendering::primitives::stri::STriPrimitive,
world::ChunkStorage,
};
use super::RenderTarget;
pub fn render_submerged_view(
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
primitive: NonSendSync<UniqueView<STriPrimitive>>,
program: NonSendSync<UniqueView<Colored2ShaderPrefab>>,
plr: View<MainPlayer>,
trans: View<Transform>,
world: UniqueView<ChunkStorage>,
) {
let (_, plr_trans) = (&plr, &trans).iter().next().expect("Main player MIA");
let plr_pos = plr_trans.0.to_scale_rotation_translation().2;
let block_at_pos = world.get_block(plr_pos.floor().as_ivec3());
let Some(block_at_pos) = block_at_pos else { return };
let Some(color) = block_at_pos.descriptor().submerge else { return };
let draw_parameters = DrawParameters {
blend: Blend::alpha_blending(),
..Default::default()
};
target.0.draw(
&primitive.0,
&primitive.1,
&program.0,
&uniform! {
color: color.to_array(),
},
&draw_parameters,
).unwrap();
}