gameloop

Started by
4 comments, last by JL 22 years, 9 months ago
Hi I want anyone to write a simple game/message-loop for me in VC++. I have tried lots of times, but I can''t get ahead with it. If I use GetMessage the loop waits for message to be retrieved, if I use PeekMessage the loop does''nt retrieve any message. This is the problem I got, the loop works well else. function updateFrame() is processed in the loop, where the objects is showed and their positions is changed. Please help me with this! Thanks /J Lindroos
/J Lindroos
Advertisement
this is what my loop looks like:

//all other initialization here
while(1)
{
int t = PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
if (t)
{
if (!GetMessage (& msg, NULL, 0, 0))
return msg.wParam;
TranslateMessage (&msg);
DispatchMessage (&msg);
}
else if (ActiveApp)
{
//PROCESS ALL INPUT HERE
//DRAW ALL GRAPHICS HERE
}
else if (!ActiveApp)
WaitMessage();
}
}
//end of the program here
is that what you wanted? if so i hope that helps, later
//-----------------------------------------------------------------------------// WINMAIN//-----------------------------------------------------------------------------int WINAPI WinMain(	HINSTANCE hinstance,					HINSTANCE hprevinstance,					LPSTR lpcmdline,					int ncmdshow){	WNDCLASS winclass;		// this will hold the class we create	HWND	 hwnd;			// generic window handle	MSG		 msg;			// generic message	//HDC      hdc;			// generic dc	//PAINTSTRUCT ps;		// generic paintstruct	// first fill in the window class stucture	winclass.style			= CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;	winclass.lpfnWndProc	= WindowProc;	winclass.cbClsExtra		= 0;	winclass.cbWndExtra		= 0;	winclass.hInstance		= hinstance;	winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);	winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);	winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);	winclass.lpszMenuName	= NULL; 	winclass.lpszClassName	= WINDOW_CLASS_NAME;	// register the window class	if (!RegisterClass(&winclass))		return(0);	// create the window, note the use of WS_POPUP	if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME,			// class								"LINK Game Engine",			// title								WS_POPUP | WS_VISIBLE,								0,0,						// x,y								WINDOW_WIDTH,				// width								WINDOW_HEIGHT,				// height								NULL,						// handle to parent 								NULL,						// handle to menu								hinstance,					// instance								NULL)))						// creation parms		return(0);	// save the window handle and instance in a global	main_window_handle = hwnd;	main_instance      = hinstance;	// perform all game console specific initialization	gameInit();	// enter main event loop	while(1)	{		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))		{ 			// test if this is a quit	        if (msg.message == WM_QUIT)	           break;				// translate any accelerator keys			TranslateMessage(&msg);			// send the message to the window proc			DispatchMessage(&msg);		}	// end if    	    // main game processing goes here	    gameMain();	} // end while	// shutdown game and release all resources	gameShutDown();	// return to Windows like this	return(msg.wParam);} // end WinMain 


-Coleco

~ c o l ec o ~



Rock the cradle of love!
You stupid WANKER!
S i g n a l D E V .com

--HASBRO SUCKS--
Rock the cradle of love! You stupid WANKER!
OK, thanks guys, I think you have helped me a lot, I''ll reply if I will get any problems when tested.

Best Regards
/J Lindroos
/J Lindroos
I hope you know Windows Programming...

---------------------------------------
"When I lie, I am telling the truth"
I am in the start but I know what I need to know.
I know how to do the messageloop, but when it came to the game everything stopped to work.

Both your loops worked, so thanks guys!
Best Regards
/J Lindroos
/J Lindroos

This topic is closed to new replies.

Advertisement