added Timer

This commit is contained in:
James Turk 2005-03-02 08:44:16 +00:00
parent a9eebf6266
commit d070a4495c

74
src/util/Timer.cpp Normal file
View File

@ -0,0 +1,74 @@
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
// $Id: Timer.cpp,v 1.1 2005/03/02 08:44:16 cozman Exp $
#include "util/Timer.hpp"
namespace photon
{
namespace util
{
Timer::Timer(bool appTimeLinked) :
appCore_(AppCore::getInstance()),
appTimeLinked_(appTimeLinked)
{
reset(); //initializes other members
}
Timer::~Timer()
{
}
void Timer::reset()
{
lastPause_ = pausedTime_ = appCore_.getTime();
paused_ = false;
}
void Timer::pause()
{
if(!paused_)
{
lastPause_ = appCore_.getTime();
paused_ = true;
}
}
void Timer::unpause()
{
if(paused_)
{
//when unpausing update the total paused time by that pause
pausedTime_ += (appCore_.getTime()-lastPause_);
paused_ = false;
}
}
double Timer::getTime() const
{
if(paused_)
{
//when paused timer adjusted to subtract currently paused time
return appCore_.getTime() -
(pausedTime_ + (appCore_.getTime() - lastPause_));
}
else
{
//paused time is the total time the program has been paused
return appCore_.getTime() - pausedTime_;
}
}
bool Timer::isPaused() const
{
return paused_;
}
}
}