Panda3D
frameRateMeter.I
1 // Filename: frameRateMeter.I
2 // Created by: drose (23Dec03)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: FrameRateMeter::get_window
18 // Access: Published
19 // Description: Returns the GraphicsOutput that was passed to
20 // setup_window(), or NULL if setup_window() has not
21 // been called.
22 ////////////////////////////////////////////////////////////////////
24 get_window() const {
25  return _window;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: FrameRateMeter::get_display_region
30 // Access: Published
31 // Description: Returns the DisplayRegion that the meter has created
32 // to render itself into the window to setup_window(),
33 // or NULL if setup_window() has not been called.
34 ////////////////////////////////////////////////////////////////////
37  return _display_region;
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: FrameRateMeter::set_update_interval
42 // Access: Published
43 // Description: Specifies the number of seconds that should elapse
44 // between updates to the frame rate indication. This
45 // should be reasonably slow (e.g. 0.2 to 1.0) so that
46 // the calculation of the frame rate text does not
47 // itself dominate the frame rate.
48 ////////////////////////////////////////////////////////////////////
49 INLINE void FrameRateMeter::
50 set_update_interval(double update_interval) {
51  _update_interval = update_interval;
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: FrameRateMeter::get_update_interval
56 // Access: Published
57 // Description: Returns the number of seconds that will elapse
58 // between updates to the frame rate indication.
59 ////////////////////////////////////////////////////////////////////
60 INLINE double FrameRateMeter::
62  return _update_interval;
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: FrameRateMeter::set_text_pattern
67 // Access: Published
68 // Description: Sets the sprintf() pattern that is used to format the
69 // text. The string "%f" or some variant will be
70 // replaced with the current frame rate in frames per
71 // second.
72 ////////////////////////////////////////////////////////////////////
73 INLINE void FrameRateMeter::
74 set_text_pattern(const string &text_pattern) {
75  _text_pattern = text_pattern;
76  Thread *current_thread = Thread::get_current_thread();
77  do_update(current_thread);
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: FrameRateMeter::get_text_pattern
82 // Access: Published
83 // Description: Returns the sprintf() pattern that is used to format the
84 // text.
85 ////////////////////////////////////////////////////////////////////
86 INLINE const string &FrameRateMeter::
88  return _text_pattern;
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: FrameRateMeter::set_clock_object
93 // Access: Published
94 // Description: Sets the clock that is used to determine the frame
95 // rate. The default is the application's global clock
96 // (ClockObject::get_global_clock()).
97 ////////////////////////////////////////////////////////////////////
98 INLINE void FrameRateMeter::
99 set_clock_object(ClockObject *clock_object) {
100  _clock_object = clock_object;
101  _last_update = 0.0f;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: FrameRateMeter::get_clock_object
106 // Access: Published
107 // Description: Returns the clock that is used to determine the frame
108 // rate.
109 ////////////////////////////////////////////////////////////////////
112  return _clock_object;
113 }
114 
115 ////////////////////////////////////////////////////////////////////
116 // Function: FrameRateMeter::update
117 // Access: Published
118 // Description: You can call this to explicitly force the
119 // FrameRateMeter to update itself with the latest frame
120 // rate information. Normally, it is not necessary to
121 // call this explicitly.
122 ////////////////////////////////////////////////////////////////////
123 INLINE void FrameRateMeter::
125  Thread *current_thread = Thread::get_current_thread();
126  do_update(current_thread);
127 }
void set_clock_object(ClockObject *clock_object)
Sets the clock that is used to determine the frame rate.
DisplayRegion * get_display_region() const
Returns the DisplayRegion that the meter has created to render itself into the window to setup_window...
double get_update_interval() const
Returns the number of seconds that will elapse between updates to the frame rate indication.
GraphicsOutput * get_window() const
Returns the GraphicsOutput that was passed to setup_window(), or NULL if setup_window() has not been ...
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
Definition: thread.I:145
A ClockObject keeps track of elapsed real time and discrete time.
Definition: clockObject.h:66
This is a base class for the various different classes that represent the result of a frame of render...
void set_text_pattern(const string &text_pattern)
Sets the sprintf() pattern that is used to format the text.
A thread; that is, a lightweight process.
Definition: thread.h:51
void set_update_interval(double update_interval)
Specifies the number of seconds that should elapse between updates to the frame rate indication...
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:61
ClockObject * get_clock_object() const
Returns the clock that is used to determine the frame rate.
const string & get_text_pattern() const
Returns the sprintf() pattern that is used to format the text.
void update()
You can call this to explicitly force the FrameRateMeter to update itself with the latest frame rate ...