From 56c23ee761d537e4b68d04884aa16fbbe840db60 Mon Sep 17 00:00:00 2001 From: Philip Linden Date: Fri, 22 Nov 2024 01:30:30 -0500 Subject: [PATCH] mod: remove the assets module for now --- src/assets.rs | 43 ------------------------------------- src/lib.rs | 3 --- src/simulator/properties.rs | 26 ++++++++++++++++------ 3 files changed, 20 insertions(+), 52 deletions(-) delete mode 100644 src/assets.rs diff --git a/src/assets.rs b/src/assets.rs deleted file mode 100644 index 36a59b6..0000000 --- a/src/assets.rs +++ /dev/null @@ -1,43 +0,0 @@ -use bevy::prelude::*; -use bevy_common_assets::ron::RonAssetPlugin; -use serde::Deserialize; - -use crate::{ - simulator::{balloon::BalloonMaterial, gas::GasSpecies}, - AppState, -}; - -/// Configuration for the properties of gases and materials. -#[derive(Asset, Debug, Deserialize, TypePath)] -pub struct PropertiesConfig { - pub gases: Vec, - pub materials: Vec, -} - -impl Default for PropertiesConfig { - fn default() -> Self { - Self { gases: vec![], materials: vec![] } - } -} - -/// Plugin for loading configuration. -pub struct ConfigLoaderPlugin; - -impl Plugin for ConfigLoaderPlugin { - fn build(&self, app: &mut App) { - app.add_plugins(RonAssetPlugin::::new(&["ron"])) - .insert_resource(PropertiesConfig::default()) - .add_systems( - Startup, - load_configs, - ); - } -} - -/// Loads the configuration and transitions to the Running state. -fn load_configs(asset_server: Res, mut commands: Commands) { - info!("Setting up configuration loader"); - let handle = asset_server.load("configs/properties.ron"); - commands.insert_resource(handle.clone()); - info!("Configuration loader setup complete"); -} diff --git a/src/lib.rs b/src/lib.rs index 1000bcb..80f997b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,9 +2,6 @@ mod app3d; mod controls; mod simulator; -#[cfg(feature = "config-files")] -mod assets; - use bevy::{asset::AssetMetaCheck, prelude::*}; pub struct YahsPlugin; diff --git a/src/simulator/properties.rs b/src/simulator/properties.rs index 038e26d..4117843 100644 --- a/src/simulator/properties.rs +++ b/src/simulator/properties.rs @@ -4,10 +4,13 @@ use std::ops::{Add, Div, Mul, Sub}; -use avian3d::{math::{Scalar, PI}, prelude::{ColliderDensity, ColliderMassProperties, PhysicsSet, RigidBody}}; +use avian3d::{ + math::{Scalar, PI}, + prelude::{ColliderDensity, ColliderMassProperties, PhysicsSet, RigidBody}, +}; use bevy::{prelude::*, reflect::Reflect}; #[cfg(feature = "config-files")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; pub const BOLTZMANN_CONSTANT: f32 = 1.38e-23_f32; // [J/K] pub const AVOGADRO_CONSTANT: f32 = 6.022e+23_f32; // [1/mol] @@ -45,9 +48,14 @@ impl Plugin for CorePropertiesPlugin { app.register_type::(); app.register_type::(); - // Ensure that the Avian density matches our computed density before - // solving physics. - app.add_systems(Update, sync_avian_density.in_set(PhysicsSet::Prepare)); + // Ensure that the Avian density matches our computed mass and density + // before it starts solving physics. + app.add_systems( + Update, + (sync_avian_mass, sync_avian_density) + .chain() + .in_set(PhysicsSet::Prepare), + ); } } @@ -268,7 +276,7 @@ impl Div for Density { } } -fn sync_avian_density(mut densities: Query<(&mut ColliderDensity, &Volume, &Mass), With>) { +fn sync_avian_density(mut densities: Query<(&mut ColliderDensity, &Volume, &Mass)>) { for (mut density, volume, mass) in densities.iter_mut() { let our_density = mass.kg() / volume.m3(); density.0 = our_density; @@ -334,6 +342,12 @@ impl Div for Mass { } } +fn sync_avian_mass(mut bodies: Query<(&mut ColliderMassProperties, &Mass)>) { + for (mut mass_props, mass) in bodies.iter_mut() { + mass_props.mass.0 = mass.0; + } +} + /// Molar mass (kg/mol) of a substance. #[derive(Component, Debug, Default, Clone, Copy, PartialEq, Reflect)] #[cfg_attr(feature = "config-files", derive(Serialize, Deserialize))]