• Advertisement
Sign in to follow this  

What do you think of this Loop per second Program?

This topic is 1861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

[CODE]
#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;
}
[/CODE] Edited by black_darkness

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement