@@ -195,38 +195,11 @@ impl Backend {
195
195
}
196
196
} ) ;
197
197
198
- let mut first_step = true ;
198
+ let mut task_sent = false ;
199
199
loop {
200
200
constraint = scene. make_constraint ( args, self . state . time , & self . mesh ) ;
201
201
let mut state_saved = false ;
202
202
unsafe { update_constraint ( & constraint) } ;
203
- if !first_step {
204
- match result_receiver. try_recv ( ) {
205
- Ok ( bvh) => {
206
- info ! ( "bvh update..." ) ;
207
- let n_surface_vert = self . mesh . mesh . mesh . surface_vert_count ;
208
- let vert: Matrix3xX < f32 > = self
209
- . state
210
- . curr_vertex
211
- . columns ( 0 , n_surface_vert)
212
- . into_owned ( ) ;
213
- self . bvh = Box :: new ( Some ( bvh) ) ;
214
- unsafe {
215
- update_bvh ( self . bvh . as_ref ( ) . as_ref ( ) . unwrap ( ) ) ;
216
- }
217
- let data = (
218
- vert,
219
- self . mesh . mesh . mesh . face . clone ( ) ,
220
- self . mesh . mesh . mesh . edge . clone ( ) ,
221
- ) ;
222
- task_sender. send ( data) . unwrap ( ) ;
223
- }
224
- Err ( mpsc:: TryRecvError :: Empty ) => { }
225
- Err ( mpsc:: TryRecvError :: Disconnected ) => {
226
- panic ! ( "bvh thread disconnected" ) ;
227
- }
228
- }
229
- }
230
203
let new_frame = ( self . state . time * args. fps ) . floor ( ) as i32 ;
231
204
if new_frame != self . state . curr_frame {
232
205
// Name: Time Per Video Frame
@@ -253,6 +226,47 @@ impl Backend {
253
226
let curr_time = Instant :: now ( ) ;
254
227
let elapsed_time = curr_time - last_time;
255
228
self . fetch_state ( & dataset, & param) ;
229
+ if task_sent {
230
+ match result_receiver. try_recv ( ) {
231
+ Ok ( bvh) => {
232
+ info ! ( "bvh update..." ) ;
233
+ let n_surface_vert = self . mesh . mesh . mesh . surface_vert_count ;
234
+ let vert: Matrix3xX < f32 > = self
235
+ . state
236
+ . curr_vertex
237
+ . columns ( 0 , n_surface_vert)
238
+ . into_owned ( ) ;
239
+ self . bvh = Box :: new ( Some ( bvh) ) ;
240
+ unsafe {
241
+ update_bvh ( self . bvh . as_ref ( ) . as_ref ( ) . unwrap ( ) ) ;
242
+ }
243
+ let data = (
244
+ vert,
245
+ self . mesh . mesh . mesh . face . clone ( ) ,
246
+ self . mesh . mesh . mesh . edge . clone ( ) ,
247
+ ) ;
248
+ task_sender. send ( data) . unwrap ( ) ;
249
+ }
250
+ Err ( mpsc:: TryRecvError :: Empty ) => { }
251
+ Err ( mpsc:: TryRecvError :: Disconnected ) => {
252
+ panic ! ( "bvh thread disconnected" ) ;
253
+ }
254
+ }
255
+ } else {
256
+ let n_surface_vert = self . mesh . mesh . mesh . surface_vert_count ;
257
+ let vert: Matrix3xX < f32 > = self
258
+ . state
259
+ . curr_vertex
260
+ . columns ( 0 , n_surface_vert)
261
+ . into_owned ( ) ;
262
+ let data = (
263
+ vert,
264
+ self . mesh . mesh . mesh . face . clone ( ) ,
265
+ self . mesh . mesh . mesh . edge . clone ( ) ,
266
+ ) ;
267
+ task_sender. send ( data) . unwrap ( ) ;
268
+ task_sent = true ;
269
+ }
256
270
self . state . curr_frame = new_frame;
257
271
writeln ! ( time_per_frame, "{} {}" , new_frame, elapsed_time. as_millis( ) ) . unwrap ( ) ;
258
272
writeln ! (
@@ -326,15 +340,6 @@ impl Backend {
326
340
panic ! ( "failed to advance" ) ;
327
341
}
328
342
self . state . time = result. time ;
329
- if first_step {
330
- let data = (
331
- self . state . curr_vertex . clone ( ) ,
332
- self . mesh . mesh . mesh . face . clone ( ) ,
333
- self . mesh . mesh . mesh . edge . clone ( ) ,
334
- ) ;
335
- task_sender. send ( data) . unwrap ( ) ;
336
- first_step = false ;
337
- }
338
343
}
339
344
let _ = result_receiver. try_recv ( ) ;
340
345
write_current_time_to_file ( finished_path. to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
0 commit comments