Feb 4, 2012 at 6:22pm UTC
I'm in the process of making a game that needs rather accurate time measurement, but I don't know how to measure time. I also need some random numbers, but I don't know the syntax for seeding with srand.
Feb 4, 2012 at 6:37pm UTC
SFML provides both time and random functionality, amongst a number of other things relevant to game programming.
Feb 4, 2012 at 7:02pm UTC
Here's a simple program that gets the current time and date and prints it out to the console. Feel free to use it for your reference. :)
1 2 3 4 5 6 7 8 9 10 11 12
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
time_t now(time(false ));
tm *localtm(localtime(&now));
cout << localtm->tm_hour << ":" << localtm->tm_min << ":" << localtm->tm_sec << endl;
cout << localtm->tm_mon + 1 << "/" << localtm->tm_mday << "/" << localtm->tm_year + 1900 << endl;
return 0;
}
The *tm struct has other members you may find of use. Here is a link:
http://www.cplusplus.com/reference/clibrary/ctime/tm/
I have heard that the Boost libraries have ways of dealing with time. Here is their official website:
http://www.boost.org/
Last edited on Feb 4, 2012 at 7:04pm UTC
Feb 4, 2012 at 7:08pm UTC
...and if you're using Windows and want to jump right in without worrying about boost library configuration issues: http://www.boostpro.com/download/
Feb 5, 2012 at 9:13pm UTC
Why does my code not display decimals when run?