-
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.
-
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
-
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 :(