Advertisement
KDOXG

framecounter example

May 7th, 2021
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <fstream>
  4. #define FRAME_RT 0.0333333f             //this is 1 divided by 30, each time stamp for 30 FPS
  5.  
  6. int main()
  7. {
  8.     std::ofstream f("check.txt");       //check with word count after you run the code
  9.     int a, b;
  10.     time_t clk;
  11.     while (clock() < CLOCKS_PER_SEC)    //count until 1 second
  12.     {
  13.         clk = clock();
  14.         a = 25; b = 70;
  15.        
  16.         for (int i = 0; i < 100; i++) {a = a^b; b = a^b; a = a^b;}  //whatever, just process test
  17.        
  18.         f << "FPS ";    //frame indicator
  19.        
  20.         while((float)(clock() - clk) / CLOCKS_PER_SEC < FRAME_RT);  //wait until 1/30 of a second
  21.     }
  22.     f.close();
  23.     return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement