Click here to Skip to main content
15,907,001 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Nothing else should happen while a while loop is going.. right? Pin
David Crow9-Feb-07 9:35
David Crow9-Feb-07 9:35 
GeneralRe: Nothing else should happen while a while loop is going.. right? Pin
Anthony Mushrow9-Feb-07 9:40
professionalAnthony Mushrow9-Feb-07 9:40 
AnswerRe: Nothing else should happen while a while loop is going.. right? Pin
lafleon9-Feb-07 10:30
lafleon9-Feb-07 10:30 
GeneralRe: Nothing else should happen while a while loop is going.. right? Pin
Anthony Mushrow9-Feb-07 10:43
professionalAnthony Mushrow9-Feb-07 10:43 
GeneralRe: Nothing else should happen while a while loop is going.. right? Pin
#realJSOP9-Feb-07 10:55
professional#realJSOP9-Feb-07 10:55 
GeneralRe: Nothing else should happen while a while loop is going.. right? Pin
Anthony Mushrow9-Feb-07 11:01
professionalAnthony Mushrow9-Feb-07 11:01 
GeneralRe: Nothing else should happen while a while loop is going.. right? Pin
led mike9-Feb-07 11:08
led mike9-Feb-07 11:08 
AnswerRe: Nothing else should happen while a while loop is going.. right? [modified] Pin
Waldermort9-Feb-07 11:41
Waldermort9-Feb-07 11:41 
first how have you declared your timer variable and how are you updating it?

A basic game loop is like this:

volatile int timer = 0; // notice the volatile keyword

bool pause = false;

void mytimerfunc()
{
    // It is best to use a thread to call this
    if ( pause == false )
        timer++;
}

int main()
{
    while ( userwantstoquit == false )
    {
        while ( pause == false && timer > 0 )
        {
            // do you game logic here, calculations, user input and message processing
            // also test if user wants to pause or exit
            if ( userwantstopause )
                pause = true;
            timer--;
        }
        // do all your drawing here
        // this is your idle time
    }
}


Now a short explanation:
look at the while( timer > 0 ) loop. You decrease the counter each time, your timer callback or thread will increase it at your fps rate. Your timer must run on it's own, outside that loop, which means the standard windows timer in no good ( it relies on windows messages ). Because you declare the timer var as a volatile, it means your loop will no stop it from being increased outside the loop.

Don't think of fps as how many times you draw to the screen. It is really how many times you run your logic. Do all your drawing, even offscreen drawing, outside that loop. Drawing takes a long time and should not intefere with the logic. The logic loop is only for calculating. IE if you have a person walking, you calculate their position in the next frame, then when you have to spare you render it to the screen.


-- modified at 17:51 Friday 9th February, 2007
GeneralRe: Nothing else should happen while a while loop is going.. right? [modified] Pin
Anthony Mushrow9-Feb-07 12:09
professionalAnthony Mushrow9-Feb-07 12:09 
Questionillegal use of this type as an expression Pin
hsuch9-Feb-07 8:11
hsuch9-Feb-07 8:11 
AnswerRe: illegal use of this type as an expression Pin
Sceptic Mole9-Feb-07 8:22
Sceptic Mole9-Feb-07 8:22 
GeneralRe: illegal use of this type as an expression Pin
hsuch9-Feb-07 13:43
hsuch9-Feb-07 13:43 
AnswerRe: illegal use of this type as an expression Pin
Chris Losinger9-Feb-07 9:39
professionalChris Losinger9-Feb-07 9:39 
GeneralRe: illegal use of this type as an expression Pin
Michael Dunn9-Feb-07 10:57
sitebuilderMichael Dunn9-Feb-07 10:57 
GeneralRe: illegal use of this type as an expression Pin
Chris Losinger9-Feb-07 11:15
professionalChris Losinger9-Feb-07 11:15 
GeneralRe: illegal use of this type as an expression Pin
Michael Dunn9-Feb-07 11:19
sitebuilderMichael Dunn9-Feb-07 11:19 
QuestionRe: illegal use of this type as an expression Pin
David Crow9-Feb-07 9:42
David Crow9-Feb-07 9:42 
AnswerRe: illegal use of this type as an expression Pin
Michael Dunn9-Feb-07 10:58
sitebuilderMichael Dunn9-Feb-07 10:58 
GeneralRe: illegal use of this type as an expression Pin
hsuch9-Feb-07 16:24
hsuch9-Feb-07 16:24 
QuestionLearning MFC Pin
Alessandra779-Feb-07 7:44
Alessandra779-Feb-07 7:44 
AnswerRe: Learning MFC Pin
Hamid_RT9-Feb-07 7:58
Hamid_RT9-Feb-07 7:58 
GeneralRe: Learning MFC Pin
Alessandra779-Feb-07 8:03
Alessandra779-Feb-07 8:03 
GeneralRe: Learning MFC Pin
Hamid_RT9-Feb-07 8:15
Hamid_RT9-Feb-07 8:15 
AnswerRe: Learning MFC Pin
Mark Salsbery9-Feb-07 8:20
Mark Salsbery9-Feb-07 8:20 
GeneralRe: Learning MFC Pin
Ravi Bhavnani9-Feb-07 8:48
professionalRavi Bhavnani9-Feb-07 8:48 

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.