@@ -488,8 +488,7 @@ static void fix_inversion(double *x) // make double converted from string look o
488488 *x = std::atof (buf);
489489}
490490
491- // calcfract - the top level routine for generating an image
492- int calc_fract ()
491+ static void init_calc_fract ()
493492{
494493 g_attractors = 0 ; // default to no known finite attractors
495494 g_display_3d = Display3DMode::NONE;
@@ -711,81 +710,75 @@ int calc_fract()
711710 }
712711 g_calc_time = 0 ;
713712 }
713+ }
714714
715- if (g_cur_fractal_specific-> calc_type != standard_fractal
716- && g_cur_fractal_specific-> calc_type != calc_mand
717- && g_cur_fractal_specific->calc_type != calc_mand_fp
718- && g_cur_fractal_specific->calc_type != lyapunov
719- && g_cur_fractal_specific->calc_type != calc_froth)
720- {
721- g_calc_type = g_cur_fractal_specific->calc_type ; // per_image can override
722- g_symmetry = g_cur_fractal_specific-> symmetry ; // calctype & symmetry
723- g_plot = g_put_color; // defaults when setsymmetry not called or does nothing
724- g_xx_begin = 0 ;
725- g_yy_begin = 0 ;
726- g_xx_start = 0 ;
727- g_yy_start = 0 ;
728- g_i_x_start = 0 ;
729- g_i_y_start = 0 ;
730- g_yy_stop = g_logical_screen_y_dots- 1 ;
731- g_i_y_stop = g_logical_screen_y_dots- 1 ;
732- g_xx_stop = g_logical_screen_x_dots- 1 ;
733- g_i_x_stop = g_logical_screen_x_dots- 1 ;
734- g_calc_status = CalcStatus::IN_PROGRESS; // mark as in-progress
735- g_distance_estimator = 0 ; // only standard escape time engine supports distest
736- // per_image routine is run here
737- if (g_cur_fractal_specific-> per_image ())
738- {
739- // not a stand-alone
740- // next two lines in case periodicity changed
741- g_close_enough = g_delta_min* std::pow ( 2.0 , -( double )( std::abs (g_periodicity_check)));
742- set_symmetry (g_symmetry, false );
743- engine_timer (g_calc_type); // non-standard fractal engine
744- }
745- if ( check_key ())
746- {
747- if (g_calc_status == CalcStatus::IN_PROGRESS) // calctype didn't set this itself,
748- {
749- g_calc_status = CalcStatus::NON_RESUMABLE; // so mark it interrupted, non-resumable
750- }
751- }
752- else
753- {
754- g_calc_status = CalcStatus::COMPLETED ; // no key, so assume it completed
715+ static bool is_standard_fractal ()
716+ {
717+ return g_cur_fractal_specific->calc_type == standard_fractal //
718+ || g_cur_fractal_specific->calc_type == calc_mand //
719+ || g_cur_fractal_specific->calc_type == calc_mand_fp //
720+ || g_cur_fractal_specific-> calc_type == lyapunov //
721+ || g_cur_fractal_specific->calc_type == calc_froth;
722+ }
723+
724+ static void calc_non_standard_fractal ()
725+ {
726+ g_calc_type = g_cur_fractal_specific-> calc_type ; // per_image can override
727+ g_symmetry = g_cur_fractal_specific-> symmetry ; // calctype & symmetry
728+ g_plot = g_put_color; // defaults when setsymmetry not called or does nothing
729+ g_xx_begin = 0 ;
730+ g_yy_begin = 0 ;
731+ g_xx_start = 0 ;
732+ g_yy_start = 0 ;
733+ g_i_x_start = 0 ;
734+ g_i_y_start = 0 ;
735+ g_yy_stop = g_logical_screen_y_dots - 1 ;
736+ g_i_y_stop = g_logical_screen_y_dots - 1 ;
737+ g_xx_stop = g_logical_screen_x_dots - 1 ;
738+ g_i_x_stop = g_logical_screen_x_dots - 1 ;
739+ g_calc_status = CalcStatus::IN_PROGRESS; // mark as in-progress
740+ g_distance_estimator = 0 ; // only standard escape time engine supports distest
741+ // per_image routine is run here
742+ if (g_cur_fractal_specific-> per_image ())
743+ {
744+ // not a stand-alone
745+ // next two lines in case periodicity changed
746+ g_close_enough = g_delta_min * std::pow ( 2.0 , -( double ) ( std::abs (g_periodicity_check)));
747+ set_symmetry (g_symmetry, false );
748+ engine_timer (g_calc_type); // non-standard fractal engine
749+ }
750+ if ( check_key ())
751+ {
752+ if (g_calc_status == CalcStatus::IN_PROGRESS) // calctype didn't set this itself,
753+ {
754+ g_calc_status = CalcStatus::NON_RESUMABLE ; // so mark it interrupted, non-resumable
755755 }
756756 }
757- else // standard escape-time engine
757+ else
758758 {
759- auto timer_work_list{[]
760- {
761- perform_work_list ();
762- return 0 ;
763- }};
764- if (g_std_calc_mode == ' 3' ) // convoluted 'g' + '2' hybrid
759+ g_calc_status = CalcStatus::COMPLETED; // no key, so assume it completed
760+ }
761+ }
762+
763+ // standard escape-time engine
764+ static void calc_standard_fractal ()
765+ {
766+ const auto timer_work_list{[]
765767 {
766- const int old_calc_mode = g_std_calc_mode;
767- if (!g_resuming || g_three_pass)
768- {
769- g_std_calc_mode = ' g' ;
770- g_three_pass = true ;
771- engine_timer (timer_work_list);
772- if (g_calc_status == CalcStatus::COMPLETED)
773- {
774- if (g_logical_screen_x_dots >= 640 ) // '2' is silly after 'g' for low res
775- {
776- g_std_calc_mode = ' 2' ;
777- }
778- else
779- {
780- g_std_calc_mode = ' 1' ;
781- }
782- engine_timer (timer_work_list);
783- g_three_pass = false ;
784- }
785- }
786- else // resuming '2' pass
768+ perform_work_list ();
769+ return 0 ;
770+ }};
771+ if (g_std_calc_mode == ' 3' ) // convoluted 'g' + '2' hybrid
772+ {
773+ const char old_calc_mode = g_std_calc_mode;
774+ if (!g_resuming || g_three_pass)
775+ {
776+ g_std_calc_mode = ' g' ;
777+ g_three_pass = true ;
778+ engine_timer (timer_work_list);
779+ if (g_calc_status == CalcStatus::COMPLETED)
787780 {
788- if (g_logical_screen_x_dots >= 640 )
781+ if (g_logical_screen_x_dots >= 640 ) // '2' is silly after 'g' for low res
789782 {
790783 g_std_calc_mode = ' 2' ;
791784 }
@@ -794,15 +787,32 @@ int calc_fract()
794787 g_std_calc_mode = ' 1' ;
795788 }
796789 engine_timer (timer_work_list);
790+ g_three_pass = false ;
797791 }
798- g_std_calc_mode = (char )old_calc_mode;
799792 }
800- else // main case, much nicer!
793+ else // resuming '2' pass
801794 {
802- g_three_pass = false ;
795+ if (g_logical_screen_x_dots >= 640 )
796+ {
797+ g_std_calc_mode = ' 2' ;
798+ }
799+ else
800+ {
801+ g_std_calc_mode = ' 1' ;
802+ }
803803 engine_timer (timer_work_list);
804804 }
805+ g_std_calc_mode = old_calc_mode;
806+ }
807+ else // main case, much nicer!
808+ {
809+ g_three_pass = false ;
810+ engine_timer (timer_work_list);
805811 }
812+ }
813+
814+ static void finish_calc_fract ()
815+ {
806816 g_calc_time += g_timer_interval;
807817
808818 if (!g_log_map_table.empty () && !g_log_map_calculate)
@@ -823,6 +833,22 @@ int calc_fract()
823833 {
824834 end_disk ();
825835 }
836+ }
837+
838+ // calcfract - the top level routine for generating an image
839+ int calc_fract ()
840+ {
841+ init_calc_fract ();
842+ if (!is_standard_fractal ())
843+ {
844+ calc_non_standard_fractal ();
845+ }
846+ else
847+ {
848+ calc_standard_fractal ();
849+ }
850+ finish_calc_fract ();
851+
826852 return g_calc_status == CalcStatus::COMPLETED ? 0 : -1 ;
827853}
828854
0 commit comments