PageRenderTime 30ms CodeModel.GetById 19ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/llframetimer.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 152 lines | 54 code | 31 blank | 67 comment | 0 complexity | 584c6e79ceb6bfce1eb6e1c7791f3ea0 MD5 | raw file
  1/** 
  2 * @file llframetimer.h
  3 * @brief A lightweight timer that measures seconds and is only
  4 * updated once per frame.
  5 *
  6 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_LLFRAMETIMER_H
 29#define LL_LLFRAMETIMER_H
 30
 31/**
 32 * *NOTE: Because of limitations on linux which we do not really have
 33 * time to explore, the total time is derived from the frame time
 34 * and is recsynchronized on every frame.
 35 */
 36
 37#include "lltimer.h"
 38#include "timing.h"
 39
 40class LL_COMMON_API LLFrameTimer 
 41{
 42public:
 43	LLFrameTimer() : mStartTime( sFrameTime ), mExpiry(0), mStarted(TRUE) {}
 44
 45	// Return the number of seconds since the start of this
 46	// application instance.
 47	static F64 getElapsedSeconds()
 48	{
 49		// Loses msec precision after ~4.5 hours...
 50		return sFrameTime;
 51	} 
 52
 53	// Return a low precision usec since epoch
 54	static U64 getTotalTime()
 55	{
 56		return sTotalTime ? sTotalTime : totalTime();
 57	}
 58
 59	// Return a low precision seconds since epoch
 60	static F64 getTotalSeconds()
 61	{
 62		return sTotalSeconds;
 63	}
 64
 65	// Call this method once per frame to update the current frame time.   This is actually called
 66	// at some other times as well
 67	static void updateFrameTime();
 68
 69	// Call this method once, and only once, per frame to update the current frame count.
 70	static void updateFrameCount()					{ sFrameCount++; }
 71
 72	static U32  getFrameCount()						{ return sFrameCount; }
 73
 74	static F32	getFrameDeltaTimeF32();
 75
 76	// Return seconds since the current frame started
 77	static F32  getCurrentFrameTime();
 78
 79	// MANIPULATORS
 80	void start();
 81	void stop();
 82	void reset();
 83	void resetWithExpiry(F32 expiration);
 84	void pause();
 85	void unpause();
 86	void setTimerExpirySec(F32 expiration);
 87	void setExpiryAt(F64 seconds_since_epoch);
 88	BOOL checkExpirationAndReset(F32 expiration);
 89	F32 getElapsedTimeAndResetF32() 				{ F32 t = F32(sFrameTime - mStartTime); reset(); return t; }
 90
 91	void setAge(const F64 age)						{ mStartTime = sFrameTime - age; }
 92
 93	// ACCESSORS
 94	BOOL hasExpired() const							{ return (sFrameTime >= mExpiry); }
 95	F32  getTimeToExpireF32() const					{ return (F32)(mExpiry - sFrameTime); }
 96	F32  getElapsedTimeF32() const					{ return mStarted ? (F32)(sFrameTime - mStartTime) : (F32)mStartTime; }
 97	BOOL getStarted() const							{ return mStarted; }
 98
 99	// return the seconds since epoch when this timer will expire.
100	F64 expiresAt() const;
101
102protected:	
103	// A single, high resolution timer that drives all LLFrameTimers
104	// *NOTE: no longer used.
105	//static LLTimer sInternalTimer;		
106
107	//
108	// Aplication constants
109	//
110
111	// Start time of opp in usec since epoch
112	static U64 sStartTotalTime;	
113
114	// 
115	// Data updated per frame
116	//
117
118	// Seconds since application start
119	static F64 sFrameTime;
120
121	// Time that has elapsed since last call to updateFrameTime()
122	static U64 sFrameDeltaTime;
123
124	// Total microseconds since epoch.
125	static U64 sTotalTime;			
126
127	// Seconds since epoch.
128	static F64 sTotalSeconds;
129
130	// Total number of frames elapsed in application
131	static S32 sFrameCount;
132
133	//
134	// Member data
135	//
136
137	// Number of seconds after application start when this timer was
138	// started. Set equal to sFrameTime when reset.
139	F64 mStartTime;
140
141	// Timer expires this many seconds after application start time.
142	F64 mExpiry;
143
144	// Useful bit of state usually associated with timers, but does
145	// not affect actual functionality
146	BOOL mStarted;
147};
148
149// Glue code for Havok (or anything else that doesn't want the full .h files)
150extern F32  getCurrentFrameTime();
151
152#endif  // LL_LLFRAMETIMER_H