@@ -40,7 +40,7 @@ pub struct FractalRenderer {
4040 experimental : bool ,
4141 show_output : bool ,
4242 pub progress : ProgressCounters ,
43- pub render_time : u128 ,
43+ pub render_time : u128
4444}
4545
4646impl FractalRenderer {
@@ -196,7 +196,7 @@ impl FractalRenderer {
196196 self . series_approximation . maximum_iteration = self . maximum_iteration ;
197197 }
198198
199- pub fn render_frame ( & mut self , frame_index : usize , filename : String ) {
199+ pub fn render_frame ( & mut self , frame_index : usize , filename : String , stop_flag : Option < Arc < RelaxedCounter > > ) {
200200 if self . show_output {
201201 print ! ( "{:<6}" , frame_index + self . frame_offset) ;
202202 print ! ( "| {:<15}" , extended_to_string_short( self . zoom) ) ;
@@ -206,6 +206,11 @@ impl FractalRenderer {
206206 let frame_time = Instant :: now ( ) ;
207207 let approximation_time = Instant :: now ( ) ;
208208
209+ let stop_flag = match stop_flag {
210+ Some ( stop_flag) => stop_flag,
211+ None => Arc :: new ( RelaxedCounter :: new ( 0 ) )
212+ } ;
213+
209214 let ( tx, rx) = mpsc:: channel ( ) ;
210215
211216 if self . show_output {
@@ -244,9 +249,15 @@ impl FractalRenderer {
244249 if frame_index == 0 {
245250 self . data_export . maximum_iteration = self . maximum_iteration ;
246251
247- self . center_reference . run ( & self . progress . reference , & self . progress . reference_maximum ) ;
252+ self . center_reference . run ( & self . progress . reference , & self . progress . reference_maximum , & stop_flag) ;
253+
254+ if stop_flag. get ( ) >= 1 {
255+ self . render_time = frame_time. elapsed ( ) . as_millis ( ) ;
256+ return ;
257+ } ;
258+
248259 self . series_approximation . maximum_iteration = self . center_reference . current_iteration ;
249- self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation ) ;
260+ self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation , & stop_flag ) ;
250261 } else {
251262 // If the image width/height changes intraframe (GUI) we need to regenerate some things
252263 if self . data_export . image_width != self . image_width || self . data_export . image_height != self . image_height {
@@ -263,9 +274,14 @@ impl FractalRenderer {
263274 // TODO make it so that the value is set back to zero, rather than remade
264275 // self.progress.reset_series_approximation();
265276
266- self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation ) ;
277+ self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation , & stop_flag ) ;
267278 }
268279 }
280+
281+ if stop_flag. get ( ) >= 1 {
282+ self . render_time = frame_time. elapsed ( ) . as_millis ( ) ;
283+ return ;
284+ } ;
269285
270286 let cos_rotate = self . rotate . cos ( ) ;
271287 let sin_rotate = self . rotate . sin ( ) ;
@@ -297,7 +313,10 @@ impl FractalRenderer {
297313
298314 self . progress . min_series_approximation . add ( self . series_approximation . min_valid_iteration ) ;
299315
300- // self.data_export.maximum_iteration = self.maximum_iteration;
316+ if stop_flag. get ( ) >= 1 {
317+ self . render_time = frame_time. elapsed ( ) . as_millis ( ) ;
318+ return ;
319+ } ;
301320
302321 tx. send ( ( ) ) . unwrap ( ) ;
303322
@@ -391,6 +410,11 @@ impl FractalRenderer {
391410 print ! ( "| {:<15}" , packing_time. elapsed( ) . as_millis( ) ) ;
392411 std:: io:: stdout ( ) . flush ( ) . unwrap ( ) ;
393412 } ;
413+
414+ if stop_flag. get ( ) >= 1 {
415+ self . render_time = frame_time. elapsed ( ) . as_millis ( ) ;
416+ return ;
417+ } ;
394418
395419 let iteration_time = Instant :: now ( ) ;
396420
@@ -420,9 +444,9 @@ impl FractalRenderer {
420444
421445 // This one has no offset because it is not a glitch resolving reference
422446 if self . analytic_derivative {
423- Perturbation :: iterate_normal_plus_derivative ( & mut pixel_data, & self . center_reference , & self . progress . iteration ) ;
447+ Perturbation :: iterate_normal_plus_derivative ( & mut pixel_data, & self . center_reference , & self . progress . iteration , & stop_flag ) ;
424448 } else {
425- Perturbation :: iterate_normal ( & mut pixel_data, & self . center_reference , & self . progress . iteration ) ;
449+ Perturbation :: iterate_normal ( & mut pixel_data, & self . center_reference , & self . progress . iteration , & stop_flag ) ;
426450 } ;
427451
428452 tx. send ( ( ) ) . unwrap ( ) ;
@@ -477,7 +501,12 @@ impl FractalRenderer {
477501 let mut glitch_reference = self . series_approximation . get_reference ( glitch_reference_pixel. delta_centre , & self . center_reference ) ;
478502
479503 correction_references += 1 ;
480- glitch_reference. run ( & Arc :: new ( RelaxedCounter :: new ( 0 ) ) , & Arc :: new ( RelaxedCounter :: new ( 0 ) ) ) ;
504+ glitch_reference. run ( & Arc :: new ( RelaxedCounter :: new ( 0 ) ) , & Arc :: new ( RelaxedCounter :: new ( 0 ) ) , & stop_flag) ;
505+
506+ if stop_flag. get ( ) >= 1 {
507+ self . render_time = frame_time. elapsed ( ) . as_millis ( ) ;
508+ return ;
509+ } ;
481510
482511 let delta_current_reference = self . series_approximation . evaluate ( glitch_reference_pixel. delta_centre , glitch_reference. start_iteration ) ;
483512
@@ -501,9 +530,9 @@ impl FractalRenderer {
501530 }
502531
503532 if self . analytic_derivative {
504- Perturbation :: iterate_normal_plus_derivative ( & mut pixel_data, & glitch_reference, & self . progress . iteration ) ;
533+ Perturbation :: iterate_normal_plus_derivative ( & mut pixel_data, & glitch_reference, & self . progress . iteration , & stop_flag ) ;
505534 } else {
506- Perturbation :: iterate_normal ( & mut pixel_data, & glitch_reference, & self . progress . iteration ) ;
535+ Perturbation :: iterate_normal ( & mut pixel_data, & glitch_reference, & self . progress . iteration , & stop_flag ) ;
507536 } ;
508537
509538 self . data_export . export_pixels ( & pixel_data, & glitch_reference, delta_pixel_extended) ;
@@ -550,7 +579,7 @@ impl FractalRenderer {
550579 while self . remaining_frames > 0 && self . zoom . to_float ( ) > 0.5 {
551580 self . render_frame ( count,
552581 format ! ( "output/{:08}_{}" , count + self . frame_offset,
553- extended_to_string_short( self . zoom) ) ) ;
582+ extended_to_string_short( self . zoom) ) , None ) ;
554583
555584 self . zoom . mantissa /= self . zoom_scale_factor ;
556585 self . zoom . reduce ( ) ;
@@ -565,7 +594,7 @@ impl FractalRenderer {
565594 // Overwrite the series approximation order
566595 self . series_approximation . order = 8 ;
567596 self . series_approximation . maximum_iteration = self . center_reference . current_iteration ;
568- self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation ) ;
597+ self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation , & Arc :: new ( RelaxedCounter :: new ( 0 ) ) ) ;
569598 }
570599
571600 // Logic in here to automatically adjust the maximum number of iterations
@@ -583,10 +612,10 @@ impl FractalRenderer {
583612 } else {
584613 if self . series_approximation . min_valid_iteration < 1000 && self . series_approximation . order > 16 {
585614 self . series_approximation . order = 16 ;
586- self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation ) ;
615+ self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation , & Arc :: new ( RelaxedCounter :: new ( 0 ) ) ) ;
587616 } else if self . series_approximation . min_valid_iteration < 10000 && self . series_approximation . order > 32 {
588617 self . series_approximation . order = 32 ;
589- self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation ) ;
618+ self . series_approximation . generate_approximation ( & self . center_reference , & self . progress . series_approximation , & Arc :: new ( RelaxedCounter :: new ( 0 ) ) ) ;
590619 }
591620 }
592621
0 commit comments