Skip to content

Commit 1161a12

Browse files
committed
use required component + remove some unused imports or obsolete comments
1 parent 88d8cb3 commit 1161a12

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

examples/interpolate_custom_schedule.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use bevy::{
1414
color::palettes::{
15-
css::{ORANGE, RED, WHITE},
15+
css::WHITE,
1616
tailwind::{CYAN_400, RED_400},
1717
},
1818
ecs::schedule::ScheduleLabel,
@@ -82,6 +82,7 @@ fn main() {
8282
// Run the app.
8383
app.run();
8484
}
85+
8586
/// Eases the translations of entities with linear interpolation.
8687
fn ease_translation_lerp(
8788
mut query: Query<(&mut Transform, &TranslationEasingState)>,
@@ -147,8 +148,8 @@ fn setup(
147148
let mesh = meshes.add(Rectangle::from_length(60.0));
148149

149150
commands.spawn((
150-
TaskToRenderTime::default(),
151151
Timestep {
152+
// Set the fixed timestep to just 5 Hz for demonstration purposes.
152153
timestep: Duration::from_secs_f32(0.5),
153154
},
154155
TaskResults::<TaskWorkerTraitImpl>::default(),
@@ -309,7 +310,6 @@ pub mod task_user {
309310
substep_count: u32,
310311
) -> Vec<(Entity, Transform, LinearVelocity, AngularVelocity)> {
311312
let simulated_time = timestep * substep_count;
312-
let to_simulate = simulated_time.as_millis() as u64;
313313
// Simulate an expensive task
314314
std::thread::sleep(Duration::from_millis(thread_rng().gen_range(200..201)));
315315

src/background_fixed_schedule.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
use bevy::ecs::schedule::{LogLevel, ScheduleBuildSettings, ScheduleLabel};
2-
use bevy::ecs::world;
3-
use bevy::log::tracing_subscriber::fmt::time;
42
use bevy::prelude::*;
53
use bevy::tasks::AsyncComputeTaskPool;
6-
use bevy::{log::trace, prelude::World, time::Time};
4+
use bevy::{prelude::World, time::Time};
75
use crossbeam_channel::Receiver;
8-
use rand::{thread_rng, Rng};
9-
use std::default;
10-
use std::slice::IterMut;
116
use std::{collections::VecDeque, time::Duration};
127

138
///
@@ -67,7 +62,7 @@ pub struct BackgroundFixedUpdatePlugin<T: TaskWorkerTrait> {
6762
impl<T: TaskWorkerTrait> Plugin for BackgroundFixedUpdatePlugin<T> {
6863
fn build(&self, app: &mut App) {
6964
app.add_systems(
70-
bevy::app::prelude::RunFixedMainLoop, // TODO: use a specific schedule for this, à la bevy's FixedMainLoop
65+
bevy::app::prelude::RunFixedMainLoop,
7166
FixedMain::run_schedule::<T>,
7267
);
7368

@@ -120,14 +115,24 @@ pub struct TaskToRenderTime {
120115
}
121116

122117
/// Difference between tasks and rendering time
123-
#[derive(Component, Default, Reflect, Clone)]
118+
#[derive(Component, Reflect, Clone)]
124119
pub struct Timestep {
125120
pub timestep: Duration,
126121
}
127122

123+
impl Default for Timestep {
124+
fn default() -> Self {
125+
Self {
126+
timestep: Duration::from_secs_f64(1.0 / 64.0),
127+
}
128+
}
129+
}
130+
128131
/// Struct to be able to configure what the task should do.
129-
/// TODO: extract first, then do work.
132+
// TODO: This should also require `TaskResults` and `WorkTask`
133+
// but their type parameter not enforcing `Default` makes the require macro fail. This should be a bevy issue.
130134
#[derive(Clone, Component)]
135+
#[require(TaskToRenderTime, Timestep)]
131136
pub struct TaskWorker<T: TaskWorkerTrait> {
132137
pub worker: T,
133138
}

src/interpolation.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use crate::*;
88
use bevy::{
9-
app::FixedMain,
109
ecs::schedule::{InternedScheduleLabel, ScheduleLabel},
1110
prelude::*,
1211
};

0 commit comments

Comments
 (0)