void CMeter2DGraphModel::UpdateTimeTitleContainer() { TRACE_FUN( Frequently, "CMeter2DGraphModel::UpdateTimeTitleContainer" ); _timeTitleContainer.clear(); float timeTitleSecs( .0 ); for( int i( timeResolution() ); i > 0; --i ) { timeTitleSecs += float( timeFrame() ) / timeResolution(); l2max::CVariant minute( int( timeTitleSecs ) / 60 ); minute.SetWidth( 2 ); l2max::CVariant second( int( timeTitleSecs ) % 60 ); second.SetWidth( 2 ); std::string timeText( minute.toString() + ":" + second.toString() ); _timeTitleContainer.push_back( timeText ); } updateConsumer().timeFrameChanged(); }
void HexagonGame::drawText() { ostringstream s; s << "time: " << toStr(currentTime).substr(0, 5) << endl; if(hasDied) s << "press r to restart" << endl; vector<Vector2f> offsets{{-1,-1},{-1,1},{1,-1},{1,1}}; Text timeText(s.str(), getFont("imagine"), 25 / getZoomFactor()); timeText.setPosition(15, 3); timeText.setColor(getColorMain()); for(auto offset : offsets) { Text timeOffsetText(s.str(), getFont("imagine"), timeText.getCharacterSize()); timeOffsetText.setPosition(timeText.getPosition() + offset); timeOffsetText.setColor(getColorB()); drawOnWindow(timeOffsetText); } drawOnWindow(timeText); for (Text* textPtr : messageTextPtrs) { for(auto offset : offsets) { Text textPtrOffset{textPtr->getString(), getFont("imagine"), textPtr->getCharacterSize()}; textPtrOffset.setPosition(textPtr->getPosition() + offset); textPtrOffset.setOrigin(textPtrOffset.getGlobalBounds().width / 2, 0); textPtrOffset.setColor(getColorB()); drawOnWindow(textPtrOffset); } textPtr->setColor(getColorMain()); drawOnWindow(*textPtr); } }
// If this is an expires line, then modify it by adding timeNow to the expiration time value. // Otherwise don't mess with it. void RegistrationDbTestContext::timeShiftExpiresLine(UtlString& line, long timeNow) { const char* EXPIRES_BEGIN = "<expires>"; const int EXPIRES_TAG_LENGTH = 9; const char* EXPIRES_END = "</expires>"; ssize_t pos1, pos2; // If the line has an expiration value, then time-shift it if (((pos1 = line.index(EXPIRES_BEGIN)) != UTL_NOT_FOUND) && ((pos2 = line.index(EXPIRES_END)) != UTL_NOT_FOUND)) { pos1 += EXPIRES_TAG_LENGTH; // skip past the tag, to the expires value CPPUNIT_ASSERT(pos2 > pos1); // expires value cannot be empty UtlString timeText(line(pos1, pos2 - pos1)); char* endptr = NULL; long timeNumber = strtol(timeText, &endptr, 10); CPPUNIT_ASSERT_EQUAL(*endptr, '\0'); char newTime[20]; // room for up to a 64-bit number, may have minus sign int newTimeLen = sprintf(newTime, "%ld", timeNow + timeNumber); CPPUNIT_ASSERT(newTimeLen > 0); // Replace the old expiration value with the new shifted value UtlString lineEnd(line(pos2, line.length() - pos2)); line.replace(pos1, newTimeLen, newTime); line.replace(pos1 + newTimeLen, lineEnd.length(), lineEnd); } }
// Member function to update the static timer comtrol. void BoidsWin::updateTimer( ) { // Set the text of the static control to show the current time. // Update the runTime. clock_t time; // Local variable used to hold the time. if ( stopped == false ) { time = clock( ) - stopTime; runTime = time; } else // The simulation is stopped so just display the current run time. { time = runTime; } CString timeText( "Time: " ); char buffer[ 50 ]; // Temporary buffer for string conversion. long minutes = ( time / CLOCKS_PER_SEC ) / 60; long seconds = ( time / CLOCKS_PER_SEC ) % 60; long hundreds = ( time / ( CLOCKS_PER_SEC / 100 ) ) % 100; timeText += _ltoa( minutes, buffer, 10 ); if ( seconds < 10 ) { timeText += ".0"; } else { timeText += "."; } timeText += _ltoa( seconds, buffer, 10 ); if ( hundreds < 10 ) { timeText += ".0"; } else { timeText += "."; } timeText += _ltoa( hundreds, buffer, 10 ); staticTime.SetWindowText( timeText ); }
void Game::Go() { sf::Clock clock1; sf::Clock clock2; float framerate = 0.0f; while (App->isOpen() && scene != NULL && scene != EXIT_SCN) { if (!scene->Init()) { std::cerr << "Scene couldn't init correctly. Game will shut down." << std::endl; App->close(); } sf::Clock sceneTimeElapsed; clock1.restart(); while(App->isOpen() && scene->nextScene == NULL) { global_frametime = clock1.getElapsedTime(); global_frametime = sf::microseconds(1000000 / frameLimit); //FIXED framerate. scene_total_time = sceneTimeElapsed.getElapsedTime(); clock1.restart(); //Framerate if (clock2.getElapsedTime().asMilliseconds() > 100) { framerate = ((float) frames / (float) clock2.getElapsedTime().asMilliseconds())*1000.0f; clock2.restart(); frames = 0; } std::stringstream ss(std::stringstream::in | std::stringstream::out); framerate*=100; framerate= floor(framerate); framerate/=100; ss << "FPS: " << framerate; sf::Text fpsText(ss.str()); fpsText.setPosition(10, 10); fpsText.setColor(sf::Color::Red); std::stringstream ss2(std::stringstream::in | std::stringstream::out); ss2 << static_cast<int>(sceneTimeElapsed.getElapsedTime().asSeconds()/60) << " : " << (((int)sceneTimeElapsed.getElapsedTime().asSeconds())%60) << " . " << sceneTimeElapsed.getElapsedTime().asMilliseconds()%1000; sf::Text timeText(ss2.str()); timeText.setPosition(0.8f * (float) App->getSize().x, 10.0f); timeText.setColor(sf::Color::White); //Input scene->input.Update(); if (scene->input.getKeyDown(InputEng::EXIT)) scene->nextScene = EXIT_SCN; //Logic scene->Update(); //Draw App->clear(sf::Color(12, 12, 12)); scene->Draw(); App->draw(fpsText); //App->draw(timeText); App->display(); frames++; } Scene* aux_scn = scene; scene = scene->nextScene; aux_scn->Destroy(); delete aux_scn; cout << "Scene change. " << endl; } }