// DWBS ------------------------------------------------------------------ DWBS
//
// PLATFORM		: ALL
// PRODUCT		: BIT_DEMON
// VISIBILITY	: PUBLIC
//
// DWBS ------------------------------------------------------------------ DWBS


#include <bdCore/bdTiming/bdStopwatch.h>
#include <bdPlatform/bdPlatformTiming/bdPlatformTiming.h>

bdStopwatch::bdStopwatch()
{
	reset();
}

bdStopwatch::bdStopwatch(const bdStopwatch &other)
{
	m_start = other.m_start;
	m_stop = other.m_stop;
}

void bdStopwatch::start()
{
	m_start = bdPlatformTiming::getHiResTimeStamp();
}

void bdStopwatch::stop()
{
	if(m_start != 0)
	{
		m_stop = bdPlatformTiming::getHiResTimeStamp();
	}
}

void bdStopwatch::reset()
{
	m_start = 0;
	m_stop = 0;
}

bdFloat32 bdStopwatch::getTimeInSeconds() const
{
	return bdPlatformTiming::getElapsedTime(m_start, m_stop);
}

bdFloat32 bdStopwatch::getElapsedTimeInSeconds() const
{
	if(m_start != 0)
	{
		const bdUInt64 stopTime = bdPlatformTiming::getHiResTimeStamp();

		return bdPlatformTiming::getElapsedTime(m_start, stopTime);
	}
	else
	{
		return 0.f;
	}
}
