reset time after some interval

This is a discussion on reset time after some interval within the Game Programming forums, part of the General Programming Boards category; Hello, I working on a game in SDL. I want to reset the timer in every 15 seconds or so. ...

  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    6

    Talking reset time after some interval

    Hello, I working on a game in SDL. I want to reset the timer in every 15 seconds or so. I have tried SDL_GetTicks() but it works fine for first time after that time goes in -tive.



    Thank-you

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    SDL_GetTicks - SDL Documentation Wiki
    How can it be negative when it returns an unsigned number?

    Rather than trying to reset the system tick count (which you're not likely to be able to do, or if you can, there will be consequences), write your own simple wrapper class.

    Something like
    Code:
    class myclock {
      private:
        Uint32 base;
      public:
        myclock() { base = SDL_GetTicks(); }
        reset() { base = SDL_GetTicks(); }
        UInt32 elapsed() { return SDL_GetTicks() - base; }
    };
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sin(x) aproximmation and 2π Interval [-π,π]
    By aggeluska in forum C Programming
    Replies: 5
    Last Post: 11-18-2013, 05:08 PM
  2. Running a procedure repeatedly after a set time interval
    By workisnotfun in forum C++ Programming
    Replies: 4
    Last Post: 05-29-2013, 10:57 PM
  3. Is there a way to reset the bash or zsh idle time?
    By Overworked_PhD in forum Linux Programming
    Replies: 3
    Last Post: 04-06-2009, 09:02 AM
  4. rand interval
    By jarheadhalo in forum C++ Programming
    Replies: 6
    Last Post: 12-02-2006, 12:07 PM
  5. Replies: 2
    Last Post: 02-28-2002, 11:40 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21