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_BOARDS 3
#define NB_LBOARDS 5 //# of leaderboard states #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 // 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 // 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. * Displays debug information in the top right corner.
* It is a 3-state display, states as follows: * It is a 3-state display, states as follows:
* 0 - Don't display any info * 0 - Don't display any info
* 1 - Display the FPS only * 1 - Display the mean and instant FPS
* 2 - Display FPS, the segment the car is on, car's distance from startline, current camera * 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 frame Frame info to display
* @param avgFps Average frame rate value to display
* @param car The current car * @param car The current car
*/ */
void void
cGrBoard::grDispDebug(float instFps, float avgFps, tCarElt *car) cGrBoard::grDispDebug(const tCarElt *car, const cGrFrameInfo* frame)
{ {
char buf[BUFSIZE]; char buf[BUFSIZE];
int x, y, dy; int x, y, dy;
@ -186,10 +186,16 @@ cGrBoard::grDispDebug(float instFps, float avgFps, tCarElt *car)
dy = GfuiFontHeight(GFUI_FONT_SMALL_C); dy = GfuiFontHeight(GFUI_FONT_SMALL_C);
//Display frame rates (instant and average) //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); 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 //Display segment name
y -= dy; y -= dy;
snprintf(buf, sizeof(buf), "Seg: %s", car->_trkPos.seg->name); snprintf(buf, sizeof(buf), "Seg: %s", car->_trkPos.seg->name);
@ -1189,8 +1195,8 @@ 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) bool forceArcade, tCarElt *currCar, bool isCurrScreen)
{ {
grDispMisc(isCurrScreen); grDispMisc(isCurrScreen);
@ -1198,7 +1204,7 @@ void cGrBoard::refreshBoard(tSituation *s, float instFps, float avgFps,
grDispArcade(currCar, s); grDispArcade(currCar, s);
} else { } else {
if (debugFlag) if (debugFlag)
grDispDebug(instFps, avgFps, currCar); grDispDebug(currCar, frameInfo);
if (GFlag) if (GFlag)
grDispGGraph(currCar); grDispGGraph(currCar);
if (boardFlag) if (boardFlag)

View file

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

View file

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

View file

@ -81,4 +81,13 @@ extern class cGrScreen* grGetCurrentScreen(void);
extern tdble grLodFactorValue; 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_ */ #endif /* _GRMAIN_H_ */

View file

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

View file

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