2002-12-01 07:56:17 +00:00
|
|
|
/*******************************************************************************
|
2002-12-29 06:50:19 +00:00
|
|
|
This file is Part of the ZEngine Library for 2D game development.
|
|
|
|
Copyright (C) 2002, 2003 James Turk
|
2002-12-01 07:56:17 +00:00
|
|
|
|
2002-12-29 06:50:19 +00:00
|
|
|
Licensed under a BSD-style license.
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
The maintainer of this library is James Turk (james@conceptofzero.net)
|
2002-12-29 06:50:19 +00:00
|
|
|
and the home of this Library is http://www.zengine.sourceforge.net
|
2002-12-01 07:56:17 +00:00
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\par File Header:
|
|
|
|
File: ZE_ZTimer.cpp <br>
|
|
|
|
Description: Implementation source file for core ZEngine Timer Object. <br>
|
|
|
|
Author(s): James Turk <br>
|
2003-01-16 05:45:58 +00:00
|
|
|
$Id: ZE_ZTimer.cpp,v 1.4 2003/01/16 05:45:58 cozman Exp $<br>
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
\file ZE_ZTimer.cpp
|
|
|
|
\brief Source file for ZTimer.
|
|
|
|
|
|
|
|
Implementation of ZTimer, the basic Timer class for ZEngine.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "ZE_ZTimer.h"
|
|
|
|
|
|
|
|
namespace ZE
|
|
|
|
{
|
|
|
|
|
2003-01-16 05:45:58 +00:00
|
|
|
Uint32 ZTimer::GetParentTime() const
|
2002-12-01 07:56:17 +00:00
|
|
|
{
|
|
|
|
if(rUseZEngine)
|
|
|
|
return rEngine->GetTime();
|
|
|
|
else
|
|
|
|
return SDL_GetTicks();
|
|
|
|
}
|
|
|
|
|
|
|
|
ZTimer::ZTimer(bool useZEngine)
|
|
|
|
{
|
|
|
|
rUseZEngine = useZEngine;
|
|
|
|
rPaused = false;
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZTimer::Reset()
|
|
|
|
{
|
|
|
|
rLastPause = rPausedTime = GetParentTime();
|
|
|
|
rPaused = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZTimer::Pause()
|
|
|
|
{
|
|
|
|
if(!rPaused)
|
|
|
|
{
|
|
|
|
rLastPause = GetParentTime();
|
|
|
|
rPaused = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZTimer::Unpause()
|
|
|
|
{
|
|
|
|
if(rPaused)
|
|
|
|
{
|
|
|
|
rPausedTime += (GetParentTime()-rLastPause);
|
|
|
|
rPaused = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-16 05:45:58 +00:00
|
|
|
Uint32 ZTimer::GetTime() const
|
2002-12-01 07:56:17 +00:00
|
|
|
{
|
|
|
|
if(rPaused)
|
|
|
|
return GetParentTime() - (rPausedTime + (GetParentTime() - rLastPause));
|
|
|
|
else
|
|
|
|
return GetParentTime() - rPausedTime;
|
|
|
|
}
|
|
|
|
|
2003-01-16 05:45:58 +00:00
|
|
|
bool ZTimer::IsPaused() const
|
2002-12-01 07:56:17 +00:00
|
|
|
{
|
|
|
|
return rPaused;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|