Hey guys, I'm wondering why the heck I'm unable to simply use one timer function in my game. Instead, I have to create copies of the exact same function over and over again in order for the time to sync or work at all.
I've created the function in a simple class(I made the class so that I didn't have to have 1000 timer functions):
asdf
class Timer
{
public:
bool WaitMilliSeconds(long int seconds) //Now THIS is how you do a fucking timer
{
static unsigned long secondsPassed;
static unsigned long startTime = GetTickCount();
static bool initTime = false;
static bool timePassed = false;
if (!initTime)
{
startTime = GetTickCount();
initTime = true;
}
secondsPassed = (GetTickCount() - startTime);
if (secondsPassed > seconds){
secondsPassed = 0;
startTime = GetTickCount();
timePassed = true;
initTime = false;
return true;
}
else
return false;
}
};
//I implement the timer as follows:
Timer t;
if (t.WaitMilliSeconds(10))
vTempDir += (vDiff / 2.0f);
and it works fine. I was hoping, in my render() function within my game loop, that I could just do
Timer t2;
t2.WaitMilliSeconds(10);
etc etc. Since they're all different classes, they shouldn't interfere with one another. But they do. I even tried
Timer t = new Timer;
t→WaitMilliSeconds(10);
But it literally still stops working if used more than once. I'm forced to make WaitMilliSeconds1, WaitMilliSeconds2, etc, why is the memory working this way? I thought when creating a pointer to a class and allocating memory for it on the stack, there'd be no way it would interfere with the function of the same class type but somewhere else in memory.
This isn't one of those brick-wall problems, I can get around this, but it's annoying, and it goes against what I learned about memory.
Any idea on how to create a function within a class that I can use over and over to measure time?
Thanks guys!