Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ Before submitting a pull request:

2. **Follow Code Standards:** Ensure your code adheres to LP's coding standards.

3. **Provide Unit Tests:** Include relevant unit tests for new features or changes.
3. **Run Local Checks:** Before opening a pull request, run `cargo fmt`, `cargo clippy --workspace`, and `cargo test --workspace` so CI time stays focused on regressions instead of formatting or lint fixes.

4. **Document Changes:** Update documentation to reflect any modifications made.
4. **Provide Unit Tests:** Include relevant unit tests for new features or changes.

5. **Document Changes:** Update documentation to reflect any modifications made.

## Communicating with Developers

Expand Down
23 changes: 11 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ on:
pull_request:
branches: [main]

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
DEBIAN_FRONTEND: noninteractive

jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
timeout-minutes: 25
timeout-minutes: 30
steps:
- name: Free disk space
run: sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /usr/local/share/boost
Expand All @@ -28,13 +32,13 @@ jobs:
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: test-suite
shared-key: workspace

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev clang lld
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev clang lld

- name: Quick check
run: cargo check --workspace
Expand All @@ -51,7 +55,7 @@ jobs:
clippy:
name: Clippy
runs-on: ubuntu-latest
timeout-minutes: 25
timeout-minutes: 30
steps:
- name: Free disk space
run: sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /usr/local/share/boost
Expand All @@ -62,15 +66,15 @@ jobs:
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: clippy-lint
shared-key: workspace

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev clang lld
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev clang lld

- name: Run clippy
run: cargo clippy --workspace -- -A clippy::upper-case-acronyms -A clippy::manual-flatten -A clippy::excessive-precision -A clippy::too-many-arguments
Expand All @@ -83,15 +87,10 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4

- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: format-check

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Check formatting
run: cargo fmt --all -- --check
run: cargo fmt --all -- --check
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ forces = { path = "crates/forces" }
information = { path = "crates/information" }
matter = { path = "crates/matter" }

bevy = { version = "0.16", features = ["dynamic_linking"] }
bevy = { version = "0.17", features = ["dynamic_linking"] }

glam = "0.29.2"

Expand All @@ -41,4 +41,4 @@ serde = "1.0"
serde_json = "1.0"

# rand for picking random values
rand = "0.9"
rand = "0.9"
2 changes: 1 addition & 1 deletion crates/energy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ edition = "2024"
description = "Core systems governing how energy manifests, transforms and flows."

[dependencies]
bevy = "0.16"
bevy = "0.17"
6 changes: 4 additions & 2 deletions crates/energy/src/conservation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub enum EnergyType {

/// Component tracking energy in a system
#[derive(Component, Debug, Clone, Copy, Reflect)]
#[reflect(Component)]
pub struct EnergyQuantity {
/// Energy amount in joules
pub value: f32,
Expand Down Expand Up @@ -70,7 +71,7 @@ pub enum TransactionType {
}

/// Event for energy transfers between entities
#[derive(Event, Debug)]
#[derive(Message, Debug)]
pub struct EnergyTransferEvent {
/// Source entity losing energy
pub source: Entity,
Expand All @@ -84,6 +85,7 @@ pub struct EnergyTransferEvent {

/// Component for precise energy accounting
#[derive(Component, Debug, Reflect)]
#[reflect(Component)]
pub struct EnergyAccountingLedger {
/// History of all transactions, newest first
pub transactions: Vec<EnergyTransaction>,
Expand Down Expand Up @@ -244,6 +246,6 @@ impl Plugin for EnergyConservationPlugin {
// Add resources
.init_resource::<EnergyConservationTracker>()
// Add event channel
.add_event::<EnergyTransferEvent>();
.add_message::<EnergyTransferEvent>();
}
}
68 changes: 35 additions & 33 deletions crates/energy/src/electromagnetism/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub const MAGNETIC_CONSTANT_DIV_4PI: f32 = 1e-7;

/// Represents an electric field component
#[derive(Component, Debug, Clone, Copy, Reflect, Default)]
#[reflect(Component)]
pub struct ElectricField {
/// Magnitude and direction of the electric field
pub field: Vec2,
Expand Down Expand Up @@ -52,6 +53,7 @@ impl ElectricField {

/// Represents a magnetic field component
#[derive(Component, Debug, Clone, Copy, Reflect, Default)]
#[reflect(Component)]
pub struct MagneticField {
/// Magnitude and direction of the magnetic field
pub field: Vec2,
Expand Down Expand Up @@ -107,7 +109,7 @@ impl MagneticField {
}

/// Event for field interactions
#[derive(Event, Debug)]
#[derive(Message, Debug)]
pub struct ElectromagneticFieldInteractionEvent {
/// Source entity generating the field
pub source: Entity,
Expand All @@ -119,45 +121,45 @@ pub struct ElectromagneticFieldInteractionEvent {

/// System for calculating field interactions
pub fn calculate_field_interactions(
mut field_interaction_events: EventWriter<ElectromagneticFieldInteractionEvent>,
mut field_interaction_events: MessageWriter<ElectromagneticFieldInteractionEvent>,
electric_fields: Query<(Entity, &ElectricField)>,
magnetic_fields: Query<(Entity, &MagneticField)>,
) {
// Electric field interactions
for (source_entity, source_field) in electric_fields.iter() {
for (target_entity, target_field) in electric_fields.iter() {
if source_entity == target_entity {
continue;
}

let interaction_strength = source_field.strength() * target_field.strength();

if interaction_strength > f32::EPSILON {
field_interaction_events.write(ElectromagneticFieldInteractionEvent {
source: source_entity,
target: target_entity,
interaction_strength,
});
}
let mut electric_pairs = electric_fields.iter_combinations();
while let Some([(entity_a, field_a), (entity_b, field_b)]) = electric_pairs.fetch_next() {
let interaction_strength = field_a.strength() * field_b.strength();

if interaction_strength > f32::EPSILON {
field_interaction_events.write(ElectromagneticFieldInteractionEvent {
source: entity_a,
target: entity_b,
interaction_strength,
});
field_interaction_events.write(ElectromagneticFieldInteractionEvent {
source: entity_b,
target: entity_a,
interaction_strength,
});
}
}

// Magnetic field interactions (similar logic)
for (source_entity, source_field) in magnetic_fields.iter() {
for (target_entity, target_field) in magnetic_fields.iter() {
if source_entity == target_entity {
continue;
}

let interaction_strength = source_field.strength() * target_field.strength();

if interaction_strength > f32::EPSILON {
field_interaction_events.write(ElectromagneticFieldInteractionEvent {
source: source_entity,
target: target_entity,
interaction_strength,
});
}
let mut magnetic_pairs = magnetic_fields.iter_combinations();
while let Some([(entity_a, field_a), (entity_b, field_b)]) = magnetic_pairs.fetch_next() {
let interaction_strength = field_a.strength() * field_b.strength();

if interaction_strength > f32::EPSILON {
field_interaction_events.write(ElectromagneticFieldInteractionEvent {
source: entity_a,
target: entity_b,
interaction_strength,
});
field_interaction_events.write(ElectromagneticFieldInteractionEvent {
source: entity_b,
target: entity_a,
interaction_strength,
});
}
}
}
Expand All @@ -172,7 +174,7 @@ impl Plugin for ElectromagneticFieldPlugin {
.register_type::<ElectricField>()
.register_type::<MagneticField>()
// Add electromagnetic field interaction event
.add_event::<ElectromagneticFieldInteractionEvent>()
.add_message::<ElectromagneticFieldInteractionEvent>()
// Add system for field interactions
.add_systems(Update, calculate_field_interactions);
}
Expand Down
5 changes: 5 additions & 0 deletions crates/energy/src/electromagnetism/interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ pub struct ElectromagneticWave {

impl ElectromagneticWave {
pub fn new(frequency: f32, direction: Vec2, electric_amplitude: f32, phase: f32) -> Self {
assert!(
frequency > 0.0,
"Electromagnetic wave frequency must be strictly positive"
);

// Calculate wavelength and wave number
let wavelength = C / frequency;
let wave_number = 2.0 * std::f32::consts::PI / wavelength;
Expand Down
2 changes: 1 addition & 1 deletion crates/energy/src/electromagnetism/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Plugin for ElectromagnetismPlugin {
.register_type::<fields::MagneticField>()
.register_type::<interactions::ElectromagneticWave>()
.register_type::<interactions::MaterialProperties>()
.add_event::<fields::ElectromagneticFieldInteractionEvent>()
.add_message::<fields::ElectromagneticFieldInteractionEvent>()
.add_systems(Update, fields::calculate_field_interactions);
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/energy/src/thermodynamics/entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bevy::prelude::*;

/// Entropy component for thermodynamic systems
#[derive(Component, Debug, Clone, Copy, Reflect)]
#[reflect(Component)]
pub struct Entropy {
/// Entropy in J/K
pub value: f32,
Expand All @@ -17,6 +18,7 @@ impl Entropy {

/// Process reversibility characteristic
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Reflect)]
#[reflect(Component)]
pub enum Reversibility {
Reversible,
Irreversible,
Expand Down
2 changes: 2 additions & 0 deletions crates/energy/src/thermodynamics/equilibrium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bevy::prelude::*;

/// Component marking systems in thermal equilibrium
#[derive(Component, Debug, Reflect)]
#[reflect(Component)]
pub struct ThermalEquilibrium {
pub connected_entities: Vec<Entity>,
/// Equilibrium group ID for transitivity tracking
Expand All @@ -12,6 +13,7 @@ pub struct ThermalEquilibrium {
/// and the matter crate is implemented
/// This is a placeholder for the actual phase state representation
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Reflect)]
#[reflect(Component)]
pub enum PhaseState {
Solid,
Liquid,
Expand Down
2 changes: 1 addition & 1 deletion crates/energy/src/thermodynamics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Plugin for ThermodynamicsPlugin {
.register_type::<entropy::Reversibility>()
.register_type::<equilibrium::ThermalEquilibrium>()
.register_type::<equilibrium::PhaseState>()
.add_event::<thermal::ThermalTransferEvent>()
.add_message::<thermal::ThermalTransferEvent>()
.configure_sets(
Update,
(
Expand Down
10 changes: 7 additions & 3 deletions crates/energy/src/thermodynamics/thermal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub const STEFAN_BOLTZMANN: f32 = 5.67e-8; // W/(m²·K⁴)

/// Temperature component for thermal systems
#[derive(Component, Debug, Clone, Copy, Reflect, Default)]
#[reflect(Component)]
pub struct Temperature {
/// Temperature in Kelvin
pub value: f32,
Expand Down Expand Up @@ -36,13 +37,15 @@ impl Temperature {

/// Thermal conductivity property
#[derive(Component, Debug, Clone, Copy, Reflect, Default)]
#[reflect(Component)]
pub struct ThermalConductivity {
/// W/(m·K)
pub value: f32,
}

/// Thermal diffusivity property
#[derive(Component, Debug, Clone, Copy, Reflect, Default)]
#[reflect(Component)]
pub struct ThermalDiffusivity {
/// m²/s
pub value: f32,
Expand All @@ -63,6 +66,7 @@ impl ThermalDiffusivity {

/// Emissivity property for radiation calculations
#[derive(Component, Debug, Clone, Copy, Reflect, Default)]
#[reflect(Component)]
pub struct Emissivity {
/// Dimensionless value between 0.0 and 1.0
/// 0.0 = perfect reflector, 1.0 = perfect emitter (black body)
Expand All @@ -78,7 +82,7 @@ impl Emissivity {
}

/// Event for thermal energy transfer between entities
#[derive(Event, Debug)]
#[derive(Message, Debug)]
pub struct ThermalTransferEvent {
/// Source entity losing thermal energy
pub source: Entity,
Expand All @@ -90,7 +94,7 @@ pub struct ThermalTransferEvent {

/// System for calculating heat conduction between entities
pub fn calculate_thermal_transfer(
mut thermal_transfer_events: EventWriter<ThermalTransferEvent>,
mut thermal_transfer_events: MessageWriter<ThermalTransferEvent>,
query: Query<(Entity, &Temperature, &ThermalConductivity)>,
) {
// Use query.iter_combinations() to efficiently compare all entities
Expand Down Expand Up @@ -157,7 +161,7 @@ impl Plugin for ThermalSystemPlugin {
.register_type::<ThermalDiffusivity>()
.register_type::<Emissivity>()
// Add thermal transfer event channel
.add_event::<ThermalTransferEvent>()
.add_message::<ThermalTransferEvent>()
// Add system for thermal calculations
.add_systems(Update, calculate_thermal_transfer);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/energy/src/waves/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Plugin for WavesPlugin {
.register_type::<propagation::WaveCenterMarker>()
.register_type::<superposition::StandingWaveMarker>()
.register_type::<wave_equation::WaveEquationComponent>()
.add_event::<oscillation::WaveGenerationEvent>()
.add_message::<oscillation::WaveGenerationEvent>()
.add_systems(
Update,
(
Expand Down
Loading
Loading