home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / audio / drive / Timer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.1 KB  |  121 lines

  1. /*
  2.  * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #ifndef TIMER_H
  18. #define TIMER_H
  19.  
  20. #include "Defines.h"
  21. #include <Inventor/SbTime.h>
  22.  
  23. class WatchTime
  24. {
  25. public:
  26.     WatchTime() { reset(); };
  27.     WatchTime(SbTime time) { set(time); }; 
  28.     WatchTime(long h, long m, long s, long t) {
  29.         _hours = h; _minutes = m; _seconds = s; _tenths = t; };
  30.     
  31.     ~WatchTime(){};
  32.  
  33.     void set(long h, long m, long s, long t) {
  34.         _hours = h; _minutes = m; _seconds = s; _tenths = t; };
  35.  
  36.     void set(SbTime);
  37.  
  38.     void reset() {
  39.         _hours = _minutes = _seconds = _tenths = 0; };
  40.  
  41.     void print() {
  42.         printf("%2d:%2d:%2d.%2d\n",_hours,_minutes,_seconds,_tenths); };
  43.         
  44.     inline Boolean operator <(const WatchTime &time) const;
  45.     inline Boolean operator ==(const WatchTime &time) const;
  46.     inline Boolean operator !=(const WatchTime &time) const
  47.         { return !(*this==time); };
  48.  
  49.     friend WatchTime operator +(const WatchTime &t0, const WatchTime &t1);
  50.     WatchTime & operator +=(const WatchTime &t)
  51.         { return (*this = *this + t); }
  52.  
  53.     // sets the string of the form H:MM:SS.DD plus a null
  54.     void setString(char buf[11]) const;
  55.     
  56. private:
  57.     long _hours;
  58.     long _minutes;
  59.     long _seconds;
  60.     long _tenths;
  61. };
  62.  
  63. inline Boolean
  64. WatchTime::operator <(const WatchTime &time) const
  65. {
  66.     return (
  67.         (_hours < time._hours) ||
  68.         
  69.         ((_hours == time._hours) &&
  70.         (_minutes < time._minutes)) ||
  71.  
  72.         ((_hours == time._hours) &&
  73.         (_minutes == time._minutes) &&
  74.         (_seconds < time._seconds)) ||
  75.         
  76.         ((_hours == time._hours) &&
  77.         (_minutes == time._minutes) &&
  78.         (_seconds == time._seconds) &&
  79.         (_tenths < time._tenths)));
  80. }
  81.  
  82.  
  83. inline Boolean
  84. WatchTime::operator ==(const WatchTime &time) const
  85. {
  86.     return 
  87.         ((_hours == time._hours) &&
  88.         (_minutes == time._minutes) &&
  89.         (_seconds == time._seconds) &&
  90.         (_tenths == time._tenths));
  91. }
  92.  
  93.  
  94. class Timer {
  95. public:
  96.     Timer() { reset(); };
  97.     ~Timer();
  98.  
  99.     void reset(); // sets all timers to 0, state to STOPPED
  100.     void update(); // updates lap timer; call this once per frame
  101.     void lap(); // updates _last_lap and _best_lap
  102.     void start(); // start (or restart) the lap timer
  103.     void stop(); // stop (pause) the lap timer
  104.  
  105.     // returns TRUE if different from last time called
  106.     Boolean get_this_lap(char *&) const;
  107.     Boolean get_last_lap(char *&) const;
  108.     Boolean get_best_lap(char *&) const;
  109.  
  110. private:
  111.     WatchTime _this_lap;
  112.     WatchTime _last_lap;
  113.     WatchTime _best_lap;
  114.  
  115.     SbTime _start;
  116.     WatchTime _offset;
  117.     Boolean _state; // RUNNING or STOPPED
  118. };
  119.  
  120. #endif
  121.