Timer.h 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /******************************************************************************
  2. Use 'Time' to access:
  3. -current time
  4. -current frame time
  5. -current frame number
  6. -modify game time speed
  7. /******************************************************************************/
  8. struct TimeClass
  9. {
  10. UInt frame ()C {return _frame;} // current frame number
  11. Flt fps ()C {return _fps ;} // current number of frames per second
  12. Flt d ()C {return _d ;} // game time delta ( frame time duration, modified by game 'speed', affected by 'smooth' 'skipUpdate' and application pauses)
  13. Flt ad ()C {return _ad ;} // application time delta ( frame time duration, NOT modified by game 'speed', affected by 'smooth' 'skipUpdate' and application pauses)
  14. Flt rd ()C {return _rd ;} // real time delta ( frame time duration, NOT modified by game 'speed', NOT affected by 'smooth' 'skipUpdate' and application pauses)
  15. Dbl time ()C {return _t ;} // game time in current frame ( seconds since application started, modified by game 'speed', affected by 'smooth' 'skipUpdate' and application pauses)
  16. Dbl appTime ()C {return _at ;} // application time in current frame ( seconds since application started, NOT modified by game 'speed', affected by 'smooth' 'skipUpdate' and application pauses)
  17. Dbl stateTime ()C {return _st ;} // state time in current frame ( seconds since last 'State' started, NOT modified by game 'speed', affected by 'smooth' 'skipUpdate' and application pauses)
  18. Dbl realTime ()C {return _rt ;} // real time in current frame ( seconds since application started, NOT modified by game 'speed', NOT affected by 'smooth' 'skipUpdate' and application pauses)
  19. Dbl curTime ()C; // real time in current moment ( seconds since application started, NOT modified by game 'speed', NOT affected by 'smooth' 'skipUpdate' and application pauses, this method always calculates the time when called)
  20. UInt curTimeMs()C; // real time in current moment (milliseconds since application started, NOT modified by game 'speed', NOT affected by 'smooth' 'skipUpdate' and application pauses, this is a little faster method than 'curTime' but returns time in milliseconds)
  21. Flt speed ( )C {return _speed;} // get game time speed (<1 slower, 1 default, >1 faster)
  22. void speed (Flt speed); // set game time speed (<1 slower, 1 default, >1 faster) and modify sound speeds (except VOLUME_MUSIC and VOLUME_AMBIENT volume groups)
  23. SMOOTH_VALUE_MODE smooth ( )C {return _sv_ad.mode( );} // get time delta smoothing, default=SV_WEIGHT4
  24. void smooth (SMOOTH_VALUE_MODE mode) { _sv_ad.mode(mode);} // set time delta smoothing
  25. void wait (Int milliseconds); // pause the current thread and wait 'milliseconds' time (this is equal to calling the system 'Sleep' function)
  26. void skipUpdate(Byte frames=1); // call this method to notify that timer should skip updating frame time for following 'frames', use this method after slow one time methods, like loading data
  27. Flt stateUpdateTime()C {return _state_update;} // get CPU time needed to process active application State Update in last frame
  28. Flt stateDrawTime ()C {return _state_draw ;} // get CPU time needed to process active application State Draw in last frame
  29. #if !EE_PRIVATE
  30. private:
  31. #endif
  32. Bool _pc;
  33. Byte _skip;
  34. UInt _start_time_ms, _frame, _frames_drawn;
  35. ULong _start_time;
  36. Flt _fps, _fps_time, _state_update, _state_draw;
  37. Dbl _rd_2, _rd_1, _rd, _ad, _d, _rt, _at, _st, _t, _speed, _time_mul;
  38. SmoothValue _sv_ad;
  39. TimeClass();
  40. #if EE_PRIVATE
  41. void create();
  42. void update();
  43. #endif
  44. }extern
  45. Time; // Application Time Access
  46. /******************************************************************************/
  47. Bool EventOccurred(Flt event_time , Flt start_time, Flt dt); // if event has occurred , 'event_time' =position in time , 'start_time'=time at the start of the frame, 'dt'=time delta
  48. Bool EventBetween (Flt event_time_from, Flt event_time_to, Flt start_time, Flt dt); // if event is occurring, 'event_time_from'=position of event start, 'event_time_to'=position of event end, 'start_time'=time at the start of the frame, 'dt'=time delta
  49. /******************************************************************************/