#include "StopWatch.h"
#include <windows.h>

StopWatch::StopWatch() 
: _frequency(0), _counter(0), _active(false), _elapsedTime(0.0)
{
	QueryPerformanceFrequency((LARGE_INTEGER*)&_frequency);
}

void StopWatch::start()
{
	_active = true;
	_elapsedTime = 0.0f;
	QueryPerformanceCounter((LARGE_INTEGER*)&_counter);
}

void StopWatch::stop()
{
	_active = false;
}

void StopWatch::resume()
{
	_active = true;
	QueryPerformanceCounter((LARGE_INTEGER*)&_counter);
}


double StopWatch::getElapsedTime()
{
	if (_active) {
		int64 currentCounter = 0;
		QueryPerformanceCounter((LARGE_INTEGER*)&currentCounter);

		_elapsedTime += ((double)(currentCounter - _counter) / (0.001 * (double)_frequency));
		_counter = currentCounter;
	}

	return _elapsedTime;
}




