IntervalTimer.cpp 771 B

123456789101112131415161718192021222324252627282930313233
  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 "IntervalTimer.h"
  11. void IntervalTimer::SetPeriod(RakNet::TimeMS period) {basePeriod=period; remaining=0;}
  12. bool IntervalTimer::UpdateInterval(RakNet::TimeMS elapsed)
  13. {
  14. if (elapsed >= remaining)
  15. {
  16. RakNet::TimeMS difference = elapsed-remaining;
  17. if (difference >= basePeriod)
  18. {
  19. remaining=basePeriod;
  20. }
  21. else
  22. {
  23. remaining=basePeriod-difference;
  24. }
  25. return true;
  26. }
  27. remaining-=elapsed;
  28. return false;
  29. }
粤ICP备19079148号