Choppy framerate without other applications

Started by
8 comments, last by Weston 19 years, 8 months ago
I'm posting this here because it's a DirectX program. The problem that I have is that my application runs choppy by itself. When I start some other Windows applications (Media player, Internet Explorer) and have them run, my program suddenly increases the framerate and it runs smoothly. The only thing I can think of now that would affect this is Windows messages. So here's my main loop:

// Begin main game loop
while (true)
{
	// Handle any messages
	if (PeekMessage(&m_Msg, NULL, 0, 0, PM_REMOVE))
	{
		if (m_Msg.message == WM_QUIT) break;

		TranslateMessage(&m_Msg);
		DispatchMessage(&m_Msg);
	}
	else 
	{
		// Is the application in the foregound?
		if (GameAppActive)
		{
			// Set the timer
			Timer = timeGetTime();
			TimerDifference = Timer - TimerLast;
			TimerLast = Timer;

			// Draw a frame
			if (!(Frame())) break;
		}
		else
		{
			// Wait for messages since it isn't active now
			WaitMessage();
			TimerLast = timeGetTime();
		}
		
		// Seems to eliminate the window covering problem
		Sleep(1);
	}
}
// End main game loop



It looks fine to me, so maybe that isn't the problem. Perhaps there are some graphics settings that would affect it? Any ideas whatsoever are welcome.
---Will DDR for food.
Advertisement
take away the 'else' from the 'if (PeekMessage...'

take away the sleep,


That should do it,

Unfortunately it doesn't help. The if/else code allows windows to completely handle all messages before drawing a frame (The Microsoft recommended way), and the Sleep(1) lets the application sit for a millisecond. For some reason, it gets rid of a problem I had earlier (I would cover the client area of the window with another window, and my computer would bog down horribly slow).

Anything else that someone would want to know about my application?
---Will DDR for food.
I found out that when I use DirectX Audio with my application, it runs smoothly. Maybe this is a threading issue?
---Will DDR for food.
My app has similar issues depending on what you call choppy. Mine kind of... oscelates between fast and slow while windowed. About 1 full fast/slow cycle per second. I figured it was an issue with my design, or some windows quirk; both of which I couldn't likely fix, hence the bug is still there.
Sorry to bring this back up again, but I don't think the problem is with my code now. I've tried other applications that depend on timeGetTime(), and they have the same problem. I'm thinking my clock is corrupted. However, to double check, I have my program ready for download here:

http://members.aol.com/tenk/Boat.zip

It should run perfectly smooth when no other applications are running.

EDIT:
Left/Right: Move camera
Esc/Right Mouse Button: Exit
---Will DDR for food.
>>My app has similar issues depending on what you call choppy. Mine kind of... oscelates between fast and slow while windowed. About 1 full fast/slow cycle per second. I figured it was an issue with my design, or some windows quirk; both of which I couldn't likely fix, hence the bug is still there.<<

Yeah i have that problem to when i run in windowed mode, fullscreen runs fine.
But i dont think it has any relation to timeGetTime, as i dont use it, and i dont use Sleep either.

It doesnt do it all the time, only sometimes, almost at the whyme of windows, which also leads me to believe its not totally my problem.

if anyone would have a direct answer to this....IT WOULD BE GREAT :)!!
Finally found a solution that works!
EDITED
timeBeginPeriod(1);Timer = timeGetTime();timeEndPeriod(1);TimerDifference = Timer - TimerLast;TimerLast = Timer;

I don't know why it works, and I don't give a damn! :)

[Edited by - Weston on August 5, 2004 11:54:57 PM]
---Will DDR for food.
you need to adjust the second timeBeginPeriod(1) to timeEndPeriod(1) like this

timeBeginPeriod(1);
Timer = timeGetTime();
timeEndPeriod(1);

what this does is it increases the precision of timeGetTime to 1ms instead of the default 5ms

check out the msdn reference for timeGetTime

you can find the info in the remarks section
Oops, I thought I had put timeEndPeriod(1) in there. Thanks for catching that, otherwise it may not have been a good thing.
---Will DDR for food.

This topic is closed to new replies.

Advertisement