Skip to content

Commit

Permalink
Remove _ftime and _timeb
Browse files Browse the repository at this point in the history
*This should fix a few warnings on Ubuntu 18 and 20.
  • Loading branch information
Reason184 committed Jul 3, 2021
1 parent 57951f6 commit 129d1f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
6 changes: 4 additions & 2 deletions sources/item.cpp
Expand Up @@ -936,7 +936,8 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance, const
}
else
s << ", ";
s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;

s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;
}

if(it.attackSpeed || (item && item->getAttackSpeed()))
Expand Down Expand Up @@ -1243,7 +1244,8 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance, const
}
else
s << ", ";
s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;

s << "Crit Chance:" << std::showpos << int32_t(item ? item->getCriticalHitChance() : it.criticalHitChance) << "%"<< std::noshowpos;
}

if(it.hasAbilities())
Expand Down
13 changes: 2 additions & 11 deletions sources/otsystem.h
Expand Up @@ -64,14 +64,6 @@
#define access _access
#endif

#ifndef timeb
#define timeb _timeb
#endif

#ifndef ftime
#define ftime _ftime
#endif

#ifndef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif
Expand Down Expand Up @@ -122,9 +114,8 @@

inline int64_t OTSYS_TIME()
{
timeb t;
ftime(&t);
return ((int64_t)t.millitm) + ((int64_t)t.time) * 1000;
using namespace std::chrono;
return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
}

inline uint32_t swap_uint32(uint32_t val)
Expand Down
38 changes: 9 additions & 29 deletions sources/tools.cpp
Expand Up @@ -681,39 +681,19 @@ std::string formatDateEx(time_t _time/* = 0*/, std::string format/* = "%d %b %Y,

std::string formatTime(time_t _time/* = 0*/, bool ms/* = false*/)
{
if(!_time)
_time = time(NULL);
else if(ms)
ms = false;

const tm* tms = localtime(&_time);
std::ostringstream s;
if(tms)
{
s << tms->tm_hour << ":" << tms->tm_min << ":";
if(tms->tm_sec < 10)
s << "0";
using namespace std::chrono;

s << tms->tm_sec;
if(ms)
{
timeb t;
ftime(&t);
auto now = system_clock::now();
auto millisec = duration_cast<milliseconds>(now.time_since_epoch()) % 1000;
auto timer = system_clock::to_time_t(now);

s << "."; // make it format zzz
if(t.millitm < 10)
s << "0";
std::tm bt = *std::localtime(&timer);
std::ostringstream oss;

if(t.millitm < 100)
s << "0";
oss << std::put_time(&bt, "%H:%M:%S"); // HH:MM:SS
oss << '.' << std::setfill('0') << std::setw(3) << millisec.count();

s << t.millitm;
}
}
else
s << "UNIX Time: " << (int32_t)_time;

return s.str();
return oss.str();
}

std::string convertIPAddress(uint32_t ip)
Expand Down

0 comments on commit 129d1f6

Please sign in to comment.