Thread: Tick-based time ?

  1. #1
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209

    Tick-based time ?

    Hey,

    I'm writing a tick-based game ( a game that develops in realtime ). However, the program won't be running 24/7, but I still want it to develop as if that number of hours had gone by when it is launched again. Is there a useful function that can access the computer's internal clock, or something of the sort ? Thanks.

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    This should get you started:
    Code:
    #include <ctime>
    
    using namespace std;
    
    int main (int argc, char** argv)
    {
      time_t rawtime;
      struct tm * timeinfo;
    
      time ( &rawtime );
      timeinfo = localtime ( &rawtime );
    
       // Manipulate timeinfo
       return 0;
    }
    You should store rawtime each time the game is run, and retrieve it once the user starts the game again. Once you read in this value, feed it into a tm struct (like shown above) and manipulate its members. tm struct reference: http://www.cplusplus.com/ref/ctime/tm.html

  3. #3
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    Thanks for the structure, I found it in time.h, but couldn't make any sense of it.

    A few questions :

    1. time_t is typedefed as a long *, therefore time_t rawtime; creates a long * with name rawtime, correct ?

    2. What's the pointer to a structure for, and how is it used ?

    3. What's the function time(___) do, and what would time(&rawtime) do ?

    4. What's the localtime function ?


    Sorry about this, but I can't make any sense of it from time.h, and the explanations I found on some websites just don't help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers
    By Big_0_72 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 07:51 PM
  2. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  3. Time conversions
    By mariabair in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2004, 04:55 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM