Panda3D
 All Classes Functions Variables Enumerations
frameRateMeter.h
1 // Filename: frameRateMeter.h
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 #ifndef FRAMERATEMETER_H
16 #define FRAMERATEMETER_H
17 
18 #include "pandabase.h"
19 #include "textNode.h"
20 #include "nodePath.h"
21 #include "graphicsOutput.h"
22 #include "displayRegion.h"
23 #include "pointerTo.h"
24 #include "pStatCollector.h"
25 
26 class GraphicsChannel;
27 class ClockObject;
28 
29 ////////////////////////////////////////////////////////////////////
30 // Class : FrameRateMeter
31 // Description : This is a special TextNode that automatically updates
32 // itself with the current frame rate. It can be placed
33 // anywhere in the world where you'd like to see the
34 // frame rate.
35 //
36 // It also has a special mode in which it may be
37 // attached directly to a channel or window. If this is
38 // done, it creates a DisplayRegion for itself and renders
39 // itself in the upper-right-hand corner.
40 ////////////////////////////////////////////////////////////////////
41 class EXPCL_PANDA_GRUTIL FrameRateMeter : public TextNode {
42 PUBLISHED:
43  FrameRateMeter(const string &name);
44  virtual ~FrameRateMeter();
45 
46  void setup_window(GraphicsOutput *window);
47  void clear_window();
48 
49  INLINE GraphicsOutput *get_window() const;
50  INLINE DisplayRegion *get_display_region() const;
51 
52  INLINE void set_update_interval(double update_interval);
53  INLINE double get_update_interval() const;
54 
55  INLINE void set_text_pattern(const string &text_pattern);
56  INLINE const string &get_text_pattern() const;
57 
58  INLINE void set_clock_object(ClockObject *clock_object);
59  INLINE ClockObject *get_clock_object() const;
60 
61  INLINE void update();
62 
63 protected:
64  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
65 
66 private:
67  void do_update(Thread *current_thread);
68 
69 private:
70  PT(GraphicsOutput) _window;
71  PT(DisplayRegion) _display_region;
72  NodePath _root;
73 
74  bool _show_milliseconds;
75  double _update_interval;
76  double _last_update;
77  string _text_pattern;
78  ClockObject *_clock_object;
79 
80  PN_stdfloat _last_aspect_ratio;
81  CPT(TransformState) _aspect_ratio_transform;
82 
83  static PStatCollector _show_fps_pcollector;
84 
85 public:
86  static TypeHandle get_class_type() {
87  return _type_handle;
88  }
89  static void init_type() {
90  TextNode::init_type();
91  register_type(_type_handle, "FrameRateMeter",
92  TextNode::get_class_type());
93  }
94  virtual TypeHandle get_type() const {
95  return get_class_type();
96  }
97  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
98 
99 private:
100  static TypeHandle _type_handle;
101 };
102 
103 #include "frameRateMeter.I"
104 
105 #endif
This collects together the pieces of data that are accumulated for each node while walking the scene ...
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
Definition: textNode.cxx:685
A lightweight class that represents a single element that may be timed and/or counted via stats...
A ClockObject keeps track of elapsed real time and discrete time.
Definition: clockObject.h:66
void update()
Can be called after the TextNode has been fully configured, to force the node to recompute its text i...
Definition: textNode.I:1421
This is a base class for the various different classes that represent the result of a frame of render...
A thread; that is, a lightweight process.
Definition: thread.h:51
The primary interface to this module.
Definition: textNode.h:52
This is a special TextNode that automatically updates itself with the current frame rate...
A rectangular subregion within a window for rendering into.
Definition: displayRegion.h:61
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48