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!).
How I can count the FPS of my game?
Moderator: BigEvilCorporation
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.
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.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
This is how I do it in DC Doom.
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.
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);
}
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.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Here's the code of the getFPS() function grab from mini devkit :
vtimer is a counter increment at each VINT
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;
}