diff options
Diffstat (limited to 'linden/indra/llcommon/llframetimer.h')
-rw-r--r-- | linden/indra/llcommon/llframetimer.h | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llframetimer.h b/linden/indra/llcommon/llframetimer.h new file mode 100644 index 0000000..007fe7d --- /dev/null +++ b/linden/indra/llcommon/llframetimer.h | |||
@@ -0,0 +1,141 @@ | |||
1 | /** | ||
2 | * @file llframetimer.h | ||
3 | * @brief A lightweight timer that measures seconds and is only | ||
4 | * updated once per frame. | ||
5 | * | ||
6 | * Copyright (c) 2002-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
9 | * to you under the terms of the GNU General Public License, version 2.0 | ||
10 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
11 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
12 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
13 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
14 | * | ||
15 | * There are special exceptions to the terms and conditions of the GPL as | ||
16 | * it is applied to this Source Code. View the full text of the exception | ||
17 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
18 | * online at http://secondlife.com/developers/opensource/flossexception | ||
19 | * | ||
20 | * By copying, modifying or distributing this software, you acknowledge | ||
21 | * that you have read and understood your obligations described above, | ||
22 | * and agree to abide by those obligations. | ||
23 | * | ||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
26 | * COMPLETENESS OR PERFORMANCE. | ||
27 | */ | ||
28 | |||
29 | #ifndef LL_LLFRAMETIMER_H | ||
30 | #define LL_LLFRAMETIMER_H | ||
31 | |||
32 | /** | ||
33 | * *NOTE: Because of limitations on linux which we do not really have | ||
34 | * time to explore, the total time is derived from the frame time | ||
35 | * and is recsynchronized on every frame. | ||
36 | */ | ||
37 | |||
38 | #include "lltimer.h" | ||
39 | #include "timing.h" | ||
40 | |||
41 | class LLFrameTimer | ||
42 | { | ||
43 | public: | ||
44 | LLFrameTimer() : mStartTime( sFrameTime ), mExpiry(0), mStarted(TRUE) {} | ||
45 | |||
46 | // Return the number of seconds since the start of this | ||
47 | // application instance. | ||
48 | static F64 getElapsedSeconds() | ||
49 | { | ||
50 | // Loses msec precision after ~4.5 hours... | ||
51 | return sFrameTime; | ||
52 | } | ||
53 | |||
54 | // Return a low precision usec since epoch | ||
55 | static U64 getTotalTime() | ||
56 | { | ||
57 | return sTotalTime ? sTotalTime : totalTime(); | ||
58 | } | ||
59 | |||
60 | // Return a low precision seconds since epoch | ||
61 | static F64 getTotalSeconds() | ||
62 | { | ||
63 | return sTotalSeconds; | ||
64 | } | ||
65 | |||
66 | // Call this method once per frame to update the current frame | ||
67 | // time. | ||
68 | static void updateFrameTime(); | ||
69 | |||
70 | static S32 getFrameCount() { return sFrameCount; } | ||
71 | |||
72 | static F32 getFrameDeltaTimeF32(); | ||
73 | |||
74 | // MANIPULATORS | ||
75 | void start() { reset(); mStarted = TRUE; } | ||
76 | void stop() { mStarted = FALSE; } | ||
77 | void reset() { mStartTime = sFrameTime; mExpiry = sFrameTime; } | ||
78 | void setTimerExpirySec(F32 expiration) { mExpiry = expiration + mStartTime; } | ||
79 | void setExpiryAt(F64 seconds_since_epoch); | ||
80 | BOOL checkExpirationAndReset(F32 expiration); | ||
81 | F32 getElapsedTimeAndResetF32() { F32 t = F32(sFrameTime - mStartTime); reset(); return t; } | ||
82 | |||
83 | void setAge(const F64 age) { mStartTime = sFrameTime - age; } | ||
84 | |||
85 | // ACCESSORS | ||
86 | BOOL hasExpired() const { return (sFrameTime >= mExpiry); } | ||
87 | F32 getTimeToExpireF32() const { return (F32)(mExpiry - sFrameTime); } | ||
88 | F32 getElapsedTimeF32() const { return (F32)(sFrameTime - mStartTime); } | ||
89 | BOOL getStarted() const { return mStarted; } | ||
90 | |||
91 | // return the seconds since epoch when this timer will expire. | ||
92 | F64 expiresAt() const; | ||
93 | |||
94 | protected: | ||
95 | // A single, high resolution timer that drives all LLFrameTimers | ||
96 | // *NOTE: no longer used. | ||
97 | //static LLTimer sInternalTimer; | ||
98 | |||
99 | // | ||
100 | // Aplication constants | ||
101 | // | ||
102 | |||
103 | // Start time of opp in usec since epoch | ||
104 | static U64 sStartTotalTime; | ||
105 | |||
106 | // | ||
107 | // Data updated per frame | ||
108 | // | ||
109 | |||
110 | // Seconds since application start | ||
111 | static F64 sFrameTime; | ||
112 | |||
113 | // Time that has elapsed since last call to updateFrameTime() | ||
114 | static U64 sFrameDeltaTime; | ||
115 | |||
116 | // Total microseconds since epoch. | ||
117 | static U64 sTotalTime; | ||
118 | |||
119 | // Seconds since epoch. | ||
120 | static F64 sTotalSeconds; | ||
121 | |||
122 | // Total number of frames elapsed in application | ||
123 | static S32 sFrameCount; | ||
124 | |||
125 | // | ||
126 | // Member data | ||
127 | // | ||
128 | |||
129 | // Number of seconds after application start when this timer was | ||
130 | // started. Set equal to sFrameTime when reset. | ||
131 | F64 mStartTime; | ||
132 | |||
133 | // Timer expires this many seconds after application start time. | ||
134 | F64 mExpiry; | ||
135 | |||
136 | // Useful bit of state usually associated with timers, but does | ||
137 | // not affect actual functionality | ||
138 | BOOL mStarted; | ||
139 | }; | ||
140 | |||
141 | #endif // LL_LLFRAMETIMER_H | ||