00001 #include "disp/view.H"
00002 #include "geom/world.H"
00003 #include "std/config.H"
00004 #include "fps.H"
00005
00006 using mlib::XYpt;
00007
00008 inline XYpt
00009 lr_corner_loc(double left, double up)
00010 {
00011 int w=0, h=0;
00012 VIEW::peek()->get_size(w,h);
00013 if (0) {
00014 cerr << "width: " << w << ", height: " << h << endl;
00015 cerr << "location in pixels: " << mlib::PIXEL(w-left, up) << endl;
00016 }
00017 return mlib::PIXEL(w-left, up);
00018 }
00019
00020 FPS::FPS()
00021 {
00022 XYpt c = lr_corner_loc(50, 10);
00023
00024
00025 c = XYpt(0.8,-0.95);
00026
00027 _text = new TEXT2D(str_ptr("fps"), str_ptr::null, c);
00028
00029 _text->set_loc(c);
00030 _text->set_string(str_ptr(""));
00031
00032 GEOMptr text(&*_text);
00033 NETWORK .set(text, 0);
00034 NO_COLOR_MOD .set(text, 1);
00035 NO_XFORM_MOD .set(text, 1);
00036 NO_DISP_MOD .set(text, 1);
00037 NO_COPY .set(text, 1);
00038 DONOT_CLIP_OBJ.set(text, 1);
00039
00040 WORLD::create(text, false);
00041
00042 _last_display = VIEW::stamp();
00043 _clock.set();
00044 }
00045
00046 int
00047 FPS::tick(void)
00048 {
00049 HSVCOLOR hsv(VIEW::peek()->color());
00050 if ((hsv[2] > 0.5) && (VIEW::peek()->get_alpha() > 0.5))
00051 {
00052 _text->set_color(COLOR(0,0,0));
00053 }
00054 else
00055 {
00056 _text->set_color(COLOR(1,1,1));
00057 }
00058
00059 const int frames_drawn = (VIEW::stamp() - _last_display);
00060 const double secs = _clock.elapsed_time();
00061
00062 if (secs > 1 && frames_drawn > 10)
00063 {
00064 char fps_str[128];
00065 double fps = frames_drawn/secs;
00066 if (fps < 1.0)
00067 sprintf(fps_str, "%5.1g fps ", fps);
00068 else
00069 sprintf(fps_str, "%5.1f fps ", fps);
00070
00071 char tps_str[128] = "";
00072
00073 static bool do_tps = Config::get_var_bool("JOT_SHOW_TRIS_PER_SEC",false);
00074 if (do_tps) {
00075 double tps = frames_drawn * VIEWS[0]->tris() / secs;
00076 if (tps < 1e3)
00077 sprintf(tps_str, "%5.1f tris/sec", tps);
00078 else if (tps < 1e6)
00079 sprintf(tps_str, "%5.1fK tris/sec", tps/1e3);
00080 else
00081 sprintf(tps_str, "%5.1fM tris/sec", tps/1e6);
00082 }
00083
00084
00085
00086 if (_text)
00087 _text->set_string(str_ptr(fps_str) + tps_str);
00088 else
00089 err_msg("%s", fps);
00090
00091 _last_display = VIEW::stamp();
00092 _clock.set();
00093 }
00094
00095 return 0;
00096 }
00097
00098