• Advertisement
Sign in to follow this  

Game freeze...

This topic is 4920 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I'm working on a 3D game in OGL using MFC as API. Everything runns smooth except that once a second (more or less exact) the execution freezes for a brief short of time. It's not long, but enough to notice and to be anoying. I have no clue what is causing this so any input would be helpful. The main game loop looks like this.
int c_gameapp::Run()
{
	MSG msg;
	bool perf_count, exitapp=false;
	__int64 freq, last_time, cur_time;
	LARGE_INTEGER tmpli;
	double time_fact, time_span;

	if(::QueryPerformanceFrequency(&tmpli))
	{
		perf_count=true;
		freq=tmpli.QuadPart;
		time_fact=1.0/freq;
		::QueryPerformanceCounter(&tmpli);
		last_time=tmpli.QuadPart;
	}
	else
	{
		perf_count=false;
		time_fact=0.001;
		last_time=timeGetTime();
	}


	while(true)
	{
		if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
		{
			if(!GetMessage(&msg,NULL,0,0))
			{
				ExitInstance();
				return (int)msg.wParam;
			}

			if(!PreTranslateMessage(&msg) )
			{
				TranslateMessage(&msg); 
				DispatchMessage(&msg);
			}
		}
		else
		{
			if(m_viewport->IsWindowEnabled() && !exitapp)
			{
				if(perf_count)
				{
					::QueryPerformanceCounter(&tmpli);
					cur_time=tmpli.QuadPart;
				}
				else
					cur_time=timeGetTime();

				time_span=(cur_time-last_time)*time_fact;
				last_time=cur_time;

				if(time_span>0)
				{
					if(!m_game.Tick((float)(time_span)))
					{
						::PostQuitMessage(0);
						exitapp=true;
					}
					m_viewport->Flip();
				}
			}
		}
	}

	//return CWinApp::Run();
}


Share this post


Link to post
Share on other sites
Advertisement
2 possibilities that come to mind are either A) You are playing the sound synchronously and execution waits till playback is complete (PlaySound() in winapi does this by default I think) or B) Your sound isn't cached in memory and needs to be loaded from disk when you play it. So look into asynchronous playback or pre-loading your sounds if those are the problem.

Some unsolicited advice is to stay away from MFC if you are doing a real-time, non turn-based game. Either use directx/opengl/winapi directly or some intermediary like SDL.

Share this post


Link to post
Share on other sites
Thank you for your thoughts...

The sound is not the issue (since I did not include soundparts in the test).

I thought of using the standard API instead, but I know MFC better and it has always worked before... :] However, I will probably test it at least.

More info:
* The problems seems to only appear when a key is pressed (and held down) to move the cam.
* The problem does not occur on all computers (but both on NVIDIA and ATI).

Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement