RakTimer.cpp 986 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "RakTimer.h"
  11. RakTimer::RakTimer(void)
  12. {
  13. timerLength=1000;
  14. Start();
  15. }
  16. RakTimer::RakTimer(int lengthInMilliseconds)
  17. {
  18. timerLength=lengthInMilliseconds;
  19. Start();
  20. }
  21. RakTimer::~RakTimer(void)
  22. {
  23. }
  24. void RakTimer::SetTimerLength(int lengthInMilliseconds)
  25. {
  26. timerLength=lengthInMilliseconds;
  27. }
  28. void RakTimer::Start()
  29. {
  30. startTime=RakNet::GetTimeMS();
  31. }
  32. void RakTimer::Pause()
  33. {
  34. pauseOffset=(int)(RakNet::GetTimeMS()-startTime);
  35. }
  36. void RakTimer::Resume()
  37. {
  38. startTime=RakNet::GetTimeMS()-pauseOffset;
  39. }
  40. bool RakTimer::IsExpired()
  41. {
  42. return (RakNet::GetTimeMS()-startTime>timerLength);
  43. }
粤ICP备19079148号