• Advertisement
Sign in to follow this  

Efficient way to time events in the main loop.

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

Hello. I've been getting away with having a main loop that does everything once every render now, for a while. Heres the problem. I want everything to be timed. For example, I'm working on a multiplayer game, and I can't have any moving faster than any other peolpe, so I need to call Move() once every .05 seconds or so. I also dont want to send directPlay messages every .05 seconds, so I need something else timing to send those every about .5 seconds. I tried using timeGetTime() but it seems like that ate 'way' too much cpu. Is there an efficient way I can do this? Also, I don't want threads. Thanks, Adam

Share this post


Link to post
Share on other sites
Advertisement
Well, the performance timer is teh shitz ;) Look it up.

...and for the "timing", i'd suggest a float or double ;)

like this


Timer timer; // your class using the preformance timer
float moveTimeCounter; // the timing thing...

moveTimerCounter += timer.getDeltaTime();

if(moveTimeCounter >= 0.5f)
{
// move the player

moveTimerCounter -= theTime; // reset the counter
}



Ok, don't bother about naming and stuff, I'm tired ok [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement