summaryrefslogtreecommitdiff
path: root/library/MiscUtils.cpp
diff options
context:
space:
mode:
authorPetr Mrázek2011-12-31 13:14:08 +0100
committerPetr Mrázek2011-12-31 13:14:08 +0100
commit52dfa842ccd3ff3add2c92b6a8a12f1ff0d9a6e0 (patch)
tree9b99a817d0d8dffedc620795bc9b394310c38977 /library/MiscUtils.cpp
parentf35cdb84cdeaed99c0bb291423ffbc05183fd35f (diff)
downloaddfhack-52dfa842ccd3ff3add2c92b6a8a12f1ff0d9a6e0.tar.gz
dfhack-52dfa842ccd3ff3add2c92b6a8a12f1ff0d9a6e0.tar.bz2
dfhack-52dfa842ccd3ff3add2c92b6a8a12f1ff0d9a6e0.tar.xz
Add missing MiscUtils.cpp
Diffstat (limited to 'library/MiscUtils.cpp')
-rw-r--r--library/MiscUtils.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/library/MiscUtils.cpp b/library/MiscUtils.cpp
new file mode 100644
index 00000000..47deea04
--- /dev/null
+++ b/library/MiscUtils.cpp
@@ -0,0 +1,74 @@
+/*
+https://github.com/peterix/dfhack
+Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+*/
+
+#include "Internal.h"
+#include "Export.h"
+#include "Core.h"
+#include "MiscUtils.h"
+
+
+
+#ifndef LINUX_BUILD
+ #include <Windows.h>
+#else
+ #include <sys/time.h>
+ #include <ctime>
+#endif
+
+#ifdef LINUX_BUILD // Linux
+uint64_t GetTimeMs64()
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ uint64_t ret = tv.tv_usec;
+
+ // Convert from micro seconds (10^-6) to milliseconds (10^-3)
+ ret /= 1000;
+ // Adds the seconds (10^0) after converting them to milliseconds (10^-3)
+ ret += (tv.tv_sec * 1000);
+ return ret;
+}
+
+
+#else // Windows
+uint64_t GetTimeMs64()
+{
+ FILETIME ft;
+ LARGE_INTEGER li;
+
+ // Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC)
+ // and copy it to a LARGE_INTEGER structure.
+ GetSystemTimeAsFileTime(&ft);
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+
+ uint64_t ret = li.QuadPart;
+ // Convert from file time to UNIX epoch time.
+ ret -= 116444736000000000LL;
+ // From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals
+ ret /= 10000;
+
+ return ret;
+}
+#endif \ No newline at end of file