Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

WindowFrameRate.cpp

Go to the documentation of this file.
00001 /*
00002  * WindowFrameRate.cpp
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2005 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00029 #include "../Include/FlyLegacy.h"
00030 #include "../Include/Fui.h"
00031 #include "../Include/Globals.h"
00032 
00033 
00034 void FrameRateNotify (Tag id,
00035                       Tag component,
00036                       EFuiEvents event,
00037                       EFuiEvents subevent)
00038 {
00039   CFuiManager *fui = globals->fuimgr;
00040   switch (event) {
00041   case EVENT_OPENWINDOW:
00042     {
00043       // Horizontal range is the number of stored samples, no grid is applicable
00044       // Vertical range defaults to 100 fps, grid lines very 20 fps
00045       float maxSamples = (float)(globals->drawRate->GetMaxSamples());
00046       fui->SetGraphGridRange (id, 'graf', 0, 0, maxSamples, 100.0f);
00047       fui->SetGraphGridSpacing (id, 'graf', maxSamples, 20.0f);
00048 
00049       // Add redraw frame rate graph trace
00050       fui->AddGraphTrace (id, 'graf', 'draw', FUI_GRAPH_TRACE_LINE);
00051       fui->SetGraphTraceColour (id, 'graf', 'draw', MakeRGB (255, 0, 0));
00052       fui->SetGraphTraceRange (id, 'graf', 'draw', 0, 0, maxSamples, 100.0f);
00053 
00054       // Set frame rate counter colour
00055       fui->SetLabelColour (id, 'rate', MakeRGB (255, 255, 255));
00056     }
00057     break;
00058 
00059   case EVENT_UPDATE:
00060     {
00061       // Update framerate
00062       static int rate = 0;
00063       rate++; if (rate > 100) rate = 0;
00064       char r[8];
00065       sprintf (r, "%d", r);
00066       fui->SetComponentText (id, 'rate', r);
00067 
00068       // Update traces
00069       float total = 0;
00070       fui->ClearGraphTracePoints(id, 'graf', 'draw');
00071       int nSamples = globals->drawRate->GetActualSamples ();
00072       for (int i=0; i<nSamples; i++) {
00073         float x = (float)i;
00074         float y = globals->drawRate->GetSample (i);
00075         fui->AddGraphTracePoint (id, 'graf', 'draw', x, y);
00076         total += y;
00077       }
00078 
00079       // Update average frame rate
00080       float avg = total / (float)nSamples;
00081       char s[8];
00082       sprintf (s, "%3d", (int)(floorf(avg)));
00083       fui->SetComponentText (id, 'rate', s);
00084 
00087 
00091     }
00092     break;
00093   }
00094 
00096 }
00097 
SourceForge.net Logo Documentation generated by doxygen