PMB, you are correct, a 16 bit random value may not be enough for some applications. For better random number generation, I found this library GNU licensed
http://www.agner.org/random/ I have not tried it yet, but it looked pretty good on first glance.
As for gpGlobals->time I once tried using it to get the remaining time of a map with no luck, so it is not even good for doing that. If anyone knows how to get a reliable "timeleft" value (engine side, not client) let me know.
For many apps, clock( ) gives sufficient resolution which is about 1/1000 of a second. But I can see some apps needing a lot more resolution.
The QueryPerformanceCounter is very interesting - thanks for mentioning this one. I'm trying to find out how it is implemented. It appears to be based on CPU frequency, or it could be based on a hardware frequency counter. If you can point me to a document that describes how the value is generated I'd appreciate it.
NOTE: I'm mostly interested in protable code using ANSI C++ because whatever timer I use has to be made portable at least to Linux.
PBM, I have a lot of code for doing my timer class - too much for a post in here I think. I'll post this main function to give you an idea what I'm doing.
Code:
tinTicks tclCPUClock::finGetTickCount( )
{
// On error clock returns -1;
tinTicks vinCurTickCount = clock( );
if ( vinRollOverCount < 0 )
vinRollOverCount = 0;
if ( vinPrevTickCount < 0 )
goto locExitPoint;
if ( vinPrevTickCount > vinCurTickCount )
// the clock has rolled over;
{
if ( vinRollOverCount == cinMaxRollOverCount )
// NOTE: This condition will NEVER happen because the roll over period is
// at least 24 days, which adds up to 5 million years by the time the
// maximum rollover count is exceeded;
vinRollOverCount = 0;
else
++vinRollOverCount;
}
locExitPoint:
{
vinPrevTickCount = vinCurTickCount;
return vinCurTickCount;
}
} // tclCPUClock::finGetTickCount
tinTicks is of type 32 bit integer. To calculate how many ticks in a second, you divide your clock tick count by the constant CLK_TCK which should be found in time.h
I added a rollover check to make sure I don't get a bad hicup if my code is left running for more than 24 days.