Skip to content

Commit

Permalink
0.15 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
merwaaan committed Dec 14, 2024
1 parent 478419a commit 245893b
Show file tree
Hide file tree
Showing 23 changed files with 635 additions and 842 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.0.0 - 2024-12-14

### ???

- aaa

## 1.0.0 - 2024-11-20

### Added
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ resolver = "2"
exclude = ["assets/example.gif", "assets/example3d.gif"]

[dependencies]
bevy = { version = "0.14.0", default-features = false, features = [
bevy = { version = "0.15.0", default-features = false, features = [
"bevy_pbr",
"bevy_sprite",
] }

[dev-dependencies]
approx = "0.5.1"
bevy = { version = "0.14.0", default-features = true }
bevy = { version = "0.15.0", default-features = true }
clap = { version = "4.5.16", features = ["derive"] }
divan = "0.1.14"
iyes_perf_ui = "0.3.0"
iyes_perf_ui = { git = "https://github.com/IyesGames/iyes_perf_ui.git", rev = "d8f3cbb2ec486b85a86b21e1aa32dcebd26ac884" }
rand = "0.8.5"

[profile.test]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn setup(
SpritesheetAnimation::from_id(animation_id),
));

commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d);
}
```

Expand Down Expand Up @@ -290,6 +290,7 @@ For more examples, browse the [examples/](examples) directory.

| bevy | bevy_spritesheet_animation |
| ---- | -------------------------- |
| 0.15 | 2.0.0 |
| 0.14 | 0.2.0 |
| 0.13 | 0.1.0 |

Expand Down
194 changes: 98 additions & 96 deletions benches/basic.rs
Original file line number Diff line number Diff line change
@@ -1,100 +1,102 @@
use std::time::Duration;

use bevy::{
ecs::system::SystemState,
prelude::*,
render::{settings::WgpuSettings, RenderPlugin},
winit::WinitPlugin,
};
use bevy_spritesheet_animation::{animator::Animator, prelude::*};
use divan::Bencher;
use rand::seq::IteratorRandom;

fn create_app() -> App {
let mut app = App::new();
app.add_plugins((
DefaultPlugins
.build()
// Headless mode
.disable::<WinitPlugin>()
.set(RenderPlugin {
render_creation: WgpuSettings {
backends: None,
..default()
}
.into(),
..default()
}),
SpritesheetAnimationPlugin::default(),
))
.finish();
app
}

fn create_animation(app: &mut App) -> AnimationId {
let mut library = app
.world_mut()
.get_resource_mut::<AnimationLibrary>()
.unwrap();

let clip = Clip::from_frames([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
let clip_id = library.register_clip(clip);

let animation = Animation::from_clip(clip_id);
library.register_animation(animation)
}

fn create_sprite(app: &mut App, animation_id: AnimationId) {
let mut atlas_layouts = app
.world_mut()
.get_resource_mut::<Assets<TextureAtlasLayout>>()
.unwrap();

let layout = atlas_layouts.add(Spritesheet::new(8, 8).atlas_layout(96, 96));

app.world_mut().spawn((
TextureAtlas {
layout: layout.clone(),
..default()
},
SpritesheetAnimation::from_id(animation_id),
));
}

#[divan::bench(args=[(1, 1000), (1000, 1000)])]
fn playback(bencher: Bencher, (animation_count, sprite_count): (usize, usize)) {
let mut app = create_app();

let animation_ids: Vec<_> = (0..animation_count)
.map(|_| create_animation(&mut app))
.collect();

let mut rng = rand::thread_rng();
for _ in 0..sprite_count {
create_sprite(&mut app, *animation_ids.iter().choose(&mut rng).unwrap());
}

let mut time = Time::new_with(());

let mut system_state: SystemState<(
Res<AnimationLibrary>,
ResMut<Animator>,
EventWriter<AnimationEvent>,
Query<(Entity, &mut SpritesheetAnimation, Option<&mut TextureAtlas>)>,
)> = SystemState::new(app.world_mut());

bencher.bench_local(|| {
for _ in 0..1000 {
let (library, mut animator, mut event_writer, mut query) =
system_state.get_mut(app.world_mut());

animator.update(&time, &library, &mut event_writer, &mut query);

time.advance_by(Duration::from_millis(100));
}
});
}
// use std::time::Duration;

// use bevy::{
// ecs::system::SystemState,
// prelude::*,
// render::{settings::WgpuSettings, RenderPlugin},
// winit::WinitPlugin,
// };
// use bevy_spritesheet_animation::{animator::Animator, prelude::*};
// use divan::Bencher;
// use rand::seq::IteratorRandom;

// fn create_app() -> App {
// let mut app = App::new();
// app.add_plugins((
// DefaultPlugins
// .build()
// // Headless mode
// .disable::<WinitPlugin>()
// .set(RenderPlugin {
// render_creation: WgpuSettings {
// backends: None,
// ..default()
// }
// .into(),
// ..default()
// }),
// SpritesheetAnimationPlugin::default(),
// ))
// .finish();
// app
// }

// fn create_animation(app: &mut App) -> AnimationId {
// let mut library = app
// .world_mut()
// .get_resource_mut::<AnimationLibrary>()
// .unwrap();

// let clip = Clip::from_frames([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// let clip_id = library.register_clip(clip);

// let animation = Animation::from_clip(clip_id);
// library.register_animation(animation)
// }

// fn create_sprite(app: &mut App, animation_id: AnimationId) {
// let mut atlas_layouts = app
// .world_mut()
// .get_resource_mut::<Assets<TextureAtlasLayout>>()
// .unwrap();

// let layout = atlas_layouts.add(Spritesheet::new(8, 8).atlas_layout(96, 96));

// app.world_mut().spawn((
// TextureAtlas {
// layout: layout.clone(),
// ..default()
// },
// SpritesheetAnimation::from_id(animation_id),
// ));
// }

// #[divan::bench(args=[(1, 1000), (1000, 1000)])]
// fn playback(bencher: Bencher, (animation_count, sprite_count): (usize, usize)) {
// let mut app = create_app();

// let animation_ids: Vec<_> = (0..animation_count)
// .map(|_| create_animation(&mut app))
// .collect();

// let mut rng = rand::thread_rng();
// for _ in 0..sprite_count {
// create_sprite(&mut app, *animation_ids.iter().choose(&mut rng).unwrap());
// }

// let mut time = Time::new_with(());

// let mut system_state: SystemState<(
// Res<AnimationLibrary>,
// ResMut<Animator>,
// EventWriter<AnimationEvent>,
// Query<(Entity, &mut SpritesheetAnimation, Option<&mut TextureAtlas>)>,
// )> = SystemState::new(app.world_mut());

// bencher.bench_local(|| {
// for _ in 0..1000 {
// let (library, mut animator, mut event_writer, mut query) =
// system_state.get_mut(app.world_mut());

// animator.update(&time, &library, &mut event_writer, &mut query);

// time.advance_by(Duration::from_millis(100));
// }
// });
// }

fn main() {
divan::main();
}

// TODO
Loading

0 comments on commit 245893b

Please sign in to comment.