1.

Solve : Timer code that doesnt interupts proceedure?

Answer»

How can i write a timer code like the 1 in Visual Basic
Timer code must be in c++
at the moment i am trying to BUILD a game where i am using a timer for running actions
1.This timer code cannot interupts other code proceedue
2.Logical function and other process will be place inside this timer code

i try writting it but when that timer function is running... my other proceedure stops
I KNOW this is because the process stops and it can only be running again when timer code has finish processing
So how can i avoid having other proceedure stop runningUse a thread, not a timer. Of course you don't present any information on what your target platform is, which makes it a bit difficult to offer much more advice than that.

General advice:

1. Don't use a timer.
2. Don't use a timer.
3. And most importantly- don't use a timer.

A GameProc() routine should run as fast as it possibly can, on a separate thread. It will grab a critical section/mutex, update game state, move objects, etc.  Release the mutex/critical section. Each iteration it should post a message to the main thread (which, for most operating systems would be the one managing the UI) to tell it to repaint, Otherwise, the game loop is throttled by the delay the timer has, which for most systems is at least 53 or so milliseconds. The Paint Message HANDLER (or equivalent) would then deal with grabbing a critical section on the various game objects as needed and drawing with them. Depending on the way the gameproc() messes with the gamestate variables SOMETIMES you can shorten critical SECTIONS so that the painting thread can get a word in edgewise.Thanks for replying

My target platform is window PC
I dont know what you mean by use a thread but i will look it up
Thanks



Discussion

No Comment Found