Skip to content

Commit

Permalink
Merge branch 'derived_state' of https://github.com/lee-orr/bevy into …
Browse files Browse the repository at this point in the history
…sub_states
  • Loading branch information
lee-orr committed Feb 1, 2024
2 parents 05e9ad8 + d8874aa commit 35e80d6
Show file tree
Hide file tree
Showing 36 changed files with 1,369 additions and 413 deletions.
53 changes: 49 additions & 4 deletions .github/workflows/validation-jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,62 @@ jobs:
- name: save traces
uses: actions/upload-artifact@v4
with:
name: example-traces.zip
name: example-traces-linux
path: traces.zip
- name: save screenshots
uses: actions/upload-artifact@v4
with:
name: screenshots.zip
name: screenshots-linux
path: screenshots.zip
- uses: actions/upload-artifact@v4
if: ${{ failure() && github.event_name == 'pull_request' }}
with:
name: example-run
name: example-run-linux
path: example-run/

run-examples-macos-metal:
if: ${{ github.event_name == 'merge_group' }}
runs-on: macos-14
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Disable audio
# Disable audio through a patch. on github m1 runners, audio timeouts after 15 minutes
run: git apply --ignore-whitespace tools/example-showcase/disable-audio.patch
- name: Build bevy
# this uses the same command as when running the example to ensure build is reused
run: |
TRACE_CHROME=trace-alien_cake_addict.json CI_TESTING_CONFIG=.github/example-run/alien_cake_addict.ron cargo build --example alien_cake_addict --features "bevy_ci_testing,trace,trace_chrome"
- name: Run examples
run: |
for example in .github/example-run/*.ron; do
example_name=`basename $example .ron`
echo -n $example_name > last_example_run
echo "running $example_name - "`date`
time TRACE_CHROME=trace-$example_name.json CI_TESTING_CONFIG=$example cargo run --example $example_name --features "bevy_ci_testing,trace,trace_chrome"
sleep 10
if [ `find ./ -maxdepth 1 -name 'screenshot-*.png' -print -quit` ]; then
mkdir screenshots-$example_name
mv screenshot-*.png screenshots-$example_name/
fi
done
zip traces.zip trace*.json
zip -r screenshots.zip screenshots-*
- name: save traces
uses: actions/upload-artifact@v4
with:
name: example-traces-macos
path: traces.zip
- name: save screenshots
uses: actions/upload-artifact@v4
with:
name: screenshots-macos
path: screenshots.zip
- uses: actions/upload-artifact@v4
if: ${{ failure() && github.event_name == 'pull_request' }}
with:
name: example-run-macos
path: example-run/

run-examples-on-wasm:
Expand Down Expand Up @@ -177,7 +222,7 @@ jobs:
- name: Save screenshots
uses: actions/upload-artifact@v4
with:
name: screenshots
name: screenshots-wasm
path: .github/start-wasm-example/screenshot-*.png

build-without-default-features:
Expand Down
10 changes: 5 additions & 5 deletions benches/benches/bevy_ecs/iteration/iter_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();

// TODO: batch this
for _ in 0..10_000 {
world.spawn((
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Position(Vec3::X),
Rotation(Vec3::X),
Velocity(Vec3::X),
));
}
))
.take(10_000),
);

let query = world.query::<(&Velocity, &mut Position)>();
Self(world, query)
Expand Down
10 changes: 5 additions & 5 deletions benches/benches/bevy_ecs/iteration/iter_simple_foreach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();

// TODO: batch this
for _ in 0..10_000 {
world.spawn((
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Position(Vec3::X),
Rotation(Vec3::X),
Velocity(Vec3::X),
));
}
))
.take(10_000),
);

let query = world.query::<(&Velocity, &mut Position)>();
Self(world, query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();

// TODO: batch this
for _ in 0..10_000 {
world.spawn((
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Position(Vec3::X),
Rotation(Vec3::X),
Velocity(Vec3::X),
));
}
))
.take(10_000),
);

let query = world.query::<(&Velocity, &mut Position)>();
Self(world, query)
Expand Down
10 changes: 5 additions & 5 deletions benches/benches/bevy_ecs/iteration/iter_simple_foreach_wide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();

// TODO: batch this
for _ in 0..10_000 {
world.spawn((
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Rotation(Vec3::X),
Position::<0>(Vec3::X),
Expand All @@ -48,8 +47,9 @@ impl<'w> Benchmark<'w> {
Velocity::<3>(Vec3::X),
Position::<4>(Vec3::X),
Velocity::<4>(Vec3::X),
));
}
))
.take(10_000),
);

let query = world.query();
Self(world, query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();

// TODO: batch this
for _ in 0..10_000 {
world.spawn((
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Rotation(Vec3::X),
Position::<0>(Vec3::X),
Expand All @@ -50,8 +49,9 @@ impl<'w> Benchmark<'w> {
Velocity::<3>(Vec3::X),
Position::<4>(Vec3::X),
Velocity::<4>(Vec3::X),
));
}
))
.take(10_000),
);

let query = world.query();
Self(world, query)
Expand Down
10 changes: 5 additions & 5 deletions benches/benches/bevy_ecs/iteration/iter_simple_sparse_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();

// TODO: batch this
for _ in 0..10_000 {
world.spawn((
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Position(Vec3::X),
Rotation(Vec3::X),
Velocity(Vec3::X),
));
}
))
.take(10_000),
);

let query = world.query::<(&Velocity, &mut Position)>();
Self(world, query)
Expand Down
10 changes: 5 additions & 5 deletions benches/benches/bevy_ecs/iteration/iter_simple_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ impl Benchmark {
pub fn new() -> Self {
let mut world = World::new();

// TODO: batch this
for _ in 0..10_000 {
world.spawn((
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Position(Vec3::X),
Rotation(Vec3::X),
Velocity(Vec3::X),
));
}
))
.take(10_000),
);

fn query_system(mut query: Query<(&Velocity, &mut Position)>) {
for (velocity, mut position) in &mut query {
Expand Down
10 changes: 5 additions & 5 deletions benches/benches/bevy_ecs/iteration/iter_simple_wide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();

// TODO: batch this
for _ in 0..10_000 {
world.spawn((
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Rotation(Vec3::X),
Position::<0>(Vec3::X),
Expand All @@ -48,8 +47,9 @@ impl<'w> Benchmark<'w> {
Velocity::<3>(Vec3::X),
Position::<4>(Vec3::X),
Velocity::<4>(Vec3::X),
));
}
))
.take(10_000),
);

let query = world.query();
Self(world, query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ impl<'w> Benchmark<'w> {
pub fn new() -> Self {
let mut world = World::new();

// TODO: batch this
for _ in 0..10_000 {
world.spawn((
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Rotation(Vec3::X),
Position::<0>(Vec3::X),
Expand All @@ -50,8 +49,9 @@ impl<'w> Benchmark<'w> {
Velocity::<3>(Vec3::X),
Position::<4>(Vec3::X),
Velocity::<4>(Vec3::X),
));
}
))
.take(10_000),
);

let query = world.query();
Self(world, query)
Expand Down
11 changes: 10 additions & 1 deletion crates/bevy_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod prelude {
}

use bevy_app::prelude::*;
use bevy_ecs::component::{ComponentId, ComponentTicks, Tick};
use bevy_ecs::prelude::*;
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
use bevy_utils::{Duration, HashSet, Instant, Uuid};
Expand All @@ -40,13 +41,21 @@ pub struct TypeRegistrationPlugin;

impl Plugin for TypeRegistrationPlugin {
fn build(&self, app: &mut App) {
app.register_type::<Entity>().register_type::<Name>();
app.register_type::<Name>();

register_ecs_types(app);
register_rust_types(app);
register_math_types(app);
}
}

fn register_ecs_types(app: &mut App) {
app.register_type::<Entity>()
.register_type::<ComponentId>()
.register_type::<Tick>()
.register_type::<ComponentTicks>();
}

fn register_rust_types(app: &mut App) {
app.register_type::<Range<f32>>()
.register_type_data::<Range<f32>, ReflectSerialize>()
Expand Down
9 changes: 9 additions & 0 deletions crates/bevy_ecs/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::{
};
pub use bevy_ecs_macros::Component;
use bevy_ptr::{OwningPtr, UnsafeCellDeref};
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
use std::cell::UnsafeCell;
use std::{
alloc::Layout,
Expand Down Expand Up @@ -287,6 +289,11 @@ impl ComponentInfo {
/// from a `World` using [`World::component_id()`] or via [`Components::component_id()`]. Access
/// to the `ComponentId` for a [`Resource`] is available via [`Components::resource_id()`].
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
#[cfg_attr(
feature = "bevy_reflect",
derive(Reflect),
reflect(Debug, Hash, PartialEq)
)]
pub struct ComponentId(usize);

impl ComponentId {
Expand Down Expand Up @@ -670,6 +677,7 @@ impl Components {
/// A value that tracks when a system ran relative to other systems.
/// This is used to power change detection.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
pub struct Tick {
tick: u32,
}
Expand Down Expand Up @@ -763,6 +771,7 @@ impl<'a> TickCells<'a> {

/// Records when a component was added and when it was last mutably dereferenced (or added).
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug))]
pub struct ComponentTicks {
pub(crate) added: Tick,
pub(crate) changed: Tick,
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ keywords = ["bevy"]
[dependencies]
glam = { version = "0.25", features = ["bytemuck"] }
serde = { version = "1", features = ["derive"], optional = true }
approx = { version = "0.5", optional = true }

[dev-dependencies]
approx = "0.5"

[features]
serialize = ["dep:serde", "glam/serde"]
# Enable approx for glam types to approximate floating point equality comparisons and assertions
approx = ["glam/approx"]
approx = ["dep:approx", "glam/approx"]
# Enable interoperation of glam types with mint-compatible libraries
mint = ["glam/mint"]
# Enable libm mathematical functions for glam types to ensure consistent outputs
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_math/src/bounding/bounded2d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub trait Bounded2d {

/// A 2D axis-aligned bounding box, or bounding rectangle
#[doc(alias = "BoundingRectangle")]
#[derive(Clone, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct Aabb2d {
/// The minimum, conventionally bottom-left, point of the box
pub min: Vec2,
Expand Down Expand Up @@ -328,7 +328,7 @@ mod aabb2d_tests {
use crate::primitives::Circle;

/// A bounding circle
#[derive(Clone, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct BoundingCircle {
/// The center of the bounding circle
pub center: Vec2,
Expand Down Expand Up @@ -425,10 +425,10 @@ impl BoundingVolume for BoundingCircle {
let diff = other.center - self.center;
let length = diff.length();
if self.radius() >= length + other.radius() {
return self.clone();
return *self;
}
if other.radius() >= length + self.radius() {
return other.clone();
return *other;
}
let dir = diff / length;
Self::new(
Expand Down
Loading

0 comments on commit 35e80d6

Please sign in to comment.