Panda3D
|
00001 // Filename: frameRateMeter.h 00002 // Created by: drose (23Dec03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef FRAMERATEMETER_H 00016 #define FRAMERATEMETER_H 00017 00018 #include "pandabase.h" 00019 #include "textNode.h" 00020 #include "nodePath.h" 00021 #include "graphicsOutput.h" 00022 #include "displayRegion.h" 00023 #include "pointerTo.h" 00024 #include "pStatCollector.h" 00025 00026 class GraphicsChannel; 00027 class ClockObject; 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Class : FrameRateMeter 00031 // Description : This is a special TextNode that automatically updates 00032 // itself with the current frame rate. It can be placed 00033 // anywhere in the world where you'd like to see the 00034 // frame rate. 00035 // 00036 // It also has a special mode in which it may be 00037 // attached directly to a channel or window. If this is 00038 // done, it creates a DisplayRegion for itself and renders 00039 // itself in the upper-right-hand corner. 00040 //////////////////////////////////////////////////////////////////// 00041 class EXPCL_PANDA_GRUTIL FrameRateMeter : public TextNode { 00042 PUBLISHED: 00043 FrameRateMeter(const string &name); 00044 virtual ~FrameRateMeter(); 00045 00046 void setup_window(GraphicsOutput *window); 00047 void clear_window(); 00048 00049 INLINE GraphicsOutput *get_window() const; 00050 INLINE DisplayRegion *get_display_region() const; 00051 00052 INLINE void set_update_interval(double update_interval); 00053 INLINE double get_update_interval() const; 00054 00055 INLINE void set_text_pattern(const string &text_pattern); 00056 INLINE const string &get_text_pattern() const; 00057 00058 INLINE void set_clock_object(ClockObject *clock_object); 00059 INLINE ClockObject *get_clock_object() const; 00060 00061 INLINE void update(); 00062 00063 protected: 00064 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data); 00065 00066 private: 00067 void do_update(Thread *current_thread); 00068 00069 private: 00070 PT(GraphicsOutput) _window; 00071 PT(DisplayRegion) _display_region; 00072 NodePath _root; 00073 00074 double _update_interval; 00075 double _last_update; 00076 string _text_pattern; 00077 ClockObject *_clock_object; 00078 00079 static PStatCollector _show_fps_pcollector; 00080 00081 public: 00082 static TypeHandle get_class_type() { 00083 return _type_handle; 00084 } 00085 static void init_type() { 00086 TextNode::init_type(); 00087 register_type(_type_handle, "FrameRateMeter", 00088 TextNode::get_class_type()); 00089 } 00090 virtual TypeHandle get_type() const { 00091 return get_class_type(); 00092 } 00093 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00094 00095 private: 00096 static TypeHandle _type_handle; 00097 }; 00098 00099 #include "frameRateMeter.I" 00100 00101 #endif