kenobi
8/29/2015 10:23:00 PM
This is extremally important question to me, though i doubt if many people are able to fully answer this, lets see
assume you got winapi classic WinMain()
app (like small game drawing by gdi, something like that)
you got a loop there
for(;;)
{
GameStateProcessing();
MessagePump();
Sleep(10);
}
you do your game data processing,
then call message pump classic code
(mine looks like that
for(;;)
{
/* EVENTS
*/
static int done = 0;
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
if(!GetMessage(&msg, NULL, 0,0)) done = 1;
else
TranslateMessage(&msg),
DispatchMessage(&msg);
if(done) break;
//.........
}
then yet you have a sleep
(may assume for example that game processing takes 10 ms, message pump part probably is quick so, all loop 'turn' takes 20 ms so game works at 50 Hz)
THE TWO IMPORTANT QUESTIONS
1) I got WndProcedure callback with my own code there.. May I assume that this procedure is called by the MessagePump part (though indirectly i call some api call, which calls my callback back) ?
Which one api call executes it? (I mean which api call executes my callback)
Is it Dispatchmessage()?
2) Not only my ap but System needs
to be handled too.. If so i thing something that i may call virtually
SystemDoYourOwnWorkForAWhileThenBack()
must be called regurally and i wonder
when it is called.. (what rules plays here)
I wonder if this something like preempting my app by bruteforce (by freezing by some interrupt in half of the routines) in regular time periods base (I do not notice such behaviour when i measure frame times by timer)
or this is maybe done when i call
Sleep() - (Sleep could be potentially
used here i think, but i dont know how it works), (or maybe some message pump appi takes opportunity that app regullary gives avay cpu for a while then do some system work there?)
what if some app do not call Sleep?
Then all cpu would be consumed and
if no MessagePump would call system task it would have to be preempted by force
(but i am only speculating here)
How it is done?
TNX