Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Music #111

Merged
merged 23 commits into from
Oct 17, 2023
Merged

Music #111

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c243f0a
Music
AnthonyTornetta May 28, 2023
ab21a6d
Merge branch 'main' into 102-add-background-music
AnthonyTornetta Oct 13, 2023
46fdba4
Updated music to new bevy version
AnthonyTornetta Oct 13, 2023
89e9819
Moved sounds folder to cosmos assets folder
AnthonyTornetta Oct 13, 2023
64a3d9a
Added basic volume resource
AnthonyTornetta Oct 13, 2023
ecaa6af
Music now plays when you change sectors
AnthonyTornetta Oct 14, 2023
08d5a63
Decluttered client main
AnthonyTornetta Oct 14, 2023
0e234ee
Ship now plays audio
AnthonyTornetta Oct 15, 2023
e0683a2
Replaced kira's spacial audio with custom spacial audio
AnthonyTornetta Oct 15, 2023
0e781fb
Fixed ship movement not by client-side synced
AnthonyTornetta Oct 16, 2023
c45c2f1
Added sound on braking
AnthonyTornetta Oct 16, 2023
70bce1e
Removed print
AnthonyTornetta Oct 16, 2023
1b9b3dd
Braking makes sound
AnthonyTornetta Oct 16, 2023
3cec398
Made audio fade out on removal
AnthonyTornetta Oct 16, 2023
e16dfb6
Fixed audio not always stopping
AnthonyTornetta Oct 16, 2023
1625de8
Abstracted asset loading to be less mistake-prone
AnthonyTornetta Oct 16, 2023
3e94ff6
Added cool laser sound effects
AnthonyTornetta Oct 16, 2023
23648c7
Killed warning
AnthonyTornetta Oct 16, 2023
5e56696
README updates
AnthonyTornetta Oct 16, 2023
343650d
Removed some temp placement files
AnthonyTornetta Oct 16, 2023
0ff5c2d
Merge branch 'main' into 102-add-background-music
AnthonyTornetta Oct 17, 2023
478ff9a
Docs
AnthonyTornetta Oct 17, 2023
6947e34
Cargo clippy
AnthonyTornetta Oct 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,514 changes: 748 additions & 766 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = ["cosmos_client", "cosmos_core", "cosmos_server"]
resolver = "2"

[workspace.dependencies]
bevy = "0.11.2"
bevy = { version = "0.11.2", default-features = false }
bevy_rapier3d = { git = "/~https://github.com/AnthonyTornetta/bevy_rapier/", version = "0.22.0", features = [
"simd-stable",
"serde-serialize",
Expand All @@ -18,13 +18,13 @@ serde_json = "1.0.107"
bincode = "1.3.3"
noise = "0.8.2"

rand = "0.8.5"
rand = "0.8.5" # Check out https://crates.io/crates/tinyrand in future
rand_chacha = "0.3.1"
bigdecimal = "0.4.1"
rayon = "1.7.0"
rayon = "1.8.0"
futures-lite = "1.13.0"

local-ip-address = "0.5.5"
local-ip-address = "0.5.6"

image = { version = "0.24.7", default-features = false, features = ["png"] }

Expand All @@ -36,9 +36,11 @@ renet_visualizer = { version = "0.0.6", features = ["bevy"] }

walkdir = "2.4.0"

toml = "0.8.0"
toml = "0.8.2"
lz4_flex = "0.11.1"

bevy_kira_audio = "0.17.0"

# For any non workspace package
[profile.dev.package."*"]
opt-level = 3
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,25 @@ See [the issues page](/~https://github.com/AnthonyTornetta/Cosmos/issues) for the
- [ ] Lit up underground blocks
- [ ] Animated textures
- [ ] Sounds
- [ ] Laser cannon fire
- [x] Laser cannon fire
- [ ] Block take damage
- [ ] Thrusters moving
- [x] Thrusters moving
- [ ] Space ship idle
- [ ] Background space music
- [x] Background space music
- [ ] Block break
- [ ] Place rotated blocks
- [ ] Multiblock machines (if enough time)
- [ ] Revamp power generation to use reactor multiblock structure
- [ ] Colored laser
- [ ] Colored glass placed in front of laser
- [ ] Inventory GUI
- [ ] Able to open inventory
- [ ] Abstract the 3d block GUI camera
- [ ] Fix the 3d block GUI camera to not render anything except GUI blocks
- [x] Inventory GUI
- [x] Able to open inventory
- [x] Abstract the 3d block GUI camera
- [x] Fix the 3d block GUI camera to not render anything except GUI blocks
- [ ] Fix seeing through cracks in blocks
- [x] Update to bevy 0.11
- [x] Update physics
- [x] Update bevy

## Release 0.0.4a
- [x] Galaxy Generation
Expand Down
28 changes: 28 additions & 0 deletions cosmos_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
# Bevy defaults minus audio and some other not needed things
# see /~https://github.com/bevyengine/bevy/blob/main/Cargo.toml#L31-L54
# from /~https://github.com/NiklasEi/bevy_game_template/blob/main/Cargo.toml
default = [
"bevy/animation",
"bevy/bevy_asset",
"bevy/bevy_scene",
"bevy/bevy_winit",
"bevy/bevy_core_pipeline",
"bevy/bevy_pbr",
"bevy/bevy_gltf",
"bevy/bevy_render",
"bevy/bevy_sprite",
"bevy/bevy_text",
"bevy/bevy_ui",
"bevy/png",
"bevy/hdr",
"bevy/zstd",
"bevy/x11",
"bevy/ktx2",
"bevy/filesystem_watcher",
"bevy/tonemapping_luts",
]

[dependencies]
cosmos_core = { version = "0.0.5", path = "../cosmos_core", features = [
"client",
Expand All @@ -23,6 +48,9 @@ image = { workspace = true }

bevy-inspector-egui = { workspace = true }

rand = { workspace = true }
rand_chacha = { workspace = true }
rayon = { workspace = true }
bevy_kira_audio = { workspace = true }

toml = { workspace = true }
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
94 changes: 94 additions & 0 deletions cosmos_client/src/asset/asset_loader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//! Loads assets based on the path in the given game state. Will call the done callback once everything is finished loading.

use std::marker::PhantomData;

use bevy::{
asset::{Asset, LoadState},
prelude::{in_state, App, AssetServer, Commands, EventWriter, Handle, IntoSystemConfigs, OnEnter, Res, ResMut, Resource, Update},
};
use cosmos_core::loader::{AddLoadingEvent, DoneLoadingEvent, LoadingManager};

use crate::state::game_state::GameState;

#[derive(Resource, Default)]
struct LoadingAssetHandle<T: Asset, K: Send + Sync + 'static> {
_phantom: PhantomData<K>,
loading_handles: Vec<Handle<T>>,
loading_id: usize,
}

#[derive(Resource, Default)]
struct DoneLoadingAssetHandle<T: Asset + 'static, K: Send + Sync + 'static> {
_phantom: PhantomData<K>,
loaded_handles: Vec<(Handle<T>, LoadState)>,
}

/// Loads assets based on the path in the given game state. Will call the done callback once everything is finished loading.
///
/// Failed handles will also be sent to the done callback, but their LoadState will indicate if they succeeded or not
///
/// Usage: [`load_assets<AssetType, AnyMarkerType>`]
///
/// The marker type is to differentiate this loading call from other loading calls, even if it's loading the same asset type.
/// You can just make a throw-away zero-sized struct for this, just make sure it's not being used by any other load_assets call in the same state.
pub fn load_assets<T: Asset, K: Send + Sync + 'static>(
app: &mut App,
state: GameState,
paths: Vec<&'static str>,
done: impl Fn(Commands, Vec<(Handle<T>, LoadState)>) + Send + Sync + 'static,
) {
let prepare_assets = move |asset_server: Res<AssetServer>,
mut commands: Commands,
mut loader: ResMut<LoadingManager>,
mut event_writer: EventWriter<AddLoadingEvent>| {
let id = loader.register_loader(&mut event_writer);

let handles = paths.iter().map(|x| asset_server.load(*x)).collect::<Vec<Handle<T>>>();

commands.insert_resource(LoadingAssetHandle::<T, K> {
loading_handles: handles,
loading_id: id,
_phantom: Default::default(),
});
};

let check_assets_done_loading = move |loading_assets: Option<ResMut<LoadingAssetHandle<T, K>>>,
done_loading: Option<ResMut<DoneLoadingAssetHandle<T, K>>>,
asset_server: Res<AssetServer>,
mut commands: Commands,
mut loader: ResMut<LoadingManager>,
mut end_writer: EventWriter<DoneLoadingEvent>| {
if let Some(mut loading_assets) = loading_assets {
let mut done_loading = done_loading.expect("This must exist if loading exists.");

loading_assets.loading_handles.retain_mut(|handle| {
let load_state = asset_server.get_load_state(handle.id());
if load_state == LoadState::Loaded || load_state == LoadState::Failed {
done_loading.loaded_handles.push((std::mem::take(handle), load_state));
false
} else {
true
}
});

if loading_assets.loading_handles.is_empty() {
commands.remove_resource::<LoadingAssetHandle<T, K>>();
loader.finish_loading(loading_assets.loading_id, &mut end_writer);

done(commands, std::mem::take(&mut done_loading.loaded_handles));
}
}
};

app.add_systems(OnEnter(state), prepare_assets)
.add_systems(Update, check_assets_done_loading.run_if(in_state(state)))
.insert_resource(LoadingAssetHandle::<T, K> {
_phantom: Default::default(),
loading_handles: Default::default(),
loading_id: Default::default(),
})
.insert_resource(DoneLoadingAssetHandle::<T, K> {
_phantom: Default::default(),
loaded_handles: Default::default(),
});
}
1 change: 1 addition & 0 deletions cosmos_client/src/asset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use bevy::prelude::App;

pub mod asset_loader;
pub mod asset_loading;

pub(super) fn register(app: &mut App) {
Expand Down
Loading