Hey.
i''ve been trying to setup my windows callback function in a class, and i have some problems with it.
It seems to work fine, but it is awfully slow.. i mean, so slow, that you can be sure there is some error in the code somewhere... and I''ve been trying to locate the error without any luck.. hoping there is someone who can point it out for me.
i have a class Engine, in which i want to encapsulate the callback function.
I have done it the easy way, by making an intermediary global function.
also, i have only one Engine object that is global too:
Engine* engine
//intermediary rutine to handle windows callback
LRESULT CALLBACK wndCallback( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){
return engine->callback( hWnd, uMsg, wParam, lParam );
}
Now, i have tried to kind''s of message loop, first i tried the non-locking which nehe talks about, where we redraw if there is no new message.
I figured this could be the cause of my slow-down, but when i tried it the other way around( with GetMessage ), performace was just as awful.
Here is both of my callback functions, with all but the loops themself cut out:
PeekMessage:
while( !done ){
if( PeekMessage( &msg, hWnd, 0, 0, PM_REMOVE ) ){
if( msg.message == WM_QUIT )
done = true;
else{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}else{
QueryPerformanceCounter( &now );
delta = ( (float)now.QuadPart / ticksPerSec );
prev = now;
//ENGINE STUFF START
renderer->render();
//ENGINE STUFF END
SwapBuffers( hDC );
}
}
GetMessage version:
while( GetMessage( &msg, hWnd, 0, 0) ){
if( msg.message == WM_QUIT ){
return 0;
}
QueryPerformanceCounter( &now );
delta = ( (float)now.QuadPart / ticksPerSec );
prev = now;
TranslateMessage( &msg );
DispatchMessage( &msg );
renderer->render();
SwapBuffers( hDC );
}
And finally the callback inside my Engine class
LRESULT Engine::callback( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){
switch( uMsg ){
case WM_CLOSE:
PostQuitMessage(0);
return 0;
}
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
Jonas Meyer Rasmussen
meyer@diku.dk