mirror of https://github.com/jorio/Pomme.git
Implement TickCount
This commit is contained in:
parent
2f57b5245e
commit
9260f05025
|
@ -15,7 +15,6 @@ set(POMME_SOURCES
|
||||||
${POMME_SRCDIR}/PommeInit.h
|
${POMME_SRCDIR}/PommeInit.h
|
||||||
${POMME_SRCDIR}/PommeInput.h
|
${POMME_SRCDIR}/PommeInput.h
|
||||||
${POMME_SRCDIR}/PommeSound.h
|
${POMME_SRCDIR}/PommeSound.h
|
||||||
${POMME_SRCDIR}/PommeTime.h
|
|
||||||
${POMME_SRCDIR}/PommeTypes.h
|
${POMME_SRCDIR}/PommeTypes.h
|
||||||
${POMME_SRCDIR}/PommeVideo.h
|
${POMME_SRCDIR}/PommeVideo.h
|
||||||
${POMME_SRCDIR}/Files/Files.cpp
|
${POMME_SRCDIR}/Files/Files.cpp
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "Pomme.h"
|
#include "Pomme.h"
|
||||||
#include "PommeInit.h"
|
#include "PommeInit.h"
|
||||||
#include "PommeTime.h"
|
|
||||||
#include "PommeFiles.h"
|
#include "PommeFiles.h"
|
||||||
#include "PommeGraphics.h"
|
#include "PommeGraphics.h"
|
||||||
#include "PommeSound.h"
|
#include "PommeSound.h"
|
||||||
|
@ -68,7 +67,6 @@ void ShowCursor()
|
||||||
|
|
||||||
void Pomme::Init()
|
void Pomme::Init()
|
||||||
{
|
{
|
||||||
Pomme::Time::Init();
|
|
||||||
Pomme::Files::Init();
|
Pomme::Files::Init();
|
||||||
Pomme::Graphics::Init();
|
Pomme::Graphics::Init();
|
||||||
Pomme::Sound::Init();
|
Pomme::Sound::Init();
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace Pomme::Time
|
|
||||||
{
|
|
||||||
void Init();
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "Pomme.h"
|
#include "Pomme.h"
|
||||||
#include "PommeTime.h"
|
|
||||||
#include "PommeTypes.h"
|
#include "PommeTypes.h"
|
||||||
#include "PommeDebug.h"
|
#include "PommeDebug.h"
|
||||||
|
|
||||||
|
|
|
@ -1,42 +1,41 @@
|
||||||
#include "Pomme.h"
|
#include "Pomme.h"
|
||||||
#include "PommeTime.h"
|
|
||||||
#include "PommeTypes.h"
|
#include "PommeTypes.h"
|
||||||
#include "PommeDebug.h"
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> bootTP;
|
using namespace std::chrono;
|
||||||
|
|
||||||
// timestamp (from unix epoch) of the mac epoch, Jan 1, 1904, 00:00:00
|
// System time point on application start
|
||||||
constexpr int JANUARY_1_1904 = -2'082'844'800;
|
static const time_point<high_resolution_clock> gBootTimePoint = high_resolution_clock::now();
|
||||||
|
|
||||||
|
// Timestamp of the Mac epoch (Jan 1, 1904, 00:00:00), relative to UNIX epoch (Jan 1, 1970, 00:00:00)
|
||||||
|
static constexpr int JANUARY_1_1904 = -2'082'844'800;
|
||||||
|
|
||||||
|
static int64_t GetMicrosecondsSinceBoot()
|
||||||
|
{
|
||||||
|
auto now = high_resolution_clock::now();
|
||||||
|
microseconds usecs = duration_cast<microseconds>(now - gBootTimePoint);
|
||||||
|
return usecs.count();
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Time Manager
|
// Time Manager
|
||||||
|
|
||||||
void Pomme::Time::Init()
|
|
||||||
{
|
|
||||||
bootTP = std::chrono::high_resolution_clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetDateTime(unsigned long* secs)
|
void GetDateTime(unsigned long* secs)
|
||||||
{
|
{
|
||||||
*secs = (unsigned long) (std::time(nullptr) + JANUARY_1_1904);
|
*secs = (unsigned long) (std::time(nullptr) + JANUARY_1_1904);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microseconds(UnsignedWide* usecs)
|
void Microseconds(UnsignedWide* usecsOut)
|
||||||
{
|
{
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
auto usecs = GetMicrosecondsSinceBoot();
|
||||||
auto usecs1 = std::chrono::duration_cast<std::chrono::microseconds>(now - bootTP);
|
usecsOut->lo = (usecs ) & 0xFFFFFFFFL;
|
||||||
auto usecs2 = usecs1.count();
|
usecsOut->hi = (usecs >> 32) & 0xFFFFFFFFL;
|
||||||
usecs->lo = usecs2 & 0xFFFFFFFFL;
|
|
||||||
usecs->hi = (usecs2 >> 32) & 0xFFFFFFFFL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UInt32 TickCount()
|
UInt32 TickCount()
|
||||||
{
|
{
|
||||||
TODO();
|
// A tick is approximately 1/60 of a second
|
||||||
return 0;
|
return (UInt32) (60L * GetMicrosecondsSinceBoot() / 1'000'000L);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue