Added clock time
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#include "RuntimeClock.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool ToUtcTime(std::time_t time, std::tm& utcTime)
|
||||
{
|
||||
return gmtime_s(&utcTime, &time) == 0;
|
||||
}
|
||||
|
||||
bool ToLocalTime(std::time_t time, std::tm& localTime)
|
||||
{
|
||||
return localtime_s(&localTime, &time) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
RuntimeClockSnapshot GetRuntimeClockSnapshot()
|
||||
{
|
||||
return MakeRuntimeClockSnapshot(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
|
||||
}
|
||||
|
||||
RuntimeClockSnapshot MakeRuntimeClockSnapshot(std::time_t now)
|
||||
{
|
||||
RuntimeClockSnapshot snapshot;
|
||||
|
||||
std::tm utcTime = {};
|
||||
if (!ToUtcTime(now, utcTime))
|
||||
return snapshot;
|
||||
|
||||
snapshot.utcTimeSeconds =
|
||||
static_cast<double>(utcTime.tm_hour * 3600 + utcTime.tm_min * 60 + utcTime.tm_sec);
|
||||
|
||||
std::tm localTime = {};
|
||||
if (!ToLocalTime(now, localTime))
|
||||
return snapshot;
|
||||
|
||||
utcTime.tm_isdst = localTime.tm_isdst;
|
||||
const std::time_t localAsTime = std::mktime(&localTime);
|
||||
const std::time_t utcAsLocalTime = std::mktime(&utcTime);
|
||||
if (localAsTime != static_cast<std::time_t>(-1) && utcAsLocalTime != static_cast<std::time_t>(-1))
|
||||
snapshot.utcOffsetSeconds = std::difftime(localAsTime, utcAsLocalTime);
|
||||
|
||||
return snapshot;
|
||||
}
|
||||
12
apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeClock.h
Normal file
12
apps/LoopThroughWithOpenGLCompositing/runtime/RuntimeClock.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
|
||||
struct RuntimeClockSnapshot
|
||||
{
|
||||
double utcTimeSeconds = 0.0;
|
||||
double utcOffsetSeconds = 0.0;
|
||||
};
|
||||
|
||||
RuntimeClockSnapshot GetRuntimeClockSnapshot();
|
||||
RuntimeClockSnapshot MakeRuntimeClockSnapshot(std::time_t now);
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "RuntimeHost.h"
|
||||
|
||||
#include "RuntimeClock.h"
|
||||
#include "RuntimeParameterUtils.h"
|
||||
#include "ShaderCompiler.h"
|
||||
#include "ShaderPackageRegistry.h"
|
||||
@@ -1321,6 +1323,7 @@ bool RuntimeHost::TryGetLayerRenderStates(unsigned outputWidth, unsigned outputH
|
||||
|
||||
void RuntimeHost::BuildLayerRenderStatesLocked(unsigned outputWidth, unsigned outputHeight, std::vector<RuntimeRenderState>& states) const
|
||||
{
|
||||
const RuntimeClockSnapshot clock = GetRuntimeClockSnapshot();
|
||||
for (const LayerPersistentState& layer : mPersistentState.layers)
|
||||
{
|
||||
auto shaderIt = mPackagesById.find(layer.shaderId);
|
||||
@@ -1331,6 +1334,8 @@ void RuntimeHost::BuildLayerRenderStatesLocked(unsigned outputWidth, unsigned ou
|
||||
state.layerId = layer.id;
|
||||
state.shaderId = layer.shaderId;
|
||||
state.timeSeconds = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - mStartTime).count();
|
||||
state.utcTimeSeconds = clock.utcTimeSeconds;
|
||||
state.utcOffsetSeconds = clock.utcOffsetSeconds;
|
||||
state.frameCount = static_cast<double>(mFrameCounter);
|
||||
state.mixAmount = 1.0;
|
||||
state.bypass = layer.bypass ? 1.0 : 0.0;
|
||||
|
||||
Reference in New Issue
Block a user