How I can count the FPS of my game?

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
eteream
Very interested
Posts: 81
Joined: Tue Dec 22, 2009 2:13 pm

How I can count the FPS of my game?

Post by eteream » Fri Feb 26, 2010 7:55 pm

Well, just that!

I'm thinking to use a frame counter on screen & do an average for a minute. There is a more easy way? There is an emulator which can tell me that?

I'm using C, and I can use asm with no problem; and of course I can download any free software or doing whatever necessary.

A note for outsiders: there is no real time clock (or any other timer) on MD. Yes, the yamaha sound chip has one, but is useful only for short periods of time (I think!).

MottZilla
Interested
Posts: 40
Joined: Mon Feb 08, 2010 9:54 pm

Post by MottZilla » Fri Feb 26, 2010 10:27 pm

I would guess you'd need to keep track of each NMI (frame rendered) and if your game engine was done calculating everything and got your video update in place in time, you'd mark that as a frame rendered and not missed. You could do this for groups of 60 frames, so you could see during various points in your game if the frame rate drops and by how many frames. Ofcourse the ironic part is that your frame rate counting and display will cause a small performance hit itself.

You definitely don't want to average a minute. I would do sets of 60 frames so every second you'd get an updated number on screen. Not too short but not too long of a sample either. Really you just want to know how often you are running out of time.

I doubt any emulator can do anything like this for you. But it shouldn't be hard to keep track of frames gone by in the set and frames that were ready on time. That way you'd have 60/60 frames were ready or say 45/60 frames were ready on time causing a 25% slowdown/missed frames.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sat Feb 27, 2010 3:32 am

This is how I do it in DC Doom.

Code: Select all

static void video_do_fps (uint32 *base, int yoffset)
{
    static unsigned int last_frames = 0;
    static int secs = 0;
    static int ifps = 0;
    char fps[8];
    int curr_ticks = I_GetTime();

    if (curr_ticks / 35 != secs)
    {
        ifps = (int)(total_frames - last_frames);
        last_frames = total_frames;
        secs = curr_ticks / 35;
    }

    sprintf(fps, "%d", ifps);
	bfont_set_fgcolor(0xFFFFFF);
	bfont_draw_str((uint16 *)((uint32)vram_l + 48 + 24 * lineBytes), lineWidth, 0, fps);
}
I_GetTime() returns the number of ticks since the game started, where there are 35 ticks per second. So the routine basically checks if a second has elapsed, then prints the current frame count - the previous frame count. Since it does this once a second, that values is the frames for the last second. So I get an average frames per second updated at one second intervals.

Note - the routine is called in the frame update routine, so it's accurate to 1/instantaneous frame rate. It's close enough and easy to do.

For something like the Genesis, I wouldn't do a divide, I'd have a counter advanced by the vertical blank handler. Every 50/60 vertical blanks, I'd update the ifps variable. Something like that.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Sat Feb 27, 2010 8:52 pm

Here's the code of the getFPS() function grab from mini devkit :

Code: Select all

u32 getFPS()
{
    static u32 framecnt;
    static u32 last;
    static u32 result;
    u32 current;
    u32 vcnt;

    vcnt = GET_VCOUNTER;
    if (vcnt >= 224) vcnt -= 224;
    else vcnt += (255 - 224);
    current = (vtimer << 8) + vcnt;

	if ((current - last) > 2000)
    {
        u32 base;

        if (ISPALSYSTEM) base = 50;
        else base = 60;
        result = ((base << 8) * framecnt) / (current - last);
        last = current;
        framecnt = 1;
    }
	else framecnt++;

	return result;
}
vtimer is a counter increment at each VINT

eteream
Very interested
Posts: 81
Joined: Tue Dec 22, 2009 2:13 pm

Post by eteream » Sat Feb 27, 2010 11:41 pm

Thanks guys! I will read it tomorrow, now i-m exhausted...

Post Reply