From 3c0a9403018b2744501fe72e5942b476bb467786 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 12 May 2009 18:00:19 +0000 Subject: [PATCH] Removed Wait_VBL. Was only used for slowing down things. Used SDL_Delay(1) instead, which let the OS handle other things. We should get about 10-20ms latency with that. Scrollbars may be slightly faster. The only place where this could be a problem is discontinuous freehand. If the current way it works isn't good, look at the "Chrono" functions (like the spray) instead. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@799 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- buttons.c | 2 +- engine.c | 21 +++++++++------------ help.c | 2 +- misc.c | 23 ++--------------------- misc.h | 1 - operatio.c | 8 ++++---- readline.c | 2 +- 7 files changed, 18 insertions(+), 41 deletions(-) diff --git a/buttons.c b/buttons.c index 8a8be8f5..4b9346d6 100644 --- a/buttons.c +++ b/buttons.c @@ -135,7 +135,7 @@ void Button_Message_initial(void) Display_cursor(); - while(!Mouse_K && !Key) if(!Get_input()) Wait_VBL(); + while(!Get_input()) SDL_Delay(1); if (Mouse_K) Wait_end_of_click(); diff --git a/engine.c b/engine.c index 82b9af99..5c843363 100644 --- a/engine.c +++ b/engine.c @@ -448,7 +448,7 @@ void Move_separator(void) Display_cursor(); } } - if(!Get_input())Wait_VBL(); + if(!Get_input())SDL_Delay(1); } // Effacer la barre en XOR @@ -895,7 +895,7 @@ void Main_handler(void) } } } - else Wait_VBL(); // 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 + else SDL_Delay(1); // 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. // Gestion de la souris @@ -1772,7 +1772,7 @@ short Wait_click_in_palette(T_Palette_button * button) for (;;) { - while(!Get_input())Wait_VBL(); + while(!Get_input())SDL_Delay(1); if (Mouse_K==LEFT_SIDE) { @@ -1858,7 +1858,7 @@ void Get_color_behind_window(byte * color, byte * click) do { - if(!Get_input())Wait_VBL(); + if(!Get_input())SDL_Delay(1); if ((Mouse_X!=old_x) || (Mouse_Y!=old_y)) { @@ -1953,7 +1953,7 @@ void Move_window(short dx, short dy) old_x=new_x; old_y=new_y; - while(!Get_input() && new_x==Mouse_X-dx && new_y==Mouse_Y-dy) Wait_VBL(); + while(!Get_input() && new_x==Mouse_X-dx && new_y==Mouse_Y-dy) SDL_Delay(1); new_x=Mouse_X-dx; @@ -2151,8 +2151,7 @@ short Window_dropdown_on_click(T_Dropdown_button *Button) do { // Attente - if(!Get_input()) - Wait_VBL(); + if(!Get_input()) SDL_Delay(1); // Mise à jour du survol selected_index=Window_click_in_rectangle(2,2,Button->Dropdown_width-2,box_height-1)? (((Mouse_Y-Window_pos_Y)/Menu_factor_Y-2)>>3) : -1; @@ -2198,8 +2197,7 @@ short Window_normal_button_onclick(word x_pos, word y_pos, word width, word heig Display_cursor(); while (Window_click_in_rectangle(x_pos,y_pos,x_pos+width-1,y_pos+height-1)) { - if(!Get_input()) - Wait_VBL(); + if(!Get_input()) SDL_Delay(1); if (!Mouse_K) { Hide_cursor(); @@ -2213,8 +2211,7 @@ short Window_normal_button_onclick(word x_pos, word y_pos, word width, word heig Display_cursor(); while (!(Window_click_in_rectangle(x_pos,y_pos,x_pos+width-1,y_pos+height-1))) { - if(!Get_input()) - Wait_VBL(); + if(!Get_input()) SDL_Delay(1); if (!Mouse_K) return 0; } @@ -2448,7 +2445,7 @@ short Window_clicked_button(void) { short Button; - if(!Get_input())Wait_VBL(); + if(!Get_input())SDL_Delay(1); // Gestion des clicks if (Mouse_K) diff --git a/help.c b/help.c index e4da7e22..9443792a 100644 --- a/help.c +++ b/help.c @@ -88,7 +88,7 @@ void Redefine_control(word *shortcut, int x_pos, int y_pos) Display_cursor(); while (1) { - while(!Get_input())Wait_VBL(); + while(!Get_input())SDL_Delay(1); if (Key==KEY_ESC) return; if (Key!=0) diff --git a/misc.c b/misc.c index 111d3d16..f70959ee 100644 --- a/misc.c +++ b/misc.c @@ -125,7 +125,7 @@ void Wait_end_of_click(void) { // On désactive tous les raccourcis clavier - while(Mouse_K) if(!Get_input()) Wait_VBL(); + while(Mouse_K) if(!Get_input()) SDL_Delay(1); } void Hide_current_image_with_stencil(byte color, byte * stencil) @@ -170,25 +170,6 @@ void Init_chrono(dword delay) return; } -void Wait_VBL(void) -// Attente de VBL. Pour avoir des scrollbars qui ont une vitesse raisonnable par exemple. -// SDL ne sait pas faire, alors on simule un timer qui a une fréquence de 100Hz, -// sans charger inutilement le CPU par du busy-wait (on n'est pas à 10ms près) -{ - 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); - } -} - void Pixel_in_brush (word x,word y,byte color) { *(Brush+y*Brush_width+x)=color; @@ -645,7 +626,7 @@ void Slider_timer(byte speed) end = SDL_GetTicks() + speed*10; do { - if (!Get_input()) Wait_VBL(); + if (!Get_input()) SDL_Delay(1); } while (Mouse_K == original_mouse_k && SDL_GetTicks()