Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualSonicD007

Posted 10 February 2013 - 01:21 PM

#1: You can’t be requesting the current time every time you need a time value. Think about how it affects your inner loop when your time function returns a different value every time it is called. My article gives one example of the problems this can cause, as quoted.
#2: As I mentioned before, clock() is forbidden as a game timer. Use QueryPerformanceCounter() and friend.
#3: Notice that GetRealTime() is called only once per frame. The time since the last update is then calculated and all the timer counters are adjusted by that much. Never get the real time more than once per frame. It’s changing, and nothing related to time should be changing until your next update (actually this is not quite true but I won’t confuse you with the details for now, especially not until you have made a game-suitable time class which is instance-based—never work with global time objects).

 

#1 and 3: I understand the reasoning for this and I will be changing that in my code.  I liked the example you gave on your website about this. (Didn't implement it at the time of writing that code because I didn't think it would impact my testing so much, I was just trying to get the loop going)


 

#2: I looked up sf::Clock (well more like asked on the sfml forums) and it seems sf::Clock does use QueryPerformanceCounter() on windows and the equivalents on mac and linux platforms (so it's a cross platform clock).  That being said, I should be able to use it just fine then as long as I getelapsedmilliseconds once and store it to a variable per frame correct?


 

How would I fix the overflow of next_game_tick?  I would think I'd have to reset it somehow so it doesn't overflow but keep it in a way that it's still correctly getting the next game tick which brings me to another question.  Wouldn't gameTime.getElapsedTime().asMilliseconds() eventually wrap around as well?  (I think I understand the fixed time step and how it works, now it's just these 2 questions and I think I'll have it working.)

 

I appreciate your time everyone, I'm almost there >.<
 

EDIT: 

So this is how the new loop looks

 
const int TICKS_PER_SECOND = 25;
    const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
    const int MAX_FRAMESKIP = 5;
    sf::Clock gameTime;
    //First tick is at 0.0 next tick is at 
    long int next_game_tick = 0;
    int loops;
    float interpolation;
 
    bool game_is_running = true;
    while( game_is_running ) {
        sf::Time curTime = gameTime.getElapsedTime();
        loops = 0;
        while( curTime.asMicroseconds() > next_game_tick && loops < MAX_FRAMESKIP) {
            std::cout << "Updating" << std::endl;
 
            next_game_tick += SKIP_TICKS;
            loops++;
        }
 
        interpolation = float( curTime.asMicroseconds() + SKIP_TICKS - next_game_tick )
                        / float( SKIP_TICKS );
        std::cout << interpolation << std::endl;
    }
    return 0;

#2SonicD007

Posted 10 February 2013 - 09:40 AM

#1: You can’t be requesting the current time every time you need a time value. Think about how it affects your inner loop when your time function returns a different value every time it is called. My article gives one example of the problems this can cause, as quoted.
#2: As I mentioned before, clock() is forbidden as a game timer. Use QueryPerformanceCounter() and friend.
#3: Notice that GetRealTime() is called only once per frame. The time since the last update is then calculated and all the timer counters are adjusted by that much. Never get the real time more than once per frame. It’s changing, and nothing related to time should be changing until your next update (actually this is not quite true but I won’t confuse you with the details for now, especially not until you have made a game-suitable time class which is instance-based—never work with global time objects).

 

#1 and 3: I understand the reasoning for this and I will be changing that in my code.  I liked the example you gave on your website about this. (Didn't implement it at the time of writing that code because I didn't think it would impact my testing so much, I was just trying to get the loop going)


 

#2: I looked up sf::Clock (well more like asked on the sfml forums) and it seems sf::Clock does use QueryPerformanceCounter() on windows and the equivalents on mac and linux platforms (so it's a cross platform clock).  That being said, I should be able to use it just fine then as long as I getelapsedmilliseconds once and store it to a variable per frame correct?


 

How would I fix the overflow of next_game_tick?  I would think I'd have to reset it somehow so it doesn't overflow but keep it in a way that it's still correctly getting the next game tick which brings me to another question.  Wouldn't gameTime.getElapsedTime().asMilliseconds() eventually wrap around as well?  (I think I understand the fixed time step and how it works, now it's just these 2 questions and I think I'll have it working.)

 

I appreciate your time everyone, I'm almost there >.<
 


#1SonicD007

Posted 10 February 2013 - 09:39 AM

#1: You can’t be requesting the current time every time you need a time value. Think about how it affects your inner loop when your time function returns a different value every time it is called. My article gives one example of the problems this can cause, as quoted.
#2: As I mentioned before, clock() is forbidden as a game timer. Use QueryPerformanceCounter() and friend.
#3: Notice that GetRealTime() is called only once per frame. The time since the last update is then calculated and all the timer counters are adjusted by that much. Never get the real time more than once per frame. It’s changing, and nothing related to time should be changing until your next update (actually this is not quite true but I won’t confuse you with the details for now, especially not until you have made a game-suitable time class which is instance-based—never work with global time objects).

 

#1 and 3: I understand the reasoning for this and I will be changing that in my code.  I liked the example you gave on your website about this. (Didn't implement it at the time of writing that code because I didn't think it would impact my testing so much, I was just trying to get the loop going)


 

#2: I looked up sf::Clock (well more like asked on the sfml forums) and it seems sf::Clock does use QueryPerformanceCounter() on windows and the equivalents on mac and linux platforms (so it's a cross platform clock).  That being said, I should be able to use it just fine then as long as I getelapsedmilliseconds once and store it to a variable per frame correct?


 

 


 

 


 

How would I fix the overflow of next_game_tick?  I would think I'd have to reset it somehow so it doesn't overflow but keep it in a way that it's still correctly getting the next game tick which brings me to another question.  Wouldn't gameTime.getElapsedTime().asMilliseconds() eventually wrap around as well?  (I think I understand the fixed time step and how it works, now it's just these 2 questions and I think I'll have it working.)

 

I appreciate your time everyone, I'm almost there >.<
 


PARTNERS