hi! is this how you get the FPS for your game?....
DWORD ticknow = 0, tickdiff = 0, ticklast = 0;
DWORD spritetick = 0;
GameLoop()
{
ticknow = timeGetTime();
tickdiff = ticknow - ticklast;
ticklast = ticknow;
// 1000 / tickdiff = FPS
// to move a sprite every one sec,
spritetick += tickdiff;
if(spritetick >= 1000)
{
// move sprite,
spritick -= 1000;
}
}
it doesn''t seem to work with me,
by the, my fps there shows 50 - 70, however my sprite doesn''t move every sec, it moves faster, thanks!
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
hmm. Should work. TimeGetTime isn''t very accurate though, so you could try using a high res timer. Look up QueryPerformanceCounter and QueryPerformanceFrequency on MSDN
____________________________________________________________
www.elf-stone.com
____________________________________________________________
www.elf-stone.com
____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux
sorry i made a mistake, my sprite moves not fast but very slow...,
so if i made this,
spritetick += tickdiff;
if(spritetick >= 1000)
{
spritePosX++;
spritick -= 1000; // reset sprite tick
}
}
the sprite will not move within a second, but around 4 seconds or so,
ie, the spritetick variable increments by 10 to 30,
what is wrong here?
thanks!
so if i made this,
spritetick += tickdiff;
if(spritetick >= 1000)
{
spritePosX++;
spritick -= 1000; // reset sprite tick
}
}
the sprite will not move within a second, but around 4 seconds or so,
ie, the spritetick variable increments by 10 to 30,
what is wrong here?
thanks!
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
oh and one more thing,
so is this formula correct?
1000 / tickdiff = Frames per second
so is this formula correct?
1000 / tickdiff = Frames per second
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
// FPS calculations __int64 end_count, start_count, dClockFrequency; QueryPerformanceCounter( (LARGE_INTEGER*)&start_count); // Timer related. QueryPerformanceFrequency( (LARGE_INTEGER*)&dClockFrequency ); //glLoadIdentity(); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); pScene->Process(); // FPS calculations again QueryPerformanceCounter((LARGE_INTEGER*)&end_count); //find the time int fps = (int)(1.0f / ((float)(end_count - start_count) / (float)dClockFrequency)); // print fps glColor3f(1, 0, 0); m_pText->DrawText(20, 20, "%d fps", fps); SwapBuffers(((XGLSetup*)m_pRendererSetup)->GetDC());[\source]
-----------
my quote is under construction
-----------my quote is under construction
// FPS calculations __int64 end_count, start_count, dClockFrequency; QueryPerformanceCounter( (LARGE_INTEGER*)&start_count); // You can take this outside not to call each frame QueryPerformanceFrequency( (LARGE_INTEGER* &dClockFrequency ); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); pScene->Process(); // FPS calculations again QueryPerformanceCounter((LARGE_INTEGER*)&end_count); //find the time int fps = (int)(1.0f / ((float)(end_count - start_count) / (float)dClockFrequency)); // print fps glColor3f(1, 0, 0); m_pText->DrawText(20, 20, "%d fps", fps); SwapBuffers(m_hDC);
sorry for the double post
-----------
my quote is under construction
[edited by - mentat on April 19, 2002 12:23:54 PM]
-----------my quote is under construction
quote: Original post by mickey
oh and one more thing,
so is this formula correct?
1000 / tickdiff = Frames per second
Well you''d commented that bit out, so I assumed it wasn''t part of the code. I was talking about the sprite timing bit when I said it should work.
To get FPS you want to divide your frames (1) by your seconds (strangely enough ), so
float FPS = 1.0/(float)(timedif*1000)
You''ll get vastly inaccurate results if you use timeGetTime for that though. You could solve that by calculating the fps across 10 or more frames, or you could use the performance counter (as I suggested above)
____________________________________________________________
www.elf-stone.com
____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux
quote: Original post by mentat
sorry for the double post
You saw the edit button - but you didn''t see the Delete Post check-box??
John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
hi guys i got it working, it was my mistake, anyway pls last question...
why will this statement returns 0?
x = tickDiff / 1000;
// x is now 0
and instead, I need to do this so it will output correctly,
x = tickDiff / 1000.0f;
my tickDiff is
DWORD tickDiff;
thanks guys,
mentat: thanks too for your code, in what way is it better than using timeGetTime() wherin timeGetTime() already returns 1 millisec.,?
why will this statement returns 0?
x = tickDiff / 1000;
// x is now 0
and instead, I need to do this so it will output correctly,
x = tickDiff / 1000.0f;
my tickDiff is
DWORD tickDiff;
thanks guys,
mentat: thanks too for your code, in what way is it better than using timeGetTime() wherin timeGetTime() already returns 1 millisec.,?
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
quote: Original post by mickey
mentat: thanks too for your code, in what way is it better than using timeGetTime() wherin timeGetTime() already returns 1 millisec.,?
timeGetTime returns a value in milliseconds, but it is not accurate to a millisecond.
And depending on the hardware, QueryPerformanceCounter will be accurate to much more than a millisecond (on my machine, QueryPerformanceFrequency tells me that I''m getting 3579545 ticks per second).
John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement