Skip to content

Commit

Permalink
move StrTime to Def_Str.h
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Sep 11, 2015
1 parent de2f886 commit 5a8fdb5
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 76 deletions.
30 changes: 0 additions & 30 deletions source/ogre/CHud.cpp
Expand Up @@ -88,36 +88,6 @@ ManualObject* CHud::Create2D(const String& mat, SceneManager* sceneMgr,
}


// hud util
String CHud::StrTime(float time)
{
int min = (int) time / 60;
float secs = time - min*60;

if (time != 0.f)
{
String ss;
ss = toStr(min)+":"+fToStr(secs,2,5,'0');
return ss;
}else
return "-:--.--";
}
String CHud::StrTime2(float time)
{
int min = (int) time / 60;
float secs = time - min*60;

if (time != 0.0)
{
String ss;
ss = toStr(min)+":"+fToStr(secs,0,2,'0');
return ss;
}else
return "-:--";
}



// HUD utils
//---------------------------------------------------------------------------------------------------------------
void CHud::UpdMiniTer()
Expand Down
1 change: 0 additions & 1 deletion source/ogre/CHud.h
Expand Up @@ -152,7 +152,6 @@ class CHud
Ogre::Vector3 projectPoint(const Ogre::Camera* cam, const Ogre::Vector3& pos); // 2d xy, z - out info

// string utils
static Ogre::String StrTime(float time), StrTime2(float time); // 2=short
Ogre::String StrClr(Ogre::ColourValue c);

// bullet debug text
Expand Down
20 changes: 10 additions & 10 deletions source/ogre/Challenges.cpp
Expand Up @@ -66,7 +66,7 @@ void CGui::ChallsListUpdate()
liChalls->setSubItemNameAt(3,l, StrChallCars(chl));

liChalls->setSubItemNameAt(4,l, gcom->clrsDiff[std::min(8,ntrks*2/3+1)]+ iToStr(ntrks,3));
liChalls->setSubItemNameAt(5,l, gcom->clrsDiff[std::min(8,int(chl.time/3.f/60.f))]+ CHud::StrTime2(chl.time));
liChalls->setSubItemNameAt(5,l, gcom->clrsDiff[std::min(8,int(chl.time/3.f/60.f))]+ StrTime2(chl.time));
liChalls->setSubItemNameAt(6,l, ct == 0 || ct == ntrks ? "" :
clr+ fToStr(100.f * ct / ntrks,0,3)+" %");

Expand Down Expand Up @@ -303,7 +303,7 @@ void CGui::ChallengeAdvance(float timeCur/*total*/)
if (trk.timeNeeded > 0.f)
{
pa = pt.time <= trk.timeNeeded;
LogO("]] TotTime: " + CHud::StrTime(pt.time) + " Needed: " + CHud::StrTime(trk.timeNeeded) + " Passed: " + (pa ? "yes":"no"));
LogO("]] TotTime: " + StrTime(pt.time) + " Needed: " + StrTime(trk.timeNeeded) + " Passed: " + (pa ? "yes":"no"));
passed &= pa;
}
if (trk.passPoints > 0.f)
Expand Down Expand Up @@ -387,8 +387,8 @@ void CGui::ChallengeAdvance(float timeCur/*total*/)
pa = pc.totalTime <= ch.totalTime;
// for p <= pp ..

LogO("]] TotalTime: "+CHud::StrTime(pc.totalTime)+" Needed: "+CHud::StrTime(ch.totalTime)+" Passed: "+(pa ? "yes":"no"));
ss += TR("#D8C0FF#{TBTime}")+": "+CHud::StrTime(pc.totalTime)+" / "+CHud::StrTime(ch.totalTime) + sPass(pa) +"\n";
LogO("]] TotalTime: "+StrTime(pc.totalTime)+" Needed: "+StrTime(ch.totalTime)+" Passed: "+(pa ? "yes":"no"));
ss += TR("#D8C0FF#{TBTime}")+": "+StrTime(pc.totalTime)+" / "+StrTime(ch.totalTime) + sPass(pa) +"\n";
passed &= pa;
}

Expand Down Expand Up @@ -518,7 +518,7 @@ void CGui::ChallFillStageInfo(bool finished)
if (trk.timeNeeded > 0.f)
{
pa = pt.time <= trk.timeNeeded;
s += TR("#D8C0FF#{TBTime}: ") + CHud::StrTime(pt.time) + " / " + CHud::StrTime(trk.timeNeeded) + sPass(pa) +"\n";
s += TR("#D8C0FF#{TBTime}: ") + StrTime(pt.time) + " / " + StrTime(trk.timeNeeded) + sPass(pa) +"\n";
passed &= pa;
}
if (trk.passPoints > 0.f)
Expand All @@ -540,7 +540,7 @@ void CGui::ChallFillStageInfo(bool finished)
else
{ /// Pass needed --------------
s += "#F0F060"+TR("#{Needed}") +"\n";
if (trk.timeNeeded > 0.f) s += TR(" #D8C0FF#{TBTime}: ") + CHud::StrTime(trk.timeNeeded) +"\n";
if (trk.timeNeeded > 0.f) s += TR(" #D8C0FF#{TBTime}: ") + StrTime(trk.timeNeeded) +"\n";
if (trk.passPoints > 0.f) s += TR(" #D8C0FF#{TBPoints}: ") + fToStr(trk.passPoints,1) +"\n";
if (trk.passPos > 0) s += TR(" #D8C0FF#{TBPosition}: ") + toStr(trk.passPos) +"\n";
if (app->scn->road) s += "\n#A8B8C8"+ app->scn->road->sTxtDesc;
Expand Down Expand Up @@ -578,7 +578,7 @@ void CGui::UpdChallDetail(int id)

//s1 += "\n"; s2 += "\n";
clr = gcom->clrsDiff[std::min(8,int(ch.time/3.f/60.f))];
s1 += TR("#80F0E0#{Time} [#{TimeMS}.]\n"); s2 += "#C0FFE0"+clr+ CHud::StrTime2(ch.time)+"\n";
s1 += TR("#80F0E0#{Time} [#{TimeMS}.]\n"); s2 += "#C0FFE0"+clr+ StrTime2(ch.time)+"\n";

// cars --------
s1 += "\n"; s2 += "\n";
Expand Down Expand Up @@ -621,7 +621,7 @@ void CGui::UpdChallDetail(int id)
fToStr(ch.avgPos + ciAddPos[p] * ch.factor ,1,3)+" ";
s2 += "\n"; }
if (ch.totalTime > 0.f){ s1 += TR(" #{TBTime}\n");
s2 += CHud::StrTime(ch.totalTime)+"\n"; }
s2 += StrTime(ch.totalTime)+"\n"; }
}
txtChP[1]->setCaption(s1); valChP[1]->setCaption(s2);

Expand All @@ -638,7 +638,7 @@ void CGui::UpdChallDetail(int id)
s1 += "#D8C0FF"; s2 += "#F0D8FF";
if (trk.passPoints > 0.f){ s1 += TR(" #{TBPoints}\n"); s2 += fToStr(trk.passPoints,2,5)+"\n"; }
if (trk.passPos > 0.f) { s1 += TR(" #{TBPosition}\n"); s2 += fToStr(trk.passPos,2,5)+"\n"; }
if (trk.timeNeeded > 0.f){ s1 += TR(" #{TBTime}\n"); s2 += CHud::StrTime(trk.timeNeeded)+"\n"; }
if (trk.timeNeeded > 0.f){ s1 += TR(" #{TBTime}\n"); s2 += StrTime(trk.timeNeeded)+"\n"; }
} }
txtChP[0]->setCaption(s1); valChP[0]->setCaption(s2);

Expand All @@ -655,7 +655,7 @@ void CGui::UpdChallDetail(int id)
s1 += "\n"; s2 += "\n"; clrP(ch.avgPoints > 0.f);
s1 += TR(" #{TBPoints}\n"); s2 += fToStr(pc.avgPoints,2,5)+"\n"; clrP(ch.avgPos > 0.f);
s1 += TR(" #{TBPosition}\n"); s2 += fToStr(pc.avgPos,2,5)+"\n"; clrP(ch.totalTime > 0.f);
s1 += TR(" #{TBTime}\n"); s2 += CHud::StrTime(pc.totalTime)+"\n";
s1 += TR(" #{TBTime}\n"); s2 += StrTime(pc.totalTime)+"\n";
}
txtChP[2]->setCaption(s1); valChP[2]->setCaption(s2);

Expand Down
8 changes: 4 additions & 4 deletions source/ogre/ChampChall.cpp
Expand Up @@ -158,17 +158,17 @@ void CGui::Ch_XmlLoad()
time += (*it).second;
++trks;
} }
LogO("Total tracks: "+ toStr(trks) + ", total time: "+ CHud::StrTime2(time/60.f)+" h:m");
LogO("Total tracks: "+ toStr(trks) + ", total time: "+ StrTime2(time/60.f)+" h:m");


#if 0 /* test race pos,points */
float trk = 100.f;
LogO("Test Time "+CHud::StrTime(trk)+" Pos Points");
LogO("Test Time "+StrTime(trk)+" Pos Points");
for (int i=-5; i <= 20; ++i)
{
float points = 0.f, t = trk + i*1.f;
int pos = GetRacePos(t, trk, 1.0f, true, &points);
LogO(" "+CHud::StrTime(t)+" "+iToStr(pos,2)+" "+fToStr(points,2,5));
LogO(" "+StrTime(t)+" "+iToStr(pos,2)+" "+fToStr(points,2,5));
}
#endif

Expand Down Expand Up @@ -354,7 +354,7 @@ void CGui::StageListAdd(int n, String name, int laps, String progress)
liStages->setSubItemNameAt(2,l, clr+ ti.scenery);
liStages->setSubItemNameAt(3,l, gcom->clrsDiff[ti.diff]+ TR("#{Diff"+toStr(ti.diff)+"}"));
liStages->setSubItemNameAt(4,l, "#60C0A0 "+toStr(laps));
liStages->setSubItemNameAt(5,l, "#80C0F0 "+CHud::StrTime2(time));
liStages->setSubItemNameAt(5,l, "#80C0F0 "+StrTime2(time));
liStages->setSubItemNameAt(6,l, progress);
}

Expand Down
4 changes: 2 additions & 2 deletions source/ogre/Championships.cpp
Expand Up @@ -62,7 +62,7 @@ void CGui::ChampsListUpdate()
liChamps->setSubItemNameAt(2,l, gcom->clrsDiff[ch.diff]+ TR("#{Diff"+toStr(ch.diff)+"}"));

liChamps->setSubItemNameAt(3,l, gcom->clrsDiff[std::min(8,ntrks*2/3+1)]+ iToStr(ntrks,3));
liChamps->setSubItemNameAt(4,l, gcom->clrsDiff[std::min(8,int(ch.time/3.f/60.f))]+" "+ CHud::StrTime2(ch.time));
liChamps->setSubItemNameAt(4,l, gcom->clrsDiff[std::min(8,int(ch.time/3.f/60.f))]+" "+ StrTime2(ch.time));
liChamps->setSubItemNameAt(5,l, ct == 0 || ct == ntrks ? "" :
clr+ fToStr(100.f * ct / ntrks,0,3)+" %");

Expand Down Expand Up @@ -158,7 +158,7 @@ void CGui::listChampChng(MyGUI::MultiList2* chlist, size_t id)

s1 += "\n"; s2 += "\n";
clr = gcom->clrsDiff[std::min(8,int(ch.time/3.f/60.f))];
s1 += TR("#80F0E0#{Time} [#{TimeMS}.]\n"); s2 += "#C0FFE0"+clr+ CHud::StrTime2(ch.time)+"\n";
s1 += TR("#80F0E0#{Time} [#{TimeMS}.]\n"); s2 += "#C0FFE0"+clr+ StrTime2(ch.time)+"\n";

s1 += "\n\n"; s2 += "\n\n";
int cur = progress[p].chs[pos].curTrack, all = data->champs->all[pos].trks.size();
Expand Down
2 changes: 1 addition & 1 deletion source/ogre/Gui_Replay.cpp
Expand Up @@ -141,7 +141,7 @@ void CGui::listRplChng(List* li, size_t pos)
ss = String(TR("#{Vehicles}: "));
for (n=0; n < pp; ++n) ss += rh.cars[n] + " ";
ss += //(netw == 0 ? "" : "M") + //TR("#{Multiplayer}")
"\n#C0D8F0" + TR("#{RplTime}: ") + CHud::StrTime(rpl.GetTimeLength()) +
"\n#C0D8F0" + TR("#{RplTime}: ") + StrTime(rpl.GetTimeLength()) +
"\n#90A0B0" + TR("#{Simulation}: ") + rh.sim_mode;

if (netw == 1) // list nicks
Expand Down
2 changes: 1 addition & 1 deletion source/ogre/Replay.cpp
Expand Up @@ -253,7 +253,7 @@ bool Replay2::LoadFile(string file, bool onlyHdr)
rs(h.track) rd(h.track_user);
String ss = ">- Load replay2 ";
ss += h.track+" ";
ss += CHud::StrTime(h.time)+" ";
ss += StrTime(h.time)+" ";

rd(h.numPlayers); s = h.numPlayers;
h.cars.clear(); h.cars.resize(s);
Expand Down
6 changes: 3 additions & 3 deletions source/ogre/Update_Poses.cpp
Expand Up @@ -195,7 +195,7 @@ void App::newPoses(float time) // time only for camera update
{
int size = replay.GetNumFrames() * 232; //par approx sizeof(ReplayFrame);
std::string s = fToStr( float(size)/1000000.f, 2,5);
String ss = String( TR("#{RplRecTime}: ")) + CHud::StrTime(replay.GetTimeLength()) + TR(" #{RplSize}: ") + s + TR(" #{UnitMB}");
String ss = String( TR("#{RplRecTime}: ")) + StrTime(replay.GetTimeLength()) + TR(" #{RplSize}: ") + s + TR(" #{UnitMB}");
gui->valRplName2->setCaption(ss);
}
}
Expand Down Expand Up @@ -508,8 +508,8 @@ void App::updatePoses(float time)
double pos = pGame->timer.GetPlayerTime(0);
float len = replay.GetTimeLength();
gui->valRplPerc->setCaption(fToStr(pos/len*100.f, 1,4)+" %");
gui->valRplCur->setCaption(CHud::StrTime(pos));
gui->valRplLen->setCaption(CHud::StrTime(len));
gui->valRplCur->setCaption(StrTime(pos));
gui->valRplLen->setCaption(StrTime(len));

float v = pos/len; gui->slRplPos->setValue(v);
}
Expand Down
30 changes: 24 additions & 6 deletions source/ogre/common/Def_Str.h
Expand Up @@ -6,15 +6,16 @@
#include <OgreStringConverter.h>
#include <MyGUI_LanguageManager.h>


// Log in ogre.log
#define LogO(s) Ogre::LogManager::getSingleton().logMessage(s)


// to string
#define toStr(v) Ogre::StringConverter::toString(v)
#define toStrC(v) Ogre::StringConverter::toString(v).c_str()

// translation
#define TR(s) MyGUI::LanguageManager::getInstance().replaceTags(s)


// format int,float to string
static Ogre::String iToStr(const int v, const char width=0)
Expand Down Expand Up @@ -44,9 +45,26 @@ static Ogre::String fToStr(const float v, const char precision=2, const char wid
#define b2s(b) (b) ? "true" : "false"


// translation
#define TR(s) MyGUI::LanguageManager::getInstance().replaceTags(s)


const int ciShadowSizesNum = 5;
const int ciShadowSizesA[ciShadowSizesNum] = {256,512,1024,2048,4096};

static Ogre::String StrTime(float time) // format time string
{
int min = (int) time / 60;
float secs = time - min*60;
if (time != 0.f)
{ Ogre::String ss = toStr(min)+":"+fToStr(secs,2,5,'0');
return ss;
}else
return "-:--.--";
}
static Ogre::String StrTime2(float time) // short
{
int min = (int) time / 60;
float secs = time - min*60;
if (time != 0.0)
{ Ogre::String ss = toStr(min)+":"+fToStr(secs,0,2,'0');
return ss;
}else
return "-:--";
}
6 changes: 3 additions & 3 deletions source/ogre/common/GuiCom_Track.cpp
Expand Up @@ -455,18 +455,18 @@ void CGuiCom::UpdGuiRdStats(const SplineRoad* rd, const Scene* sc, const String&
bool no = timeCur < 0.1f || !rd;
if (ch==1) no = false; // show track's not current

stTrk[ch][9]->setCaption(CHud::StrTime(noTrk ? 0.f : timeT));
stTrk[ch][9]->setCaption(StrTime(noTrk ? 0.f : timeT));
stTrk[ch][10]->setCaption(noTrk ? "--" : speedTrk);

if (ch==0)
if (no)
{ stTrk[ch][11]->setCaption(CHud::StrTime(0.f));
{ stTrk[ch][11]->setCaption(StrTime(0.f));
stTrk[ch][12]->setCaption("--");
stTrk[ch][13]->setCaption("--");
}else
{ // car record
std::string speed = fToStr(len / timeCur * m, 0,3) + unit;
stTrk[ch][11]->setCaption(CHud::StrTime(timeCur));
stTrk[ch][11]->setCaption(StrTime(timeCur));
stTrk[ch][12]->setCaption(speed);
// points
float points = 0.f;
Expand Down
8 changes: 4 additions & 4 deletions source/ogre/common/Tools.cpp
Expand Up @@ -433,7 +433,7 @@ void CGui::ToolGhostsConv()
{ float dist = (fr.pos - oldPos).MagnitudeSquared();
if (dist > 16.f) //1.f small
{
LogO("!Jump at "+CHud::StrTime2(fr.time)+" d "+fToStr(sqrt(dist),0)+"m");
LogO("!Jump at "+StrTime2(fr.time)+" d "+fToStr(sqrt(dist),0)+"m");
++jmp;
} }
// check vel at start
Expand All @@ -443,7 +443,7 @@ void CGui::ToolGhostsConv()
float vel = 3.6f * dist / (fr.time - oldTime);
bool bad = vel > 30;
if (bad)
LogO("!Vel at "+CHud::StrTime(fr.time)+" kmh "+fToStr(vel,0) + (bad ? " BAD":""));
LogO("!Vel at "+StrTime(fr.time)+" kmh "+fToStr(vel,0) + (bad ? " BAD":""));
}
oldPos = fr.pos; oldTime = fr.time;
}
Expand Down Expand Up @@ -507,7 +507,7 @@ void CGui::ToolTestTrkGhosts()
{ float dist = (fr.pos - oldPos).MagnitudeSquared();
if (dist > 6.f*6.f) //par
{
LogO("!Jump at "+CHud::StrTime2(fr.time)+" d "+fToStr(sqrt(dist),0)+"m");
LogO("!Jump at "+StrTime2(fr.time)+" d "+fToStr(sqrt(dist),0)+"m");
++jmp;
} }
// check vel at start
Expand All @@ -517,7 +517,7 @@ void CGui::ToolTestTrkGhosts()
float vel = 3.6f * dist / (fr.time - oldTime);
bool bad = vel > 30;
if (bad)
LogO("!Vel at "+CHud::StrTime(fr.time)+" kmh "+fToStr(vel,0) + (bad ? " BAD":""));
LogO("!Vel at "+StrTime(fr.time)+" kmh "+fToStr(vel,0) + (bad ? " BAD":""));
}
oldPos = fr.pos; oldTime = fr.time;
}
Expand Down
21 changes: 11 additions & 10 deletions source/ogre/common/data/TracksXml.cpp
Expand Up @@ -219,28 +219,29 @@ bool TracksXml::LoadIni(string file, bool check)

LogO("))) Checking for all tracks ghosts");
nn = trks.size();
for (int r=0; r < 2; ++r)
for (i=0; i < nn; ++i)
{
string sRev = r==1 ? "_r" : "";
for (i=0; i < nn; ++i)
const TrackInfo& ti = trks[i];
const string& s = ti.name;
for (int r=0; r < 2; ++r)
{
const TrackInfo& ti = trks[i];
const string& s = ti.name;
string sRev = r==1 ? "_r" : "";
string file = PATHMANAGER::TrkGhosts()+"/"+ s + sRev + ".gho";
if (!ti.test && !ti.testC)
if (!PATHMANAGER::FileExists(file))
{ if (r==1) LogO("!Rev Missing trk gho for: " + s);
else LogO("! Missing trk gho for: " + s);
}else
{ // check time can take few sec
TrackGhost gho;
gho.LoadFile(file);
TrackGhost gho; gho.LoadFile(file, false);
float tgh = gho.GetTimeLength();
float ti = times[s]*1.02f, td = tgh - ti;
if (fabs(td) > 20.f)
LogO("trk gho time diff big: "+s+" time: "+CHud::StrTime(tgh)+
" trk: "+CHud::StrTime(ti)+" d: "+fToStr(td,0,2));
}
{ ss.str("");
ss << "time diff big: " << setw(19) << s+sRev;
ss << " time "+StrTime(tgh)+" trk "+StrTime(ti)+" d "+fToStr(td,0,3);
LogO(ss.str());
} }
}
}
LogO("");
Expand Down
2 changes: 1 addition & 1 deletion source/road/PaceNotesGen.cpp
Expand Up @@ -343,7 +343,7 @@ void PaceNotes::Rebuild(SplineRoad* road, Scene* sc, bool reversed)
if (!PATHMANAGER::FileExists(file))
LogO("Pace trk gho not found: "+file);/**/
else
{ gho.LoadFile(file);
{ gho.LoadFile(file, false);
num = gho.getNumFrames();
}

Expand Down

0 comments on commit 5a8fdb5

Please sign in to comment.