Archived

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

Curious about timers

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

I must say the tutorials are excellent!!! I''m up to tutorial lesson 21 now and I am curious about something. Is there anything wrong with using windows timers instead of putting in the pause stuff like the tutorial? What I mean is: ---------------------------------- #include "time.h" ... //After you''re done setting up and displaying the window... SetTimer(hWnd,1,milliseconds,(TIMERPROC) DrawGLScene); //This allows you to cause the scene to draw every so many milliseconds. You can manipulate your enemies in another SetTimer that runs at a slower rate. The rate will not increase on a faster machine. //Instead of calling this, make it a callback VOID CALLBACK DrawGLScene(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime) { ... } //In WinMain, instead of PeekMessage(&msg,NULL,0,0,PM_REMOVE) //use GetMessage(&msg, NULL, 0, 0) ---------------------------------- Any thoughts on this? Seems like games wouldn''t use very much CPU if you did it this way. --solo

Share this post


Link to post
Share on other sites
Well, as far as I know... There''s nothing wrong with that, except for the fact that timing in windows message loop is not really "accurate". You won''t get a precise 1 milliseconds out of that. Most of the time you can notice the difference quite easily. People usually use another timing method and I suggest you looking at the article section. You''ll find what you really need there.

Share this post


Link to post
Share on other sites
You won''t get faster than 50 millisecond messages out of SetTimer, even if you pass in a value less than 50. SetTimer wasn''t designed for that resolution, it was designed for times in the 0.5 seconds and higher. So, at the fastest rate of 50 ms, you max out at 20 fps. I know, because that''s how I initially did my projects until I found NeHe and saw how he was doing it, which is much more effective (but like you say, hammers the CPU pretty good). What I do now is basically NeHe''s run-loop, but if I want to be nicer to the CPU, I put a Sleep(5) or similar right after my call to my render function, which yields the CPU to background tasks. This way, you can keep your fps way up (although not WAY up), and still be nice to the CPU.

Share this post


Link to post
Share on other sites