Skip to content

Commit

Permalink
Update to Bevy 0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qhdwight committed Jul 15, 2023
1 parent e607480 commit dae32cd
Show file tree
Hide file tree
Showing 8 changed files with 940 additions and 670 deletions.
1,329 changes: 801 additions & 528 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ edition = "2021"

[dependencies]
anyhow = "1.0.4"
bevy = { version = "0.10.0", features = ["serialize"] }
bevy_rapier3d = { version = "0.21.0", features = ["enhanced-determinism", "debug-render"] }
bevy = { version = "0.11.0", features = ["serialize"] }
bevy_rapier3d = { version = "0.22.0", features = ["enhanced-determinism", "debug-render"] }
bytemuck = "1.7"
ron = "0.8.0"
toml = "0.5.9"
flagset = "0.4.3"
serde = "1.0.149"
smartstring = { version = "1.0.1", features = ["serde"] }
wgpu = "0.15.0"
wgpu = "0.16.0"

[profile.dev]
opt-level = 1
Expand Down
6 changes: 3 additions & 3 deletions assets/default.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ key_back = "S"
key_left = "A"
key_right = "D"
key_up = "Space"
key_down = "LControl"
key_sprint = "LShift"
key_down = "ControlLeft"
key_sprint = "ShiftLeft"
key_jump = "Space"
key_crouch = "LControl"
key_crouch = "ControlLeft"
key_fly = "F"
key_reload = "R"
key_fire = "Q"
Binary file removed assets/fonts/FiraMono-Medium.ttf
Binary file not shown.
85 changes: 32 additions & 53 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ extern crate core;
use std::{
f32::consts::TAU,
fmt::Write,
time::Duration,
};

use bevy::{
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
asset::ChangeWatcher,
diagnostic::DiagnosticsStore,
diagnostic::FrameTimeDiagnosticsPlugin,
ecs::schedule::ScheduleLabel,
prelude::*,
prelude::shape::Cube,
render::{
Expand Down Expand Up @@ -44,24 +48,30 @@ fn main() {
color: Color::WHITE,
brightness: 0.25,
})
.add_plugins(DefaultPlugins.set(AssetPlugin {
watch_for_changes: true,
..default()
}))
.insert_resource(RapierConfiguration {
..default()
})
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugin(RapierDebugRenderPlugin::default())
.add_plugin(VoxelsPlugin)
.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(InventoryPlugin)
.add_plugins((
DefaultPlugins.set(AssetPlugin {
watch_for_changes: Some(ChangeWatcher {
delay: Duration::from_millis(100),
}),
..default()
}),
RapierPhysicsPlugin::<NoUserData>::default(),
VoxelsPlugin,
FrameTimeDiagnosticsPlugin::default(),
InventoryPlugin,
))
.add_asset::<Config>()
.init_asset_loader::<ConfigAssetLoader>()
.add_startup_systems((setup_sys, spawn_ui_sys, spawn_voxel_sys, spawn_player_sys))
.add_systems((player_input_system.in_base_set(CoreSet::PreUpdate), cursor_grab_sys, update_fps_text_sys))
.add_systems((player_look_sys, player_move_sys, modify_equip_state_sys, modify_item_sys, item_pickup_sys).chain().in_set(PlayerSet::Logic))
.add_systems((item_pickup_animate_sys, render_player_camera_sys, render_inventory_sys, update_hud_system).chain().in_set(PlayerSet::Render))
.add_systems(Startup, (setup_sys, spawn_ui_sys, spawn_voxel_sys, spawn_player_sys))
.add_systems(PreUpdate, player_input_system)
.add_systems(Update, (
(cursor_grab_sys, update_fps_text_sys),
(player_look_sys, player_move_sys, modify_equip_state_sys, modify_item_sys, item_pickup_sys).chain().in_set(PlayerSet::Logic),
(item_pickup_animate_sys, render_player_camera_sys, render_inventory_sys, update_hud_system).chain().in_set(PlayerSet::Render),
))
.run();
}

Expand Down Expand Up @@ -140,26 +150,21 @@ fn setup_sys(
commands.insert_resource(DefaultMaterials { gun_material });
}

fn spawn_ui_sys(asset_server: Res<AssetServer>, mut commands: Commands) {
let font = asset_server.load("fonts/FiraMono-Medium.ttf");

fn spawn_ui_sys(mut commands: Commands) {
commands
.spawn(TextBundle {
style: Style {
align_self: AlignSelf::FlexEnd,
position_type: PositionType::Absolute,
position: UiRect {
top: Val::Px(5.0),
right: Val::Px(5.0),
..default()
},
top: Val::Px(5.0),
left: Val::Px(5.0),
..default()
},
text: Text {
sections: vec![
TextSection {
value: "".to_string(),
style: TextStyle { font: font.clone(), font_size: 16.0, color: Color::WHITE },
style: TextStyle { font_size: 16.0, color: Color::WHITE, ..default() },
},
],
..default()
Expand All @@ -173,18 +178,15 @@ fn spawn_ui_sys(asset_server: Res<AssetServer>, mut commands: Commands) {
style: Style {
align_self: AlignSelf::FlexEnd,
position_type: PositionType::Absolute,
position: UiRect {
bottom: Val::Px(5.0),
left: Val::Px(5.0),
..default()
},
bottom: Val::Px(5.0),
left: Val::Px(5.0),
..default()
},
text: Text {
sections: vec![
TextSection {
value: "".to_string(),
style: TextStyle { font: font.clone(), font_size: 12.0, color: Color::ANTIQUE_WHITE },
style: TextStyle { font_size: 12.0, color: Color::ANTIQUE_WHITE, ..default() },
},
],
..default()
Expand Down Expand Up @@ -250,31 +252,8 @@ fn spawn_player_sys(mut commands: Commands) {
commands.spawn((Camera3dBundle::default(), RenderPlayer(0)));
}

#[derive(Resource)]
pub struct Buffers {
// Place edge table and triangle table in uniform buffer
// They are too large to have inline in the shader
edge_table: Buffer,
tri_table: Buffer,
points: BufVec<Vec2>,
heights: BufVec<f32>,
voxels: Buffer,
voxels_staging: Buffer,
vertices: BufVec<Vec4>,
normals: BufVec<Vec4>,
uvs: BufVec<Vec2>,
indices: BufVec<u32>,
atomics: BufVec<u32>,
atomics_staging: Buffer,
}

struct BindingGroups {
simplex: BindGroup,
voxels: BindGroup,
}

fn update_fps_text_sys(
diagnostics: Res<Diagnostics>,
diagnostics: Res<DiagnosticsStore>,
mut query: Query<&mut Text, With<TopRightText>>,
) {
for mut text in query.iter_mut() {
Expand Down
7 changes: 4 additions & 3 deletions src/qgame/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy::{
asset::{AssetLoader, LoadContext, LoadedAsset},
input::mouse::MouseMotion,
prelude::*,
reflect::TypePath,
reflect::TypeUuid,
utils::BoxedFuture,
};
Expand All @@ -30,7 +31,7 @@ pub struct PlayerInput {
pub wanted_item_slot: Option<u8>,
}

#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, TypeUuid)]
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, TypeUuid, TypePath)]
#[uuid = "9ac18a62-063a-4fa1-9575-d295ce69997b"]
pub struct Config {
pub sensitivity: f32,
Expand Down Expand Up @@ -62,10 +63,10 @@ impl Default for Config {
key_right: KeyCode::D,
key_up: KeyCode::Q,
key_down: KeyCode::E,
key_sprint: KeyCode::LShift,
key_sprint: KeyCode::ShiftLeft,
key_jump: KeyCode::Space,
key_fly: KeyCode::F,
key_crouch: KeyCode::LControl,
key_crouch: KeyCode::ControlLeft,
key_fire: KeyCode::Q,
sensitivity: 0.5,
key_reload: KeyCode::R,
Expand Down
7 changes: 4 additions & 3 deletions src/qgame/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
use bevy::{
asset::{AssetLoader, LoadContext, LoadedAsset},
prelude::*,
reflect::TypePath,
reflect::TypeUuid,
utils::{BoxedFuture, HashMap},
};
Expand Down Expand Up @@ -34,7 +35,7 @@ pub struct ItemStateProps {
pub is_persistent: bool,
}

#[derive(Serialize, Deserialize, TypeUuid)]
#[derive(Serialize, Deserialize, TypeUuid, TypePath)]
#[uuid = "2cc54620-95c6-4522-b40e-0a4991ebae5f"]
pub struct ItemProps {
pub name: ItemName,
Expand All @@ -43,15 +44,15 @@ pub struct ItemProps {
pub equip_states: HashMap<EquipStateName, ItemStateProps>,
}

#[derive(Serialize, Deserialize, TypeUuid)]
#[derive(Serialize, Deserialize, TypeUuid, TypePath)]
#[uuid = "46e9c7af-27c2-4560-86e7-df48f9e84729"]
pub struct WeaponProps {
pub damage: u16,
pub headshot_factor: f32,
pub item_props: ItemProps,
}

#[derive(Serialize, Deserialize, TypeUuid)]
#[derive(Serialize, Deserialize, TypeUuid, TypePath)]
#[uuid = "df56751c-7560-420d-b480-eb8fb6f9b9bf"]
pub struct GunProps {
pub mag_size: u16,
Expand Down
Loading

0 comments on commit dae32cd

Please sign in to comment.