diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 0418c7f8c..9ddde2efc 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -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( - 0, - (CurTick - MinTick), - (double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) * - TickToMicroSeconds) + - MinTick * TickToMicroSeconds; + s_Time = std::chrono::nanoseconds((int64_t)(mix( + 0, + (CurTick - MinTick), + (double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) * + TickToNanoSeconds.count())) + + MinTick * TickToNanoSeconds; } else { int MinTick = pThis->m_LastLocalTick; - s_Time = (int64_t)(mix(0, - pThis->m_CurrentLocalTick - MinTick, - (double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) * - TickToMicroSeconds) + - MinTick * TickToMicroSeconds; + s_Time = std::chrono::nanoseconds((int64_t)(mix(0, + pThis->m_CurrentLocalTick - MinTick, + (double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) * + 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( - 0, - (CurTick - MinTick), - (double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) * - TickToMicroSeconds) + - MinTick * TickToMicroSeconds; + s_Time = std::chrono::nanoseconds((int64_t)(mix( + 0, + (CurTick - MinTick), + (double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) * + 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); } } diff --git a/src/game/client/render.h b/src/game/client/render.h index 9136daf52..e61cecafc 100644 --- a/src/game/client/render.h +++ b/src/game/client/render.h @@ -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); diff --git a/src/game/client/render_map.cpp b/src/game/client/render_map.cpp index bcfafb575..9a7dba5da 100644 --- a/src/game/client/render_map.cpp +++ b/src/game/client/render_map.cpp @@ -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 diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index fc42ee0b3..f6a5ab83f 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -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; }