FPS Problem, pls help

This is a discussion on FPS Problem, pls help within the Game Programming forums, part of the General Programming Boards category; Im making my own DX8 engine in C++ but I have a small problem in FPS. You see, when I ...

  1. #1
    Unregistered
    Guest

    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!

  2. #2
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Post the part of the code where you determine the fps, sounds like the VB code is wrong.

  3. #3
    Unregistered
    Guest
    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.

  4. #4
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    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.

  5. #5
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    >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.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  6. #6
    Unregistered
    Guest
    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.

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    69
    Sorry for my n00byness, but thats in C++ write?

  8. #8
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    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.

  9. #9
    Unregistered
    Guest
    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!

  10. #10
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    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;
    }

  11. #11
    Registered User
    Join Date
    Jun 2002
    Posts
    69
    Geforce 2 MX400 should run around 30-60 FPS in a 3D game.

  12. #12
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    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.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 06:20 AM
  2. Game update...
    By jdinger in forum Game Programming
    Replies: 14
    Last Post: 11-08-2002, 07:10 AM
  3. SkyLock graphics demo (scrolling, etc.)
    By jdinger in forum Game Programming
    Replies: 9
    Last Post: 06-30-2002, 09:18 PM
  4. Spot the problem..a test question, pls help!
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2002, 01:40 AM
  5. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 08:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21