/indra/llcommon/lleventtimer.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 85 lines · 41 code · 13 blank · 31 comment · 8 complexity · c3905fc9ee00c220eb571252e99b3d73 MD5 · raw file

  1. /**
  2. * @file lleventtimer.cpp
  3. * @brief Cross-platform objects for doing timing
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "lleventtimer.h"
  28. #include "u64.h"
  29. //////////////////////////////////////////////////////////////////////////////
  30. //
  31. // LLEventTimer Implementation
  32. //
  33. //////////////////////////////////////////////////////////////////////////////
  34. LLEventTimer::LLEventTimer(F32 period)
  35. : mEventTimer()
  36. {
  37. mPeriod = period;
  38. }
  39. LLEventTimer::LLEventTimer(const LLDate& time)
  40. : mEventTimer()
  41. {
  42. mPeriod = (F32)(time.secondsSinceEpoch() - LLDate::now().secondsSinceEpoch());
  43. }
  44. LLEventTimer::~LLEventTimer()
  45. {
  46. }
  47. //static
  48. void LLEventTimer::updateClass()
  49. {
  50. std::list<LLEventTimer*> completed_timers;
  51. for (instance_iter iter = beginInstances(); iter != endInstances(); )
  52. {
  53. LLEventTimer& timer = *iter++;
  54. F32 et = timer.mEventTimer.getElapsedTimeF32();
  55. if (timer.mEventTimer.getStarted() && et > timer.mPeriod) {
  56. timer.mEventTimer.reset();
  57. if ( timer.tick() )
  58. {
  59. completed_timers.push_back( &timer );
  60. }
  61. }
  62. }
  63. if ( completed_timers.size() > 0 )
  64. {
  65. for (std::list<LLEventTimer*>::iterator completed_iter = completed_timers.begin();
  66. completed_iter != completed_timers.end();
  67. completed_iter++ )
  68. {
  69. delete *completed_iter;
  70. }
  71. }
  72. }