Advertisement
Guest User

Untitled

a guest
Mar 11th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #ifndef TIME_KEEPER_H_
  2. #define TIME_KEEPER_H_
  3.  
  4. class GlfwApiInterface;
  5.  
  6. class TimeKeeper {
  7.   public:
  8.     explicit TimeKeeper(GlfwApiInterface *glfw_api);
  9.     virtual ~TimeKeeper();
  10.     void calculate();
  11.     void reset();
  12.     double getDelta() const;
  13.   protected:
  14.     GlfwApiInterface *glfw_api_;
  15.     double frame_time_;
  16.     double delta_;
  17. };
  18.  
  19. #endif
  20.  
  21.  
  22. ///////////////////
  23.  
  24. #include "time_keeper.h"
  25. #include "api/glfw_api_interface.h"
  26.  
  27. TimeKeeper::TimeKeeper(GlfwApiInterface* glfw_api)
  28.     : glfw_api_(glfw_api), frame_time_(0), delta_(0) {
  29. }
  30.  
  31. TimeKeeper::~TimeKeeper() {
  32. }
  33.  
  34. void TimeKeeper::calculate() {
  35.   double time = glfw_api_->glfwGetTime();
  36.  
  37.   delta_ = time - frame_time_;
  38.   frame_time_ = time;
  39. }
  40.  
  41. void TimeKeeper::reset() {
  42.   delta_ = 0;
  43.   frame_time_ = glfw_api_->glfwGetTime();
  44. }
  45.  
  46. double TimeKeeper::getDelta() const {
  47.   return delta_;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement