bool frameEnded(const FrameEvent &evt) { // Fill Here ----------------------------------------------- static Ogre::DisplayString currFps = L"현재 FPS: "; static Ogre::DisplayString avgFps = L"평균 FPS: "; static Ogre::DisplayString bestFps = L"최고 FPS: "; static Ogre::DisplayString worstFps = L"최저 FPS: "; OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("AverageFps"); OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("CurrFps"); OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("BestFps"); OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("WorstFps"); const RenderTarget::FrameStats& stats = mRoot->getAutoCreatedWindow()->getStatistics(); guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS)); guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS)); // --------------------------------------------------------- return mContinue; }
//----------------------------------------------------------------------- OverlayElement* Profiler::createTextArea(const String& name, Real width, Real height, Real top, Real left, uint fontSize, const String& caption, bool show) { OverlayElement* textArea = OverlayManager::getSingleton().createOverlayElement("TextArea", name); textArea->setMetricsMode(GMM_PIXELS); textArea->setWidth(width); textArea->setHeight(height); textArea->setTop(top); textArea->setLeft(left); textArea->setParameter("font_name", "BlueHighway"); textArea->setParameter("char_height", StringConverter::toString(fontSize)); textArea->setCaption(caption); textArea->setParameter("colour_top", "1 1 1"); textArea->setParameter("colour_bottom", "1 1 1"); if (show) { textArea->show(); } else { textArea->hide(); } return textArea; }
void _setOverlay(void) { mOverlayMgr = OverlayManager::getSingletonPtr(); mTextOverlay = mOverlayMgr->create("TextOverlay"); mPanel = static_cast<Ogre::OverlayContainer*>(mOverlayMgr->createOverlayElement("Panel", "container1")); mPanel->setDimensions(1, 1); mPanel->setPosition(-0.3f, 0.5f); OverlayElement* textBox = mOverlayMgr->createOverlayElement("TextArea", "TextID"); textBox->setMetricsMode(Ogre::GMM_PIXELS); textBox->setPosition(10, 10); textBox->setWidth(100); textBox->setHeight(20); textBox->setParameter("font_name", "Font/NanumBold18"); textBox->setParameter("char_height", "40"); textBox->setColour(Ogre::ColourValue::White); textBox->setCaption(L"한국산업기술대학교 이대현 선수"); mPanel->addChild(textBox); mTextOverlay->add2D(mPanel); mTextOverlay->show(); mLogoOverlay = OverlayManager::getSingleton().getByName("Overlay/KPU_LOGO"); mLogoOverlay->show(); mLogoOverlay = OverlayManager::getSingleton().getByName("Overlay/Information"); mLogoOverlay->show(); }
// ------------------------------------------------------------------------- void OgreBulletListener::updateStats(void) { // update stats when necessary if (mFpsStaticText) { const RenderTarget::FrameStats& stats = mWindow->getStatistics(); static String avgFps = "Average FPS: "; static String currFps = "Current FPS: "; static String tris = "Triangle Count: "; mFpsStaticText->setValue ( avgFps + StringConverter::toString(stats.avgFPS) + " / " + currFps + StringConverter::toString(stats.lastFPS) + " / " + tris + StringConverter::toString(stats.triangleCount) ); } try { OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); guiDbg->setCaption(mDebugText); } catch(...) {} }
void updateStats(void){ static String currFps = "Current FPS: "; static String avgFps = "Average FPS: "; static String bestFps = "Best FPS: "; static String worstFps = "Worst FPS: "; static String tris = "Triangle Count: "; static String batches = "Batch Count: "; // update stats when necessary try { OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps"); OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps"); OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Core/BestFps"); OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps"); const RenderTarget::FrameStats& stats = mWindow->getStatistics(); guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) +" "+StringConverter::toString(stats.worstFrameTime)+" ms"); OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris"); guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount)); OverlayElement* guiBatches = OverlayManager::getSingleton().getOverlayElement("Core/NumBatches"); guiBatches->setCaption(batches + StringConverter::toString(stats.batchCount)); OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); guiDbg->setCaption(mDebugText); } catch(...) { /* ignore */ } }
void OgreFramework::UpdateStats() { static String currFps = "Current FPS: "; static String avgFps = "Average FPS: "; static String bestFps = "Best FPS: "; static String worstFps = "Worst FPS: "; static String tris = "Triangle Count: "; static String batches = "Batch Count: "; OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps"); OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps"); OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Core/BestFps"); OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps"); const RenderTarget::FrameStats& stats = m_renderWnd->getStatistics(); guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) +" "+StringConverter::toString(stats.worstFrameTime)+" ms"); OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris"); guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount)); OverlayElement* guiBatches = OverlayManager::getSingleton().getOverlayElement("Core/NumBatches"); guiBatches->setCaption(batches + StringConverter::toString(stats.batchCount)); OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); guiDbg->setCaption(""); }
void DebugText::updateStats(Ogre::String text) { static String currFps = "Current FPS: "; //static String avgFps = "Average FPS: "; //static String bestFps = "Best FPS: "; //static String worstFps = "Worst FPS: "; //static String tris = "Triangle Count: "; // update stats when necessary OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps"); OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps"); OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Core/BestFps"); OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps"); guiAvg->hide(); //guiCurr->hide(); guiBest->hide(); guiWorst->hide(); //OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Core/WorstFps"); /*guiAvg->setCaption(avgFps + StringConverter::toString(mWindow->getAverageFPS()));*/ guiCurr->setCaption(currFps + StringConverter::toString(mWindow->getLastFPS())); //guiBest->setCaption(bestFps + StringConverter::toString(mWindow->getBestFPS()) // +" "+StringConverter::toString(mWindow->getBestFrameTime())+" ms"); //guiWorst->setCaption(worstFps + StringConverter::toString(mWindow->getWorstFPS()) // +" "+StringConverter::toString(mWindow->getWorstFrameTime())+" ms"); //OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Core/NumTris"); //guiTris->setCaption(tris + StringConverter::toString(mWindow->getTriangleCount())); OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); guiDbg->setCaption(text); //guiDbg->setPosition(0,0); //mDebugOverlay-> }
void CoreListener::updateStats(void) { static String currFps = "Current FPS: "; static String avgFps = "Average FPS: "; static String bestFps = "Best FPS: "; static String worstFps = "Worst FPS: "; static String tris = "Triangle Count: "; static String missTime = "Mission Time: "; // update stats when necessary try { OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("USCA/AverageFps"); OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("USCA/CurrFps"); OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("USCA/BestFps"); OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("USCA/WorstFps"); OverlayElement* guiTime = OverlayManager::getSingleton().getOverlayElement("USCA/MissionTime"); const RenderTarget::FrameStats& stats = Shmoulette::Core::getSingleton()->getWindow()->getStatistics(); guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)+"("+ts(Shmoulette::Level::getSingleton()->getCurrentSegment()->getTimeTrack())+")"); guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) +" "+StringConverter::toString(stats.worstFrameTime)+" ms"); guiTime->setCaption(missTime + ts(Level::getSingleton()->getCurrentSegment()->getTimeTrack()) +" "+StringConverter::toString(stats.worstFrameTime)+" secs"); OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("USCA/NumTris"); guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount)); OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("USCA/DebugText"); //guiDbg->setCaption(Shmoulette::Core::getSingleton()->getWindow()->getDe->getDebugText()); } catch(...) { // ignore } }
//----------------------------------------------------------------------- void Profiler::displayResults() { if (!mEnabled) { return; } // if its time to update the display if (!(mCurrentFrame % mUpdateDisplayFrequency)) { ProfileHistoryList::iterator iter; ProfileBarList::iterator bIter; OverlayElement* g; Real newGuiHeight = mGuiHeight; int profileCount = 0; Real maxTimeMillisecs = (Real)mMaxTotalFrameTime / 1000.0f; // go through each profile and display it for (iter = mProfileHistory.begin(), bIter = mProfileBars.begin(); iter != mProfileHistory.end() && bIter != mProfileBars.end(); ++iter, ++bIter) { // display the profile's name and the number of times it was called in a frame g = *bIter; g->show(); g->setCaption(String((*iter).name + " (" + StringConverter::toString((*iter).numCallsThisFrame) + ")")); g->setLeft(10 + (*iter).hierarchicalLvl * 15.0f); // display the main bar that show the percentage of the frame time that this // profile has taken bIter++; g = *bIter; g->show(); // most of this junk has been set before, but we do this to get around a weird // Ogre gui issue (bug?) g->setMetricsMode(GMM_PIXELS); g->setHeight(mBarHeight); if (mDisplayMode == DISPLAY_PERCENTAGE) g->setWidth(((*iter).currentTimePercent) * mGuiWidth); else g->setWidth(((*iter).currentTimeMillisecs / maxTimeMillisecs) * mGuiWidth); g->setLeft(mGuiWidth); g->setTop(mGuiBorderWidth + profileCount * (mBarHeight + mBarSpacing)); // display line to indicate the minimum frame time for this profile bIter++; g = *bIter; g->show(); if (mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + (*iter).minTimePercent * mGuiWidth); else g->setLeft(mBarIndent + ((*iter).minTimeMillisecs / maxTimeMillisecs) * mGuiWidth); // display line to indicate the maximum frame time for this profile bIter++; g = *bIter; g->show(); if (mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + (*iter).maxTimePercent * mGuiWidth); else g->setLeft(mBarIndent + ((*iter).maxTimeMillisecs / maxTimeMillisecs) * mGuiWidth); // display line to indicate the average frame time for this profile bIter++; g = *bIter; g->show(); if ((*iter).totalCalls != 0) if (mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + ((*iter).totalTimePercent / (*iter).totalCalls) * mGuiWidth); else g->setLeft(mBarIndent + (((*iter).totalTimeMillisecs / (*iter).totalCalls) / maxTimeMillisecs) * mGuiWidth); else g->setLeft(mBarIndent); // display text bIter++; g = *bIter; g->show(); if (mDisplayMode == DISPLAY_PERCENTAGE) { g->setLeft(mBarIndent + (*iter).currentTimePercent * mGuiWidth + 2); g->setCaption(StringConverter::toString((*iter).currentTimePercent * 100.0f, 3, 3) + "%"); } else { g->setLeft(mBarIndent + ((*iter).currentTimeMillisecs / maxTimeMillisecs) * mGuiWidth + 2); g->setCaption(StringConverter::toString((*iter).currentTimeMillisecs, 3, 3) + "ms"); } // we set the height of the display with respect to the number of profiles displayed newGuiHeight += mBarHeight + mBarSpacing; profileCount++; } // set the main display dimensions mProfileGui->setMetricsMode(GMM_PIXELS); mProfileGui->setHeight(newGuiHeight); mProfileGui->setWidth(mGuiWidth * 2 + 15); mProfileGui->setTop(5); mProfileGui->setLeft(5); // we hide all the remaining pre-created bars for (; bIter != mProfileBars.end(); ++bIter) { (*bIter)->hide(); } } mCurrentFrame++; }
bool TruckHUD::update(float dt, Beam *truck, bool visible) { OverlayElement *overlayElement = 0; // only update every 300 ms if (visible) { updatetime -= dt; if (updatetime <= 0.0f) { // update now, reset timer updatetime = 0.3f; } else { // don't update visuals, only count stats visible = false; } } if (visible) { overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Truckname"); overlayElement->setCaption(truck->getTruckName()); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Truckauthor"); overlayElement->setCaption(_L("(no author information available)")); std::vector<authorinfo_t> file_authors = truck->getAuthors(); if (!file_authors.empty()) { String authors = ""; for (std::vector<authorinfo_t>::iterator it = file_authors.begin(); it != file_authors.end(); ++it) { authors += (*it).name + " "; } overlayElement->setCaption(_L("Authors: ") + authors); } checkOverflow(overlayElement); std::vector<std::string> description = truck->getDescription(); for (unsigned int i=1; i < 3; i++) { overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/DescriptionLine" + TOSTRING(i+1)); overlayElement->setCaption(""); if (i < description.size()) { overlayElement->setCaption(ANSI_TO_UTF(description[i])); } checkOverflow(overlayElement); } beam_t *beam = truck->getBeams(); float average_deformation = 0.0f; float beamstress = 0.0f; float current_deformation = 0.0f; float mass = truck->getTotalMass(); int beamCount = truck->getBeamCount(); int beambroken = 0; int beamdeformed = 0; for (int i=0; i < beamCount; i++, beam++) { if (beam->broken != 0) { beambroken++; } beamstress += beam->stress; current_deformation = fabs(beam->L-beam->refL); if (fabs(current_deformation) > 0.0001f && beam->type != BEAM_HYDRO && beam->type != BEAM_INVISIBLE_HYDRO) { beamdeformed++; } average_deformation += current_deformation; } overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamTotal"); overlayElement->setCaption(_L("beam count: ") + TOUTFSTRING(beamCount)); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamBroken"); overlayElement->setCaption(_L("broken: ") + TOUTFSTRING(beambroken) + U(" (") + TOUTFSTRING(Round((float)beambroken / (float)beamCount, 2) * 100.0f) + U("%)")); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamHealth"); float health = ((float)beambroken / (float)beamCount) * 10.0f + ((float)beamdeformed / (float)beamCount); if (health < 1.0f) { overlayElement->setCaption(_L("health: ") + TOUTFSTRING(Round((1.0f - health) * 100.0f, 2)) + U("%")); overlayElement->setColour(ColourValue(0.6f, 0.8f, 0.4f, 1.0f)); } else if (health >= 1.0f) { health = ((float)beambroken / (float)beamCount) * 3.0f; health = std::min(health, 1.0f); overlayElement->setCaption(_L("destruction: ") + TOUTFSTRING(Round(health * 100.0f, 2)) + U("%")); overlayElement->setColour(ColourValue(0.8f, 0.4f, 0.4f, 1.0f)); } checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamDeformed"); overlayElement->setCaption(_L("deformed: ") + TOUTFSTRING(beamdeformed) + U(" (") + TOUTFSTRING(Round((float)beamdeformed / (float)beamCount, 2) * 100.0f) + U("%)")); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageBeamDeformation"); overlayElement->setCaption(_L("average deformation: ") + TOUTFSTRING(Round((float)average_deformation / (float)beamCount, 4) * 100.0f)); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageBeamStress"); wchar_t beamstressstr[256]; swprintf(beamstressstr, 256, L"%+08.0f", 1-(float)beamstress/(float)beamCount); overlayElement->setCaption(_L("average stress: ") + UTFString(beamstressstr)); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/NodeCount"); int ncount = truck->getNodeCount(); int wcount = truck->getWheelNodeCount(); wchar_t nodecountstr[256]; swprintf(nodecountstr, 256, L"%d (wheels: %d)", ncount, wcount); overlayElement->setCaption(_L("node count: ") + UTFString(nodecountstr)); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/TruckWeight"); wchar_t truckmassstr[256]; UTFString massstr = _L("current mass:"); swprintf(truckmassstr, 256, L"%ls %8.2f kg (%.2f tons)", massstr.asWStr_c_str(), mass, mass / 1000.0f); overlayElement->setCaption(UTFString(truckmassstr)); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Gees"); wchar_t geesstr[256]; Vector3 gees = truck->getGForces(); // apply deadzones ==> no flickering +/- if (fabs(gees.y) < 0.01) gees.y = 0.0f; if (fabs(gees.z) < 0.01) gees.z = 0.0f; UTFString tmp = _L("Gees: Vertical %1.2fg // Saggital %1.2fg // Lateral %1.2fg"); swprintf(geesstr, 256, tmp.asWStr_c_str(), gees.x, gees.y, gees.z); overlayElement->setCaption(UTFString(geesstr)); checkOverflow(overlayElement); // max g-forces if (truck->driveable == TRUCK || truck->driveable == AIRPLANE || truck->driveable == BOAT) { if (gees.x > maxPosVerG[truck->driveable]) maxPosVerG[truck->driveable] = gees.x; if (gees.x < maxNegVerG[truck->driveable]) maxNegVerG[truck->driveable] = gees.x; if (gees.y > maxPosSagG[truck->driveable]) maxPosSagG[truck->driveable] = gees.y; if (gees.y < maxNegSagG[truck->driveable]) maxNegSagG[truck->driveable] = gees.y; if (gees.z > maxPosLatG[truck->driveable]) maxPosLatG[truck->driveable] = gees.z; if (gees.z < maxNegLatG[truck->driveable]) maxNegLatG[truck->driveable] = gees.z; tmp = _L("maxG: V %1.2fg %1.2fg // S %1.2fg %1.2fg // L %1.2fg %1.2fg"); swprintf(geesstr, 256, tmp.asWStr_c_str(), maxPosVerG[truck->driveable], maxNegVerG[truck->driveable], maxPosSagG[truck->driveable], maxNegSagG[truck->driveable], maxPosLatG[truck->driveable], maxNegLatG[truck->driveable] ); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Gees2"); overlayElement->setCaption(UTFString(geesstr)); checkOverflow(overlayElement); } } Vector3 hdir = Vector3::ZERO; if (truck->cameranodepos[0] >= 0 && truck->cameranodepos[0] < MAX_NODES) { hdir = (truck->nodes[truck->cameranodepos[0]].RelPosition - truck->nodes[truck->cameranodedir[0]].RelPosition).normalisedCopy(); } float g_along_hdir = hdir.dotProduct(truck->ffforce / 10000.0f); // always update these statistics, also if not visible! overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentRPM"); overlayElement->setCaption(""); UTFString rpmsstr = _L("current RPM:"); if (truck->driveable == TRUCK && truck->engine) { overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentRPM"); overlayElement->setCaption(rpmsstr + U(" ") + TOUTFSTRING(Round(truck->engine->getRPM())) + U(" / ") + TOUTFSTRING(Round(truck->engine->getMaxRPM()))); } else if (truck->driveable == AIRPLANE) { for (int i=0; i < 8; i++) { if (truck->aeroengines[i]) { rpmsstr = rpmsstr + U(" / ") + TOUTFSTRING(Round(truck->aeroengines[i]->getRPM())); } } overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentRPM"); overlayElement->setCaption(UTFString(rpmsstr)); } checkOverflow(overlayElement); UTFString cspeedstr = _L("current Speed:") + U(" "); UTFString mspeedstr = _L("max Speed:") + U(" "); UTFString altitudestr = _L("Altitude:") + U(" "); if (truck->driveable == TRUCK) { maxVelos[truck->driveable] = std::max(maxVelos[truck->driveable], truck->WheelSpeed); minVelos[truck->driveable] = std::min(truck->WheelSpeed, minVelos[truck->driveable]); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentVelocity"); float velocityKMH = truck->WheelSpeed* 3.6f; float velocityMPH = truck->WheelSpeed * 2.23693629f; // apply a deadzone ==> no flickering +/- if (fabs(truck->WheelSpeed) < 1.0f) { velocityKMH = velocityMPH = 0.0f; } overlayElement->setCaption(cspeedstr + TOUTFSTRING(Round(velocityKMH)) + U(" km/h (") + TOUTFSTRING(Round(velocityMPH)) + U(" mph)")); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/MaxVelocity"); float velocityMaxKMH = maxVelos[truck->driveable] * 3.6f; float velocityMinKMH = minVelos[truck->driveable] * 3.6f; float velocityMaxMPH = maxVelos[truck->driveable] * 2.23693629f; float velocityMinMPH = minVelos[truck->driveable] * 2.23693629f; overlayElement->setCaption(mspeedstr + TOUTFSTRING(Round(velocityMaxKMH)) + U("km/h (") + TOUTFSTRING(Round(velocityMaxMPH)) + U("mph)") + U(", min: ") + TOUTFSTRING(Round(velocityMinKMH)) + U("km/h (") + TOUTFSTRING(Round(velocityMinMPH)) + U("mph)")); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageVelocity"); overlayElement->setCaption(""); } else if (truck->driveable == AIRPLANE || truck->driveable == BOAT) { float velocity = truck->nodes[0].Velocity.length(); if (truck->cameranodepos[0] >= 0 && truck->cameranodedir[0] && truck->driveable == BOAT) { hdir = (truck->nodes[truck->cameranodepos[0]].RelPosition - truck->nodes[truck->cameranodedir[0]].RelPosition).normalisedCopy(); velocity = hdir.dotProduct(truck->nodes[truck->cameranodepos[0]].Velocity); } maxVelos[truck->driveable] = std::max(maxVelos[truck->driveable], velocity); minVelos[truck->driveable] = std::min(velocity, minVelos[truck->driveable]); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentVelocity"); float velocityKN = velocity * 1.94384449f; // apply a deadzone ==> no flickering +/- if (fabs(velocity) < 1.0f) { velocityKN = 0.0f; } overlayElement->setCaption(cspeedstr + TOUTFSTRING(Round(velocityKN)) + U(" kn")); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/MaxVelocity"); float velocityMaxKN = maxVelos[truck->driveable] * 1.94384449f; float velocityMinKN = minVelos[truck->driveable] * 1.94384449f; overlayElement->setCaption(mspeedstr + TOUTFSTRING(Round(maxVelos[truck->driveable])) + U(" kn, min: ") + TOUTFSTRING(Round(minVelos[truck->driveable])) + U(" kn")); checkOverflow(overlayElement); overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageVelocity"); overlayElement->setCaption(""); if (truck->driveable == AIRPLANE) { float altitude = truck->nodes[0].AbsPosition.y * 1.1811f; overlayElement->setCaption(altitudestr + TOUTFSTRING(Round(altitude)) + U(" m")); checkOverflow(overlayElement); } } else if (truck->driveable == MACHINE) { OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/MaxVelocity")->setCaption(""); OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentVelocity")->setCaption(""); OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageVelocity")->setCaption(""); } OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/TimeStats")->setCaption(""); if (visible) { // update commands // clear them first for (int i=1; i <= COMMANDS_VISIBLE; i++) { overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Command" + TOSTRING(i)); overlayElement->setCaption(""); } int filledCommands = 0; for (int i=1; i < MAX_COMMANDS && filledCommands < COMMANDS_VISIBLE; i += 2) { if(truck->commandkey[i].beams.empty() || truck->commandkey[i].description == "hide") continue; filledCommands++; char commandID[256] = {}; String keyStr = ""; sprintf(commandID, "COMMANDS_%02d", i); int eventID = RoR::Application::GetInputEngine()->resolveEventName(String(commandID)); String keya = RoR::Application::GetInputEngine()->getEventCommand(eventID); sprintf(commandID, "COMMANDS_%02d", i+1); eventID = RoR::Application::GetInputEngine()->resolveEventName(String(commandID)); String keyb = RoR::Application::GetInputEngine()->getEventCommand(eventID); // cut off expl if (keya.size() > 6 && keya.substr(0,5) == "EXPL+") keya = keya.substr(5); if (keyb.size() > 6 && keyb.substr(0,5) == "EXPL+") keyb = keyb.substr(5); keyStr = keya + "/" + keyb; overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Command" + TOSTRING(filledCommands)); if (truck->commandkey[i].description.empty()) { overlayElement->setCaption(keyStr + ": " + _L("unknown function")); } else { overlayElement->setCaption(keyStr + ": " + truck->commandkey[i].description); } checkOverflow(overlayElement); } // hide command section title if no commands overlayElement = overlayElement = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CommandsTitleLabel"); overlayElement->setCaption(""); if (filledCommands > 0) { // TODO: Fix the position of this overlay element //overlayElement->setCaption(_L("Commands:")); checkOverflow(overlayElement); } } return true; }
//----------------------------------------------------------------------- void OverlayProfileSessionListener::displayResults(ProfileInstance* instance, ProfileBarList::const_iterator& bIter, Real& maxTimeMillisecs, Real& newGuiHeight, int& profileCount) { OverlayElement* g; // display the profile's name and the number of times it was called in a frame g = *bIter; ++bIter; g->show(); g->setCaption(String(instance->name + " (" + StringConverter::toString(instance->history.numCallsThisFrame) + ")")); g->setLeft(10 + instance->hierarchicalLvl * 15.0f); // display the main bar that show the percentage of the frame time that this // profile has taken g = *bIter; ++bIter; g->show(); // most of this junk has been set before, but we do this to get around a weird // Ogre gui issue (bug?) g->setMetricsMode(GMM_PIXELS); g->setHeight(mBarHeight); if (mDisplayMode == DISPLAY_PERCENTAGE) g->setWidth( (instance->history.currentTimePercent) * mGuiWidth); else g->setWidth( (instance->history.currentTimeMillisecs / maxTimeMillisecs) * mGuiWidth); g->setLeft(mGuiWidth); g->setTop(mGuiBorderWidth + profileCount * (mBarHeight + mBarSpacing)); // display line to indicate the minimum frame time for this profile g = *bIter; ++bIter; g->show(); if(mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + instance->history.minTimePercent * mGuiWidth); else g->setLeft(mBarIndent + (instance->history.minTimeMillisecs / maxTimeMillisecs) * mGuiWidth); // display line to indicate the maximum frame time for this profile g = *bIter; ++bIter; g->show(); if(mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + instance->history.maxTimePercent * mGuiWidth); else g->setLeft(mBarIndent + (instance->history.maxTimeMillisecs / maxTimeMillisecs) * mGuiWidth); // display line to indicate the average frame time for this profile g = *bIter; ++bIter; g->show(); if(instance->history.totalCalls != 0) { if (mDisplayMode == DISPLAY_PERCENTAGE) g->setLeft(mBarIndent + (instance->history.totalTimePercent / instance->history.totalCalls) * mGuiWidth); else g->setLeft(mBarIndent + ((instance->history.totalTimeMillisecs / instance->history.totalCalls) / maxTimeMillisecs) * mGuiWidth); } else g->setLeft(mBarIndent); // display text g = *bIter; ++bIter; g->show(); if (mDisplayMode == DISPLAY_PERCENTAGE) { g->setLeft(mBarIndent + instance->history.currentTimePercent * mGuiWidth + 2); g->setCaption(StringConverter::toString(instance->history.currentTimePercent * 100.0f, 3, 3) + "%"); } else { g->setLeft(mBarIndent + (instance->history.currentTimeMillisecs / maxTimeMillisecs) * mGuiWidth + 2); g->setCaption(StringConverter::toString(instance->history.currentTimeMillisecs, 3, 3) + "ms"); } // we set the height of the display with respect to the number of profiles displayed newGuiHeight += mBarHeight + mBarSpacing; ++profileCount; // display children ProfileInstance::ProfileChildren::const_iterator it = instance->children.begin(), endit = instance->children.end(); for(;it != endit; ++it) { ProfileInstance* child = it->second; displayResults(child, bIter, maxTimeMillisecs, newGuiHeight, profileCount); } }
void GamePlayState::update(unsigned long timePassed) { mMoveScale = mMoveSpeed * timePassed / 1000000.0f; mRotScale = mRotateSpeed * timePassed / 1000000.0f; // Quick hack. Let the camera move: if (mForward) mTranslateVector.z = -mMoveScale; if (mBackward) mTranslateVector.z = mMoveScale; if (mLeft) mTranslateVector.x = -mMoveScale; if (mRight) mTranslateVector.x = mMoveScale; mCamera->yaw(mRotX * mRotScale); mCamera->pitch(mRotY * mRotScale); mCamera->moveRelative(mTranslateVector); mTranslateVector = Vector3::ZERO; mRotX = 0; mRotY = 0; if (mSceneDisplay) { mSceneDetailIndex = (mSceneDetailIndex+1)%2 ; // I Do not need points for now switch(mSceneDetailIndex) { case 0 : mCamera->setPolygonMode(PM_SOLID) ; break ; case 1 : mCamera->setPolygonMode(PM_WIREFRAME) ; break ; //case 2 : mCamera->setPolygonMode(PM_POINTS) ; break ; } mSceneDisplay = false; } if (mPortalDisplay) { // reuse mSceneMgr->getOption("ShowPortals", &mPortalDisplay); mPortalDisplay = !mPortalDisplay; mSceneMgr->setOption("ShowPortals", &mPortalDisplay); mPortalDisplay = false; } if (mScreenShot) { char tmp[20]; sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots); RenderWindow* w = Ogre::Root::getSingleton().getAutoCreatedWindow(); w->writeContentsToFile(tmp); mScreenShot = false; } // mConsole->update(timePassed); if (mDebug) { // update stats when necessary try { // Temporary: Debug Overlay static String currFps = "Current FPS: "; static String avgFps = "Average FPS: "; static String bestFps = "Best FPS: "; static String worstFps = "Worst FPS: "; static String tris = "Triangle Count: "; static String batches = "Batch Count: "; OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Opde/AverageFps"); OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Opde/CurrFps"); OverlayElement* guiBest = OverlayManager::getSingleton().getOverlayElement("Opde/BestFps"); OverlayElement* guiWorst = OverlayManager::getSingleton().getOverlayElement("Opde/WorstFps"); const RenderTarget::FrameStats& stats = mWindow->getStatistics(); guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS)); guiCurr->setCaption(currFps + StringConverter::toString(stats.lastFPS)); guiBest->setCaption(bestFps + StringConverter::toString(stats.bestFPS) +" "+StringConverter::toString(stats.bestFrameTime)+" ms"); guiWorst->setCaption(worstFps + StringConverter::toString(stats.worstFPS) +" "+StringConverter::toString(stats.worstFrameTime)+" ms"); OverlayElement* guiTris = OverlayManager::getSingleton().getOverlayElement("Opde/NumTris"); guiTris->setCaption(tris + StringConverter::toString(stats.triangleCount)); OverlayElement* guiBatches = OverlayManager::getSingleton().getOverlayElement("Opde/NumBatches"); guiBatches->setCaption(batches + StringConverter::toString(stats.batchCount)); // OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText"); } catch(...) { // ignore } // update the portal statistics try { // Volca: I've disabled the timing reports, they need a patch of SM to work OverlayElement* guibc = OverlayManager::getSingleton().getOverlayElement("Opde/BackCulls"); OverlayElement* guiep = OverlayManager::getSingleton().getOverlayElement("Opde/EvalPorts"); OverlayElement* guirc = OverlayManager::getSingleton().getOverlayElement("Opde/RendCells"); OverlayElement* guitt = OverlayManager::getSingleton().getOverlayElement("Opde/TravTime"); OverlayElement* guisr = OverlayManager::getSingleton().getOverlayElement("Opde/StaticRenderTime"); OverlayElement* guivo = OverlayManager::getSingleton().getOverlayElement("Opde/VisibleObjectsTime"); OverlayElement* guill = OverlayManager::getSingleton().getOverlayElement("Opde/LightListTime"); OverlayElement* guilc = OverlayManager::getSingleton().getOverlayElement("Opde/LightCount"); OverlayElement* guisg = OverlayManager::getSingleton().getOverlayElement("Opde/SceneGraphTime"); // Temporary: Debug Overlay static String sbc = "Backface culls: "; static String sep = "Evaluated portals: "; static String src = "Rendered cells: "; static String stt = "Traversal Time: "; static String ssr = "Static Build Time: "; static String vot = "Visible obj. Time: "; static String llt = "Light list. Time: "; static String lcs = "Light count : "; static String sgt = "Scene graph Time: "; uint bculls = 0, eports = 0, rendc = 0, travtm = 0; unsigned long statbt, fvot, lltime, sgtime, lcnt; mSceneMgr->getOption("BackfaceCulls", &bculls); // mSceneMgr->getOption("CellsRendered", &rendc); mSceneMgr->getOption("EvaluatedPortals", &eports); // mSceneMgr->getOption("TraversalTime", &travtm); mSceneMgr->getOption("StaticBuildTime", &statbt); mSceneMgr->getOption("FindVisibleObjectsTime", &fvot); mSceneMgr->getOption("LightListTime", &lltime); mSceneMgr->getOption("LightCount", &lcnt); mSceneMgr->getOption("SceneGraphTime", &sgtime); travtm = static_cast<DarkCamera*>(mCamera)->getTraversalTime(); rendc = static_cast<DarkCamera*>(mCamera)->getVisibleCellCount(); guibc->setCaption(sbc + StringConverter::toString(bculls)); guiep->setCaption(sep + StringConverter::toString(eports)); guirc->setCaption(src + StringConverter::toString(rendc)); guitt->setCaption(stt + StringConverter::toString(travtm) + " ms"); guisr->setCaption(ssr + StringConverter::toString(statbt) + " ms"); guivo->setCaption(vot + StringConverter::toString(fvot) + " ms"); guill->setCaption(llt + StringConverter::toString(lltime) + " ms"); guilc->setCaption(lcs + StringConverter::toString(lcnt)); guisg->setCaption(sgt + StringConverter::toString(sgtime) + " ms"); } catch(...) { // ignore } } }
bool TruckHUD::update(float dt, Beam *truck, SceneManager *mSceneMgr, Camera* mCamera, RenderWindow* mWindow, bool visible) { OverlayElement *descl = 0; //only update every 300 ms if(visible) { updatetime -= dt; if(updatetime <= 0) { // update now, reset timer updatetime = 0.3; } else // dont update visuals, only count stats visible = false; } if(visible) { OverlayElement* oTruckname = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Truckname"); oTruckname->setCaption(truck->getTruckName()); checkOverflow(oTruckname); OverlayElement* oTruckauthor = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Truckauthor"); std::vector<authorinfo_t> file_authors = truck->getAuthors(); if(file_authors.size() > 0) { String author_string = String(""); for(unsigned int i=0;i<file_authors.size();i++) author_string += file_authors[i].name + String(" "); oTruckauthor->setCaption(_L("Authors: ") + author_string); } else { oTruckauthor->setCaption(_L("(no author information available)")); } checkOverflow(oTruckauthor); std::vector<std::string> desc = truck->getDescription(); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/DescriptionLine1"); if(desc.size() > 0) descl->setCaption(ANSI_TO_UTF(desc[0])); else descl->setCaption(""); checkOverflow(descl); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/DescriptionLine2"); if(desc.size() > 1) descl->setCaption(ANSI_TO_UTF(desc[1])); else descl->setCaption(""); checkOverflow(descl); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/DescriptionLine3"); if(desc.size() > 2) descl->setCaption(ANSI_TO_UTF(desc[2])); else descl->setCaption(""); checkOverflow(descl); int beamCount = truck->getBeamCount(); beam_t *beam = truck->getBeams(); int beambroken = 0; float beamstress = 0; int beamdeformed = 0; float average_deformation = 0; float current_deformation = 0; float mass = truck->getTotalMass(); for(int i=0; i<beamCount; i++, beam++) { if(beam->broken != 0) beambroken++; beamstress += beam->stress; current_deformation = fabs(beam->L-beam->refL); if (fabs(current_deformation) > 0.0001f && beam->type != BEAM_HYDRO && beam->type != BEAM_INVISIBLE_HYDRO) beamdeformed++; average_deformation += current_deformation; } wchar_t beamcountstr[256]; swprintf(beamcountstr, 256, L"%d", beamCount); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamTotal"); descl->setCaption(_L("beam count: ") + UTFString(beamcountstr)); checkOverflow(descl); wchar_t beambrokenstr[256]; swprintf(beambrokenstr, 256, L"%0.2f", ((float)beambroken/(float)beamCount)*100); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamBroken"); descl->setCaption(_L("broken: ") + TOUTFSTRING(beambroken) + U(" (") + UTFString(beambrokenstr) + U("%)")); checkOverflow(descl); wchar_t beamhealthstr[256]; float health = ((float)beambroken/(float)beamCount) * 10 + ((float)beamdeformed/(float)beamCount); if(health<1) { swprintf(beamhealthstr, 256, L"%0.2f", (1-health)*100); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamHealth"); descl->setCaption(_L("health: ") + UTFString(beamhealthstr) + U("%")); checkOverflow(descl); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamHealth"); descl->setColour(ColourValue(0.6,0.8,0.4,1)); checkOverflow(descl); }else if(health>1) { health = ((float)beambroken/(float)beamCount) * 3; if(health>1) health=1; swprintf(beamhealthstr, 256, L"%0.2f", (health)*100); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamHealth"); descl->setCaption(_L("destruction: ") + UTFString(beamhealthstr) + U("%")); checkOverflow(descl); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamHealth"); descl->setColour(ColourValue(0.8,0.4,0.4,1)); checkOverflow(descl); } wchar_t beamdeformedstr[256]; swprintf(beamdeformedstr, 256, L"%0.2f", ((float)beamdeformed/(float)beamCount)*100); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/BeamDeformed"); descl->setCaption(_L("deformed: ") + TOUTFSTRING(beamdeformed) + U(" (") + UTFString(beamdeformedstr) + U("%)")); checkOverflow(descl); wchar_t beamavdeformedstr[256]; swprintf(beamavdeformedstr, 256, L"%0.4f", ((float)average_deformation/(float)beamCount)); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageBeamDeformation"); descl->setCaption(_L("average deformation: ") + UTFString(beamavdeformedstr)); checkOverflow(descl); wchar_t beamstressstr[256]; swprintf(beamstressstr, 256, L"%+08.0f", 1-(float)beamstress/(float)beamCount); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageBeamStress"); descl->setCaption(_L("average stress: ") + UTFString(beamstressstr)); checkOverflow(descl); int nodeCount = truck->getNodeCount(); int wcount = truck->getWheelNodeCount(); wchar_t nodecountstr[256]; swprintf(nodecountstr, 256, L"%d (wheels: %d)", nodeCount, wcount); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/NodeCount"); descl->setCaption(_L("node count: ") + UTFString(nodecountstr)); checkOverflow(descl); wchar_t truckmassstr[256]; UTFString massstr = _L("current mass:"); swprintf(truckmassstr, 256, L"%ls %8.2f kg (%.2f tons)", massstr.asWStr_c_str(), mass, mass/1000); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/TruckWeight"); descl->setCaption(UTFString(truckmassstr)); checkOverflow(descl); wchar_t geesstr[256]; Vector3 gees = truck->getGForces(); UTFString tmp = _L("Gees: Vertical %1.2fg // Saggital %1.2fg // Lateral %1.2fg"); swprintf(geesstr, 256, tmp.asWStr_c_str(), gees.x, gees.y, gees.z); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Gees"); descl->setCaption(UTFString(geesstr)); checkOverflow(descl); //maxGees if(truck->driveable == TRUCK || truck->driveable == AIRPLANE || truck->driveable == BOAT) { if(gees.x > maxPosVerG[truck->driveable]) maxPosVerG[truck->driveable] = gees.x; if(gees.x < maxNegVerG[truck->driveable]) maxNegVerG[truck->driveable] = gees.x; if(gees.y > maxPosSagG[truck->driveable]) maxPosSagG[truck->driveable] = gees.y; if(gees.y < maxNegSagG[truck->driveable]) maxNegSagG[truck->driveable] = gees.y; if(gees.z > maxPosLatG[truck->driveable]) maxPosLatG[truck->driveable] = gees.z; if(gees.z < maxNegLatG[truck->driveable]) maxNegLatG[truck->driveable] = gees.z; tmp = _L("maxG: V %1.2fg %1.2fg // S %1.2fg %1.2fg // L %1.2fg %1.2fg"); swprintf(geesstr, 256, tmp.asWStr_c_str(), maxPosVerG[truck->driveable], maxNegVerG[truck->driveable], maxPosSagG[truck->driveable], maxNegSagG[truck->driveable], maxPosLatG[truck->driveable], maxNegLatG[truck->driveable] ); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/Gees2"); descl->setCaption(UTFString(geesstr)); checkOverflow(descl); } } Vector3 hdir = Vector3::ZERO; if(truck->cameranodepos[0]>=0) hdir = truck->nodes[truck->cameranodepos[0]].RelPosition-truck->nodes[truck->cameranodedir[0]].RelPosition; hdir.normalise(); float g_along_hdir=hdir.dotProduct(truck->ffforce/10000.0); //LOG("ffforce: " + TOSTRING(truck->ffforce.x) + ", " + TOSTRING(truck->ffforce.y) + ", " + TOSTRING(truck->ffforce.z) + " / direction: " + TOSTRING(hdir.x) + ", " + TOSTRING(hdir.y) + ", " + TOSTRING(hdir.z)); // TODO: FIX THIS! //char rpmstring[256]; //sprintf(rpmstring, "current GForces: %2.2f", g_along_hdir); //OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentRPM")->setCaption(rpmstring); // always update these statistics, also if not visible! UTFString rpmsstr = _L("current RPM:"); if(truck->driveable == TRUCK && truck->engine) { wchar_t rpmstring[256]; UTFString rpmsstr = _L("current RPM:"); swprintf(rpmstring, 256, L"%ls %.0f / %.0f", rpmsstr.asWStr_c_str(), truck->engine->getRPM(), truck->engine->getMaxRPM()*1.25); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentRPM"); descl->setCaption(UTFString(rpmstring)); checkOverflow(descl); } else if (truck->driveable == AIRPLANE) { wchar_t rpmstring[256]; if(truck->aeroengines[0] && truck->aeroengines[1] && truck->aeroengines[2] && truck->aeroengines[3]) swprintf(rpmstring, 256, L"%ls %.0f / %.0f / %.0f / %.0f", rpmsstr.asWStr_c_str(), truck->aeroengines[0]->getRPM(), truck->aeroengines[1]->getRPM(), truck->aeroengines[2]->getRPM(), truck->aeroengines[3]->getRPM()); else if(truck->aeroengines[0] && truck->aeroengines[1] && truck->aeroengines[2] && !truck->aeroengines[3]) swprintf(rpmstring, 256, L"%ls %.0f / %.0f / %.0f", rpmsstr.asWStr_c_str(), truck->aeroengines[0]->getRPM(), truck->aeroengines[1]->getRPM(), truck->aeroengines[2]->getRPM()); else if(truck->aeroengines[0] && truck->aeroengines[1] && !truck->aeroengines[2] && !truck->aeroengines[3]) swprintf(rpmstring, 256, L"%ls %.0f / %.0f", rpmsstr.asWStr_c_str(), truck->aeroengines[0]->getRPM(), truck->aeroengines[1]->getRPM()); else if(truck->aeroengines[0] && !truck->aeroengines[1] && !truck->aeroengines[2] && !truck->aeroengines[3]) swprintf(rpmstring, 256, L"%ls %.0f", rpmsstr.asWStr_c_str(), truck->aeroengines[0]->getRPM()); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentRPM"); descl->setCaption(UTFString(rpmstring)); checkOverflow(descl); } else { descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentRPM"); descl->setCaption(""); } UTFString cspeedstr = _L("current Speed:"); UTFString maxspstr = _L("max Speed:"); if(truck->driveable == TRUCK) { wchar_t velostring[256]; float velocityKMH = (truck->WheelSpeed * 3.6); if(velocityKMH > maxVelos[truck->driveable]) maxVelos[truck->driveable] = velocityKMH; if(velocityKMH < minVelos[truck->driveable]) minVelos[truck->driveable] = velocityKMH; // round values if zero ==> no flickering +/- if (fabs(velocityKMH) < 1) velocityKMH = 0; float velocityMPH = velocityKMH / 1.609; swprintf(velostring, 256, L"%ls %+.0f km/h (%+.0f mp/h)", cspeedstr.asWStr_c_str(), ceil(velocityKMH), ceil(velocityMPH)); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentVelocity"); descl->setCaption(UTFString(velostring)); checkOverflow(descl); float velocityMaxMPH = maxVelos[truck->driveable] / 1.609; float velocityMinMPH = minVelos[truck->driveable] / 1.609; swprintf(velostring, 256, L"%ls %+.0fkmh/%+.0fmph, min: %+.0fkmh/%+.0fmph", maxspstr.asWStr_c_str(), ceil(maxVelos[truck->driveable]), ceil(velocityMaxMPH), ceil(minVelos[truck->driveable]), ceil(velocityMinMPH)); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/MaxVelocity"); descl->setCaption(UTFString(velostring)); checkOverflow(descl); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageVelocity"); descl->setCaption(""); } else if(truck->driveable == AIRPLANE) { wchar_t velostring[256]; float velocity = truck->nodes[0].Velocity.length()*1.9438; if(velocity > maxVelos[truck->driveable]) maxVelos[truck->driveable] = velocity; if(velocity < minVelos[truck->driveable]) minVelos[truck->driveable] = velocity; // round values if zero ==> no flickering +/- if (fabs(velocity) < 1) velocity = 0; swprintf(velostring, 256, L"%ls %+.0f kn", cspeedstr.asWStr_c_str(), ceil(velocity)); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentVelocity"); descl->setCaption(UTFString(velostring)); checkOverflow(descl); swprintf(velostring, 256, L"%ls %+.0fkn, min: %+.0f kn", maxspstr.asWStr_c_str(), ceil(maxVelos[truck->driveable]), ceil(minVelos[truck->driveable])); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/MaxVelocity"); descl->setCaption(UTFString(velostring)); checkOverflow(descl); float alt = truck->nodes[0].AbsPosition.y*1.1811; UTFString altstr = _L("Altitude:"); swprintf(velostring, 256, L"%ls %+.0f m", altstr.asWStr_c_str(), ceil(alt)); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageVelocity"); descl->setCaption(velostring); checkOverflow(descl); } else if(truck->driveable == BOAT) { wchar_t velostring[256]; Vector3 hdir=truck->nodes[truck->cameranodepos[0]].RelPosition-truck->nodes[truck->cameranodedir[0]].RelPosition; hdir.normalise(); float velocity=hdir.dotProduct(truck->nodes[truck->cameranodepos[0]].Velocity)*1.9438; if(velocity > maxVelos[truck->driveable]) maxVelos[truck->driveable] = velocity; if(velocity < minVelos[truck->driveable]) minVelos[truck->driveable] = velocity; swprintf(velostring, 256, L"%ls %+.0f kn", cspeedstr.asWStr_c_str(),ceil(velocity)); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentVelocity"); descl->setCaption(UTFString(velostring)); checkOverflow(descl); swprintf(velostring, 256, L"%ls %+.0fkn, min: %+.0f kn", maxspstr.asWStr_c_str(),ceil(maxVelos[truck->driveable]), ceil(minVelos[truck->driveable])); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/MaxVelocity"); descl->setCaption(UTFString(velostring)); checkOverflow(descl); descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageVelocity"); descl->setCaption(""); } else if(truck->driveable == MACHINE) { OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/MaxVelocity")->setCaption(""); OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CurrentVelocity")->setCaption(""); OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/AverageVelocity")->setCaption(""); } OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/TimeStats")->setCaption(""); if(visible) { // update commands //clear them first for(int i=1;i<=COMMANDS_VISIBLE;i++) { char commandOverlayID[256]; sprintf(commandOverlayID, "tracks/TruckInfoBox/Command%d", i); // no wchar needed descl = OverlayManager::getSingleton().getOverlayElement(commandOverlayID); descl->setCaption(string("")); } int j = 0; for(int i=1,j=0;i<MAX_COMMANDS && j<COMMANDS_VISIBLE;i+=2) { if (truck->commandkey[i].description.size() == 0) continue; j++; char commandID[256]; String keyStr=""; sprintf(commandID, "COMMANDS_%02d", i); int eventID = INPUTENGINE.resolveEventName(String(commandID)); String keya = INPUTENGINE.getEventCommand(eventID); sprintf(commandID, "COMMANDS_%02d", i+1); eventID = INPUTENGINE.resolveEventName(String(commandID)); String keyb = INPUTENGINE.getEventCommand(eventID); //cut off expl if(keya.size()>6 && keya.substr(0,5) == "EXPL+") keya = keya.substr(5); if(keyb.size()>6 && keyb.substr(0,5) == "EXPL+") keyb = keyb.substr(5); keyStr = keya + "/" + keyb; char commandOverlayID[256]; sprintf(commandOverlayID, "tracks/TruckInfoBox/Command%d", j); descl = OverlayManager::getSingleton().getOverlayElement(commandOverlayID); descl->setCaption(keyStr + ": " + truck->commandkey[i].description); checkOverflow(descl); } // hide command section title if no commands if(j == 0) { OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CommandsTitleLabel")->setCaption(""); } else { descl = OverlayManager::getSingleton().getOverlayElement("tracks/TruckInfoBox/CommandsTitleLabel"); descl->setCaption(_L("Commands:")); checkOverflow(descl); } } return true; }