Archived

This topic is now archived and is closed to further replies.

gameloop

This topic is 6011 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 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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

//-----------------------------------------------------------------------------
// 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--

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites