00001
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031
00032 #ifndef RCSC_GAME_TIME_H
00033 #define RCSC_GAME_TIME_H
00034
00035 #include <iostream>
00036
00037 namespace rcsc {
00038
00043 class GameTime {
00044 private:
00046 long M_cycle;
00048 long M_stopped;
00049
00050 public:
00052 GameTime()
00053 : M_cycle( 0 )
00054 , M_stopped( 0 )
00055 { }
00056
00062 GameTime( const long & c,
00063 const long & s )
00064 : M_cycle( c )
00065 , M_stopped( s )
00066 { }
00067
00072 const
00073 long & cycle() const
00074 {
00075 return M_cycle;
00076 }
00077
00082 const
00083 long & stopped() const
00084 {
00085 return M_stopped;
00086 }
00087
00094 const
00095 GameTime & assign( const long & c, const long & s )
00096 {
00097 M_cycle = c;
00098 M_stopped = s;
00099 return *this;
00100 }
00101
00107 const
00108 GameTime & setCycle( const long & c )
00109 {
00110 M_cycle = c;
00111 return *this;
00112 }
00113
00119 const
00120 GameTime & setStopped( const long & s )
00121 {
00122 M_stopped = s;
00123 return *this;
00124 }
00125
00131 const
00132 GameTime & addCycle( const long & t )
00133 {
00134 M_cycle += t;
00135 return *this;
00136 }
00137
00143 const
00144 GameTime & addStopped( const long & t )
00145 {
00146 M_stopped += t;
00147 return *this;
00148 }
00149 };
00150
00151 }
00152
00153
00160 inline
00161 std::ostream &
00162 operator<<( std::ostream & o,
00163 const rcsc::GameTime & t )
00164 {
00165 o << "[" << t.cycle() << ", " << t.stopped() << "]";
00166 return o;
00167 }
00168
00169
00177 inline
00178 bool
00179 operator==( const rcsc::GameTime & lhs,
00180 const rcsc::GameTime & rhs )
00181 {
00182 return ( lhs.cycle() == rhs.cycle()
00183 && lhs.stopped() == rhs.stopped() );
00184 }
00185
00186
00193 inline
00194 bool operator!=( const rcsc::GameTime & lhs,
00195 const rcsc::GameTime & rhs )
00196 {
00197 return !( lhs == rhs );
00198 }
00199
00200
00207 inline
00208 bool
00209 operator<( const rcsc::GameTime & lhs,
00210 const rcsc::GameTime & rhs )
00211 {
00212 return ( lhs.cycle() < rhs.cycle()
00213 || ( lhs.cycle() == rhs.cycle()
00214 && lhs.stopped() < rhs.stopped() )
00215 );
00216 }
00217
00218
00225 inline
00226 bool
00227 operator<=( const rcsc::GameTime & lhs,
00228 const rcsc::GameTime & rhs )
00229 {
00230 return ( lhs.cycle() < rhs.cycle()
00231 || ( lhs.cycle() == rhs.cycle()
00232 && lhs.stopped() <= rhs.stopped() )
00233 );
00234 }
00235
00236
00243 inline
00244 bool
00245 operator>( const rcsc::GameTime & lhs,
00246 const rcsc::GameTime & rhs )
00247 {
00248 return ( lhs.cycle() > rhs.cycle()
00249 || ( lhs.cycle() == rhs.cycle()
00250 && lhs.stopped() > rhs.stopped() )
00251 );
00252 }
00253
00254
00261 inline
00262 bool
00263 operator>=( const rcsc::GameTime & lhs,
00264 const rcsc::GameTime & rhs )
00265 {
00266 return ( lhs.cycle() > rhs.cycle()
00267 || ( lhs.cycle() == rhs.cycle()
00268 && lhs.stopped() >= rhs.stopped() )
00269 );
00270 }
00271
00272 #endif