PageRenderTime 14ms CodeModel.GetById 8ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
27#include "linden_common.h"
28
29#include "lleventtimer.h"
30
31#include "u64.h"
32
33
34//////////////////////////////////////////////////////////////////////////////
35//
36//		LLEventTimer Implementation
37//
38//////////////////////////////////////////////////////////////////////////////
39
40LLEventTimer::LLEventTimer(F32 period)
41: mEventTimer()
42{
43	mPeriod = period;
44}
45
46LLEventTimer::LLEventTimer(const LLDate& time)
47: mEventTimer()
48{
49	mPeriod = (F32)(time.secondsSinceEpoch() - LLDate::now().secondsSinceEpoch());
50}
51
52
53LLEventTimer::~LLEventTimer()
54{
55}
56
57//static
58void LLEventTimer::updateClass() 
59{
60	std::list<LLEventTimer*> completed_timers;
61	for (instance_iter iter = beginInstances(); iter != endInstances(); ) 
62	{
63		LLEventTimer& timer = *iter++;
64		F32 et = timer.mEventTimer.getElapsedTimeF32();
65		if (timer.mEventTimer.getStarted() && et > timer.mPeriod) {
66			timer.mEventTimer.reset();
67			if ( timer.tick() )
68			{
69				completed_timers.push_back( &timer );
70			}
71		}
72	}
73
74	if ( completed_timers.size() > 0 )
75	{
76		for (std::list<LLEventTimer*>::iterator completed_iter = completed_timers.begin(); 
77			 completed_iter != completed_timers.end(); 
78			 completed_iter++ ) 
79		{
80			delete *completed_iter;
81		}
82	}
83}
84
85