mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Add missing nanosecond conversions
This commit is contained in:
parent
bb41d02c69
commit
2677949e58
|
@ -88,10 +88,10 @@ void CMapLayers::EnvelopeEval(int TimeOffsetMillis, int Env, float *pChannels, v
|
|||
|
||||
CMapItemEnvelope *pItem = (CMapItemEnvelope *)pThis->m_pLayers->Map()->GetItem(Start + Env, 0, 0);
|
||||
|
||||
const int64_t TickToMicroSeconds = (1000000ll / (int64_t)pThis->Client()->GameTickSpeed());
|
||||
const auto TickToNanoSeconds = std::chrono::nanoseconds(1s) / (int64_t)pThis->Client()->GameTickSpeed();
|
||||
|
||||
static int64_t s_Time = 0;
|
||||
static int64_t s_LastLocalTime = time_get_nanoseconds();
|
||||
static std::chrono::nanoseconds s_Time{0};
|
||||
static auto s_LastLocalTime = tw::time_get();
|
||||
if(pThis->Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
||||
{
|
||||
const IDemoPlayer::CInfo *pInfo = pThis->DemoPlayer()->BaseInfo();
|
||||
|
@ -108,24 +108,24 @@ void CMapLayers::EnvelopeEval(int TimeOffsetMillis, int Env, float *pChannels, v
|
|||
// get the lerp of the current tick and prev
|
||||
int MinTick = pThis->Client()->PrevGameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
|
||||
int CurTick = pThis->Client()->GameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
|
||||
s_Time = (int64_t)(mix<double>(
|
||||
s_Time = std::chrono::nanoseconds((int64_t)(mix<double>(
|
||||
0,
|
||||
(CurTick - MinTick),
|
||||
(double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) *
|
||||
TickToMicroSeconds) +
|
||||
MinTick * TickToMicroSeconds;
|
||||
TickToNanoSeconds.count())) +
|
||||
MinTick * TickToNanoSeconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
int MinTick = pThis->m_LastLocalTick;
|
||||
s_Time = (int64_t)(mix<double>(0,
|
||||
s_Time = std::chrono::nanoseconds((int64_t)(mix<double>(0,
|
||||
pThis->m_CurrentLocalTick - MinTick,
|
||||
(double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) *
|
||||
TickToMicroSeconds) +
|
||||
MinTick * TickToMicroSeconds;
|
||||
TickToNanoSeconds.count())) +
|
||||
MinTick * TickToNanoSeconds;
|
||||
}
|
||||
}
|
||||
CRenderTools::RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time + (int64_t)TimeOffsetMillis * 1000ll, pChannels);
|
||||
CRenderTools::RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time + (int64_t)TimeOffsetMillis * std::chrono::nanoseconds(1ms), pChannels);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -136,21 +136,21 @@ void CMapLayers::EnvelopeEval(int TimeOffsetMillis, int Env, float *pChannels, v
|
|||
// get the lerp of the current tick and prev
|
||||
int MinTick = pThis->Client()->PrevGameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
|
||||
int CurTick = pThis->Client()->GameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
|
||||
s_Time = (int64_t)(mix<double>(
|
||||
s_Time = std::chrono::nanoseconds((int64_t)(mix<double>(
|
||||
0,
|
||||
(CurTick - MinTick),
|
||||
(double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) *
|
||||
TickToMicroSeconds) +
|
||||
MinTick * TickToMicroSeconds;
|
||||
TickToNanoSeconds.count())) +
|
||||
MinTick * TickToNanoSeconds;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int64_t CurTime = time_get_nanoseconds();
|
||||
auto CurTime = tw::time_get();
|
||||
s_Time += CurTime - s_LastLocalTime;
|
||||
s_LastLocalTime = CurTime;
|
||||
}
|
||||
CRenderTools::RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time + (int64_t)std::chrono::nanoseconds(std::chrono::milliseconds(TimeOffsetMillis)).count(), pChannels);
|
||||
CRenderTools::RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time + std::chrono::nanoseconds(std::chrono::milliseconds(TimeOffsetMillis)), pChannels);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ public:
|
|||
void RenderTee(class CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f);
|
||||
|
||||
// map render methods (render_map.cpp)
|
||||
static void RenderEvalEnvelope(CEnvPoint *pPoints, int NumPoints, int Channels, int64_t TimeNanos, float *pResult);
|
||||
static void RenderEvalEnvelope(CEnvPoint *pPoints, int NumPoints, int Channels, std::chrono::nanoseconds TimeNanos, float *pResult);
|
||||
void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser);
|
||||
void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha = 1.0f);
|
||||
void RenderTilemap(CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
void CRenderTools::RenderEvalEnvelope(CEnvPoint *pPoints, int NumPoints, int Channels, int64_t TimeNanos, float *pResult)
|
||||
void CRenderTools::RenderEvalEnvelope(CEnvPoint *pPoints, int NumPoints, int Channels, std::chrono::nanoseconds TimeNanos, float *pResult)
|
||||
{
|
||||
if(NumPoints == 0)
|
||||
{
|
||||
|
@ -37,17 +37,17 @@ void CRenderTools::RenderEvalEnvelope(CEnvPoint *pPoints, int NumPoints, int Cha
|
|||
|
||||
int64_t MaxPointTime = (int64_t)pPoints[NumPoints - 1].m_Time * std::chrono::nanoseconds(1ms).count();
|
||||
if(MaxPointTime > 0) // TODO: remove this check when implementing a IO check for maps(in this case broken envelopes)
|
||||
TimeNanos = TimeNanos % MaxPointTime;
|
||||
TimeNanos = std::chrono::nanoseconds(TimeNanos.count() % MaxPointTime);
|
||||
else
|
||||
TimeNanos = 0;
|
||||
TimeNanos = decltype(TimeNanos)::zero();
|
||||
|
||||
int TimeMillis = (int)(TimeNanos / std::chrono::nanoseconds(1ms).count());
|
||||
int TimeMillis = (int)(TimeNanos / std::chrono::nanoseconds(1ms).count()).count();
|
||||
for(int i = 0; i < NumPoints - 1; i++)
|
||||
{
|
||||
if(TimeMillis >= pPoints[i].m_Time && TimeMillis <= pPoints[i + 1].m_Time)
|
||||
{
|
||||
float Delta = pPoints[i + 1].m_Time - pPoints[i].m_Time;
|
||||
float a = (float)(((double)TimeNanos / (double)std::chrono::nanoseconds(1ms).count()) - pPoints[i].m_Time) / Delta;
|
||||
float a = (float)(((double)TimeNanos.count() / (double)std::chrono::nanoseconds(1ms).count()) - pPoints[i].m_Time) / Delta;
|
||||
|
||||
if(pPoints[i].m_Curvetype == CURVETYPE_SMOOTH)
|
||||
a = -2 * a * a * a + 3 * a * a; // second hermite basis
|
||||
|
|
|
@ -93,7 +93,7 @@ public:
|
|||
|
||||
int Eval(float Time, float *pResult)
|
||||
{
|
||||
CRenderTools::RenderEvalEnvelope(m_lPoints.base_ptr(), m_lPoints.size(), m_Channels, (int64_t)((double)Time * (double)std::chrono::nanoseconds(1s).count()), pResult);
|
||||
CRenderTools::RenderEvalEnvelope(m_lPoints.base_ptr(), m_lPoints.size(), m_Channels, std::chrono::nanoseconds((int64_t)((double)Time * (double)std::chrono::nanoseconds(1s).count())), pResult);
|
||||
return m_Channels;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue