summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2014-10-29 17:53:46 +0100
committerkrzys-h <krzys_h@interia.pl>2014-10-29 17:53:46 +0100
commit6d2fd18b419ddc202fa14cb14c98e8f3d5ecf646 (patch)
tree9075499f6dd08609a229a55a1aa15104ac5b1955 /src/common
parent61e06149c65fbc61c6d927f527195a9b4a8154dc (diff)
downloadcolobot-6d2fd18b419ddc202fa14cb14c98e8f3d5ecf646.tar.gz
colobot-6d2fd18b419ddc202fa14cb14c98e8f3d5ecf646.tar.bz2
colobot-6d2fd18b419ddc202fa14cb14c98e8f3d5ecf646.zip
Implemented mission timer
Diffstat (limited to 'src/common')
-rw-r--r--src/common/misc.cpp13
-rw-r--r--src/common/misc.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/src/common/misc.cpp b/src/common/misc.cpp
index 4954fc0..35a5560 100644
--- a/src/common/misc.cpp
+++ b/src/common/misc.cpp
@@ -26,6 +26,8 @@
#include <string.h>
#include <ctype.h>
#include <time.h>
+#include <sstream>
+#include <iomanip>
// Returns a non-accented letter.
@@ -232,6 +234,17 @@ void TimeToAsciiClean(time_t time, char *buffer)
when.tm_hour, when.tm_min);
}
+std::string TimeFormat(float time)
+{
+ int minutes = floor(time/60);
+ double time2 = fmod(time, 60);
+ double seconds;
+ double fraction = modf(time2, &seconds)*100;
+ std::ostringstream sstream;
+ sstream << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << floor(seconds) << "." << std::setfill('0') << std::setw(2) << floor(fraction);
+ return sstream.str();
+}
+
// Adds an extension to file, if doesn't already one.
diff --git a/src/common/misc.h b/src/common/misc.h
index 4b75ae3..b53bbdd 100644
--- a/src/common/misc.h
+++ b/src/common/misc.h
@@ -22,6 +22,7 @@
#include <time.h>
+#include <string>
// TODO: rewrite/refactor or remove
@@ -32,6 +33,7 @@ extern char GetToLower(char letter);
extern void TimeToAscii(time_t time, char *buffer);
extern void TimeToAsciiClean(time_t time, char *buffer);
+extern std::string TimeFormat(float time);
extern void AddExt(char* filename, const char* ext);