Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. long start_time, end_time, elapsed, deltat, Now, lastUpdate;
  5.  
  6. int deltah = 0;
  7.  
  8. int main()
  9. {
  10.     start_time = clock();
  11.  
  12.     while(1) {
  13.         end_time = clock();
  14.         elapsed = (end_time - start_time); //Czas od rozpoczęcia programu w milisekundach
  15.        
  16.         Now = elapsed;
  17.         deltat = (Now - lastUpdate); //Obliczenie czasu wykonywania się pętli
  18.        
  19.         if(deltat == 0) //Ten kod wymusza, aby dalsza część kodu wykonywała się co najmniej co 1ms
  20.             continue;
  21.        
  22.         lastUpdate = Now;
  23.        
  24.         deltah += deltat; //deltah to suma każdego czasu wykonania pętli
  25.        
  26.         if(deltah >= 40) {
  27.             printf("%d\n", deltah); //Biorąc pod uwage powyższe operacje, kod powinien się wykonywać co 40ms
  28.             deltah = 0;
  29.         }
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement