I have a problem with a timer class based on a SDL timer.
class CTimer
{
public:
CTimer(): startTick(0), endTick(0), curTime(0), running(false) {};
void Start() { startTick += SDL_GetTicks() - endTick; running = true; };
void Stop() { endTick = SDL_GetTicks(); running = false; };
void Reset() { startTick = 0; endTick = 0; curTime = 0; };
inline int operator()() { return running ? curTime = ((int) SDL_GetTicks - startTick) / 1000 + 1 : curTime; };
private:
int startTick;
int endTick;
int curTime;
bool running;
};
The () operator should return time in seconds (stored in curTime). But it always returns 4202 (curTime is always equal to that). What am I doing wrong?
Test code:
int main()
{
SDL_Init (SDL_INIT_TIMER);
CApp::CTimer timer;
timer.Start();
for (int i = 0; i < 15; ++i)
{
SDL_Delay (1000);
std::cout << timer() << '\n';
}
return 0;
}