-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
635 additions
and
842 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.