/*	XGTimer.cpp
 *
 *		Some useful timer stuff.  Sort of lame.
 */

/**********************************************************************

  XGTimer.cpp is copyright 1998-1999 Sassafras Software Inc.
  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#include <XConfig.h>			// must be first to optimize compile on MSVC++

#if OPT_WINOS == 1
#include <time.h>
#endif

#include <XTimer.h>

TTIME XGTimer::fStartTime;

/************************************************************************/
/*																		*/
/*	Construction/Destruction											*/
/*																		*/
/************************************************************************/

/*$	XGTimer::XGTimer
 *
 *		Construction
 */

XGTimer::XGTimer (void)
{
	fNextTime = 0;
}

/*$	XGTimer::~XGTimer
 *
 *		Destruction
 */

XGTimer::~XGTimer ()
{
}

void XGTimer::Reset (TTIME delay)
{
	fNextTime = PUpTime() + delay;
}

bool XGTimer::Expired (void)
{
	return(fNextTime <= PUpTime());
}

TTIME XGTimer::PUpTime (void)
{
#if OPT_MACOS == 1
	return(LMGetTime() - fStartTime);
#endif

#if OPT_WINOS == 1
	return(time(NULL) - fStartTime);
#endif

#if OPT_XWIN == 1
#endif
}

TTIME XGTimer::Ticks (void)
{
#if OPT_MACOS == 1
	return(TickCount());
#endif

#if OPT_WINOS == 1
	return(GetTickCount());
#endif

#if OPT_XWIN == 1
#endif
}

TTIME XGTimer::SecsToTicks (TTIME s)
{
#if OPT_MACOS == 1
	return(s * 60);
#endif

#if OPT_WINOS == 1
	return(s * 1000);
#endif

#if OPT_XWIN == 1
#endif
}

void XGTimer::SetStartTime (void)
{
	fStartTime = PUpTime();
}
