From d070a4495cddbe2e41e003e9eb2834ed95d86516 Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 2 Mar 2005 08:44:16 +0000 Subject: [PATCH] added Timer --- src/util/Timer.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/util/Timer.cpp diff --git a/src/util/Timer.cpp b/src/util/Timer.cpp new file mode 100644 index 0000000..39fe02c --- /dev/null +++ b/src/util/Timer.cpp @@ -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_; +} + +} +}