Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualblack_darkness

Posted 15 December 2012 - 01:07 PM

I am planning on using this algorithm as a basis for FPS counters in an ALLEGRO game.

I tried to make the variables self explanatory.

This program updates the console every 5 seconds with
lps: Loops per second, and most of the other variables used in the program.

#include<iostream>
#include<time.h>
int main()
{
using namespace std;
#define WAIT 5 //5 seconds
time_t timer_start = time(NULL);
time_t timer_end = timer_start;
time_t prev_timer = timer_start;
unsigned int while_cntr = 0;
unsigned int prev_while_cntr = 0;
unsigned int last_loop = 0;
unsigned int avg_lps = NULL;
unsigned int lps = NULL;
bool go = false;

cout<<"This is a time.h testing program\n\n";

prev_timer = timer_start-timer_end;
while(go==false)
{
  while_cntr++;
  timer_start = time(NULL);
  timer_start = timer_start-timer_end;
  if(timer_start >= prev_timer + WAIT)
  {
   last_loop=while_cntr-prev_while_cntr;
   lps = last_loop/(timer_start-prev_timer);
   avg_lps = while_cntr/timer_start;
   prev_timer=timer_start;
   prev_while_cntr = while_cntr;
   cout<<"lps: "<<lps<<"\n";
   cout<<"avg_lps: "<<avg_lps<<"\n";
   cout<<"timer_start: "<<timer_start<<"\n";
   cout<<"timer_end: "<<timer_end<<"\n";
   cout<<"prev_timer: "<<prev_timer<<"\n";
   cout<<"while_cntr: "<<while_cntr<<"\n";
   cout<<"prev_while_cntr: "<<prev_while_cntr<<"\n";
   cout<<"last_loop: "<<last_loop<<"\n\n";
  }
}
return 0;
}

#1black_darkness

Posted 15 December 2012 - 01:06 PM

I am planning on using this algorithm as a basis for FPS counters in an ALLEGRO game.

I tried to make the variables self explanatory.

This program updates the console every 5 seconds with
lps: Loops per second, and all of the other variables used in the program.

#include<iostream>
#include<time.h>
int main()
{
using namespace std;
#define WAIT 5 //5 seconds
time_t timer_start = time(NULL);
time_t timer_end = timer_start;
time_t prev_timer = timer_start;
unsigned int while_cntr = 0;
unsigned int prev_while_cntr = 0;
unsigned int last_loop = 0;
unsigned int avg_lps = NULL;
unsigned int lps = NULL;
bool go = false;

cout<<"This is a time.h testing program\n\n";

prev_timer = timer_start-timer_end;
while(go==false)
{
  while_cntr++;
  timer_start = time(NULL);
  timer_start = timer_start-timer_end;
  if(timer_start >= prev_timer + WAIT)
  {
   last_loop=while_cntr-prev_while_cntr;
   lps = last_loop/(timer_start-prev_timer);
   avg_lps = while_cntr/timer_start;
   prev_timer=timer_start;
   prev_while_cntr = while_cntr;
   cout<<"lps: "<<lps<<"\n";
   cout<<"avg_lps: "<<avg_lps<<"\n";
   cout<<"timer_start: "<<timer_start<<"\n";
   cout<<"timer_end: "<<timer_end<<"\n";
   cout<<"prev_timer: "<<prev_timer<<"\n";
   cout<<"while_cntr: "<<while_cntr<<"\n";
   cout<<"prev_while_cntr: "<<prev_while_cntr<<"\n";
   cout<<"last_loop: "<<last_loop<<"\n\n";
  }
}
return 0;
}

PARTNERS