Timer.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include "core/ConfigVar.h"
  16. #include "core/Timer.h"
  17. ConfigVar cv_timer_scale_game(
  18. "timer_scale_game", "Timer speed for game related things", "1"
  19. );
  20. /**
  21. * Timer singleton
  22. */
  23. template<>Timer *Ogre::Singleton<Timer>::msSingleton = nullptr;
  24. Timer::Timer():
  25. system_time_total_(0),
  26. system_time_delta_(0),
  27. game_time_total_(0),
  28. game_time_delta_(0),
  29. game_timer_(0)
  30. {}
  31. float Timer::GetSystemTimeTotal(){return system_time_total_;}
  32. float Timer::GetSystemTimeDelta(){return system_time_delta_;}
  33. float Timer::GetGameTimeTotal(){return game_time_total_;}
  34. float Timer::GetGameTimeDelta(){return game_time_delta_;}
  35. void Timer::AddTime( const float time ){
  36. system_time_delta_ = time;
  37. system_time_total_ += system_time_delta_;
  38. game_time_delta_ = time * cv_timer_scale_game.GetF();
  39. game_time_total_ += game_time_delta_;
  40. if (game_timer_ > 0){
  41. game_timer_ -= time;
  42. if (game_timer_ < 0) game_timer_ = 0;
  43. }
  44. }
  45. void Timer::SetGameTimer(const float timer){game_timer_ = timer;}
  46. int Timer::GetGameTimer() const{return (int) game_timer_;}