Re #572: use 3-letter code in scrolling leaderboard
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5320 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: bb24cd0f5ccd20d463a6d4ba571b4792a828775f Former-commit-id: ae9780fe6ba83fa4480928c1c5b6d757b4698473
This commit is contained in:
parent
5afb7c0a4d
commit
d2919b6748
4 changed files with 7 additions and 57 deletions
|
@ -74,6 +74,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
char name[MAX_NAME_LEN]; /**< Driver's name */
|
||||
char sname[MAX_NAME_LEN]; /**< Driver's short name */
|
||||
char codename[3+1]; /**< Driver's 3-letter codename */
|
||||
char teamname[MAX_NAME_LEN]; /**< Team name */
|
||||
char carName[MAX_NAME_LEN]; /**< Car object name */
|
||||
char category[MAX_NAME_LEN]; /**< Car's category */
|
||||
|
@ -113,6 +114,7 @@ typedef struct {
|
|||
/* structure access shortcuts */
|
||||
#define _name info.name /**< short cut to tInitCar#name */
|
||||
#define _sname info.sname /**< short cut to tInitCar#sname */
|
||||
#define _cname info.codename /**< short cut to tInitCar#codename */
|
||||
#define _teamname info.teamname /**< short cut to tInitCar#teamname */
|
||||
#define _carName info.carName /**< short cut to tInitCar#carName */
|
||||
#define _category info.category /**< short cut to tInitCar#category */
|
||||
|
|
|
@ -1627,11 +1627,6 @@ cGrBoard::grDispLeaderBoardScroll(const tSituation *s)
|
|||
void
|
||||
cGrBoard::grDispLeaderBoardScrollLine(const tSituation *s)
|
||||
{
|
||||
// At the start of the race or when first engaging this mode,
|
||||
// we generate the 3-letter names to be used
|
||||
if (iTimer == 0 || iStringStart == 0 || sShortNames.size() == 0)
|
||||
grMakeThreeLetterNames(s);
|
||||
|
||||
// At first, get the current time and rebuild the ScrollLine text
|
||||
if (iTimer == 0 || s->currentTime < iTimer) {
|
||||
iTimer = s->currentTime;
|
||||
|
@ -1651,7 +1646,7 @@ cGrBoard::grDispLeaderBoardScrollLine(const tSituation *s)
|
|||
// Driver position + name
|
||||
osRoster.width(3);
|
||||
osRoster << (i + 1);
|
||||
osRoster << ": " << sShortNames[i];
|
||||
osRoster << ": " << s->cars[i]->_cname;
|
||||
|
||||
// Display driver time / time behind leader / laps behind leader
|
||||
string sEntry = grGenerateLeaderBoardEntry(s->cars[i], s, (i == 0));
|
||||
|
@ -1765,54 +1760,6 @@ cGrBoard::grGenerateLeaderBoardEntry(const tCarElt *car, const tSituation* s,
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* grMakeThreeLetterNames
|
||||
*
|
||||
* Let's build an array of 3-letter name abbreviations (sShortNames).
|
||||
* As we follow original name order, this array can be indexed
|
||||
* the same as the original names' array.
|
||||
*
|
||||
* @param s situation provided by SD
|
||||
*/
|
||||
void
|
||||
cGrBoard::grMakeThreeLetterNames(const tSituation *s)
|
||||
{
|
||||
// Build up two arrays of the original and the short names, same order.
|
||||
sShortNames.clear();
|
||||
std::vector<string> origNames;
|
||||
for (int i = 0; i < s->_ncars; i++) { // Loop over each name in the race
|
||||
string st(s->cars[i]->_name);
|
||||
origNames.push_back(st);
|
||||
remove(st.begin(), st.end(), ' '); // Remove spaces
|
||||
sShortNames.push_back(st.substr(0, 3)); // Cut to 3 characters
|
||||
} // for i
|
||||
// Copy to hold original 3-letter names, for search
|
||||
std::vector<string> origShortNames(sShortNames);
|
||||
|
||||
// Check for matching names
|
||||
for (unsigned int i = 0; i < sShortNames.size(); i++) {
|
||||
string sSearch(origShortNames[i]);
|
||||
for (unsigned int j = i + 1; j < sShortNames.size(); j++) {
|
||||
if (sSearch == origShortNames[j]) { // Same 3-letter name found
|
||||
// Let's find the first mismatching character
|
||||
unsigned int k;
|
||||
for (k = 0;
|
||||
k < std::min(origNames[i].size(), origNames[j].size());
|
||||
++k) {
|
||||
if (origNames[i][k] != origNames[j][k]) break;
|
||||
} // for k
|
||||
// Set 3rd char of the short name to the mismatching char (or last one).
|
||||
// It is the driver designer's responsibility from now on
|
||||
// to provide some unsimilarities between driver names.
|
||||
sShortNames[i][2] = origNames[i][k];
|
||||
sShortNames[j][2] = origNames[j][k];
|
||||
} // if sSearch
|
||||
} // for j
|
||||
} // for i
|
||||
// 3-letter name array ready to use!
|
||||
} // grMakeThreeLetterName
|
||||
|
||||
|
||||
/**
|
||||
* Set up a drawing area to put textual info there.
|
||||
*
|
||||
|
|
|
@ -47,12 +47,11 @@ class cGrBoard
|
|||
int centerAnchor;
|
||||
int rightAnchor;
|
||||
int speedoRise;
|
||||
std::vector<std::string> sShortNames;
|
||||
// Scrolling leaderboard variables
|
||||
int iStart;
|
||||
double iTimer;
|
||||
int iStringStart;
|
||||
std::string st; // This is the line we will display in the bottom
|
||||
std::string st; // This is the line we will display in the top
|
||||
|
||||
private:
|
||||
void grDispDebug(const tSituation *s, const cGrFrameInfo* frame);
|
||||
|
@ -83,7 +82,6 @@ class cGrBoard
|
|||
double &time, int *laps_different, float **color);
|
||||
void grGetLapsTime(const tSituation *s, char* result,
|
||||
char const** label) const;
|
||||
void grMakeThreeLetterNames(const tSituation *s);
|
||||
void grSetupDrawingArea(int xl, int yb, int xr, int yt) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -534,12 +534,15 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int
|
|||
if (normal_carname || elt->_driverType == RM_DRV_HUMAN) {
|
||||
strncpy(elt->_name, GfParmGetStr(robhdle, path, ROB_ATTR_NAME, "none"), MAX_NAME_LEN - 1);
|
||||
strncpy(elt->_sname, GfParmGetStr(robhdle, path, ROB_ATTR_SNAME, "none"), MAX_NAME_LEN - 1);
|
||||
strncpy(elt->_cname, GfParmGetStr(robhdle, path, ROB_ATTR_CODE, "---"), 3);
|
||||
} else {
|
||||
strncpy(elt->_name, GfParmGetStr(ReInfo->params, path2, ROB_ATTR_NAME, "none"), MAX_NAME_LEN - 1);
|
||||
strncpy(elt->_sname, GfParmGetStr(ReInfo->params, path2, ROB_ATTR_SNAME, "none"), MAX_NAME_LEN - 1);
|
||||
strncpy(elt->_cname, GfParmGetStr(ReInfo->params, path2, ROB_ATTR_CODE, "---"), 3);
|
||||
}
|
||||
elt->_name[MAX_NAME_LEN - 1] = 0;
|
||||
elt->_sname[MAX_NAME_LEN - 1] = 0;
|
||||
elt->_cname[3] = 0;
|
||||
|
||||
teamname = GfParmGetStr(robhdle, path, ROB_ATTR_TEAM, "none");
|
||||
teamname = GfParmGetStr(ReInfo->params, path2, ROB_ATTR_TEAM, teamname ); //Use the name in params if it has a team name
|
||||
|
|
Loading…
Reference in a new issue