|
1 | 1 | use bevy::ecs::schedule::{LogLevel, ScheduleBuildSettings, ScheduleLabel};
|
2 |
| -use bevy::ecs::world; |
3 |
| -use bevy::log::tracing_subscriber::fmt::time; |
4 | 2 | use bevy::prelude::*;
|
5 | 3 | use bevy::tasks::AsyncComputeTaskPool;
|
6 |
| -use bevy::{log::trace, prelude::World, time::Time}; |
| 4 | +use bevy::{prelude::World, time::Time}; |
7 | 5 | use crossbeam_channel::Receiver;
|
8 |
| -use rand::{thread_rng, Rng}; |
9 |
| -use std::default; |
10 |
| -use std::slice::IterMut; |
11 | 6 | use std::{collections::VecDeque, time::Duration};
|
12 | 7 |
|
13 | 8 | ///
|
@@ -67,7 +62,7 @@ pub struct BackgroundFixedUpdatePlugin<T: TaskWorkerTrait> {
|
67 | 62 | impl<T: TaskWorkerTrait> Plugin for BackgroundFixedUpdatePlugin<T> {
|
68 | 63 | fn build(&self, app: &mut App) {
|
69 | 64 | app.add_systems(
|
70 |
| - bevy::app::prelude::RunFixedMainLoop, // TODO: use a specific schedule for this, à la bevy's FixedMainLoop |
| 65 | + bevy::app::prelude::RunFixedMainLoop, |
71 | 66 | FixedMain::run_schedule::<T>,
|
72 | 67 | );
|
73 | 68 |
|
@@ -120,14 +115,24 @@ pub struct TaskToRenderTime {
|
120 | 115 | }
|
121 | 116 |
|
122 | 117 | /// Difference between tasks and rendering time
|
123 |
| -#[derive(Component, Default, Reflect, Clone)] |
| 118 | +#[derive(Component, Reflect, Clone)] |
124 | 119 | pub struct Timestep {
|
125 | 120 | pub timestep: Duration,
|
126 | 121 | }
|
127 | 122 |
|
| 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 | + |
128 | 131 | /// 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. |
130 | 134 | #[derive(Clone, Component)]
|
| 135 | +#[require(TaskToRenderTime, Timestep)] |
131 | 136 | pub struct TaskWorker<T: TaskWorkerTrait> {
|
132 | 137 | pub worker: T,
|
133 | 138 | }
|
|
0 commit comments