Re #373 Added total number of frames in the 5-keypad-selectable debug indicator (top right of the race screen)

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3451 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 05177702d976489d5adb5283083f05c76779f44b
Former-commit-id: abf3aa2a210c189ea7d6eeaba7f6ec56ba7a3a30
This commit is contained in:
pouillot 2011-03-19 11:21:04 +00:00
parent 830f223ad1
commit ab6d7dfc0a
6 changed files with 51 additions and 37 deletions

View file

@ -46,7 +46,7 @@ static float grDefaultClr[4] = {0.9, 0.9, 0.15, 1.0};
#define NB_BOARDS 3
#define NB_LBOARDS 5 //# of leaderboard states
#define NB_DEBUG 3
#define NB_DEBUG 4
// Boards work on a OrthoCam with fixed height of 600, width flows
// with split screen(s) and can be limited to 'board width' % of screen
@ -167,15 +167,15 @@ cGrBoard::selectBoard(int val)
* Displays debug information in the top right corner.
* It is a 3-state display, states as follows:
* 0 - Don't display any info
* 1 - Display the FPS only
* 2 - Display FPS, the segment the car is on, car's distance from startline, current camera
* 1 - Display the mean and instant FPS
* 2 - Like 2 + the absolute frame counter
* 3 - Like 2 + the segment the car is on, car's distance from startline, current camera
*
* @param instFps Instant frame rate value to display
* @param avgFps Average frame rate value to display
* @param frame Frame info to display
* @param car The current car
*/
void
cGrBoard::grDispDebug(float instFps, float avgFps, tCarElt *car)
cGrBoard::grDispDebug(const tCarElt *car, const cGrFrameInfo* frame)
{
char buf[BUFSIZE];
int x, y, dy;
@ -186,10 +186,16 @@ cGrBoard::grDispDebug(float instFps, float avgFps, tCarElt *car)
dy = GfuiFontHeight(GFUI_FONT_SMALL_C);
//Display frame rates (instant and average)
snprintf(buf, sizeof(buf), "FPS: %.1f(%.1f)", instFps, avgFps);
snprintf(buf, sizeof(buf), "FPS: %.1f(%.1f)", frame->fInstFps, frame->fAvgFps);
GfuiPrintString(buf, grWhite, GFUI_FONT_SMALL_C, x, y, GFUI_ALIGN_HL_VB);
if(debugFlag == 2) { //Only display detailed information in Debug Mode 2
if(debugFlag == 2) { //Only display detailed information in Debug Mode > 1
//Display frame counter
y -= dy;
snprintf(buf, sizeof(buf), "Frm: %u", frame->nTotalFrames);
GfuiPrintString(buf, grWhite, GFUI_FONT_SMALL_C, x, y, GFUI_ALIGN_HL_VB);
} else if(debugFlag == 3) { //Only display detailed information in Debug Mode > 1
//Display segment name
y -= dy;
snprintf(buf, sizeof(buf), "Seg: %s", car->_trkPos.seg->name);
@ -1189,7 +1195,7 @@ void cGrBoard::grGetLapsTime(tSituation *s, tCarElt *car,
}
}
void cGrBoard::refreshBoard(tSituation *s, float instFps, float avgFps,
void cGrBoard::refreshBoard(tSituation *s, const cGrFrameInfo* frameInfo,
bool forceArcade, tCarElt *currCar, bool isCurrScreen)
{
grDispMisc(isCurrScreen);
@ -1198,7 +1204,7 @@ void cGrBoard::refreshBoard(tSituation *s, float instFps, float avgFps,
grDispArcade(currCar, s);
} else {
if (debugFlag)
grDispDebug(instFps, avgFps, currCar);
grDispDebug(currCar, frameInfo);
if (GFlag)
grDispGGraph(currCar);
if (boardFlag)

View file

@ -24,6 +24,7 @@
#include <raceman.h> //tSituation
class cGrTrackMap;
class cGrFrameInfo;
#include <string>
#include <vector>
@ -48,7 +49,7 @@ class cGrBoard
std::vector<std::string> sShortNames;
private:
void grDispDebug(float instFps, float avgFps, tCarElt *car);
void grDispDebug(const tCarElt *car, const cGrFrameInfo* frame);
void grDispGGraph(tCarElt *car);
void grDispCarBoard1(tCarElt *car, tSituation *s);
void grDispMisc(bool bCurrentScreen);
@ -80,7 +81,7 @@ class cGrBoard
void initBoardCar(tCarElt *car);
inline cGrTrackMap *getTrackMap() { return trackMap; }
void refreshBoard(tSituation *s, float instFps, float avgFps,
void refreshBoard(tSituation *s, const cGrFrameInfo* frameInfo,
bool forceArcade, tCarElt *currCar, bool isCurrScreen);
void loadDefaults(tCarElt *curCar);
};

View file

@ -57,13 +57,10 @@ ssgContext grContext;
class cGrScreen *grScreens[GR_NB_MAX_SCREEN] = {NULL, NULL, NULL, NULL};
tdble grLodFactorValue = 1.0;
// FPS indicator variables.
static float grInstFps; // Instant frame rate (average along a 1 second shifting window).
static float grAvgFps; // Average frame rate (since the beginning of the race).
static double dFPSPrevTime;
static int nFPSFrames;
static int nFPSTotalFrames;
static int nFPSTotalSeconds;
// Frame/FPS info.
static cGrFrameInfo frameInfo;
static double fFPSPrevInstTime; // Last "instant" FPS refresh time
static unsigned nFPSTotalSeconds; // Total duration since initView
// Mouse coords graphics backend to screen ratios.
static float fMouseRatioX, fMouseRatioY;
@ -269,12 +266,12 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen)
fMouseRatioX = width / 640.0;
fMouseRatioY = height / 480.0;
dFPSPrevTime = GfTimeClock();
nFPSFrames = 0;
nFPSTotalFrames = 0;
frameInfo.fInstFps = 0.0;
frameInfo.fAvgFps = 0.0;
frameInfo.nInstFrames = 0;
frameInfo.nTotalFrames = 0;
fFPSPrevInstTime = GfTimeClock();
nFPSTotalSeconds = 0;
grInstFps = 0;
grAvgFps = 0;
if (!grHandle)
{
@ -338,16 +335,16 @@ refresh(tSituation *s)
GfProfStartProfile("refresh");
// Compute FPS indicators every second.
nFPSFrames++;
nFPSTotalFrames++;
frameInfo.nInstFrames++;
const double dCurTime = GfTimeClock();
const double dDeltaTime = dCurTime - dFPSPrevTime;
const double dDeltaTime = dCurTime - fFPSPrevInstTime;
if (dDeltaTime > 1.0) {
++nFPSTotalSeconds;
grInstFps = nFPSFrames / dDeltaTime;
nFPSFrames = 0;
dFPSPrevTime = dCurTime;
grAvgFps = (tdble)nFPSTotalFrames / nFPSTotalSeconds;
fFPSPrevInstTime = dCurTime;
frameInfo.fInstFps = frameInfo.nInstFrames / dDeltaTime;
frameInfo.nTotalFrames += frameInfo.nInstFrames;
frameInfo.nInstFrames = 0;
frameInfo.fAvgFps = (double)frameInfo.nTotalFrames / nFPSTotalSeconds;
}
TRACE_GL("refresh: start");
@ -370,7 +367,7 @@ refresh(tSituation *s)
GfProfStopProfile("grDrawBackground/glClear");
for (i = 0; i < grNbActiveScreens; i++) {
grScreens[i]->update(s, grInstFps, grAvgFps);
grScreens[i]->update(s, &frameInfo);
}
grUpdateSmoke(s->currentTime);
@ -507,7 +504,7 @@ shutdownCars(void)
if (nFPSTotalSeconds > 0)
GfLogTrace("Average FPS: %.2f\n",
(double)nFPSTotalFrames/((double)nFPSTotalSeconds + GfTimeClock() - dFPSPrevTime));
(double)frameInfo.nTotalFrames/((double)nFPSTotalSeconds + GfTimeClock() - fFPSPrevInstTime));
}
int

View file

@ -81,4 +81,13 @@ extern class cGrScreen* grGetCurrentScreen(void);
extern tdble grLodFactorValue;
class cGrFrameInfo
{
public:
double fInstFps; // "Instant" frame rate (average along a 1 second shifting window).
double fAvgFps; // Average frame rate (since the beginning of the race).
unsigned nInstFrames; // Nb of frames since the last "instant" FPS refresh time
unsigned nTotalFrames; // Total nb of frames since initView
};
#endif /* _GRMAIN_H_ */

View file

@ -300,7 +300,7 @@ void cGrScreen::camDraw(tSituation *s)
/* Update screen display */
void cGrScreen::update(tSituation *s, float instFps, float avgFps)
void cGrScreen::update(tSituation *s, const cGrFrameInfo* frameInfo)
{
if (!active) {
return;
@ -381,7 +381,7 @@ void cGrScreen::update(tSituation *s, float instFps, float avgFps)
glDisable(GL_TEXTURE_2D);
TRACE_GL("cGrScreen::update glDisable(GL_DEPTH_TEST)");
board->refreshBoard(s, instFps, avgFps, false, curCar,
board->refreshBoard(s, frameInfo, false, curCar,
grNbActiveScreens > 1 && grGetCurrentScreen() == this);
TRACE_GL("cGrScreen::update display boards");

View file

@ -23,6 +23,7 @@
#include "grcam.h" //Cameras
class cGrBoard;
class cGrFrameInfo;
class cGrScreen {
protected:
@ -63,7 +64,7 @@ class cGrScreen {
inline void deactivate(void) { active = false; }
inline void setZoom(const long zoom) { curCam->setZoom(zoom); }
int isInScreen(int x, int y);
void update(tSituation *s, float instFps, float avgFps);
void update(tSituation *s, const cGrFrameInfo* frameInfo);
void camDraw(tSituation *s);
void updateCurrent(tSituation *s);