/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: src/drivers/wintel32/core/time/wintel32timer.cpp

*/

#include "drivers/wintel32/core/core.hpp"

CHighTimer *
CWintel32HighTimer::create()
{
    if (!ms_pSingleton) {
        ms_pSingleton = new CWintel32HighTimer();
	}

    return ms_pSingleton;
}

CHighTimer *
CWintel32HighTimer::get()
{
    if (!ms_pSingleton) {
        return create();
    }

    return ms_pSingleton;
}

CWintel32HighTimer::CWintel32HighTimer() : CHighTimer()
{
    // period is the number of counter increments that occur over 1 second
    if (FALSE == QueryPerformanceFrequency(&m_Frequency)) {
        sgxTrace("Can not query performance timer.");
    } else {
        m_FrequencyTime = (double)m_Frequency.QuadPart;
    }
}

CWintel32HighTimer::~CWintel32HighTimer()
{
}


void 
CWintel32HighTimer::start()
{
    CHighTimer::start();
    QueryPerformanceCounter(&m_Start);
}

tREAL32 
CWintel32HighTimer::getTime()
{
LARGE_INTEGER curr;
double t;

    QueryPerformanceCounter(&curr);

    t = (double)(curr.QuadPart - m_Start.QuadPart) * 1000.0;
    t /= m_FrequencyTime;

    return (tREAL32)t;
}
