Switched getTime() to std::chrono on all platforms.

This commit is contained in:
dongresource 2020-09-16 20:14:00 +02:00
parent efda6673b5
commit 5efc8ac089
3 changed files with 9 additions and 14 deletions

View File

@ -1,7 +1,5 @@
#include "CNStructs.hpp"
#if defined _MSC_VER
#include <chrono>
#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::milliseconds>((std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now())).time_since_epoch());
return (uint64_t)(value.count());
#endif
time_t getTime() {
using namespace std::chrono;
milliseconds value = duration_cast<milliseconds>((time_point_cast<milliseconds>(high_resolution_clock::now())).time_since_epoch());
return (time_t)value.count();
}

View File

@ -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)

View File

@ -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)