Function for calculate FPS

Strictly for discussing ZSNES development and for submitting code. You can also join us on IRC at irc.libera.chat in #zsnes.
Please, no requests here.

Moderator: ZSNES Mods

Post Reply
hernaldo

Function for calculate FPS

Post by hernaldo »

Hello
i'm build a simple emulator, it works, but very slow. I use C# with SDL. net.

i know that the emulator must run to 60 fps, but i like wirte a function that calculate the fps. Any Help in C/C++ that guide to me?

thanks,

bye
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Post by Nach »

Take the system time each time you render a frame, see much how much you're averaging rendering per second.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
blargg
Regular
Posts: 327
Joined: Thu Jun 30, 2005 1:54 pm
Location: USA
Contact:

Post by blargg »

Count the number of frames that occur within a one-second interval. The result is the frames per second. :)
AamirM
Regen Developer
Regen Developer
Posts: 533
Joined: Sun Feb 17, 2008 8:01 am
Contact:

Post by AamirM »

The following is used in Regen/GTK+:

Code: Select all

int do_fps = 0;
static void display_fps(int frames_rendered)
{
	static time_t fpstimer;
	static unsigned int previous_frames;
	static time_t temptime;
	static double fps;
	static char fpsstring[8];
	static struct tms tm;

	if(do_fps < frames_rendered)
	{
		temptime = times(&tm);
		fps = (double)(frames_rendered - previous_frames) * 100 / (temptime - fpstimer);
		snprintf(fpsstring, 7, "%2.2lf", fps);

		fpstimer = temptime;
		previous_frames = frames_rendered;
		do_fps = frames_rendered + 30;
	}

	// Display fpsstring here
}
Just make a counter to count the number of frames rendered so far and pass it to this function.

You will need to convert it to C# yourself.
hernaldo

Post by hernaldo »

thanks a lot!
Post Reply