@@ -43,6 +43,9 @@ fn add_assets(
43
43
commands. insert_resource ( BoxMaterialHandle ( box_material_handle) ) ;
44
44
}
45
45
46
+ #[ derive( Component ) ]
47
+ struct ComputeTransform ( Task < Transform > ) ;
48
+
46
49
/// This system generates tasks simulating computationally intensive
47
50
/// work that potentially spans multiple frames/ticks. A separate
48
51
/// system, `handle_tasks`, will poll the spawned tasks on subsequent
@@ -66,7 +69,7 @@ fn spawn_tasks(mut commands: Commands, thread_pool: Res<AsyncComputeTaskPool>) {
66
69
} ) ;
67
70
68
71
// Spawn new entity and add our new task as a component
69
- commands. spawn ( ) . insert ( task) ;
72
+ commands. spawn ( ) . insert ( ComputeTransform ( task) ) ;
70
73
}
71
74
}
72
75
}
@@ -78,12 +81,12 @@ fn spawn_tasks(mut commands: Commands, thread_pool: Res<AsyncComputeTaskPool>) {
78
81
/// removes the task component from the entity.
79
82
fn handle_tasks (
80
83
mut commands : Commands ,
81
- mut transform_tasks : Query < ( Entity , & mut Task < Transform > ) > ,
84
+ mut transform_tasks : Query < ( Entity , & mut ComputeTransform ) > ,
82
85
box_mesh_handle : Res < BoxMeshHandle > ,
83
86
box_material_handle : Res < BoxMaterialHandle > ,
84
87
) {
85
88
for ( entity, mut task) in transform_tasks. iter_mut ( ) {
86
- if let Some ( transform) = future:: block_on ( future:: poll_once ( & mut * task) ) {
89
+ if let Some ( transform) = future:: block_on ( future:: poll_once ( & mut task. 0 ) ) {
87
90
// Add our new PbrBundle of components to our tagged entity
88
91
commands. entity ( entity) . insert_bundle ( PbrBundle {
89
92
mesh : box_mesh_handle. clone ( ) ,
@@ -93,7 +96,7 @@ fn handle_tasks(
93
96
} ) ;
94
97
95
98
// Task is complete, so remove task component from entity
96
- commands. entity ( entity) . remove :: < Task < Transform > > ( ) ;
99
+ commands. entity ( entity) . remove :: < ComputeTransform > ( ) ;
97
100
}
98
101
}
99
102
}
0 commit comments