1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-21 12:49:10 +00:00

Kill pnUtilsExe.

This commit is contained in:
Darryl Pogue
2012-04-14 19:27:10 -07:00
parent 1ae3979753
commit f38682882b
16 changed files with 86 additions and 630 deletions

View File

@ -39,13 +39,68 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
#include "pnUtTime.h"
#if HS_BUILD_FOR_UNIX
#include <time.h>
#include <sys/time.h>
#endif
/******************************************************************************
* I've combined all the pnUtils Time stuff in here and made it work cross-
* platform as best as possible.
*
* At some point, hsTimer needs to be rewritten to ensure that it's fully
* corss-platform and using a reliable millisecond clock.
* When that happens, these functions should be merged into hsTimer.
*
* -- dpogue (April 14, 2012)
*
*****************************************************************************/
namespace pnUtilsExe {
uint32_t TimeGetTickCount () {
#if HS_BUILD_FOR_WIN32
return GetTickCount();
#else
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
return 0;
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
#endif
}
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtTime.cpp
*
* Time adjustment functions
*
* For debug builds, adjust the initial time value so that the high
* bit or the time value itself is about to wrap, to catch application
* bugs that don't handle wrapping or depend on the high bit's value.
*
***/
#include "pnUtTime.h"
static uint32_t s_adjustment;
//===========================================================================
static void InitializeAdjustment () {
ASSERT(!s_adjustment);
uint32_t currTime = TimeGetTickCount();
uint32_t startBits = (currTime & 0x80) ? 0x7fff0000 : 0xffff0000;
uint32_t startMask = 0xffff0000;
s_adjustment = (((currTime & ~startMask) | startBits) - currTime) | 1;
ASSERT(s_adjustment);
}
//===========================================================================
AUTO_INIT_FUNC(AutoInitializeAdjustment) {
if (!s_adjustment)
InitializeAdjustment();
}
} using namespace pnUtilsExe;
/*****************************************************************************
@ -54,38 +109,37 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*
***/
//===========================================================================
void TimeGetElapsedDesc (
uint32_t minutesElapsed,
TimeElapsedDesc * desc
) {
const unsigned kMinutesPerHour = 60;
const unsigned kMinutesPerDay = 1440;
const unsigned kMinutesPerWeek = 10080;
const unsigned kMinutesPerMonth = 43830;
const unsigned kMinutesPerYear = 525960;
uint32_t & elapsed = minutesElapsed;
desc->years = (elapsed / kMinutesPerYear); elapsed -= desc->years * kMinutesPerYear;
desc->months = (elapsed / kMinutesPerMonth); elapsed -= desc->months * kMinutesPerMonth;
desc->weeks = (elapsed / kMinutesPerWeek); elapsed -= desc->weeks * kMinutesPerWeek;
desc->days = (elapsed / kMinutesPerDay); elapsed -= desc->days * kMinutesPerDay;
desc->hours = (elapsed / kMinutesPerHour); elapsed -= desc->hours * kMinutesPerHour;
desc->minutes = elapsed;
}
//============================================================================
uint32_t TimeGetSecondsSince2001Utc () {
uint64_t time = TimeGetTime();
uint32_t seconds = (uint32_t)((time - kTime1601To2001) / kTimeIntervalsPerSecond);
return seconds;
}
//============================================================================
uint32_t TimeGetSecondsSince1970Utc () {
uint64_t time = TimeGetTime();
uint32_t seconds = (uint32_t)((time - kTime1601To1970) / kTimeIntervalsPerSecond);
return seconds;
uint64_t TimeGetTime () {
#ifdef HS_BUILD_FOR_WIN32
uint64_t time;
COMPILER_ASSERT(sizeof(uint64_t) == sizeof(FILETIME));
GetSystemTimeAsFileTime((FILETIME *) &time);
return time;
#else
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
return 0;
long long time = ts.tv_sec * 1000000000LL + ts.tv_nsec;
return time / 100;
#endif
}
uint32_t TimeGetMs () {
#ifdef HS_DEBUGGING
// For debug builds, return an adjusted timer value
if (!s_adjustment)
InitializeAdjustment();
return TimeGetTickCount() + s_adjustment;
#else
// For release builds, just return the operating system's timer
return TimeGetTickCount();
#endif
}