diff --git a/buttons.c b/buttons.c index 90105156..9606662a 100644 --- a/buttons.c +++ b/buttons.c @@ -135,7 +135,7 @@ void Button_Message_initial(void) Display_cursor(); - while(!Get_input() && !Mouse_K && !Key) SDL_Delay(20); + while(!Mouse_K && !Key) if(!Get_input()) SDL_Delay(20); if (Mouse_K) Wait_end_of_click(); diff --git a/engine.c b/engine.c index c8f54883..40b5676b 100644 --- a/engine.c +++ b/engine.c @@ -895,8 +895,24 @@ void Main_handler(void) } } } - else SDL_Delay(20); // S'il n'y a pas d'évènement, on ne gère pas tout ça et on attend un peu. La partie en dessous doit être exécutée quand - // même pour les trucs asynchrones, par exemple le spray. + else + { + // No event : we go asleep for a while, but we try to get waked up at constant intervals of time + // no matter the machine speed or system load. The time is fixed to 10ms (that should be about a cpu slice on most systems) + // This allows nice smooth mouse movement. + const int delay = 10; + + Uint32 debut; + debut = SDL_GetTicks(); + // Première attente : le complément de "delay" millisecondes + SDL_Delay(delay - (debut % delay)); + // Si ça ne suffit pas, on complète par des attentes successives de "1ms". + // (Remarque, Windows arrondit généralement aux 10ms supérieures) + while ( SDL_GetTicks()/delay <= debut/delay) + { + SDL_Delay(1); + } + } // Gestion de la souris diff --git a/operatio.c b/operatio.c index 0e7667aa..a1454ef4 100644 --- a/operatio.c +++ b/operatio.c @@ -39,6 +39,9 @@ #define M_PI 3.14159265358979323846 #endif +/// Time (in SDL ticks) when the next airbrush drawing should be done. Also used for discontinuous freehand drawing. +Uint32 Airbrush_next_time; + void Start_operation_stack(word new_operation) { Brush_rotation_center_is_defined=0; @@ -300,7 +303,7 @@ void Freehand_mode2_1_0(void) Operation_push(Paintbrush_X); Operation_push(Paintbrush_Y); Print_coordinates(); - SDL_Delay(20); + Airbrush_next_time = SDL_GetTicks() + Airbrush_delay*10; } @@ -319,18 +322,22 @@ void Freehand_mode2_1_2(void) if ( (start_x!=Paintbrush_X) || (start_y!=Paintbrush_Y) ) { - Hide_cursor(); - // On affiche définitivement le pinceau - Display_paintbrush(Paintbrush_X,Paintbrush_Y,Fore_color,0); - Display_cursor(); Print_coordinates(); - SDL_Delay(20); + if (SDL_GetTicks()>Airbrush_next_time) + { + Airbrush_next_time+=Airbrush_delay*10; + Hide_cursor(); + // On affiche définitivement le pinceau + Display_paintbrush(Paintbrush_X,Paintbrush_Y,Fore_color,0); + Display_cursor(); + } } Operation_push(Paintbrush_X); Operation_push(Paintbrush_Y); } +// ---------- void Freehand_mode2_2_0(void) // Opération : OPERATION_DISCONTINUOUS_DRAW @@ -342,12 +349,12 @@ void Freehand_mode2_2_0(void) Init_start_operation(); Backup(); Shade_table=Shade_table_right; - // On affiche définitivement le pinceau - Display_paintbrush(Paintbrush_X,Paintbrush_Y,Back_color,0); Operation_push(Paintbrush_X); Operation_push(Paintbrush_Y); Print_coordinates(); - SDL_Delay(20); + Airbrush_next_time = SDL_GetTicks() + Airbrush_delay*10; + // On affiche définitivement le pinceau + Display_paintbrush(Paintbrush_X,Paintbrush_Y,Back_color,0); } @@ -366,12 +373,15 @@ void Freehand_mode2_2_2(void) if ( (start_x!=Paintbrush_X) || (start_y!=Paintbrush_Y) ) { - Hide_cursor(); - // On affiche définitivement le pinceau - Display_paintbrush(Paintbrush_X,Paintbrush_Y,Back_color,0); - Display_cursor(); Print_coordinates(); - SDL_Delay(20); + if (SDL_GetTicks()>Airbrush_next_time) + { + Airbrush_next_time+=Airbrush_delay*10; + Hide_cursor(); + // On affiche définitivement le pinceau + Display_paintbrush(Paintbrush_X,Paintbrush_Y,Back_color,0); + Display_cursor(); + } } Operation_push(Paintbrush_X); @@ -2042,7 +2052,6 @@ void Curve_3_points_12_11(void) ///////////////////////////////////////////////////////////// OPERATION_AIRBRUSH -Uint32 Airbrush_next_time; void Airbrush_1_0(void) // // Opération : OPERATION_AIRBRUSH