mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-25 05:08:21 -06:00
add chunk borders
This commit is contained in:
parent
2c0638fca2
commit
813f3ffb73
|
@ -1,8 +1,8 @@
|
||||||
#version 150 core
|
#version 150 core
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 out_color;
|
||||||
uniform vec4 u_color;
|
uniform vec4 color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
color = u_color;
|
out_color = color;
|
||||||
}
|
}
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -32,12 +32,6 @@ pub(crate) mod delta_time;
|
||||||
pub(crate) mod cursor_lock;
|
pub(crate) mod cursor_lock;
|
||||||
pub(crate) mod control_flow;
|
pub(crate) mod control_flow;
|
||||||
|
|
||||||
use rendering::{
|
|
||||||
Renderer,
|
|
||||||
RenderTarget,
|
|
||||||
BackgroundColor,
|
|
||||||
clear_background
|
|
||||||
};
|
|
||||||
use world::{
|
use world::{
|
||||||
init_game_world,
|
init_game_world,
|
||||||
loading::update_loaded_world_around_player,
|
loading::update_loaded_world_around_player,
|
||||||
|
@ -54,9 +48,14 @@ use events::{
|
||||||
use input::{init_input, process_inputs};
|
use input::{init_input, process_inputs};
|
||||||
use fly_controller::update_controllers;
|
use fly_controller::update_controllers;
|
||||||
use rendering::{
|
use rendering::{
|
||||||
|
Renderer,
|
||||||
|
RenderTarget,
|
||||||
|
BackgroundColor,
|
||||||
|
clear_background,
|
||||||
primitives::init_simple_box_buffers,
|
primitives::init_simple_box_buffers,
|
||||||
selection_box::render_selection_box,
|
selection_box::render_selection_box,
|
||||||
world::draw_world,
|
world::draw_world,
|
||||||
|
world::draw_current_chunk_border,
|
||||||
};
|
};
|
||||||
use block_placement::block_placement_system;
|
use block_placement::block_placement_system;
|
||||||
use delta_time::{DeltaTime, init_delta_time};
|
use delta_time::{DeltaTime, init_delta_time};
|
||||||
|
@ -94,6 +93,7 @@ fn render() -> Workload {
|
||||||
(
|
(
|
||||||
clear_background,
|
clear_background,
|
||||||
draw_world,
|
draw_world,
|
||||||
|
draw_current_chunk_border,
|
||||||
render_selection_box,
|
render_selection_box,
|
||||||
).into_sequential_workload()
|
).into_sequential_workload()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use glam::Mat4;
|
|
||||||
use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView};
|
use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView};
|
||||||
use glium::{
|
use glium::{
|
||||||
Surface,
|
Surface,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use glam::Vec3;
|
use glam::{Vec3, Mat4, Quat, ivec3};
|
||||||
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter};
|
use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter};
|
||||||
use glium::{
|
use glium::{
|
||||||
implement_vertex, uniform,
|
implement_vertex, uniform,
|
||||||
|
@ -15,10 +15,12 @@ use glium::{
|
||||||
DepthTest,
|
DepthTest,
|
||||||
PolygonMode,
|
PolygonMode,
|
||||||
BackfaceCullingMode,
|
BackfaceCullingMode,
|
||||||
}
|
}, Blend
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
camera::Camera,
|
camera::Camera,
|
||||||
|
player::MainPlayer,
|
||||||
|
transform::Transform,
|
||||||
prefabs::{
|
prefabs::{
|
||||||
ChunkShaderPrefab,
|
ChunkShaderPrefab,
|
||||||
BlockTexturesPrefab,
|
BlockTexturesPrefab,
|
||||||
|
@ -28,7 +30,7 @@ use crate::{
|
||||||
ChunkStorage,
|
ChunkStorage,
|
||||||
ChunkMeshStorage,
|
ChunkMeshStorage,
|
||||||
chunk::CHUNK_SIZE,
|
chunk::CHUNK_SIZE,
|
||||||
},
|
}, settings::GameSettings,
|
||||||
};
|
};
|
||||||
use super::{RenderTarget, primitives::SimpleBoxBuffers};
|
use super::{RenderTarget, primitives::SimpleBoxBuffers};
|
||||||
|
|
||||||
|
@ -107,27 +109,72 @@ pub fn draw_world(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this doesn't use culling!
|
//this doesn't use culling!
|
||||||
// pub fn draw_chunk_borders(
|
pub fn draw_current_chunk_border(
|
||||||
// mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
mut target: NonSendSync<UniqueViewMut<RenderTarget>>,
|
||||||
// chunks: UniqueView<ChunkStorage>,
|
player: View<MainPlayer>,
|
||||||
// buffers: NonSendSync<UniqueView<SimpleBoxBuffers>>,
|
transforms: View<Transform>,
|
||||||
// program: NonSendSync<UniqueView<BasicShaderPrefab>>,
|
buffers: NonSendSync<UniqueView<SimpleBoxBuffers>>,
|
||||||
// camera: View<Camera>,
|
program: NonSendSync<UniqueView<BasicColoredShaderPrefab>>,
|
||||||
// ) {
|
camera: View<Camera>,
|
||||||
// for (&position, chunk) in &chunks.chunks {
|
settings: UniqueView<GameSettings>,
|
||||||
// let world_position = position.as_vec3() * CHUNK_SIZE as f32;
|
) {
|
||||||
// target.0.draw(
|
if !settings.debug_draw_current_chunk_border {
|
||||||
// &buffers.0,
|
return
|
||||||
// &buffers.1,
|
}
|
||||||
// &program.0,
|
let camera = camera.iter().next().expect("No cameras in the scene");
|
||||||
// &uniform! {
|
let view = camera.view_matrix.to_cols_array_2d();
|
||||||
// position_offset: world_position.to_array(),
|
let perspective = camera.perspective_matrix.to_cols_array_2d();
|
||||||
// view: view,
|
let (_, &player_transform) = (&player, &transforms).iter().next().expect("No player");
|
||||||
// perspective: perspective,
|
let (_, _, player_position) = player_transform.0.to_scale_rotation_translation();
|
||||||
// tex: texture_sampler,
|
let player_in_chunk = ivec3(
|
||||||
// },
|
(player_position.x as i32).div_euclid(CHUNK_SIZE as i32),
|
||||||
// &draw_parameters
|
(player_position.y as i32).div_euclid(CHUNK_SIZE as i32),
|
||||||
// ).unwrap();
|
(player_position.z as i32).div_euclid(CHUNK_SIZE as i32),
|
||||||
// }
|
);
|
||||||
// }
|
let world_position = player_in_chunk.as_vec3() * CHUNK_SIZE as f32;
|
||||||
|
target.0.draw(
|
||||||
|
&buffers.0,
|
||||||
|
&buffers.1,
|
||||||
|
&program.0,
|
||||||
|
&uniform! {
|
||||||
|
model: Mat4::from_scale_rotation_translation(
|
||||||
|
Vec3::splat(CHUNK_SIZE as f32),
|
||||||
|
Quat::default(),
|
||||||
|
world_position
|
||||||
|
).to_cols_array_2d(),
|
||||||
|
color: [0.25f32; 4],
|
||||||
|
view: view,
|
||||||
|
perspective: perspective,
|
||||||
|
},
|
||||||
|
&DrawParameters {
|
||||||
|
depth: Depth {
|
||||||
|
test: DepthTest::IfLess,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
blend: Blend::alpha_blending(),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
).unwrap();
|
||||||
|
target.0.draw(
|
||||||
|
&buffers.0,
|
||||||
|
&buffers.1,
|
||||||
|
&program.0,
|
||||||
|
&uniform! {
|
||||||
|
model: Mat4::from_scale_rotation_translation(
|
||||||
|
Vec3::splat(CHUNK_SIZE as f32),
|
||||||
|
Quat::default(),
|
||||||
|
world_position
|
||||||
|
).to_cols_array_2d(),
|
||||||
|
color: [0.0f32; 4],
|
||||||
|
view: view,
|
||||||
|
perspective: perspective,
|
||||||
|
},
|
||||||
|
&DrawParameters {
|
||||||
|
polygon_mode: PolygonMode::Point,
|
||||||
|
line_width: Some(2.),
|
||||||
|
point_size: Some(5.),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
).unwrap();
|
||||||
|
}
|
||||||
|
|
|
@ -5,14 +5,14 @@ pub struct GameSettings {
|
||||||
/// there's a 1 chunk border of loaded but invisible around this
|
/// there's a 1 chunk border of loaded but invisible around this
|
||||||
pub render_distance: u8,
|
pub render_distance: u8,
|
||||||
pub mouse_sensitivity: f32,
|
pub mouse_sensitivity: f32,
|
||||||
pub debug_draw_chunk_border: bool,
|
pub debug_draw_current_chunk_border: bool,
|
||||||
}
|
}
|
||||||
impl Default for GameSettings {
|
impl Default for GameSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
render_distance: 5,
|
render_distance: 5,
|
||||||
mouse_sensitivity: 1.,
|
mouse_sensitivity: 1.,
|
||||||
debug_draw_chunk_border: cfg!(debug_assertions),
|
debug_draw_current_chunk_border: cfg!(debug_assertions),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue