Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

What do you think of this Loop per second Program?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 black_darkness   Members   

280
Like
0Likes
Like

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 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;
}

Edited by black_darkness, 15 December 2012 - 01:07 PM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.