Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamkob12 committed Sep 27, 2023
1 parent df8cb7c commit 499ba0b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/add_break_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn add_break_detector(
change: VoxelChange::Added,
blocks: blocks_in_the_way(pos, forward, REACH_DISTANCE)
.iter()
.skip(1)
.map(|&(x, y, z)| {
let tmp = one_d_cords(y, CHUNK_DIMS);
if let Some(block) = get_neighbor(tmp, z, CHUNK_DIMS) {
Expand Down
55 changes: 17 additions & 38 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::utils::three_d_cords;

// const FACTOR: usize = CHUNK_DIMS.0;
// Render distance should be above 1.
pub const RENDER_DISTANCE: i32 = 8;
pub const RENDER_DISTANCE: i32 = 10;
pub const GEN_SEED: u32 = 5;
const CROSSHAIR_SIZE: f32 = 36.0;

Expand All @@ -55,7 +55,18 @@ struct LoadedChunks(usize);

fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest()));
app.add_plugins(
DefaultPlugins
.set(ImagePlugin::default_nearest())
.set(WindowPlugin {
primary_window: Some(Window {
resizable: false,
mode: bevy::window::WindowMode::BorderlessFullscreen,
..Default::default()
}),
..Default::default()
}),
);
app.add_plugins(AtmospherePlugin);
app.add_plugins(PlayerPlugin);

Expand Down Expand Up @@ -96,8 +107,8 @@ fn main() {
add_break_detector,
),
);
app.add_systems(Update, spawn_and_despawn_chunks);
app.add_systems(Update, handle_block_break_place);
app.add_systems(PreUpdate, spawn_and_despawn_chunks);
app.add_systems(PostUpdate, handle_block_break_place);

app.run();
}
Expand All @@ -108,7 +119,6 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
meshes: ResMut<Assets<Mesh>>,
asset_server: Res<AssetServer>,
primary_window: Query<&Window, With<PrimaryWindow>>,
) {
let noise = Perlin::new(GEN_SEED);
let texture_handle: Handle<Image> = asset_server.load("UV_map_example.png");
Expand All @@ -119,31 +129,6 @@ fn setup(
});
commands.insert_resource(BlockMaterial(mat));
commands.spawn(LoadedChunks(0));
let mut window_width = CROSSHAIR_SIZE;
let mut window_height = CROSSHAIR_SIZE;
if let Ok(window) = primary_window.get_single() {
(window_width, window_height) = (window.resolution.width(), window.resolution.height());
} else {
warn!("Primary window not found ");
}

commands.spawn(
TextBundle::from_section(
format!("+"),
TextStyle {
font_size: CROSSHAIR_SIZE,
color: Color::LIME_GREEN,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
align_items: AlignItems::Center,
top: Val::Px(window_height / 2.0 - CROSSHAIR_SIZE / 2.0),
left: Val::Px(window_width / 2.0 - CROSSHAIR_SIZE / 2.0),
..default()
}),
);
}

fn frame_chunk_update(
Expand Down Expand Up @@ -255,9 +240,6 @@ fn handle_tasks(
cords,
meta_data: metadata,
},
BlockChangeQueue {
block_queue: vec![],
},
))
.id();
chunk_map.insert_ent(cords, ent);
Expand All @@ -268,7 +250,7 @@ fn handle_tasks(
if loaded_chunks.0 == (RENDER_DISTANCE * RENDER_DISTANCE) as usize {
next_state.set(InitialChunkLoadState::MeshesLoaded);
commands.entity(counter_ent).despawn();
println!("\nInternal Log:\nMeshes have been loaded");
info!("\nInternal Log:\nMeshes have been loaded");
}
}
_ => {}
Expand All @@ -290,7 +272,7 @@ fn check_if_loaded(
}
}
next_state.set(InitialChunkLoadState::Complete);
println!("\nInternal Log:\nChunk entities have been successfully spawned");
info!("\nInternal Log:\nChunk entities have been successfully spawned");
}

// Whoever reads this funtion sometime in the future, Please forgive me.
Expand Down Expand Up @@ -349,11 +331,9 @@ fn handle_block_break_place(
};

if vox == AIR && matches!(event.change, VoxelChange::Broken) {
println!("hey2");
continue 'A;
}
if (onto == AIR || vox != AIR) && matches!(event.change, VoxelChange::Added) {
println!("hey2");
if onto != AIR {
break 'A;
}
Expand All @@ -380,7 +360,6 @@ fn handle_block_break_place(
VoxelChange::Broken => c.grid[block] = AIR,
}

println!("hey3");
commands.entity(e).insert(ToUpdate);
break 'A;
}
Expand Down
8 changes: 5 additions & 3 deletions src/player.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::f32::consts::PI;

// CREDIT TO bevy_flycam
// ~~~~~~~~~~~~~~~~~~~
// I copied this code because the 0.11 port wasn't on crates.io
Expand Down Expand Up @@ -31,8 +33,8 @@ pub struct MovementSettings {
impl Default for MovementSettings {
fn default() -> Self {
Self {
sensitivity: 0.00012,
speed: 18.,
sensitivity: 0.00008,
speed: 10.,
}
}
}
Expand Down Expand Up @@ -109,7 +111,7 @@ fn setup_player(mut commands: Commands) {
},
FlyCam,
CurrentChunk([0, 0]),
AtmosphereCamera::default(),
// AtmosphereCamera::default(),
));
}

Expand Down
26 changes: 25 additions & 1 deletion src/sky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::*;
use bevy::prelude::*;
use bevy_atmosphere::prelude::*;

pub fn setup_light(mut commands: Commands) {
pub fn setup_light(mut commands: Commands, primary_window: Query<&Window, With<PrimaryWindow>>) {
// commands.insert_resource(AtmosphereModel::new(Nishita {
// sun_position: Vec3::new(0., 1., -1.),
// sun_intensity: 10.0,
Expand All @@ -19,6 +19,30 @@ pub fn setup_light(mut commands: Commands) {
},
Sun,
));
let mut window_width = CROSSHAIR_SIZE;
let mut window_height = CROSSHAIR_SIZE;
if let Ok(window) = primary_window.get_single() {
(window_width, window_height) = (window.resolution.width(), window.resolution.height());
} else {
warn!("Primary window not found ");
}
commands.spawn(
TextBundle::from_section(
format!("+"),
TextStyle {
font_size: CROSSHAIR_SIZE,
color: Color::LIME_GREEN,
..default()
},
)
.with_style(Style {
position_type: PositionType::Absolute,
align_items: AlignItems::Center,
top: Val::Px(window_height / 2.0 - CROSSHAIR_SIZE / 2.0),
left: Val::Px(window_width / 2.0 - CROSSHAIR_SIZE / 2.0),
..default()
}),
);
}

#[derive(Component)]
Expand Down

0 comments on commit 499ba0b

Please sign in to comment.