From 186e62dec45bc1e606b3a536f4f6689922910b9b Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 19 Aug 2012 16:55:46 +0100 Subject: [PATCH] Pad frame numbers with zeros for screenshots and recording --- src/cat/LuaScriptInterface.cpp | 9 ++++++++- src/game/GameView.cpp | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index dc3d5fb97..bcf20098a 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -6,6 +6,7 @@ */ #include +#include #include "Config.h" #include "Format.h" #include "LuaScriptInterface.h" @@ -2083,6 +2084,8 @@ int luatpt_setwindowsize(lua_State* l) return 0; } +int screenshotIndex = 0; + int luatpt_screenshot(lua_State* l) { //TODO Implement @@ -2098,7 +2101,11 @@ int luatpt_screenshot(lua_State* l) VideoBuffer screenshot(luacon_ren->DumpFrame()); data = format::VideoBufferToPNG(screenshot); } - Client::Ref().WriteFile(data, "screenshot.png"); + std::stringstream filename; + filename << "screenshot_"; + filename << std::setfill('0') << std::setw(6) << (screenshotIndex++); + filename << ".png"; + Client::Ref().WriteFile(data, filename.str()); return 0; } diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index dbe7f3058..f812358b7 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -1825,7 +1825,13 @@ void GameView::OnDraw() { VideoBuffer screenshot(ren->DumpFrame()); std::vector data = format::VideoBufferToPNG(screenshot); - Client::Ref().WriteFile(data, "screenshot_" + format::NumberToString(screenshotIndex++) + ".png"); + + std::stringstream filename; + filename << "screenshot_"; + filename << std::setfill('0') << std::setw(6) << (screenshotIndex++); + filename << ".png"; + + Client::Ref().WriteFile(data, filename.str()); doScreenshot = false; } @@ -1833,7 +1839,13 @@ void GameView::OnDraw() { VideoBuffer screenshot(ren->DumpFrame()); std::vector data = format::VideoBufferToPPM(screenshot); - Client::Ref().WriteFile(data, "frame_" + format::NumberToString(recordingIndex++) + ".ppm"); + + std::stringstream filename; + filename << "frame_"; + filename << std::setfill('0') << std::setw(6) << (recordingIndex++); + filename << ".ppm"; + + Client::Ref().WriteFile(data, filename.str()); }