From 5efc8ac089e482414c3162d9423b254427acb94a Mon Sep 17 00:00:00 2001 From: dongresource Date: Wed, 16 Sep 2020 20:14:00 +0200 Subject: [PATCH] Switched getTime() to std::chrono on all platforms. --- src/CNStructs.cpp | 19 +++++++------------ src/CNStructs.hpp | 2 +- src/MissionManager.cpp | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/CNStructs.cpp b/src/CNStructs.cpp index 6d889ea..3501594 100644 --- a/src/CNStructs.cpp +++ b/src/CNStructs.cpp @@ -1,7 +1,5 @@ #include "CNStructs.hpp" -#if defined _MSC_VER #include -#endif std::string U16toU8(char16_t* src) { try { @@ -24,13 +22,10 @@ size_t U8toU16(std::string src, char16_t* des) { return tmp.length(); } -uint64_t getTime() { -#ifndef _MSC_VER - struct timeval tp; - gettimeofday(&tp, NULL); - return tp.tv_sec * 1000 + tp.tv_usec / 1000; -#else -std::chrono::milliseconds value = std::chrono::duration_cast((std::chrono::time_point_cast(std::chrono::high_resolution_clock::now())).time_since_epoch()); -return (uint64_t)(value.count()); -#endif -} \ No newline at end of file +time_t getTime() { + using namespace std::chrono; + + milliseconds value = duration_cast((time_point_cast(high_resolution_clock::now())).time_since_epoch()); + + return (time_t)value.count(); +} diff --git a/src/CNStructs.hpp b/src/CNStructs.hpp index 30309ce..3fa635b 100644 --- a/src/CNStructs.hpp +++ b/src/CNStructs.hpp @@ -32,7 +32,7 @@ std::string U16toU8(char16_t* src); size_t U8toU16(std::string src, char16_t* des); // returns number of char16_t that was written at des -uint64_t getTime(); +time_t getTime(); // The PROTOCOL_VERSION definition is defined by the build system. #if !defined(PROTOCOL_VERSION) diff --git a/src/MissionManager.cpp b/src/MissionManager.cpp index f547351..2ad8f9f 100644 --- a/src/MissionManager.cpp +++ b/src/MissionManager.cpp @@ -78,7 +78,7 @@ void MissionManager::taskEnd(CNSocket* sock, CNPacketData* data) { * Yes, this is pretty stupid. * * iSUInstancename is the number of items to give. It is usually negative at the end of - * a mission, so as to clean up it's quest items. + * a mission, to clean up its quest items. */ for (int i = 0; i < 3; i++) if (task["m_iSUItem"][i] != 0)