-
FPS Problem, pls help
Im making my own DX8 engine in C++ but I have a small problem in FPS.
You see, when I made my DX8 engine in VB6, I used to get 1800+ fps in an empty window, with just begining/ending the scene. Now, in C++ I get 400 the most!! I use the same FPS code. Somebody help pls!
-
Post the part of the code where you determine the fps, sounds like the VB code is wrong.
-
No, the code is correct. Ive checked it many times. Something is wrong with the C++ version. My code is a regular fps counter, im sure it works. Any ideas? Also, my fullscreen app is 2x or even 3x faster than the windowed one.
-
How are we suppose to know without seeing the code you used? You say something is wrong with the c++ version, try posting that version and then someone could help you. You can't just say that something is wrong, without posting code or giving a little more information.
-
>No, the code is correct. Ive checked it many times.
what are you system specs?
>Also, my fullscreen app is 2x or even 3x faster than the windowed one.
as it very well should be.
-
Ok, this is my code:
Code:
RTTimeServer::RTTimeServer()
{
//Initialize the timer.
if (FAILED(QueryPerformanceFrequency((LARGE_INTEGER*)&g->TimeAndFPS.nFreq)))
g->TimeAndFPS.mInited = false;
g->TimeAndFPS.mInited = true;
}
int RTTimeServer::GetFPS()
{
if (!g->TimeAndFPS.mInited)
return 0;
INT64 ThisCount=0;
INT64 Diff=0;
QueryPerformanceCounter((LARGE_INTEGER*)&ThisCount);
g->TimeAndFPS.mFrameCount++;
Diff = ThisCount - g->TimeAndFPS.lTickCount;
if (Diff >= g->TimeAndFPS.nFreq)
{
g->TimeAndFPS.mFrameRate = g->TimeAndFPS.mFrameCount;
g->TimeAndFPS.mFrameCount =0;
g->TimeAndFPS.lTickCount = ThisCount;
}
return (g->TimeAndFPS.mFrameRate);
}
Im using VC++6. My system is PIII 500, 256 RAM, GF2 MX400 and WinXP with the latest nvidia detonators.
-
Sorry for my n00byness, but thats in C++ write?
-
I think this is your problem you need to set
g->TimeAndFPS.mFrameCount and g->mFrameRate to 0 and you need to set
g->TimeAndFPS.lTickCount to
QueryPerformanceCounter((LARGE_INTEGER*)&lTickCoun t);
in the constructor.
Otherwise g->TimeAndFPS.lTickCount has garbage and when you call getFPS Diff = ThisCount - g->TimeAndFPS.lTickCount;
Diff will also become garbage.
-
Oh yes, you were right about the QueryPerfCounter in the constructor, but now my fps is even lower. This is more correct though I think cause it subtracts the correct time (lTickCount) which was initated in the constructor. But i should get around 2000 fps in windowed mode, right? Like i did in VB6. Also, if I dont clear the screen and perform no DX8 operations, I get around 35000 fps!
-
Here's some code that I wrote that gives me a
fps about 30. I would be really suprised if you could
get your actual game to run at 2000 fps since most games run at 50 or less fps.
Code:
#include <windows.h>
#include <iostream>
using std::cout;
using std::endl;
class Timer {
public:
enum { INVALID_FPS = 0 };
Timer() : frame_count(0), fps(INVALID_FPS), invalid_timer(false)
{
if (FAILED(QueryPerformanceFrequency((LARGE_INTEGER*)&freq)))
invalid_timer = true;
QueryPerformanceCounter((LARGE_INTEGER*)&tick_count);
}
INT64 get_freq() const { return freq; }
// should be called every frame
void set_frame()
{
INT64 count_now;
INT64 diff;
QueryPerformanceCounter((LARGE_INTEGER*)&count_now);
frame_count++;
diff = count_now - tick_count;
if (diff > get_freq()) {
fps = frame_count;
tick_count = count_now;
frame_count = 0;
}
}
int get_fps() const
{
return fps;
}
bool invalid() const { return invalid_timer; }
bool fps_invalid() const { return fps == INVALID_FPS; }
private:
INT64 tick_count;
INT64 freq;
int frame_count;
int fps;
bool invalid_timer;
};
int main()
{
int fps;
DWORD start_time;
Timer timer;
for(;;) {
start_time = GetTickCount();
if (!timer.invalid()) {
timer.set_frame();
if (!timer.fps_invalid()) {
fps = timer.get_fps();
cout << "fps = " << fps << endl;
}
}
while(GetTickCount() - start_time < 33)
continue;
}
return 0;
}
-
Geforce 2 MX400 should run around 30-60 FPS in a 3D game.
-
ok first a window drawing nothing on a mid ro high range system will run at around 450 - 600 fps in windowed and 900 - 1800 in full screen...
but when you start drawing things his will start to drop off significantly.
>But i should get around 2000 fps in windowed mode, right?
no, what are your system specs? what resolution are you drawing in?
if you drawing at 320 - 280 you probably should get 2000 fps in windowed, anything in higher res most likely will not.
>Also, if I dont clear the screen and perform no DX8 operations, I get around 35000 fps!
thats cause you doing nothing.