• Popular Now

• 12
• 9
• 9
• 13
• 10

Archived

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

Timer with minimal code

This topic is 6455 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

This may sound like a complete newbie question, but how can I implement a timer with minimal code? I bascially want to have an update function called several times per second. Back in the days of djgpp w/ allegro, this would have been easy to implement, and with very little code. How can this be done in Windows?

Share on other sites
Here is an example I found in a book.
  //1. In the header file, specify the ID of the timer.#define MY_TIMER 1//2. Create the timer.int nTimer = SetTimer(hWnd, MY_TIMER, 1000, NULL);//3. In the window procedure, process the timer messages.case WM_TILER: switch(wParam) { case MY_TIMER: //Do something here. break; }break;

This is not a very good way of doing it, but it is simple.

#define MY_LIFE BUSY

Edited by - The_C_Guy on July 15, 2000 11:17:11 PM

Share on other sites
or if you want to lock it.
  DWORD game_time;DWORD nTimel;while(!done){nTime=GetTickCount();...//game loop stuffwhile(GetTickCount()-nTime<33);//30 fps, can be changed}

JoeMont001@aol.com www.polarisoft.n3.net

Share on other sites
Thanks, that seemed to work nicely. I guess I wouldn''t have to ask newbie questions like this if I bought a few good books, but I prefer to waste all of my money on games

Share on other sites
Make a timer class . Things will be very simple once your done with it - which really isn''t a hard task. I''ll send you one if you want it.

"Paranoia is the belief in a hidden order behind the visible." - Anonymous

Share on other sites
dont suppose i could have a copy please staffan?

pete@jumblesoftware.com

Share on other sites
Right now, I''m only using this for a relatively small project (just a screensaver), and I really only needed one timer. But if I ever do anything more complex, I''ll make sure that everything is done with reusable classes (that''s what OOA/OOD/OOP is all about, right?)

Share on other sites
quote:
Original post by Staffan

Make a timer class . Things will be very simple once your done with it - which really isn't a hard task. I'll send you one if you want it.

"Paranoia is the belief in a hidden order behind the visible." - Anonymous

Is this class cross-platform?

I'm looking for something that's applicable whether I'm on Be, Linux, or DOS.

my email is wrenhal@juno.com

B e S
It's Da BOMB Baby!!!
<!-- It's Da BOMB Baby!!! -->

Edited by - wrenhal on July 17, 2000 4:28:08 PM