Rename 'percent_done' to 'fraction_done'

Because they are not percentages but fractional values in the range [0,1]
calculate-0.9.5
Daniel van Vugt 4 years ago
parent 14e91cc8d2
commit 6e8542f95f

@ -78,7 +78,7 @@ typedef struct
size_t size); size_t size);
void (*on_boot_progress)(ply_boot_splash_plugin_t *plugin, void (*on_boot_progress)(ply_boot_splash_plugin_t *plugin,
double duration, double duration,
double percent_done); double fraction_done);
void (*on_root_mounted)(ply_boot_splash_plugin_t *plugin); void (*on_root_mounted)(ply_boot_splash_plugin_t *plugin);
void (*hide_splash_screen)(ply_boot_splash_plugin_t *plugin, void (*hide_splash_screen)(ply_boot_splash_plugin_t *plugin,
ply_event_loop_t *loop); ply_event_loop_t *loop);

@ -67,7 +67,7 @@ struct _ply_text_progress_bar
int number_of_rows; int number_of_rows;
int number_of_columns; int number_of_columns;
double percent_done; double fraction_done;
uint32_t is_hidden : 1; uint32_t is_hidden : 1;
}; };
@ -186,9 +186,9 @@ ply_text_progress_bar_draw (ply_text_progress_bar_t *progress_bar)
progress_bar->column, progress_bar->column,
progress_bar->row); progress_bar->row);
brown_fraction = -(progress_bar->percent_done * progress_bar->percent_done) + 2 * progress_bar->percent_done; brown_fraction = -(progress_bar->fraction_done * progress_bar->fraction_done) + 2 * progress_bar->fraction_done;
blue_fraction = progress_bar->percent_done; blue_fraction = progress_bar->fraction_done;
white_fraction = progress_bar->percent_done * progress_bar->percent_done; white_fraction = progress_bar->fraction_done * progress_bar->fraction_done;
for (i = 0; i < width; i++) { for (i = 0; i < width; i++) {
double f; double f;
@ -262,16 +262,16 @@ ply_text_progress_bar_hide (ply_text_progress_bar_t *progress_bar)
} }
void void
ply_text_progress_bar_set_percent_done (ply_text_progress_bar_t *progress_bar, ply_text_progress_bar_set_fraction_done (ply_text_progress_bar_t *progress_bar,
double percent_done) double fraction_done)
{ {
progress_bar->percent_done = percent_done; progress_bar->fraction_done = fraction_done;
} }
double double
ply_text_progress_bar_get_percent_done (ply_text_progress_bar_t *progress_bar) ply_text_progress_bar_get_fraction_done (ply_text_progress_bar_t *progress_bar)
{ {
return progress_bar->percent_done; return progress_bar->fraction_done;
} }
int int

@ -42,10 +42,10 @@ void ply_text_progress_bar_show (ply_text_progress_bar_t *progress_bar,
ply_text_display_t *display); ply_text_display_t *display);
void ply_text_progress_bar_hide (ply_text_progress_bar_t *progress_bar); void ply_text_progress_bar_hide (ply_text_progress_bar_t *progress_bar);
void ply_text_progress_bar_set_percent_done (ply_text_progress_bar_t *progress_bar, void ply_text_progress_bar_set_fraction_done (ply_text_progress_bar_t *progress_bar,
double percent_done); double fraction_done);
double ply_text_progress_bar_get_percent_done (ply_text_progress_bar_t *progress_bar); double ply_text_progress_bar_get_fraction_done (ply_text_progress_bar_t *progress_bar);
int ply_text_progress_bar_get_number_of_rows (ply_text_progress_bar_t *progress_bar); int ply_text_progress_bar_get_number_of_rows (ply_text_progress_bar_t *progress_bar);
int ply_text_progress_bar_get_number_of_columns (ply_text_progress_bar_t *progress_bar); int ply_text_progress_bar_get_number_of_columns (ply_text_progress_bar_t *progress_bar);

@ -37,7 +37,7 @@ struct _ply_text_step_bar
int number_of_rows; int number_of_rows;
int number_of_columns; int number_of_columns;
double percent_done; double fraction_done;
uint32_t is_hidden : 1; uint32_t is_hidden : 1;
}; };
@ -81,7 +81,7 @@ ply_text_step_bar_draw (ply_text_step_bar_t *step_bar)
step_bar->column, step_bar->column,
step_bar->row); step_bar->row);
cur = step_bar->percent_done * step_bar->number_of_columns; cur = step_bar->fraction_done * step_bar->number_of_columns;
for (i = 0; i < step_bar->number_of_columns; i++) { for (i = 0; i < step_bar->number_of_columns; i++) {
if (i == cur) if (i == cur)
ply_text_display_set_foreground_color (step_bar->display, ply_text_display_set_foreground_color (step_bar->display,
@ -132,16 +132,16 @@ ply_text_step_bar_hide (ply_text_step_bar_t *step_bar)
} }
void void
ply_text_step_bar_set_percent_done (ply_text_step_bar_t *step_bar, ply_text_step_bar_set_fraction_done (ply_text_step_bar_t *step_bar,
double percent_done) double fraction_done)
{ {
step_bar->percent_done = percent_done; step_bar->fraction_done = fraction_done;
} }
double double
ply_text_step_bar_get_percent_done (ply_text_step_bar_t *step_bar) ply_text_step_bar_get_fraction_done (ply_text_step_bar_t *step_bar)
{ {
return step_bar->percent_done; return step_bar->fraction_done;
} }
int int

@ -36,10 +36,10 @@ void ply_text_step_bar_show (ply_text_step_bar_t *step_bar,
ply_text_display_t *display); ply_text_display_t *display);
void ply_text_step_bar_hide (ply_text_step_bar_t *step_bar); void ply_text_step_bar_hide (ply_text_step_bar_t *step_bar);
void ply_text_step_bar_set_percent_done (ply_text_step_bar_t *step_bar, void ply_text_step_bar_set_fraction_done (ply_text_step_bar_t *step_bar,
double percent_done); double fraction_done);
double ply_text_step_bar_get_percent_done (ply_text_step_bar_t *step_bar); double ply_text_step_bar_get_fraction_done (ply_text_step_bar_t *step_bar);
int ply_text_step_bar_get_number_of_rows (ply_text_step_bar_t *step_bar); int ply_text_step_bar_get_number_of_rows (ply_text_step_bar_t *step_bar);
int ply_text_step_bar_get_number_of_columns (ply_text_step_bar_t *step_bar); int ply_text_step_bar_get_number_of_columns (ply_text_step_bar_t *step_bar);

@ -62,7 +62,7 @@ struct _ply_progress_animation
ply_rectangle_t area; ply_rectangle_t area;
ply_rectangle_t frame_area; ply_rectangle_t frame_area;
double percent_done; double fraction_done;
int previous_frame_number; int previous_frame_number;
double transition_start_time; double transition_start_time;
@ -88,7 +88,7 @@ ply_progress_animation_new (const char *image_dir,
progress_animation->frames_prefix = strdup (frames_prefix); progress_animation->frames_prefix = strdup (frames_prefix);
progress_animation->image_dir = strdup (image_dir); progress_animation->image_dir = strdup (image_dir);
progress_animation->is_hidden = true; progress_animation->is_hidden = true;
progress_animation->percent_done = 0.0; progress_animation->fraction_done = 0.0;
progress_animation->area.x = 0; progress_animation->area.x = 0;
progress_animation->area.y = 0; progress_animation->area.y = 0;
progress_animation->area.width = 0; progress_animation->area.width = 0;
@ -216,7 +216,7 @@ ply_progress_animation_draw (ply_progress_animation_t *progress_animation)
if (number_of_frames == 0) if (number_of_frames == 0)
return; return;
frame_number = progress_animation->percent_done * (number_of_frames - 1); frame_number = progress_animation->fraction_done * (number_of_frames - 1);
if (progress_animation->previous_frame_number != frame_number && if (progress_animation->previous_frame_number != frame_number &&
progress_animation->transition != PLY_PROGRESS_ANIMATION_TRANSITION_NONE && progress_animation->transition != PLY_PROGRESS_ANIMATION_TRANSITION_NONE &&
@ -456,17 +456,17 @@ ply_progress_animation_get_height (ply_progress_animation_t *progress_animation)
} }
void void
ply_progress_animation_set_percent_done (ply_progress_animation_t *progress_animation, ply_progress_animation_set_fraction_done (ply_progress_animation_t *progress_animation,
double percent_done) double fraction_done)
{ {
progress_animation->percent_done = percent_done; progress_animation->fraction_done = fraction_done;
ply_progress_animation_draw (progress_animation); ply_progress_animation_draw (progress_animation);
} }
double double
ply_progress_animation_get_percent_done (ply_progress_animation_t *progress_animation) ply_progress_animation_get_fraction_done (ply_progress_animation_t *progress_animation)
{ {
return progress_animation->percent_done; return progress_animation->fraction_done;
} }
/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */

@ -64,9 +64,9 @@ bool ply_progress_animation_is_hidden (ply_progress_animation_t *progress_animat
long ply_progress_animation_get_width (ply_progress_animation_t *progress_animation); long ply_progress_animation_get_width (ply_progress_animation_t *progress_animation);
long ply_progress_animation_get_height (ply_progress_animation_t *progress_animation); long ply_progress_animation_get_height (ply_progress_animation_t *progress_animation);
void ply_progress_animation_set_percent_done (ply_progress_animation_t *progress_animation, void ply_progress_animation_set_fraction_done (ply_progress_animation_t *progress_animation,
double percent_done); double fraction_done);
double ply_progress_animation_get_percent_done (ply_progress_animation_t *progress_animation); double ply_progress_animation_get_fraction_done (ply_progress_animation_t *progress_animation);
#endif #endif

@ -58,7 +58,7 @@ struct _ply_progress_bar
uint32_t fg_color; uint32_t fg_color;
uint32_t bg_color; uint32_t bg_color;
double percent_done; double fraction_done;
uint32_t is_hidden : 1; uint32_t is_hidden : 1;
}; };
@ -73,7 +73,7 @@ ply_progress_bar_new (void)
progress_bar->is_hidden = true; progress_bar->is_hidden = true;
progress_bar->fg_color = 0xffffffff; /* Solid white */ progress_bar->fg_color = 0xffffffff; /* Solid white */
progress_bar->bg_color = 0x01000000; /* Transparent */ progress_bar->bg_color = 0x01000000; /* Transparent */
progress_bar->percent_done = 0.0; progress_bar->fraction_done = 0.0;
return progress_bar; return progress_bar;
} }
@ -105,7 +105,7 @@ ply_progress_bar_draw_area (ply_progress_bar_t *progress_bar,
*/ */
fill_area = progress_bar->area; fill_area = progress_bar->area;
fill_area.width = progress_bar->area.width * progress_bar->percent_done; fill_area.width = progress_bar->area.width * progress_bar->fraction_done;
ply_pixel_buffer_fill_with_hex_color (buffer, &fill_area, progress_bar->fg_color); ply_pixel_buffer_fill_with_hex_color (buffer, &fill_area, progress_bar->fg_color);
fill_area.x = fill_area.x + fill_area.width; fill_area.x = fill_area.x + fill_area.width;
@ -179,17 +179,17 @@ ply_progress_bar_get_height (ply_progress_bar_t *progress_bar)
} }
void void
ply_progress_bar_set_percent_done (ply_progress_bar_t *progress_bar, ply_progress_bar_set_fraction_done (ply_progress_bar_t *progress_bar,
double percent_done) double fraction_done)
{ {
progress_bar->percent_done = percent_done; progress_bar->fraction_done = fraction_done;
ply_progress_bar_draw (progress_bar); ply_progress_bar_draw (progress_bar);
} }
double double
ply_progress_bar_get_percent_done (ply_progress_bar_t *progress_bar) ply_progress_bar_get_fraction_done (ply_progress_bar_t *progress_bar)
{ {
return progress_bar->percent_done; return progress_bar->fraction_done;
} }
void void

@ -56,9 +56,9 @@ bool ply_progress_bar_is_hidden (ply_progress_bar_t *bar);
long ply_progress_bar_get_width (ply_progress_bar_t *bar); long ply_progress_bar_get_width (ply_progress_bar_t *bar);
long ply_progress_bar_get_height (ply_progress_bar_t *bar); long ply_progress_bar_get_height (ply_progress_bar_t *bar);
void ply_progress_bar_set_percent_done (ply_progress_bar_t *bar, void ply_progress_bar_set_fraction_done (ply_progress_bar_t *bar,
double percent_done); double fraction_done);
double ply_progress_bar_get_percent_done (ply_progress_bar_t *bar); double ply_progress_bar_get_fraction_done (ply_progress_bar_t *bar);
void ply_progress_bar_set_colors (ply_progress_bar_t *bar, void ply_progress_bar_set_colors (ply_progress_bar_t *bar,
uint32_t fg_color, uint32_t fg_color,

@ -237,12 +237,12 @@ on_timeout (ply_boot_splash_plugin_t *plugin)
static void static void
on_boot_progress (ply_boot_splash_plugin_t *plugin, on_boot_progress (ply_boot_splash_plugin_t *plugin,
double duration, double duration,
double percent_done) double fraction_done)
{ {
script_lib_plymouth_on_boot_progress (plugin->script_state, script_lib_plymouth_on_boot_progress (plugin->script_state,
plugin->script_plymouth_lib, plugin->script_plymouth_lib,
duration, duration,
percent_done); fraction_done);
} }
static bool static bool

@ -1149,11 +1149,11 @@ on_timeout (ply_boot_splash_plugin_t *plugin)
static void static void
on_boot_progress (ply_boot_splash_plugin_t *plugin, on_boot_progress (ply_boot_splash_plugin_t *plugin,
double duration, double duration,
double percent_done) double fraction_done)
{ {
if (plugin->progress_target < 0) if (plugin->progress_target < 0)
plugin->progress = percent_done; plugin->progress = fraction_done;
plugin->progress_target = percent_done; plugin->progress_target = fraction_done;
} }
static void static void

@ -536,16 +536,16 @@ update_status (ply_boot_splash_plugin_t *plugin,
static void static void
on_boot_progress (ply_boot_splash_plugin_t *plugin, on_boot_progress (ply_boot_splash_plugin_t *plugin,
double duration, double duration,
double percent_done) double fraction_done)
{ {
ply_list_node_t *node; ply_list_node_t *node;
double total_duration; double total_duration;
total_duration = duration / percent_done; total_duration = duration / fraction_done;
/* Fun made-up smoothing function to make the growth asymptotic: /* Fun made-up smoothing function to make the growth asymptotic:
* fraction(time,estimate)=1-2^(-(time^1.45)/estimate) */ * fraction(time,estimate)=1-2^(-(time^1.45)/estimate) */
percent_done = 1.0 - pow (2.0, -pow (duration, 1.45) / total_duration) * (1.0 - percent_done); fraction_done = 1.0 - pow (2.0, -pow (duration, 1.45) / total_duration) * (1.0 - fraction_done);
node = ply_list_get_first_node (plugin->views); node = ply_list_get_first_node (plugin->views);
@ -556,7 +556,7 @@ on_boot_progress (ply_boot_splash_plugin_t *plugin,
view = ply_list_node_get_data (node); view = ply_list_node_get_data (node);
next_node = ply_list_get_next_node (plugin->views, node); next_node = ply_list_get_next_node (plugin->views, node);
ply_text_step_bar_set_percent_done (view->step_bar, percent_done); ply_text_step_bar_set_fraction_done (view->step_bar, fraction_done);
if (plugin->is_animating) if (plugin->is_animating)
ply_text_step_bar_draw (view->step_bar); ply_text_step_bar_draw (view->step_bar);

@ -542,16 +542,16 @@ update_status (ply_boot_splash_plugin_t *plugin,
static void static void
on_boot_progress (ply_boot_splash_plugin_t *plugin, on_boot_progress (ply_boot_splash_plugin_t *plugin,
double duration, double duration,
double percent_done) double fraction_done)
{ {
ply_list_node_t *node; ply_list_node_t *node;
double total_duration; double total_duration;
total_duration = duration / percent_done; total_duration = duration / fraction_done;
/* Fun made-up smoothing function to make the growth asymptotic: /* Fun made-up smoothing function to make the growth asymptotic:
* fraction(time,estimate)=1-2^(-(time^1.45)/estimate) */ * fraction(time,estimate)=1-2^(-(time^1.45)/estimate) */
percent_done = 1.0 - pow (2.0, -pow (duration, 1.45) / total_duration) * (1.0 - percent_done); fraction_done = 1.0 - pow (2.0, -pow (duration, 1.45) / total_duration) * (1.0 - fraction_done);
node = ply_list_get_first_node (plugin->views); node = ply_list_get_first_node (plugin->views);
@ -562,7 +562,7 @@ on_boot_progress (ply_boot_splash_plugin_t *plugin,
view = ply_list_node_get_data (node); view = ply_list_node_get_data (node);
next_node = ply_list_get_next_node (plugin->views, node); next_node = ply_list_get_next_node (plugin->views, node);
ply_text_progress_bar_set_percent_done (view->progress_bar, percent_done); ply_text_progress_bar_set_fraction_done (view->progress_bar, fraction_done);
if (plugin->is_animating) if (plugin->is_animating)
ply_text_progress_bar_draw (view->progress_bar); ply_text_progress_bar_draw (view->progress_bar);

@ -68,8 +68,8 @@
#define FRAMES_PER_SECOND 30 #define FRAMES_PER_SECOND 30
#endif #endif
#ifndef SHOW_ANIMATION_PERCENT #ifndef SHOW_ANIMATION_FRACTION
#define SHOW_ANIMATION_PERCENT 0.9 #define SHOW_ANIMATION_FRACTION 0.9
#endif #endif
#define PROGRESS_BAR_WIDTH 400 #define PROGRESS_BAR_WIDTH 400
@ -1707,7 +1707,7 @@ on_animation_stopped (ply_boot_splash_plugin_t *plugin)
static void static void
update_progress_animation (ply_boot_splash_plugin_t *plugin, update_progress_animation (ply_boot_splash_plugin_t *plugin,
double percent_done) double fraction_done)
{ {
ply_list_node_t *node; ply_list_node_t *node;
view_t *view; view_t *view;
@ -1718,13 +1718,13 @@ update_progress_animation (ply_boot_splash_plugin_t *plugin,
view = ply_list_node_get_data (node); view = ply_list_node_get_data (node);
if (view->progress_animation != NULL) if (view->progress_animation != NULL)
ply_progress_animation_set_percent_done (view->progress_animation, ply_progress_animation_set_fraction_done (view->progress_animation,
percent_done); fraction_done);
ply_progress_bar_set_percent_done (view->progress_bar, percent_done); ply_progress_bar_set_fraction_done (view->progress_bar, fraction_done);
if (!ply_progress_bar_is_hidden (view->progress_bar) && if (!ply_progress_bar_is_hidden (view->progress_bar) &&
plugin->mode_settings[plugin->mode].progress_bar_show_percent_complete) { plugin->mode_settings[plugin->mode].progress_bar_show_percent_complete) {
snprintf (buf, sizeof(buf), _("%d%% complete"), (int)(percent_done * 100)); snprintf (buf, sizeof(buf), _("%d%% complete"), (int)(fraction_done * 100));
view_show_message (view, buf); view_show_message (view, buf);
} }
@ -1735,7 +1735,7 @@ update_progress_animation (ply_boot_splash_plugin_t *plugin,
static void static void
on_boot_progress (ply_boot_splash_plugin_t *plugin, on_boot_progress (ply_boot_splash_plugin_t *plugin,
double duration, double duration,
double percent_done) double fraction_done)
{ {
if (plugin->mode == PLY_BOOT_SPLASH_MODE_UPDATES || if (plugin->mode == PLY_BOOT_SPLASH_MODE_UPDATES ||
plugin->mode == PLY_BOOT_SPLASH_MODE_SYSTEM_UPGRADE || plugin->mode == PLY_BOOT_SPLASH_MODE_SYSTEM_UPGRADE ||
@ -1753,7 +1753,7 @@ on_boot_progress (ply_boot_splash_plugin_t *plugin,
* become_idle gets called. * become_idle gets called.
*/ */
if (plugin->mode_settings[plugin->mode].use_end_animation && if (plugin->mode_settings[plugin->mode].use_end_animation &&
percent_done >= SHOW_ANIMATION_PERCENT) { fraction_done >= SHOW_ANIMATION_FRACTION) {
if (plugin->stop_trigger == NULL) { if (plugin->stop_trigger == NULL) {
ply_trace ("boot progressed to end"); ply_trace ("boot progressed to end");
@ -1767,21 +1767,21 @@ on_boot_progress (ply_boot_splash_plugin_t *plugin,
} else { } else {
double total_duration; double total_duration;
percent_done *= (1 / SHOW_ANIMATION_PERCENT); fraction_done *= (1 / SHOW_ANIMATION_FRACTION);
switch (plugin->progress_function) { switch (plugin->progress_function) {
/* Fun made-up smoothing function to make the growth asymptotic: /* Fun made-up smoothing function to make the growth asymptotic:
* fraction(time,estimate)=1-2^(-(time^1.45)/estimate) */ * fraction(time,estimate)=1-2^(-(time^1.45)/estimate) */
case PROGRESS_FUNCTION_TYPE_WWOODS: case PROGRESS_FUNCTION_TYPE_WWOODS:
total_duration = duration / percent_done; total_duration = duration / fraction_done;
percent_done = 1.0 - pow (2.0, -pow (duration, 1.45) / total_duration) * (1.0 - percent_done); fraction_done = 1.0 - pow (2.0, -pow (duration, 1.45) / total_duration) * (1.0 - fraction_done);
break; break;
case PROGRESS_FUNCTION_TYPE_LINEAR: case PROGRESS_FUNCTION_TYPE_LINEAR:
break; break;
} }
update_progress_animation (plugin, percent_done); update_progress_animation (plugin, fraction_done);
} }
} }

Loading…
Cancel
Save