Archived

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

program flow and timed events

This topic is 5012 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''m new to game programming, been doing web software and unix system programming for about 5 years. Trying my hand at some "one armed bandit" type games. I''m using managed directx and I have all the display stuff figured out nicely, input handling etc, but I''m missing something when it comes to the correct way to handle time delays. For example, someone clicks the "spin" button, I immediately generate the random numbers for the 3 results, but I don''t want to display them immediately, I want to light up a button for a second, then show each one with a delay between, then some sort of overlay if there is a winning combination or whatever. All the logic is done, graphics displaying etc, but this timing thing is confusing me. I obviously can''t use sleeps because that would destroy the rendering, should I be using threads? Any sites I should be checking or books reading for this kind of information? thanks in advance.

Share this post


Link to post
Share on other sites
Depends on how you''ve partitioned the problem. If the graphical objects have access to the information ( result and current time ) they can then query the current time and display the approritate state, and the logic can all be encapsualted into the graphical object. Such as a single collumn can have 3 states, waiting, spinning, and stopping. The waiting state just displays the last graphic , if there wasn''t one then a random graphic. The spinning would display a animiated spinning graphic, but also check the current time to see if it is greater than the stop time. If it is, it then transitions to the stopped state. The stopped state displays the result graphic. So when you enter the spinning state give it the appropriate spin duration. As the collumn move to the right, the spind duration increases by a factor of X, which will cause them to stop in sequential order.

If you wanted alittle more flexiblity, you an break out the logical element from the graphical elements. This is alittle more involved and proably doesn''t suit your problem. So i would switch with teh single object solution.

Good Luck!

-ddn

Share this post


Link to post
Share on other sites
You could use the High resolution timers (info somwhere in these foums) or the "timeGetTime()" function. Then when an event
occurs, you save the current time. Then each frame you check that saved time against the current time for that frame, and
when a certain amount of time has elapsed you proceed one step
by displaying the next image, and repeat that process until you
have displayed the complete result.

Hope i wasn''t to vague in my description.

Share this post


Link to post
Share on other sites
Use timers and a current time like the previous posters said, but take it even farther and have a currentGameTime. This would be read-only to everything but a specific timeUpdate() routine.

This way objects could time themselves easily (stopTime = currentGameTime + SPIN_TIME) but also gives you full control over the flow of time.

In your timeUpdate(), you could increment currentGameTime by the amount of real time that has passed or you could easily slow or speed it up. All objects should act consistently regardless of how the actual rate of passage of your game time (though you need a timeScaleFactor for interpolation). This also allows you to handle pausing and replays easier.

Share this post


Link to post
Share on other sites