diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 9bcea8906..0e606cfbc 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1610,12 +1610,22 @@ void IrrDriver::update(float dt) video::IImage* image = m_video_driver->createScreenShot(); if (image) { - static int screenshot_id = 1; + time_t rawtime; + time ( &rawtime ); + tm* timeInfo = gmtime( &rawtime ); + std::string now = StringUtils::insertValues(std::string("%i.%i.%i %i.%i.%i"), + timeInfo->tm_year + 1900, + timeInfo->tm_mon, timeInfo->tm_mday, + timeInfo->tm_hour, timeInfo->tm_min, + timeInfo->tm_sec); + #if defined(WIN32) - std::string path = StringUtils::insertValues("C:\\Temp\\supertuxkart_%s_%i.png", race_manager->getTrackName().c_str(), screenshot_id++); + std::string path = StringUtils::insertValues("C:\\Temp\\supertuxkart %s %s.png", + race_manager->getTrackName().c_str(), now); #else - std::string path = StringUtils::insertValues("/tmp/supertuxkart_%s_%i.png", race_manager->getTrackName().c_str(), screenshot_id++); + std::string path = StringUtils::insertValues("/tmp/supertuxkart %s %s.png", + race_manager->getTrackName().c_str(), now); #endif if (irr_driver->getVideoDriver()->writeImageToFile(image, io::path(path.c_str()), 0)) @@ -1623,7 +1633,8 @@ void IrrDriver::update(float dt) RaceGUIBase* base = World::getWorld()->getRaceGUI(); if (base != NULL) { - base->addMessage(core::stringw(("Screenshot saved to\n" + path).c_str()), NULL, 2.0f, video::SColor(255,255,255,255), true, false); + base->addMessage(core::stringw(("Screenshot saved to\n" + path).c_str()), NULL, + 2.0f, video::SColor(255,255,255,255), true, false); } } else @@ -1631,7 +1642,8 @@ void IrrDriver::update(float dt) RaceGUIBase* base = World::getWorld()->getRaceGUI(); if (base != NULL) { - base->addMessage(core::stringw(("FAILED saving screenshot to\n" + path + "\n:(").c_str()), NULL, 2.0f, video::SColor(255,255,255,255), true, false); + base->addMessage(core::stringw(("FAILED saving screenshot to\n" + path + "\n:(").c_str()), + NULL, 2.0f, video::SColor(255,255,255,255), true, false); } } image->drop(); diff --git a/src/utils/string_utils.hpp b/src/utils/string_utils.hpp index a60547089..05901aaa5 100644 --- a/src/utils/string_utils.hpp +++ b/src/utils/string_utils.hpp @@ -127,6 +127,51 @@ namespace StringUtils // ------------------------------------------------------------------------ // Note: the order in which the templates are specified is important, since // otherwise some compilers will not find the right template to use. + + template + std::string insertValues(const std::string &s, const T1 &v1, + const T2 &v2, const T3 &v3, const T4 &v4, + const T5 &v5,const T6 &v6) + { + std::vector all_vals; + std::ostringstream dummy; + dummy << v1; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v2; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v3; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v4; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v5; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v6; all_vals.push_back(dummy.str()); + return insertValues(s, all_vals); + } + + template + std::string insertValues(const std::string &s, const T1 &v1, + const T2 &v2, const T3 &v3, const T4 &v4, + const T5 &v5) + { + std::vector all_vals; + std::ostringstream dummy; + dummy << v1; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v2; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v3; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v4; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v5; all_vals.push_back(dummy.str()); + return insertValues(s, all_vals); + } + + template + std::string insertValues(const std::string &s, const T1 &v1, + const T2 &v2, const T3 &v3, const T4 &v4) + { + std::vector all_vals; + std::ostringstream dummy; + dummy << v1; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v2; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v3; all_vals.push_back(dummy.str()); dummy.str(""); + dummy << v4; all_vals.push_back(dummy.str()); + return insertValues(s, all_vals); + } + /** Shortcut insert_values taking three values, see above for * full docs. * \param s String in which all %s or %d are replaced.