|
From: Emiliano <sky...@fa...> - 2004-02-27 16:44:49
|
First of all, thank you again for your precious hints. ----- Original Message ----- From: "Per Westermark" <pw...@ia...> To: "Emiliano" <sky...@fa...> Cc: <dev...@li...> Sent: Friday, February 27, 2004 4:30 PM Subject: Re: [Dev-C++] WinAPI help... > Unless this is a movie viewer or similar, where the drawed material > requires a fixed frame rate, you shouldn't create the code for a fixed > frame rate, since you can't know the speed of the machine, and amount of > other programs currently needing processing time. No, I need just to update the 3d world at regular time intervals. Of course, the updating function is supposed to be simple and fast. > You might use GetTickCount() to getch which millisecond you started draw. > When the thread has drawn everything, it calls GetTickCount() again. The > difference between these two represents number of used ms. You may then > Sleep(xx-consumed) ms. Call GetTickCount() and check how lock you slept > since all you know is that the program slept >= xx-consumed. > The disadvantage with the above solution is that if the drawing takes >= > allowed time, the machine will spend 100% of available capacity drawing. > You might instead define that it is the sleep time between end of one > frame and start of drawing of next frame that should fixed. Yes, but if I'm not wrong, in this way I could have a very fast world when the scene is simple, and a very slow one when the scene is full of stuff. > You might also use the DirectX methods for drawing your information - they > have functions for synchronizing frame rates. Alas, I don't know how to > program with DirectX in the Dev-C++ environment. I have only tried this > with M$ VC++. I think DX won't work with dev-cpp, uh? :)) > About your "strage" framerate: Windows tries to run threads for full > time slices before swapping. Thread with the timer func: "GetMessage() -> Dispatch()" (the doc says that with a TimerFunc, no message is posted to the thread queue... but I still need GetMessage() for it to work!!!) Thread handling the window: "GetMessage() -> Dispatch()" Thread performing the drawing: "WaitForSingleObject() -> draw()" Two more questions: 1) I have the timer running as HIGHEST priority, main task is normal and drawing task IDLE. Has this something to do with time slices given to each thread? I thougt that with Wait/GetMessage each thread went active only when it had a message waiting... 2) Sometime I press esc, a PostQuitMessage(0); is issued (as the debug output says)... but I must be losing it, since the program goes on!! Or the win thread goes into starvation?? I can't say. thanks again, Emiliano |