MAX_GEARS and average fps
Mart Kelder <[email protected]>
| Newsgroups | gmane.games.torcs.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all, I have made two small patches. First, MAX_GEARS is the constant number which tells Torcs what the maximum number of gears is a car can have (including reverse and neutral). But the definition of MAX_GEARS isn't the only place where this is defined. Some static char* definitions also implicit define the maximum number of gears. The patch "max_gears.patch" solves this. It maybe also solves the problem that the gear numbers are not displayed correctly if the car has no reverse. Secondly, someone asked for the average fps for automatic testing purposes. I made a simple patch which prints the average fps of a race to the console. Regards, Mart ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Torcs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/torcs-devel
fps_average.patch
(text/x-diff, 1.2 KB)
Index: src/modules/graphic/ssggraph/grmain.cpp
===================================================================
--- src/modules/graphic/ssggraph/grmain.cpp (revision 5)
+++ src/modules/graphic/ssggraph/grmain.cpp (working copy)
@@ -47,6 +47,8 @@
int maxTextureUnits = 0;
static double OldTime;
static int nFrame;
+static int nTotalFrame;
+static int nSeconds;
float grFps;
double grCurTime;
double grDeltaTime;
@@ -246,6 +248,8 @@
OldTime = GfTimeClock();
nFrame = 0;
+ nTotalFrame = 0;
+ nSeconds = 0;
grFps = 0;
sprintf(buf, "%s%s", GetLocalDir(), GR_PARAM_FILE);
@@ -304,12 +308,14 @@
START_PROFILE("refresh");
nFrame++;
+ nTotalFrame++;
grCurTime = GfTimeClock();
grDeltaTime = grCurTime - OldTime;
if ((grCurTime - OldTime) > 1.0) {
/* The Frames Per Second (FPS) display is refreshed every second */
grFps = (tdble)nFrame / (grCurTime - OldTime);
nFrame = 0;
+ ++nSeconds;
OldTime = grCurTime;
}
@@ -434,6 +440,9 @@
for (i = 0; i < GR_NB_MAX_SCREEN; i++) {
grScreens[i]->setCurrentCar(NULL);
}
+
+ if (nSeconds > 0)
+ printf( "Avagerage Fps: %.2f\n", (double)nTotalFrame/((double)nSeconds+GfTimeClock()-OldTime) );
}
int
max_gears.patch
(text/x-diff, 3.8 KB)
Index: src/modules/simu/simuv2/transmission.cpp
===================================================================
--- src/modules/simu/simuv2/transmission.cpp (revision 24)
+++ src/modules/simu/simuv2/transmission.cpp (working copy)
@@ -19,7 +19,7 @@
#include "sim.h"
-static char *gearname[MAX_GEARS] = {"r", "n", "1", "2", "3", "4", "5", "6", "7", "8"};
+//static char *gearname[MAX_GEARS] = {"r", "n", "1", "2", "3", "4", "5", "6", "7", "8"};
void
SimTransmissionConfig(tCar *car)
@@ -81,7 +81,10 @@
trans->gearbox.gearMax = 0;
for (i = MAX_GEARS - 1; i >= 0; i--) {
- sprintf(path, "%s/%s/%s", SECT_GEARBOX, ARR_GEARS, gearname[i]);
+ if (i<2)
+ sprintf(path, "%s/%s/%s", SECT_GEARBOX, ARR_GEARS, i==0 ? "r" : "n");
+ else
+ sprintf(path, "%s/%s/%d", SECT_GEARBOX, ARR_GEARS, i-1);
gRatio = GfParmGetNum(hdle, path, PRM_RATIO, (char*)NULL, 0.0);
if ((trans->gearbox.gearMax == 0) && (gRatio != 0.0)) {
trans->gearbox.gearMax = i - 1;
Index: src/modules/simu/simuv3/transmission.cpp
===================================================================
--- src/modules/simu/simuv3/transmission.cpp (revision 5)
+++ src/modules/simu/simuv3/transmission.cpp (working copy)
@@ -19,7 +19,7 @@
#include "sim.h"
-static char *gearname[MAX_GEARS] = {"r", "n", "1", "2", "3", "4", "5", "6", "7", "8"};
+//static char *gearname[MAX_GEARS] = {"r", "n", "1", "2", "3", "4", "5", "6", "7", "8"};
void
SimTransmissionConfig(tCar *car)
@@ -80,7 +80,10 @@
trans->gearbox.gearMax = 0;
//printf ("engine I %f\n", car->engine.I);
for (i = MAX_GEARS - 1; i >= 0; i--) {
- sprintf(path, "%s/%s/%s", SECT_GEARBOX, ARR_GEARS, gearname[i]);
+ if (i<2)
+ sprintf(path, "%s/%s/%s", SECT_GEARBOX, ARR_GEARS, i==0 ? "r" : "n");
+ else
+ sprintf(path, "%s/%s/%d", SECT_GEARBOX, ARR_GEARS, i-1);
gRatio = GfParmGetNum(hdle, path, PRM_RATIO, (char*)NULL, 0.0f);
if ((trans->gearbox.gearMax == 0) && (gRatio != 0.0f)) {
trans->gearbox.gearMax = i - 1;
Index: src/modules/graphic/ssggraph/grboard.cpp
===================================================================
--- src/modules/graphic/ssggraph/grboard.cpp (revision 5)
+++ src/modules/graphic/ssggraph/grboard.cpp (working copy)
@@ -467,7 +467,7 @@
}
}
-static const char *gearStr[MAX_GEARS] = {"R", "N", "1", "2", "3", "4", "5", "6", "7", "8"};
+//static const char *gearStr[MAX_GEARS] = {"R", "N", "1", "2", "3", "4", "5", "6", "7", "8"};
#define ALIGN_CENTER 0
#define ALIGN_LEFT 1
@@ -570,7 +570,11 @@
x = Winx + Winw/2;
y = Winy;
- sprintf(buf, " kph %s", gearStr[car->_gear+car->_gearOffset]);
+ if (car->_gear <= 0)
+ sprintf(buf, " kph %s", car->_gear == 0 ? "N" : "R");
+ else
+ sprintf(buf, " kph %d", car->_gear);
+ //sprintf(buf, " kph %s", gearStr[car->_gear+car->_gearOffset]);
GfuiPrintString(buf, grBlue, GFUI_FONT_BIG_C, x, y, GFUI_ALIGN_HL_VB);
x = Winx + Winw/2;
@@ -721,7 +725,11 @@
glCallList(curInst->needleList);
glPopMatrix();
- GfuiPrintString((char*)(gearStr[car->_gear+car->_gearOffset]), grRed, GFUI_FONT_LARGE_C,
+ if (car->_gear <= 0)
+ strcpy(buf, car->_gear == 0 ? "N" : "R");
+ else
+ sprintf(buf, "%d", car->_gear);
+ GfuiPrintString(buf, grRed, GFUI_FONT_LARGE_C,
(int)curInst->digitXCenter, (int)(curInst->digitYCenter), GFUI_ALIGN_HC_VB);
@@ -831,7 +839,10 @@
sprintf(buf, "%3d km/h", abs((int)(car->_speed_x * 3.6)));
GfuiPrintString(buf, grDefaultClr, GFUI_FONT_BIG_C, x, y, GFUI_ALIGN_HR_VB);
y = YM;
- sprintf(buf, "%s", gearStr[car->_gear+car->_gearOffset]);
+ if (car->_gear <= 0)
+ sprintf(buf, "%s", car->_gear == 0 ? "N" : "R");
+ else
+ sprintf(buf, "%d", car->_gear);
GfuiPrintString(buf, grDefaultClr, GFUI_FONT_LARGE_C, x, y, GFUI_ALIGN_HR_VB);
grDispEngineLeds (car, Winx + Winw - XM, YM + dy + GfuiFontHeight (GFUI_FONT_BIG_C), ALIGN_RIGHT, 0);