Click here to Skip to main content
15,884,176 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: make a timer Pin
Rajesh R Subramanian17-May-10 23:26
professionalRajesh R Subramanian17-May-10 23:26 
JokeRe: make a timer Pin
CPallini17-May-10 23:45
mveCPallini17-May-10 23:45 
AnswerRe: make a timer Pin
Maximilien18-May-10 0:30
Maximilien18-May-10 0:30 
GeneralRe: make a timer Pin
Stephen Hewitt18-May-10 0:35
Stephen Hewitt18-May-10 0:35 
AnswerRe: make a timer Pin
KarstenK18-May-10 1:26
mveKarstenK18-May-10 1:26 
AnswerRe: Here is your count down timer hasani2007 Pin
Software_Developer18-May-10 7:31
Software_Developer18-May-10 7:31 
GeneralRe: Here is your count down timer hasani2007 Pin
Stephen Hewitt18-May-10 14:04
Stephen Hewitt18-May-10 14:04 
AnswerRe: make a timer Pin
Aescleal19-May-10 5:49
Aescleal19-May-10 5:49 
Hi Folks,

nothing like coming late to the party but as no one has mentioned the way most games are written I thought I'd stick me oar in...

In any game the timing is worked into the main dispatch loop. Every cycle around your dispatch loop you grab input, you update the timer, evolve the rest of the system based on how much time has elapsed and then render the game world according to what's happens. It looks something like this:

unsigned last_time = get_current_time_in_ms();

while( true )
{
    /*
       Record who's got keys pressed, where the mouse is, network stuff
     */

    update_IO_state();

    /*
        Sort out how much time has elapsed and how much time we have to evolve the game state over
     */

    unsigned time_now = get_current_time_in_ms();
    unsigned ms_this_loop = time_now - last_time;
    last_time = time_now;

    /*
        Change the state of all the game objects
     */

    evolve( ms_this_loop );

    /*
        Display the changes
     */

    render();
}


All the functions take some additional parameters depending on how you store your game state.

The key point of this lot is that the game hammers along flat out - the thread this is on will eat a CPU. It churns out frames as often as it can and slows down when there's something system intensive happening. Oh, and if you do your IO on another thread make sure everything is synchronised properly or something weird WILL happen, possibly not on your computer but on your first customer's computer.

Hope that helps,

Cheers,

Ash
Questionrecursive function Pin
hasani200717-May-10 22:26
hasani200717-May-10 22:26 
AnswerRe: recursive function Pin
CPallini17-May-10 22:45
mveCPallini17-May-10 22:45 
QuestionRe: recursive function Pin
David Crow19-May-10 3:52
David Crow19-May-10 3:52 
Questionsingel document app cannot recieve WM_KEYDOWN event Pin
dnqhung17-May-10 21:00
dnqhung17-May-10 21:00 
AnswerRe: singel document app cannot recieve WM_KEYDOWN event Pin
Aescleal18-May-10 5:12
Aescleal18-May-10 5:12 
GeneralRe: singel document app cannot recieve WM_KEYDOWN event Pin
dnqhung18-May-10 15:33
dnqhung18-May-10 15:33 
GeneralRe: singel document app cannot recieve WM_KEYDOWN event Pin
Aescleal18-May-10 22:38
Aescleal18-May-10 22:38 
GeneralRe: singel document app cannot recieve WM_KEYDOWN event Pin
dnqhung21-May-10 15:57
dnqhung21-May-10 15:57 
QuestionObtaining the version info of external app [solved] Pin
PaulowniaK17-May-10 19:43
PaulowniaK17-May-10 19:43 
AnswerRe: Obtaining the version info of external app Pin
Stephen Hewitt17-May-10 20:42
Stephen Hewitt17-May-10 20:42 
GeneralRe: Obtaining the version info of external app Pin
PaulowniaK17-May-10 20:50
PaulowniaK17-May-10 20:50 
QuestionProblem with CreateFileMapping() window7/Vista. Pin
janaswamy uday17-May-10 19:41
janaswamy uday17-May-10 19:41 
AnswerRe: Problem with CreateFileMapping() window7/Vista. Pin
hanq_3891013017-May-10 20:59
hanq_3891013017-May-10 20:59 
AnswerRe: Problem with CreateFileMapping() window7/Vista. Pin
Richard MacCutchan17-May-10 21:37
mveRichard MacCutchan17-May-10 21:37 
Questionaudio chat Pin
69917-May-10 17:24
69917-May-10 17:24 
AnswerRe: audio chat Pin
Stephen Hewitt17-May-10 17:33
Stephen Hewitt17-May-10 17:33 
AnswerRe: audio chat Pin
Cedric Moonen17-May-10 20:20
Cedric Moonen17-May-10 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.