Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. #include <a_samp>
  2. #define ROUNDS 100
  3. forward TimerCallback();
  4.  
  5. new timer_id = -1;
  6. new tick = 0;
  7. new tick_differential = 0;
  8. new last_tick = 0;
  9. new tick_counter = 0;
  10. new Float:tick_average = 0.0;
  11. new tick_goal = 1000;
  12. new caught_min = 10000;
  13. new caught_max = 0;
  14. new tick_catcher[ROUNDS];
  15.  
  16. public OnGameModeInit() {
  17.     last_tick = GetTickCount();
  18.     timer_id = SetTimer("TimerCallback", tick_goal, 1);
  19.     return 1;
  20. }
  21.  
  22. public TimerCallback() {
  23.     tick = GetTickCount();
  24.     tick_differential = (tick - last_tick) - tick_goal;
  25.  
  26.     if(tick_differential < 0 || tick_differential > ROUNDS-2) {
  27.         tick_catcher[ROUNDS-1]++;
  28.     } else {
  29.         tick_catcher[tick_differential]++;
  30.     }
  31.  
  32.     if(tick_differential < caught_min)
  33.         caught_min = tick_differential;
  34.     if(tick_differential > caught_max)
  35.         caught_max = tick_differential;
  36.  
  37.     tick_counter++;
  38.     tick_average = tick_average + ((tick_differential - tick_average) / (tick_counter + 1.0));
  39.  
  40.     last_tick = tick;
  41.  
  42.     printf("Tick: %d", tick);
  43.     printf("Tick diff: %d", tick_differential);
  44.     printf("Tick avg: %f", tick_average);
  45.     print("================");
  46.  
  47.     if(tick_counter > ROUNDS) {
  48.         showResults();
  49.     }
  50.     return 1;
  51. }
  52.  
  53. showResults() {
  54.     KillTimer(timer_id);
  55.  
  56.     print("================");
  57.     print("================");
  58.     print("================");
  59.    
  60.     new string[256];
  61.     for(new i = 0; i < ROUNDS; i++) {
  62.         if(i < caught_min || i > caught_max)
  63.             continue;
  64.  
  65.         if(i >= 10)
  66.             format(string, sizeof(string), "%s%d,", string, i);
  67.         else
  68.             format(string, sizeof(string), "%s0%d,", string, i);
  69.     }
  70.     printf("%s", string);
  71.     format(string, sizeof(string), "");
  72.  
  73.     for(new i = 0; i < ROUNDS; i++) {
  74.         if(i < caught_min || i > caught_max)
  75.             continue;
  76.  
  77.         new l = tick_catcher[i];
  78.         if(l >= 10)
  79.             format(string, sizeof(string), "%s%d,", string, l);
  80.         else
  81.             format(string, sizeof(string), "%s0%d,", string, l);
  82.     }
  83.     printf("%s", string);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement