From 6c8bbfbc5681c37eb053cfcf9ec25c5c07e1f021 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 14 Dec 2008 11:17:15 +0000 Subject: [PATCH] Now idles when there is nothing to do. Much less CPUtime use, but the spray is slowed down. We need to improve the handling of Get_input in Gestion_principale. Get_input now returns 1 if something happened, and 0 if not. So we can chose what to do depending on that. We should try not to wait if the operation needs to be asynchronous, but there is no way to know that for now, and it may be quite complex to determine (i think the shade effect can be asynchronous for example, so it'll affect pretty much all operations). The other solution would be to drop events to react to the more recent ones. It would look smoother but the mouse will do strange things. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@378 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- divers.c | 15 ++++++++++----- divers.h | 2 +- moteur.c | 17 ++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/divers.c b/divers.c index 23e42fcf..afde30d4 100644 --- a/divers.c +++ b/divers.c @@ -143,14 +143,14 @@ void Sensibilite_souris(__attribute__((unused)) word X,__attribute__((unused)) w } -void Get_input(void) +int Get_input(void) //Gestion des évènements: mouvement de la souris, clic sur les boutons, et utilisation du clavier. { SDL_Event event; + byte ok; Touche=0; - { - byte ok = 0; + ok = 0; if( SDL_PollEvent(&event)) /* Il y a un évènement en attente */ { @@ -172,10 +172,12 @@ void Get_input(void) INPUT_Nouveau_Mouse_K = 2; } break; + case SDL_MOUSEBUTTONUP: //Bouton souris relaché INPUT_Nouveau_Mouse_K=0; break; + case SDL_KEYUP: { int ToucheR = Conversion_Touche(event.key.keysym); @@ -193,6 +195,7 @@ void Get_input(void) } break; } + case SDL_KEYDOWN: { //Appui sur une touche du clavier @@ -264,6 +267,7 @@ void Get_input(void) break; } } + else return 0; // Il ne s'est rien passé //Gestion "avancée" du curseur: interdire la descente du curseur dans le //menu lorsqu'on est en train de travailler dans l'image @@ -357,7 +361,7 @@ void Get_input(void) // Vidage de toute mise à jour de l'affichage à l'écran qui serait encore en attente. // (c'est fait ici car on est sur que cette fonction est apellée partout ou on a besoin d'interragir avec l'utilisateur) Flush_update(); - } + return 1; // Il y a des choses à faire } @@ -382,8 +386,9 @@ void Wait_VBL(void) SDL_Delay(Delai - (debut % Delai)); // 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() / Delai == debut / Delai) + while (SDL_GetTicks() / Delai <= debut / Delai) { + puts("Waiting..."); SDL_Delay(1); } } diff --git a/divers.h b/divers.h index be14dac7..548eb17f 100644 --- a/divers.h +++ b/divers.h @@ -25,7 +25,7 @@ void Permuter_dans_l_image_les_couleurs(byte Couleur_1,byte Couleur_2); void Remap_general_LOWLEVEL(byte * Table_conv,byte * Buffer,short Largeur,short Hauteur,short Largeur_buffer); void Scroll_picture(short Decalage_X,short Decalage_Y); void Set_mouse_video_mode_number(void); -void Get_input(void); +int Get_input(void); void Set_mouse_position(void); void Attendre_fin_de_click(void); void Sensibilite_souris(word X,word Y); diff --git a/moteur.c b/moteur.c index d409d0ca..fedefc3c 100644 --- a/moteur.c +++ b/moteur.c @@ -446,7 +446,7 @@ void Deplacer_Split(void) Afficher_curseur(); } - Get_input(); + while(!Get_input())Wait_VBL(); } // Effacer la barre en XOR @@ -487,8 +487,8 @@ void Gestion_principale(void) do { - Get_input(); - + if(!Get_input()) + { // Redimensionnement demandé if (Resize_Largeur || Resize_Hauteur) { @@ -844,6 +844,9 @@ void Gestion_principale(void) Afficher_curseur(); } } + } + 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 + // même pour les trucs asynchrones, par exemple le spray. // Gestion de la souris @@ -1475,7 +1478,7 @@ short Attendre_click_dans_palette(struct Fenetre_Bouton_palette * Enreg) for (;;) { - Get_input(); + while(!Get_input())Wait_VBL(); if (Mouse_K==A_GAUCHE) { @@ -1564,7 +1567,7 @@ void Recuperer_couleur_derriere_fenetre(byte * Couleur, byte * Click) do { - Get_input(); + while(!Get_input())Wait_VBL(); if ((Mouse_X!=Ancien_X) || (Mouse_Y!=Ancien_Y)) { @@ -1660,7 +1663,7 @@ void Deplacer_fenetre(short Dx, short Dy) Ancien_X=Nouveau_X; Ancien_Y=Nouveau_Y; - Get_input(); + while(!Get_input())Wait_VBL(); Nouveau_X=Mouse_X-Dx; if (Nouveau_X<0) @@ -1940,7 +1943,7 @@ short Fenetre_Bouton_clicke(void) { short Bouton; - Get_input(); + while(!Get_input())Wait_VBL(); // Gestion des clicks if (Mouse_K)