From d2919b674887d669587a05fdcc4520fcc751ee5a Mon Sep 17 00:00:00 2001 From: kmetykog Date: Fri, 15 Mar 2013 00:24:04 +0000 Subject: [PATCH] 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 --- src/interfaces/car.h | 2 + src/modules/graphic/ssggraph/grboard.cpp | 55 +------------------- src/modules/graphic/ssggraph/grboard.h | 4 +- src/modules/racing/standardgame/raceinit.cpp | 3 ++ 4 files changed, 7 insertions(+), 57 deletions(-) diff --git a/src/interfaces/car.h b/src/interfaces/car.h index d4d97b534..15632ecb1 100644 --- a/src/interfaces/car.h +++ b/src/interfaces/car.h @@ -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 */ diff --git a/src/modules/graphic/ssggraph/grboard.cpp b/src/modules/graphic/ssggraph/grboard.cpp index 1b4293e8f..675d27cc6 100644 --- a/src/modules/graphic/ssggraph/grboard.cpp +++ b/src/modules/graphic/ssggraph/grboard.cpp @@ -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 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 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. * diff --git a/src/modules/graphic/ssggraph/grboard.h b/src/modules/graphic/ssggraph/grboard.h index 3d469c95d..e4f670013 100644 --- a/src/modules/graphic/ssggraph/grboard.h +++ b/src/modules/graphic/ssggraph/grboard.h @@ -47,12 +47,11 @@ class cGrBoard int centerAnchor; int rightAnchor; int speedoRise; - std::vector 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: diff --git a/src/modules/racing/standardgame/raceinit.cpp b/src/modules/racing/standardgame/raceinit.cpp index 221bc4f87..8f1e81fe5 100644 --- a/src/modules/racing/standardgame/raceinit.cpp +++ b/src/modules/racing/standardgame/raceinit.cpp @@ -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