home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #ifndef TIMER_H
- #define TIMER_H
-
- #include "Defines.h"
- #include <Inventor/SbTime.h>
-
- class WatchTime
- {
- public:
- WatchTime() { reset(); };
- WatchTime(SbTime time) { set(time); };
- WatchTime(long h, long m, long s, long t) {
- _hours = h; _minutes = m; _seconds = s; _tenths = t; };
-
- ~WatchTime(){};
-
- void set(long h, long m, long s, long t) {
- _hours = h; _minutes = m; _seconds = s; _tenths = t; };
-
- void set(SbTime);
-
- void reset() {
- _hours = _minutes = _seconds = _tenths = 0; };
-
- void print() {
- printf("%2d:%2d:%2d.%2d\n",_hours,_minutes,_seconds,_tenths); };
-
- inline Boolean operator <(const WatchTime &time) const;
- inline Boolean operator ==(const WatchTime &time) const;
- inline Boolean operator !=(const WatchTime &time) const
- { return !(*this==time); };
-
- friend WatchTime operator +(const WatchTime &t0, const WatchTime &t1);
- WatchTime & operator +=(const WatchTime &t)
- { return (*this = *this + t); }
-
- // sets the string of the form H:MM:SS.DD plus a null
- void setString(char buf[11]) const;
-
- private:
- long _hours;
- long _minutes;
- long _seconds;
- long _tenths;
- };
-
- inline Boolean
- WatchTime::operator <(const WatchTime &time) const
- {
- return (
- (_hours < time._hours) ||
-
- ((_hours == time._hours) &&
- (_minutes < time._minutes)) ||
-
- ((_hours == time._hours) &&
- (_minutes == time._minutes) &&
- (_seconds < time._seconds)) ||
-
- ((_hours == time._hours) &&
- (_minutes == time._minutes) &&
- (_seconds == time._seconds) &&
- (_tenths < time._tenths)));
- }
-
-
- inline Boolean
- WatchTime::operator ==(const WatchTime &time) const
- {
- return
- ((_hours == time._hours) &&
- (_minutes == time._minutes) &&
- (_seconds == time._seconds) &&
- (_tenths == time._tenths));
- }
-
-
- class Timer {
- public:
- Timer() { reset(); };
- ~Timer();
-
- void reset(); // sets all timers to 0, state to STOPPED
- void update(); // updates lap timer; call this once per frame
- void lap(); // updates _last_lap and _best_lap
- void start(); // start (or restart) the lap timer
- void stop(); // stop (pause) the lap timer
-
- // returns TRUE if different from last time called
- Boolean get_this_lap(char *&) const;
- Boolean get_last_lap(char *&) const;
- Boolean get_best_lap(char *&) const;
-
- private:
- WatchTime _this_lap;
- WatchTime _last_lap;
- WatchTime _best_lap;
-
- SbTime _start;
- WatchTime _offset;
- Boolean _state; // RUNNING or STOPPED
- };
-
- #endif
-